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 */
103 unsigned long testcalls = 0; /* calls to function "test" */
105 unsigned long simulatedopcount = 0; /* -b flag */
106 int closeprob = 0; /* -c flag */
107 int debug = 0; /* -d flag */
108 unsigned long debugstart = 0; /* -D flag */
109 unsigned long maxfilelen = 256 * 1024; /* -l flag */
110 int sizechecks = 1; /* -n flag disables them */
111 int maxoplen = 64 * 1024; /* -o flag */
112 int quiet = 0; /* -q flag */
113 unsigned long progressinterval = 0; /* -p flag */
114 int readbdy = 1; /* -r flag */
115 int style = 0; /* -s flag */
116 int truncbdy = 1; /* -t flag */
117 int writebdy = 1; /* -w flag */
118 long monitorstart = -1; /* -m flag */
119 long monitorend = -1; /* -m flag */
120 int lite = 0; /* -L flag */
121 long numops = -1; /* -N flag */
122 int randomoplen = 1; /* -O flag disables it */
123 int seed = 1; /* -S flag */
124 int mapped_writes = 1; /* -W flag disables */
125 int mapped_reads = 1; /* -R flag disables it */
127 FILE * fsxlogf = NULL;
132 vwarnc(code, fmt, ap)
137 fprintf(stderr, "fsx: ");
139 vfprintf(stderr, fmt, ap);
140 fprintf(stderr, ": ");
142 fprintf(stderr, "%s\n", strerror(code));
147 warn(const char * fmt, ...)
151 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, struct timeval *tv)
178 struct log_entry *le;
182 le->operation = operation;
188 if (logptr >= LOGSIZE)
197 struct log_entry *lp;
199 prt("LOG DUMP (%d total operations):\n", logcount);
200 if (logcount < LOGSIZE) {
207 for ( ; count > 0; count--) {
210 opnum = i+1 + (logcount/LOGSIZE)*LOGSIZE;
212 prt("%d: %lu.%06lu ", opnum,
213 lp->tv.tv_sec, lp->tv.tv_usec);
215 switch (lp->operation) {
217 prt("MAPREAD 0x%x thru 0x%x (0x%x bytes)",
218 lp->args[0], lp->args[0] + lp->args[1] - 1,
220 if (badoff >= lp->args[0] && badoff <
221 lp->args[0] + lp->args[1])
225 prt("MAPWRITE 0x%x thru 0x%x (0x%x bytes)",
226 lp->args[0], lp->args[0] + lp->args[1] - 1,
228 if (badoff >= lp->args[0] && badoff <
229 lp->args[0] + lp->args[1])
233 prt("READ 0x%x thru 0x%x (0x%x bytes)",
234 lp->args[0], lp->args[0] + lp->args[1] - 1,
236 if (badoff >= lp->args[0] &&
237 badoff < lp->args[0] + lp->args[1])
241 prt("WRITE 0x%x thru 0x%x (0x%x bytes)",
242 lp->args[0], lp->args[0] + lp->args[1] - 1,
244 if (lp->args[0] > lp->args[2])
246 else if (lp->args[0] + lp->args[1] > lp->args[2])
248 if ((badoff >= lp->args[0] || badoff >=lp->args[2]) &&
249 badoff < lp->args[0] + lp->args[1])
253 down = lp->args[0] < lp->args[1];
254 prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
255 down ? "DOWN" : "UP", lp->args[1], lp->args[0]);
256 if (badoff >= lp->args[!down] &&
257 badoff < lp->args[!!down])
264 prt("SKIPPED (no operation)");
267 prt("BOGUS LOG ENTRY (operation code = %d)!",
279 save_buffer(char *buffer, off_t bufferlength, int fd)
282 ssize_t byteswritten;
284 if (fd <= 0 || bufferlength == 0)
287 if (bufferlength > SSIZE_MAX) {
288 prt("fsx flaw: overflow in save_buffer\n");
292 off_t size_by_seek = lseek(fd, (off_t)0, SEEK_END);
293 if (size_by_seek == (off_t)-1)
294 prterr("save_buffer: lseek eof");
295 else if (bufferlength > size_by_seek) {
296 warn("save_buffer: .fsxgood file too short... will"
297 "save 0x%llx bytes instead of 0x%llx\n",
298 (unsigned long long)size_by_seek,
299 (unsigned long long)bufferlength);
300 bufferlength = size_by_seek;
304 ret = lseek(fd, (off_t)0, SEEK_SET);
305 if (ret == (off_t)-1)
306 prterr("save_buffer: lseek 0");
308 byteswritten = write(fd, buffer, (size_t)bufferlength);
309 if (byteswritten != bufferlength) {
310 if (byteswritten == -1)
311 prterr("save_buffer write");
313 warn("save_buffer: short write, 0x%x bytes instead"
315 (unsigned)byteswritten,
316 (unsigned long long)bufferlength);
322 report_failure(int status)
328 save_buffer(good_buf, file_size, fsxgoodfd);
329 prt("Correct content saved for comparison\n");
330 prt("(maybe hexdump \"%s\" vs \"%s\")\n",
339 #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
340 *(((unsigned char *)(cp)) + 1)))
343 check_buffers(unsigned offset, unsigned size)
351 if (memcmp(good_buf + offset, temp_buf, size) != 0) {
352 prt("READ BAD DATA: offset = 0x%x, size = 0x%x\n",
354 prt("OFFSET\tGOOD\tBAD\tRANGE\n");
356 c = good_buf[offset];
360 bad = short_at(&temp_buf[i]);
361 prt("0x%5x\t0x%04x\t0x%04x", offset,
362 short_at(&good_buf[offset]), bad);
363 op = temp_buf[offset & 1 ? i+1 : i];
375 prt("operation# (mod 256) for the bad data"
376 "may be %u\n", ((unsigned)op & 0xff));
378 prt("operation# (mod 256) for the bad data"
379 "unknown, check HOLE and EXTEND ops\n");
381 prt("????????????????\n");
389 } *test_files = NULL;
391 int num_test_files = 0;
392 enum fd_iteration_policy {
397 int fd_policy = FD_RANDOM;
416 prt("unknown policy");
420 return &test_files[ index % num_test_files ];
424 assign_fd_policy(char *policy)
426 if (!strcmp(policy, "random"))
427 fd_policy = FD_RANDOM;
428 else if (!strcmp(policy, "rotate"))
429 fd_policy = FD_ROTATE;
431 prt("unknown -I policy: '%s'\n", policy);
439 struct test_file *tf = get_tf();
443 static const char *basename(const char *path)
445 char *c = strrchr(path, '/');
447 return c ? c++ : path;
451 open_test_files(char **argv, int argc)
453 struct test_file *tf;
456 num_test_files = argc;
457 if (num_test_files == 1)
458 fd_policy = FD_SINGLE;
460 test_files = calloc(num_test_files, sizeof(*test_files));
461 if (test_files == NULL) {
462 prterr("reallocating space for test files");
466 for (i = 0, tf = test_files; i < num_test_files; i++, tf++) {
469 tf->fd = open(tf->path, O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC),
477 if (quiet || fd_policy == FD_SINGLE)
480 for (i = 0, tf = test_files; i < num_test_files; i++, tf++)
481 prt("fd %d: %s\n", i, tf->path);
485 close_test_files(void)
488 struct test_file *tf;
490 for (i = 0, tf = test_files; i < num_test_files; i++, tf++) {
506 if (fstat(fd, &statbuf)) {
507 prterr("check_size: fstat");
508 statbuf.st_size = -1;
510 size_by_seek = lseek(fd, (off_t)0, SEEK_END);
511 if (file_size != statbuf.st_size || file_size != size_by_seek) {
512 prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
513 (unsigned long long)file_size,
514 (unsigned long long)statbuf.st_size,
515 (unsigned long long)size_by_seek);
522 check_trunc_hack(void)
527 ftruncate(fd, (off_t)0);
528 ftruncate(fd, (off_t)100000);
530 if (statbuf.st_size != (off_t)100000) {
531 prt("no extend on truncate! not posix!\n");
537 static char *tf_buf = NULL;
538 static int max_tf_len = 0;
544 int highest = num_test_files - 1;
547 len = snprintf(&dummy, 0, "%u ", highest);
549 prterr("finding max tf_buf");
552 tf_buf = malloc(len + 1);
553 if (tf_buf == NULL) {
554 prterr("allocating tf_buf");
557 max_tf_len = sprintf(tf_buf, "%u ", highest);
561 fill_tf_buf(struct test_file *tf)
566 sprintf(tf_buf,"%u ", tf - test_files);
571 output_line(struct test_file *tf, int op, unsigned long offset,
572 unsigned long size, struct timeval *tv)
578 [OP_WRITE] = "write",
579 [OP_TRUNCATE] = "trunc from",
580 [OP_MAPREAD] = "mapread",
581 [OP_MAPWRITE] = "mapwrite",
584 if (fd_policy != FD_SINGLE)
585 tf_num = fill_tf_buf(tf);
588 if (!(!quiet && ((progressinterval &&
589 testcalls % progressinterval == 0) ||
591 (monitorstart == -1 ||
592 (offset + size > monitorstart &&
593 (monitorend == -1 || offset <= monitorend)))))))
596 prt("%06lu %lu.%06lu %*s%-10s %#08x %s %#08x\t(0x%x bytes)\n",
597 testcalls, tv->tv_sec, tv->tv_usec, max_tf_len,
599 offset, op == OP_TRUNCATE ? " to " : "thru",
600 offset + size - 1, size);
604 doread(unsigned offset, unsigned size)
609 struct test_file *tf = get_tf();
612 offset -= offset % readbdy;
613 gettimeofday(&t, NULL);
615 if (!quiet && testcalls > simulatedopcount)
616 prt("skipping zero size read\n");
617 log4(OP_SKIPPED, OP_READ, offset, size, &t);
620 if (size + offset > file_size) {
621 if (!quiet && testcalls > simulatedopcount)
622 prt("skipping seek/read past end of file\n");
623 log4(OP_SKIPPED, OP_READ, offset, size, &t);
627 log4(OP_READ, offset, size, 0, &t);
629 if (testcalls <= simulatedopcount)
632 output_line(tf, OP_READ, offset, size, &t);
634 ret = lseek(fd, (off_t)offset, SEEK_SET);
635 if (ret == (off_t)-1) {
636 prterr("doread: lseek");
639 iret = read(fd, temp_buf, size);
640 if (!quiet && (debug > 1 &&
641 (monitorstart == -1 ||
642 (offset + size > monitorstart &&
643 (monitorend == -1 || offset <= monitorend))))) {
644 gettimeofday(&t, NULL);
645 prt(" %lu.%06lu read done\n", t.tv_sec, t.tv_usec);
649 prterr("doread: read");
651 prt("short read: 0x%x bytes instead of 0x%x\n",
655 check_buffers(offset, size);
660 domapread(unsigned offset, unsigned size)
666 struct test_file *tf = get_tf();
669 offset -= offset % readbdy;
670 gettimeofday(&t, NULL);
672 if (!quiet && testcalls > simulatedopcount)
673 prt("skipping zero size read\n");
674 log4(OP_SKIPPED, OP_MAPREAD, offset, size, &t);
677 if (size + offset > file_size) {
678 if (!quiet && testcalls > simulatedopcount)
679 prt("skipping seek/read past end of file\n");
680 log4(OP_SKIPPED, OP_MAPREAD, offset, size, &t);
684 log4(OP_MAPREAD, offset, size, 0, &t);
686 if (testcalls <= simulatedopcount)
689 output_line(tf, OP_MAPREAD, offset, size, &t);
691 pg_offset = offset & page_mask;
692 map_size = pg_offset + size;
694 if ((p = mmap(0, map_size, PROT_READ, MAP_FILE | MAP_SHARED, fd,
695 (off_t)(offset - pg_offset))) == MAP_FAILED) {
696 prterr("domapread: mmap");
699 if (!quiet && (debug > 1 &&
700 (monitorstart == -1 ||
701 (offset + size > monitorstart &&
702 (monitorend == -1 || offset <= monitorend))))) {
703 gettimeofday(&t, NULL);
704 prt(" %lu.%06lu mmap done\n", t.tv_sec, t.tv_usec);
706 memcpy(temp_buf, p + pg_offset, size);
707 if (!quiet && (debug > 1 &&
708 (monitorstart == -1 ||
709 (offset + size > monitorstart &&
710 (monitorend == -1 || offset <= monitorend))))) {
711 gettimeofday(&t, NULL);
712 prt(" %lu.%06lu memcpy done\n", t.tv_sec, t.tv_usec);
714 if (munmap(p, map_size) != 0) {
715 prterr("domapread: munmap");
718 if (!quiet && (debug > 1 &&
719 (monitorstart == -1 ||
720 (offset + size > monitorstart &&
721 (monitorend == -1 || offset <= monitorend))))) {
722 gettimeofday(&t, NULL);
723 prt(" %lu.%06lu munmap done\n", t.tv_sec, t.tv_usec);
726 check_buffers(offset, size);
731 gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size)
734 good_buf[offset] = testcalls % 256;
736 good_buf[offset] += original_buf[offset];
743 dowrite(unsigned offset, unsigned size)
748 struct test_file *tf = get_tf();
751 offset -= offset % writebdy;
752 gettimeofday(&t, NULL);
754 if (!quiet && testcalls > simulatedopcount)
755 prt("skipping zero size write\n");
756 log4(OP_SKIPPED, OP_WRITE, offset, size, &t);
760 log4(OP_WRITE, offset, size, file_size, &t);
762 gendata(original_buf, good_buf, offset, size);
763 if (file_size < offset + size) {
764 if (file_size < offset)
765 memset(good_buf + file_size, '\0', offset - file_size);
766 file_size = offset + size;
768 warn("Lite file size bug in fsx!");
773 if (testcalls <= simulatedopcount)
776 output_line(tf, OP_WRITE, offset, size, &t);
778 ret = lseek(fd, (off_t)offset, SEEK_SET);
779 if (ret == (off_t)-1) {
780 prterr("dowrite: lseek");
783 iret = write(fd, good_buf + offset, size);
784 if (!quiet && (debug > 1 &&
785 (monitorstart == -1 ||
786 (offset + size > monitorstart &&
787 (monitorend == -1 || offset <= monitorend))))) {
788 gettimeofday(&t, NULL);
789 prt(" %lu.%06lu write done\n", t.tv_sec, t.tv_usec);
793 prterr("dowrite: write");
795 prt("short write: 0x%x bytes instead of 0x%x\n",
803 domapwrite(unsigned offset, unsigned size)
810 struct test_file *tf = get_tf();
813 offset -= offset % writebdy;
814 gettimeofday(&t, NULL);
816 if (!quiet && testcalls > simulatedopcount)
817 prt("skipping zero size write\n");
818 log4(OP_SKIPPED, OP_MAPWRITE, offset, size, &t);
821 cur_filesize = file_size;
823 log4(OP_MAPWRITE, offset, size, 0, &t);
825 gendata(original_buf, good_buf, offset, size);
826 if (file_size < offset + size) {
827 if (file_size < offset)
828 memset(good_buf + file_size, '\0', offset - file_size);
829 file_size = offset + size;
831 warn("Lite file size bug in fsx!");
836 if (testcalls <= simulatedopcount)
839 output_line(tf, OP_MAPWRITE, offset, size, &t);
841 if (file_size > cur_filesize) {
842 if (ftruncate(fd, file_size) == -1) {
843 prterr("domapwrite: ftruncate");
846 if (!quiet && (debug > 1 &&
847 (monitorstart == -1 ||
848 (offset + size > monitorstart &&
849 (monitorend == -1 || offset <= monitorend))))) {
850 gettimeofday(&t, NULL);
851 prt(" %lu.%06lu truncate done\n", t.tv_sec, t.tv_usec);
854 pg_offset = offset & page_mask;
855 map_size = pg_offset + size;
857 if ((p = mmap(0, map_size, PROT_READ | PROT_WRITE, MAP_FILE|MAP_SHARED,
858 fd, (off_t)(offset - pg_offset))) == MAP_FAILED) {
859 prterr("domapwrite: mmap");
862 if (!quiet && (debug > 1 &&
863 (monitorstart == -1 ||
864 (offset + size > monitorstart &&
865 (monitorend == -1 || offset <= monitorend))))) {
866 gettimeofday(&t, NULL);
867 prt(" %lu.%06lu mmap done\n", t.tv_sec, t.tv_usec);
869 memcpy(p + pg_offset, good_buf + offset, size);
870 if (!quiet && (debug > 1 &&
871 (monitorstart == -1 ||
872 (offset + size > monitorstart &&
873 (monitorend == -1 || offset <= monitorend))))) {
874 gettimeofday(&t, NULL);
875 prt(" %lu.%06lu memcpy done\n", t.tv_sec, t.tv_usec);
877 if (msync(p, map_size, 0) != 0) {
878 prterr("domapwrite: msync");
881 if (!quiet && (debug > 1 &&
882 (monitorstart == -1 ||
883 (offset + size > monitorstart &&
884 (monitorend == -1 || offset <= monitorend))))) {
885 gettimeofday(&t, NULL);
886 prt(" %lu.%06lu msync done\n", t.tv_sec, t.tv_usec);
888 if (munmap(p, map_size) != 0) {
889 prterr("domapwrite: munmap");
892 if (!quiet && (debug > 1 &&
893 (monitorstart == -1 ||
894 (offset + size > monitorstart &&
895 (monitorend == -1 || offset <= monitorend))))) {
896 gettimeofday(&t, NULL);
897 prt(" %lu.%06lu munmap done\n", t.tv_sec, t.tv_usec);
903 dotruncate(unsigned size)
906 int oldsize = file_size;
907 struct test_file *tf = get_tf();
910 size -= size % truncbdy;
911 gettimeofday(&t, NULL);
912 if (size > biggest) {
914 if (!quiet && testcalls > simulatedopcount)
915 prt("truncating to largest ever: 0x%x\n", size);
918 log4(OP_TRUNCATE, size, (unsigned)file_size, 0, &t);
920 if (size > file_size)
921 memset(good_buf + file_size, '\0', size - file_size);
924 if (testcalls <= simulatedopcount)
927 output_line(tf, OP_TRUNCATE, oldsize, size, &t);
929 if (ftruncate(fd, (off_t)size) == -1) {
930 prt("ftruncate1: %x\n", size);
931 prterr("dotruncate: ftruncate");
934 if (!quiet && debug > 1) {
935 gettimeofday(&t, NULL);
936 prt(" %lu.%06lu trunc done\n", t.tv_sec, t.tv_usec);
947 if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
948 prterr("writefileimage: lseek");
951 iret = write(fd, good_buf, file_size);
952 if ((off_t)iret != file_size) {
954 prterr("writefileimage: write");
956 prt("short write: 0x%x bytes instead of 0x%llx\n",
957 iret, (unsigned long long)file_size);
960 if (lite ? 0 : ftruncate(fd, file_size) == -1) {
961 prt("ftruncate2: %llx\n", (unsigned long long)file_size);
962 prterr("writefileimage: ftruncate");
972 struct test_file *tf = get_tf();
974 if (testcalls <= simulatedopcount)
977 gettimeofday(&t, NULL);
978 log4(OP_CLOSEOPEN, file_size, (unsigned)file_size, 0, &t);
981 prt("%06lu %lu.%06lu close/open\n", testcalls, t.tv_sec,
984 prterr("docloseopen: close");
987 if (!quiet && debug > 1) {
988 gettimeofday(&t, NULL);
989 prt(" %lu.%06lu close done\n", t.tv_sec, t.tv_usec);
991 tf->fd = open(tf->path, O_RDWR, 0);
993 prterr("docloseopen: open");
996 if (!quiet && debug > 1) {
997 gettimeofday(&t, NULL);
998 prt(" %lu.%06lu open done\n", t.tv_sec, t.tv_usec);
1006 unsigned long offset;
1007 unsigned long size = maxoplen;
1008 unsigned long rv = random();
1009 unsigned long op = rv % (3 + !lite + mapped_writes);
1011 /* turn off the map read if necessary */
1013 if (op == 2 && !mapped_reads)
1016 if (simulatedopcount > 0 && testcalls == simulatedopcount)
1021 if (debugstart > 0 && testcalls >= debugstart)
1024 if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
1025 prt("%lu...\n", testcalls);
1032 * MAPWRITE: op = 3 or 4
1034 if (lite ? 0 : op == 3 && (style & 1) == 0) /* vanilla truncate? */
1035 dotruncate(random() % maxfilelen);
1038 size = random() % (maxoplen+1);
1039 if (lite ? 0 : op == 3)
1043 if (op == 1 || op == (lite ? 3 : 4)) {
1044 offset %= maxfilelen;
1045 if (offset + size > maxfilelen)
1046 size = maxfilelen - offset;
1048 domapwrite(offset, size);
1050 dowrite(offset, size);
1053 offset %= file_size;
1056 if (offset + size > file_size)
1057 size = file_size - offset;
1059 domapread(offset, size);
1061 doread(offset, size);
1065 if (sizechecks && testcalls > simulatedopcount)
1067 if (closeprob && (rv >> 3) < (1 << 28) / closeprob)
1077 prt("signal %d\n", sig);
1078 prt("testcalls = %lu\n", testcalls);
1086 fprintf(stdout, "usage: %s",
1087 "fsx [-dnqLOW] [-b opnum] [-c Prob] [-l flen] [-m "
1088 "start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t "
1089 "truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] "
1090 "[ -I random|rotate ] fname [additional paths to fname..]\n"
1091 " -b opnum: beginning operation number (default 1)\n"
1092 " -c P: 1 in P chance of file close+open at each op (default infinity)\n"
1093 " -d: debug output for all operations [-d -d = more debugging]\n"
1094 " -l flen: the upper bound on file size (default 262144)\n"
1095 " -m startop:endop: monitor (print debug output) specified byte rang"
1096 "(default 0:infinity)\n"
1097 " -n: no verifications of file size\n"
1098 " -o oplen: the upper bound on operation size (default 65536)\n"
1099 " -p progressinterval: debug output at specified operation interval\n"
1100 " -q: quieter operation\n"
1101 " -r readbdy: 4096 would make reads page aligned (default 1)\n"
1102 " -s style: 1 gives smaller truncates (default 0)\n"
1103 " -t truncbdy: 4096 would make truncates page aligned (default 1)\n"
1104 " -w writebdy: 4096 would make writes page aligned (default 1)\n"
1105 " -D startingop: debug output starting at specified operation\n"
1106 " -L: fsxLite - no file creations & no file size changes\n"
1107 " -N numops: total # operations to do (default infinity)\n"
1108 " -O: use oplen (see -o flag) for every op (default random)\n"
1109 " -P: save .fsxlog and .fsxgood files in dirpath (default ./)\n"
1110 " -S seed: for random # generator (default 1) 0 gets timestamp\n"
1111 " -W: mapped write operations DISabled\n"
1112 " -R: read() system calls only (mapped reads disabled)\n"
1113 " -I: When multiple paths to the file are given each operation uses"
1114 " a different path. Iterate through them in order with 'rotate'"
1115 " or chose then at 'random'. (defaults to random)\n"
1116 " fname: this filename is REQUIRED (no default)\n");
1122 getnum(char *s, char **e)
1127 ret = strtol(s, e, 0);
1155 main(int argc, char **argv)
1164 page_size = getpagesize();
1165 page_mask = page_size - 1;
1167 setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
1169 while ((ch = getopt(argc, argv,
1170 "b:c:dl:m:no:p:qr:s:t:w:D:I:LN:OP:RS:W"))
1174 simulatedopcount = getnum(optarg, &endp);
1176 fprintf(stdout, "Will begin at operation"
1179 if (simulatedopcount == 0)
1181 simulatedopcount -= 1;
1184 closeprob = getnum(optarg, &endp);
1187 "Chance of close/open is 1 in %d\n",
1196 maxfilelen = getnum(optarg, &endp);
1197 if (maxfilelen <= 0)
1201 monitorstart = getnum(optarg, &endp);
1202 if (monitorstart < 0)
1204 if (!endp || *endp++ != ':')
1206 monitorend = getnum(endp, &endp);
1209 if (monitorend == 0)
1210 monitorend = -1; /* aka infinity */
1216 maxoplen = getnum(optarg, &endp);
1221 progressinterval = getnum(optarg, &endp);
1222 if (progressinterval < 0)
1229 readbdy = getnum(optarg, &endp);
1234 style = getnum(optarg, &endp);
1235 if (style < 0 || style > 1)
1239 truncbdy = getnum(optarg, &endp);
1244 writebdy = getnum(optarg, &endp);
1249 debugstart = getnum(optarg, &endp);
1254 assign_fd_policy(optarg);
1260 numops = getnum(optarg, &endp);
1268 strncpy(goodfile, optarg, sizeof(goodfile));
1269 strcat(goodfile, "/");
1270 strncpy(logfile, optarg, sizeof(logfile));
1271 strcat(logfile, "/");
1278 seed = getnum(optarg, &endp);
1280 seed = time(0) % 10000;
1282 fprintf(stdout, "Seed set to %d\n", seed);
1289 fprintf(stdout, "mapped writes DISABLED\n");
1302 signal(SIGHUP, cleanup);
1303 signal(SIGINT, cleanup);
1304 signal(SIGPIPE, cleanup);
1305 signal(SIGALRM, cleanup);
1306 signal(SIGTERM, cleanup);
1307 signal(SIGXCPU, cleanup);
1308 signal(SIGXFSZ, cleanup);
1309 signal(SIGVTALRM, cleanup);
1310 signal(SIGUSR1, cleanup);
1311 signal(SIGUSR2, cleanup);
1313 initstate(seed, state, 256);
1316 open_test_files(argv, argc);
1318 strncat(goodfile, dirpath ? basename(fname) : fname, 256);
1319 strcat (goodfile, ".fsxgood");
1320 fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
1321 if (fsxgoodfd < 0) {
1325 strncat(logfile, dirpath ? basename(fname) : fname, 256);
1326 strcat (logfile, ".fsxlog");
1327 fsxlogf = fopen(logfile, "w");
1328 if (fsxlogf == NULL) {
1335 file_size = maxfilelen = lseek(fd, (off_t)0, SEEK_END);
1336 if (file_size == (off_t)-1) {
1338 warn("main: lseek eof");
1341 ret = lseek(fd, (off_t)0, SEEK_SET);
1342 if (ret == (off_t)-1) {
1344 warn("main: lseek 0");
1348 original_buf = (char *) malloc(maxfilelen);
1349 for (i = 0; i < maxfilelen; i++)
1350 original_buf[i] = random() % 256;
1351 good_buf = (char *) malloc(maxfilelen);
1352 memset(good_buf, '\0', maxfilelen);
1353 temp_buf = (char *) malloc(maxoplen);
1354 memset(temp_buf, '\0', maxoplen);
1355 if (lite) { /* zero entire existing file */
1359 written = write(fd, good_buf, (size_t)maxfilelen);
1360 if (written != maxfilelen) {
1361 if (written == -1) {
1363 warn("main: error on write");
1365 warn("main: short write, 0x%x bytes instead"
1367 (unsigned)written, maxfilelen);
1373 while (numops == -1 || numops--)
1377 prt("All operations completed A-OK!\n");