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>
45 /*---------------------------------------------------------------------------
47 Test program used to test DMAPI by issuing read, write, and trunc calls to a
48 file. The command line is:
50 rwt [-r|-w|-t] [-o offset] [-l length] pathname
54 indicates that a read should be done (the default if none specified)
56 indiates that a write should be done
58 indicates that a truncate should be done, in which case the -l
61 offset at which to begin the read, write or truncate (default is 0).
63 the length in bytes to read or write (default is 1).
65 the file to be used by the test.
67 ----------------------------------------------------------------------------*/
70 extern char *sys_errlist[];
82 fprintf(stderr, "usage:\t%s [-r|-w|-t] [-o offset] [-l length] "
83 "pathname\n", Progname);
93 char *pathname = NULL;
106 if (Progname = strrchr(argv[0], '/')) {
112 /* Crack and validate the command line options. */
114 while ((opt = getopt(argc, argv, "rwto:l:")) != EOF) {
126 offset = atol(optarg);
129 length = atol(optarg);
135 if (optind + 1 != argc)
137 if (rflag + wflag + tflag > 1)
139 pathname = argv[optind];
141 if ((fd = open(pathname, O_RDWR)) < 0) {
142 fprintf(stderr, "open of %s failed, %s\n", pathname,
147 if ((bufp = malloc(length)) == NULL) {
148 fprintf(stderr, "malloc of %d bytes failed\n", length);
152 memset(bufp, ch, length);
156 if ((seek_off = lseek(fd, offset, SEEK_SET)) < 0) {
157 fprintf(stderr, "seek failed, %s\n", strerror(errno));
160 if (seek_off != offset) {
162 "seeked to offset %lld, actually "
164 (int64_t)offset, (int64_t)seek_off);
170 if ((rc = write(fd, bufp, length)) < 0) {
171 fprintf(stderr, "write failed, %s\n", strerror(errno));
175 fprintf(stderr, "expected to write %d bytes, actually "
176 "wrote %d bytes\n", length, rc);
180 if (ftruncate(fd, offset) != 0) {
181 fprintf(stderr, "truncate failed, %s\n",
186 if ((rc = read(fd, bufp, length)) < 0) {
187 fprintf(stderr, "read failed, %s\n", strerror(errno));
191 fprintf(stderr, "expected to read %d bytes, actually "
192 "read %d bytes\n", length, rc);