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 $
38 * $DragonFly: src/tools/regression/fsx/fsx.c,v 1.1 2003/10/11 15:37:14 drhodus Exp $
42 #include <sys/types.h>
45 # include <sys/param.h>
64 #define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */
67 * A log entry is an operation and a bunch of arguments.
77 struct log_entry oplog
[LOGSIZE
]; /* the log */
78 int logptr
= 0; /* current position in log */
79 int logcount
= 0; /* total ops */
88 #define OP_CLOSEOPEN 4
96 char *original_buf
; /* a pointer to the original data */
97 char *good_buf
; /* a pointer to the correct data */
98 char *temp_buf
; /* a pointer to the current data */
99 char *fname
; /* name of our test file */
100 int fd
; /* fd for our test file */
105 unsigned long testcalls
= 0; /* calls to function "test" */
107 unsigned long simulatedopcount
= 0; /* -b flag */
108 int closeprob
= 0; /* -c flag */
109 int debug
= 0; /* -d flag */
110 unsigned long debugstart
= 0; /* -D flag */
111 unsigned long maxfilelen
= 256 * 1024; /* -l flag */
112 int sizechecks
= 1; /* -n flag disables them */
113 int maxoplen
= 64 * 1024; /* -o flag */
114 int quiet
= 0; /* -q flag */
115 unsigned long progressinterval
= 0; /* -p flag */
116 int readbdy
= 1; /* -r flag */
117 int style
= 0; /* -s flag */
118 int truncbdy
= 1; /* -t flag */
119 int writebdy
= 1; /* -w flag */
120 long monitorstart
= -1; /* -m flag */
121 long monitorend
= -1; /* -m flag */
122 int lite
= 0; /* -L flag */
123 long numops
= -1; /* -N flag */
124 int randomoplen
= 1; /* -O flag disables it */
125 int seed
= 1; /* -S flag */
126 int mapped_writes
= 1; /* -W flag disables */
127 int mapped_reads
= 1; /* -R flag disables it */
129 FILE * fsxlogf
= NULL
;
135 vwarnc(code
, fmt
, ap
)
140 fprintf(stderr
, "fsx: ");
142 vfprintf(stderr
, fmt
, ap
);
143 fprintf(stderr
, ": ");
145 fprintf(stderr
, "%s\n", strerror(code
));
150 warn(const char * fmt
, ...)
154 vwarnc(errno
, fmt
, ap
);
165 vfprintf(stdout
, fmt
, args
);
167 vfprintf(fsxlogf
, fmt
, args
);
174 prt("%s%s%s\n", prefix
, prefix
? ": " : "", strerror(errno
));
179 log4(int operation
, int arg0
, int arg1
, int arg2
)
181 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
;
215 prt("%d(%d mod 256): ", opnum
, opnum
%256);
217 if ((closeopen
= lp
->operation
< 0))
218 lp
->operation
= ~ lp
->operation
;
220 switch (lp
->operation
) {
222 prt("MAPREAD\t0x%x thru 0x%x\t(0x%x bytes)",
223 lp
->args
[0], lp
->args
[0] + lp
->args
[1] - 1,
225 if (badoff
>= lp
->args
[0] && badoff
<
226 lp
->args
[0] + lp
->args
[1])
230 prt("MAPWRITE 0x%x thru 0x%x\t(0x%x bytes)",
231 lp
->args
[0], lp
->args
[0] + lp
->args
[1] - 1,
233 if (badoff
>= lp
->args
[0] && badoff
<
234 lp
->args
[0] + lp
->args
[1])
238 prt("READ\t0x%x thru 0x%x\t(0x%x bytes)",
239 lp
->args
[0], lp
->args
[0] + lp
->args
[1] - 1,
241 if (badoff
>= lp
->args
[0] &&
242 badoff
< lp
->args
[0] + lp
->args
[1])
246 prt("WRITE\t0x%x thru 0x%x\t(0x%x bytes)",
247 lp
->args
[0], lp
->args
[0] + lp
->args
[1] - 1,
249 if (lp
->args
[0] > lp
->args
[2])
251 else if (lp
->args
[0] + lp
->args
[1] > lp
->args
[2])
253 if ((badoff
>= lp
->args
[0] || badoff
>=lp
->args
[2]) &&
254 badoff
< lp
->args
[0] + lp
->args
[1])
258 down
= lp
->args
[0] < lp
->args
[1];
259 prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
260 down
? "DOWN" : "UP", lp
->args
[1], lp
->args
[0]);
261 if (badoff
>= lp
->args
[!down
] &&
262 badoff
< lp
->args
[!!down
])
266 prt("SKIPPED (no operation)");
269 prt("BOGUS LOG ENTRY (operation code = %d)!",
273 prt("\n\t\tCLOSE/OPEN");
283 save_buffer(char *buffer
, off_t bufferlength
, int fd
)
286 ssize_t byteswritten
;
288 if (fd
<= 0 || bufferlength
== 0)
291 if (bufferlength
> SSIZE_MAX
) {
292 prt("fsx flaw: overflow in save_buffer\n");
296 off_t size_by_seek
= lseek(fd
, (off_t
)0, SEEK_END
);
297 if (size_by_seek
== (off_t
)-1)
298 prterr("save_buffer: lseek eof");
299 else if (bufferlength
> size_by_seek
) {
300 warn("save_buffer: .fsxgood file too short... will save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek
,
301 (unsigned long long)bufferlength
);
302 bufferlength
= size_by_seek
;
306 ret
= lseek(fd
, (off_t
)0, SEEK_SET
);
307 if (ret
== (off_t
)-1)
308 prterr("save_buffer: lseek 0");
310 byteswritten
= write(fd
, buffer
, (size_t)bufferlength
);
311 if (byteswritten
!= bufferlength
) {
312 if (byteswritten
== -1)
313 prterr("save_buffer write");
315 warn("save_buffer: short write, 0x%x bytes instead of 0x%llx\n",
316 (unsigned)byteswritten
,
317 (unsigned long long)bufferlength
);
323 report_failure(int status
)
329 save_buffer(good_buf
, file_size
, fsxgoodfd
);
330 prt("Correct content saved for comparison\n");
331 prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n",
340 #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
341 *(((unsigned char *)(cp)) + 1)))
344 check_buffers(unsigned offset
, unsigned size
)
352 if (memcmp(good_buf
+ offset
, temp_buf
, size
) != 0) {
353 prt("READ BAD DATA: offset = 0x%x, size = 0x%x\n",
355 prt("OFFSET\tGOOD\tBAD\tRANGE\n");
357 c
= good_buf
[offset
];
361 bad
= short_at(&temp_buf
[i
]);
362 prt("0x%5x\t0x%04x\t0x%04x", offset
,
363 short_at(&good_buf
[offset
]), bad
);
364 op
= temp_buf
[offset
& 1 ? i
+1 : i
];
376 prt("operation# (mod 256) for the bad data may be %u\n", ((unsigned)op
& 0xff));
378 prt("operation# (mod 256) for the bad data unknown, check HOLE and EXTEND ops\n");
380 prt("????????????????\n");
392 if (fstat(fd
, &statbuf
)) {
393 prterr("check_size: fstat");
394 statbuf
.st_size
= -1;
396 size_by_seek
= lseek(fd
, (off_t
)0, SEEK_END
);
397 if (file_size
!= statbuf
.st_size
|| file_size
!= size_by_seek
) {
398 prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
399 (unsigned long long)file_size
,
400 (unsigned long long)statbuf
.st_size
,
401 (unsigned long long)size_by_seek
);
408 check_trunc_hack(void)
412 ftruncate(fd
, (off_t
)0);
413 ftruncate(fd
, (off_t
)100000);
415 if (statbuf
.st_size
!= (off_t
)100000) {
416 prt("no extend on truncate! not posix!\n");
419 ftruncate(fd
, (off_t
)0);
424 doread(unsigned offset
, unsigned size
)
429 offset
-= offset
% readbdy
;
431 if (!quiet
&& testcalls
> simulatedopcount
)
432 prt("skipping zero size read\n");
433 log4(OP_SKIPPED
, OP_READ
, offset
, size
);
436 if (size
+ offset
> file_size
) {
437 if (!quiet
&& testcalls
> simulatedopcount
)
438 prt("skipping seek/read past end of file\n");
439 log4(OP_SKIPPED
, OP_READ
, offset
, size
);
443 log4(OP_READ
, offset
, size
, 0);
445 if (testcalls
<= simulatedopcount
)
448 if (!quiet
&& ((progressinterval
&&
449 testcalls
% progressinterval
== 0) ||
451 (monitorstart
== -1 ||
452 (offset
+ size
> monitorstart
&&
453 (monitorend
== -1 || offset
<= monitorend
))))))
454 prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls
,
455 offset
, offset
+ size
- 1, size
);
456 ret
= lseek(fd
, (off_t
)offset
, SEEK_SET
);
457 if (ret
== (off_t
)-1) {
458 prterr("doread: lseek");
461 iret
= read(fd
, temp_buf
, size
);
464 prterr("doread: read");
466 prt("short read: 0x%x bytes instead of 0x%x\n",
470 check_buffers(offset
, size
);
475 check_eofpage(char *s
, unsigned offset
, char *p
, int size
)
477 unsigned last_page
, should_be_zero
;
479 if (offset
+ size
<= (file_size
& ~page_mask
))
482 * we landed in the last page of the file
483 * test to make sure the VM system provided 0's
484 * beyond the true end of the file mapping
485 * (as required by mmap def in 1996 posix 1003.1)
487 last_page
= ((int)p
+ (offset
& page_mask
) + size
) & ~page_mask
;
489 for (should_be_zero
= last_page
+ (file_size
& page_mask
);
490 should_be_zero
< last_page
+ page_size
;
492 if (*(char *)should_be_zero
) {
493 prt("Mapped %s: non-zero data past EOF (0x%llx) page offset 0x%x is 0x%04x\n",
494 s
, file_size
- 1, should_be_zero
& page_mask
,
495 short_at(should_be_zero
));
502 domapread(unsigned offset
, unsigned size
)
508 offset
-= offset
% readbdy
;
510 if (!quiet
&& testcalls
> simulatedopcount
)
511 prt("skipping zero size read\n");
512 log4(OP_SKIPPED
, OP_MAPREAD
, offset
, size
);
515 if (size
+ offset
> file_size
) {
516 if (!quiet
&& testcalls
> simulatedopcount
)
517 prt("skipping seek/read past end of file\n");
518 log4(OP_SKIPPED
, OP_MAPREAD
, offset
, size
);
522 log4(OP_MAPREAD
, offset
, size
, 0);
524 if (testcalls
<= simulatedopcount
)
527 if (!quiet
&& ((progressinterval
&&
528 testcalls
% progressinterval
== 0) ||
530 (monitorstart
== -1 ||
531 (offset
+ size
> monitorstart
&&
532 (monitorend
== -1 || offset
<= monitorend
))))))
533 prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls
,
534 offset
, offset
+ size
- 1, size
);
536 pg_offset
= offset
& page_mask
;
537 map_size
= pg_offset
+ size
;
539 if ((p
= (char *)mmap(0, map_size
, PROT_READ
, MAP_FILE
| MAP_SHARED
, fd
,
540 (off_t
)(offset
- pg_offset
))) == (char *)-1) {
541 prterr("domapread: mmap");
544 memcpy(temp_buf
, p
+ pg_offset
, size
);
546 check_eofpage("Read", offset
, p
, size
);
548 if (munmap(p
, map_size
) != 0) {
549 prterr("domapread: munmap");
553 check_buffers(offset
, size
);
558 gendata(char *original_buf
, char *good_buf
, unsigned offset
, unsigned size
)
561 good_buf
[offset
] = testcalls
% 256;
563 good_buf
[offset
] += original_buf
[offset
];
570 dowrite(unsigned offset
, unsigned size
)
575 offset
-= offset
% writebdy
;
577 if (!quiet
&& testcalls
> simulatedopcount
)
578 prt("skipping zero size write\n");
579 log4(OP_SKIPPED
, OP_WRITE
, offset
, size
);
583 log4(OP_WRITE
, offset
, size
, file_size
);
585 gendata(original_buf
, good_buf
, offset
, size
);
586 if (file_size
< offset
+ size
) {
587 if (file_size
< offset
)
588 memset(good_buf
+ file_size
, '\0', offset
- file_size
);
589 file_size
= offset
+ size
;
591 warn("Lite file size bug in fsx!");
596 if (testcalls
<= simulatedopcount
)
599 if (!quiet
&& ((progressinterval
&&
600 testcalls
% progressinterval
== 0) ||
602 (monitorstart
== -1 ||
603 (offset
+ size
> monitorstart
&&
604 (monitorend
== -1 || offset
<= monitorend
))))))
605 prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls
,
606 offset
, offset
+ size
- 1, size
);
607 ret
= lseek(fd
, (off_t
)offset
, SEEK_SET
);
608 if (ret
== (off_t
)-1) {
609 prterr("dowrite: lseek");
612 iret
= write(fd
, good_buf
+ offset
, size
);
615 prterr("dowrite: write");
617 prt("short write: 0x%x bytes instead of 0x%x\n",
625 domapwrite(unsigned offset
, unsigned size
)
632 offset
-= offset
% writebdy
;
634 if (!quiet
&& testcalls
> simulatedopcount
)
635 prt("skipping zero size write\n");
636 log4(OP_SKIPPED
, OP_MAPWRITE
, offset
, size
);
639 cur_filesize
= file_size
;
641 log4(OP_MAPWRITE
, offset
, size
, 0);
643 gendata(original_buf
, good_buf
, offset
, size
);
644 if (file_size
< offset
+ size
) {
645 if (file_size
< offset
)
646 memset(good_buf
+ file_size
, '\0', offset
- file_size
);
647 file_size
= offset
+ size
;
649 warn("Lite file size bug in fsx!");
654 if (testcalls
<= simulatedopcount
)
657 if (!quiet
&& ((progressinterval
&&
658 testcalls
% progressinterval
== 0) ||
660 (monitorstart
== -1 ||
661 (offset
+ size
> monitorstart
&&
662 (monitorend
== -1 || offset
<= monitorend
))))))
663 prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls
,
664 offset
, offset
+ size
- 1, size
);
666 if (file_size
> cur_filesize
) {
667 if (ftruncate(fd
, file_size
) == -1) {
668 prterr("domapwrite: ftruncate");
672 pg_offset
= offset
& page_mask
;
673 map_size
= pg_offset
+ size
;
675 if ((p
= (char *)mmap(0, map_size
, PROT_READ
| PROT_WRITE
,
676 MAP_FILE
| MAP_SHARED
, fd
,
677 (off_t
)(offset
- pg_offset
))) == (char *)-1) {
678 prterr("domapwrite: mmap");
681 memcpy(p
+ pg_offset
, good_buf
+ offset
, size
);
682 if (msync(p
, map_size
, 0) != 0) {
683 prterr("domapwrite: msync");
687 check_eofpage("Write", offset
, p
, size
);
689 if (munmap(p
, map_size
) != 0) {
690 prterr("domapwrite: munmap");
697 dotruncate(unsigned size
)
699 int oldsize
= file_size
;
701 size
-= size
% truncbdy
;
702 if (size
> biggest
) {
704 if (!quiet
&& testcalls
> simulatedopcount
)
705 prt("truncating to largest ever: 0x%x\n", size
);
708 log4(OP_TRUNCATE
, size
, (unsigned)file_size
, 0);
710 if (size
> file_size
)
711 memset(good_buf
+ file_size
, '\0', size
- file_size
);
714 if (testcalls
<= simulatedopcount
)
717 if ((progressinterval
&& testcalls
% progressinterval
== 0) ||
718 (debug
&& (monitorstart
== -1 || monitorend
== -1 ||
719 size
<= monitorend
)))
720 prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls
, oldsize
, size
);
721 if (ftruncate(fd
, (off_t
)size
) == -1) {
722 prt("ftruncate1: %x\n", size
);
723 prterr("dotruncate: ftruncate");
734 if (lseek(fd
, (off_t
)0, SEEK_SET
) == (off_t
)-1) {
735 prterr("writefileimage: lseek");
738 iret
= write(fd
, good_buf
, file_size
);
739 if ((off_t
)iret
!= file_size
) {
741 prterr("writefileimage: write");
743 prt("short write: 0x%x bytes instead of 0x%llx\n",
744 iret
, (unsigned long long)file_size
);
747 if (lite
? 0 : ftruncate(fd
, file_size
) == -1) {
748 prt("ftruncate2: %llx\n", (unsigned long long)file_size
);
749 prterr("writefileimage: ftruncate");
758 if (testcalls
<= simulatedopcount
)
762 prt("%lu close/open\n", testcalls
);
764 prterr("docloseopen: close");
767 fd
= open(fname
, O_RDWR
, 0);
769 prterr("docloseopen: open");
778 unsigned long offset
;
779 unsigned long size
= maxoplen
;
780 unsigned long rv
= random();
781 unsigned long op
= rv
% (3 + !lite
+ mapped_writes
);
783 /* turn off the map read if necessary */
785 if (op
== 2 && !mapped_reads
)
788 if (simulatedopcount
> 0 && testcalls
== simulatedopcount
)
794 closeopen
= (rv
>> 3) < (1 << 28) / closeprob
;
796 if (debugstart
> 0 && testcalls
>= debugstart
)
799 if (!quiet
&& testcalls
< simulatedopcount
&& testcalls
% 100000 == 0)
800 prt("%lu...\n", testcalls
);
807 * MAPWRITE: op = 3 or 4
809 if (lite
? 0 : op
== 3 && style
== 0) /* vanilla truncate? */
810 dotruncate(random() % maxfilelen
);
813 size
= random() % (maxoplen
+1);
814 if (lite
? 0 : op
== 3)
818 if (op
== 1 || op
== (lite
? 3 : 4)) {
819 offset
%= maxfilelen
;
820 if (offset
+ size
> maxfilelen
)
821 size
= maxfilelen
- offset
;
823 domapwrite(offset
, size
);
825 dowrite(offset
, size
);
831 if (offset
+ size
> file_size
)
832 size
= file_size
- offset
;
834 domapread(offset
, size
);
836 doread(offset
, size
);
840 if (sizechecks
&& testcalls
> simulatedopcount
)
852 prt("signal %d\n", sig
);
853 prt("testcalls = %lu\n", testcalls
);
861 fprintf(stdout
, "usage: %s",
862 "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\
863 -b opnum: beginning operation number (default 1)\n\
864 -c P: 1 in P chance of file close+open at each op (default infinity)\n\
865 -d: debug output for all operations\n\
866 -l flen: the upper bound on file size (default 262144)\n\
867 -m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\
868 -n: no verifications of file size\n\
869 -o oplen: the upper bound on operation size (default 65536)\n\
870 -p progressinterval: debug output at specified operation interval\n\
871 -q: quieter operation\n\
872 -r readbdy: 4096 would make reads page aligned (default 1)\n\
873 -s style: 1 gives smaller truncates (default 0)\n\
874 -t truncbdy: 4096 would make truncates page aligned (default 1)\n\
875 -w writebdy: 4096 would make writes page aligned (default 1)\n\
876 -D startingop: debug output starting at specified operation\n\
877 -L: fsxLite - no file creations & no file size changes\n\
878 -N numops: total # operations to do (default infinity)\n\
879 -O: use oplen (see -o flag) for every op (default random)\n\
880 -P dirpath: save .fsxlog and .fsxgood files in dirpath (default ./)\n\
881 -S seed: for random # generator (default 1) 0 gets timestamp\n\
882 -W: mapped write operations DISabled\n\
883 -R: mapped read operations DISabled)\n\
884 fname: this filename is REQUIRED (no default)\n");
890 getnum(char *s
, char **e
)
895 ret
= strtol(s
, e
, 0);
924 main(int argc
, char **argv
)
934 page_size
= getpagesize();
935 page_mask
= page_size
- 1;
937 setvbuf(stdout
, (char *)0, _IOLBF
, 0); /* line buffered stdout */
939 while ((ch
= getopt(argc
, argv
, "b:c:dl:m:no:p:qr:s:t:w:D:LN:OP:RS:W"))
943 simulatedopcount
= getnum(optarg
, &endp
);
945 fprintf(stdout
, "Will begin at operation %ld\n",
947 if (simulatedopcount
== 0)
949 simulatedopcount
-= 1;
952 closeprob
= getnum(optarg
, &endp
);
955 "Chance of close/open is 1 in %d\n",
964 maxfilelen
= getnum(optarg
, &endp
);
969 monitorstart
= getnum(optarg
, &endp
);
970 if (monitorstart
< 0)
972 if (!endp
|| *endp
++ != ':')
974 monitorend
= getnum(endp
, &endp
);
978 monitorend
= -1; /* aka infinity */
984 maxoplen
= getnum(optarg
, &endp
);
989 progressinterval
= getnum(optarg
, &endp
);
990 if (progressinterval
< 0)
997 readbdy
= getnum(optarg
, &endp
);
1002 style
= getnum(optarg
, &endp
);
1003 if (style
< 0 || style
> 1)
1007 truncbdy
= getnum(optarg
, &endp
);
1012 writebdy
= getnum(optarg
, &endp
);
1017 debugstart
= getnum(optarg
, &endp
);
1025 numops
= getnum(optarg
, &endp
);
1033 strncpy(goodfile
, optarg
, sizeof(goodfile
));
1034 strcat(goodfile
, "/");
1035 strncpy(logfile
, optarg
, sizeof(logfile
));
1036 strcat(logfile
, "/");
1042 seed
= getnum(optarg
, &endp
);
1044 seed
= time(0) % 10000;
1046 fprintf(stdout
, "Seed set to %d\n", seed
);
1053 fprintf(stdout
, "mapped writes DISABLED\n");
1066 signal(SIGHUP
, cleanup
);
1067 signal(SIGINT
, cleanup
);
1068 signal(SIGPIPE
, cleanup
);
1069 signal(SIGALRM
, cleanup
);
1070 signal(SIGTERM
, cleanup
);
1071 signal(SIGXCPU
, cleanup
);
1072 signal(SIGXFSZ
, cleanup
);
1073 signal(SIGVTALRM
, cleanup
);
1074 signal(SIGUSR1
, cleanup
);
1075 signal(SIGUSR2
, cleanup
);
1077 initstate(seed
, state
, 256);
1079 fd
= open(fname
, O_RDWR
|(lite
? 0 : O_CREAT
|O_TRUNC
), 0666);
1084 strncat(goodfile
, fname
, 256);
1085 strcat (goodfile
, ".fsxgood");
1086 fsxgoodfd
= open(goodfile
, O_RDWR
|O_CREAT
|O_TRUNC
, 0666);
1087 if (fsxgoodfd
< 0) {
1091 strncat(logfile
, fname
, 256);
1092 strcat (logfile
, ".fsxlog");
1093 fsxlogf
= fopen(logfile
, "w");
1094 if (fsxlogf
== NULL
) {
1100 file_size
= maxfilelen
= lseek(fd
, (off_t
)0, SEEK_END
);
1101 if (file_size
== (off_t
)-1) {
1103 warn("main: lseek eof");
1106 ret
= lseek(fd
, (off_t
)0, SEEK_SET
);
1107 if (ret
== (off_t
)-1) {
1109 warn("main: lseek 0");
1113 original_buf
= (char *) malloc(maxfilelen
);
1114 for (i
= 0; i
< maxfilelen
; i
++)
1115 original_buf
[i
] = random() % 256;
1116 good_buf
= (char *) malloc(maxfilelen
);
1117 memset(good_buf
, '\0', maxfilelen
);
1118 temp_buf
= (char *) malloc(maxoplen
);
1119 memset(temp_buf
, '\0', maxoplen
);
1120 if (lite
) { /* zero entire existing file */
1123 written
= write(fd
, good_buf
, (size_t)maxfilelen
);
1124 if (written
!= maxfilelen
) {
1125 if (written
== -1) {
1127 warn("main: error on write");
1129 warn("main: short write, 0x%x bytes instead of 0x%x\n",
1130 (unsigned)written
, maxfilelen
);
1136 while (numops
== -1 || numops
--)
1143 prt("All operations completed A-OK!\n");