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
97 char *original_buf
; /* a pointer to the original data */
98 char *good_buf
; /* a pointer to the correct data */
99 char *temp_buf
; /* a pointer to the current data */
100 char *fname
; /* name of our test file */
101 int fd
; /* fd for our test file */
106 unsigned long testcalls
= 0; /* calls to function "test" */
108 unsigned long simulatedopcount
= 0; /* -b flag */
109 int closeprob
= 0; /* -c flag */
110 int debug
= 0; /* -d flag */
111 unsigned long debugstart
= 0; /* -D flag */
112 unsigned long maxfilelen
= 256 * 1024; /* -l flag */
113 int sizechecks
= 1; /* -n flag disables them */
114 int maxoplen
= 64 * 1024; /* -o flag */
115 int quiet
= 0; /* -q flag */
116 unsigned long progressinterval
= 0; /* -p flag */
117 int readbdy
= 1; /* -r flag */
118 int style
= 0; /* -s flag */
119 int truncbdy
= 1; /* -t flag */
120 int writebdy
= 1; /* -w flag */
121 long monitorstart
= -1; /* -m flag */
122 long monitorend
= -1; /* -m flag */
123 int lite
= 0; /* -L flag */
124 long numops
= -1; /* -N flag */
125 int randomoplen
= 1; /* -O flag disables it */
126 int seed
= 1; /* -S flag */
127 int mapped_writes
= 1; /* -W flag disables */
128 int mapped_reads
= 1; /* -R flag disables it */
130 FILE * fsxlogf
= NULL
;
136 vwarnc(code
, fmt
, ap
)
141 fprintf(stderr
, "fsx: ");
143 vfprintf(stderr
, fmt
, ap
);
144 fprintf(stderr
, ": ");
146 fprintf(stderr
, "%s\n", strerror(code
));
151 warn(const char * fmt
, ...)
155 vwarnc(errno
, fmt
, ap
);
166 vfprintf(stdout
, fmt
, args
);
171 vfprintf(fsxlogf
, fmt
, args
);
179 prt("%s%s%s\n", prefix
, prefix
? ": " : "", strerror(errno
));
184 log4(int operation
, int arg0
, int arg1
, int arg2
)
186 struct log_entry
*le
;
189 le
->operation
= operation
;
191 le
->operation
= ~ le
->operation
;
197 if (logptr
>= LOGSIZE
)
206 struct log_entry
*lp
;
208 prt("LOG DUMP (%d total operations):\n", logcount
);
209 if (logcount
< LOGSIZE
) {
216 for ( ; count
> 0; count
--) {
219 opnum
= i
+1 + (logcount
/LOGSIZE
)*LOGSIZE
;
220 prt("%d(%d mod 256): ", opnum
, opnum
%256);
222 if ((closeopen
= lp
->operation
< 0))
223 lp
->operation
= ~ lp
->operation
;
225 switch (lp
->operation
) {
227 prt("MAPREAD\t0x%x thru 0x%x\t(0x%x bytes)",
228 lp
->args
[0], lp
->args
[0] + lp
->args
[1] - 1,
230 if (badoff
>= lp
->args
[0] && badoff
<
231 lp
->args
[0] + lp
->args
[1])
235 prt("MAPWRITE 0x%x thru 0x%x\t(0x%x bytes)",
236 lp
->args
[0], lp
->args
[0] + lp
->args
[1] - 1,
238 if (badoff
>= lp
->args
[0] && badoff
<
239 lp
->args
[0] + lp
->args
[1])
243 prt("READ\t0x%x thru 0x%x\t(0x%x bytes)",
244 lp
->args
[0], lp
->args
[0] + lp
->args
[1] - 1,
246 if (badoff
>= lp
->args
[0] &&
247 badoff
< lp
->args
[0] + lp
->args
[1])
251 prt("WRITE\t0x%x thru 0x%x\t(0x%x bytes)",
252 lp
->args
[0], lp
->args
[0] + lp
->args
[1] - 1,
254 if (lp
->args
[0] > lp
->args
[2])
256 else if (lp
->args
[0] + lp
->args
[1] > lp
->args
[2])
258 if ((badoff
>= lp
->args
[0] || badoff
>=lp
->args
[2]) &&
259 badoff
< lp
->args
[0] + lp
->args
[1])
263 down
= lp
->args
[0] < lp
->args
[1];
264 prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
265 down
? "DOWN" : "UP", lp
->args
[1], lp
->args
[0]);
266 if (badoff
>= lp
->args
[!down
] &&
267 badoff
< lp
->args
[!!down
])
271 prt("SKIPPED (no operation)");
274 prt("BOGUS LOG ENTRY (operation code = %d)!",
278 prt("\n\t\tCLOSE/OPEN");
288 save_buffer(char *buffer
, off_t bufferlength
, int fd
)
291 ssize_t byteswritten
;
293 if (fd
<= 0 || bufferlength
== 0)
296 if (bufferlength
> SSIZE_MAX
) {
297 prt("fsx flaw: overflow in save_buffer\n");
301 off_t size_by_seek
= lseek(fd
, (off_t
)0, SEEK_END
);
302 if (size_by_seek
== (off_t
)-1)
303 prterr("save_buffer: lseek eof");
304 else if (bufferlength
> size_by_seek
) {
305 warn("save_buffer: .fsxgood file too short... will save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek
,
306 (unsigned long long)bufferlength
);
307 bufferlength
= size_by_seek
;
311 ret
= lseek(fd
, (off_t
)0, SEEK_SET
);
312 if (ret
== (off_t
)-1)
313 prterr("save_buffer: lseek 0");
315 byteswritten
= write(fd
, buffer
, (size_t)bufferlength
);
316 if (byteswritten
!= bufferlength
) {
317 if (byteswritten
== -1)
318 prterr("save_buffer write");
320 warn("save_buffer: short write, 0x%x bytes instead of 0x%llx\n",
321 (unsigned)byteswritten
,
322 (unsigned long long)bufferlength
);
328 report_failure(int status
)
334 save_buffer(good_buf
, file_size
, fsxgoodfd
);
335 prt("Correct content saved for comparison\n");
336 prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n",
345 #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
346 *(((unsigned char *)(cp)) + 1)))
349 check_buffers(unsigned offset
, unsigned size
)
357 if (memcmp(good_buf
+ offset
, temp_buf
, size
) != 0) {
358 prt("READ BAD DATA: offset = 0x%x, size = 0x%x\n",
360 prt("OFFSET\tGOOD\tBAD\tRANGE\n");
362 c
= good_buf
[offset
];
366 bad
= short_at(&temp_buf
[i
]);
367 prt("0x%5x\t0x%04x\t0x%04x", offset
,
368 short_at(&good_buf
[offset
]), bad
);
369 op
= temp_buf
[offset
& 1 ? i
+1 : i
];
381 prt("operation# (mod 256) for the bad data may be %u\n", ((unsigned)op
& 0xff));
383 prt("operation# (mod 256) for the bad data 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");
424 ftruncate(fd
, (off_t
)0);
429 doread(unsigned offset
, unsigned size
)
434 offset
-= offset
% readbdy
;
436 if (!quiet
&& testcalls
> simulatedopcount
)
437 prt("skipping zero size read\n");
438 log4(OP_SKIPPED
, OP_READ
, offset
, size
);
441 if (size
+ offset
> file_size
) {
442 if (!quiet
&& testcalls
> simulatedopcount
)
443 prt("skipping seek/read past end of file\n");
444 log4(OP_SKIPPED
, OP_READ
, offset
, size
);
448 log4(OP_READ
, offset
, size
, 0);
450 if (testcalls
<= simulatedopcount
)
453 if (!quiet
&& ((progressinterval
&&
454 testcalls
% progressinterval
== 0) ||
456 (monitorstart
== -1 ||
457 (offset
+ size
> monitorstart
&&
458 (monitorend
== -1 || offset
<= monitorend
))))))
459 prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls
,
460 offset
, offset
+ size
- 1, size
);
461 ret
= lseek(fd
, (off_t
)offset
, SEEK_SET
);
462 if (ret
== (off_t
)-1) {
463 prterr("doread: lseek");
466 iret
= read(fd
, temp_buf
, size
);
469 prterr("doread: read");
471 prt("short read: 0x%x bytes instead of 0x%x\n",
475 check_buffers(offset
, size
);
480 check_eofpage(char *s
, unsigned offset
, char *p
, int size
)
482 uintptr_t last_page
, should_be_zero
;
484 if (offset
+ size
<= (file_size
& ~page_mask
))
487 * we landed in the last page of the file
488 * test to make sure the VM system provided 0's
489 * beyond the true end of the file mapping
490 * (as required by mmap def in 1996 posix 1003.1)
492 last_page
= ((uintptr_t)p
+ (offset
& page_mask
) + size
) & ~page_mask
;
494 for (should_be_zero
= last_page
+ (file_size
& page_mask
);
495 should_be_zero
< last_page
+ page_size
;
497 if (*(char *)should_be_zero
) {
498 prt("Mapped %s: non-zero data past EOF (0x%llx) page offset 0x%x is 0x%04x\n",
499 s
, file_size
- 1, should_be_zero
& page_mask
,
500 short_at(should_be_zero
));
507 domapread(unsigned offset
, unsigned size
)
513 offset
-= offset
% readbdy
;
515 if (!quiet
&& testcalls
> simulatedopcount
)
516 prt("skipping zero size read\n");
517 log4(OP_SKIPPED
, OP_MAPREAD
, offset
, size
);
520 if (size
+ offset
> file_size
) {
521 if (!quiet
&& testcalls
> simulatedopcount
)
522 prt("skipping seek/read past end of file\n");
523 log4(OP_SKIPPED
, OP_MAPREAD
, offset
, size
);
527 log4(OP_MAPREAD
, offset
, size
, 0);
529 if (testcalls
<= simulatedopcount
)
532 if (!quiet
&& ((progressinterval
&&
533 testcalls
% progressinterval
== 0) ||
535 (monitorstart
== -1 ||
536 (offset
+ size
> monitorstart
&&
537 (monitorend
== -1 || offset
<= monitorend
))))))
538 prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls
,
539 offset
, offset
+ size
- 1, size
);
541 pg_offset
= offset
& page_mask
;
542 map_size
= pg_offset
+ size
;
544 if ((p
= (char *)mmap(0, map_size
, PROT_READ
, MAP_FILE
| MAP_SHARED
, fd
,
545 (off_t
)(offset
- pg_offset
))) == (char *)-1) {
546 prterr("domapread: mmap");
549 memcpy(temp_buf
, p
+ pg_offset
, size
);
551 check_eofpage("Read", offset
, p
, size
);
553 if (munmap(p
, map_size
) != 0) {
554 prterr("domapread: munmap");
558 check_buffers(offset
, size
);
563 gendata(char *original_buf
, char *good_buf
, unsigned offset
, unsigned size
)
566 good_buf
[offset
] = testcalls
% 256;
568 good_buf
[offset
] += original_buf
[offset
];
575 dowrite(unsigned offset
, unsigned size
)
580 offset
-= offset
% writebdy
;
582 if (!quiet
&& testcalls
> simulatedopcount
)
583 prt("skipping zero size write\n");
584 log4(OP_SKIPPED
, OP_WRITE
, offset
, size
);
588 log4(OP_WRITE
, offset
, size
, file_size
);
590 gendata(original_buf
, good_buf
, offset
, size
);
591 if (file_size
< offset
+ size
) {
592 if (file_size
< offset
)
593 memset(good_buf
+ file_size
, '\0', offset
- file_size
);
594 file_size
= offset
+ size
;
596 warn("Lite file size bug in fsx!");
601 if (testcalls
<= simulatedopcount
)
604 if (!quiet
&& ((progressinterval
&&
605 testcalls
% progressinterval
== 0) ||
607 (monitorstart
== -1 ||
608 (offset
+ size
> monitorstart
&&
609 (monitorend
== -1 || offset
<= monitorend
))))))
610 prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls
,
611 offset
, offset
+ size
- 1, size
);
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
);
620 prterr("dowrite: write");
622 prt("short write: 0x%x bytes instead of 0x%x\n",
630 domapwrite(unsigned offset
, unsigned size
)
637 offset
-= offset
% writebdy
;
639 if (!quiet
&& testcalls
> simulatedopcount
)
640 prt("skipping zero size write\n");
641 log4(OP_SKIPPED
, OP_MAPWRITE
, offset
, size
);
644 cur_filesize
= file_size
;
646 log4(OP_MAPWRITE
, offset
, size
, 0);
648 gendata(original_buf
, good_buf
, offset
, size
);
649 if (file_size
< offset
+ size
) {
650 if (file_size
< offset
)
651 memset(good_buf
+ file_size
, '\0', offset
- file_size
);
652 file_size
= offset
+ size
;
654 warn("Lite file size bug in fsx!");
659 if (testcalls
<= simulatedopcount
)
662 if (!quiet
&& ((progressinterval
&&
663 testcalls
% progressinterval
== 0) ||
665 (monitorstart
== -1 ||
666 (offset
+ size
> monitorstart
&&
667 (monitorend
== -1 || offset
<= monitorend
))))))
668 prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls
,
669 offset
, offset
+ size
- 1, size
);
671 if (file_size
> cur_filesize
) {
672 if (ftruncate(fd
, file_size
) == -1) {
673 prterr("domapwrite: ftruncate");
677 pg_offset
= offset
& page_mask
;
678 map_size
= pg_offset
+ size
;
680 if ((p
= (char *)mmap(0, map_size
, PROT_READ
| PROT_WRITE
,
681 MAP_FILE
| MAP_SHARED
, fd
,
682 (off_t
)(offset
- pg_offset
))) == (char *)-1) {
683 prterr("domapwrite: mmap");
686 memcpy(p
+ pg_offset
, good_buf
+ offset
, size
);
687 if (msync(p
, map_size
, 0) != 0) {
688 prterr("domapwrite: msync");
692 check_eofpage("Write", offset
, p
, size
);
694 if (munmap(p
, map_size
) != 0) {
695 prterr("domapwrite: munmap");
702 dotruncate(unsigned size
)
704 int oldsize
= file_size
;
706 size
-= size
% truncbdy
;
707 if (size
> biggest
) {
709 if (!quiet
&& testcalls
> simulatedopcount
)
710 prt("truncating to largest ever: 0x%x\n", size
);
713 log4(OP_TRUNCATE
, size
, (unsigned)file_size
, 0);
715 if (size
> file_size
)
716 memset(good_buf
+ file_size
, '\0', size
- file_size
);
719 if (testcalls
<= simulatedopcount
)
722 if ((progressinterval
&& testcalls
% progressinterval
== 0) ||
723 (debug
&& (monitorstart
== -1 || monitorend
== -1 ||
724 size
<= monitorend
)))
725 prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls
, oldsize
, size
);
726 if (ftruncate(fd
, (off_t
)size
) == -1) {
727 prt("ftruncate1: %x\n", size
);
728 prterr("dotruncate: ftruncate");
739 if (lseek(fd
, (off_t
)0, SEEK_SET
) == (off_t
)-1) {
740 prterr("writefileimage: lseek");
743 iret
= write(fd
, good_buf
, file_size
);
744 if ((off_t
)iret
!= file_size
) {
746 prterr("writefileimage: write");
748 prt("short write: 0x%x bytes instead of 0x%llx\n",
749 iret
, (unsigned long long)file_size
);
752 if (lite
? 0 : ftruncate(fd
, file_size
) == -1) {
753 prt("ftruncate2: %llx\n", (unsigned long long)file_size
);
754 prterr("writefileimage: ftruncate");
763 if (testcalls
<= simulatedopcount
)
767 prt("%lu close/open\n", testcalls
);
769 prterr("docloseopen: close");
772 fd
= open(fname
, O_RDWR
, 0);
774 prterr("docloseopen: open");
783 unsigned long offset
;
784 unsigned long size
= maxoplen
;
785 unsigned long rv
= random();
786 unsigned long op
= rv
% (3 + !lite
+ mapped_writes
);
788 /* turn off the map read if necessary */
790 if (op
== 2 && !mapped_reads
)
793 if (simulatedopcount
> 0 && testcalls
== simulatedopcount
)
799 closeopen
= (rv
>> 3) < (1 << 28) / closeprob
;
801 if (debugstart
> 0 && testcalls
>= debugstart
)
804 if (!quiet
&& testcalls
< simulatedopcount
&& testcalls
% 100000 == 0)
805 prt("%lu...\n", testcalls
);
812 * MAPWRITE: op = 3 or 4
814 if (lite
? 0 : op
== 3 && style
== 0) /* vanilla truncate? */
815 dotruncate(random() % maxfilelen
);
818 size
= random() % (maxoplen
+1);
819 if (lite
? 0 : op
== 3)
823 if (op
== 1 || op
== (lite
? 3 : 4)) {
824 offset
%= maxfilelen
;
825 if (offset
+ size
> maxfilelen
)
826 size
= maxfilelen
- offset
;
828 domapwrite(offset
, size
);
830 dowrite(offset
, size
);
836 if (offset
+ size
> file_size
)
837 size
= file_size
- offset
;
839 domapread(offset
, size
);
841 doread(offset
, size
);
845 if (sizechecks
&& testcalls
> simulatedopcount
)
857 prt("signal %d\n", sig
);
858 prt("testcalls = %lu\n", testcalls
);
866 fprintf(stdout
, "usage: %s",
867 "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\
868 -b opnum: beginning operation number (default 1)\n\
869 -c P: 1 in P chance of file close+open at each op (default infinity)\n\
870 -d: debug output for all operations\n\
871 -l flen: the upper bound on file size (default 262144)\n\
872 -m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\
873 -n: no verifications of file size\n\
874 -o oplen: the upper bound on operation size (default 65536)\n\
875 -p progressinterval: debug output at specified operation interval\n\
876 -q: quieter operation\n\
877 -r readbdy: 4096 would make reads page aligned (default 1)\n\
878 -s style: 1 gives smaller truncates (default 0)\n\
879 -t truncbdy: 4096 would make truncates page aligned (default 1)\n\
880 -w writebdy: 4096 would make writes page aligned (default 1)\n\
881 -D startingop: debug output starting at specified operation\n\
882 -L: fsxLite - no file creations & no file size changes\n\
883 -N numops: total # operations to do (default infinity)\n\
884 -O: use oplen (see -o flag) for every op (default random)\n\
885 -P dirpath: save .fsxlog and .fsxgood files in dirpath (default ./)\n\
886 -S seed: for random # generator (default 1) 0 gets timestamp\n\
887 -W: mapped write operations DISabled\n\
888 -R: mapped read operations DISabled)\n\
889 fname: this filename is REQUIRED (no default)\n");
895 getnum(char *s
, char **e
)
900 ret
= strtol(s
, e
, 0);
929 main(int argc
, char **argv
)
939 page_size
= getpagesize();
940 page_mask
= page_size
- 1;
942 setvbuf(stdout
, (char *)0, _IOLBF
, 0); /* line buffered stdout */
944 while ((ch
= getopt(argc
, argv
, "b:c:dl:m:no:p:qr:s:t:w:D:LN:OP:RS:W"))
948 simulatedopcount
= getnum(optarg
, &endp
);
950 fprintf(stdout
, "Will begin at operation %ld\n",
952 if (simulatedopcount
== 0)
954 simulatedopcount
-= 1;
957 closeprob
= getnum(optarg
, &endp
);
960 "Chance of close/open is 1 in %d\n",
969 maxfilelen
= getnum(optarg
, &endp
);
974 monitorstart
= getnum(optarg
, &endp
);
975 if (monitorstart
< 0)
977 if (!endp
|| *endp
++ != ':')
979 monitorend
= getnum(endp
, &endp
);
983 monitorend
= -1; /* aka infinity */
989 maxoplen
= getnum(optarg
, &endp
);
994 progressinterval
= getnum(optarg
, &endp
);
995 if (progressinterval
< 0)
1002 readbdy
= getnum(optarg
, &endp
);
1007 style
= getnum(optarg
, &endp
);
1008 if (style
< 0 || style
> 1)
1012 truncbdy
= getnum(optarg
, &endp
);
1017 writebdy
= getnum(optarg
, &endp
);
1022 debugstart
= getnum(optarg
, &endp
);
1030 numops
= getnum(optarg
, &endp
);
1038 strncpy(goodfile
, optarg
, sizeof(goodfile
));
1039 strcat(goodfile
, "/");
1040 strncpy(logfile
, optarg
, sizeof(logfile
));
1041 strcat(logfile
, "/");
1047 seed
= getnum(optarg
, &endp
);
1049 seed
= time(0) % 10000;
1051 fprintf(stdout
, "Seed set to %d\n", seed
);
1058 fprintf(stdout
, "mapped writes DISABLED\n");
1071 signal(SIGHUP
, cleanup
);
1072 signal(SIGINT
, cleanup
);
1073 signal(SIGPIPE
, cleanup
);
1074 signal(SIGALRM
, cleanup
);
1075 signal(SIGTERM
, cleanup
);
1076 signal(SIGXCPU
, cleanup
);
1077 signal(SIGXFSZ
, cleanup
);
1078 signal(SIGVTALRM
, cleanup
);
1079 signal(SIGUSR1
, cleanup
);
1080 signal(SIGUSR2
, cleanup
);
1082 initstate(seed
, state
, 256);
1084 fd
= open(fname
, O_RDWR
|(lite
? 0 : O_CREAT
|O_TRUNC
), 0666);
1089 strncat(goodfile
, fname
, 256);
1090 strcat (goodfile
, ".fsxgood");
1091 fsxgoodfd
= open(goodfile
, O_RDWR
|O_CREAT
|O_TRUNC
, 0666);
1092 if (fsxgoodfd
< 0) {
1096 strncat(logfile
, fname
, 256);
1097 strcat (logfile
, ".fsxlog");
1098 fsxlogf
= fopen(logfile
, "w");
1099 if (fsxlogf
== NULL
) {
1105 file_size
= maxfilelen
= lseek(fd
, (off_t
)0, SEEK_END
);
1106 if (file_size
== (off_t
)-1) {
1108 warn("main: lseek eof");
1111 ret
= lseek(fd
, (off_t
)0, SEEK_SET
);
1112 if (ret
== (off_t
)-1) {
1114 warn("main: lseek 0");
1118 original_buf
= (char *) malloc(maxfilelen
);
1119 for (i
= 0; i
< maxfilelen
; i
++)
1120 original_buf
[i
] = random() % 256;
1121 good_buf
= (char *) malloc(maxfilelen
);
1122 memset(good_buf
, '\0', maxfilelen
);
1123 temp_buf
= (char *) malloc(maxoplen
);
1124 memset(temp_buf
, '\0', maxoplen
);
1125 if (lite
) { /* zero entire existing file */
1128 written
= write(fd
, good_buf
, (size_t)maxfilelen
);
1129 if (written
!= maxfilelen
) {
1130 if (written
== -1) {
1132 warn("main: error on write");
1134 warn("main: short write, 0x%x bytes instead of 0x%x\n",
1135 (unsigned)written
, maxfilelen
);
1141 while (numops
== -1 || numops
--)
1148 prt("All operations completed A-OK!\n");