2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 #include <sys/types.h>
47 /*---------------------------------------------------------------------------
49 Test program used to test DMAPI by issuing read, write, and trunc calls to a
50 file. The command line is:
52 rwt [-r|-w|-t] [-o offset] [-l length] pathname
56 indicates that a read should be done (the default if none specified)
58 indiates that a write should be done
60 indicates that a truncate should be done, in which case the -l
63 offset at which to begin the read, write or truncate (default is 0).
65 the length in bytes to read or write (default is 1).
67 the file to be used by the test.
69 ----------------------------------------------------------------------------*/
72 extern char *sys_errlist[];
86 fprintf(stderr, "usage:\t%s [-r|-w|-t] [-o offset] [-l length] "
87 "pathname\n", Progname);
97 char *pathname = NULL;
111 if (Progname = strrchr(argv[0], '/')) {
117 /* Crack and validate the command line options. */
119 while ((opt = getopt(argc, argv, "rwto:l:")) != EOF) {
131 offset = atol(optarg);
134 length = atol(optarg);
140 if (optind + 1 != argc)
142 if (rflag + wflag + tflag > 1)
144 pathname = argv[optind];
146 if ((fd = open(pathname, O_RDWR)) < 0) {
147 fprintf(stderr, "open of %s failed, %s\n", pathname,
152 if ((bufp = malloc(length)) == NULL) {
153 fprintf(stderr, "malloc of %d bytes failed\n", length);
157 memset(bufp, ch, length);
161 if ((seek_off = lseek(fd, offset, SEEK_SET)) < 0) {
162 fprintf(stderr, "seek failed, %s\n", strerror(errno));
165 if (seek_off != offset) {
166 fprintf(stderr, "seeked to offset %d, actually "
167 "arrived at %d\n", offset, seek_off);
173 if ((rc = write(fd, bufp, length)) < 0) {
174 fprintf(stderr, "write failed, %s\n", strerror(errno));
178 fprintf(stderr, "expected to write %d bytes, actually "
179 "wrote %d bytes\n", length, rc);
183 if (ftruncate(fd, offset) != 0) {
184 fprintf(stderr, "truncate failed, %s\n",
189 if ((rc = read(fd, bufp, length)) < 0) {
190 fprintf(stderr, "read failed, %s\n", strerror(errno));
194 fprintf(stderr, "expected to read %d bytes, actually "
195 "read %d bytes\n", length, rc);