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 if (Progname = strrchr(argv[0], '/')) {
98 /* Crack and validate the command line options. */
100 while ((opt = getopt(argc, argv, "rwto:l:")) != EOF) {
112 offset = atol(optarg);
115 length = atol(optarg);
121 if (optind + 1 != argc)
123 if (rflag + wflag + tflag > 1)
125 pathname = argv[optind];
127 if ((fd = open(pathname, O_RDWR)) < 0) {
128 fprintf(stderr, "open of %s failed, %s\n", pathname,
133 if ((bufp = malloc(length)) == NULL) {
134 fprintf(stderr, "malloc of %d bytes failed\n", length);
138 memset(bufp, ch, length);
142 if ((seek_off = lseek(fd, offset, SEEK_SET)) < 0) {
143 fprintf(stderr, "seek failed, %s\n", strerror(errno));
146 if (seek_off != offset) {
148 "seeked to offset %lld, actually "
150 (int64_t)offset, (int64_t)seek_off);
156 if ((rc = write(fd, bufp, length)) < 0) {
157 fprintf(stderr, "write failed, %s\n", strerror(errno));
161 fprintf(stderr, "expected to write %d bytes, actually "
162 "wrote %d bytes\n", length, rc);
166 if (ftruncate(fd, offset) != 0) {
167 fprintf(stderr, "truncate failed, %s\n",
172 if ((rc = read(fd, bufp, length)) < 0) {
173 fprintf(stderr, "read failed, %s\n", strerror(errno));
177 fprintf(stderr, "expected to read %d bytes, actually "
178 "read %d bytes\n", length, rc);