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 1.1 (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.apple.com/publicsource 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
34 * $FreeBSD: src/tools/regression/fsx/fsx.c,v 1.1 2001/12/20 04:15:57 jkh Exp $
37 #include <sys/types.h>
39 #if defined(_UWIN) || defined(__linux__)
40 # include <sys/param.h>
44 # include <sys/time.h>
60 #define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */
63 * A log entry is an operation and a bunch of arguments.
74 struct log_entry oplog[LOGSIZE]; /* the log */
75 int logptr = 0; /* current position in log */
76 int logcount = 0; /* total ops */
85 #define OP_CLOSEOPEN 4
93 char *original_buf; /* a pointer to the original data */
94 char *good_buf; /* a pointer to the correct data */
95 char *temp_buf; /* a pointer to the current data */
96 char *fname; /* name of our test file */
97 char logfile[1024]; /* name of our log file */
98 char goodfile[1024]; /* name of our test file */
99 int fd; /* fd for our test file */
104 unsigned long testcalls = 0; /* calls to function "test" */
106 unsigned long simulatedopcount = 0; /* -b flag */
107 int closeprob = 0; /* -c flag */
108 int debug = 0; /* -d flag */
109 unsigned long debugstart = 0; /* -D flag */
110 unsigned long maxfilelen = 256 * 1024; /* -l flag */
111 int sizechecks = 1; /* -n flag disables them */
112 int maxoplen = 64 * 1024; /* -o flag */
113 int quiet = 0; /* -q flag */
114 unsigned long progressinterval = 0; /* -p flag */
115 int readbdy = 1; /* -r flag */
116 int style = 0; /* -s flag */
117 int truncbdy = 1; /* -t flag */
118 int writebdy = 1; /* -w flag */
119 long monitorstart = -1; /* -m flag */
120 long monitorend = -1; /* -m flag */
121 int lite = 0; /* -L flag */
122 long numops = -1; /* -N flag */
123 int randomoplen = 1; /* -O flag disables it */
124 int seed = 1; /* -S flag */
125 int mapped_writes = 1; /* -W flag disables */
126 int mapped_reads = 1; /* -R flag disables it */
128 FILE * fsxlogf = NULL;
134 vwarnc(code, fmt, ap)
139 fprintf(stderr, "fsx: ");
141 vfprintf(stderr, fmt, ap);
142 fprintf(stderr, ": ");
144 fprintf(stderr, "%s\n", strerror(code));
149 warn(const char * fmt, ...)
153 vwarnc(errno, fmt, ap);
164 vfprintf(stdout, fmt, args);
166 vfprintf(fsxlogf, fmt, args);
173 prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno));
178 log4(int operation, int arg0, int arg1, int arg2, struct timeval *tv)
180 struct log_entry *le;
184 le->operation = operation;
186 le->operation = ~ le->operation;
192 if (logptr >= LOGSIZE)
201 struct log_entry *lp;
203 prt("LOG DUMP (%d total operations):\n", logcount);
204 if (logcount < LOGSIZE) {
211 for ( ; count > 0; count--) {
214 opnum = i+1 + (logcount/LOGSIZE)*LOGSIZE;
216 prt("%d(%d mod 256): %lu.%06lu ", opnum, opnum%256,
217 lp->tv.tv_sec, lp->tv.tv_usec);
218 if ((closeopen = lp->operation < 0))
219 lp->operation = ~ lp->operation;
221 switch (lp->operation) {
223 prt("MAPREAD\t0x%x thru 0x%x (0x%x bytes)",
224 lp->args[0], lp->args[0] + lp->args[1] - 1,
226 if (badoff >= lp->args[0] && badoff <
227 lp->args[0] + lp->args[1])
231 prt("MAPWRITE 0x%x thru 0x%x (0x%x bytes)",
232 lp->args[0], lp->args[0] + lp->args[1] - 1,
234 if (badoff >= lp->args[0] && badoff <
235 lp->args[0] + lp->args[1])
239 prt("READ\t0x%x thru 0x%x (0x%x bytes)",
240 lp->args[0], lp->args[0] + lp->args[1] - 1,
242 if (badoff >= lp->args[0] &&
243 badoff < lp->args[0] + lp->args[1])
247 prt("WRITE\t0x%x thru 0x%x (0x%x bytes)",
248 lp->args[0], lp->args[0] + lp->args[1] - 1,
250 if (lp->args[0] > lp->args[2])
252 else if (lp->args[0] + lp->args[1] > lp->args[2])
254 if ((badoff >= lp->args[0] || badoff >=lp->args[2]) &&
255 badoff < lp->args[0] + lp->args[1])
259 down = lp->args[0] < lp->args[1];
260 prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
261 down ? "DOWN" : "UP", lp->args[1], lp->args[0]);
262 if (badoff >= lp->args[!down] &&
263 badoff < lp->args[!!down])
267 prt("SKIPPED (no operation)");
270 prt("BOGUS LOG ENTRY (operation code = %d)!",
274 prt("\n\t\tCLOSE/OPEN");
284 save_buffer(char *buffer, off_t bufferlength, int fd)
287 ssize_t byteswritten;
289 if (fd <= 0 || bufferlength == 0)
292 if (bufferlength > SSIZE_MAX) {
293 prt("fsx flaw: overflow in save_buffer\n");
297 off_t size_by_seek = lseek(fd, (off_t)0, SEEK_END);
298 if (size_by_seek == (off_t)-1)
299 prterr("save_buffer: lseek eof");
300 else if (bufferlength > size_by_seek) {
301 warn("save_buffer: .fsxgood file too short... will
302 save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek,
303 (unsigned long long)bufferlength);
304 bufferlength = size_by_seek;
308 ret = lseek(fd, (off_t)0, SEEK_SET);
309 if (ret == (off_t)-1)
310 prterr("save_buffer: lseek 0");
312 byteswritten = write(fd, buffer, (size_t)bufferlength);
313 if (byteswritten != bufferlength) {
314 if (byteswritten == -1)
315 prterr("save_buffer write");
317 warn("save_buffer: short write, 0x%x bytes instead
319 (unsigned)byteswritten,
320 (unsigned long long)bufferlength);
326 report_failure(int status)
332 save_buffer(good_buf, file_size, fsxgoodfd);
333 prt("Correct content saved for comparison\n");
334 prt("(maybe hexdump \"%s\" vs \"%s\")\n",
343 #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
344 *(((unsigned char *)(cp)) + 1)))
347 check_buffers(unsigned offset, unsigned size)
355 if (memcmp(good_buf + offset, temp_buf, size) != 0) {
356 prt("READ BAD DATA: offset = 0x%x, size = 0x%x\n",
358 prt("OFFSET\tGOOD\tBAD\tRANGE\n");
360 c = good_buf[offset];
364 bad = short_at(&temp_buf[i]);
365 prt("0x%5x\t0x%04x\t0x%04x", offset,
366 short_at(&good_buf[offset]), bad);
367 op = temp_buf[offset & 1 ? i+1 : i];
379 prt("operation# (mod 256) for the bad data
380 may be %u\n", ((unsigned)op & 0xff));
382 prt("operation# (mod 256) for the bad data
383 unknown, check HOLE and EXTEND ops\n");
385 prt("????????????????\n");
397 if (fstat(fd, &statbuf)) {
398 prterr("check_size: fstat");
399 statbuf.st_size = -1;
401 size_by_seek = lseek(fd, (off_t)0, SEEK_END);
402 if (file_size != statbuf.st_size || file_size != size_by_seek) {
403 prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
404 (unsigned long long)file_size,
405 (unsigned long long)statbuf.st_size,
406 (unsigned long long)size_by_seek);
413 check_trunc_hack(void)
417 ftruncate(fd, (off_t)0);
418 ftruncate(fd, (off_t)100000);
420 if (statbuf.st_size != (off_t)100000) {
421 prt("no extend on truncate! not posix!\n");
429 doread(unsigned offset, unsigned size)
435 offset -= offset % readbdy;
436 gettimeofday(&t, NULL);
438 if (!quiet && testcalls > simulatedopcount)
439 prt("skipping zero size read\n");
440 log4(OP_SKIPPED, OP_READ, offset, size, &t);
443 if (size + offset > file_size) {
444 if (!quiet && testcalls > simulatedopcount)
445 prt("skipping seek/read past end of file\n");
446 log4(OP_SKIPPED, OP_READ, offset, size, &t);
450 log4(OP_READ, offset, size, 0, &t);
452 if (testcalls <= simulatedopcount)
455 if (!quiet && ((progressinterval &&
456 testcalls % progressinterval == 0) ||
458 (monitorstart == -1 ||
459 (offset + size > monitorstart &&
460 (monitorend == -1 || offset <= monitorend))))))
461 prt("%06lu %lu.%06lu read %#08x thru %#08x\t(0x%x bytes)\n",
462 testcalls, t.tv_sec, t.tv_usec, offset, offset + size - 1,
464 ret = lseek(fd, (off_t)offset, SEEK_SET);
465 if (ret == (off_t)-1) {
466 prterr("doread: lseek");
469 iret = read(fd, temp_buf, size);
470 if (!quiet && (debug > 1 &&
471 (monitorstart == -1 ||
472 (offset + size > monitorstart &&
473 (monitorend == -1 || offset <= monitorend))))) {
474 gettimeofday(&t, NULL);
475 prt(" %lu.%06lu read done\n", t.tv_sec, t.tv_usec);
479 prterr("doread: read");
481 prt("short read: 0x%x bytes instead of 0x%x\n",
485 check_buffers(offset, size);
490 domapread(unsigned offset, unsigned size)
497 offset -= offset % readbdy;
498 gettimeofday(&t, NULL);
500 if (!quiet && testcalls > simulatedopcount)
501 prt("skipping zero size read\n");
502 log4(OP_SKIPPED, OP_MAPREAD, offset, size, &t);
505 if (size + offset > file_size) {
506 if (!quiet && testcalls > simulatedopcount)
507 prt("skipping seek/read past end of file\n");
508 log4(OP_SKIPPED, OP_MAPREAD, offset, size, &t);
512 log4(OP_MAPREAD, offset, size, 0, &t);
514 if (testcalls <= simulatedopcount)
517 if (!quiet && ((progressinterval &&
518 testcalls % progressinterval == 0) ||
520 (monitorstart == -1 ||
521 (offset + size > monitorstart &&
522 (monitorend == -1 || offset <= monitorend))))))
523 prt("%06lu %lu.%06lu mapread %#08x thru %#08x\t(0x%x bytes)\n",
524 testcalls, t.tv_sec, t.tv_usec, offset, offset + size - 1,
527 pg_offset = offset & page_mask;
528 map_size = pg_offset + size;
530 if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_FILE | MAP_SHARED, fd,
531 (off_t)(offset - pg_offset))) == (char *)-1) {
532 prterr("domapread: mmap");
535 memcpy(temp_buf, p + pg_offset, size);
536 if (!quiet && (debug > 1 &&
537 (monitorstart == -1 ||
538 (offset + size > monitorstart &&
539 (monitorend == -1 || offset <= monitorend))))) {
540 gettimeofday(&t, NULL);
541 prt(" %lu.%06lu memcpy done\n", t.tv_sec, t.tv_usec);
543 if (munmap(p, map_size) != 0) {
544 prterr("domapread: munmap");
547 if (!quiet && (debug > 1 &&
548 (monitorstart == -1 ||
549 (offset + size > monitorstart &&
550 (monitorend == -1 || offset <= monitorend))))) {
551 gettimeofday(&t, NULL);
552 prt(" %lu.%06lu munmap done\n", t.tv_sec, t.tv_usec);
555 check_buffers(offset, size);
560 gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size)
563 good_buf[offset] = testcalls % 256;
565 good_buf[offset] += original_buf[offset];
572 dowrite(unsigned offset, unsigned size)
578 offset -= offset % writebdy;
579 gettimeofday(&t, NULL);
581 if (!quiet && testcalls > simulatedopcount)
582 prt("skipping zero size write\n");
583 log4(OP_SKIPPED, OP_WRITE, offset, size, &t);
587 log4(OP_WRITE, offset, size, file_size, &t);
589 gendata(original_buf, good_buf, offset, size);
590 if (file_size < offset + size) {
591 if (file_size < offset)
592 memset(good_buf + file_size, '\0', offset - file_size);
593 file_size = offset + size;
595 warn("Lite file size bug in fsx!");
600 if (testcalls <= simulatedopcount)
603 if (!quiet && ((progressinterval &&
604 testcalls % progressinterval == 0) ||
606 (monitorstart == -1 ||
607 (offset + size > monitorstart &&
608 (monitorend == -1 || offset <= monitorend))))))
609 prt("%06lu %lu.%06lu write %#08x thru %#08x\t(0x%x bytes)\n",
610 testcalls, t.tv_sec, t.tv_usec, offset, offset + size - 1,
612 ret = lseek(fd, (off_t)offset, SEEK_SET);
613 if (ret == (off_t)-1) {
614 prterr("dowrite: lseek");
617 iret = write(fd, good_buf + offset, size);
618 if (!quiet && (debug > 1 &&
619 (monitorstart == -1 ||
620 (offset + size > monitorstart &&
621 (monitorend == -1 || offset <= monitorend))))) {
622 gettimeofday(&t, NULL);
623 prt(" %lu.%06lu write done\n", t.tv_sec, t.tv_usec);
627 prterr("dowrite: write");
629 prt("short write: 0x%x bytes instead of 0x%x\n",
637 domapwrite(unsigned offset, unsigned size)
645 offset -= offset % writebdy;
646 gettimeofday(&t, NULL);
648 if (!quiet && testcalls > simulatedopcount)
649 prt("skipping zero size write\n");
650 log4(OP_SKIPPED, OP_MAPWRITE, offset, size, &t);
653 cur_filesize = file_size;
655 log4(OP_MAPWRITE, offset, size, 0, &t);
657 gendata(original_buf, good_buf, offset, size);
658 if (file_size < offset + size) {
659 if (file_size < offset)
660 memset(good_buf + file_size, '\0', offset - file_size);
661 file_size = offset + size;
663 warn("Lite file size bug in fsx!");
668 if (testcalls <= simulatedopcount)
671 if (!quiet && ((progressinterval &&
672 testcalls % progressinterval == 0) ||
674 (monitorstart == -1 ||
675 (offset + size > monitorstart &&
676 (monitorend == -1 || offset <= monitorend))))))
677 prt("%06lu %lu.%06lu mapwrite %#08x thru %#08x\t(0x%x bytes)\n",
678 testcalls, t.tv_sec, t.tv_usec, offset, offset + size - 1,
681 if (file_size > cur_filesize) {
682 if (ftruncate(fd, file_size) == -1) {
683 prterr("domapwrite: ftruncate");
687 pg_offset = offset & page_mask;
688 map_size = pg_offset + size;
690 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
691 MAP_FILE | MAP_SHARED, fd,
692 (off_t)(offset - pg_offset))) == (char *)-1) {
693 prterr("domapwrite: mmap");
696 memcpy(p + pg_offset, good_buf + offset, size);
697 if (!quiet && (debug > 1 &&
698 (monitorstart == -1 ||
699 (offset + size > monitorstart &&
700 (monitorend == -1 || offset <= monitorend))))) {
701 gettimeofday(&t, NULL);
702 prt(" %lu.%06lu memcpy done\n", t.tv_sec, t.tv_usec);
704 if (msync(p, map_size, 0) != 0) {
705 prterr("domapwrite: msync");
708 if (!quiet && (debug > 1 &&
709 (monitorstart == -1 ||
710 (offset + size > monitorstart &&
711 (monitorend == -1 || offset <= monitorend))))) {
712 gettimeofday(&t, NULL);
713 prt(" %lu.%06lu msync done\n", t.tv_sec, t.tv_usec);
715 if (munmap(p, map_size) != 0) {
716 prterr("domapwrite: munmap");
719 if (!quiet && (debug > 1 &&
720 (monitorstart == -1 ||
721 (offset + size > monitorstart &&
722 (monitorend == -1 || offset <= monitorend))))) {
723 gettimeofday(&t, NULL);
724 prt(" %lu.%06lu munmap done\n", t.tv_sec, t.tv_usec);
730 dotruncate(unsigned size)
733 int oldsize = file_size;
735 size -= size % truncbdy;
736 gettimeofday(&t, NULL);
737 if (size > biggest) {
739 if (!quiet && testcalls > simulatedopcount)
740 prt("truncating to largest ever: 0x%x\n", size);
743 log4(OP_TRUNCATE, size, (unsigned)file_size, 0, &t);
745 if (size > file_size)
746 memset(good_buf + file_size, '\0', size - file_size);
749 if (testcalls <= simulatedopcount)
752 if ((progressinterval && testcalls % progressinterval == 0) ||
753 (debug && (monitorstart == -1 || monitorend == -1 ||
754 size <= monitorend)))
755 prt("%06lu %lu.%06lu trunc from %#08x to %#08x\n",
756 testcalls, t.tv_sec, t.tv_usec, oldsize, size);
757 if (ftruncate(fd, (off_t)size) == -1) {
758 prt("ftruncate1: %x\n", size);
759 prterr("dotruncate: ftruncate");
762 if (!quiet && debug > 1) {
763 gettimeofday(&t, NULL);
764 prt(" %lu.%06lu trunc done\n", t.tv_sec, t.tv_usec);
774 if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
775 prterr("writefileimage: lseek");
778 iret = write(fd, good_buf, file_size);
779 if ((off_t)iret != file_size) {
781 prterr("writefileimage: write");
783 prt("short write: 0x%x bytes instead of 0x%llx\n",
784 iret, (unsigned long long)file_size);
787 if (lite ? 0 : ftruncate(fd, file_size) == -1) {
788 prt("ftruncate2: %llx\n", (unsigned long long)file_size);
789 prterr("writefileimage: ftruncate");
800 if (testcalls <= simulatedopcount)
803 log4(OP_CLOSEOPEN, file_size, (unsigned)file_size, 0, &t);
805 gettimeofday(&t, NULL);
807 prt("%06lu %lu.%06lu close/open\n", testcalls, t.tv_sec,
810 prterr("docloseopen: close");
813 if (!quiet && debug > 1) {
814 gettimeofday(&t, NULL);
815 prt(" %lu.%06lu close done\n", t.tv_sec, t.tv_usec);
817 fd = open(fname, O_RDWR, 0);
819 prterr("docloseopen: open");
822 if (!quiet && debug > 1) {
823 gettimeofday(&t, NULL);
824 prt(" %lu.%06lu opendone\n", t.tv_sec, t.tv_usec);
832 unsigned long offset;
833 unsigned long size = maxoplen;
834 unsigned long rv = random();
835 unsigned long op = rv % (3 + !lite + mapped_writes);
837 /* turn off the map read if necessary */
839 if (op == 2 && !mapped_reads)
842 if (simulatedopcount > 0 && testcalls == simulatedopcount)
848 closeopen = (rv >> 3) < (1 << 28) / closeprob;
850 if (debugstart > 0 && testcalls >= debugstart)
853 if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
854 prt("%lu...\n", testcalls);
861 * MAPWRITE: op = 3 or 4
863 if (lite ? 0 : op == 3 && (style & 1) == 0) /* vanilla truncate? */
864 dotruncate(random() % maxfilelen);
867 size = random() % (maxoplen+1);
868 if (lite ? 0 : op == 3)
872 if (op == 1 || op == (lite ? 3 : 4)) {
873 offset %= maxfilelen;
874 if (offset + size > maxfilelen)
875 size = maxfilelen - offset;
877 domapwrite(offset, size);
879 dowrite(offset, size);
885 if (offset + size > file_size)
886 size = file_size - offset;
888 domapread(offset, size);
890 doread(offset, size);
894 if (sizechecks && testcalls > simulatedopcount)
906 prt("signal %d\n", sig);
907 prt("testcalls = %lu\n", testcalls);
915 fprintf(stdout, "usage: %s",
916 "fsx [-dnqLOW] [-b opnum] [-c Prob] [-l flen] [-m
917 start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t
918 truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed]
920 -b opnum: beginning operation number (default 1)\n\
921 -c P: 1 in P chance of file close+open at each op (default infinity)\n\
922 -d: debug output for all operations [-d -d = more debugging]\n\
923 -l flen: the upper bound on file size (default 262144)\n\
924 -m startop:endop: monitor (print debug output) specified byte range
925 (default 0:infinity)\n\
926 -n: no verifications of file size\n\
927 -o oplen: the upper bound on operation size (default 65536)\n\
928 -p progressinterval: debug output at specified operation interval\n\
929 -q: quieter operation\n\
930 -r readbdy: 4096 would make reads page aligned (default 1)\n\
931 -s style: 1 gives smaller truncates (default 0)\n\
932 -t truncbdy: 4096 would make truncates page aligned (default 1)\n\
933 -w writebdy: 4096 would make writes page aligned (default 1)\n\
934 -D startingop: debug output starting at specified operation\n\
935 -L: fsxLite - no file creations & no file size changes\n\
936 -N numops: total # operations to do (default infinity)\n\
937 -O: use oplen (see -o flag) for every op (default random)\n\
938 -P: save .fsxlog and .fsxgood files in dirpath (default ./)\n\
939 -S seed: for random # generator (default 1) 0 gets timestamp\n\
940 -W: mapped write operations DISabled\n\
941 -R: read() system calls only (mapped reads disabled)\n\
942 fname: this filename is REQUIRED (no default)\n");
948 getnum(char *s, char **e)
953 ret = strtol(s, e, 0);
981 static const char *basename(const char *path)
983 char *c = strrchr(path, '/');
985 return c ? c++ : path;
989 main(int argc, char **argv)
998 page_size = getpagesize();
999 page_mask = page_size - 1;
1001 setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
1003 while ((ch = getopt(argc, argv, "b:c:dl:m:no:p:qr:s:t:w:D:LN:OP:RS:W"))
1007 simulatedopcount = getnum(optarg, &endp);
1009 fprintf(stdout, "Will begin at operation
1012 if (simulatedopcount == 0)
1014 simulatedopcount -= 1;
1017 closeprob = getnum(optarg, &endp);
1020 "Chance of close/open is 1 in %d\n",
1029 maxfilelen = getnum(optarg, &endp);
1030 if (maxfilelen <= 0)
1034 monitorstart = getnum(optarg, &endp);
1035 if (monitorstart < 0)
1037 if (!endp || *endp++ != ':')
1039 monitorend = getnum(endp, &endp);
1042 if (monitorend == 0)
1043 monitorend = -1; /* aka infinity */
1049 maxoplen = getnum(optarg, &endp);
1054 progressinterval = getnum(optarg, &endp);
1055 if (progressinterval < 0)
1062 readbdy = getnum(optarg, &endp);
1067 style = getnum(optarg, &endp);
1068 if (style < 0 || style > 1)
1072 truncbdy = getnum(optarg, &endp);
1077 writebdy = getnum(optarg, &endp);
1082 debugstart = getnum(optarg, &endp);
1090 numops = getnum(optarg, &endp);
1098 strncpy(goodfile, optarg, sizeof(goodfile));
1099 strcat(goodfile, "/");
1100 strncpy(logfile, optarg, sizeof(logfile));
1101 strcat(logfile, "/");
1108 seed = getnum(optarg, &endp);
1110 seed = time(0) % 10000;
1112 fprintf(stdout, "Seed set to %d\n", seed);
1119 fprintf(stdout, "mapped writes 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, dirpath ? basename(fname) : fname, 256);
1151 strcat (goodfile, ".fsxgood");
1152 fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
1153 if (fsxgoodfd < 0) {
1157 strncat(logfile, dirpath ? basename(fname) : 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
1197 (unsigned)written, maxfilelen);
1203 while (numops == -1 || numops--)
1210 prt("All operations completed A-OK!\n");