2 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <sys/types.h>
31 /*---------------------------------------------------------------------------
33 Test program used to test DMAPI by issuing read, write, and trunc calls to a
34 file. The command line is:
36 rwt [-r|-w|-t] [-o offset] [-l length] pathname
40 indicates that a read should be done (the default if none specified)
42 indiates that a write should be done
44 indicates that a truncate should be done, in which case the -l
47 offset at which to begin the read, write or truncate (default is 0).
49 the length in bytes to read or write (default is 1).
51 the file to be used by the test.
53 ----------------------------------------------------------------------------*/
56 extern char *sys_errlist[];
68 fprintf(stderr, "usage:\t%s [-r|-w|-t] [-o offset] [-l length] "
69 "pathname\n", Progname);
79 char *pathname = NULL;
92 Progname = strrchr(argv[0], '/');
99 /* Crack and validate the command line options. */
101 while ((opt = getopt(argc, argv, "rwto:l:")) != EOF) {
113 offset = atol(optarg);
116 length = atol(optarg);
122 if (optind + 1 != argc)
124 if (rflag + wflag + tflag > 1)
126 pathname = argv[optind];
128 if ((fd = open(pathname, O_RDWR)) < 0) {
129 fprintf(stderr, "open of %s failed, %s\n", pathname,
134 if ((bufp = malloc(length)) == NULL) {
135 fprintf(stderr, "malloc of %zd bytes failed\n", length);
139 memset(bufp, ch, length);
143 if ((seek_off = lseek(fd, offset, SEEK_SET)) < 0) {
144 fprintf(stderr, "seek failed, %s\n", strerror(errno));
147 if (seek_off != offset) {
149 "seeked to offset %lld, actually "
151 (long long) offset, (long long) seek_off);
157 if ((rc = write(fd, bufp, length)) < 0) {
158 fprintf(stderr, "write failed, %s\n", strerror(errno));
162 fprintf(stderr, "expected to write %zd bytes, actually "
163 "wrote %zd bytes\n", length, rc);
167 if (ftruncate(fd, offset) != 0) {
168 fprintf(stderr, "truncate failed, %s\n",
173 if ((rc = read(fd, bufp, length)) < 0) {
174 fprintf(stderr, "read failed, %s\n", strerror(errno));
178 fprintf(stderr, "expected to read %zd bytes, actually "
179 "read %zd bytes\n", length, rc);