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.2 (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
35 * Checks for mmap last-page zero fill.
37 * $FreeBSD: src/tools/regression/fsx/fsx.c,v 1.2 2003/04/23 23:42:23 jkh Exp $
40 #include <sys/param.h>
54 #define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */
57 * A log entry is an operation and a bunch of arguments.
67 struct log_entry oplog[LOGSIZE]; /* the log */
68 int logptr = 0; /* current position in log */
69 int logcount = 0; /* total ops */
73 static void log4(int operation, int arg0, int arg1, int arg2);
74 static void vwarnc(int code, const char *fmt, va_list ap);
75 static void warn(const char * fmt, ...);
76 static void prt(const char *fmt, ...);
77 static void prterr(const char *prefix);
78 static void logdump(void);
79 static void save_buffer(char *buffer, off_t bufferlength, int fd);
80 static void report_failure(int status);
81 static void check_buffers(unsigned offset, unsigned size);
82 static void check_trunc_hack(void);
83 static void check_size(void);
84 static void doread(unsigned offset, unsigned size);
85 static void check_eofpage(const char *s, unsigned offset, char *p, int size);
86 static void domapread(unsigned offset, unsigned size);
87 static void gendata(char *original_buf, char *good_buf,
88 unsigned offset, unsigned size);
89 static void dowrite(unsigned offset, unsigned size);
90 static void domapwrite(unsigned offset, unsigned size);
91 static void dotruncate(unsigned size);
92 static void docloseopen(void);
93 static void test(void);
94 static void segv(int sig);
95 static void cleanup(int sig);
96 static void usage(void);
97 static int getnum(char *s, char **e);
105 #define OP_TRUNCATE 3
106 #define OP_CLOSEOPEN 4
108 #define OP_MAPWRITE 6
114 char *original_buf; /* a pointer to the original data */
115 char *good_buf; /* a pointer to the correct data */
116 char *temp_buf; /* a pointer to the current data */
117 char *fname; /* name of our test file */
118 int fd; /* fd for our test file */
123 unsigned long testcalls = 0; /* calls to function "test" */
125 unsigned long simulatedopcount = 0; /* -b flag */
126 int closeprob = 0; /* -c flag */
127 int debug = 0; /* -d flag */
128 unsigned long debugstart = 0; /* -D flag */
129 unsigned long maxfilelen = 256 * 1024; /* -l flag */
130 int sizechecks = 1; /* -n flag disables them */
131 int maxoplen = 64 * 1024; /* -o flag */
132 int quiet = 0; /* -q flag */
133 unsigned long progressinterval = 0; /* -p flag */
134 int readbdy = 1; /* -r flag */
135 int style = 0; /* -s flag */
136 int truncbdy = 1; /* -t flag */
137 int writebdy = 1; /* -w flag */
138 long monitorstart = -1; /* -m flag */
139 long monitorend = -1; /* -m flag */
140 int lite = 0; /* -L flag */
141 long numops = -1; /* -N flag */
142 int randomoplen = 1; /* -O flag disables it */
143 int seed = 1; /* -S flag */
144 int mapped_writes = 1; /* -W flag disables */
145 int mapped_reads = 1; /* -R flag disables it */
147 FILE * fsxlogf = NULL;
154 vwarnc(int code, const char *fmt, va_list ap)
156 fprintf(stderr, "fsx: ");
158 vfprintf(stderr, fmt, ap);
159 fprintf(stderr, ": ");
161 fprintf(stderr, "%s\n", strerror(code));
166 warn(const char * fmt, ...)
170 vwarnc(errno, fmt, ap);
177 prt(const char *fmt, ...)
182 vfprintf(stdout, fmt, args);
186 vfprintf(fsxlogf, fmt, args);
192 prterr(const char *prefix)
194 prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno));
198 log4(int operation, int arg0, int arg1, int arg2)
200 struct log_entry *le;
203 le->operation = operation;
205 le->operation = ~ le->operation;
211 if (logptr >= LOGSIZE)
221 struct log_entry *lp;
223 prt("LOG DUMP (%d total operations):\n", logcount);
224 if (logcount < LOGSIZE) {
231 for ( ; count > 0; count--) {
234 opnum = i+1 + rounddown(logcount, LOGSIZE);
235 prt("%d(%d mod 256): ", opnum, opnum%256);
237 if ((closeopen = lp->operation < 0))
238 lp->operation = ~ lp->operation;
240 switch (lp->operation) {
242 prt("MAPREAD\t0x%x thru 0x%x\t(0x%x bytes)",
243 lp->args[0], lp->args[0] + lp->args[1] - 1,
245 if (badoff >= lp->args[0] && badoff <
246 lp->args[0] + lp->args[1])
250 prt("MAPWRITE\t0x%x thru 0x%x\t(0x%x bytes)",
251 lp->args[0], lp->args[0] + lp->args[1] - 1,
253 if (badoff >= lp->args[0] && badoff <
254 lp->args[0] + lp->args[1])
258 prt("READ\t0x%x thru 0x%x\t(0x%x bytes)",
259 lp->args[0], lp->args[0] + lp->args[1] - 1,
261 if (badoff >= lp->args[0] &&
262 badoff < lp->args[0] + lp->args[1])
266 prt("WRITE\t0x%x thru 0x%x\t(0x%x bytes)",
267 lp->args[0], lp->args[0] + lp->args[1] - 1,
269 if (lp->args[0] > lp->args[2])
271 else if (lp->args[0] + lp->args[1] > lp->args[2])
273 if ((badoff >= lp->args[0] || badoff >=lp->args[2]) &&
274 badoff < lp->args[0] + lp->args[1])
278 down = lp->args[0] < lp->args[1];
279 prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
280 down ? "DOWN" : "UP", lp->args[1], lp->args[0]);
281 if (badoff >= lp->args[!down] &&
282 badoff < lp->args[!!down])
286 prt("SKIPPED (no operation)");
289 prt("BOGUS LOG ENTRY (operation code = %d)!",
293 prt("\n\t\tCLOSE/OPEN");
303 save_buffer(char *buffer, off_t bufferlength, int xfd)
306 ssize_t byteswritten;
308 if (xfd <= 0 || bufferlength == 0)
311 if (bufferlength > SSIZE_MAX) {
312 prt("fsx flaw: overflow in save_buffer\n");
316 off_t size_by_seek = lseek(xfd, (off_t)0, SEEK_END);
317 if (size_by_seek == (off_t)-1)
318 prterr("save_buffer: lseek eof");
319 else if (bufferlength > size_by_seek) {
320 warn("save_buffer: .fsxgood file too short... "
321 "will save 0x%jx bytes instead of 0x%llx\n",
322 (intmax_t)size_by_seek,
323 (intmax_t)bufferlength);
324 bufferlength = size_by_seek;
328 ret = lseek(xfd, (off_t)0, SEEK_SET);
329 if (ret == (off_t)-1)
330 prterr("save_buffer: lseek 0");
332 byteswritten = write(xfd, buffer, (size_t)bufferlength);
333 if (byteswritten != bufferlength) {
334 if (byteswritten == -1)
335 prterr("save_buffer write");
337 warn("save_buffer: short write, "
338 "0x%x bytes instead of 0x%jx\n",
339 (unsigned)byteswritten,
340 (intmax_t)bufferlength);
347 report_failure(int status)
353 save_buffer(good_buf, file_size, fsxgoodfd);
354 prt("Correct content saved for comparison\n");
355 prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n",
364 #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
365 *(((unsigned char *)(cp)) + 1)))
369 check_buffers(unsigned offset, unsigned size)
377 if (memcmp(good_buf + offset, temp_buf, size) != 0) {
378 prt("READ BAD DATA: offset = 0x%x, size = 0x%x\n",
380 prt("OFFSET\t\tGOOD\tBAD\tRANGE\n");
382 c = good_buf[offset];
386 bad = short_at(&temp_buf[i]);
387 prt("0x%08x\t0x%04x\t0x%04x", offset,
388 short_at(&good_buf[offset]), bad);
389 op = temp_buf[offset & 1 ? i+1 : i];
401 prt("operation# (mod 256) for the bad data may be %u\n", ((unsigned)op & 0xff));
403 prt("operation# (mod 256) for the bad data unknown, check HOLE and EXTEND ops\n");
405 prt("????????????????\n");
417 if (fstat(fd, &statbuf)) {
418 prterr("check_size: fstat");
419 statbuf.st_size = -1;
421 size_by_seek = lseek(fd, (off_t)0, SEEK_END);
422 if (file_size != statbuf.st_size || file_size != size_by_seek) {
423 prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
424 (unsigned long long)file_size,
425 (unsigned long long)statbuf.st_size,
426 (unsigned long long)size_by_seek);
433 check_trunc_hack(void)
437 ftruncate(fd, (off_t)0);
438 ftruncate(fd, (off_t)100000);
440 if (statbuf.st_size != (off_t)100000) {
441 prt("no extend on truncate! not posix!\n");
444 ftruncate(fd, (off_t)0);
449 doread(unsigned offset, unsigned size)
454 offset -= offset % readbdy;
456 if (!quiet && testcalls > simulatedopcount)
457 prt("skipping zero size read\n");
458 log4(OP_SKIPPED, OP_READ, offset, size);
461 if (size + offset > file_size) {
462 if (!quiet && testcalls > simulatedopcount)
463 prt("skipping seek/read past end of file\n");
464 log4(OP_SKIPPED, OP_READ, offset, size);
468 log4(OP_READ, offset, size, 0);
470 if (testcalls <= simulatedopcount)
473 if (!quiet && ((progressinterval &&
474 testcalls % progressinterval == 0) ||
476 (monitorstart == -1 ||
477 (offset + size > monitorstart &&
478 (monitorend == -1 || offset <= monitorend))))))
479 prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
480 offset, offset + size - 1, size);
481 ret = lseek(fd, (off_t)offset, SEEK_SET);
482 if (ret == (off_t)-1) {
483 prterr("doread: lseek");
486 iret = read(fd, temp_buf, size);
489 prterr("doread: read");
491 prt("short read: 0x%x bytes instead of 0x%x\n",
495 check_buffers(offset, size);
500 check_eofpage(const char *s, unsigned offset, char *p, int size)
502 intptr_t last_page, should_be_zero;
504 if (offset + size <= (file_size & ~page_mask))
507 * we landed in the last page of the file
508 * test to make sure the VM system provided 0's
509 * beyond the true end of the file mapping
510 * (as required by mmap def in 1996 posix 1003.1)
512 last_page = ((intptr_t)p + (offset & page_mask) + size) & ~(intptr_t)page_mask;
514 for (should_be_zero = last_page + (file_size & page_mask);
515 should_be_zero < last_page + page_size;
517 if (*(char *)should_be_zero) {
518 prt("Mapped %s: non-zero data past EOF (0x%llx) page offset 0x%x is 0x%04x\n",
519 s, file_size - 1, should_be_zero & page_mask,
520 *(char *)(should_be_zero));
528 domapread(unsigned offset, unsigned size)
534 offset -= offset % readbdy;
536 if (!quiet && testcalls > simulatedopcount)
537 prt("skipping zero size read\n");
538 log4(OP_SKIPPED, OP_MAPREAD, offset, size);
541 if (size + offset > file_size) {
542 if (!quiet && testcalls > simulatedopcount)
543 prt("skipping seek/read past end of file\n");
544 log4(OP_SKIPPED, OP_MAPREAD, offset, size);
548 log4(OP_MAPREAD, offset, size, 0);
550 if (testcalls <= simulatedopcount)
553 if (!quiet && ((progressinterval &&
554 testcalls % progressinterval == 0) ||
556 (monitorstart == -1 ||
557 (offset + size > monitorstart &&
558 (monitorend == -1 || offset <= monitorend))))))
559 prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
560 offset, offset + size - 1, size);
562 pg_offset = offset & page_mask;
563 map_size = pg_offset + size;
565 if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_FILE | MAP_SHARED, fd,
566 (off_t)(offset - pg_offset))) == (char *)-1) {
567 prterr("domapread: mmap");
570 if (setjmp(jmpbuf) == 0) {
572 memcpy(temp_buf, p + pg_offset, size);
573 check_eofpage("Read", offset, p, size);
576 report_failure(1901);
579 if (munmap(p, map_size) != 0) {
580 prterr("domapread: munmap");
584 check_buffers(offset, size);
589 gendata(char *obuf, char *gbuf, unsigned offset, unsigned size)
592 gbuf[offset] = testcalls % 256;
594 gbuf[offset] += obuf[offset];
601 dowrite(unsigned offset, unsigned size)
606 offset -= offset % writebdy;
608 if (!quiet && testcalls > simulatedopcount)
609 prt("skipping zero size write\n");
610 log4(OP_SKIPPED, OP_WRITE, offset, size);
614 log4(OP_WRITE, offset, size, file_size);
616 gendata(original_buf, good_buf, offset, size);
617 if (file_size < offset + size) {
618 if (file_size < offset)
619 memset(good_buf + file_size, '\0', offset - file_size);
620 file_size = offset + size;
622 warn("Lite file size bug in fsx!");
627 if (testcalls <= simulatedopcount)
630 if (!quiet && ((progressinterval &&
631 testcalls % progressinterval == 0) ||
633 (monitorstart == -1 ||
634 (offset + size > monitorstart &&
635 (monitorend == -1 || offset <= monitorend))))))
636 prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
637 offset, offset + size - 1, size);
638 ret = lseek(fd, (off_t)offset, SEEK_SET);
639 if (ret == (off_t)-1) {
640 prterr("dowrite: lseek");
643 iret = write(fd, good_buf + offset, size);
646 prterr("dowrite: write");
648 prt("short write: 0x%x bytes instead of 0x%x\n",
656 domapwrite(unsigned offset, unsigned size)
663 offset -= offset % writebdy;
665 if (!quiet && testcalls > simulatedopcount)
666 prt("skipping zero size write\n");
667 log4(OP_SKIPPED, OP_MAPWRITE, offset, size);
670 cur_filesize = file_size;
672 log4(OP_MAPWRITE, offset, size, 0);
674 gendata(original_buf, good_buf, offset, size);
675 if (file_size < offset + size) {
676 if (file_size < offset)
677 memset(good_buf + file_size, '\0', offset - file_size);
678 file_size = offset + size;
680 warn("Lite file size bug in fsx!");
685 if (testcalls <= simulatedopcount)
688 if (!quiet && ((progressinterval &&
689 testcalls % progressinterval == 0) ||
691 (monitorstart == -1 ||
692 (offset + size > monitorstart &&
693 (monitorend == -1 || offset <= monitorend))))))
694 prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
695 offset, offset + size - 1, size);
697 if (file_size > cur_filesize) {
698 if (ftruncate(fd, file_size) == -1) {
699 prterr("domapwrite: ftruncate");
703 pg_offset = offset & page_mask;
704 map_size = pg_offset + size;
706 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
707 MAP_FILE | MAP_SHARED, fd,
708 (off_t)(offset - pg_offset))) == (char *)-1) {
709 prterr("domapwrite: mmap");
712 if (setjmp(jmpbuf) == 0) {
714 memcpy(p + pg_offset, good_buf + offset, size);
715 if (msync(p, map_size, 0) != 0) {
716 prterr("domapwrite: msync");
719 check_eofpage("Write", offset, p, size);
722 report_failure(2021);
725 if (munmap(p, map_size) != 0) {
726 prterr("domapwrite: munmap");
733 dotruncate(unsigned size)
735 int oldsize = file_size;
737 size -= size % truncbdy;
738 if (size > biggest) {
740 if (!quiet && testcalls > simulatedopcount)
741 prt("truncating to largest ever: 0x%x\n", size);
744 log4(OP_TRUNCATE, size, (unsigned)file_size, 0);
746 if (size > file_size)
747 memset(good_buf + file_size, '\0', size - file_size);
750 if (testcalls <= simulatedopcount)
753 if ((progressinterval && testcalls % progressinterval == 0) ||
754 (debug && (monitorstart == -1 || monitorend == -1 ||
755 size <= monitorend)))
756 prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls, oldsize, size);
757 if (ftruncate(fd, (off_t)size) == -1) {
758 prt("ftruncate1: %x\n", size);
759 prterr("dotruncate: ftruncate");
770 if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
771 prterr("writefileimage: lseek");
774 iret = write(fd, good_buf, file_size);
775 if ((off_t)iret != file_size) {
777 prterr("writefileimage: write");
779 prt("short write: 0x%x bytes instead of 0x%jx\n",
780 iret, (intmax_t)file_size);
783 if (lite ? 0 : ftruncate(fd, file_size) == -1) {
784 prt("ftruncate2: %jx\n", (intmax_t)file_size);
785 prterr("writefileimage: ftruncate");
794 if (testcalls <= simulatedopcount)
798 prt("%lu close/open\n", testcalls);
800 prterr("docloseopen: close");
803 fd = open(fname, O_RDWR, 0);
805 prterr("docloseopen: open");
814 unsigned long offset;
815 unsigned long size = maxoplen;
816 unsigned long rv = random();
817 unsigned long op = rv % (3 + !lite + mapped_writes);
819 /* turn off the map read if necessary */
821 if (op == 2 && !mapped_reads)
824 if (simulatedopcount > 0 && testcalls == simulatedopcount)
830 closeopen = (rv >> 3) < (1 << 28) / closeprob;
832 if (debugstart > 0 && testcalls >= debugstart)
835 if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
836 prt("%lu...\n", testcalls);
843 * MAPWRITE: op = 3 or 4
845 if (lite ? 0 : op == 3 && style == 0) /* vanilla truncate? */
846 dotruncate(random() % maxfilelen);
849 size = random() % (maxoplen+1);
850 if (lite ? 0 : op == 3)
854 if (op == 1 || op == (lite ? 3 : 4)) {
855 offset %= maxfilelen;
856 if (offset + size > maxfilelen)
857 size = maxfilelen - offset;
859 domapwrite(offset, size);
861 dowrite(offset, size);
867 if (offset + size > file_size)
868 size = file_size - offset;
870 domapread(offset, size);
872 doread(offset, size);
876 if (sizechecks && testcalls > simulatedopcount)
890 report_failure(9999);
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 -l flen: the upper bound on file size (default 262144)\n\
913 -m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\
914 -n: no verifications of file size\n\
915 -o oplen: the upper bound on operation size (default 65536)\n\
916 -p progressinterval: debug output at specified operation interval\n\
917 -q: quieter operation\n\
918 -r readbdy: 4096 would make reads page aligned (default 1)\n\
919 -s style: 1 gives smaller truncates (default 0)\n\
920 -t truncbdy: 4096 would make truncates page aligned (default 1)\n\
921 -w writebdy: 4096 would make writes page aligned (default 1)\n\
922 -D startingop: debug output starting at specified operation\n\
923 -L: fsxLite - no file creations & no file size changes\n\
924 -N numops: total # operations to do (default infinity)\n\
925 -O: use oplen (see -o flag) for every op (default random)\n\
926 -P dirpath: save .fsxlog and .fsxgood files in dirpath (default ./)\n\
927 -S seed: for random # generator (default 1) 0 gets timestamp\n\
928 -W: mapped write operations DISabled\n\
929 -R: mapped read operations DISabled)\n\
930 fname: this filename is REQUIRED (no default)\n");
936 getnum(char *s, char **e)
941 ret = strtol(s, e, 0);
970 main(int argc, char **argv)
980 page_size = getpagesize();
981 page_mask = page_size - 1;
983 setvbuf(stdout, NULL, _IOLBF, 0); /* line buffered stdout */
985 while ((ch = getopt(argc, argv, "b:c:dl:m:no:p:qr:s:t:w:D:LN:OP:RS:W"))
989 simulatedopcount = getnum(optarg, &endp);
991 fprintf(stdout, "Will begin at operation %ld\n",
993 if (simulatedopcount == 0)
995 simulatedopcount -= 1;
998 closeprob = getnum(optarg, &endp);
1001 "Chance of close/open is 1 in %d\n",
1010 maxfilelen = getnum(optarg, &endp);
1011 if (maxfilelen <= 0)
1015 monitorstart = getnum(optarg, &endp);
1016 if (monitorstart < 0)
1018 if (!endp || *endp++ != ':')
1020 monitorend = getnum(endp, &endp);
1023 if (monitorend == 0)
1024 monitorend = -1; /* aka infinity */
1030 maxoplen = getnum(optarg, &endp);
1035 progressinterval = getnum(optarg, &endp);
1036 if ((int)progressinterval < 0)
1043 readbdy = getnum(optarg, &endp);
1048 style = getnum(optarg, &endp);
1049 if (style < 0 || style > 1)
1053 truncbdy = getnum(optarg, &endp);
1058 writebdy = getnum(optarg, &endp);
1063 debugstart = getnum(optarg, &endp);
1071 numops = getnum(optarg, &endp);
1079 strncpy(goodfile, optarg, sizeof(goodfile));
1080 strcat(goodfile, "/");
1081 strncpy(logfile, optarg, sizeof(logfile));
1082 strcat(logfile, "/");
1088 seed = getnum(optarg, &endp);
1090 seed = time(0) % 10000;
1092 fprintf(stdout, "Seed set to %d\n", seed);
1099 fprintf(stdout, "mapped writes DISABLED\n");
1112 signal(SIGHUP, cleanup);
1113 signal(SIGINT, cleanup);
1114 signal(SIGPIPE, cleanup);
1115 signal(SIGALRM, cleanup);
1116 signal(SIGTERM, cleanup);
1117 signal(SIGXCPU, cleanup);
1118 signal(SIGXFSZ, cleanup);
1119 signal(SIGVTALRM, cleanup);
1120 signal(SIGUSR1, cleanup);
1121 signal(SIGUSR2, cleanup);
1122 signal(SIGSEGV, segv);
1124 initstate(seed, state, 256);
1126 fd = open(fname, O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC), 0666);
1131 strncat(goodfile, fname, 256);
1132 strcat (goodfile, ".fsxgood");
1133 fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
1134 if (fsxgoodfd < 0) {
1138 strncat(logfile, fname, 256);
1139 strcat (logfile, ".fsxlog");
1140 fsxlogf = fopen(logfile, "w");
1141 if (fsxlogf == NULL) {
1147 file_size = maxfilelen = lseek(fd, (off_t)0, SEEK_END);
1148 if (file_size == (off_t)-1) {
1150 warn("main: lseek eof");
1153 ret = lseek(fd, (off_t)0, SEEK_SET);
1154 if (ret == (off_t)-1) {
1156 warn("main: lseek 0");
1160 original_buf = (char *) malloc(maxfilelen);
1161 for (i = 0; i < maxfilelen; i++)
1162 original_buf[i] = random() % 256;
1163 good_buf = (char *) malloc(maxfilelen);
1164 memset(good_buf, '\0', maxfilelen);
1165 temp_buf = (char *) malloc(maxoplen);
1166 memset(temp_buf, '\0', maxoplen);
1167 if (lite) { /* zero entire existing file */
1170 written = write(fd, good_buf, (size_t)maxfilelen);
1171 if (written != maxfilelen) {
1172 if (written == -1) {
1174 warn("main: error on write");
1176 warn("main: short write, 0x%x bytes instead of 0x%x\n",
1177 (unsigned)written, maxfilelen);
1183 while (numops == -1 || numops--)
1190 prt("All operations completed A-OK!\n");