2 * Copyright (c) 1998-2001 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 2.0 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Author: Avadis Tevanian, Jr.
25 * File system exerciser.
27 * Rewrite and enhancements 1998-2001 Conrad Minshall -- conrad@mac.com
29 * Various features from Joe Sokol, Pat Dirks, and Clark Warner.
31 * Small changes to work under Linux -- davej@suse.de
33 * Sundry porting patches from Guy Harris 12/2001
35 * Checks for mmap last-page zero fill.
37 * Updated license to APSL 2.0, 2004/7/27 - Jordan Hubbard
43 #include <sys/types.h>
46 # include <sys/param.h>
65 #define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */
68 * A log entry is an operation and a bunch of arguments.
78 struct log_entry oplog[LOGSIZE]; /* the log */
79 int logptr = 0; /* current position in log */
80 int logcount = 0; /* total ops */
89 #define OP_CLOSEOPEN 4
93 #define OP_INVALIDATE 8
98 char *original_buf; /* a pointer to the original data */
99 char *good_buf; /* a pointer to the correct data */
100 char *temp_buf; /* a pointer to the current data */
101 char *fname; /* name of our test file */
102 int fd; /* fd for our test file */
107 unsigned long testcalls = 0; /* calls to function "test" */
109 unsigned long simulatedopcount = 0; /* -b flag */
110 int closeprob = 0; /* -c flag */
111 int invlprob = 0; /* -i flag */
112 int debug = 0; /* -d flag */
113 unsigned long debugstart = 0; /* -D flag */
114 unsigned long maxfilelen = 256 * 1024; /* -l flag */
115 int sizechecks = 1; /* -n flag disables them */
116 int maxoplen = 64 * 1024; /* -o flag */
117 int quiet = 0; /* -q flag */
118 unsigned long progressinterval = 0; /* -p flag */
119 int readbdy = 1; /* -r flag */
120 int style = 0; /* -s flag */
121 int truncbdy = 1; /* -t flag */
122 int writebdy = 1; /* -w flag */
123 long monitorstart = -1; /* -m flag */
124 long monitorend = -1; /* -m flag */
125 int lite = 0; /* -L flag */
126 long numops = -1; /* -N flag */
127 int randomoplen = 1; /* -O flag disables it */
128 int seed = 1; /* -S flag */
129 int mapped_writes = 1; /* -W flag disables */
130 int mapped_reads = 1; /* -R flag disables it */
131 int mapped_msync = 1; /* -U flag disables */
133 FILE * fsxlogf = NULL;
140 vwarnc(code, fmt, ap)
145 fprintf(stderr, "fsx: ");
147 vfprintf(stderr, fmt, ap);
148 fprintf(stderr, ": ");
150 fprintf(stderr, "%s\n", strerror(code));
155 warn(const char * fmt, ...)
159 vwarnc(errno, fmt, ap);
170 vfprintf(stdout, fmt, args);
175 vfprintf(fsxlogf, fmt, args);
183 prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno));
188 do_log4(int operation, int arg0, int arg1, int arg2)
190 struct log_entry *le;
193 le->operation = operation;
199 if (logptr >= LOGSIZE)
205 log4(int operation, int arg0, int arg1, int arg2)
207 do_log4(operation, arg0, arg1, arg2);
209 do_log4(OP_CLOSEOPEN, 0, 0, 0);
211 do_log4(OP_INVALIDATE, 0, 0, 0);
218 struct log_entry *lp;
219 int i, count, down, opnum;
221 prt("LOG DUMP (%d total operations):\n", logcount);
222 if (logcount < LOGSIZE) {
230 opnum = i + 1 + (logcount/LOGSIZE)*LOGSIZE;
231 for ( ; count > 0; count--) {
234 if (lp->operation == OP_CLOSEOPEN ||
235 lp->operation == OP_INVALIDATE) {
236 switch (lp->operation) {
238 prt("\t\tCLOSE/OPEN\n");
241 prt("\t\tMS_INVALIDATE\n");
250 prt("%d(%d mod 256): ", opnum, opnum%256);
251 switch (lp->operation) {
253 prt("MAPREAD\t0x%x thru 0x%x\t(0x%x bytes)",
254 lp->args[0], lp->args[0] + lp->args[1] - 1,
256 if (badoff >= lp->args[0] && badoff <
257 lp->args[0] + lp->args[1])
261 prt("MAPWRITE 0x%x thru 0x%x\t(0x%x bytes)",
262 lp->args[0], lp->args[0] + lp->args[1] - 1,
264 if (badoff >= lp->args[0] && badoff <
265 lp->args[0] + lp->args[1])
269 prt("READ\t0x%x thru 0x%x\t(0x%x bytes)",
270 lp->args[0], lp->args[0] + lp->args[1] - 1,
272 if (badoff >= lp->args[0] &&
273 badoff < lp->args[0] + lp->args[1])
277 prt("WRITE\t0x%x thru 0x%x\t(0x%x bytes)",
278 lp->args[0], lp->args[0] + lp->args[1] - 1,
280 if (lp->args[0] > lp->args[2])
282 else if (lp->args[0] + lp->args[1] > lp->args[2])
284 if ((badoff >= lp->args[0] || badoff >=lp->args[2]) &&
285 badoff < lp->args[0] + lp->args[1])
289 down = lp->args[0] < lp->args[1];
290 prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
291 down ? "DOWN" : "UP", lp->args[1], lp->args[0]);
292 if (badoff >= lp->args[!down] &&
293 badoff < lp->args[!!down])
297 prt("SKIPPED (no operation)");
300 prt("BOGUS LOG ENTRY (operation code = %d)!",
313 save_buffer(char *buffer, off_t bufferlength, int fd)
316 ssize_t byteswritten;
318 if (fd <= 0 || bufferlength == 0)
321 if (bufferlength > SSIZE_MAX) {
322 prt("fsx flaw: overflow in save_buffer\n");
326 off_t size_by_seek = lseek(fd, (off_t)0, SEEK_END);
327 if (size_by_seek == (off_t)-1)
328 prterr("save_buffer: lseek eof");
329 else if (bufferlength > size_by_seek) {
330 warn("save_buffer: .fsxgood file too short... will save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek,
331 (unsigned long long)bufferlength);
332 bufferlength = size_by_seek;
336 ret = lseek(fd, (off_t)0, SEEK_SET);
337 if (ret == (off_t)-1)
338 prterr("save_buffer: lseek 0");
340 byteswritten = write(fd, buffer, (size_t)bufferlength);
341 if (byteswritten != bufferlength) {
342 if (byteswritten == -1)
343 prterr("save_buffer write");
345 warn("save_buffer: short write, 0x%x bytes instead of 0x%llx\n",
346 (unsigned)byteswritten,
347 (unsigned long long)bufferlength);
353 report_failure(int status)
359 save_buffer(good_buf, file_size, fsxgoodfd);
360 prt("Correct content saved for comparison\n");
361 prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n",
370 #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
371 *(((unsigned char *)(cp)) + 1)))
374 check_buffers(unsigned offset, unsigned size)
382 if (memcmp(good_buf + offset, temp_buf, size) != 0) {
383 prt("READ BAD DATA: offset = 0x%x, size = 0x%x\n",
385 prt("OFFSET\tGOOD\tBAD\tRANGE\n");
387 c = good_buf[offset];
391 bad = short_at(&temp_buf[i]);
392 prt("0x%5x\t0x%04x\t0x%04x", offset,
393 short_at(&good_buf[offset]), bad);
394 op = temp_buf[offset & 1 ? i+1 : i];
406 prt("operation# (mod 256) for the bad data may be %u\n", ((unsigned)op & 0xff));
408 prt("operation# (mod 256) for the bad data unknown, check HOLE and EXTEND ops\n");
410 prt("????????????????\n");
422 if (fstat(fd, &statbuf)) {
423 prterr("check_size: fstat");
424 statbuf.st_size = -1;
426 size_by_seek = lseek(fd, (off_t)0, SEEK_END);
427 if (file_size != statbuf.st_size || file_size != size_by_seek) {
428 prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
429 (unsigned long long)file_size,
430 (unsigned long long)statbuf.st_size,
431 (unsigned long long)size_by_seek);
438 check_trunc_hack(void)
442 ftruncate(fd, (off_t)0);
443 ftruncate(fd, (off_t)100000);
445 if (statbuf.st_size != (off_t)100000) {
446 prt("no extend on truncate! not posix!\n");
449 ftruncate(fd, (off_t)0);
454 doread(unsigned offset, unsigned size)
459 offset -= offset % readbdy;
461 if (!quiet && testcalls > simulatedopcount)
462 prt("skipping zero size read\n");
463 log4(OP_SKIPPED, OP_READ, offset, size);
466 if (size + offset > file_size) {
467 if (!quiet && testcalls > simulatedopcount)
468 prt("skipping seek/read past end of file\n");
469 log4(OP_SKIPPED, OP_READ, offset, size);
473 log4(OP_READ, offset, size, 0);
475 if (testcalls <= simulatedopcount)
478 if (!quiet && ((progressinterval &&
479 testcalls % progressinterval == 0) ||
481 (monitorstart == -1 ||
482 (offset + size > monitorstart &&
483 (monitorend == -1 || offset <= monitorend))))))
484 prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
485 offset, offset + size - 1, size);
486 ret = lseek(fd, (off_t)offset, SEEK_SET);
487 if (ret == (off_t)-1) {
488 prterr("doread: lseek");
491 iret = read(fd, temp_buf, size);
494 prterr("doread: read");
496 prt("short read: 0x%x bytes instead of 0x%x\n",
500 check_buffers(offset, size);
505 check_eofpage(char *s, unsigned offset, char *p, int size)
507 uintptr_t last_page, should_be_zero;
509 if (offset + size <= (file_size & ~page_mask))
512 * we landed in the last page of the file
513 * test to make sure the VM system provided 0's
514 * beyond the true end of the file mapping
515 * (as required by mmap def in 1996 posix 1003.1)
517 last_page = ((uintptr_t)p + (offset & page_mask) + size) & ~page_mask;
519 for (should_be_zero = last_page + (file_size & page_mask);
520 should_be_zero < last_page + page_size;
522 if (*(char *)should_be_zero) {
523 prt("Mapped %s: non-zero data past EOF (0x%llx) page offset 0x%x is 0x%04x\n",
524 s, file_size - 1, should_be_zero & page_mask,
525 short_at(should_be_zero));
532 domapread(unsigned offset, unsigned size)
538 offset -= offset % readbdy;
540 if (!quiet && testcalls > simulatedopcount)
541 prt("skipping zero size read\n");
542 log4(OP_SKIPPED, OP_MAPREAD, offset, size);
545 if (size + offset > file_size) {
546 if (!quiet && testcalls > simulatedopcount)
547 prt("skipping seek/read past end of file\n");
548 log4(OP_SKIPPED, OP_MAPREAD, offset, size);
552 log4(OP_MAPREAD, offset, size, 0);
554 if (testcalls <= simulatedopcount)
557 if (!quiet && ((progressinterval &&
558 testcalls % progressinterval == 0) ||
560 (monitorstart == -1 ||
561 (offset + size > monitorstart &&
562 (monitorend == -1 || offset <= monitorend))))))
563 prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
564 offset, offset + size - 1, size);
566 pg_offset = offset & page_mask;
567 map_size = pg_offset + size;
569 if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_FILE | MAP_SHARED, fd,
570 (off_t)(offset - pg_offset))) == (char *)-1) {
571 prterr("domapread: mmap");
574 memcpy(temp_buf, p + pg_offset, size);
576 check_eofpage("Read", offset, p, size);
578 if (munmap(p, map_size) != 0) {
579 prterr("domapread: munmap");
583 check_buffers(offset, size);
588 gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size)
591 good_buf[offset] = testcalls % 256;
593 good_buf[offset] += original_buf[offset];
600 dowrite(unsigned offset, unsigned size)
605 offset -= offset % writebdy;
607 if (!quiet && testcalls > simulatedopcount)
608 prt("skipping zero size write\n");
609 log4(OP_SKIPPED, OP_WRITE, offset, size);
613 log4(OP_WRITE, offset, size, file_size);
615 gendata(original_buf, good_buf, offset, size);
616 if (file_size < offset + size) {
617 if (file_size < offset)
618 memset(good_buf + file_size, '\0', offset - file_size);
619 file_size = offset + size;
621 warn("Lite file size bug in fsx!");
626 if (testcalls <= simulatedopcount)
629 if (!quiet && ((progressinterval &&
630 testcalls % progressinterval == 0) ||
632 (monitorstart == -1 ||
633 (offset + size > monitorstart &&
634 (monitorend == -1 || offset <= monitorend))))))
635 prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
636 offset, offset + size - 1, size);
637 ret = lseek(fd, (off_t)offset, SEEK_SET);
638 if (ret == (off_t)-1) {
639 prterr("dowrite: lseek");
642 iret = write(fd, good_buf + offset, size);
645 prterr("dowrite: write");
647 prt("short write: 0x%x bytes instead of 0x%x\n",
655 domapwrite(unsigned offset, unsigned size)
662 offset -= offset % writebdy;
664 if (!quiet && testcalls > simulatedopcount)
665 prt("skipping zero size write\n");
666 log4(OP_SKIPPED, OP_MAPWRITE, offset, size);
669 cur_filesize = file_size;
671 log4(OP_MAPWRITE, offset, size, 0);
673 gendata(original_buf, good_buf, offset, size);
674 if (file_size < offset + size) {
675 if (file_size < offset)
676 memset(good_buf + file_size, '\0', offset - file_size);
677 file_size = offset + size;
679 warn("Lite file size bug in fsx!");
684 if (testcalls <= simulatedopcount)
687 if (!quiet && ((progressinterval &&
688 testcalls % progressinterval == 0) ||
690 (monitorstart == -1 ||
691 (offset + size > monitorstart &&
692 (monitorend == -1 || offset <= monitorend))))))
693 prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
694 offset, offset + size - 1, size);
696 if (file_size > cur_filesize) {
697 if (ftruncate(fd, file_size) == -1) {
698 prterr("domapwrite: ftruncate");
702 pg_offset = offset & page_mask;
703 map_size = pg_offset + size;
705 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
706 MAP_FILE | MAP_SHARED, fd,
707 (off_t)(offset - pg_offset))) == MAP_FAILED) {
708 prterr("domapwrite: mmap");
711 memcpy(p + pg_offset, good_buf + offset, size);
712 if (mapped_msync && msync(p, map_size, MS_SYNC) != 0) {
713 prterr("domapwrite: msync");
717 check_eofpage("Write", offset, p, size);
719 if (munmap(p, map_size) != 0) {
720 prterr("domapwrite: munmap");
727 dotruncate(unsigned size)
729 int oldsize = file_size;
731 size -= size % truncbdy;
732 if (size > biggest) {
734 if (!quiet && testcalls > simulatedopcount)
735 prt("truncating to largest ever: 0x%x\n", size);
738 log4(OP_TRUNCATE, size, (unsigned)file_size, 0);
740 if (size > file_size)
741 memset(good_buf + file_size, '\0', size - file_size);
744 if (testcalls <= simulatedopcount)
747 if ((progressinterval && testcalls % progressinterval == 0) ||
748 (debug && (monitorstart == -1 || monitorend == -1 ||
749 size <= monitorend)))
750 prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls, oldsize, size);
751 if (ftruncate(fd, (off_t)size) == -1) {
752 prt("ftruncate1: %x\n", size);
753 prterr("dotruncate: ftruncate");
764 if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
765 prterr("writefileimage: lseek");
768 iret = write(fd, good_buf, file_size);
769 if ((off_t)iret != file_size) {
771 prterr("writefileimage: write");
773 prt("short write: 0x%x bytes instead of 0x%llx\n",
774 iret, (unsigned long long)file_size);
777 if (lite ? 0 : ftruncate(fd, file_size) == -1) {
778 prt("ftruncate2: %llx\n", (unsigned long long)file_size);
779 prterr("writefileimage: ftruncate");
788 if (testcalls <= simulatedopcount)
792 prt("%lu close/open\n", testcalls);
794 prterr("docloseopen: close");
797 fd = open(fname, O_RDWR, 0);
799 prterr("docloseopen: open");
812 if (testcalls <= simulatedopcount)
815 prt("%lu msync(MS_INVALIDATE)\n", testcalls);
817 if ((p = (char *)mmap(0, file_size, PROT_READ | PROT_WRITE,
818 MAP_FILE | MAP_SHARED, fd, 0)) == MAP_FAILED) {
819 prterr("doinvl: mmap");
823 if (msync(p, 0, MS_SYNC | MS_INVALIDATE) != 0) {
824 prterr("doinvl: msync");
828 if (munmap(p, file_size) != 0) {
829 prterr("doinvl: munmap");
838 unsigned long offset;
839 unsigned long size = maxoplen;
840 unsigned long rv = random();
841 unsigned long op = rv % (3 + !lite + mapped_writes);
843 /* turn off the map read if necessary */
845 if (op == 2 && !mapped_reads)
848 if (simulatedopcount > 0 && testcalls == simulatedopcount)
854 closeopen = (rv >> 3) < (1 << 28) / closeprob;
856 invl = (rv >> 3) < (1 << 28) / invlprob;
858 if (debugstart > 0 && testcalls >= debugstart)
861 if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
862 prt("%lu...\n", testcalls);
869 * MAPWRITE: op = 3 or 4
871 if (lite ? 0 : op == 3 && style == 0) /* vanilla truncate? */
872 dotruncate(random() % maxfilelen);
875 size = random() % (maxoplen+1);
876 if (lite ? 0 : op == 3)
880 if (op == 1 || op == (lite ? 3 : 4)) {
881 offset %= maxfilelen;
882 if (offset + size > maxfilelen)
883 size = maxfilelen - offset;
885 domapwrite(offset, size);
887 dowrite(offset, size);
893 if (offset + size > file_size)
894 size = file_size - offset;
896 domapread(offset, size);
898 doread(offset, size);
902 if (sizechecks && testcalls > simulatedopcount)
916 prt("signal %d\n", sig);
917 prt("testcalls = %lu\n", testcalls);
925 fprintf(stdout, "usage: %s",
926 "fsx [-dnqLOW] [-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\
927 -b opnum: beginning operation number (default 1)\n\
928 -c P: 1 in P chance of file close+open at each op (default infinity)\n\
929 -d: debug output for all operations\n\
930 -i P: 1 in P chance of calling msync(MS_INVALIDATE) (default infinity)\n\
931 -l flen: the upper bound on file size (default 262144)\n\
932 -m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\
933 -n: no verifications of file size\n\
934 -o oplen: the upper bound on operation size (default 65536)\n\
935 -p progressinterval: debug output at specified operation interval\n\
936 -q: quieter operation\n\
937 -r readbdy: 4096 would make reads page aligned (default 1)\n\
938 -s style: 1 gives smaller truncates (default 0)\n\
939 -t truncbdy: 4096 would make truncates page aligned (default 1)\n\
940 -w writebdy: 4096 would make writes page aligned (default 1)\n\
941 -D startingop: debug output starting at specified operation\n\
942 -L: fsxLite - no file creations & no file size changes\n\
943 -N numops: total # operations to do (default infinity)\n\
944 -O: use oplen (see -o flag) for every op (default random)\n\
945 -P dirpath: save .fsxlog and .fsxgood files in dirpath (default ./)\n\
946 -S seed: for random # generator (default 1) 0 gets timestamp\n\
947 -W: mapped write operations DISabled\n\
948 -R: mapped read operations DISabled)\n\
949 -U: msync after mapped write operations DISabled\n\
950 fname: this filename is REQUIRED (no default)\n");
956 getnum(char *s, char **e)
961 ret = strtol(s, e, 0);
990 main(int argc, char **argv)
1000 page_size = getpagesize();
1001 page_mask = page_size - 1;
1003 setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
1005 while ((ch = getopt(argc, argv,
1006 "b:c:di:l:m:no:p:qr:s:t:w:D:LN:OP:RS:UW")) != -1)
1009 simulatedopcount = getnum(optarg, &endp);
1011 fprintf(stdout, "Will begin at operation %ld\n",
1013 if (simulatedopcount == 0)
1015 simulatedopcount -= 1;
1018 closeprob = getnum(optarg, &endp);
1021 "Chance of close/open is 1 in %d\n",
1030 invlprob = getnum(optarg, &endp);
1033 "Chance of MS_INVALIDATE is 1 in %d\n",
1039 maxfilelen = getnum(optarg, &endp);
1040 if (maxfilelen <= 0)
1044 monitorstart = getnum(optarg, &endp);
1045 if (monitorstart < 0)
1047 if (!endp || *endp++ != ':')
1049 monitorend = getnum(endp, &endp);
1052 if (monitorend == 0)
1053 monitorend = -1; /* aka infinity */
1059 maxoplen = getnum(optarg, &endp);
1064 progressinterval = getnum(optarg, &endp);
1065 if (progressinterval < 0)
1072 readbdy = getnum(optarg, &endp);
1077 style = getnum(optarg, &endp);
1078 if (style < 0 || style > 1)
1082 truncbdy = getnum(optarg, &endp);
1087 writebdy = getnum(optarg, &endp);
1092 debugstart = getnum(optarg, &endp);
1100 numops = getnum(optarg, &endp);
1108 strncpy(goodfile, optarg, sizeof(goodfile));
1109 strcat(goodfile, "/");
1110 strncpy(logfile, optarg, sizeof(logfile));
1111 strcat(logfile, "/");
1117 seed = getnum(optarg, &endp);
1119 seed = time(0) % 10000;
1121 fprintf(stdout, "Seed set to %d\n", seed);
1128 fprintf(stdout, "mapped writes DISABLED\n");
1133 fprintf(stdout, "mapped msync DISABLED\n");
1146 signal(SIGHUP, cleanup);
1147 signal(SIGINT, cleanup);
1148 signal(SIGPIPE, cleanup);
1149 signal(SIGALRM, cleanup);
1150 signal(SIGTERM, cleanup);
1151 signal(SIGXCPU, cleanup);
1152 signal(SIGXFSZ, cleanup);
1153 signal(SIGVTALRM, cleanup);
1154 signal(SIGUSR1, cleanup);
1155 signal(SIGUSR2, cleanup);
1157 initstate(seed, state, 256);
1159 fd = open(fname, O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC), 0666);
1164 strncat(goodfile, fname, 256);
1165 strcat (goodfile, ".fsxgood");
1166 fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
1167 if (fsxgoodfd < 0) {
1171 strncat(logfile, fname, 256);
1172 strcat (logfile, ".fsxlog");
1173 fsxlogf = fopen(logfile, "w");
1174 if (fsxlogf == NULL) {
1180 file_size = maxfilelen = lseek(fd, (off_t)0, SEEK_END);
1181 if (file_size == (off_t)-1) {
1183 warn("main: lseek eof");
1186 ret = lseek(fd, (off_t)0, SEEK_SET);
1187 if (ret == (off_t)-1) {
1189 warn("main: lseek 0");
1193 original_buf = (char *) malloc(maxfilelen);
1194 for (i = 0; i < maxfilelen; i++)
1195 original_buf[i] = random() % 256;
1196 good_buf = (char *) malloc(maxfilelen);
1197 memset(good_buf, '\0', maxfilelen);
1198 temp_buf = (char *) malloc(maxoplen);
1199 memset(temp_buf, '\0', maxoplen);
1200 if (lite) { /* zero entire existing file */
1203 written = write(fd, good_buf, (size_t)maxfilelen);
1204 if (written != maxfilelen) {
1205 if (written == -1) {
1207 warn("main: error on write");
1209 warn("main: short write, 0x%x bytes instead of 0x%x\n",
1210 (unsigned)written, maxfilelen);
1216 while (numops == -1 || numops--)
1223 prt("All operations completed A-OK!\n");