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>
66 #define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */
69 * A log entry is an operation and a bunch of arguments.
79 struct log_entry oplog[LOGSIZE]; /* the log */
80 int logptr = 0; /* current position in log */
81 int logcount = 0; /* total ops */
90 #define OP_CLOSEOPEN 4
94 #define OP_INVALIDATE 8
99 char *original_buf; /* a pointer to the original data */
100 char *good_buf; /* a pointer to the correct data */
101 char *temp_buf; /* a pointer to the current data */
102 char *fname; /* name of our test file */
103 int fd; /* fd for our test file */
108 unsigned long testcalls = 0; /* calls to function "test" */
110 unsigned long simulatedopcount = 0; /* -b flag */
111 int closeprob = 0; /* -c flag */
112 int invlprob = 0; /* -i flag */
113 int debug = 0; /* -d flag */
114 unsigned long debugstart = 0; /* -D flag */
115 off_t maxfilelen = 256 * 1024; /* -l flag */
116 int sizechecks = 1; /* -n flag disables them */
117 int maxoplen = 64 * 1024; /* -o flag */
118 int quiet = 0; /* -q flag */
119 unsigned long progressinterval = 0; /* -p flag */
120 int readbdy = 1; /* -r flag */
121 int style = 0; /* -s flag */
122 int truncbdy = 1; /* -t flag */
123 int writebdy = 1; /* -w flag */
124 long monitorstart = -1; /* -m flag */
125 long monitorend = -1; /* -m flag */
126 int lite = 0; /* -L flag */
127 long numops = -1; /* -N flag */
128 int randomoplen = 1; /* -O flag disables it */
129 int seed = 1; /* -S flag */
130 int mapped_writes = 1; /* -W flag disables */
131 int mapped_reads = 1; /* -R flag disables it */
132 int mapped_msync = 1; /* -U flag disables */
134 FILE * fsxlogf = NULL;
141 prt(const char *fmt, ...)
146 vfprintf(stdout, fmt, args);
151 vfprintf(fsxlogf, fmt, args);
157 prterr(const char *prefix)
159 prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno));
164 do_log4(int operation, int arg0, int arg1, int arg2)
166 struct log_entry *le;
169 le->operation = operation;
175 if (logptr >= LOGSIZE)
181 log4(int operation, int arg0, int arg1, int arg2)
183 do_log4(operation, arg0, arg1, arg2);
185 do_log4(OP_CLOSEOPEN, 0, 0, 0);
187 do_log4(OP_INVALIDATE, 0, 0, 0);
194 struct log_entry *lp;
195 int i, count, down, opnum;
197 prt("LOG DUMP (%d total operations):\n", logcount);
198 if (logcount < LOGSIZE) {
206 opnum = i + 1 + (logcount/LOGSIZE)*LOGSIZE;
207 for ( ; count > 0; count--) {
210 if (lp->operation == OP_CLOSEOPEN ||
211 lp->operation == OP_INVALIDATE) {
212 switch (lp->operation) {
214 prt("\t\tCLOSE/OPEN\n");
217 prt("\t\tMS_INVALIDATE\n");
226 prt("%d(%d mod 256): ", opnum, opnum%256);
227 switch (lp->operation) {
229 prt("MAPREAD\t0x%x thru 0x%x\t(0x%x bytes)",
230 lp->args[0], lp->args[0] + lp->args[1] - 1,
232 if (badoff >= lp->args[0] && badoff <
233 lp->args[0] + lp->args[1])
237 prt("MAPWRITE 0x%x thru 0x%x\t(0x%x bytes)",
238 lp->args[0], lp->args[0] + lp->args[1] - 1,
240 if (badoff >= lp->args[0] && badoff <
241 lp->args[0] + lp->args[1])
245 prt("READ\t0x%x thru 0x%x\t(0x%x bytes)",
246 lp->args[0], lp->args[0] + lp->args[1] - 1,
248 if (badoff >= lp->args[0] &&
249 badoff < lp->args[0] + lp->args[1])
254 int offset = lp->args[0];
255 int len = lp->args[1];
256 int oldlen = lp->args[2];
258 prt("WRITE\t0x%x thru 0x%x\t(0x%x bytes)",
259 offset, offset + len - 1,
263 else if (offset + len > oldlen)
265 if ((badoff >= offset || badoff >=oldlen) &&
266 badoff < offset + len)
271 down = lp->args[0] < lp->args[1];
272 prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
273 down ? "DOWN" : "UP", lp->args[1], lp->args[0]);
274 if (badoff >= lp->args[!down] &&
275 badoff < lp->args[!!down])
279 prt("SKIPPED (no operation)");
282 prt("BOGUS LOG ENTRY (operation code = %d)!",
295 save_buffer(char *buffer, off_t bufferlength, int savefd)
298 ssize_t byteswritten;
300 if (savefd <= 0 || bufferlength == 0)
303 if (bufferlength > SSIZE_MAX) {
304 prt("fsx flaw: overflow in save_buffer\n");
308 off_t size_by_seek = lseek(savefd, (off_t)0, SEEK_END);
309 if (size_by_seek == (off_t)-1)
310 prterr("save_buffer: lseek eof");
311 else if (bufferlength > size_by_seek) {
312 warn("save_buffer: .fsxgood file too short... will save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek,
313 (unsigned long long)bufferlength);
314 bufferlength = size_by_seek;
318 ret = lseek(savefd, (off_t)0, SEEK_SET);
319 if (ret == (off_t)-1)
320 prterr("save_buffer: lseek 0");
322 byteswritten = write(savefd, buffer, (size_t)bufferlength);
323 if (byteswritten != bufferlength) {
324 if (byteswritten == -1)
325 prterr("save_buffer write");
327 warn("save_buffer: short write, 0x%x bytes instead of 0x%llx\n",
328 (unsigned)byteswritten,
329 (unsigned long long)bufferlength);
335 report_failure(int status)
341 save_buffer(good_buf, file_size, fsxgoodfd);
342 prt("Correct content saved for comparison\n");
343 prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n",
352 #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
353 *(((unsigned char *)(cp)) + 1)))
356 check_buffers(unsigned offset, unsigned size)
364 if (memcmp(good_buf + offset, temp_buf, size) != 0) {
365 prt("READ BAD DATA: offset = 0x%x, size = 0x%x\n",
367 prt("OFFSET\tGOOD\tBAD\tRANGE\n");
369 c = good_buf[offset];
373 bad = short_at(&temp_buf[i]);
374 prt("0x%5x\t0x%04x\t0x%04x", offset,
375 short_at(&good_buf[offset]), bad);
376 op = temp_buf[offset & 1 ? i+1 : i];
388 prt("operation# (mod 256) for the bad data may be %u\n", ((unsigned)op & 0xff));
390 prt("operation# (mod 256) for the bad data unknown, check HOLE and EXTEND ops\n");
392 prt("????????????????\n");
404 if (fstat(fd, &statbuf)) {
405 prterr("check_size: fstat");
406 statbuf.st_size = -1;
408 size_by_seek = lseek(fd, (off_t)0, SEEK_END);
409 if (file_size != statbuf.st_size || file_size != size_by_seek) {
410 prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
411 (unsigned long long)file_size,
412 (unsigned long long)statbuf.st_size,
413 (unsigned long long)size_by_seek);
420 check_trunc_hack(void)
424 ftruncate(fd, (off_t)0);
425 ftruncate(fd, (off_t)100000);
427 if (statbuf.st_size != (off_t)100000) {
428 prt("no extend on truncate! not posix!\n");
431 ftruncate(fd, (off_t)0);
436 doread(off_t offset, off_t size)
441 offset -= offset % readbdy;
443 if (!quiet && testcalls > simulatedopcount)
444 prt("skipping zero size read\n");
445 log4(OP_SKIPPED, OP_READ, offset, size);
448 if (size + offset > file_size) {
449 if (!quiet && testcalls > simulatedopcount)
450 prt("skipping seek/read past end of file\n");
451 log4(OP_SKIPPED, OP_READ, offset, size);
455 log4(OP_READ, offset, size, 0);
457 if (testcalls <= simulatedopcount)
460 if (!quiet && ((progressinterval &&
461 testcalls % progressinterval == 0) ||
463 (monitorstart == -1 ||
464 (offset + size > monitorstart &&
465 (monitorend == -1 || offset <= monitorend))))))
466 prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
467 offset, offset + size - 1, size);
468 ret = lseek(fd, (off_t)offset, SEEK_SET);
469 if (ret == (off_t)-1) {
470 prterr("doread: lseek");
473 iret = read(fd, temp_buf, size);
476 prterr("doread: read");
478 prt("short read: 0x%x bytes instead of 0x%x\n",
482 check_buffers(offset, size);
487 check_eofpage(const char *s, unsigned offset, char *p, int size)
489 uintptr_t last_page, should_be_zero;
491 if (offset + size <= (file_size & ~page_mask))
494 * we landed in the last page of the file
495 * test to make sure the VM system provided 0's
496 * beyond the true end of the file mapping
497 * (as required by mmap def in 1996 posix 1003.1)
499 last_page = ((uintptr_t)p + (offset & page_mask) + size) & ~page_mask;
501 for (should_be_zero = last_page + (file_size & page_mask);
502 should_be_zero < last_page + page_size;
504 if (*(char *)should_be_zero) {
505 prt("Mapped %s: non-zero data past EOF (0x%llx) page offset 0x%x is 0x%04x\n",
506 s, file_size - 1, should_be_zero & page_mask,
507 short_at(should_be_zero));
514 domapread(unsigned offset, unsigned size)
520 offset -= offset % readbdy;
522 if (!quiet && testcalls > simulatedopcount)
523 prt("skipping zero size read\n");
524 log4(OP_SKIPPED, OP_MAPREAD, offset, size);
527 if (size + offset > file_size) {
528 if (!quiet && testcalls > simulatedopcount)
529 prt("skipping seek/read past end of file\n");
530 log4(OP_SKIPPED, OP_MAPREAD, offset, size);
534 log4(OP_MAPREAD, offset, size, 0);
536 if (testcalls <= simulatedopcount)
539 if (!quiet && ((progressinterval &&
540 testcalls % progressinterval == 0) ||
542 (monitorstart == -1 ||
543 (offset + size > monitorstart &&
544 (monitorend == -1 || offset <= monitorend))))))
545 prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
546 offset, offset + size - 1, size);
548 pg_offset = offset & page_mask;
549 map_size = pg_offset + size;
551 if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_FILE | MAP_SHARED, fd,
552 (off_t)(offset - pg_offset))) == (char *)-1) {
553 prterr("domapread: mmap");
556 memcpy(temp_buf, p + pg_offset, size);
558 check_eofpage("Read", offset, p, size);
560 if (munmap(p, map_size) != 0) {
561 prterr("domapread: munmap");
565 check_buffers(offset, size);
570 gendata(unsigned offset, unsigned size)
573 good_buf[offset] = testcalls % 256;
575 good_buf[offset] += original_buf[offset];
582 dowrite(unsigned offset, unsigned size)
587 offset -= offset % writebdy;
589 if (!quiet && testcalls > simulatedopcount)
590 prt("skipping zero size write\n");
591 log4(OP_SKIPPED, OP_WRITE, offset, size);
595 log4(OP_WRITE, offset, size, file_size);
597 gendata(offset, size);
598 if (file_size < offset + size) {
599 if (file_size < offset)
600 memset(good_buf + file_size, '\0', offset - file_size);
601 file_size = offset + size;
603 warn("Lite file size bug in fsx!");
608 if (testcalls <= simulatedopcount)
611 if (!quiet && ((progressinterval &&
612 testcalls % progressinterval == 0) ||
614 (monitorstart == -1 ||
615 (offset + size > monitorstart &&
616 (monitorend == -1 || offset <= monitorend))))))
617 prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
618 offset, offset + size - 1, size);
619 ret = lseek(fd, (off_t)offset, SEEK_SET);
620 if (ret == (off_t)-1) {
621 prterr("dowrite: lseek");
624 iret = write(fd, good_buf + offset, size);
627 prterr("dowrite: write");
629 prt("short write: 0x%x bytes instead of 0x%x\n",
637 domapwrite(unsigned offset, unsigned size)
644 offset -= offset % writebdy;
646 if (!quiet && testcalls > simulatedopcount)
647 prt("skipping zero size write\n");
648 log4(OP_SKIPPED, OP_MAPWRITE, offset, size);
651 cur_filesize = file_size;
653 log4(OP_MAPWRITE, offset, size, 0);
655 gendata(offset, size);
656 if (file_size < offset + size) {
657 if (file_size < offset)
658 memset(good_buf + file_size, '\0', offset - file_size);
659 file_size = offset + size;
661 warn("Lite file size bug in fsx!");
666 if (testcalls <= simulatedopcount)
669 if (!quiet && ((progressinterval &&
670 testcalls % progressinterval == 0) ||
672 (monitorstart == -1 ||
673 (offset + size > monitorstart &&
674 (monitorend == -1 || offset <= monitorend))))))
675 prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
676 offset, offset + size - 1, size);
678 if (file_size > cur_filesize) {
679 if (ftruncate(fd, file_size) == -1) {
680 prterr("domapwrite: ftruncate");
684 pg_offset = offset & page_mask;
685 map_size = pg_offset + size;
687 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
688 MAP_FILE | MAP_SHARED, fd,
689 (off_t)(offset - pg_offset))) == MAP_FAILED) {
690 prterr("domapwrite: mmap");
693 memcpy(p + pg_offset, good_buf + offset, size);
694 if (mapped_msync && msync(p, map_size, MS_SYNC) != 0) {
695 prterr("domapwrite: msync");
699 check_eofpage("Write", offset, p, size);
701 if (munmap(p, map_size) != 0) {
702 prterr("domapwrite: munmap");
709 dotruncate(unsigned size)
711 int oldsize = file_size;
713 size -= size % truncbdy;
714 if (size > biggest) {
716 if (!quiet && testcalls > simulatedopcount)
717 prt("truncating to largest ever: 0x%x\n", size);
720 log4(OP_TRUNCATE, size, (unsigned)file_size, 0);
722 if (size > file_size)
723 memset(good_buf + file_size, '\0', size - file_size);
726 if (testcalls <= simulatedopcount)
729 if ((progressinterval && testcalls % progressinterval == 0) ||
730 (debug && (monitorstart == -1 || monitorend == -1 ||
731 size <= monitorend)))
732 prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls, oldsize, size);
733 if (ftruncate(fd, (off_t)size) == -1) {
734 prt("ftruncate1: %x\n", size);
735 prterr("dotruncate: ftruncate");
746 if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
747 prterr("writefileimage: lseek");
750 iret = write(fd, good_buf, file_size);
751 if ((off_t)iret != file_size) {
753 prterr("writefileimage: write");
755 prt("short write: 0x%x bytes instead of 0x%llx\n",
756 iret, (unsigned long long)file_size);
759 if (lite ? 0 : ftruncate(fd, file_size) == -1) {
760 prt("ftruncate2: %llx\n", (unsigned long long)file_size);
761 prterr("writefileimage: ftruncate");
770 if (testcalls <= simulatedopcount)
774 prt("%lu close/open\n", testcalls);
776 prterr("docloseopen: close");
779 fd = open(fname, O_RDWR, 0);
781 prterr("docloseopen: open");
794 if (testcalls <= simulatedopcount)
797 prt("%lu msync(MS_INVALIDATE)\n", testcalls);
799 if ((p = (char *)mmap(0, file_size, PROT_READ | PROT_WRITE,
800 MAP_FILE | MAP_SHARED, fd, 0)) == MAP_FAILED) {
801 prterr("doinvl: mmap");
805 if (msync(p, 0, MS_SYNC | MS_INVALIDATE) != 0) {
806 prterr("doinvl: msync");
810 if (munmap(p, file_size) != 0) {
811 prterr("doinvl: munmap");
821 off_t size = maxoplen;
822 unsigned long rv = random();
823 unsigned long op = rv % (3 + !lite + mapped_writes);
825 /* turn off the map read if necessary */
827 if (op == 2 && !mapped_reads)
830 if (simulatedopcount > 0 && testcalls == simulatedopcount)
836 closeopen = (rv >> 3) < (1ul << 28) / closeprob;
838 invl = (rv >> 3) < (1ul << 28) / invlprob;
840 if (debugstart > 0 && testcalls >= debugstart)
843 if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
844 prt("%lu...\n", testcalls);
851 * MAPWRITE: op = 3 or 4
853 if (lite ? 0 : op == 3 && style == 0) /* vanilla truncate? */
854 dotruncate(random() % maxfilelen);
857 size = random() % (maxoplen+1);
858 if (lite ? 0 : op == 3)
862 if (op == 1 || op == (lite ? 3 : 4)) {
863 offset %= maxfilelen;
864 if (offset + size > maxfilelen)
865 size = maxfilelen - offset;
867 domapwrite(offset, size);
869 dowrite(offset, size);
875 if (offset + size > file_size)
876 size = file_size - offset;
878 domapread(offset, size);
880 doread(offset, size);
884 if (sizechecks && testcalls > simulatedopcount)
898 prt("signal %d\n", sig);
899 prt("testcalls = %lu\n", testcalls);
907 fprintf(stdout, "usage: %s",
908 "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\
909 -b opnum: beginning operation number (default 1)\n\
910 -c P: 1 in P chance of file close+open at each op (default infinity)\n\
911 -d: debug output for all operations\n\
912 -i P: 1 in P chance of calling msync(MS_INVALIDATE) (default infinity)\n\
913 -l flen: the upper bound on file size (default 262144)\n\
914 -m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\
915 -n: no verifications of file size\n\
916 -o oplen: the upper bound on operation size (default 65536)\n\
917 -p progressinterval: debug output at specified operation interval\n\
918 -q: quieter operation\n\
919 -r readbdy: 4096 would make reads page aligned (default 1)\n\
920 -s style: 1 gives smaller truncates (default 0)\n\
921 -t truncbdy: 4096 would make truncates page aligned (default 1)\n\
922 -w writebdy: 4096 would make writes page aligned (default 1)\n\
923 -D startingop: debug output starting at specified operation\n\
924 -L: fsxLite - no file creations & no file size changes\n\
925 -N numops: total # operations to do (default infinity)\n\
926 -O: use oplen (see -o flag) for every op (default random)\n\
927 -P dirpath: save .fsxlog and .fsxgood files in dirpath (default ./)\n\
928 -S seed: for random # generator (default 1) 0 gets timestamp\n\
929 -W: mapped write operations DISabled\n\
930 -R: mapped read operations DISabled)\n\
931 -U: msync after mapped write operations DISabled\n\
932 fname: this filename is REQUIRED (no default)\n");
938 getnum(char *s, char **e)
943 ret = strtol(s, e, 0);
972 main(int argc, char **argv)
983 page_size = getpagesize();
984 page_mask = page_size - 1;
986 setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
988 while ((ch = getopt(argc, argv,
989 "b:c:di:l:m:no:p:qr:s:t:w:D:LN:OP:RS:UW")) != -1)
992 simulatedopcount = getnum(optarg, &endp);
994 fprintf(stdout, "Will begin at operation %ld\n",
996 if (simulatedopcount == 0)
998 simulatedopcount -= 1;
1001 closeprob = getnum(optarg, &endp);
1004 "Chance of close/open is 1 in %d\n",
1013 invlprob = getnum(optarg, &endp);
1016 "Chance of MS_INVALIDATE is 1 in %d\n",
1022 maxfilelen = getnum(optarg, &endp);
1023 if (maxfilelen <= 0)
1027 monitorstart = getnum(optarg, &endp);
1028 if (monitorstart < 0)
1030 if (!endp || *endp++ != ':')
1032 monitorend = getnum(endp, &endp);
1035 if (monitorend == 0)
1036 monitorend = -1; /* aka infinity */
1042 maxoplen = getnum(optarg, &endp);
1047 progressinterval = getnum(optarg, &endp);
1048 if (progressinterval < 0)
1055 readbdy = getnum(optarg, &endp);
1060 style = getnum(optarg, &endp);
1061 if (style < 0 || style > 1)
1065 truncbdy = getnum(optarg, &endp);
1070 writebdy = getnum(optarg, &endp);
1075 debugstart = getnum(optarg, &endp);
1083 numops = getnum(optarg, &endp);
1091 strncpy(goodfile, optarg, sizeof(goodfile));
1092 strcat(goodfile, "/");
1093 strncpy(logfile, optarg, sizeof(logfile));
1094 strcat(logfile, "/");
1100 seed = getnum(optarg, &endp);
1102 if (clock_gettime(CLOCK_REALTIME, &now) != 0)
1103 err(1, "clock_gettime");
1104 seed = now.tv_nsec % 10000;
1107 fprintf(stdout, "Seed set to %d\n", seed);
1114 fprintf(stdout, "mapped writes DISABLED\n");
1119 fprintf(stdout, "mapped msync DISABLED\n");
1132 signal(SIGHUP, cleanup);
1133 signal(SIGINT, cleanup);
1134 signal(SIGPIPE, cleanup);
1135 signal(SIGALRM, cleanup);
1136 signal(SIGTERM, cleanup);
1137 signal(SIGXCPU, cleanup);
1138 signal(SIGXFSZ, cleanup);
1139 signal(SIGVTALRM, cleanup);
1140 signal(SIGUSR1, cleanup);
1141 signal(SIGUSR2, cleanup);
1143 initstate(seed, state, 256);
1145 fd = open(fname, O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC), 0666);
1150 strncat(goodfile, fname, 256);
1151 strcat (goodfile, ".fsxgood");
1152 fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
1153 if (fsxgoodfd < 0) {
1157 strncat(logfile, fname, 256);
1158 strcat (logfile, ".fsxlog");
1159 fsxlogf = fopen(logfile, "w");
1160 if (fsxlogf == NULL) {
1166 file_size = maxfilelen = lseek(fd, (off_t)0, SEEK_END);
1167 if (file_size == (off_t)-1) {
1169 warn("main: lseek eof");
1172 ret = lseek(fd, (off_t)0, SEEK_SET);
1173 if (ret == (off_t)-1) {
1175 warn("main: lseek 0");
1179 original_buf = (char *) malloc(maxfilelen);
1180 for (i = 0; i < maxfilelen; i++)
1181 original_buf[i] = random() % 256;
1182 good_buf = (char *) malloc(maxfilelen);
1183 memset(good_buf, '\0', maxfilelen);
1184 temp_buf = (char *) malloc(maxoplen);
1185 memset(temp_buf, '\0', maxoplen);
1186 if (lite) { /* zero entire existing file */
1189 written = write(fd, good_buf, (size_t)maxfilelen);
1190 if (written != maxfilelen) {
1191 if (written == -1) {
1193 warn("main: error on write");
1195 warn("main: short write, 0x%x bytes instead of 0x%lx\n",
1196 (unsigned)written, maxfilelen);
1202 while (numops == -1 || numops--)
1209 prt("All operations completed A-OK!\n");