2 * Copyright (C) 1991, NeXT Computer, Inc. All Rights Reserverd.
5 * Author: Avadis Tevanian, Jr.
7 * File system exerciser.
9 * Rewritten 8/98 by Conrad Minshall.
11 * Small changes to work under Linux -- davej.
38 #define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */
41 * A log entry is an operation and a bunch of arguments.
51 struct log_entry oplog[LOGSIZE]; /* the log */
52 int logptr = 0; /* current position in log */
53 int logcount = 0; /* total ops */
62 #define OP_CLOSEOPEN 4
68 #define PAGE_SIZE getpagesize()
70 #define PAGE_MASK (PAGE_SIZE - 1)
72 char *original_buf; /* a pointer to the original data */
73 char *good_buf; /* a pointer to the correct data */
74 char *temp_buf; /* a pointer to the current data */
75 char *fname; /* name of our test file */
76 int fd; /* fd for our test file */
81 unsigned long testcalls = 0; /* calls to function "test" */
83 unsigned long simulatedopcount = 0; /* -b flag */
84 int closeprob = 0; /* -c flag */
85 int debug = 0; /* -d flag */
86 unsigned long debugstart = 0; /* -D flag */
87 int flush = 0; /* -f flag */
88 int do_fsync = 0; /* -y flag */
89 unsigned long maxfilelen = 256 * 1024; /* -l flag */
90 int sizechecks = 1; /* -n flag disables them */
91 int maxoplen = 64 * 1024; /* -o flag */
92 int quiet = 0; /* -q flag */
93 unsigned long progressinterval = 0; /* -p flag */
94 int readbdy = 1; /* -r flag */
95 int style = 0; /* -s flag */
96 int prealloc = 0; /* -x flag */
97 int truncbdy = 1; /* -t flag */
98 int writebdy = 1; /* -w flag */
99 long monitorstart = -1; /* -m flag */
100 long monitorend = -1; /* -m flag */
101 int lite = 0; /* -L flag */
102 long numops = -1; /* -N flag */
103 int randomoplen = 1; /* -O flag disables it */
104 int seed = 1; /* -S flag */
105 int mapped_writes = 1; /* -W flag disables */
106 int mapped_reads = 1; /* -R flag disables it */
108 int o_direct; /* -Z */
115 int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset);
118 #define fsxread(a,b,c,d) aio_rw(READ, a,b,c,d)
119 #define fsxwrite(a,b,c,d) aio_rw(WRITE, a,b,c,d)
121 #define fsxread(a,b,c,d) read(a,b,c)
122 #define fsxwrite(a,b,c,d) write(a,b,c)
125 FILE * fsxlogf = NULL;
129 static void *round_up(void *ptr, unsigned long align, unsigned long offset)
131 unsigned long ret = (unsigned long)ptr;
133 ret = ((ret + align - 1) & ~(align - 1));
139 vwarnc(int code, const char *fmt, va_list ap) {
140 fprintf(stderr, "fsx: ");
142 vfprintf(stderr, fmt, ap);
143 fprintf(stderr, ": ");
145 fprintf(stderr, "%s\n", strerror(code));
149 warn(const char * fmt, ...) {
152 vwarnc(errno, fmt, ap);
162 vfprintf(stdout, fmt, args);
164 vfprintf(fsxlogf, fmt, args);
171 prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno));
176 log4(int operation, int arg0, int arg1, int arg2)
178 struct log_entry *le;
181 le->operation = operation;
183 le->operation = ~ le->operation;
189 if (logptr >= LOGSIZE)
198 struct log_entry *lp;
200 prt("LOG DUMP (%d total operations):\n", logcount);
201 if (logcount < LOGSIZE) {
208 for ( ; count > 0; count--) {
211 opnum = i+1 + (logcount/LOGSIZE)*LOGSIZE;
212 prt("%d(%d mod 256): ", opnum, opnum%256);
214 if ((closeopen = lp->operation < 0))
215 lp->operation = ~ lp->operation;
217 switch (lp->operation) {
219 prt("MAPREAD\t0x%x thru 0x%x\t(0x%x bytes)",
220 lp->args[0], lp->args[0] + lp->args[1] - 1,
222 if (badoff >= lp->args[0] && badoff <
223 lp->args[0] + lp->args[1])
227 prt("MAPWRITE 0x%x thru 0x%x\t(0x%x bytes)",
228 lp->args[0], lp->args[0] + lp->args[1] - 1,
230 if (badoff >= lp->args[0] && badoff <
231 lp->args[0] + lp->args[1])
235 prt("READ\t0x%x thru 0x%x\t(0x%x bytes)",
236 lp->args[0], lp->args[0] + lp->args[1] - 1,
238 if (badoff >= lp->args[0] &&
239 badoff < lp->args[0] + lp->args[1])
243 prt("WRITE\t0x%x thru 0x%x\t(0x%x bytes)",
244 lp->args[0], lp->args[0] + lp->args[1] - 1,
246 if (lp->args[0] > lp->args[2])
248 else if (lp->args[0] + lp->args[1] > lp->args[2])
250 if ((badoff >= lp->args[0] || badoff >=lp->args[2]) &&
251 badoff < lp->args[0] + lp->args[1])
255 down = lp->args[0] < lp->args[1];
256 prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
257 down ? "DOWN" : "UP", lp->args[1], lp->args[0]);
258 if (badoff >= lp->args[!down] &&
259 badoff < lp->args[!!down])
263 prt("SKIPPED (no operation)");
266 prt("BOGUS LOG ENTRY (operation code = %d)!",
270 prt("\n\t\tCLOSE/OPEN");
280 save_buffer(char *buffer, off_t bufferlength, int fd)
283 ssize_t byteswritten;
285 if (fd <= 0 || bufferlength == 0)
288 if (bufferlength > SSIZE_MAX) {
289 prt("fsx flaw: overflow in save_buffer\n");
293 off_t size_by_seek = lseek(fd, (off_t)0, L_XTND);
294 if (size_by_seek == (off_t)-1)
295 prterr("save_buffer: lseek eof");
296 else if (bufferlength > size_by_seek) {
297 warn("save_buffer: .fsxgood file too short... will save 0x%qx bytes instead of 0x%qx\n", (unsigned long long)size_by_seek,
298 (unsigned long long)bufferlength);
299 bufferlength = size_by_seek;
303 ret = lseek(fd, (off_t)0, SEEK_SET);
304 if (ret == (off_t)-1)
305 prterr("save_buffer: lseek 0");
307 byteswritten = write(fd, buffer, (size_t)bufferlength);
308 if (byteswritten != bufferlength) {
309 if (byteswritten == -1)
310 prterr("save_buffer write");
312 warn("save_buffer: short write, 0x%x bytes instead of 0x%qx\n",
313 (unsigned)byteswritten,
314 (unsigned long long)bufferlength);
320 report_failure(int status)
326 save_buffer(good_buf, file_size, fsxgoodfd);
327 prt("Correct content saved for comparison\n");
328 prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n",
337 #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
338 *(((unsigned char *)(cp)) + 1)))
341 check_buffers(unsigned offset, unsigned size)
349 if (bcmp(good_buf + offset, temp_buf, size) != 0) {
350 prt("READ BAD DATA: offset = 0x%x, size = 0x%x, fname = %s\n",
351 offset, size, fname);
352 prt("OFFSET\tGOOD\tBAD\tRANGE\n");
354 c = good_buf[offset];
358 bad = short_at(&temp_buf[i]);
359 prt("0x%5x\t0x%04x\t0x%04x", offset,
360 short_at(&good_buf[offset]), bad);
361 op = temp_buf[offset & 1 ? i+1 : i];
364 prt("operation# (mod 256) for "
365 "the bad data may be %u\n",
366 ((unsigned)op & 0xff));
368 prt("operation# (mod 256) for "
369 "the bad data unknown, check"
370 " HOLE and EXTEND ops\n");
390 if (fstat(fd, &statbuf)) {
391 prterr("check_size: fstat");
392 statbuf.st_size = -1;
394 size_by_seek = lseek(fd, (off_t)0, L_XTND);
395 if (file_size != statbuf.st_size || file_size != size_by_seek) {
396 prt("Size error: expected 0x%qx stat 0x%qx seek 0x%qx\n",
397 (unsigned long long)file_size,
398 (unsigned long long)statbuf.st_size,
399 (unsigned long long)size_by_seek);
406 check_trunc_hack(void)
410 ftruncate(fd, (off_t)0);
411 ftruncate(fd, (off_t)100000);
413 if (statbuf.st_size != (off_t)100000) {
414 prt("no extend on truncate! not posix!\n");
421 doflush(unsigned offset, unsigned size)
427 if (o_direct == O_DIRECT)
430 pg_offset = offset & mmap_mask;
431 map_size = pg_offset + size;
433 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
434 MAP_FILE | MAP_SHARED, fd,
435 (off_t)(offset - pg_offset))) == (char *)-1) {
436 prterr("doflush: mmap");
439 if (msync(p, map_size, MS_INVALIDATE) != 0) {
440 prterr("doflush: msync");
443 if (munmap(p, map_size) != 0) {
444 prterr("doflush: munmap");
450 doread(unsigned offset, unsigned size)
455 offset -= offset % readbdy;
457 size -= size % readbdy;
459 if (!quiet && testcalls > simulatedopcount && !o_direct)
460 prt("skipping zero size read\n");
461 log4(OP_SKIPPED, OP_READ, offset, size);
464 if (size + offset > file_size) {
465 if (!quiet && testcalls > simulatedopcount)
466 prt("skipping seek/read past end of file\n");
467 log4(OP_SKIPPED, OP_READ, offset, size);
471 log4(OP_READ, offset, size, 0);
473 if (testcalls <= simulatedopcount)
477 ((progressinterval && testcalls % progressinterval == 0) ||
479 (monitorstart == -1 ||
480 (offset + size > monitorstart &&
481 (monitorend == -1 || offset <= monitorend))))))
482 prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
483 offset, offset + size - 1, size);
484 ret = lseek(fd, (off_t)offset, SEEK_SET);
485 if (ret == (off_t)-1) {
486 prterr("doread: lseek");
489 iret = fsxread(fd, temp_buf, size, offset);
492 prterr("doread: read");
494 prt("short read: 0x%x bytes instead of 0x%x\n",
498 check_buffers(offset, size);
503 domapread(unsigned offset, unsigned size)
509 offset -= offset % readbdy;
511 if (!quiet && testcalls > simulatedopcount)
512 prt("skipping zero size read\n");
513 log4(OP_SKIPPED, OP_MAPREAD, offset, size);
516 if (size + offset > file_size) {
517 if (!quiet && testcalls > simulatedopcount)
518 prt("skipping seek/read past end of file\n");
519 log4(OP_SKIPPED, OP_MAPREAD, offset, size);
523 log4(OP_MAPREAD, offset, size, 0);
525 if (testcalls <= simulatedopcount)
529 ((progressinterval && testcalls % progressinterval == 0) ||
531 (monitorstart == -1 ||
532 (offset + size > monitorstart &&
533 (monitorend == -1 || offset <= monitorend))))))
534 prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
535 offset, offset + size - 1, size);
537 pg_offset = offset & PAGE_MASK;
538 map_size = pg_offset + size;
540 if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_SHARED, fd,
541 (off_t)(offset - pg_offset))) == (char *)-1) {
542 prterr("domapread: mmap");
545 memcpy(temp_buf, p + pg_offset, size);
546 if (munmap(p, map_size) != 0) {
547 prterr("domapread: munmap");
551 check_buffers(offset, size);
556 gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size)
559 good_buf[offset] = testcalls % 256;
561 good_buf[offset] += original_buf[offset];
568 dowrite(unsigned offset, unsigned size)
573 offset -= offset % writebdy;
575 size -= size % writebdy;
577 if (!quiet && testcalls > simulatedopcount && !o_direct)
578 prt("skipping zero size write\n");
579 log4(OP_SKIPPED, OP_WRITE, offset, size);
583 log4(OP_WRITE, offset, size, file_size);
585 gendata(original_buf, good_buf, offset, size);
586 if (file_size < offset + size) {
587 if (file_size < offset)
588 bzero(good_buf + file_size, offset - file_size);
589 file_size = offset + size;
591 warn("Lite file size bug in fsx!");
596 if (testcalls <= simulatedopcount)
600 ((progressinterval && testcalls % progressinterval == 0) ||
602 (monitorstart == -1 ||
603 (offset + size > monitorstart &&
604 (monitorend == -1 || offset <= monitorend))))))
605 prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
606 offset, offset + size - 1, size);
607 ret = lseek(fd, (off_t)offset, SEEK_SET);
608 if (ret == (off_t)-1) {
609 prterr("dowrite: lseek");
612 iret = fsxwrite(fd, good_buf + offset, size, offset);
615 prterr("dowrite: write");
617 prt("short write: 0x%x bytes instead of 0x%x\n",
623 prt("fsync() failed: %s\n", strerror(errno));
628 doflush(offset, size);
634 domapwrite(unsigned offset, unsigned size)
641 offset -= offset % writebdy;
643 if (!quiet && testcalls > simulatedopcount)
644 prt("skipping zero size write\n");
645 log4(OP_SKIPPED, OP_MAPWRITE, offset, size);
648 cur_filesize = file_size;
650 log4(OP_MAPWRITE, offset, size, 0);
652 gendata(original_buf, good_buf, offset, size);
653 if (file_size < offset + size) {
654 if (file_size < offset)
655 bzero(good_buf + file_size, offset - file_size);
656 file_size = offset + size;
658 warn("Lite file size bug in fsx!");
663 if (testcalls <= simulatedopcount)
667 ((progressinterval && testcalls % progressinterval == 0) ||
669 (monitorstart == -1 ||
670 (offset + size > monitorstart &&
671 (monitorend == -1 || offset <= monitorend))))))
672 prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
673 offset, offset + size - 1, size);
675 if (file_size > cur_filesize) {
676 if (ftruncate(fd, file_size) == -1) {
677 prterr("domapwrite: ftruncate");
681 pg_offset = offset & PAGE_MASK;
682 map_size = pg_offset + size;
684 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
685 MAP_FILE | MAP_SHARED, fd,
686 (off_t)(offset - pg_offset))) == (char *)-1) {
687 prterr("domapwrite: mmap");
690 memcpy(p + pg_offset, good_buf + offset, size);
691 if (msync(p, map_size, 0) != 0) {
692 prterr("domapwrite: msync");
695 if (munmap(p, map_size) != 0) {
696 prterr("domapwrite: munmap");
703 dotruncate(unsigned size)
705 int oldsize = file_size;
707 size -= size % truncbdy;
708 if (size > biggest) {
710 if (!quiet && testcalls > simulatedopcount)
711 prt("truncating to largest ever: 0x%x\n", size);
714 log4(OP_TRUNCATE, size, (unsigned)file_size, 0);
716 if (size > file_size)
717 bzero(good_buf + file_size, size - file_size);
720 if (testcalls <= simulatedopcount)
723 if ((progressinterval && testcalls % progressinterval == 0) ||
724 (debug && (monitorstart == -1 || monitorend == -1 ||
725 size <= monitorend)))
726 prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls, oldsize, size);
727 if (ftruncate(fd, (off_t)size) == -1) {
728 prt("ftruncate1: %x\n", size);
729 prterr("dotruncate: ftruncate");
740 if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
741 prterr("writefileimage: lseek");
744 iret = write(fd, good_buf, file_size);
745 if ((off_t)iret != file_size) {
747 prterr("writefileimage: write");
749 prt("short write: 0x%x bytes instead of 0x%qx\n",
750 iret, (unsigned long long)file_size);
753 if (lite ? 0 : ftruncate(fd, file_size) == -1) {
754 prt("ftruncate2: %qx\n", (unsigned long long)file_size);
755 prterr("writefileimage: ftruncate");
764 if (testcalls <= simulatedopcount)
768 prt("%lu close/open\n", testcalls);
770 prterr("docloseopen: close");
773 fd = open(fname, O_RDWR|o_direct, 0);
775 prterr("docloseopen: open");
784 unsigned long offset;
785 unsigned long size = maxoplen;
786 unsigned long rv = random();
787 unsigned long op = rv % (3 + !lite + mapped_writes);
789 /* turn off the map read if necessary */
791 if (op == 2 && !mapped_reads)
794 if (simulatedopcount > 0 && testcalls == simulatedopcount)
800 closeopen = (rv >> 3) < (1 << 28) / closeprob;
802 if (debugstart > 0 && testcalls >= debugstart)
805 if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
806 prt("%lu...\n", testcalls);
813 * MAPWRITE: op = 3 or 4
815 if (lite ? 0 : op == 3 && (style & 1) == 0) /* vanilla truncate? */
816 dotruncate(random() % maxfilelen);
819 size = random() % (maxoplen+1);
820 if (lite ? 0 : op == 3)
824 if (op == 1 || op == (lite ? 3 : 4)) {
825 offset %= maxfilelen;
826 if (offset + size > maxfilelen)
827 size = maxfilelen - offset;
829 domapwrite(offset, size);
831 dowrite(offset, size);
837 if (offset + size > file_size)
838 size = file_size - offset;
840 domapread(offset, size);
842 doread(offset, size);
846 if (sizechecks && testcalls > simulatedopcount)
858 prt("signal %d\n", sig);
859 prt("testcalls = %lu\n", testcalls);
867 fprintf(stdout, "usage: %s",
868 "fsx [-dnqxALOWZ] [-b opnum] [-c Prob] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] fname\n\
869 -b opnum: beginning operation number (default 1)\n\
870 -c P: 1 in P chance of file close+open at each op (default infinity)\n\
871 -d: debug output for all operations\n\
872 -f flush and invalidate cache after I/O\n\
873 -l flen: the upper bound on file size (default 262144)\n\
874 -m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\
875 -n: no verifications of file size\n\
876 -o oplen: the upper bound on operation size (default 65536)\n\
877 -p progressinterval: debug output at specified operation interval\n\
878 -q: quieter operation\n\
879 -r readbdy: 4096 would make reads page aligned (default 1)\n\
880 -s style: 1 gives smaller truncates (default 0)\n\
881 -t truncbdy: 4096 would make truncates page aligned (default 1)\n\
882 -w writebdy: 4096 would make writes page aligned (default 1)\n\
883 -x: preallocate file space before starting, XFS only (default 0)\n\
884 -y synchronize changes to a file\n"
887 " -A: Use the AIO system calls\n"
889 " -D startingop: debug output starting at specified operation\n\
890 -L: fsxLite - no file creations & no file size changes\n\
891 -N numops: total # operations to do (default infinity)\n\
892 -O: use oplen (see -o flag) for every op (default random)\n\
893 -P: save .fsxlog and .fsxgood files in dirpath (default ./)\n\
894 -S seed: for random # generator (default 1) 0 gets timestamp\n\
895 -W: mapped write operations DISabled\n\
896 -R: read() system calls only (mapped reads disabled)\n\
897 -Z: O_DIRECT (use -R, -W, -r and -w too)\n\
898 fname: this filename is REQUIRED (no default)\n");
904 getnum(char *s, char **e)
909 ret = strtol(s, e, 0);
945 ret = io_queue_init(QSZ, &io_ctx);
947 fprintf(stderr, "aio_setup: io_queue_init failed: %s\n",
955 __aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
957 struct io_event event;
958 static struct timespec ts;
959 struct iocb *iocbs[] = { &iocb };
963 io_prep_pread(&iocb, fd, buf, len, offset);
965 io_prep_pwrite(&iocb, fd, buf, len, offset);
970 ret = io_submit(io_ctx, 1, iocbs);
972 fprintf(stderr, "errcode=%d\n", ret);
973 fprintf(stderr, "aio_rw: io_submit failed: %s\n",
978 ret = io_getevents(io_ctx, 1, 1, &event, &ts);
980 fprintf(stderr, "errcode=%d\n", ret);
981 fprintf(stderr, "aio_rw: io_getevents failed: %s\n",
985 if (len != event.res) {
986 fprintf(stderr, "bad read length: %lu instead of %u\n",
992 int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
997 ret = __aio_rw(rw, fd, buf, len, offset);
1000 ret = read(fd, buf, len);
1002 ret = write(fd, buf, len);
1010 main(int argc, char **argv)
1014 char goodfile[1024];
1020 page_size = getpagesize();
1021 page_mask = page_size - 1;
1022 mmap_mask = page_mask;
1025 setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
1027 while ((ch = getopt(argc, argv, "b:c:dfl:m:no:p:qr:s:t:w:xyAD:LN:OP:RS:WZ"))
1031 simulatedopcount = getnum(optarg, &endp);
1033 fprintf(stdout, "Will begin at operation %ld\n",
1035 if (simulatedopcount == 0)
1037 simulatedopcount -= 1;
1040 closeprob = getnum(optarg, &endp);
1043 "Chance of close/open is 1 in %d\n",
1055 maxfilelen = getnum(optarg, &endp);
1056 if (maxfilelen <= 0)
1060 monitorstart = getnum(optarg, &endp);
1061 if (monitorstart < 0)
1063 if (!endp || *endp++ != ':')
1065 monitorend = getnum(endp, &endp);
1068 if (monitorend == 0)
1069 monitorend = -1; /* aka infinity */
1075 maxoplen = getnum(optarg, &endp);
1080 progressinterval = getnum(optarg, &endp);
1081 if (progressinterval == 0)
1088 readbdy = getnum(optarg, &endp);
1093 style = getnum(optarg, &endp);
1094 if (style < 0 || style > 1)
1098 truncbdy = getnum(optarg, &endp);
1103 writebdy = getnum(optarg, &endp);
1117 debugstart = getnum(optarg, &endp);
1125 numops = getnum(optarg, &endp);
1133 strncpy(goodfile, optarg, sizeof(goodfile));
1134 strcat(goodfile, "/");
1135 strncpy(logfile, optarg, sizeof(logfile));
1136 strcat(logfile, "/");
1142 seed = getnum(optarg, &endp);
1144 seed = time(0) % 10000;
1146 fprintf(stdout, "Seed set to %d\n", seed);
1153 fprintf(stdout, "mapped writes DISABLED\n");
1156 o_direct = O_DIRECT;
1168 signal(SIGHUP, cleanup);
1169 signal(SIGINT, cleanup);
1170 signal(SIGPIPE, cleanup);
1171 signal(SIGALRM, cleanup);
1172 signal(SIGTERM, cleanup);
1173 signal(SIGXCPU, cleanup);
1174 signal(SIGXFSZ, cleanup);
1175 signal(SIGVTALRM, cleanup);
1176 signal(SIGUSR1, cleanup);
1177 signal(SIGUSR2, cleanup);
1179 initstate(seed, state, 256);
1182 O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC)|o_direct, 0666);
1189 xfs_flock64_t resv = { 0 };
1190 #ifdef HAVE_XFS_PLATFORM_DEFS_H
1191 if (!platform_test_xfs_fd(fd)) {
1193 fprintf(stderr, "main: cannot prealloc, non XFS\n");
1197 resv.l_len = maxfilelen;
1198 if ((xfsctl(fname, fd, XFS_IOC_RESVSP, &resv)) < 0) {
1204 strncat(goodfile, fname, 256);
1205 strcat (goodfile, ".fsxgood");
1206 fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
1207 if (fsxgoodfd < 0) {
1211 strncat(logfile, fname, 256);
1212 strcat (logfile, ".fsxlog");
1213 fsxlogf = fopen(logfile, "w");
1214 if (fsxlogf == NULL) {
1226 file_size = maxfilelen = lseek(fd, (off_t)0, L_XTND);
1227 if (file_size == (off_t)-1) {
1229 warn("main: lseek eof");
1232 ret = lseek(fd, (off_t)0, SEEK_SET);
1233 if (ret == (off_t)-1) {
1235 warn("main: lseek 0");
1239 original_buf = (char *) malloc(maxfilelen);
1240 for (i = 0; i < maxfilelen; i++)
1241 original_buf[i] = random() % 256;
1242 good_buf = (char *) malloc(maxfilelen + writebdy);
1243 good_buf = round_up(good_buf, writebdy, 0);
1244 bzero(good_buf, maxfilelen);
1245 temp_buf = (char *) malloc(maxoplen + readbdy);
1246 temp_buf = round_up(temp_buf, readbdy, 0);
1247 bzero(temp_buf, maxoplen);
1248 if (lite) { /* zero entire existing file */
1251 written = write(fd, good_buf, (size_t)maxfilelen);
1252 if (written != maxfilelen) {
1253 if (written == -1) {
1255 warn("main: error on write");
1257 warn("main: short write, 0x%x bytes instead "
1266 while (numops == -1 || numops--)
1273 prt("All operations completed A-OK!\n");