1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3*49cdfc7eSAndroid Build Coastguard Worker *
4*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify it
5*49cdfc7eSAndroid Build Coastguard Worker * under the terms of version 2 of the GNU General Public License as
6*49cdfc7eSAndroid Build Coastguard Worker * published by the Free Software Foundation.
7*49cdfc7eSAndroid Build Coastguard Worker *
8*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it would be useful, but
9*49cdfc7eSAndroid Build Coastguard Worker * WITHOUT ANY WARRANTY; without even the implied warranty of
10*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11*49cdfc7eSAndroid Build Coastguard Worker *
12*49cdfc7eSAndroid Build Coastguard Worker * Further, this software is distributed without any warranty that it is
13*49cdfc7eSAndroid Build Coastguard Worker * free of the rightful claim of any third person regarding infringement
14*49cdfc7eSAndroid Build Coastguard Worker * or the like. Any license provided herein, whether implied or
15*49cdfc7eSAndroid Build Coastguard Worker * otherwise, applies only to this software file. Patent licenses, if
16*49cdfc7eSAndroid Build Coastguard Worker * any, provided herein do not apply to combinations of this program with
17*49cdfc7eSAndroid Build Coastguard Worker * other software, or any other product whatsoever.
18*49cdfc7eSAndroid Build Coastguard Worker *
19*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License along
20*49cdfc7eSAndroid Build Coastguard Worker * with this program; if not, write the Free Software Foundation, Inc.,
21*49cdfc7eSAndroid Build Coastguard Worker * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22*49cdfc7eSAndroid Build Coastguard Worker *
23*49cdfc7eSAndroid Build Coastguard Worker * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24*49cdfc7eSAndroid Build Coastguard Worker * Mountain View, CA 94043, or:
25*49cdfc7eSAndroid Build Coastguard Worker *
26*49cdfc7eSAndroid Build Coastguard Worker * http://www.sgi.com
27*49cdfc7eSAndroid Build Coastguard Worker *
28*49cdfc7eSAndroid Build Coastguard Worker * For further information regarding this notice, see:
29*49cdfc7eSAndroid Build Coastguard Worker *
30*49cdfc7eSAndroid Build Coastguard Worker * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31*49cdfc7eSAndroid Build Coastguard Worker */
32*49cdfc7eSAndroid Build Coastguard Worker /*
33*49cdfc7eSAndroid Build Coastguard Worker * This program will grow a list of files.
34*49cdfc7eSAndroid Build Coastguard Worker * Each file will grow by grow_incr before the same
35*49cdfc7eSAndroid Build Coastguard Worker * file grows twice. Each file is open and closed before next file is opened.
36*49cdfc7eSAndroid Build Coastguard Worker *
37*49cdfc7eSAndroid Build Coastguard Worker * To just verify file contents: growfiles -g 0 -c 1 filename
38*49cdfc7eSAndroid Build Coastguard Worker *
39*49cdfc7eSAndroid Build Coastguard Worker * See help and prt_examples functions below.
40*49cdfc7eSAndroid Build Coastguard Worker *
41*49cdfc7eSAndroid Build Coastguard Worker * Basic code layout
42*49cdfc7eSAndroid Build Coastguard Worker * process cmdline
43*49cdfc7eSAndroid Build Coastguard Worker * print debug message about options used
44*49cdfc7eSAndroid Build Coastguard Worker * setup signal handlers
45*49cdfc7eSAndroid Build Coastguard Worker * return control to user (if wanted - default action)
46*49cdfc7eSAndroid Build Coastguard Worker * fork number of desired childern (if wanted)
47*49cdfc7eSAndroid Build Coastguard Worker * re-exec self (if wanted)
48*49cdfc7eSAndroid Build Coastguard Worker * Determine number of files
49*49cdfc7eSAndroid Build Coastguard Worker * malloc space or i/o buffer
50*49cdfc7eSAndroid Build Coastguard Worker * Loop until stop is set
51*49cdfc7eSAndroid Build Coastguard Worker * Determine if hit iteration, time, max errors or num bytes reached
52*49cdfc7eSAndroid Build Coastguard Worker * Loop through each file
53*49cdfc7eSAndroid Build Coastguard Worker * open file
54*49cdfc7eSAndroid Build Coastguard Worker * fstat file - to determine if file if a fifo
55*49cdfc7eSAndroid Build Coastguard Worker * prealloc file space (if wanted)
56*49cdfc7eSAndroid Build Coastguard Worker * growfile
57*49cdfc7eSAndroid Build Coastguard Worker * check last write
58*49cdfc7eSAndroid Build Coastguard Worker * check whole file
59*49cdfc7eSAndroid Build Coastguard Worker * shrink file
60*49cdfc7eSAndroid Build Coastguard Worker * close file
61*49cdfc7eSAndroid Build Coastguard Worker * delay (if wanted)
62*49cdfc7eSAndroid Build Coastguard Worker * End loop
63*49cdfc7eSAndroid Build Coastguard Worker * End loop
64*49cdfc7eSAndroid Build Coastguard Worker * remove all files (if wanted)
65*49cdfc7eSAndroid Build Coastguard Worker *
66*49cdfc7eSAndroid Build Coastguard Worker * Author: Richard Logan
67*49cdfc7eSAndroid Build Coastguard Worker *
68*49cdfc7eSAndroid Build Coastguard Worker */
69*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
70*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
71*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
72*49cdfc7eSAndroid Build Coastguard Worker #include <ctype.h>
73*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
74*49cdfc7eSAndroid Build Coastguard Worker #include <time.h>
75*49cdfc7eSAndroid Build Coastguard Worker #include <sys/file.h>
76*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
77*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
78*49cdfc7eSAndroid Build Coastguard Worker #include <sys/time.h>
79*49cdfc7eSAndroid Build Coastguard Worker #include <sys/param.h>
80*49cdfc7eSAndroid Build Coastguard Worker #include <sys/signal.h>
81*49cdfc7eSAndroid Build Coastguard Worker #include <sys/statfs.h>
82*49cdfc7eSAndroid Build Coastguard Worker #include <sys/vfs.h>
83*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
84*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
85*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
86*49cdfc7eSAndroid Build Coastguard Worker #include <inttypes.h>
87*49cdfc7eSAndroid Build Coastguard Worker #include "dataascii.h"
88*49cdfc7eSAndroid Build Coastguard Worker #include "random_range.h"
89*49cdfc7eSAndroid Build Coastguard Worker #include "databin.h"
90*49cdfc7eSAndroid Build Coastguard Worker #include "open_flags.h"
91*49cdfc7eSAndroid Build Coastguard Worker #include "forker.h"
92*49cdfc7eSAndroid Build Coastguard Worker #include "file_lock.h"
93*49cdfc7eSAndroid Build Coastguard Worker
94*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
95*49cdfc7eSAndroid Build Coastguard Worker #include <sys/panic.h>
96*49cdfc7eSAndroid Build Coastguard Worker #include <sys/category.h>
97*49cdfc7eSAndroid Build Coastguard Worker #endif
98*49cdfc7eSAndroid Build Coastguard Worker
99*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
100*49cdfc7eSAndroid Build Coastguard Worker
101*49cdfc7eSAndroid Build Coastguard Worker int set_sig(void);
102*49cdfc7eSAndroid Build Coastguard Worker void sig_handler(int sig);
103*49cdfc7eSAndroid Build Coastguard Worker static void notify_others(void);
104*49cdfc7eSAndroid Build Coastguard Worker int handle_error(void);
105*49cdfc7eSAndroid Build Coastguard Worker int cleanup(void);
106*49cdfc7eSAndroid Build Coastguard Worker void usage(void);
107*49cdfc7eSAndroid Build Coastguard Worker void help(void);
108*49cdfc7eSAndroid Build Coastguard Worker void prt_examples(FILE * stream);
109*49cdfc7eSAndroid Build Coastguard Worker int growfile(int fd, char *file, int grow_incr, char *buf,
110*49cdfc7eSAndroid Build Coastguard Worker unsigned long *curr_size_ptr);
111*49cdfc7eSAndroid Build Coastguard Worker int shrinkfile(int fd, char *filename, int trunc_incr,
112*49cdfc7eSAndroid Build Coastguard Worker int trunc_inter, int just_trunc);
113*49cdfc7eSAndroid Build Coastguard Worker int check_write(int fd, int cf_inter, char *filename, int mode);
114*49cdfc7eSAndroid Build Coastguard Worker int check_file(int fd, int cf_inter, char *filename, int no_file_check);
115*49cdfc7eSAndroid Build Coastguard Worker int file_size(int fd);
116*49cdfc7eSAndroid Build Coastguard Worker int lkfile(int fd, int operation, int lklevel);
117*49cdfc7eSAndroid Build Coastguard Worker
118*49cdfc7eSAndroid Build Coastguard Worker #ifndef linux
119*49cdfc7eSAndroid Build Coastguard Worker int pre_alloc(int fd, long size);
120*49cdfc7eSAndroid Build Coastguard Worker #endif /* !linux */
121*49cdfc7eSAndroid Build Coastguard Worker
122*49cdfc7eSAndroid Build Coastguard Worker extern int datapidgen(int, char *, int, int);
123*49cdfc7eSAndroid Build Coastguard Worker extern int datapidchk(int, char *, int, int, char **);
124*49cdfc7eSAndroid Build Coastguard Worker
125*49cdfc7eSAndroid Build Coastguard Worker /* LTP status reporting */
126*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "growfiles"; /* Default test program identifier. */
127*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1; /* Total number of test cases. */
128*49cdfc7eSAndroid Build Coastguard Worker
129*49cdfc7eSAndroid Build Coastguard Worker /* To avoid extensive modifications to the code, use this bodge */
130*49cdfc7eSAndroid Build Coastguard Worker #define exit(x) myexit(x)
myexit(int x)131*49cdfc7eSAndroid Build Coastguard Worker void myexit(int x)
132*49cdfc7eSAndroid Build Coastguard Worker {
133*49cdfc7eSAndroid Build Coastguard Worker if (x)
134*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "Test failed");
135*49cdfc7eSAndroid Build Coastguard Worker else
136*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "Test passed");
137*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
138*49cdfc7eSAndroid Build Coastguard Worker }
139*49cdfc7eSAndroid Build Coastguard Worker
140*49cdfc7eSAndroid Build Coastguard Worker #define NEWIO 1 /* Use the tlibio.c functions */
141*49cdfc7eSAndroid Build Coastguard Worker
142*49cdfc7eSAndroid Build Coastguard Worker #ifndef NEWIO
143*49cdfc7eSAndroid Build Coastguard Worker #define NEWIO 0 /* specifies to use original iowrite.c */
144*49cdfc7eSAndroid Build Coastguard Worker /* functions instead of tlibio.c functions */
145*49cdfc7eSAndroid Build Coastguard Worker /* Once it is proven tlibio.c functions work properly, */
146*49cdfc7eSAndroid Build Coastguard Worker /* only tlibio.c functions will be used */
147*49cdfc7eSAndroid Build Coastguard Worker #else
148*49cdfc7eSAndroid Build Coastguard Worker #include "tlibio.h"
149*49cdfc7eSAndroid Build Coastguard Worker #endif
150*49cdfc7eSAndroid Build Coastguard Worker
151*49cdfc7eSAndroid Build Coastguard Worker #ifndef PATH_MAX
152*49cdfc7eSAndroid Build Coastguard Worker #define PATH_MAX 1023
153*49cdfc7eSAndroid Build Coastguard Worker #endif
154*49cdfc7eSAndroid Build Coastguard Worker
155*49cdfc7eSAndroid Build Coastguard Worker #define DEF_DIR "."
156*49cdfc7eSAndroid Build Coastguard Worker #define DEF_FILE "gf"
157*49cdfc7eSAndroid Build Coastguard Worker
158*49cdfc7eSAndroid Build Coastguard Worker char *Progname;
159*49cdfc7eSAndroid Build Coastguard Worker int Debug = 0;
160*49cdfc7eSAndroid Build Coastguard Worker
161*49cdfc7eSAndroid Build Coastguard Worker int Pid = 0;
162*49cdfc7eSAndroid Build Coastguard Worker
163*49cdfc7eSAndroid Build Coastguard Worker int io_type = 0; /* I/O type -sync */
164*49cdfc7eSAndroid Build Coastguard Worker
165*49cdfc7eSAndroid Build Coastguard Worker #ifdef O_LARGEFILE
166*49cdfc7eSAndroid Build Coastguard Worker int open_flags = O_RDWR | O_CREAT | O_LARGEFILE; /* open flags */
167*49cdfc7eSAndroid Build Coastguard Worker #else
168*49cdfc7eSAndroid Build Coastguard Worker #warning O_LARGEFILE is not defined!
169*49cdfc7eSAndroid Build Coastguard Worker int open_flags = O_RDWR | O_CREAT; /* open flags */
170*49cdfc7eSAndroid Build Coastguard Worker #endif
171*49cdfc7eSAndroid Build Coastguard Worker
172*49cdfc7eSAndroid Build Coastguard Worker #define MAX_FC_READ 196608 /* 4096 * 48 - 48 blocks */
173*49cdfc7eSAndroid Build Coastguard Worker
174*49cdfc7eSAndroid Build Coastguard Worker #define PATTERN_ASCII 1 /* repeating alphabet letter pattern */
175*49cdfc7eSAndroid Build Coastguard Worker /* allows multiple writers and to be checked */
176*49cdfc7eSAndroid Build Coastguard Worker #define PATTERN_PID 2 /* <pid><words byte offset><pid> */
177*49cdfc7eSAndroid Build Coastguard Worker /* Assumes 64 bit word. Only allows single */
178*49cdfc7eSAndroid Build Coastguard Worker /* process to write and check */
179*49cdfc7eSAndroid Build Coastguard Worker /*
180*49cdfc7eSAndroid Build Coastguard Worker * 1234567890123456789012345678901234567890123456789012345678901234
181*49cdfc7eSAndroid Build Coastguard Worker * ________________________________________________________________
182*49cdfc7eSAndroid Build Coastguard Worker * < pid >< offset in file of this word >< pid >
183*49cdfc7eSAndroid Build Coastguard Worker */
184*49cdfc7eSAndroid Build Coastguard Worker
185*49cdfc7eSAndroid Build Coastguard Worker #define PATTERN_OFFSET 3 /* Like PATTERN_PID but has a fixed number */
186*49cdfc7eSAndroid Build Coastguard Worker /* (STATIC_NUM) instead of pid. */
187*49cdfc7eSAndroid Build Coastguard Worker /* Allows multiple processes to write/read */
188*49cdfc7eSAndroid Build Coastguard Worker #define PATTERN_ALT 4 /* alternating bit pattern (i.e. 0x5555555...) */
189*49cdfc7eSAndroid Build Coastguard Worker #define PATTERN_CHKER 5 /* checkerboard pattern (i.e. 0xff00ff00ff00...) */
190*49cdfc7eSAndroid Build Coastguard Worker #define PATTERN_CNTING 6 /* counting pattern (i.e. 0 - 07, 0 - 07, ...) */
191*49cdfc7eSAndroid Build Coastguard Worker #define PATTERN_ONES 7 /* all bits set (i.e. 0xffffffffffffff...) */
192*49cdfc7eSAndroid Build Coastguard Worker #define PATTERN_ZEROS 8 /* all bits cleared (i.e. 0x000000000...) */
193*49cdfc7eSAndroid Build Coastguard Worker #define PATTERN_RANDOM 9 /* random integers - can not be checked */
194*49cdfc7eSAndroid Build Coastguard Worker #define STATIC_NUM 221849 /* used instead of pid when PATTERN_OFFSET */
195*49cdfc7eSAndroid Build Coastguard Worker
196*49cdfc7eSAndroid Build Coastguard Worker #define MODE_RAND_SIZE 1 /* random write and trunc */
197*49cdfc7eSAndroid Build Coastguard Worker #define MODE_RAND_LSEEK 2 /* random lseek before write */
198*49cdfc7eSAndroid Build Coastguard Worker #define MODE_GROW_BY_LSEEK 4 /* lseek beyond end of file then write a byte */
199*49cdfc7eSAndroid Build Coastguard Worker #define RANDOM_OPEN 999876 /* if Open_flags set to this value, open flags */
200*49cdfc7eSAndroid Build Coastguard Worker /* will be randomly choosen from Open_flags[] */
201*49cdfc7eSAndroid Build Coastguard Worker #define MODE_FIFO S_IFIFO /* defined in stat.h 0010000 */
202*49cdfc7eSAndroid Build Coastguard Worker
203*49cdfc7eSAndroid Build Coastguard Worker int num_files = 0; /* num_auto_files + cmd line files */
204*49cdfc7eSAndroid Build Coastguard Worker char *filenames; /* pointer to space containing filenames */
205*49cdfc7eSAndroid Build Coastguard Worker int remove_files = 0; /* if set, cleanup default is not to cleanup */
206*49cdfc7eSAndroid Build Coastguard Worker int bytes_consumed = 0; /* total bytes consumed, all files */
207*49cdfc7eSAndroid Build Coastguard Worker int bytes_to_consume = 0; /* non-zero if -B was specified, total bytes */
208*49cdfc7eSAndroid Build Coastguard Worker int Maxerrs = 100; /* Max number errors before forced exit */
209*49cdfc7eSAndroid Build Coastguard Worker int Errors = 0; /* number of encountered errors */
210*49cdfc7eSAndroid Build Coastguard Worker int Upanic_on_error = 0; /* call upanic if error and this variable set */
211*49cdfc7eSAndroid Build Coastguard Worker
212*49cdfc7eSAndroid Build Coastguard Worker /* The *_size variables are only used when random iosize option (-r) is used */
213*49cdfc7eSAndroid Build Coastguard Worker int max_size = 5000;
214*49cdfc7eSAndroid Build Coastguard Worker int min_size = 1; /* also set in option parsing */
215*49cdfc7eSAndroid Build Coastguard Worker int mult_size = 1; /* when random iosz, iosz must be mult of mult_size */
216*49cdfc7eSAndroid Build Coastguard Worker /* the *_lseek variables are only used when radon lseek option (-R) is used */
217*49cdfc7eSAndroid Build Coastguard Worker int min_lseek = 0; /* also set in option parsing */
218*49cdfc7eSAndroid Build Coastguard Worker int max_lseek = -1; /* -1 means size of file */
219*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
220*49cdfc7eSAndroid Build Coastguard Worker int Pattern = PATTERN_OFFSET; /* This pattern is 64 bit word based */
221*49cdfc7eSAndroid Build Coastguard Worker #else
222*49cdfc7eSAndroid Build Coastguard Worker int Pattern = PATTERN_ASCII;
223*49cdfc7eSAndroid Build Coastguard Worker #endif
224*49cdfc7eSAndroid Build Coastguard Worker int Seed = -1; /* random number seed, < 0 == uninitialized */
225*49cdfc7eSAndroid Build Coastguard Worker int Nseeds = 0; /* Number of seed specified by the user */
226*49cdfc7eSAndroid Build Coastguard Worker int *Seeds; /* malloc'ed arrary of ints holding user spec seeds */
227*49cdfc7eSAndroid Build Coastguard Worker
228*49cdfc7eSAndroid Build Coastguard Worker int using_random = 0; /* flag indicating randomization is being used */
229*49cdfc7eSAndroid Build Coastguard Worker float delaysecs = 0.0; /* delay between iterations (in seconds) */
230*49cdfc7eSAndroid Build Coastguard Worker int delaytime; /* delay between iterations in clocks/uses */
231*49cdfc7eSAndroid Build Coastguard Worker int lockfile = 0; /* if set, do file locking */
232*49cdfc7eSAndroid Build Coastguard Worker /* 1 = do file locking around write, trunc */
233*49cdfc7eSAndroid Build Coastguard Worker /* and reads. */
234*49cdfc7eSAndroid Build Coastguard Worker /* 2 = write lock around all file operations */
235*49cdfc7eSAndroid Build Coastguard Worker
236*49cdfc7eSAndroid Build Coastguard Worker off_t Woffset = 0; /* offset before last write */
237*49cdfc7eSAndroid Build Coastguard Worker int Grow_incr = 4096; /* sz of last write */
238*49cdfc7eSAndroid Build Coastguard Worker int Mode = 0; /* bitmask of write/trunc mode */
239*49cdfc7eSAndroid Build Coastguard Worker /* also knows if dealing with fifo */
240*49cdfc7eSAndroid Build Coastguard Worker char *Buffer = NULL; /* buffer used by write and write check */
241*49cdfc7eSAndroid Build Coastguard Worker int Alignment = 0; /* if non word multiple, io will not be word aligned */
242*49cdfc7eSAndroid Build Coastguard Worker int Opid = 0; /* original pid */
243*49cdfc7eSAndroid Build Coastguard Worker
244*49cdfc7eSAndroid Build Coastguard Worker int Sync_with_others = 0; /* Flag indicating to stop other if we stop before DONE */
245*49cdfc7eSAndroid Build Coastguard Worker int Iter_cnt = 0; /* contains current iteration count value */
246*49cdfc7eSAndroid Build Coastguard Worker char TagName[40]; /* name of this growfiles (see Monster) */
247*49cdfc7eSAndroid Build Coastguard Worker
248*49cdfc7eSAndroid Build Coastguard Worker struct fileinfo_t {
249*49cdfc7eSAndroid Build Coastguard Worker char *filename;
250*49cdfc7eSAndroid Build Coastguard Worker int fd;
251*49cdfc7eSAndroid Build Coastguard Worker int openflags;
252*49cdfc7eSAndroid Build Coastguard Worker int mode;
253*49cdfc7eSAndroid Build Coastguard Worker } Fileinfo;
254*49cdfc7eSAndroid Build Coastguard Worker
255*49cdfc7eSAndroid Build Coastguard Worker /*
256*49cdfc7eSAndroid Build Coastguard Worker * Define open flags that will be used when '-o random' option is used.
257*49cdfc7eSAndroid Build Coastguard Worker * Note: If there is more than one growfiles doing its thing to the same
258*49cdfc7eSAndroid Build Coastguard Worker * file, O_TRUNC will cause data mismatches. How you ask?
259*49cdfc7eSAndroid Build Coastguard Worker * timing of events, example:
260*49cdfc7eSAndroid Build Coastguard Worker * Process one Process two
261*49cdfc7eSAndroid Build Coastguard Worker * --------------- -------------
262*49cdfc7eSAndroid Build Coastguard Worker * get write lock
263*49cdfc7eSAndroid Build Coastguard Worker * fstat file
264*49cdfc7eSAndroid Build Coastguard Worker * lseek
265*49cdfc7eSAndroid Build Coastguard Worker * generate pattern
266*49cdfc7eSAndroid Build Coastguard Worker * open with O_TRUNC
267*49cdfc7eSAndroid Build Coastguard Worker * write with wrong pattern
268*49cdfc7eSAndroid Build Coastguard Worker * because offset is wrong
269*49cdfc7eSAndroid Build Coastguard Worker *
270*49cdfc7eSAndroid Build Coastguard Worker * The second process truncated the file after the pattern was
271*49cdfc7eSAndroid Build Coastguard Worker * determined, thus the pattern is wrong for the file location.
272*49cdfc7eSAndroid Build Coastguard Worker *
273*49cdfc7eSAndroid Build Coastguard Worker * There can also be a timing problem with open flag O_APPEND if
274*49cdfc7eSAndroid Build Coastguard Worker * file locks are not being used (-l option). Things could happen
275*49cdfc7eSAndroid Build Coastguard Worker * between the fstat and the write. Thus, writing the wrong pattern.
276*49cdfc7eSAndroid Build Coastguard Worker * If all processes observe the file locks, O_APPEND should be ok
277*49cdfc7eSAndroid Build Coastguard Worker * to use.
278*49cdfc7eSAndroid Build Coastguard Worker */
279*49cdfc7eSAndroid Build Coastguard Worker int Open_flags[] = {
280*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
281*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT,
282*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_RAW,
283*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_BIG,
284*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_APPEND,
285*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_NDELAY,
286*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_PLACE,
287*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_SYNC,
288*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_RAW | O_SYNC,
289*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_NDELAY | O_SYNC,
290*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_NDELAY | O_SYNC | O_BIG,
291*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_RAW,
292*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_RAW | O_APPEND,
293*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_RAW | O_BIG,
294*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_RAW | O_APPEND | O_BIG,
295*49cdfc7eSAndroid Build Coastguard Worker /***
296*49cdfc7eSAndroid Build Coastguard Worker * O_WELLFORMED makes -o random require well formed i/o
297*49cdfc7eSAndroid Build Coastguard Worker ***/
298*49cdfc7eSAndroid Build Coastguard Worker #if ALLOW_O_WELLFORMED
299*49cdfc7eSAndroid Build Coastguard Worker #if O_PARALLEL
300*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_PARALLEL | O_WELLFORMED | O_RAW,
301*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_PARALLEL | O_WELLFORMED | O_RAW | O_TRUNC,
302*49cdfc7eSAndroid Build Coastguard Worker #endif /* O_PARALLEL */
303*49cdfc7eSAndroid Build Coastguard Worker #endif
304*49cdfc7eSAndroid Build Coastguard Worker
305*49cdfc7eSAndroid Build Coastguard Worker #else /* CRAY */
306*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT,
307*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_APPEND,
308*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_NDELAY,
309*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_SYNC,
310*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_SYNC | O_NDELAY,
311*49cdfc7eSAndroid Build Coastguard Worker O_RDWR | O_CREAT | O_APPEND | O_NDELAY,
312*49cdfc7eSAndroid Build Coastguard Worker
313*49cdfc7eSAndroid Build Coastguard Worker #endif /* CRAY */
314*49cdfc7eSAndroid Build Coastguard Worker };
315*49cdfc7eSAndroid Build Coastguard Worker
316*49cdfc7eSAndroid Build Coastguard Worker #define REXEC_INIT 0 /* don't do re-exec of childern */
317*49cdfc7eSAndroid Build Coastguard Worker #define REXEC_DOIT 1 /* Do re-exec of childern */
318*49cdfc7eSAndroid Build Coastguard Worker #define REXEC_DONE 2 /* We've already been re-exec'ed */
319*49cdfc7eSAndroid Build Coastguard Worker
320*49cdfc7eSAndroid Build Coastguard Worker #ifndef BSIZE
321*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
322*49cdfc7eSAndroid Build Coastguard Worker #define BSIZE 1024
323*49cdfc7eSAndroid Build Coastguard Worker #else
324*49cdfc7eSAndroid Build Coastguard Worker #define BSIZE 512
325*49cdfc7eSAndroid Build Coastguard Worker #endif /* CRAY */
326*49cdfc7eSAndroid Build Coastguard Worker #endif /* BSIZE */
327*49cdfc7eSAndroid Build Coastguard Worker
328*49cdfc7eSAndroid Build Coastguard Worker #define USECS_PER_SEC 1000000 /* microseconds per second */
329*49cdfc7eSAndroid Build Coastguard Worker
330*49cdfc7eSAndroid Build Coastguard Worker /*
331*49cdfc7eSAndroid Build Coastguard Worker * Define macros used when dealing with file locks.
332*49cdfc7eSAndroid Build Coastguard Worker */
333*49cdfc7eSAndroid Build Coastguard Worker #define LKLVL0 1 /* file lock around write/read/trunc */
334*49cdfc7eSAndroid Build Coastguard Worker #define LKLVL1 2 /* file lock after open to before close */
335*49cdfc7eSAndroid Build Coastguard Worker
336*49cdfc7eSAndroid Build Coastguard Worker /*
337*49cdfc7eSAndroid Build Coastguard Worker * Define special max lseek values
338*49cdfc7eSAndroid Build Coastguard Worker */
339*49cdfc7eSAndroid Build Coastguard Worker #define LSK_EOF -1 /* set fptr up to EOF */
340*49cdfc7eSAndroid Build Coastguard Worker #define LSK_EOFPLUSGROW -2 /* set fptr up to EOF + grow - leave whole */
341*49cdfc7eSAndroid Build Coastguard Worker #define LSK_EOFMINUSGROW -3 /* set fptr up to EOF-grow - no grow */
342*49cdfc7eSAndroid Build Coastguard Worker
343*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
344*49cdfc7eSAndroid Build Coastguard Worker * MAIN
345*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
main(int argc,char ** argv)346*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char **argv)
347*49cdfc7eSAndroid Build Coastguard Worker {
348*49cdfc7eSAndroid Build Coastguard Worker extern char *optarg; /* used by getopt */
349*49cdfc7eSAndroid Build Coastguard Worker extern int optind;
350*49cdfc7eSAndroid Build Coastguard Worker
351*49cdfc7eSAndroid Build Coastguard Worker int ind;
352*49cdfc7eSAndroid Build Coastguard Worker int first_file_ind = 0;
353*49cdfc7eSAndroid Build Coastguard Worker int num_auto_files = 0; /* files created by tool */
354*49cdfc7eSAndroid Build Coastguard Worker int seq_auto_files = 0; /* auto files created by tool created by tool */
355*49cdfc7eSAndroid Build Coastguard Worker char *auto_dir = DEF_DIR;
356*49cdfc7eSAndroid Build Coastguard Worker char *auto_file = DEF_FILE;
357*49cdfc7eSAndroid Build Coastguard Worker int grow_incr = 4096;
358*49cdfc7eSAndroid Build Coastguard Worker int trunc_incr = 4096;
359*49cdfc7eSAndroid Build Coastguard Worker int trunc_inter = 0; /* 0 means none, */
360*49cdfc7eSAndroid Build Coastguard Worker int unlink_inter = 0; /* 0 means none, 1 means always unlink */
361*49cdfc7eSAndroid Build Coastguard Worker int unlink_inter_ran = -1; /* -1 -use unlink_inter, otherwise randomly choose */
362*49cdfc7eSAndroid Build Coastguard Worker /* between unlink_inter and unlink_inter_ran */
363*49cdfc7eSAndroid Build Coastguard Worker int file_check_inter = 0; /* 0 means never, 1 means always */
364*49cdfc7eSAndroid Build Coastguard Worker int write_check_inter = 1; /* 0 means never, 1 means always */
365*49cdfc7eSAndroid Build Coastguard Worker int iterations = 1; /* number of increments to be added */
366*49cdfc7eSAndroid Build Coastguard Worker int no_file_check = 0; /* if set, no whole file checking will be done */
367*49cdfc7eSAndroid Build Coastguard Worker int num;
368*49cdfc7eSAndroid Build Coastguard Worker int fd; /* file descriptor */
369*49cdfc7eSAndroid Build Coastguard Worker int stop = 0; /* loop stopper if set */
370*49cdfc7eSAndroid Build Coastguard Worker
371*49cdfc7eSAndroid Build Coastguard Worker unsigned long curr_size = 0; /* BUG:14136 (keep track of file size) */
372*49cdfc7eSAndroid Build Coastguard Worker unsigned long fs_limit = 2147483647; /* BUG:14136 (filesystem size limit is 2G by default) */
373*49cdfc7eSAndroid Build Coastguard Worker struct statfs fsbuf;
374*49cdfc7eSAndroid Build Coastguard Worker
375*49cdfc7eSAndroid Build Coastguard Worker int tmp;
376*49cdfc7eSAndroid Build Coastguard Worker char chr;
377*49cdfc7eSAndroid Build Coastguard Worker int ret;
378*49cdfc7eSAndroid Build Coastguard Worker int pre_alloc_space = 0;
379*49cdfc7eSAndroid Build Coastguard Worker #ifndef linux
380*49cdfc7eSAndroid Build Coastguard Worker long total_grow_value; /* used in pre-allocations */
381*49cdfc7eSAndroid Build Coastguard Worker #endif
382*49cdfc7eSAndroid Build Coastguard Worker int backgrnd = 1; /* return control to user */
383*49cdfc7eSAndroid Build Coastguard Worker struct stat statbuf;
384*49cdfc7eSAndroid Build Coastguard Worker int time_iterval = -1;
385*49cdfc7eSAndroid Build Coastguard Worker time_t start_time = 0;
386*49cdfc7eSAndroid Build Coastguard Worker char reason[128]; /* reason for loop termination */
387*49cdfc7eSAndroid Build Coastguard Worker int num_procs = 1;
388*49cdfc7eSAndroid Build Coastguard Worker int forker_mode = 0;
389*49cdfc7eSAndroid Build Coastguard Worker int reexec = REXEC_INIT; /* reexec info */
390*49cdfc7eSAndroid Build Coastguard Worker char *exec_path = NULL;
391*49cdfc7eSAndroid Build Coastguard Worker
392*49cdfc7eSAndroid Build Coastguard Worker /*char *strrchr();*/
393*49cdfc7eSAndroid Build Coastguard Worker
394*49cdfc7eSAndroid Build Coastguard Worker char *filename; /* name of file specified by user */
395*49cdfc7eSAndroid Build Coastguard Worker char *cptr; /* temp char pointer */
396*49cdfc7eSAndroid Build Coastguard Worker extern int Forker_npids; /* num of forked pid, defined in forker.c */
397*49cdfc7eSAndroid Build Coastguard Worker struct timeval tv1;
398*49cdfc7eSAndroid Build Coastguard Worker
399*49cdfc7eSAndroid Build Coastguard Worker if (argv[0][0] == '-')
400*49cdfc7eSAndroid Build Coastguard Worker reexec = REXEC_DONE;
401*49cdfc7eSAndroid Build Coastguard Worker /*
402*49cdfc7eSAndroid Build Coastguard Worker * Determine name of file used to invoke this program
403*49cdfc7eSAndroid Build Coastguard Worker */
404*49cdfc7eSAndroid Build Coastguard Worker if ((Progname = strrchr(argv[0], '/')) != NULL)
405*49cdfc7eSAndroid Build Coastguard Worker Progname++;
406*49cdfc7eSAndroid Build Coastguard Worker else
407*49cdfc7eSAndroid Build Coastguard Worker Progname = argv[0];
408*49cdfc7eSAndroid Build Coastguard Worker
409*49cdfc7eSAndroid Build Coastguard Worker TagName[0] = '\0';
410*49cdfc7eSAndroid Build Coastguard Worker
411*49cdfc7eSAndroid Build Coastguard Worker /*
412*49cdfc7eSAndroid Build Coastguard Worker * Process options
413*49cdfc7eSAndroid Build Coastguard Worker */
414*49cdfc7eSAndroid Build Coastguard Worker while ((ind = getopt(argc, argv,
415*49cdfc7eSAndroid Build Coastguard Worker "hB:C:c:bd:D:e:Ef:g:H:I:i:lL:n:N:O:o:pP:q:wt:r:R:s:S:T:uU:W:xy"))
416*49cdfc7eSAndroid Build Coastguard Worker != EOF) {
417*49cdfc7eSAndroid Build Coastguard Worker switch (ind) {
418*49cdfc7eSAndroid Build Coastguard Worker
419*49cdfc7eSAndroid Build Coastguard Worker case 'h':
420*49cdfc7eSAndroid Build Coastguard Worker help();
421*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
422*49cdfc7eSAndroid Build Coastguard Worker
423*49cdfc7eSAndroid Build Coastguard Worker case 'B':
424*49cdfc7eSAndroid Build Coastguard Worker switch (sscanf(optarg, "%i%c", &bytes_to_consume, &chr)) {
425*49cdfc7eSAndroid Build Coastguard Worker case 1: /* noop */
426*49cdfc7eSAndroid Build Coastguard Worker break;
427*49cdfc7eSAndroid Build Coastguard Worker
428*49cdfc7eSAndroid Build Coastguard Worker case 2:
429*49cdfc7eSAndroid Build Coastguard Worker if (chr == 'b') {
430*49cdfc7eSAndroid Build Coastguard Worker bytes_to_consume *= BSIZE;
431*49cdfc7eSAndroid Build Coastguard Worker } else {
432*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
433*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --B option arg invalid\n",
434*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
435*49cdfc7eSAndroid Build Coastguard Worker usage();
436*49cdfc7eSAndroid Build Coastguard Worker exit(1);
437*49cdfc7eSAndroid Build Coastguard Worker }
438*49cdfc7eSAndroid Build Coastguard Worker break;
439*49cdfc7eSAndroid Build Coastguard Worker
440*49cdfc7eSAndroid Build Coastguard Worker default:
441*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
442*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --B option arg invalid\n",
443*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
444*49cdfc7eSAndroid Build Coastguard Worker usage();
445*49cdfc7eSAndroid Build Coastguard Worker exit(1);
446*49cdfc7eSAndroid Build Coastguard Worker break;
447*49cdfc7eSAndroid Build Coastguard Worker }
448*49cdfc7eSAndroid Build Coastguard Worker
449*49cdfc7eSAndroid Build Coastguard Worker break;
450*49cdfc7eSAndroid Build Coastguard Worker
451*49cdfc7eSAndroid Build Coastguard Worker case 'E':
452*49cdfc7eSAndroid Build Coastguard Worker prt_examples(stdout);
453*49cdfc7eSAndroid Build Coastguard Worker exit(0);
454*49cdfc7eSAndroid Build Coastguard Worker
455*49cdfc7eSAndroid Build Coastguard Worker case 'b': /* batch */
456*49cdfc7eSAndroid Build Coastguard Worker backgrnd = 0;
457*49cdfc7eSAndroid Build Coastguard Worker break;
458*49cdfc7eSAndroid Build Coastguard Worker
459*49cdfc7eSAndroid Build Coastguard Worker case 'C':
460*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i", &write_check_inter) != 1) {
461*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
462*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --c option arg invalid\n",
463*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
464*49cdfc7eSAndroid Build Coastguard Worker usage();
465*49cdfc7eSAndroid Build Coastguard Worker exit(1);
466*49cdfc7eSAndroid Build Coastguard Worker }
467*49cdfc7eSAndroid Build Coastguard Worker break;
468*49cdfc7eSAndroid Build Coastguard Worker
469*49cdfc7eSAndroid Build Coastguard Worker case 'c':
470*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i", &file_check_inter) != 1) {
471*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
472*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --c option arg invalid\n",
473*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
474*49cdfc7eSAndroid Build Coastguard Worker usage();
475*49cdfc7eSAndroid Build Coastguard Worker exit(1);
476*49cdfc7eSAndroid Build Coastguard Worker }
477*49cdfc7eSAndroid Build Coastguard Worker break;
478*49cdfc7eSAndroid Build Coastguard Worker
479*49cdfc7eSAndroid Build Coastguard Worker case 'd':
480*49cdfc7eSAndroid Build Coastguard Worker auto_dir = optarg;
481*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
482*49cdfc7eSAndroid Build Coastguard Worker unsetenv("TMPDIR"); /* force the use of auto_dir */
483*49cdfc7eSAndroid Build Coastguard Worker #endif
484*49cdfc7eSAndroid Build Coastguard Worker if (stat(auto_dir, &statbuf) == -1) {
485*49cdfc7eSAndroid Build Coastguard Worker if (mkdir(auto_dir, 0777) == -1) {
486*49cdfc7eSAndroid Build Coastguard Worker if (errno != EEXIST) {
487*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
488*49cdfc7eSAndroid Build Coastguard Worker "%s%s: Unable to make dir %s\n",
489*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName,
490*49cdfc7eSAndroid Build Coastguard Worker auto_dir);
491*49cdfc7eSAndroid Build Coastguard Worker exit(1);
492*49cdfc7eSAndroid Build Coastguard Worker }
493*49cdfc7eSAndroid Build Coastguard Worker }
494*49cdfc7eSAndroid Build Coastguard Worker } else {
495*49cdfc7eSAndroid Build Coastguard Worker if (!(statbuf.st_mode & S_IFDIR)) {
496*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
497*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %s already exists and is not a directory\n",
498*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, auto_dir);
499*49cdfc7eSAndroid Build Coastguard Worker exit(1);
500*49cdfc7eSAndroid Build Coastguard Worker }
501*49cdfc7eSAndroid Build Coastguard Worker }
502*49cdfc7eSAndroid Build Coastguard Worker break;
503*49cdfc7eSAndroid Build Coastguard Worker
504*49cdfc7eSAndroid Build Coastguard Worker case 'D':
505*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i", &Debug) != 1) {
506*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
507*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --D option arg invalid\n",
508*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
509*49cdfc7eSAndroid Build Coastguard Worker usage();
510*49cdfc7eSAndroid Build Coastguard Worker exit(1);
511*49cdfc7eSAndroid Build Coastguard Worker }
512*49cdfc7eSAndroid Build Coastguard Worker break;
513*49cdfc7eSAndroid Build Coastguard Worker
514*49cdfc7eSAndroid Build Coastguard Worker case 'e':
515*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i", &Maxerrs) != 1) {
516*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
517*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --e option arg invalid\n",
518*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
519*49cdfc7eSAndroid Build Coastguard Worker usage();
520*49cdfc7eSAndroid Build Coastguard Worker exit(1);
521*49cdfc7eSAndroid Build Coastguard Worker }
522*49cdfc7eSAndroid Build Coastguard Worker break;
523*49cdfc7eSAndroid Build Coastguard Worker
524*49cdfc7eSAndroid Build Coastguard Worker case 'f':
525*49cdfc7eSAndroid Build Coastguard Worker auto_file = optarg;
526*49cdfc7eSAndroid Build Coastguard Worker break;
527*49cdfc7eSAndroid Build Coastguard Worker
528*49cdfc7eSAndroid Build Coastguard Worker case 'g':
529*49cdfc7eSAndroid Build Coastguard Worker if ((ret = sscanf(optarg, "%i%c", &grow_incr, &chr)) < 1
530*49cdfc7eSAndroid Build Coastguard Worker || grow_incr < 0) {
531*49cdfc7eSAndroid Build Coastguard Worker
532*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
533*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --g option arg invalid\n",
534*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
535*49cdfc7eSAndroid Build Coastguard Worker usage();
536*49cdfc7eSAndroid Build Coastguard Worker exit(1);
537*49cdfc7eSAndroid Build Coastguard Worker }
538*49cdfc7eSAndroid Build Coastguard Worker if (ret == 2) {
539*49cdfc7eSAndroid Build Coastguard Worker if (chr == 'b' || chr == 'B')
540*49cdfc7eSAndroid Build Coastguard Worker grow_incr *= 4096;
541*49cdfc7eSAndroid Build Coastguard Worker else {
542*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
543*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --g option arg invalid\n",
544*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
545*49cdfc7eSAndroid Build Coastguard Worker usage();
546*49cdfc7eSAndroid Build Coastguard Worker exit(1);
547*49cdfc7eSAndroid Build Coastguard Worker }
548*49cdfc7eSAndroid Build Coastguard Worker }
549*49cdfc7eSAndroid Build Coastguard Worker break;
550*49cdfc7eSAndroid Build Coastguard Worker
551*49cdfc7eSAndroid Build Coastguard Worker case 'H':
552*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%f", &delaysecs) != 1
553*49cdfc7eSAndroid Build Coastguard Worker || delaysecs < 0) {
554*49cdfc7eSAndroid Build Coastguard Worker
555*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
556*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --H option arg invalid\n",
557*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
558*49cdfc7eSAndroid Build Coastguard Worker usage();
559*49cdfc7eSAndroid Build Coastguard Worker exit(1);
560*49cdfc7eSAndroid Build Coastguard Worker }
561*49cdfc7eSAndroid Build Coastguard Worker break;
562*49cdfc7eSAndroid Build Coastguard Worker
563*49cdfc7eSAndroid Build Coastguard Worker case 'i':
564*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i", &iterations) != 1 ||
565*49cdfc7eSAndroid Build Coastguard Worker iterations < 0) {
566*49cdfc7eSAndroid Build Coastguard Worker
567*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
568*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --i option arg invalid\n",
569*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
570*49cdfc7eSAndroid Build Coastguard Worker usage();
571*49cdfc7eSAndroid Build Coastguard Worker exit(1);
572*49cdfc7eSAndroid Build Coastguard Worker }
573*49cdfc7eSAndroid Build Coastguard Worker break;
574*49cdfc7eSAndroid Build Coastguard Worker
575*49cdfc7eSAndroid Build Coastguard Worker case 'I':
576*49cdfc7eSAndroid Build Coastguard Worker #if NEWIO
577*49cdfc7eSAndroid Build Coastguard Worker if ((io_type = lio_parse_io_arg1(optarg)) == -1) {
578*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
579*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --I arg is invalid, must be s, p, f, a, l, L or r.\n",
580*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
581*49cdfc7eSAndroid Build Coastguard Worker exit(1);
582*49cdfc7eSAndroid Build Coastguard Worker }
583*49cdfc7eSAndroid Build Coastguard Worker if (io_type & LIO_RANDOM)
584*49cdfc7eSAndroid Build Coastguard Worker using_random++;
585*49cdfc7eSAndroid Build Coastguard Worker #else
586*49cdfc7eSAndroid Build Coastguard Worker if ((io_type = parse_io_arg(optarg)) == -1) {
587*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
588*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --I arg is invalid, must be s, p, f, a, l, L or r.\n",
589*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
590*49cdfc7eSAndroid Build Coastguard Worker exit(1);
591*49cdfc7eSAndroid Build Coastguard Worker }
592*49cdfc7eSAndroid Build Coastguard Worker if (io_type == 99) /* hold-over until tlibio.h */
593*49cdfc7eSAndroid Build Coastguard Worker using_random++;
594*49cdfc7eSAndroid Build Coastguard Worker #endif
595*49cdfc7eSAndroid Build Coastguard Worker break;
596*49cdfc7eSAndroid Build Coastguard Worker
597*49cdfc7eSAndroid Build Coastguard Worker case 'l':
598*49cdfc7eSAndroid Build Coastguard Worker lockfile++;
599*49cdfc7eSAndroid Build Coastguard Worker if (lockfile > 2)
600*49cdfc7eSAndroid Build Coastguard Worker lockfile = 2; /* lockfile can only be 1 or 2 */
601*49cdfc7eSAndroid Build Coastguard Worker break;
602*49cdfc7eSAndroid Build Coastguard Worker
603*49cdfc7eSAndroid Build Coastguard Worker case 'L':
604*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i", &time_iterval) != 1 ||
605*49cdfc7eSAndroid Build Coastguard Worker time_iterval < 0) {
606*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
607*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --L option arg invalid\n",
608*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
609*49cdfc7eSAndroid Build Coastguard Worker usage();
610*49cdfc7eSAndroid Build Coastguard Worker exit(1);
611*49cdfc7eSAndroid Build Coastguard Worker }
612*49cdfc7eSAndroid Build Coastguard Worker break;
613*49cdfc7eSAndroid Build Coastguard Worker
614*49cdfc7eSAndroid Build Coastguard Worker case 'n':
615*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i:%i", &num_procs, &forker_mode) <
616*49cdfc7eSAndroid Build Coastguard Worker 1 || num_procs < 0) {
617*49cdfc7eSAndroid Build Coastguard Worker
618*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
619*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --n option arg invalid\n",
620*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
621*49cdfc7eSAndroid Build Coastguard Worker usage();
622*49cdfc7eSAndroid Build Coastguard Worker exit(1);
623*49cdfc7eSAndroid Build Coastguard Worker }
624*49cdfc7eSAndroid Build Coastguard Worker
625*49cdfc7eSAndroid Build Coastguard Worker break;
626*49cdfc7eSAndroid Build Coastguard Worker
627*49cdfc7eSAndroid Build Coastguard Worker case 'N':
628*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i", &num_auto_files) != 1 ||
629*49cdfc7eSAndroid Build Coastguard Worker num_auto_files < 0) {
630*49cdfc7eSAndroid Build Coastguard Worker
631*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
632*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --N option arg invalid\n",
633*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
634*49cdfc7eSAndroid Build Coastguard Worker usage();
635*49cdfc7eSAndroid Build Coastguard Worker exit(1);
636*49cdfc7eSAndroid Build Coastguard Worker }
637*49cdfc7eSAndroid Build Coastguard Worker break;
638*49cdfc7eSAndroid Build Coastguard Worker
639*49cdfc7eSAndroid Build Coastguard Worker case 'O':
640*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i", &Alignment) != 1 ||
641*49cdfc7eSAndroid Build Coastguard Worker Alignment < 0) {
642*49cdfc7eSAndroid Build Coastguard Worker
643*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
644*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --O option arg invalid\n",
645*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
646*49cdfc7eSAndroid Build Coastguard Worker usage();
647*49cdfc7eSAndroid Build Coastguard Worker exit(1);
648*49cdfc7eSAndroid Build Coastguard Worker }
649*49cdfc7eSAndroid Build Coastguard Worker break;
650*49cdfc7eSAndroid Build Coastguard Worker
651*49cdfc7eSAndroid Build Coastguard Worker case 'o':
652*49cdfc7eSAndroid Build Coastguard Worker if (strcmp(optarg, "random") == 0) {
653*49cdfc7eSAndroid Build Coastguard Worker open_flags = RANDOM_OPEN;
654*49cdfc7eSAndroid Build Coastguard Worker using_random++;
655*49cdfc7eSAndroid Build Coastguard Worker
656*49cdfc7eSAndroid Build Coastguard Worker } else if ((open_flags = parse_open_flags(optarg, NULL))
657*49cdfc7eSAndroid Build Coastguard Worker == -1) {
658*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
659*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --o arg contains invalid flag\n",
660*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
661*49cdfc7eSAndroid Build Coastguard Worker exit(1);
662*49cdfc7eSAndroid Build Coastguard Worker }
663*49cdfc7eSAndroid Build Coastguard Worker break;
664*49cdfc7eSAndroid Build Coastguard Worker
665*49cdfc7eSAndroid Build Coastguard Worker case 'p': /* pre allocate space */
666*49cdfc7eSAndroid Build Coastguard Worker #ifdef linux
667*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: --p is illegal option on linux system\n",
668*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
669*49cdfc7eSAndroid Build Coastguard Worker exit(1);
670*49cdfc7eSAndroid Build Coastguard Worker #else
671*49cdfc7eSAndroid Build Coastguard Worker pre_alloc_space++;
672*49cdfc7eSAndroid Build Coastguard Worker #endif
673*49cdfc7eSAndroid Build Coastguard Worker break;
674*49cdfc7eSAndroid Build Coastguard Worker
675*49cdfc7eSAndroid Build Coastguard Worker case 'P':
676*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
677*49cdfc7eSAndroid Build Coastguard Worker if (strcmp(optarg, "PANIC") != 0) {
678*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: --P arg must be PANIC\n",
679*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
680*49cdfc7eSAndroid Build Coastguard Worker exit(1);
681*49cdfc7eSAndroid Build Coastguard Worker }
682*49cdfc7eSAndroid Build Coastguard Worker Upanic_on_error++;
683*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: Will call upanic after writes\n", Progname, TagName);
684*49cdfc7eSAndroid Build Coastguard Worker #else
685*49cdfc7eSAndroid Build Coastguard Worker printf
686*49cdfc7eSAndroid Build Coastguard Worker ("%s%s: --P is illegal option on non-cray system\n",
687*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
688*49cdfc7eSAndroid Build Coastguard Worker exit(1);
689*49cdfc7eSAndroid Build Coastguard Worker #endif
690*49cdfc7eSAndroid Build Coastguard Worker break;
691*49cdfc7eSAndroid Build Coastguard Worker
692*49cdfc7eSAndroid Build Coastguard Worker case 'q': /* file content or pattern */
693*49cdfc7eSAndroid Build Coastguard Worker switch (optarg[0]) {
694*49cdfc7eSAndroid Build Coastguard Worker case 'A':
695*49cdfc7eSAndroid Build Coastguard Worker Pattern = PATTERN_ALT;
696*49cdfc7eSAndroid Build Coastguard Worker break;
697*49cdfc7eSAndroid Build Coastguard Worker case 'a':
698*49cdfc7eSAndroid Build Coastguard Worker Pattern = PATTERN_ASCII;
699*49cdfc7eSAndroid Build Coastguard Worker break;
700*49cdfc7eSAndroid Build Coastguard Worker case 'p':
701*49cdfc7eSAndroid Build Coastguard Worker Pattern = PATTERN_PID;
702*49cdfc7eSAndroid Build Coastguard Worker break;
703*49cdfc7eSAndroid Build Coastguard Worker case 'o':
704*49cdfc7eSAndroid Build Coastguard Worker Pattern = PATTERN_OFFSET;
705*49cdfc7eSAndroid Build Coastguard Worker break;
706*49cdfc7eSAndroid Build Coastguard Worker case 'c':
707*49cdfc7eSAndroid Build Coastguard Worker Pattern = PATTERN_CHKER;
708*49cdfc7eSAndroid Build Coastguard Worker break;
709*49cdfc7eSAndroid Build Coastguard Worker case 'C':
710*49cdfc7eSAndroid Build Coastguard Worker Pattern = PATTERN_CNTING;
711*49cdfc7eSAndroid Build Coastguard Worker break;
712*49cdfc7eSAndroid Build Coastguard Worker case 'r':
713*49cdfc7eSAndroid Build Coastguard Worker Pattern = PATTERN_RANDOM;
714*49cdfc7eSAndroid Build Coastguard Worker using_random++;
715*49cdfc7eSAndroid Build Coastguard Worker break;
716*49cdfc7eSAndroid Build Coastguard Worker case 'z':
717*49cdfc7eSAndroid Build Coastguard Worker Pattern = PATTERN_ZEROS;
718*49cdfc7eSAndroid Build Coastguard Worker break;
719*49cdfc7eSAndroid Build Coastguard Worker case 'O':
720*49cdfc7eSAndroid Build Coastguard Worker Pattern = PATTERN_ONES;
721*49cdfc7eSAndroid Build Coastguard Worker break;
722*49cdfc7eSAndroid Build Coastguard Worker default:
723*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
724*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --C option arg invalid, A, a, p, o, c, C, r, z, or 0\n",
725*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
726*49cdfc7eSAndroid Build Coastguard Worker usage();
727*49cdfc7eSAndroid Build Coastguard Worker exit(1);
728*49cdfc7eSAndroid Build Coastguard Worker }
729*49cdfc7eSAndroid Build Coastguard Worker break;
730*49cdfc7eSAndroid Build Coastguard Worker
731*49cdfc7eSAndroid Build Coastguard Worker case 'R': /* random lseek before write arg: [min-]max */
732*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i-%i", &min_lseek, &max_lseek) !=
733*49cdfc7eSAndroid Build Coastguard Worker 2) {
734*49cdfc7eSAndroid Build Coastguard Worker min_lseek = 1; /* same as default in define */
735*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i%c", &max_lseek, &chr) !=
736*49cdfc7eSAndroid Build Coastguard Worker 1) {
737*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
738*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --R option arg invalid: [min-]max\n",
739*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
740*49cdfc7eSAndroid Build Coastguard Worker exit(1);
741*49cdfc7eSAndroid Build Coastguard Worker }
742*49cdfc7eSAndroid Build Coastguard Worker }
743*49cdfc7eSAndroid Build Coastguard Worker if (max_lseek < LSK_EOFMINUSGROW) {
744*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
745*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --R option, max_lseek is invalid\n",
746*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
747*49cdfc7eSAndroid Build Coastguard Worker exit(1);
748*49cdfc7eSAndroid Build Coastguard Worker }
749*49cdfc7eSAndroid Build Coastguard Worker Mode |= MODE_RAND_LSEEK;
750*49cdfc7eSAndroid Build Coastguard Worker using_random++;
751*49cdfc7eSAndroid Build Coastguard Worker break;
752*49cdfc7eSAndroid Build Coastguard Worker
753*49cdfc7eSAndroid Build Coastguard Worker case 'r': /* random io size arg: [min-]max[:mult] */
754*49cdfc7eSAndroid Build Coastguard Worker
755*49cdfc7eSAndroid Build Coastguard Worker /* min-max:mult format */
756*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i-%i:%i%c", &min_size, &max_size,
757*49cdfc7eSAndroid Build Coastguard Worker &mult_size, &chr) != 3) {
758*49cdfc7eSAndroid Build Coastguard Worker min_size = 1;
759*49cdfc7eSAndroid Build Coastguard Worker /* max:mult format */
760*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i:%i%c", &max_size,
761*49cdfc7eSAndroid Build Coastguard Worker &mult_size, &chr) != 2) {
762*49cdfc7eSAndroid Build Coastguard Worker /* min-max format */
763*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i-%i%c", &min_size,
764*49cdfc7eSAndroid Build Coastguard Worker &max_size, &chr) != 2) {
765*49cdfc7eSAndroid Build Coastguard Worker min_size = 1;
766*49cdfc7eSAndroid Build Coastguard Worker if (sscanf
767*49cdfc7eSAndroid Build Coastguard Worker (optarg, "%i%c", &max_size,
768*49cdfc7eSAndroid Build Coastguard Worker &chr) != 1) {
769*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
770*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --r option arg invalid: [min-]max[:mult]\n",
771*49cdfc7eSAndroid Build Coastguard Worker Progname,
772*49cdfc7eSAndroid Build Coastguard Worker TagName);
773*49cdfc7eSAndroid Build Coastguard Worker exit(1);
774*49cdfc7eSAndroid Build Coastguard Worker }
775*49cdfc7eSAndroid Build Coastguard Worker }
776*49cdfc7eSAndroid Build Coastguard Worker }
777*49cdfc7eSAndroid Build Coastguard Worker }
778*49cdfc7eSAndroid Build Coastguard Worker
779*49cdfc7eSAndroid Build Coastguard Worker if (max_size < 0) {
780*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
781*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --r option, max_size is invalid\n",
782*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
783*49cdfc7eSAndroid Build Coastguard Worker exit(1);
784*49cdfc7eSAndroid Build Coastguard Worker }
785*49cdfc7eSAndroid Build Coastguard Worker /*
786*49cdfc7eSAndroid Build Coastguard Worker * If min and max are the same, no randomness
787*49cdfc7eSAndroid Build Coastguard Worker */
788*49cdfc7eSAndroid Build Coastguard Worker if (min_size != max_size) {
789*49cdfc7eSAndroid Build Coastguard Worker Mode |= MODE_RAND_SIZE;
790*49cdfc7eSAndroid Build Coastguard Worker using_random++;
791*49cdfc7eSAndroid Build Coastguard Worker }
792*49cdfc7eSAndroid Build Coastguard Worker break;
793*49cdfc7eSAndroid Build Coastguard Worker
794*49cdfc7eSAndroid Build Coastguard Worker case 'S':
795*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i", &seq_auto_files) != 1 ||
796*49cdfc7eSAndroid Build Coastguard Worker seq_auto_files < 0) {
797*49cdfc7eSAndroid Build Coastguard Worker
798*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
799*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --S option arg invalid\n",
800*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
801*49cdfc7eSAndroid Build Coastguard Worker usage();
802*49cdfc7eSAndroid Build Coastguard Worker exit(1);
803*49cdfc7eSAndroid Build Coastguard Worker }
804*49cdfc7eSAndroid Build Coastguard Worker break;
805*49cdfc7eSAndroid Build Coastguard Worker
806*49cdfc7eSAndroid Build Coastguard Worker case 's': /* format: seed[,seed...] */
807*49cdfc7eSAndroid Build Coastguard Worker
808*49cdfc7eSAndroid Build Coastguard Worker /* count the number of seeds */
809*49cdfc7eSAndroid Build Coastguard Worker cptr = optarg;
810*49cdfc7eSAndroid Build Coastguard Worker for (Nseeds = 1; *cptr; Nseeds++) {
811*49cdfc7eSAndroid Build Coastguard Worker if ((filename = strchr(cptr, ',')) == NULL)
812*49cdfc7eSAndroid Build Coastguard Worker break;
813*49cdfc7eSAndroid Build Coastguard Worker cptr = filename;
814*49cdfc7eSAndroid Build Coastguard Worker cptr++;
815*49cdfc7eSAndroid Build Coastguard Worker }
816*49cdfc7eSAndroid Build Coastguard Worker Seeds = malloc(Nseeds * sizeof(int));
817*49cdfc7eSAndroid Build Coastguard Worker
818*49cdfc7eSAndroid Build Coastguard Worker /*
819*49cdfc7eSAndroid Build Coastguard Worker * check that each seed is valid and put them in
820*49cdfc7eSAndroid Build Coastguard Worker * the newly malloc'ed Seeds arrary.
821*49cdfc7eSAndroid Build Coastguard Worker */
822*49cdfc7eSAndroid Build Coastguard Worker filename = cptr = optarg;
823*49cdfc7eSAndroid Build Coastguard Worker for (Nseeds = 0; *cptr; Nseeds++) {
824*49cdfc7eSAndroid Build Coastguard Worker if ((filename = strchr(cptr, ',')) == NULL) {
825*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(cptr, "%i", &Seeds[Nseeds]) <
826*49cdfc7eSAndroid Build Coastguard Worker 1) {
827*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
828*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --s option arg %s invalid\n",
829*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName,
830*49cdfc7eSAndroid Build Coastguard Worker cptr);
831*49cdfc7eSAndroid Build Coastguard Worker usage();
832*49cdfc7eSAndroid Build Coastguard Worker exit(1);
833*49cdfc7eSAndroid Build Coastguard Worker }
834*49cdfc7eSAndroid Build Coastguard Worker Nseeds++;
835*49cdfc7eSAndroid Build Coastguard Worker break;
836*49cdfc7eSAndroid Build Coastguard Worker }
837*49cdfc7eSAndroid Build Coastguard Worker
838*49cdfc7eSAndroid Build Coastguard Worker *filename = '\0';
839*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(cptr, "%i", &Seeds[Nseeds]) < 1) {
840*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
841*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --s option arg %s invalid\n",
842*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, cptr);
843*49cdfc7eSAndroid Build Coastguard Worker usage();
844*49cdfc7eSAndroid Build Coastguard Worker exit(1);
845*49cdfc7eSAndroid Build Coastguard Worker }
846*49cdfc7eSAndroid Build Coastguard Worker *filename = ','; /* restore string */
847*49cdfc7eSAndroid Build Coastguard Worker cptr = filename;
848*49cdfc7eSAndroid Build Coastguard Worker cptr++;
849*49cdfc7eSAndroid Build Coastguard Worker }
850*49cdfc7eSAndroid Build Coastguard Worker break;
851*49cdfc7eSAndroid Build Coastguard Worker
852*49cdfc7eSAndroid Build Coastguard Worker case 't':
853*49cdfc7eSAndroid Build Coastguard Worker if ((ret =
854*49cdfc7eSAndroid Build Coastguard Worker sscanf(optarg, "%i%c", &trunc_incr, &chr)) < 1
855*49cdfc7eSAndroid Build Coastguard Worker || trunc_incr < 0) {
856*49cdfc7eSAndroid Build Coastguard Worker
857*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
858*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --t option arg invalid\n",
859*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
860*49cdfc7eSAndroid Build Coastguard Worker usage();
861*49cdfc7eSAndroid Build Coastguard Worker exit(1);
862*49cdfc7eSAndroid Build Coastguard Worker }
863*49cdfc7eSAndroid Build Coastguard Worker if (ret == 2) {
864*49cdfc7eSAndroid Build Coastguard Worker if (chr == 'b' || chr == 'B')
865*49cdfc7eSAndroid Build Coastguard Worker trunc_incr *= 4096;
866*49cdfc7eSAndroid Build Coastguard Worker else {
867*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
868*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --t option arg invalid\n",
869*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
870*49cdfc7eSAndroid Build Coastguard Worker usage();
871*49cdfc7eSAndroid Build Coastguard Worker exit(1);
872*49cdfc7eSAndroid Build Coastguard Worker }
873*49cdfc7eSAndroid Build Coastguard Worker }
874*49cdfc7eSAndroid Build Coastguard Worker break;
875*49cdfc7eSAndroid Build Coastguard Worker
876*49cdfc7eSAndroid Build Coastguard Worker case 'T': /* truncate interval */
877*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i%c", &trunc_inter, &chr) != 1 ||
878*49cdfc7eSAndroid Build Coastguard Worker trunc_inter < 0) {
879*49cdfc7eSAndroid Build Coastguard Worker
880*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
881*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --T option arg invalid\n",
882*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
883*49cdfc7eSAndroid Build Coastguard Worker usage();
884*49cdfc7eSAndroid Build Coastguard Worker exit(1);
885*49cdfc7eSAndroid Build Coastguard Worker }
886*49cdfc7eSAndroid Build Coastguard Worker break;
887*49cdfc7eSAndroid Build Coastguard Worker
888*49cdfc7eSAndroid Build Coastguard Worker case 'u':
889*49cdfc7eSAndroid Build Coastguard Worker remove_files++;
890*49cdfc7eSAndroid Build Coastguard Worker break;
891*49cdfc7eSAndroid Build Coastguard Worker
892*49cdfc7eSAndroid Build Coastguard Worker case 'U': /* how often to unlink file */
893*49cdfc7eSAndroid Build Coastguard Worker /*
894*49cdfc7eSAndroid Build Coastguard Worker * formats:
895*49cdfc7eSAndroid Build Coastguard Worker * A-B - randomly pick interval between A and B
896*49cdfc7eSAndroid Build Coastguard Worker * X - unlink file every X iteration
897*49cdfc7eSAndroid Build Coastguard Worker */
898*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(optarg, "%i-%i", &unlink_inter,
899*49cdfc7eSAndroid Build Coastguard Worker &unlink_inter_ran) == 2) {
900*49cdfc7eSAndroid Build Coastguard Worker
901*49cdfc7eSAndroid Build Coastguard Worker if (unlink_inter < 0 || unlink_inter_ran < 0) {
902*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
903*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --U option arg invalid\n",
904*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
905*49cdfc7eSAndroid Build Coastguard Worker usage();
906*49cdfc7eSAndroid Build Coastguard Worker exit(1);
907*49cdfc7eSAndroid Build Coastguard Worker }
908*49cdfc7eSAndroid Build Coastguard Worker /* ensure unlink_inter contains smaller value */
909*49cdfc7eSAndroid Build Coastguard Worker if (unlink_inter > unlink_inter_ran) {
910*49cdfc7eSAndroid Build Coastguard Worker tmp = unlink_inter_ran;
911*49cdfc7eSAndroid Build Coastguard Worker unlink_inter_ran = unlink_inter;
912*49cdfc7eSAndroid Build Coastguard Worker unlink_inter = tmp;
913*49cdfc7eSAndroid Build Coastguard Worker }
914*49cdfc7eSAndroid Build Coastguard Worker using_random++;
915*49cdfc7eSAndroid Build Coastguard Worker
916*49cdfc7eSAndroid Build Coastguard Worker } else if (sscanf(optarg, "%i%c", &unlink_inter, &chr)
917*49cdfc7eSAndroid Build Coastguard Worker != 1 || unlink_inter < 0) {
918*49cdfc7eSAndroid Build Coastguard Worker
919*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
920*49cdfc7eSAndroid Build Coastguard Worker "%s%s: --U option arg invalid\n",
921*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
922*49cdfc7eSAndroid Build Coastguard Worker usage();
923*49cdfc7eSAndroid Build Coastguard Worker exit(1);
924*49cdfc7eSAndroid Build Coastguard Worker }
925*49cdfc7eSAndroid Build Coastguard Worker break;
926*49cdfc7eSAndroid Build Coastguard Worker
927*49cdfc7eSAndroid Build Coastguard Worker case 'x':
928*49cdfc7eSAndroid Build Coastguard Worker if (reexec != REXEC_DONE)
929*49cdfc7eSAndroid Build Coastguard Worker reexec = REXEC_DOIT;
930*49cdfc7eSAndroid Build Coastguard Worker break;
931*49cdfc7eSAndroid Build Coastguard Worker
932*49cdfc7eSAndroid Build Coastguard Worker case 'w':
933*49cdfc7eSAndroid Build Coastguard Worker Mode |= MODE_GROW_BY_LSEEK;
934*49cdfc7eSAndroid Build Coastguard Worker break;
935*49cdfc7eSAndroid Build Coastguard Worker
936*49cdfc7eSAndroid Build Coastguard Worker case 'W':
937*49cdfc7eSAndroid Build Coastguard Worker TCID = optarg;
938*49cdfc7eSAndroid Build Coastguard Worker sprintf(TagName, "(%.39s)", optarg);
939*49cdfc7eSAndroid Build Coastguard Worker break;
940*49cdfc7eSAndroid Build Coastguard Worker
941*49cdfc7eSAndroid Build Coastguard Worker case 'y':
942*49cdfc7eSAndroid Build Coastguard Worker Sync_with_others = 1;
943*49cdfc7eSAndroid Build Coastguard Worker break;
944*49cdfc7eSAndroid Build Coastguard Worker
945*49cdfc7eSAndroid Build Coastguard Worker case '?':
946*49cdfc7eSAndroid Build Coastguard Worker usage();
947*49cdfc7eSAndroid Build Coastguard Worker exit(1);
948*49cdfc7eSAndroid Build Coastguard Worker break;
949*49cdfc7eSAndroid Build Coastguard Worker }
950*49cdfc7eSAndroid Build Coastguard Worker }
951*49cdfc7eSAndroid Build Coastguard Worker
952*49cdfc7eSAndroid Build Coastguard Worker if (Debug == 1) {
953*49cdfc7eSAndroid Build Coastguard Worker cptr = getenv("TOUTPUT");
954*49cdfc7eSAndroid Build Coastguard Worker if ((cptr != NULL) && (strcmp(cptr, "NOPASS") == 0)) {
955*49cdfc7eSAndroid Build Coastguard Worker Debug = 0;
956*49cdfc7eSAndroid Build Coastguard Worker }
957*49cdfc7eSAndroid Build Coastguard Worker }
958*49cdfc7eSAndroid Build Coastguard Worker
959*49cdfc7eSAndroid Build Coastguard Worker if (Pattern == PATTERN_RANDOM) {
960*49cdfc7eSAndroid Build Coastguard Worker no_file_check = 1;
961*49cdfc7eSAndroid Build Coastguard Worker if (write_check_inter || file_check_inter)
962*49cdfc7eSAndroid Build Coastguard Worker printf
963*49cdfc7eSAndroid Build Coastguard Worker ("%s%s: %d Using random pattern - no data checking will be performed!\n",
964*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, getpid());
965*49cdfc7eSAndroid Build Coastguard Worker } else if (max_lseek == LSK_EOFPLUSGROW || Mode & MODE_GROW_BY_LSEEK) {
966*49cdfc7eSAndroid Build Coastguard Worker no_file_check = 1;
967*49cdfc7eSAndroid Build Coastguard Worker
968*49cdfc7eSAndroid Build Coastguard Worker if (file_check_inter)
969*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: %d Using random lseek beyond EOF or lseek grow,\n\
970*49cdfc7eSAndroid Build Coastguard Worker no whole file checking will be performed!\n", Progname, TagName,
971*49cdfc7eSAndroid Build Coastguard Worker getpid());
972*49cdfc7eSAndroid Build Coastguard Worker
973*49cdfc7eSAndroid Build Coastguard Worker }
974*49cdfc7eSAndroid Build Coastguard Worker
975*49cdfc7eSAndroid Build Coastguard Worker if (Mode & MODE_RAND_SIZE)
976*49cdfc7eSAndroid Build Coastguard Worker grow_incr = max_size;
977*49cdfc7eSAndroid Build Coastguard Worker
978*49cdfc7eSAndroid Build Coastguard Worker set_sig();
979*49cdfc7eSAndroid Build Coastguard Worker
980*49cdfc7eSAndroid Build Coastguard Worker Opid = getpid();
981*49cdfc7eSAndroid Build Coastguard Worker Pid = Opid;
982*49cdfc7eSAndroid Build Coastguard Worker
983*49cdfc7eSAndroid Build Coastguard Worker if (backgrnd) {
984*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 1)
985*49cdfc7eSAndroid Build Coastguard Worker printf
986*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG2 forking, returning control to the user\n",
987*49cdfc7eSAndroid Build Coastguard Worker Progname, Opid);
988*49cdfc7eSAndroid Build Coastguard Worker background(Progname); /* give user their prompt back */
989*49cdfc7eSAndroid Build Coastguard Worker }
990*49cdfc7eSAndroid Build Coastguard Worker #if CRAY
991*49cdfc7eSAndroid Build Coastguard Worker if (Sync_with_others)
992*49cdfc7eSAndroid Build Coastguard Worker setpgrp();
993*49cdfc7eSAndroid Build Coastguard Worker #endif
994*49cdfc7eSAndroid Build Coastguard Worker
995*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 3) {
996*49cdfc7eSAndroid Build Coastguard Worker #if NEWIO
997*49cdfc7eSAndroid Build Coastguard Worker lio_set_debug(Debug - 3);
998*49cdfc7eSAndroid Build Coastguard Worker #else
999*49cdfc7eSAndroid Build Coastguard Worker set_iowrite_debug(Debug - 3);
1000*49cdfc7eSAndroid Build Coastguard Worker #endif
1001*49cdfc7eSAndroid Build Coastguard Worker }
1002*49cdfc7eSAndroid Build Coastguard Worker
1003*49cdfc7eSAndroid Build Coastguard Worker /*
1004*49cdfc7eSAndroid Build Coastguard Worker * Print some program information here if debug is turned on to
1005*49cdfc7eSAndroid Build Coastguard Worker * level 3 or higher.
1006*49cdfc7eSAndroid Build Coastguard Worker */
1007*49cdfc7eSAndroid Build Coastguard Worker
1008*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2) {
1009*49cdfc7eSAndroid Build Coastguard Worker
1010*49cdfc7eSAndroid Build Coastguard Worker if (Mode & MODE_GROW_BY_LSEEK)
1011*49cdfc7eSAndroid Build Coastguard Worker printf
1012*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG lseeking past end of file, writting a \"w\"\n",
1013*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid);
1014*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_OFFSET)
1015*49cdfc7eSAndroid Build Coastguard Worker printf
1016*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %d<byteoffset>%d per word pattern multi-writers.\n",
1017*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, STATIC_NUM, STATIC_NUM);
1018*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_PID)
1019*49cdfc7eSAndroid Build Coastguard Worker printf
1020*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 <pid><byteoffset><pid> per word pattern - 1 writer\n",
1021*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid);
1022*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ASCII)
1023*49cdfc7eSAndroid Build Coastguard Worker printf
1024*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 ascii pattern (vi'able)- allows multiple writers\n",
1025*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid);
1026*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ALT)
1027*49cdfc7eSAndroid Build Coastguard Worker printf
1028*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 alt bit pattern - allows multiple writers\n",
1029*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid);
1030*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_CHKER)
1031*49cdfc7eSAndroid Build Coastguard Worker printf
1032*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 checkerboard pattern - allows multiple writers\n",
1033*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid);
1034*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_CNTING)
1035*49cdfc7eSAndroid Build Coastguard Worker printf
1036*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 counting pattern - allows multiple writers\n",
1037*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid);
1038*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_RANDOM)
1039*49cdfc7eSAndroid Build Coastguard Worker printf
1040*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 random integer pattern - no write/file checking\n",
1041*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid);
1042*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ONES)
1043*49cdfc7eSAndroid Build Coastguard Worker printf
1044*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 all ones pattern - allows multiple writers\n",
1045*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid);
1046*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ZEROS)
1047*49cdfc7eSAndroid Build Coastguard Worker printf
1048*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 all zeros pattern - allows multiple writers\n",
1049*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid);
1050*49cdfc7eSAndroid Build Coastguard Worker
1051*49cdfc7eSAndroid Build Coastguard Worker else
1052*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 unknown pattern\n",
1053*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid);
1054*49cdfc7eSAndroid Build Coastguard Worker if (bytes_to_consume)
1055*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 bytes_to_consume = %d\n",
1056*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, bytes_to_consume);
1057*49cdfc7eSAndroid Build Coastguard Worker printf
1058*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 Maxerrs = %d, pre_alloc_space = %d, filelocking = %d\n",
1059*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, Maxerrs, pre_alloc_space, lockfile);
1060*49cdfc7eSAndroid Build Coastguard Worker
1061*49cdfc7eSAndroid Build Coastguard Worker printf
1062*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 Debug = %d, remove files in cleanup : %d\n",
1063*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, Debug, remove_files);
1064*49cdfc7eSAndroid Build Coastguard Worker
1065*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 Mode = %#o\n", Progname, Pid, Mode);
1066*49cdfc7eSAndroid Build Coastguard Worker
1067*49cdfc7eSAndroid Build Coastguard Worker if (open_flags == RANDOM_OPEN)
1068*49cdfc7eSAndroid Build Coastguard Worker printf
1069*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 open_flags = (random), io_type = %#o\n",
1070*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, io_type);
1071*49cdfc7eSAndroid Build Coastguard Worker else
1072*49cdfc7eSAndroid Build Coastguard Worker printf
1073*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 open_flags = %#o, io_type = %#o\n",
1074*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, open_flags, io_type);
1075*49cdfc7eSAndroid Build Coastguard Worker
1076*49cdfc7eSAndroid Build Coastguard Worker if (Mode & MODE_RAND_SIZE) {
1077*49cdfc7eSAndroid Build Coastguard Worker printf
1078*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 random write/trunc: min=%d, max=%d, mult = %d\n",
1079*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, min_size, max_size, mult_size);
1080*49cdfc7eSAndroid Build Coastguard Worker } else {
1081*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 grow_incr = %d\n",
1082*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, grow_incr);
1083*49cdfc7eSAndroid Build Coastguard Worker }
1084*49cdfc7eSAndroid Build Coastguard Worker if (Mode & MODE_RAND_LSEEK) {
1085*49cdfc7eSAndroid Build Coastguard Worker if (max_lseek == LSK_EOF)
1086*49cdfc7eSAndroid Build Coastguard Worker printf
1087*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 random lseek: min=%d, max=<endoffile>\n",
1088*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, min_lseek);
1089*49cdfc7eSAndroid Build Coastguard Worker else if (max_lseek == LSK_EOFPLUSGROW)
1090*49cdfc7eSAndroid Build Coastguard Worker printf
1091*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 random lseek: min=%d, max=<endoffile+iosize>\n",
1092*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, min_lseek);
1093*49cdfc7eSAndroid Build Coastguard Worker else if (max_lseek == LSK_EOFMINUSGROW)
1094*49cdfc7eSAndroid Build Coastguard Worker printf
1095*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 random lseek: min=%d, max=<endoffile-iosize>\n",
1096*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, min_lseek);
1097*49cdfc7eSAndroid Build Coastguard Worker else
1098*49cdfc7eSAndroid Build Coastguard Worker printf
1099*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 random lseek: min=%d, max=%d\n",
1100*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, min_lseek, max_lseek);
1101*49cdfc7eSAndroid Build Coastguard Worker }
1102*49cdfc7eSAndroid Build Coastguard Worker
1103*49cdfc7eSAndroid Build Coastguard Worker printf
1104*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 check write interval = %d, check file interval = %d\n",
1105*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, write_check_inter, file_check_inter);
1106*49cdfc7eSAndroid Build Coastguard Worker
1107*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 trunc interval = %d, trunc_incr = %d\n",
1108*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, trunc_inter, trunc_incr);
1109*49cdfc7eSAndroid Build Coastguard Worker
1110*49cdfc7eSAndroid Build Coastguard Worker if (no_file_check)
1111*49cdfc7eSAndroid Build Coastguard Worker printf
1112*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 no whole file checking will be done\n",
1113*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid);
1114*49cdfc7eSAndroid Build Coastguard Worker
1115*49cdfc7eSAndroid Build Coastguard Worker if (unlink_inter_ran == -1) {
1116*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 unlink_inter = %d\n",
1117*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, unlink_inter);
1118*49cdfc7eSAndroid Build Coastguard Worker } else {
1119*49cdfc7eSAndroid Build Coastguard Worker printf
1120*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 unlink_inter = %d, unlink_inter_ran = %d\n",
1121*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, unlink_inter, unlink_inter_ran);
1122*49cdfc7eSAndroid Build Coastguard Worker }
1123*49cdfc7eSAndroid Build Coastguard Worker
1124*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 8) {
1125*49cdfc7eSAndroid Build Coastguard Worker num = sizeof(Open_flags) / sizeof(int);
1126*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG9 random open flags values:\n",
1127*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid);
1128*49cdfc7eSAndroid Build Coastguard Worker for (ind = 0; ind < num; ind++) {
1129*49cdfc7eSAndroid Build Coastguard Worker printf("\t%#o\n", Open_flags[ind]);
1130*49cdfc7eSAndroid Build Coastguard Worker }
1131*49cdfc7eSAndroid Build Coastguard Worker }
1132*49cdfc7eSAndroid Build Coastguard Worker }
1133*49cdfc7eSAndroid Build Coastguard Worker /* end of DEBUG > 2 */
1134*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 1 && num_procs > 1) {
1135*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG2 about to fork %d more copies\n", Progname,
1136*49cdfc7eSAndroid Build Coastguard Worker Opid, num_procs - 1);
1137*49cdfc7eSAndroid Build Coastguard Worker }
1138*49cdfc7eSAndroid Build Coastguard Worker
1139*49cdfc7eSAndroid Build Coastguard Worker fflush(stdout); /* ensure pending i/o is flushed before forking */
1140*49cdfc7eSAndroid Build Coastguard Worker fflush(stderr);
1141*49cdfc7eSAndroid Build Coastguard Worker
1142*49cdfc7eSAndroid Build Coastguard Worker forker(num_procs, forker_mode, Progname);
1143*49cdfc7eSAndroid Build Coastguard Worker
1144*49cdfc7eSAndroid Build Coastguard Worker Pid = getpid(); /* reset after the forks */
1145*49cdfc7eSAndroid Build Coastguard Worker /*
1146*49cdfc7eSAndroid Build Coastguard Worker * If user specified random seed(s), get that random seed value.
1147*49cdfc7eSAndroid Build Coastguard Worker * get random seed if it was not specified by the user.
1148*49cdfc7eSAndroid Build Coastguard Worker * This is done after the forks, because pid is used to get the seed.
1149*49cdfc7eSAndroid Build Coastguard Worker */
1150*49cdfc7eSAndroid Build Coastguard Worker if (Nseeds == 1) {
1151*49cdfc7eSAndroid Build Coastguard Worker /*
1152*49cdfc7eSAndroid Build Coastguard Worker * If only one seed specified, all processes will get that seed.
1153*49cdfc7eSAndroid Build Coastguard Worker */
1154*49cdfc7eSAndroid Build Coastguard Worker Seed = Seeds[0];
1155*49cdfc7eSAndroid Build Coastguard Worker } else if (Nseeds > 1) {
1156*49cdfc7eSAndroid Build Coastguard Worker /*
1157*49cdfc7eSAndroid Build Coastguard Worker * More than one seed was specified.
1158*49cdfc7eSAndroid Build Coastguard Worker * The original process gets the first seed. Each
1159*49cdfc7eSAndroid Build Coastguard Worker * process will be get the next seed in the specified list.
1160*49cdfc7eSAndroid Build Coastguard Worker */
1161*49cdfc7eSAndroid Build Coastguard Worker if (Opid == Pid) {
1162*49cdfc7eSAndroid Build Coastguard Worker Seed = Seeds[0];
1163*49cdfc7eSAndroid Build Coastguard Worker } else {
1164*49cdfc7eSAndroid Build Coastguard Worker /*
1165*49cdfc7eSAndroid Build Coastguard Worker * If user didn't specify enough seeds, use default method.
1166*49cdfc7eSAndroid Build Coastguard Worker */
1167*49cdfc7eSAndroid Build Coastguard Worker if (Forker_npids >= Nseeds) {
1168*49cdfc7eSAndroid Build Coastguard Worker struct timeval ts;
1169*49cdfc7eSAndroid Build Coastguard Worker gettimeofday(&ts, NULL);
1170*49cdfc7eSAndroid Build Coastguard Worker Seed = ts.tv_sec + Pid; /* default random seed */
1171*49cdfc7eSAndroid Build Coastguard Worker } else {
1172*49cdfc7eSAndroid Build Coastguard Worker Seed = Seeds[Forker_npids];
1173*49cdfc7eSAndroid Build Coastguard Worker }
1174*49cdfc7eSAndroid Build Coastguard Worker }
1175*49cdfc7eSAndroid Build Coastguard Worker } else {
1176*49cdfc7eSAndroid Build Coastguard Worker /*
1177*49cdfc7eSAndroid Build Coastguard Worker * Generate a random seed based on time and pid.
1178*49cdfc7eSAndroid Build Coastguard Worker * It has a good chance of being unique for each pid.
1179*49cdfc7eSAndroid Build Coastguard Worker */
1180*49cdfc7eSAndroid Build Coastguard Worker struct timeval ts;
1181*49cdfc7eSAndroid Build Coastguard Worker gettimeofday(&ts, NULL);
1182*49cdfc7eSAndroid Build Coastguard Worker Seed = ts.tv_sec + Pid; /* default random seed */
1183*49cdfc7eSAndroid Build Coastguard Worker //Seed=time(0) + Pid; /* default random seed */
1184*49cdfc7eSAndroid Build Coastguard Worker
1185*49cdfc7eSAndroid Build Coastguard Worker }
1186*49cdfc7eSAndroid Build Coastguard Worker
1187*49cdfc7eSAndroid Build Coastguard Worker random_range_seed(Seed);
1188*49cdfc7eSAndroid Build Coastguard Worker
1189*49cdfc7eSAndroid Build Coastguard Worker if (using_random && Debug > 0)
1190*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: %d DEBUG1 Using random seed of %d\n",
1191*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, Seed);
1192*49cdfc7eSAndroid Build Coastguard Worker
1193*49cdfc7eSAndroid Build Coastguard Worker if (unlink_inter_ran > 0) {
1194*49cdfc7eSAndroid Build Coastguard Worker /*
1195*49cdfc7eSAndroid Build Coastguard Worker * Find unlinking file interval. This must be done after
1196*49cdfc7eSAndroid Build Coastguard Worker * the seed was set. This allows multiple copies to
1197*49cdfc7eSAndroid Build Coastguard Worker * get different intervals.
1198*49cdfc7eSAndroid Build Coastguard Worker */
1199*49cdfc7eSAndroid Build Coastguard Worker tmp = unlink_inter;
1200*49cdfc7eSAndroid Build Coastguard Worker unlink_inter =
1201*49cdfc7eSAndroid Build Coastguard Worker (int)random_range(tmp, unlink_inter_ran, 1, NULL);
1202*49cdfc7eSAndroid Build Coastguard Worker
1203*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2)
1204*49cdfc7eSAndroid Build Coastguard Worker printf
1205*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 Unlink interval is %d (random %d - %d)\n",
1206*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, unlink_inter, tmp,
1207*49cdfc7eSAndroid Build Coastguard Worker unlink_inter_ran);
1208*49cdfc7eSAndroid Build Coastguard Worker }
1209*49cdfc7eSAndroid Build Coastguard Worker
1210*49cdfc7eSAndroid Build Coastguard Worker /*
1211*49cdfc7eSAndroid Build Coastguard Worker * re-exec all childern if reexec is set to REXEC_DOIT.
1212*49cdfc7eSAndroid Build Coastguard Worker * This is useful on MPP systems to get the
1213*49cdfc7eSAndroid Build Coastguard Worker * child process on another PE.
1214*49cdfc7eSAndroid Build Coastguard Worker */
1215*49cdfc7eSAndroid Build Coastguard Worker if (reexec == REXEC_DOIT && Opid != Pid) {
1216*49cdfc7eSAndroid Build Coastguard Worker if (exec_path == NULL) {
1217*49cdfc7eSAndroid Build Coastguard Worker exec_path = argv[0];
1218*49cdfc7eSAndroid Build Coastguard Worker /* Get space for cmd (2 extra, 1 for - and 1 fro NULL */
1219*49cdfc7eSAndroid Build Coastguard Worker argv[0] = malloc(strlen(exec_path) + 2);
1220*49cdfc7eSAndroid Build Coastguard Worker sprintf(argv[0], "-%s", exec_path);
1221*49cdfc7eSAndroid Build Coastguard Worker }
1222*49cdfc7eSAndroid Build Coastguard Worker
1223*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2)
1224*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 %s/%d: execvp(%s, argv)\n",
1225*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, argv[0]);
1226*49cdfc7eSAndroid Build Coastguard Worker
1227*49cdfc7eSAndroid Build Coastguard Worker execvp(argv[0], argv);
1228*49cdfc7eSAndroid Build Coastguard Worker }
1229*49cdfc7eSAndroid Build Coastguard Worker
1230*49cdfc7eSAndroid Build Coastguard Worker /*** begin filename stuff here *****/
1231*49cdfc7eSAndroid Build Coastguard Worker /*
1232*49cdfc7eSAndroid Build Coastguard Worker * Determine the number of files to be dealt with
1233*49cdfc7eSAndroid Build Coastguard Worker */
1234*49cdfc7eSAndroid Build Coastguard Worker if (optind == argc) {
1235*49cdfc7eSAndroid Build Coastguard Worker /*
1236*49cdfc7eSAndroid Build Coastguard Worker * no cmd line files, therfore, set
1237*49cdfc7eSAndroid Build Coastguard Worker * the default number of auto created files
1238*49cdfc7eSAndroid Build Coastguard Worker */
1239*49cdfc7eSAndroid Build Coastguard Worker if (!num_auto_files && !seq_auto_files)
1240*49cdfc7eSAndroid Build Coastguard Worker num_auto_files = 1;
1241*49cdfc7eSAndroid Build Coastguard Worker } else {
1242*49cdfc7eSAndroid Build Coastguard Worker first_file_ind = optind;
1243*49cdfc7eSAndroid Build Coastguard Worker num_files += argc - optind;
1244*49cdfc7eSAndroid Build Coastguard Worker }
1245*49cdfc7eSAndroid Build Coastguard Worker
1246*49cdfc7eSAndroid Build Coastguard Worker if (num_auto_files) {
1247*49cdfc7eSAndroid Build Coastguard Worker num_files += num_auto_files;
1248*49cdfc7eSAndroid Build Coastguard Worker }
1249*49cdfc7eSAndroid Build Coastguard Worker
1250*49cdfc7eSAndroid Build Coastguard Worker if (seq_auto_files) {
1251*49cdfc7eSAndroid Build Coastguard Worker num_files += seq_auto_files;
1252*49cdfc7eSAndroid Build Coastguard Worker }
1253*49cdfc7eSAndroid Build Coastguard Worker
1254*49cdfc7eSAndroid Build Coastguard Worker /*
1255*49cdfc7eSAndroid Build Coastguard Worker * get space for file names
1256*49cdfc7eSAndroid Build Coastguard Worker */
1257*49cdfc7eSAndroid Build Coastguard Worker if ((filenames = malloc(num_files * PATH_MAX)) == NULL) {
1258*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %d %s/%d: malloc(%d) failed: %s\n",
1259*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
1260*49cdfc7eSAndroid Build Coastguard Worker num_files * PATH_MAX, strerror(errno));
1261*49cdfc7eSAndroid Build Coastguard Worker exit(1);
1262*49cdfc7eSAndroid Build Coastguard Worker }
1263*49cdfc7eSAndroid Build Coastguard Worker
1264*49cdfc7eSAndroid Build Coastguard Worker /*
1265*49cdfc7eSAndroid Build Coastguard Worker * fill in filename cmd files then auto files.
1266*49cdfc7eSAndroid Build Coastguard Worker */
1267*49cdfc7eSAndroid Build Coastguard Worker
1268*49cdfc7eSAndroid Build Coastguard Worker num = 0;
1269*49cdfc7eSAndroid Build Coastguard Worker if (first_file_ind) {
1270*49cdfc7eSAndroid Build Coastguard Worker for (ind = first_file_ind; ind < argc; ind++, num++) {
1271*49cdfc7eSAndroid Build Coastguard Worker strcpy((char *)filenames + (num * PATH_MAX), argv[ind]);
1272*49cdfc7eSAndroid Build Coastguard Worker }
1273*49cdfc7eSAndroid Build Coastguard Worker }
1274*49cdfc7eSAndroid Build Coastguard Worker
1275*49cdfc7eSAndroid Build Coastguard Worker /*
1276*49cdfc7eSAndroid Build Coastguard Worker * construct auto filename and insert them into filenames space
1277*49cdfc7eSAndroid Build Coastguard Worker */
1278*49cdfc7eSAndroid Build Coastguard Worker
1279*49cdfc7eSAndroid Build Coastguard Worker for (ind = 0; ind < num_auto_files; ind++, num++) {
1280*49cdfc7eSAndroid Build Coastguard Worker gettimeofday(&tv1, NULL);
1281*49cdfc7eSAndroid Build Coastguard Worker sprintf((char *)filenames + (num * PATH_MAX),
1282*49cdfc7eSAndroid Build Coastguard Worker "%s/%s%ld%ld%d.%d", auto_dir, auto_file,
1283*49cdfc7eSAndroid Build Coastguard Worker (long)tv1.tv_sec, (long)tv1.tv_usec, rand(), ind);
1284*49cdfc7eSAndroid Build Coastguard Worker }
1285*49cdfc7eSAndroid Build Coastguard Worker
1286*49cdfc7eSAndroid Build Coastguard Worker /*
1287*49cdfc7eSAndroid Build Coastguard Worker * construct auto seq filenames
1288*49cdfc7eSAndroid Build Coastguard Worker */
1289*49cdfc7eSAndroid Build Coastguard Worker for (ind = 1; ind <= seq_auto_files; ind++, num++) {
1290*49cdfc7eSAndroid Build Coastguard Worker sprintf((char *)filenames + (num * PATH_MAX), "%s/%s%d",
1291*49cdfc7eSAndroid Build Coastguard Worker auto_dir, auto_file, ind);
1292*49cdfc7eSAndroid Build Coastguard Worker }
1293*49cdfc7eSAndroid Build Coastguard Worker
1294*49cdfc7eSAndroid Build Coastguard Worker /**** end filename stuff ****/
1295*49cdfc7eSAndroid Build Coastguard Worker
1296*49cdfc7eSAndroid Build Coastguard Worker if (time_iterval > 0) {
1297*49cdfc7eSAndroid Build Coastguard Worker struct timeval ts;
1298*49cdfc7eSAndroid Build Coastguard Worker gettimeofday(&ts, NULL);
1299*49cdfc7eSAndroid Build Coastguard Worker start_time = ts.tv_sec;
1300*49cdfc7eSAndroid Build Coastguard Worker //start_time=time(0);
1301*49cdfc7eSAndroid Build Coastguard Worker }
1302*49cdfc7eSAndroid Build Coastguard Worker
1303*49cdfc7eSAndroid Build Coastguard Worker /*
1304*49cdfc7eSAndroid Build Coastguard Worker * get space for I/O buffer
1305*49cdfc7eSAndroid Build Coastguard Worker */
1306*49cdfc7eSAndroid Build Coastguard Worker if (grow_incr) {
1307*49cdfc7eSAndroid Build Coastguard Worker if ((Buffer = malloc(grow_incr + Alignment)) == NULL) {
1308*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
1309*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: malloc(%d) failed: %s\n",
1310*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
1311*49cdfc7eSAndroid Build Coastguard Worker grow_incr, strerror(errno));
1312*49cdfc7eSAndroid Build Coastguard Worker exit(1);
1313*49cdfc7eSAndroid Build Coastguard Worker }
1314*49cdfc7eSAndroid Build Coastguard Worker if (Alignment)
1315*49cdfc7eSAndroid Build Coastguard Worker Buffer = Buffer + Alignment;
1316*49cdfc7eSAndroid Build Coastguard Worker
1317*49cdfc7eSAndroid Build Coastguard Worker }
1318*49cdfc7eSAndroid Build Coastguard Worker
1319*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2) {
1320*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 num_files = %d\n",
1321*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, num_files);
1322*49cdfc7eSAndroid Build Coastguard Worker }
1323*49cdfc7eSAndroid Build Coastguard Worker #ifndef linux
1324*49cdfc7eSAndroid Build Coastguard Worker if (pre_alloc_space) {
1325*49cdfc7eSAndroid Build Coastguard Worker if (iterations == 0) {
1326*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
1327*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: can NOT pre-alloc and grow forever\n",
1328*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__);
1329*49cdfc7eSAndroid Build Coastguard Worker exit(1);
1330*49cdfc7eSAndroid Build Coastguard Worker }
1331*49cdfc7eSAndroid Build Coastguard Worker if (Mode & MODE_RAND_SIZE) {
1332*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
1333*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: can NOT pre-alloc and do random io size\n",
1334*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__);
1335*49cdfc7eSAndroid Build Coastguard Worker exit(1);
1336*49cdfc7eSAndroid Build Coastguard Worker }
1337*49cdfc7eSAndroid Build Coastguard Worker
1338*49cdfc7eSAndroid Build Coastguard Worker total_grow_value = grow_incr * iterations;
1339*49cdfc7eSAndroid Build Coastguard Worker
1340*49cdfc7eSAndroid Build Coastguard Worker /*
1341*49cdfc7eSAndroid Build Coastguard Worker * attempt to limit
1342*49cdfc7eSAndroid Build Coastguard Worker */
1343*49cdfc7eSAndroid Build Coastguard Worker if (bytes_to_consume && bytes_to_consume < total_grow_value) {
1344*49cdfc7eSAndroid Build Coastguard Worker total_grow_value = bytes_to_consume;
1345*49cdfc7eSAndroid Build Coastguard Worker }
1346*49cdfc7eSAndroid Build Coastguard Worker }
1347*49cdfc7eSAndroid Build Coastguard Worker #endif
1348*49cdfc7eSAndroid Build Coastguard Worker
1349*49cdfc7eSAndroid Build Coastguard Worker /*
1350*49cdfc7eSAndroid Build Coastguard Worker * If delaying between iterations, get amount time to
1351*49cdfc7eSAndroid Build Coastguard Worker * delaysecs in clocks or usecs.
1352*49cdfc7eSAndroid Build Coastguard Worker * If on the CRAY, delaytime is in clocks since
1353*49cdfc7eSAndroid Build Coastguard Worker * _rtc() will be used, which does not have the overhead
1354*49cdfc7eSAndroid Build Coastguard Worker * of gettimeofday(2).
1355*49cdfc7eSAndroid Build Coastguard Worker */
1356*49cdfc7eSAndroid Build Coastguard Worker if (delaysecs) {
1357*49cdfc7eSAndroid Build Coastguard Worker #if CRAY
1358*49cdfc7eSAndroid Build Coastguard Worker int hz;
1359*49cdfc7eSAndroid Build Coastguard Worker hz = sysconf(_SC_CLK_TCK);
1360*49cdfc7eSAndroid Build Coastguard Worker delaytime = (int)((float)hz * delaysecs);
1361*49cdfc7eSAndroid Build Coastguard Worker #else
1362*49cdfc7eSAndroid Build Coastguard Worker delaytime = (int)((float)USECS_PER_SEC * delaysecs);
1363*49cdfc7eSAndroid Build Coastguard Worker #endif
1364*49cdfc7eSAndroid Build Coastguard Worker }
1365*49cdfc7eSAndroid Build Coastguard Worker
1366*49cdfc7eSAndroid Build Coastguard Worker if (statfs(auto_dir, &fsbuf) == -1) {
1367*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: Unable to get the info of mounted "
1368*49cdfc7eSAndroid Build Coastguard Worker "filesystem that includes dir %s\n",
1369*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, auto_dir);
1370*49cdfc7eSAndroid Build Coastguard Worker exit(1);
1371*49cdfc7eSAndroid Build Coastguard Worker }
1372*49cdfc7eSAndroid Build Coastguard Worker
1373*49cdfc7eSAndroid Build Coastguard Worker /* Compare two values and use the smaller one as limit */
1374*49cdfc7eSAndroid Build Coastguard Worker fs_limit = MIN(fsbuf.f_bsize * fsbuf.f_bavail / num_files, fs_limit);
1375*49cdfc7eSAndroid Build Coastguard Worker
1376*49cdfc7eSAndroid Build Coastguard Worker /*
1377*49cdfc7eSAndroid Build Coastguard Worker * This is the main iteration loop.
1378*49cdfc7eSAndroid Build Coastguard Worker * Each iteration, all files can be opened, written to,
1379*49cdfc7eSAndroid Build Coastguard Worker * read to check the write, check the whole file,
1380*49cdfc7eSAndroid Build Coastguard Worker * truncated, and closed.
1381*49cdfc7eSAndroid Build Coastguard Worker */
1382*49cdfc7eSAndroid Build Coastguard Worker for (Iter_cnt = 1; !stop; Iter_cnt++) {
1383*49cdfc7eSAndroid Build Coastguard Worker struct timeval ts;
1384*49cdfc7eSAndroid Build Coastguard Worker if (iterations && (Iter_cnt >= iterations + 1)) {
1385*49cdfc7eSAndroid Build Coastguard Worker strcpy(reason, "Hit iteration value");
1386*49cdfc7eSAndroid Build Coastguard Worker stop = 1;
1387*49cdfc7eSAndroid Build Coastguard Worker continue;
1388*49cdfc7eSAndroid Build Coastguard Worker }
1389*49cdfc7eSAndroid Build Coastguard Worker gettimeofday(&ts, NULL);
1390*49cdfc7eSAndroid Build Coastguard Worker if ((time_iterval > 0)
1391*49cdfc7eSAndroid Build Coastguard Worker && (start_time + time_iterval < ts.tv_sec)) {
1392*49cdfc7eSAndroid Build Coastguard Worker
1393*49cdfc7eSAndroid Build Coastguard Worker sprintf(reason, "Hit time value of %d", time_iterval);
1394*49cdfc7eSAndroid Build Coastguard Worker stop = 1;
1395*49cdfc7eSAndroid Build Coastguard Worker continue;
1396*49cdfc7eSAndroid Build Coastguard Worker }
1397*49cdfc7eSAndroid Build Coastguard Worker
1398*49cdfc7eSAndroid Build Coastguard Worker if (bytes_to_consume && bytes_consumed >= bytes_to_consume) {
1399*49cdfc7eSAndroid Build Coastguard Worker sprintf(reason, "Hit bytes consumed value of %d",
1400*49cdfc7eSAndroid Build Coastguard Worker bytes_to_consume);
1401*49cdfc7eSAndroid Build Coastguard Worker stop = 1;
1402*49cdfc7eSAndroid Build Coastguard Worker continue;
1403*49cdfc7eSAndroid Build Coastguard Worker }
1404*49cdfc7eSAndroid Build Coastguard Worker
1405*49cdfc7eSAndroid Build Coastguard Worker /*
1406*49cdfc7eSAndroid Build Coastguard Worker * This loop will loop through all files.
1407*49cdfc7eSAndroid Build Coastguard Worker * Each iteration, a single file can be opened, written to,
1408*49cdfc7eSAndroid Build Coastguard Worker * read to check the write, check the whole file,
1409*49cdfc7eSAndroid Build Coastguard Worker * truncated, and closed.
1410*49cdfc7eSAndroid Build Coastguard Worker */
1411*49cdfc7eSAndroid Build Coastguard Worker for (ind = 0; ind < num_files; ind++) {
1412*49cdfc7eSAndroid Build Coastguard Worker
1413*49cdfc7eSAndroid Build Coastguard Worker fflush(stdout);
1414*49cdfc7eSAndroid Build Coastguard Worker fflush(stderr);
1415*49cdfc7eSAndroid Build Coastguard Worker
1416*49cdfc7eSAndroid Build Coastguard Worker filename = (char *)filenames + (ind * PATH_MAX);
1417*49cdfc7eSAndroid Build Coastguard Worker Fileinfo.filename =
1418*49cdfc7eSAndroid Build Coastguard Worker (char *)filenames + (ind * PATH_MAX);
1419*49cdfc7eSAndroid Build Coastguard Worker
1420*49cdfc7eSAndroid Build Coastguard Worker if (open_flags == RANDOM_OPEN) {
1421*49cdfc7eSAndroid Build Coastguard Worker ret =
1422*49cdfc7eSAndroid Build Coastguard Worker Open_flags[random_range
1423*49cdfc7eSAndroid Build Coastguard Worker (0,
1424*49cdfc7eSAndroid Build Coastguard Worker sizeof(Open_flags) /
1425*49cdfc7eSAndroid Build Coastguard Worker sizeof(int) - 1, 1, NULL)];
1426*49cdfc7eSAndroid Build Coastguard Worker }
1427*49cdfc7eSAndroid Build Coastguard Worker
1428*49cdfc7eSAndroid Build Coastguard Worker else
1429*49cdfc7eSAndroid Build Coastguard Worker ret = open_flags;
1430*49cdfc7eSAndroid Build Coastguard Worker
1431*49cdfc7eSAndroid Build Coastguard Worker Fileinfo.openflags = ret;
1432*49cdfc7eSAndroid Build Coastguard Worker
1433*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 3) {
1434*49cdfc7eSAndroid Build Coastguard Worker printf
1435*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %s/%d: %d Open filename = %s, open flags = %#o %s\n",
1436*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__,
1437*49cdfc7eSAndroid Build Coastguard Worker Iter_cnt, filename, ret,
1438*49cdfc7eSAndroid Build Coastguard Worker openflags2symbols(ret, ",", 0));
1439*49cdfc7eSAndroid Build Coastguard Worker } else if (Debug > 2) {
1440*49cdfc7eSAndroid Build Coastguard Worker printf
1441*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %s/%d: %d filename = %s, open flags = %#o\n",
1442*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__,
1443*49cdfc7eSAndroid Build Coastguard Worker Iter_cnt, filename, ret);
1444*49cdfc7eSAndroid Build Coastguard Worker }
1445*49cdfc7eSAndroid Build Coastguard Worker
1446*49cdfc7eSAndroid Build Coastguard Worker /*
1447*49cdfc7eSAndroid Build Coastguard Worker * open file with desired flags.
1448*49cdfc7eSAndroid Build Coastguard Worker */
1449*49cdfc7eSAndroid Build Coastguard Worker if ((fd = open(filename, ret, 0777)) == -1) {
1450*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
1451*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: open(%s, %#o, 0777) returned -1, errno:%d %s\n",
1452*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__,
1453*49cdfc7eSAndroid Build Coastguard Worker __LINE__, filename, ret, errno,
1454*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
1455*49cdfc7eSAndroid Build Coastguard Worker handle_error();
1456*49cdfc7eSAndroid Build Coastguard Worker continue;
1457*49cdfc7eSAndroid Build Coastguard Worker }
1458*49cdfc7eSAndroid Build Coastguard Worker
1459*49cdfc7eSAndroid Build Coastguard Worker Fileinfo.fd = fd;
1460*49cdfc7eSAndroid Build Coastguard Worker
1461*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_EX, LKLVL1); /* lock if lockfile is LKLVL1 */
1462*49cdfc7eSAndroid Build Coastguard Worker
1463*49cdfc7eSAndroid Build Coastguard Worker #ifndef linux
1464*49cdfc7eSAndroid Build Coastguard Worker /*
1465*49cdfc7eSAndroid Build Coastguard Worker * preallocation is only done once, if specified.
1466*49cdfc7eSAndroid Build Coastguard Worker */
1467*49cdfc7eSAndroid Build Coastguard Worker if (pre_alloc_space) {
1468*49cdfc7eSAndroid Build Coastguard Worker if (pre_alloc(fd, total_grow_value) != 0) {
1469*49cdfc7eSAndroid Build Coastguard Worker cleanup();
1470*49cdfc7eSAndroid Build Coastguard Worker exit(2);
1471*49cdfc7eSAndroid Build Coastguard Worker }
1472*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 1) {
1473*49cdfc7eSAndroid Build Coastguard Worker printf
1474*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG2 %s/%d: pre_allocated %ld for file %s\n",
1475*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__,
1476*49cdfc7eSAndroid Build Coastguard Worker total_grow_value, filename);
1477*49cdfc7eSAndroid Build Coastguard Worker }
1478*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL1); /* release lock */
1479*49cdfc7eSAndroid Build Coastguard Worker close(fd);
1480*49cdfc7eSAndroid Build Coastguard Worker Iter_cnt = 0; /* reset outside loop to restart from one */
1481*49cdfc7eSAndroid Build Coastguard Worker continue;
1482*49cdfc7eSAndroid Build Coastguard Worker }
1483*49cdfc7eSAndroid Build Coastguard Worker #endif
1484*49cdfc7eSAndroid Build Coastguard Worker
1485*49cdfc7eSAndroid Build Coastguard Worker /*
1486*49cdfc7eSAndroid Build Coastguard Worker * grow file by desired amount.
1487*49cdfc7eSAndroid Build Coastguard Worker * growfile() will set the Grow_incr variable and
1488*49cdfc7eSAndroid Build Coastguard Worker * possiblly update the Mode variable indicating
1489*49cdfc7eSAndroid Build Coastguard Worker * if we are dealing with a FIFO file.
1490*49cdfc7eSAndroid Build Coastguard Worker */
1491*49cdfc7eSAndroid Build Coastguard Worker
1492*49cdfc7eSAndroid Build Coastguard Worker /* BUG:14136 (don't go past filesystem size limit) */
1493*49cdfc7eSAndroid Build Coastguard Worker curr_size = file_size(fd);
1494*49cdfc7eSAndroid Build Coastguard Worker if (curr_size + grow_incr >= fs_limit) {
1495*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL1); /* release lock */
1496*49cdfc7eSAndroid Build Coastguard Worker close(fd);
1497*49cdfc7eSAndroid Build Coastguard Worker sprintf(reason,
1498*49cdfc7eSAndroid Build Coastguard Worker "Reached %ld filesize which is almost %ld limit.",
1499*49cdfc7eSAndroid Build Coastguard Worker curr_size, fs_limit);
1500*49cdfc7eSAndroid Build Coastguard Worker stop = 1;
1501*49cdfc7eSAndroid Build Coastguard Worker continue;
1502*49cdfc7eSAndroid Build Coastguard Worker }
1503*49cdfc7eSAndroid Build Coastguard Worker
1504*49cdfc7eSAndroid Build Coastguard Worker if (growfile(fd, filename, grow_incr, Buffer, &curr_size) != 0) { /* BUG:14136 */
1505*49cdfc7eSAndroid Build Coastguard Worker handle_error();
1506*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL1); /* release lock */
1507*49cdfc7eSAndroid Build Coastguard Worker close(fd);
1508*49cdfc7eSAndroid Build Coastguard Worker continue;
1509*49cdfc7eSAndroid Build Coastguard Worker }
1510*49cdfc7eSAndroid Build Coastguard Worker
1511*49cdfc7eSAndroid Build Coastguard Worker /*
1512*49cdfc7eSAndroid Build Coastguard Worker * check if last write is not corrupted
1513*49cdfc7eSAndroid Build Coastguard Worker */
1514*49cdfc7eSAndroid Build Coastguard Worker if (check_write(fd, write_check_inter, filename,
1515*49cdfc7eSAndroid Build Coastguard Worker Mode) != 0) {
1516*49cdfc7eSAndroid Build Coastguard Worker handle_error();
1517*49cdfc7eSAndroid Build Coastguard Worker }
1518*49cdfc7eSAndroid Build Coastguard Worker
1519*49cdfc7eSAndroid Build Coastguard Worker /*
1520*49cdfc7eSAndroid Build Coastguard Worker * Check that whole file is not corrupted.
1521*49cdfc7eSAndroid Build Coastguard Worker */
1522*49cdfc7eSAndroid Build Coastguard Worker if (check_file(fd, file_check_inter, filename,
1523*49cdfc7eSAndroid Build Coastguard Worker no_file_check) != 0) {
1524*49cdfc7eSAndroid Build Coastguard Worker handle_error();
1525*49cdfc7eSAndroid Build Coastguard Worker }
1526*49cdfc7eSAndroid Build Coastguard Worker
1527*49cdfc7eSAndroid Build Coastguard Worker /*
1528*49cdfc7eSAndroid Build Coastguard Worker * shrink file by desired amount if it is time
1529*49cdfc7eSAndroid Build Coastguard Worker */
1530*49cdfc7eSAndroid Build Coastguard Worker
1531*49cdfc7eSAndroid Build Coastguard Worker if (shrinkfile
1532*49cdfc7eSAndroid Build Coastguard Worker (fd, filename, trunc_incr, trunc_inter,
1533*49cdfc7eSAndroid Build Coastguard Worker Mode) != 0) {
1534*49cdfc7eSAndroid Build Coastguard Worker handle_error();
1535*49cdfc7eSAndroid Build Coastguard Worker }
1536*49cdfc7eSAndroid Build Coastguard Worker
1537*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL1); /* release lock */
1538*49cdfc7eSAndroid Build Coastguard Worker
1539*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 4)
1540*49cdfc7eSAndroid Build Coastguard Worker printf
1541*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG5 %s/%d: %d Closing file %s fd:%d \n",
1542*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__,
1543*49cdfc7eSAndroid Build Coastguard Worker Iter_cnt, filename, fd);
1544*49cdfc7eSAndroid Build Coastguard Worker close(fd);
1545*49cdfc7eSAndroid Build Coastguard Worker
1546*49cdfc7eSAndroid Build Coastguard Worker /*
1547*49cdfc7eSAndroid Build Coastguard Worker * Unlink the file if that is desired
1548*49cdfc7eSAndroid Build Coastguard Worker */
1549*49cdfc7eSAndroid Build Coastguard Worker if (unlink_inter && (Iter_cnt % unlink_inter == 0)) {
1550*49cdfc7eSAndroid Build Coastguard Worker
1551*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 4)
1552*49cdfc7eSAndroid Build Coastguard Worker printf
1553*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG5 %s/%d: %d Unlinking file %s\n",
1554*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__,
1555*49cdfc7eSAndroid Build Coastguard Worker Iter_cnt, filename);
1556*49cdfc7eSAndroid Build Coastguard Worker
1557*49cdfc7eSAndroid Build Coastguard Worker unlink(filename);
1558*49cdfc7eSAndroid Build Coastguard Worker }
1559*49cdfc7eSAndroid Build Coastguard Worker
1560*49cdfc7eSAndroid Build Coastguard Worker /*
1561*49cdfc7eSAndroid Build Coastguard Worker * delay while staying active for "delaysecs" seconds.
1562*49cdfc7eSAndroid Build Coastguard Worker */
1563*49cdfc7eSAndroid Build Coastguard Worker if (delaytime) {
1564*49cdfc7eSAndroid Build Coastguard Worker
1565*49cdfc7eSAndroid Build Coastguard Worker int ct, end;
1566*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
1567*49cdfc7eSAndroid Build Coastguard Worker ct = _rtc();
1568*49cdfc7eSAndroid Build Coastguard Worker end = ct + delaytime;
1569*49cdfc7eSAndroid Build Coastguard Worker while (ct < end) {
1570*49cdfc7eSAndroid Build Coastguard Worker ct = _rtc();
1571*49cdfc7eSAndroid Build Coastguard Worker }
1572*49cdfc7eSAndroid Build Coastguard Worker #else
1573*49cdfc7eSAndroid Build Coastguard Worker struct timeval curtime;
1574*49cdfc7eSAndroid Build Coastguard Worker gettimeofday(&curtime, NULL);
1575*49cdfc7eSAndroid Build Coastguard Worker ct = curtime.tv_sec * USECS_PER_SEC +
1576*49cdfc7eSAndroid Build Coastguard Worker curtime.tv_usec;
1577*49cdfc7eSAndroid Build Coastguard Worker end = ct + delaytime;
1578*49cdfc7eSAndroid Build Coastguard Worker while (ct < end) {
1579*49cdfc7eSAndroid Build Coastguard Worker
1580*49cdfc7eSAndroid Build Coastguard Worker gettimeofday(&curtime, NULL);
1581*49cdfc7eSAndroid Build Coastguard Worker ct = curtime.tv_sec * USECS_PER_SEC +
1582*49cdfc7eSAndroid Build Coastguard Worker curtime.tv_usec;
1583*49cdfc7eSAndroid Build Coastguard Worker }
1584*49cdfc7eSAndroid Build Coastguard Worker #endif
1585*49cdfc7eSAndroid Build Coastguard Worker }
1586*49cdfc7eSAndroid Build Coastguard Worker }
1587*49cdfc7eSAndroid Build Coastguard Worker #ifndef linux
1588*49cdfc7eSAndroid Build Coastguard Worker /*
1589*49cdfc7eSAndroid Build Coastguard Worker * if Iter_cnt == 0, then we pre allocated space to all files
1590*49cdfc7eSAndroid Build Coastguard Worker * and we are starting outside loop over. Set pre_alloc_space
1591*49cdfc7eSAndroid Build Coastguard Worker * to zero otherwise we get in infinite loop
1592*49cdfc7eSAndroid Build Coastguard Worker */
1593*49cdfc7eSAndroid Build Coastguard Worker if (Iter_cnt == 0) {
1594*49cdfc7eSAndroid Build Coastguard Worker pre_alloc_space = 0;
1595*49cdfc7eSAndroid Build Coastguard Worker }
1596*49cdfc7eSAndroid Build Coastguard Worker #endif
1597*49cdfc7eSAndroid Build Coastguard Worker
1598*49cdfc7eSAndroid Build Coastguard Worker } /* end iteration for loop */
1599*49cdfc7eSAndroid Build Coastguard Worker
1600*49cdfc7eSAndroid Build Coastguard Worker if (Debug) {
1601*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: %d %s/%d: DONE %d iterations to %d files. %s\n",
1602*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__, Iter_cnt,
1603*49cdfc7eSAndroid Build Coastguard Worker num_files, reason);
1604*49cdfc7eSAndroid Build Coastguard Worker }
1605*49cdfc7eSAndroid Build Coastguard Worker fflush(stdout);
1606*49cdfc7eSAndroid Build Coastguard Worker fflush(stderr);
1607*49cdfc7eSAndroid Build Coastguard Worker
1608*49cdfc7eSAndroid Build Coastguard Worker cleanup();
1609*49cdfc7eSAndroid Build Coastguard Worker
1610*49cdfc7eSAndroid Build Coastguard Worker if (Errors) {
1611*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2) {
1612*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: %d DEBUG3 %d error(s) encountered\n",
1613*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, Errors);
1614*49cdfc7eSAndroid Build Coastguard Worker printf
1615*49cdfc7eSAndroid Build Coastguard Worker ("%s%s: %d DEBUG3 %s/%d: exiting with value of 1\n",
1616*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__);
1617*49cdfc7eSAndroid Build Coastguard Worker }
1618*49cdfc7eSAndroid Build Coastguard Worker exit(1);
1619*49cdfc7eSAndroid Build Coastguard Worker }
1620*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2) {
1621*49cdfc7eSAndroid Build Coastguard Worker printf
1622*49cdfc7eSAndroid Build Coastguard Worker ("%s%s: %d DEBUG3 %s/%d: no errors, exiting with value of 0\n",
1623*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__);
1624*49cdfc7eSAndroid Build Coastguard Worker }
1625*49cdfc7eSAndroid Build Coastguard Worker
1626*49cdfc7eSAndroid Build Coastguard Worker exit(0);
1627*49cdfc7eSAndroid Build Coastguard Worker tst_exit(); /* to keep compiler happy */
1628*49cdfc7eSAndroid Build Coastguard Worker }
1629*49cdfc7eSAndroid Build Coastguard Worker
1630*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1631*49cdfc7eSAndroid Build Coastguard Worker *
1632*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
set_sig(void)1633*49cdfc7eSAndroid Build Coastguard Worker int set_sig(void)
1634*49cdfc7eSAndroid Build Coastguard Worker {
1635*49cdfc7eSAndroid Build Coastguard Worker int sig;
1636*49cdfc7eSAndroid Build Coastguard Worker
1637*49cdfc7eSAndroid Build Coastguard Worker /*
1638*49cdfc7eSAndroid Build Coastguard Worker * now loop through all signals and set the handlers
1639*49cdfc7eSAndroid Build Coastguard Worker */
1640*49cdfc7eSAndroid Build Coastguard Worker
1641*49cdfc7eSAndroid Build Coastguard Worker for (sig = 1; sig < NSIG; sig++) {
1642*49cdfc7eSAndroid Build Coastguard Worker switch (sig) {
1643*49cdfc7eSAndroid Build Coastguard Worker case SIGKILL:
1644*49cdfc7eSAndroid Build Coastguard Worker case SIGSTOP:
1645*49cdfc7eSAndroid Build Coastguard Worker case SIGCONT:
1646*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
1647*49cdfc7eSAndroid Build Coastguard Worker case SIGINFO:
1648*49cdfc7eSAndroid Build Coastguard Worker case SIGRECOVERY:
1649*49cdfc7eSAndroid Build Coastguard Worker #endif /* CRAY */
1650*49cdfc7eSAndroid Build Coastguard Worker #ifdef SIGCKPT
1651*49cdfc7eSAndroid Build Coastguard Worker case SIGCKPT:
1652*49cdfc7eSAndroid Build Coastguard Worker #endif /* SIGCKPT */
1653*49cdfc7eSAndroid Build Coastguard Worker #ifdef SIGRESTART
1654*49cdfc7eSAndroid Build Coastguard Worker case SIGRESTART:
1655*49cdfc7eSAndroid Build Coastguard Worker #endif /* SIGRESTART */
1656*49cdfc7eSAndroid Build Coastguard Worker case SIGCHLD:
1657*49cdfc7eSAndroid Build Coastguard Worker break;
1658*49cdfc7eSAndroid Build Coastguard Worker
1659*49cdfc7eSAndroid Build Coastguard Worker default:
1660*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
1661*49cdfc7eSAndroid Build Coastguard Worker sigset(sig, sig_handler);
1662*49cdfc7eSAndroid Build Coastguard Worker #else
1663*49cdfc7eSAndroid Build Coastguard Worker /* linux and cray */
1664*49cdfc7eSAndroid Build Coastguard Worker signal(sig, sig_handler);
1665*49cdfc7eSAndroid Build Coastguard Worker #endif
1666*49cdfc7eSAndroid Build Coastguard Worker break;
1667*49cdfc7eSAndroid Build Coastguard Worker }
1668*49cdfc7eSAndroid Build Coastguard Worker } /* endfor */
1669*49cdfc7eSAndroid Build Coastguard Worker
1670*49cdfc7eSAndroid Build Coastguard Worker return 0;
1671*49cdfc7eSAndroid Build Coastguard Worker }
1672*49cdfc7eSAndroid Build Coastguard Worker
1673*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1674*49cdfc7eSAndroid Build Coastguard Worker *
1675*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
sig_handler(int sig)1676*49cdfc7eSAndroid Build Coastguard Worker void sig_handler(int sig)
1677*49cdfc7eSAndroid Build Coastguard Worker {
1678*49cdfc7eSAndroid Build Coastguard Worker int exit_stat = 2;
1679*49cdfc7eSAndroid Build Coastguard Worker
1680*49cdfc7eSAndroid Build Coastguard Worker if (sig == SIGUSR2) {
1681*49cdfc7eSAndroid Build Coastguard Worker fprintf(stdout,
1682*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: received SIGUSR2 (%d) - stopping.\n",
1683*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__, sig);
1684*49cdfc7eSAndroid Build Coastguard Worker #ifndef sgi
1685*49cdfc7eSAndroid Build Coastguard Worker signal(sig, sig_handler); /* allow us to get this signal more than once */
1686*49cdfc7eSAndroid Build Coastguard Worker #endif
1687*49cdfc7eSAndroid Build Coastguard Worker
1688*49cdfc7eSAndroid Build Coastguard Worker } else if (sig == SIGINT) {
1689*49cdfc7eSAndroid Build Coastguard Worker /* The user has told us to cleanup, don't pretend it's an error. */
1690*49cdfc7eSAndroid Build Coastguard Worker exit_stat = 0;
1691*49cdfc7eSAndroid Build Coastguard Worker if (Debug != 0) {
1692*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
1693*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: received unexpected signal: %d\n",
1694*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
1695*49cdfc7eSAndroid Build Coastguard Worker sig);
1696*49cdfc7eSAndroid Build Coastguard Worker }
1697*49cdfc7eSAndroid Build Coastguard Worker } else {
1698*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
1699*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: received unexpected signal: %d\n",
1700*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__, sig);
1701*49cdfc7eSAndroid Build Coastguard Worker }
1702*49cdfc7eSAndroid Build Coastguard Worker
1703*49cdfc7eSAndroid Build Coastguard Worker notify_others();
1704*49cdfc7eSAndroid Build Coastguard Worker cleanup();
1705*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2) {
1706*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: %d DEBUG3 %s/%d: Exiting with a value of %d\n",
1707*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__, exit_stat);
1708*49cdfc7eSAndroid Build Coastguard Worker }
1709*49cdfc7eSAndroid Build Coastguard Worker exit(exit_stat);
1710*49cdfc7eSAndroid Build Coastguard Worker }
1711*49cdfc7eSAndroid Build Coastguard Worker
1712*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1713*49cdfc7eSAndroid Build Coastguard Worker * this function attempts to send SIGUSR2 to other growfiles processes
1714*49cdfc7eSAndroid Build Coastguard Worker * telling them to stop.
1715*49cdfc7eSAndroid Build Coastguard Worker *
1716*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
notify_others(void)1717*49cdfc7eSAndroid Build Coastguard Worker static void notify_others(void)
1718*49cdfc7eSAndroid Build Coastguard Worker {
1719*49cdfc7eSAndroid Build Coastguard Worker static int send_signals = 0;
1720*49cdfc7eSAndroid Build Coastguard Worker int ind;
1721*49cdfc7eSAndroid Build Coastguard Worker
1722*49cdfc7eSAndroid Build Coastguard Worker if (Sync_with_others && send_signals == 0) {
1723*49cdfc7eSAndroid Build Coastguard Worker
1724*49cdfc7eSAndroid Build Coastguard Worker #if CRAY
1725*49cdfc7eSAndroid Build Coastguard Worker send_signals = 1; /* only send signals once */
1726*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 1)
1727*49cdfc7eSAndroid Build Coastguard Worker printf
1728*49cdfc7eSAndroid Build Coastguard Worker ("%s%s: %d DEBUG2 %s/%d: Sending SIGUSR2 to pgrp\n",
1729*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__);
1730*49cdfc7eSAndroid Build Coastguard Worker killm(C_PGRP, getpgrp(), SIGUSR2);
1731*49cdfc7eSAndroid Build Coastguard Worker #else
1732*49cdfc7eSAndroid Build Coastguard Worker send_signals = 1; /* only send signals once */
1733*49cdfc7eSAndroid Build Coastguard Worker
1734*49cdfc7eSAndroid Build Coastguard Worker for (ind = 0; ind < Forker_npids; ind++) {
1735*49cdfc7eSAndroid Build Coastguard Worker if (Forker_pids[ind] != Pid)
1736*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 1)
1737*49cdfc7eSAndroid Build Coastguard Worker printf
1738*49cdfc7eSAndroid Build Coastguard Worker ("%s%s: %d DEBUG2 %s/%d: Sending SIGUSR2 to pid %d\n",
1739*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__,
1740*49cdfc7eSAndroid Build Coastguard Worker __LINE__, Forker_pids[ind]);
1741*49cdfc7eSAndroid Build Coastguard Worker kill(Forker_pids[ind], SIGUSR2);
1742*49cdfc7eSAndroid Build Coastguard Worker }
1743*49cdfc7eSAndroid Build Coastguard Worker #endif
1744*49cdfc7eSAndroid Build Coastguard Worker }
1745*49cdfc7eSAndroid Build Coastguard Worker
1746*49cdfc7eSAndroid Build Coastguard Worker }
1747*49cdfc7eSAndroid Build Coastguard Worker
1748*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1749*49cdfc7eSAndroid Build Coastguard Worker * this function will count the number of errors encountered.
1750*49cdfc7eSAndroid Build Coastguard Worker * This function will call upanic if wanted or cleanup and
1751*49cdfc7eSAndroid Build Coastguard Worker * and exit is Maxerrs were encountered.
1752*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
handle_error(void)1753*49cdfc7eSAndroid Build Coastguard Worker int handle_error(void)
1754*49cdfc7eSAndroid Build Coastguard Worker {
1755*49cdfc7eSAndroid Build Coastguard Worker Errors++;
1756*49cdfc7eSAndroid Build Coastguard Worker
1757*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
1758*49cdfc7eSAndroid Build Coastguard Worker if (Errors & Upanic_on_error) {
1759*49cdfc7eSAndroid Build Coastguard Worker upanic(PA_PANIC);
1760*49cdfc7eSAndroid Build Coastguard Worker }
1761*49cdfc7eSAndroid Build Coastguard Worker #endif
1762*49cdfc7eSAndroid Build Coastguard Worker
1763*49cdfc7eSAndroid Build Coastguard Worker if (Maxerrs && Errors >= Maxerrs) {
1764*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: %d %s/%d: %d Hit max errors value of %d\n",
1765*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__, Iter_cnt,
1766*49cdfc7eSAndroid Build Coastguard Worker Maxerrs);
1767*49cdfc7eSAndroid Build Coastguard Worker notify_others();
1768*49cdfc7eSAndroid Build Coastguard Worker cleanup();
1769*49cdfc7eSAndroid Build Coastguard Worker
1770*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2) {
1771*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: %d DEBUG3 %d error(s) encountered\n",
1772*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, Errors);
1773*49cdfc7eSAndroid Build Coastguard Worker printf
1774*49cdfc7eSAndroid Build Coastguard Worker ("%s%s: %d DEBUG3 %s/%d: exiting with value of 1\n",
1775*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__);
1776*49cdfc7eSAndroid Build Coastguard Worker }
1777*49cdfc7eSAndroid Build Coastguard Worker
1778*49cdfc7eSAndroid Build Coastguard Worker exit(1);
1779*49cdfc7eSAndroid Build Coastguard Worker }
1780*49cdfc7eSAndroid Build Coastguard Worker
1781*49cdfc7eSAndroid Build Coastguard Worker return 0;
1782*49cdfc7eSAndroid Build Coastguard Worker }
1783*49cdfc7eSAndroid Build Coastguard Worker
1784*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1785*49cdfc7eSAndroid Build Coastguard Worker *
1786*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
cleanup(void)1787*49cdfc7eSAndroid Build Coastguard Worker int cleanup(void)
1788*49cdfc7eSAndroid Build Coastguard Worker {
1789*49cdfc7eSAndroid Build Coastguard Worker int ind;
1790*49cdfc7eSAndroid Build Coastguard Worker
1791*49cdfc7eSAndroid Build Coastguard Worker if (remove_files) {
1792*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2)
1793*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 Removing all %d files\n",
1794*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, num_files);
1795*49cdfc7eSAndroid Build Coastguard Worker for (ind = 0; ind <= num_files; ind++) {
1796*49cdfc7eSAndroid Build Coastguard Worker unlink(filenames + (ind * PATH_MAX));
1797*49cdfc7eSAndroid Build Coastguard Worker }
1798*49cdfc7eSAndroid Build Coastguard Worker }
1799*49cdfc7eSAndroid Build Coastguard Worker if (using_random && Debug > 1)
1800*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: %d DEBUG2 Used random seed: %d\n",
1801*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, Seed);
1802*49cdfc7eSAndroid Build Coastguard Worker return 0;
1803*49cdfc7eSAndroid Build Coastguard Worker }
1804*49cdfc7eSAndroid Build Coastguard Worker
1805*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1806*49cdfc7eSAndroid Build Coastguard Worker *
1807*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
usage(void)1808*49cdfc7eSAndroid Build Coastguard Worker void usage(void)
1809*49cdfc7eSAndroid Build Coastguard Worker {
1810*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
1811*49cdfc7eSAndroid Build Coastguard Worker "Usage: %s%s [-bhEluy][[-g grow_incr][-i num][-t trunc_incr][-T trunc_inter]\n",
1812*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName);
1813*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
1814*49cdfc7eSAndroid Build Coastguard Worker "[-d auto_dir][-e maxerrs][-f auto_file][-N num_files][-w][-c chk_inter][-D debug]\n");
1815*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
1816*49cdfc7eSAndroid Build Coastguard Worker "[-s seed][-S seq_auto_files][-p][-P PANIC][-I io_type][-o open_flags][-B maxbytes]\n");
1817*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
1818*49cdfc7eSAndroid Build Coastguard Worker "[-r iosizes][-R lseeks][-U unlk_inter][-W tagname] [files]\n");
1819*49cdfc7eSAndroid Build Coastguard Worker
1820*49cdfc7eSAndroid Build Coastguard Worker return;
1821*49cdfc7eSAndroid Build Coastguard Worker
1822*49cdfc7eSAndroid Build Coastguard Worker } /* end of usage */
1823*49cdfc7eSAndroid Build Coastguard Worker
1824*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1825*49cdfc7eSAndroid Build Coastguard Worker *
1826*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
help(void)1827*49cdfc7eSAndroid Build Coastguard Worker void help(void)
1828*49cdfc7eSAndroid Build Coastguard Worker {
1829*49cdfc7eSAndroid Build Coastguard Worker usage();
1830*49cdfc7eSAndroid Build Coastguard Worker
1831*49cdfc7eSAndroid Build Coastguard Worker fprintf(stdout, "\
1832*49cdfc7eSAndroid Build Coastguard Worker -h Specfied to print this help and exit.\n\
1833*49cdfc7eSAndroid Build Coastguard Worker -b Specfied to execute in sync mode.(def async mode)\n\
1834*49cdfc7eSAndroid Build Coastguard Worker -B maxbytes Max bytes to consume by all files. growfiles exits when more\n\
1835*49cdfc7eSAndroid Build Coastguard Worker than maxbytes have been consumed. (def no chk) If maxbytes ends\n\
1836*49cdfc7eSAndroid Build Coastguard Worker with the letter 'b', maxbytes is multiplied by BSIZE\n\
1837*49cdfc7eSAndroid Build Coastguard Worker -C write_chk Specifies how often to check the last write (default 1)\n\
1838*49cdfc7eSAndroid Build Coastguard Worker -c file_chk Specifies how often to check whole file (default 0)\n\
1839*49cdfc7eSAndroid Build Coastguard Worker -d auto_dir Specifies the directory to auto created files. (default .)\n\
1840*49cdfc7eSAndroid Build Coastguard Worker -D debug_lvl Specifies the debug level (default 1)\n\
1841*49cdfc7eSAndroid Build Coastguard Worker -E Print examples and exit\n\
1842*49cdfc7eSAndroid Build Coastguard Worker -e errs The number errors that will terminate this program (def 100)\n\
1843*49cdfc7eSAndroid Build Coastguard Worker -f auto_file Specifies the base filename files created. (default \"gf\")\n\
1844*49cdfc7eSAndroid Build Coastguard Worker -g grow_incr Specfied to grow by incr for each num. (default 4096)\n\
1845*49cdfc7eSAndroid Build Coastguard Worker grow_incr may end in b for blocks\n\
1846*49cdfc7eSAndroid Build Coastguard Worker If -r option is used, this option is ignored and size is random\n\
1847*49cdfc7eSAndroid Build Coastguard Worker -H delay Amount of time to delay between each file (default 0.0)\n\
1848*49cdfc7eSAndroid Build Coastguard Worker -I io_type Specifies io type: s - sync, p - polled async, a - async (def s)\n\
1849*49cdfc7eSAndroid Build Coastguard Worker l - listio sync, L - listio async, r - random\n\
1850*49cdfc7eSAndroid Build Coastguard Worker -i iteration Specfied to grow each file num times. 0 means forever (default 1)\n\
1851*49cdfc7eSAndroid Build Coastguard Worker -l Specfied to do file locking around write/read/trunc\n\
1852*49cdfc7eSAndroid Build Coastguard Worker If specified twice, file locking after open to just before close\n\
1853*49cdfc7eSAndroid Build Coastguard Worker -L time Specfied to exit after time secs, must be used with -i.\n\
1854*49cdfc7eSAndroid Build Coastguard Worker -N num_files Specifies the number of files to be created.\n\
1855*49cdfc7eSAndroid Build Coastguard Worker The default is zero if cmd line files.\n\
1856*49cdfc7eSAndroid Build Coastguard Worker The default is one if no cmd line files.\n\
1857*49cdfc7eSAndroid Build Coastguard Worker -n num_procs Specifies the number of copies of this cmd.\n\
1858*49cdfc7eSAndroid Build Coastguard Worker -o op_type Specifies open flages: (def O_RDWR,O_CREAT) op_type can be 'random'\n\
1859*49cdfc7eSAndroid Build Coastguard Worker -O offset adjust i/o buffer alignment by offset bytes\n\
1860*49cdfc7eSAndroid Build Coastguard Worker -P PANIC Specifies to call upanic on error.\n\
1861*49cdfc7eSAndroid Build Coastguard Worker -p Specifies to pre-allocate space\n\
1862*49cdfc7eSAndroid Build Coastguard Worker -q pattern pattern can be a - ascii, p - pid with boff, o boff (def)\n\
1863*49cdfc7eSAndroid Build Coastguard Worker A - Alternating bits, r - random, O - all ones, z - all zeros,\n\
1864*49cdfc7eSAndroid Build Coastguard Worker c - checkboard, C - counting\n\
1865*49cdfc7eSAndroid Build Coastguard Worker -R [min-]max random lseek before write and trunc, max of -1 means filesz,\n\
1866*49cdfc7eSAndroid Build Coastguard Worker -2 means filesz+grow, -3 filesz-grow. (min def is 0)\n\
1867*49cdfc7eSAndroid Build Coastguard Worker -r [min-]max random io write size (min def is 1)\n\
1868*49cdfc7eSAndroid Build Coastguard Worker -S seq_auto_files Specifies the number of seqental auto files (default 0)\n\
1869*49cdfc7eSAndroid Build Coastguard Worker -s seed[,seed...] Specifies the random number seed (default time(0)+pid)\n\
1870*49cdfc7eSAndroid Build Coastguard Worker -t trunc_incr Specfied the amount to shrink file. (default 4096)\n\
1871*49cdfc7eSAndroid Build Coastguard Worker trunc_inter may end in b for blocks\n\
1872*49cdfc7eSAndroid Build Coastguard Worker If -R option is used, this option is ignored and trunc is random\n\
1873*49cdfc7eSAndroid Build Coastguard Worker -T trunc_inter Specfied the how many grows happen before shrink. (default 0)\n\
1874*49cdfc7eSAndroid Build Coastguard Worker -u unlink files before exit\n\
1875*49cdfc7eSAndroid Build Coastguard Worker -U ui[-ui2] Unlink files each ui iteration (def 0)\n\
1876*49cdfc7eSAndroid Build Coastguard Worker -w Specfied to grow via lseek instead of writes.\n\
1877*49cdfc7eSAndroid Build Coastguard Worker -W tag-name Who-am-i. My Monster tag name. (used by Monster).\n\
1878*49cdfc7eSAndroid Build Coastguard Worker -x Re-exec children before continuing - useful on MPP systems\n\
1879*49cdfc7eSAndroid Build Coastguard Worker -y Attempt to sync copies - if one fails it will send sigusr2 to others\n\
1880*49cdfc7eSAndroid Build Coastguard Worker Action to each file every iteration is open, write, write check\n\
1881*49cdfc7eSAndroid Build Coastguard Worker file check, trunc and closed.\n");
1882*49cdfc7eSAndroid Build Coastguard Worker
1883*49cdfc7eSAndroid Build Coastguard Worker return;
1884*49cdfc7eSAndroid Build Coastguard Worker }
1885*49cdfc7eSAndroid Build Coastguard Worker
1886*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1887*49cdfc7eSAndroid Build Coastguard Worker *
1888*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
prt_examples(FILE * stream)1889*49cdfc7eSAndroid Build Coastguard Worker void prt_examples(FILE * stream)
1890*49cdfc7eSAndroid Build Coastguard Worker {
1891*49cdfc7eSAndroid Build Coastguard Worker /* This example creates 200 files in directory dir1. It writes */
1892*49cdfc7eSAndroid Build Coastguard Worker /* 4090 bytes 100 times then truncates 408990 bytes off the file */
1893*49cdfc7eSAndroid Build Coastguard Worker /* The file contents are checked every 1000 grow. */
1894*49cdfc7eSAndroid Build Coastguard Worker fprintf(stream,
1895*49cdfc7eSAndroid Build Coastguard Worker "# run forever: writes of 4090 bytes then on every 100 iterval\n\
1896*49cdfc7eSAndroid Build Coastguard Worker # truncate file by 408990 bytes. Done to 200 files in dir1.\n\
1897*49cdfc7eSAndroid Build Coastguard Worker %s -i 0 -g 4090 -T 100 -t 408990 -l -C 10 -c 1000 -d dir1 -S 200\n\n",
1898*49cdfc7eSAndroid Build Coastguard Worker Progname);
1899*49cdfc7eSAndroid Build Coastguard Worker
1900*49cdfc7eSAndroid Build Coastguard Worker /* same as above with 5000 byte grow and a 499990 byte tuncate */
1901*49cdfc7eSAndroid Build Coastguard Worker fprintf(stream,
1902*49cdfc7eSAndroid Build Coastguard Worker "# same as above with writes of 5000 bytes and truncs of 499990\n\
1903*49cdfc7eSAndroid Build Coastguard Worker %s -i 0 -g 5000 -T 100 -t 499990 -l -C 10 -c 1000 -d dir2 -S 200\n\n",
1904*49cdfc7eSAndroid Build Coastguard Worker Progname);
1905*49cdfc7eSAndroid Build Coastguard Worker
1906*49cdfc7eSAndroid Build Coastguard Worker /* This example beats on opens and closes */
1907*49cdfc7eSAndroid Build Coastguard Worker fprintf(stream,
1908*49cdfc7eSAndroid Build Coastguard Worker "# runs forever: beats on opens and closes of file ocfile - no io\n\
1909*49cdfc7eSAndroid Build Coastguard Worker %s -i 0 -g 0 -c 0 -C 0 ocfile\n\n",
1910*49cdfc7eSAndroid Build Coastguard Worker Progname);
1911*49cdfc7eSAndroid Build Coastguard Worker
1912*49cdfc7eSAndroid Build Coastguard Worker fprintf(stream, "# writes 4096 to files until 50 blocks are written\n\
1913*49cdfc7eSAndroid Build Coastguard Worker %s -i 0 -g 4096 -B 50b file1 file2\n\n", Progname);
1914*49cdfc7eSAndroid Build Coastguard Worker
1915*49cdfc7eSAndroid Build Coastguard Worker fprintf(stream,
1916*49cdfc7eSAndroid Build Coastguard Worker "# write one byte to 750 files in gdir then unlinks them\n\
1917*49cdfc7eSAndroid Build Coastguard Worker %s -g 1 -C 0 -d gdir -u -S 750\n\n", Progname);
1918*49cdfc7eSAndroid Build Coastguard Worker
1919*49cdfc7eSAndroid Build Coastguard Worker fprintf(stream, "# run 30 secs: random iosize, random lseek up to eof\n\
1920*49cdfc7eSAndroid Build Coastguard Worker %s -r 1-5000 -R 0--1 -i 0 -L 30 -C 1 g_rand1 g_rand2\n\n", Progname);
1921*49cdfc7eSAndroid Build Coastguard Worker
1922*49cdfc7eSAndroid Build Coastguard Worker fprintf(stream,
1923*49cdfc7eSAndroid Build Coastguard Worker "# run 30 secs: grow by lseek then write single byte, trunc every 10 itervals\n\
1924*49cdfc7eSAndroid Build Coastguard Worker %s -g 5000 -wlu -i 0 -L 30 -C 1 -T 10 g_sleek1 g_lseek2\n\n",
1925*49cdfc7eSAndroid Build Coastguard Worker Progname);
1926*49cdfc7eSAndroid Build Coastguard Worker
1927*49cdfc7eSAndroid Build Coastguard Worker fprintf(stream,
1928*49cdfc7eSAndroid Build Coastguard Worker "# run forever: 5 copies of random iosize, random lseek to beyond eof,\n\
1929*49cdfc7eSAndroid Build Coastguard Worker # rand io types doing a trunc every 5 iterations, with unlinks.\n\
1930*49cdfc7eSAndroid Build Coastguard Worker %s -i0 -r 1-50000 -R 0--2 -I r -C1 -l -n5 -u -U 100-200 gf_rana gf_ranb\n\n",
1931*49cdfc7eSAndroid Build Coastguard Worker Progname);
1932*49cdfc7eSAndroid Build Coastguard Worker
1933*49cdfc7eSAndroid Build Coastguard Worker fprintf(stream,
1934*49cdfc7eSAndroid Build Coastguard Worker "# run forever: 5 copies of random iosize, random lseek to beyond eof,\n\
1935*49cdfc7eSAndroid Build Coastguard Worker # random open flags, rand io types doing a trunc every 10 iterations.\n\
1936*49cdfc7eSAndroid Build Coastguard Worker %s -i0 -r 1-50000 -R 0--2 -o random -I r -C0 -l -T 20 -uU100-200 -n 5 gf_rand1 gf_rand2\n",
1937*49cdfc7eSAndroid Build Coastguard Worker Progname);
1938*49cdfc7eSAndroid Build Coastguard Worker
1939*49cdfc7eSAndroid Build Coastguard Worker return;
1940*49cdfc7eSAndroid Build Coastguard Worker }
1941*49cdfc7eSAndroid Build Coastguard Worker
1942*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
1943*49cdfc7eSAndroid Build Coastguard Worker *
1944*49cdfc7eSAndroid Build Coastguard Worker * The file descriptor current offset is assumed to be the end of the
1945*49cdfc7eSAndroid Build Coastguard Worker * file.
1946*49cdfc7eSAndroid Build Coastguard Worker * Woffset will be set to the offset before the write.
1947*49cdfc7eSAndroid Build Coastguard Worker * Grow_incr will be set to the size of the write or lseek write.
1948*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
growfile(int fd,char * file,int grow_incr,char * buf,unsigned long * curr_size_ptr)1949*49cdfc7eSAndroid Build Coastguard Worker int /* BUG:14136 */ growfile(int fd, char *file, int grow_incr, char *buf,
1950*49cdfc7eSAndroid Build Coastguard Worker unsigned long *curr_size_ptr)
1951*49cdfc7eSAndroid Build Coastguard Worker {
1952*49cdfc7eSAndroid Build Coastguard Worker off_t noffset;
1953*49cdfc7eSAndroid Build Coastguard Worker int ret;
1954*49cdfc7eSAndroid Build Coastguard Worker int cur_offset;
1955*49cdfc7eSAndroid Build Coastguard Worker char *errmsg;
1956*49cdfc7eSAndroid Build Coastguard Worker off_t fsize; /* current size of file */
1957*49cdfc7eSAndroid Build Coastguard Worker int size_grew; /* size the file grew */
1958*49cdfc7eSAndroid Build Coastguard Worker struct stat stbuf;
1959*49cdfc7eSAndroid Build Coastguard Worker off_t off_tmp = 0;
1960*49cdfc7eSAndroid Build Coastguard Worker
1961*49cdfc7eSAndroid Build Coastguard Worker /*
1962*49cdfc7eSAndroid Build Coastguard Worker * Do a stat on the open file.
1963*49cdfc7eSAndroid Build Coastguard Worker * If the file is a fifo, set the bit in Mode variable.
1964*49cdfc7eSAndroid Build Coastguard Worker * This fifo check must be done prior to growfile() returning.
1965*49cdfc7eSAndroid Build Coastguard Worker * Also get the current size of the file.
1966*49cdfc7eSAndroid Build Coastguard Worker */
1967*49cdfc7eSAndroid Build Coastguard Worker if (fstat(fd, &stbuf) != -1) {
1968*49cdfc7eSAndroid Build Coastguard Worker if (S_ISFIFO(stbuf.st_mode)) {
1969*49cdfc7eSAndroid Build Coastguard Worker Fileinfo.mode |= MODE_FIFO;
1970*49cdfc7eSAndroid Build Coastguard Worker Mode |= MODE_FIFO;
1971*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 3)
1972*49cdfc7eSAndroid Build Coastguard Worker printf
1973*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG4 %s/%d: file is a fifo - no lseek or truncs,\n",
1974*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__);
1975*49cdfc7eSAndroid Build Coastguard Worker }
1976*49cdfc7eSAndroid Build Coastguard Worker fsize = stbuf.st_size;
1977*49cdfc7eSAndroid Build Coastguard Worker
1978*49cdfc7eSAndroid Build Coastguard Worker } else {
1979*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
1980*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: Unable to fstat(%d, &buf), errno:%d %s\n",
1981*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__, fd, errno,
1982*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
1983*49cdfc7eSAndroid Build Coastguard Worker
1984*49cdfc7eSAndroid Build Coastguard Worker return -1;
1985*49cdfc7eSAndroid Build Coastguard Worker }
1986*49cdfc7eSAndroid Build Coastguard Worker
1987*49cdfc7eSAndroid Build Coastguard Worker if (grow_incr <= 0) { /* don't attempt i/o if grow_incr <= 0 */
1988*49cdfc7eSAndroid Build Coastguard Worker
1989*49cdfc7eSAndroid Build Coastguard Worker Grow_incr = grow_incr;
1990*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2)
1991*49cdfc7eSAndroid Build Coastguard Worker printf
1992*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %s/%d: Not attempting to grow, growsize == %d\n",
1993*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, grow_incr);
1994*49cdfc7eSAndroid Build Coastguard Worker return grow_incr;
1995*49cdfc7eSAndroid Build Coastguard Worker }
1996*49cdfc7eSAndroid Build Coastguard Worker
1997*49cdfc7eSAndroid Build Coastguard Worker if (Mode & MODE_RAND_SIZE) {
1998*49cdfc7eSAndroid Build Coastguard Worker grow_incr =
1999*49cdfc7eSAndroid Build Coastguard Worker random_range(min_size, max_size, mult_size, &errmsg);
2000*49cdfc7eSAndroid Build Coastguard Worker if (errmsg != NULL) {
2001*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2002*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: random_range() failed - %s\n",
2003*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2004*49cdfc7eSAndroid Build Coastguard Worker errmsg);
2005*49cdfc7eSAndroid Build Coastguard Worker return -1;
2006*49cdfc7eSAndroid Build Coastguard Worker }
2007*49cdfc7eSAndroid Build Coastguard Worker Grow_incr = grow_incr;
2008*49cdfc7eSAndroid Build Coastguard Worker } else
2009*49cdfc7eSAndroid Build Coastguard Worker Grow_incr = grow_incr;
2010*49cdfc7eSAndroid Build Coastguard Worker
2011*49cdfc7eSAndroid Build Coastguard Worker if (!(Mode & MODE_FIFO)) {
2012*49cdfc7eSAndroid Build Coastguard Worker if ((cur_offset = lseek(fd, 0, SEEK_CUR)) == -1) {
2013*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %d %s/%d: tell failed: %s\n",
2014*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2015*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
2016*49cdfc7eSAndroid Build Coastguard Worker return -1;
2017*49cdfc7eSAndroid Build Coastguard Worker }
2018*49cdfc7eSAndroid Build Coastguard Worker }
2019*49cdfc7eSAndroid Build Coastguard Worker
2020*49cdfc7eSAndroid Build Coastguard Worker if (Mode & MODE_GROW_BY_LSEEK) {
2021*49cdfc7eSAndroid Build Coastguard Worker Woffset = fsize;
2022*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2) {
2023*49cdfc7eSAndroid Build Coastguard Worker printf
2024*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %s/%d: Current size of file is %ld\n",
2025*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, (long)Woffset);
2026*49cdfc7eSAndroid Build Coastguard Worker printf
2027*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %s/%d: lseeking to %d byte with SEEK_END\n",
2028*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, grow_incr - 1);
2029*49cdfc7eSAndroid Build Coastguard Worker }
2030*49cdfc7eSAndroid Build Coastguard Worker
2031*49cdfc7eSAndroid Build Coastguard Worker if ((noffset = lseek(fd, grow_incr - 1, SEEK_END)) == -1) {
2032*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2033*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %s/%d: lseek(fd, %d, SEEK_END) failed: %s\n",
2034*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, __FILE__, __LINE__,
2035*49cdfc7eSAndroid Build Coastguard Worker grow_incr - 1, strerror(errno));
2036*49cdfc7eSAndroid Build Coastguard Worker return -1;
2037*49cdfc7eSAndroid Build Coastguard Worker }
2038*49cdfc7eSAndroid Build Coastguard Worker
2039*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_EX, LKLVL0); /* get exclusive lock */
2040*49cdfc7eSAndroid Build Coastguard Worker
2041*49cdfc7eSAndroid Build Coastguard Worker #if NEWIO
2042*49cdfc7eSAndroid Build Coastguard Worker ret =
2043*49cdfc7eSAndroid Build Coastguard Worker lio_write_buffer(fd, io_type, "w", 1, SIGUSR1, &errmsg, 0);
2044*49cdfc7eSAndroid Build Coastguard Worker #else
2045*49cdfc7eSAndroid Build Coastguard Worker ret = write_buffer(fd, io_type, "w", 1, 0, &errmsg);
2046*49cdfc7eSAndroid Build Coastguard Worker #endif
2047*49cdfc7eSAndroid Build Coastguard Worker
2048*49cdfc7eSAndroid Build Coastguard Worker if (ret != 1) {
2049*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %d %s/%d: %d %s\n",
2050*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2051*49cdfc7eSAndroid Build Coastguard Worker Iter_cnt, errmsg);
2052*49cdfc7eSAndroid Build Coastguard Worker if (ret == -ENOSPC) {
2053*49cdfc7eSAndroid Build Coastguard Worker cleanup();
2054*49cdfc7eSAndroid Build Coastguard Worker exit(2);
2055*49cdfc7eSAndroid Build Coastguard Worker }
2056*49cdfc7eSAndroid Build Coastguard Worker }
2057*49cdfc7eSAndroid Build Coastguard Worker /***
2058*49cdfc7eSAndroid Build Coastguard Worker write(fd, "w", 1);
2059*49cdfc7eSAndroid Build Coastguard Worker ****/
2060*49cdfc7eSAndroid Build Coastguard Worker
2061*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2062*49cdfc7eSAndroid Build Coastguard Worker
2063*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2)
2064*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 %s/%d: %d wrote 1 byte to file\n",
2065*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, Iter_cnt);
2066*49cdfc7eSAndroid Build Coastguard Worker
2067*49cdfc7eSAndroid Build Coastguard Worker } else { /* end of grow by lseek */
2068*49cdfc7eSAndroid Build Coastguard Worker
2069*49cdfc7eSAndroid Build Coastguard Worker if (Fileinfo.openflags & O_APPEND) {
2070*49cdfc7eSAndroid Build Coastguard Worker /*
2071*49cdfc7eSAndroid Build Coastguard Worker * Deal with special case of the open flag containing O_APPEND.
2072*49cdfc7eSAndroid Build Coastguard Worker * If it does, the current offset does not matter since the write
2073*49cdfc7eSAndroid Build Coastguard Worker * will be done end of the file.
2074*49cdfc7eSAndroid Build Coastguard Worker */
2075*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 4)
2076*49cdfc7eSAndroid Build Coastguard Worker printf
2077*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG5 %s/%d: dealing with O_APPEND condition\n",
2078*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__);
2079*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_EX, LKLVL0); /* get exclusive lock */
2080*49cdfc7eSAndroid Build Coastguard Worker
2081*49cdfc7eSAndroid Build Coastguard Worker /*
2082*49cdfc7eSAndroid Build Coastguard Worker * do fstat again to get size of the file.
2083*49cdfc7eSAndroid Build Coastguard Worker * This is done inside a file lock (if locks are being used).
2084*49cdfc7eSAndroid Build Coastguard Worker */
2085*49cdfc7eSAndroid Build Coastguard Worker if (fstat(fd, &stbuf) != -1) {
2086*49cdfc7eSAndroid Build Coastguard Worker Woffset = stbuf.st_size;
2087*49cdfc7eSAndroid Build Coastguard Worker } else {
2088*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2089*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: Unable to fstat(%d, &buf), errno:%d %s\n",
2090*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__,
2091*49cdfc7eSAndroid Build Coastguard Worker __LINE__, fd, errno, strerror(errno));
2092*49cdfc7eSAndroid Build Coastguard Worker
2093*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0); /* release lock */
2094*49cdfc7eSAndroid Build Coastguard Worker return -1;
2095*49cdfc7eSAndroid Build Coastguard Worker }
2096*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2)
2097*49cdfc7eSAndroid Build Coastguard Worker printf
2098*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %s/%d: dealing with O_APPEND condition (offset:fsz:%d)\n",
2099*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__,
2100*49cdfc7eSAndroid Build Coastguard Worker (int)stbuf.st_size);
2101*49cdfc7eSAndroid Build Coastguard Worker
2102*49cdfc7eSAndroid Build Coastguard Worker } else if (Mode & MODE_RAND_LSEEK) {
2103*49cdfc7eSAndroid Build Coastguard Worker if (max_lseek == LSK_EOF) { /* within file size */
2104*49cdfc7eSAndroid Build Coastguard Worker noffset =
2105*49cdfc7eSAndroid Build Coastguard Worker random_range(min_lseek, fsize, 1, NULL);
2106*49cdfc7eSAndroid Build Coastguard Worker } else if (max_lseek == LSK_EOFPLUSGROW) {
2107*49cdfc7eSAndroid Build Coastguard Worker /* max to beyond file size */
2108*49cdfc7eSAndroid Build Coastguard Worker noffset =
2109*49cdfc7eSAndroid Build Coastguard Worker random_range(min_lseek, fsize + grow_incr,
2110*49cdfc7eSAndroid Build Coastguard Worker 1, NULL);
2111*49cdfc7eSAndroid Build Coastguard Worker } else if (max_lseek == LSK_EOFMINUSGROW) {
2112*49cdfc7eSAndroid Build Coastguard Worker /*
2113*49cdfc7eSAndroid Build Coastguard Worker * Attempt to not grow the file.
2114*49cdfc7eSAndroid Build Coastguard Worker * If the i/o will fit from min_lseek to EOF,
2115*49cdfc7eSAndroid Build Coastguard Worker * pick offset to allow it to fit.
2116*49cdfc7eSAndroid Build Coastguard Worker * Otherwise, pick the min_lseek offset and grow
2117*49cdfc7eSAndroid Build Coastguard Worker * file by smallest amount.
2118*49cdfc7eSAndroid Build Coastguard Worker * If min_lseek is != 0, there will be a problem
2119*49cdfc7eSAndroid Build Coastguard Worker * with whole file checking if file is ever smaller
2120*49cdfc7eSAndroid Build Coastguard Worker * than min_lseek.
2121*49cdfc7eSAndroid Build Coastguard Worker */
2122*49cdfc7eSAndroid Build Coastguard Worker if (fsize <= min_lseek + grow_incr)
2123*49cdfc7eSAndroid Build Coastguard Worker noffset = min_lseek; /* file will still grow */
2124*49cdfc7eSAndroid Build Coastguard Worker else
2125*49cdfc7eSAndroid Build Coastguard Worker noffset =
2126*49cdfc7eSAndroid Build Coastguard Worker random_range(min_lseek,
2127*49cdfc7eSAndroid Build Coastguard Worker fsize - grow_incr, 1,
2128*49cdfc7eSAndroid Build Coastguard Worker NULL);
2129*49cdfc7eSAndroid Build Coastguard Worker } else {
2130*49cdfc7eSAndroid Build Coastguard Worker noffset =
2131*49cdfc7eSAndroid Build Coastguard Worker random_range(min_lseek, max_lseek, 1, NULL);
2132*49cdfc7eSAndroid Build Coastguard Worker }
2133*49cdfc7eSAndroid Build Coastguard Worker
2134*49cdfc7eSAndroid Build Coastguard Worker if ((Woffset = lseek(fd, noffset, SEEK_SET)) == -1) {
2135*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2136*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: lseek(%d, %ld, "
2137*49cdfc7eSAndroid Build Coastguard Worker "SEEK_SET) l2 failed: %s\n", Progname,
2138*49cdfc7eSAndroid Build Coastguard Worker TagName, Pid, __FILE__, __LINE__, fd,
2139*49cdfc7eSAndroid Build Coastguard Worker (long)noffset, strerror(errno));
2140*49cdfc7eSAndroid Build Coastguard Worker return -1;
2141*49cdfc7eSAndroid Build Coastguard Worker } else if (Debug > 2)
2142*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 %s/%d: lseeked to "
2143*49cdfc7eSAndroid Build Coastguard Worker "random offset %ld (fsz:%d)\n",
2144*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__,
2145*49cdfc7eSAndroid Build Coastguard Worker (long)Woffset, (int)stbuf.st_size);
2146*49cdfc7eSAndroid Build Coastguard Worker
2147*49cdfc7eSAndroid Build Coastguard Worker }
2148*49cdfc7eSAndroid Build Coastguard Worker
2149*49cdfc7eSAndroid Build Coastguard Worker /*
2150*49cdfc7eSAndroid Build Coastguard Worker * lseek to end of file only if not fifo
2151*49cdfc7eSAndroid Build Coastguard Worker */
2152*49cdfc7eSAndroid Build Coastguard Worker else if (!(Mode & MODE_FIFO)) {
2153*49cdfc7eSAndroid Build Coastguard Worker if ((Woffset = lseek(fd, 0, SEEK_END)) == -1) {
2154*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2155*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: lseek(fd, 0, SEEK_END) failed: %s\n",
2156*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__,
2157*49cdfc7eSAndroid Build Coastguard Worker __LINE__, strerror(errno));
2158*49cdfc7eSAndroid Build Coastguard Worker return -1;
2159*49cdfc7eSAndroid Build Coastguard Worker } else if (Debug > 2)
2160*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 %s/%d: lseeked to "
2161*49cdfc7eSAndroid Build Coastguard Worker "end of file, offset %ld\n",
2162*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__,
2163*49cdfc7eSAndroid Build Coastguard Worker (long)Woffset);
2164*49cdfc7eSAndroid Build Coastguard Worker }
2165*49cdfc7eSAndroid Build Coastguard Worker
2166*49cdfc7eSAndroid Build Coastguard Worker if (Pattern == PATTERN_OFFSET)
2167*49cdfc7eSAndroid Build Coastguard Worker datapidgen(STATIC_NUM, buf, grow_incr, Woffset);
2168*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_PID)
2169*49cdfc7eSAndroid Build Coastguard Worker datapidgen(Pid, buf, grow_incr, Woffset);
2170*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ASCII)
2171*49cdfc7eSAndroid Build Coastguard Worker dataasciigen(NULL, buf, grow_incr, Woffset);
2172*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_RANDOM)
2173*49cdfc7eSAndroid Build Coastguard Worker databingen('r', buf, grow_incr, Woffset);
2174*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ALT)
2175*49cdfc7eSAndroid Build Coastguard Worker databingen('a', buf, grow_incr, Woffset);
2176*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_CHKER)
2177*49cdfc7eSAndroid Build Coastguard Worker databingen('c', buf, grow_incr, Woffset);
2178*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_CNTING)
2179*49cdfc7eSAndroid Build Coastguard Worker databingen('C', buf, grow_incr, Woffset);
2180*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ZEROS)
2181*49cdfc7eSAndroid Build Coastguard Worker databingen('z', buf, grow_incr, Woffset);
2182*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ONES)
2183*49cdfc7eSAndroid Build Coastguard Worker databingen('o', buf, grow_incr, Woffset);
2184*49cdfc7eSAndroid Build Coastguard Worker else
2185*49cdfc7eSAndroid Build Coastguard Worker dataasciigen(NULL, buf, grow_incr, Woffset);
2186*49cdfc7eSAndroid Build Coastguard Worker
2187*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2)
2188*49cdfc7eSAndroid Build Coastguard Worker printf
2189*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %s/%d: attempting to write %d bytes\n",
2190*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, grow_incr);
2191*49cdfc7eSAndroid Build Coastguard Worker
2192*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_EX, LKLVL0); /* get exclusive lock */
2193*49cdfc7eSAndroid Build Coastguard Worker
2194*49cdfc7eSAndroid Build Coastguard Worker /*****
2195*49cdfc7eSAndroid Build Coastguard Worker ret=write(fd, buf, grow_incr);
2196*49cdfc7eSAndroid Build Coastguard Worker
2197*49cdfc7eSAndroid Build Coastguard Worker off_tmp = tell(fd);
2198*49cdfc7eSAndroid Build Coastguard Worker
2199*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2200*49cdfc7eSAndroid Build Coastguard Worker
2201*49cdfc7eSAndroid Build Coastguard Worker if (ret != grow_incr) {
2202*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s: %s/%d: write failed: %s\n",
2203*49cdfc7eSAndroid Build Coastguard Worker Progname, __FILE__, __LINE__, strerror(errno));
2204*49cdfc7eSAndroid Build Coastguard Worker return -1;
2205*49cdfc7eSAndroid Build Coastguard Worker }
2206*49cdfc7eSAndroid Build Coastguard Worker *****/
2207*49cdfc7eSAndroid Build Coastguard Worker
2208*49cdfc7eSAndroid Build Coastguard Worker #if NEWIO
2209*49cdfc7eSAndroid Build Coastguard Worker ret = lio_write_buffer(fd, io_type, buf, grow_incr,
2210*49cdfc7eSAndroid Build Coastguard Worker SIGUSR1, &errmsg, 0);
2211*49cdfc7eSAndroid Build Coastguard Worker #else
2212*49cdfc7eSAndroid Build Coastguard Worker ret = write_buffer(fd, io_type, buf, grow_incr, 0, &errmsg);
2213*49cdfc7eSAndroid Build Coastguard Worker #endif
2214*49cdfc7eSAndroid Build Coastguard Worker
2215*49cdfc7eSAndroid Build Coastguard Worker if (Mode & MODE_FIFO) {
2216*49cdfc7eSAndroid Build Coastguard Worker /* If it is a fifo then just pretend the file
2217*49cdfc7eSAndroid Build Coastguard Worker * offset is where we think it should be.
2218*49cdfc7eSAndroid Build Coastguard Worker */
2219*49cdfc7eSAndroid Build Coastguard Worker off_tmp = Woffset + grow_incr;
2220*49cdfc7eSAndroid Build Coastguard Worker } else {
2221*49cdfc7eSAndroid Build Coastguard Worker if ((off_tmp = lseek(fd, 0, SEEK_CUR)) < 0) { /* get offset after the write */
2222*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2223*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %s/%d: tell(2) failed: %d %s\n",
2224*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, __FILE__, __LINE__,
2225*49cdfc7eSAndroid Build Coastguard Worker errno, strerror(errno));
2226*49cdfc7eSAndroid Build Coastguard Worker return -1;
2227*49cdfc7eSAndroid Build Coastguard Worker }
2228*49cdfc7eSAndroid Build Coastguard Worker #if NEWIO
2229*49cdfc7eSAndroid Build Coastguard Worker #if defined(sgi) || defined(__linux__)
2230*49cdfc7eSAndroid Build Coastguard Worker /* If this is POSIX I/O and it is via aio_{read,write}
2231*49cdfc7eSAndroid Build Coastguard Worker * or lio_listio then after completion of the I/O the
2232*49cdfc7eSAndroid Build Coastguard Worker * value of the file offset for the file is
2233*49cdfc7eSAndroid Build Coastguard Worker * unspecified--which means we cannot trust what
2234*49cdfc7eSAndroid Build Coastguard Worker * tell() told us. Fudge it here.
2235*49cdfc7eSAndroid Build Coastguard Worker */
2236*49cdfc7eSAndroid Build Coastguard Worker if ((io_type & LIO_IO_ASYNC_TYPES)
2237*49cdfc7eSAndroid Build Coastguard Worker || (io_type & LIO_RANDOM)) {
2238*49cdfc7eSAndroid Build Coastguard Worker if (off_tmp != Woffset + grow_incr) {
2239*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 5) {
2240*49cdfc7eSAndroid Build Coastguard Worker printf
2241*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG6 %s/%d: posix fudge, forcing tmp (%"
2242*49cdfc7eSAndroid Build Coastguard Worker PRId64
2243*49cdfc7eSAndroid Build Coastguard Worker ") to match Woffset+grow_incr (%"
2244*49cdfc7eSAndroid Build Coastguard Worker PRId64 ")\n", Progname,
2245*49cdfc7eSAndroid Build Coastguard Worker Pid, __FILE__, __LINE__,
2246*49cdfc7eSAndroid Build Coastguard Worker (int64_t) off_tmp,
2247*49cdfc7eSAndroid Build Coastguard Worker (int64_t) Woffset +
2248*49cdfc7eSAndroid Build Coastguard Worker grow_incr);
2249*49cdfc7eSAndroid Build Coastguard Worker }
2250*49cdfc7eSAndroid Build Coastguard Worker off_tmp = Woffset + grow_incr;
2251*49cdfc7eSAndroid Build Coastguard Worker }
2252*49cdfc7eSAndroid Build Coastguard Worker }
2253*49cdfc7eSAndroid Build Coastguard Worker #endif /* sgi __linux__ */
2254*49cdfc7eSAndroid Build Coastguard Worker #endif
2255*49cdfc7eSAndroid Build Coastguard Worker }
2256*49cdfc7eSAndroid Build Coastguard Worker *curr_size_ptr = off_tmp; /* BUG:14136 */
2257*49cdfc7eSAndroid Build Coastguard Worker
2258*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2259*49cdfc7eSAndroid Build Coastguard Worker
2260*49cdfc7eSAndroid Build Coastguard Worker if (ret != grow_incr) {
2261*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %d %s/%d: %d %s\n",
2262*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2263*49cdfc7eSAndroid Build Coastguard Worker Iter_cnt, errmsg);
2264*49cdfc7eSAndroid Build Coastguard Worker if (ret == -ENOSPC) {
2265*49cdfc7eSAndroid Build Coastguard Worker cleanup();
2266*49cdfc7eSAndroid Build Coastguard Worker exit(2);
2267*49cdfc7eSAndroid Build Coastguard Worker }
2268*49cdfc7eSAndroid Build Coastguard Worker return -1;
2269*49cdfc7eSAndroid Build Coastguard Worker }
2270*49cdfc7eSAndroid Build Coastguard Worker
2271*49cdfc7eSAndroid Build Coastguard Worker /*
2272*49cdfc7eSAndroid Build Coastguard Worker * Check for a condition where the file was truncated just before
2273*49cdfc7eSAndroid Build Coastguard Worker * the write.
2274*49cdfc7eSAndroid Build Coastguard Worker */
2275*49cdfc7eSAndroid Build Coastguard Worker if (off_tmp != Woffset + grow_incr) {
2276*49cdfc7eSAndroid Build Coastguard Worker /*
2277*49cdfc7eSAndroid Build Coastguard Worker * The offset after the write was not as expected.
2278*49cdfc7eSAndroid Build Coastguard Worker * This could be caused by the following:
2279*49cdfc7eSAndroid Build Coastguard Worker * - file truncated after the lseek and before the write.
2280*49cdfc7eSAndroid Build Coastguard Worker * - the file was written to after fstat and before the write
2281*49cdfc7eSAndroid Build Coastguard Worker * and the file was opened with O_APPEND.
2282*49cdfc7eSAndroid Build Coastguard Worker *
2283*49cdfc7eSAndroid Build Coastguard Worker * The pattern written to the file will be considered corrupted.
2284*49cdfc7eSAndroid Build Coastguard Worker */
2285*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 0 && lockfile) {
2286*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: %d DEBUG1 %s/%d: offset after "
2287*49cdfc7eSAndroid Build Coastguard Worker "write(%ld) not as exp(%ld+%d=%ld)\n",
2288*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__,
2289*49cdfc7eSAndroid Build Coastguard Worker __LINE__, (long)off_tmp, (long)Woffset,
2290*49cdfc7eSAndroid Build Coastguard Worker grow_incr, (long)(Woffset + grow_incr));
2291*49cdfc7eSAndroid Build Coastguard Worker printf
2292*49cdfc7eSAndroid Build Coastguard Worker ("%s%s: %d DEBUG1 %s/%d: %d Assuming file "
2293*49cdfc7eSAndroid Build Coastguard Worker "changed by another process, resetting "
2294*49cdfc7eSAndroid Build Coastguard Worker "offset:%ld (expect pattern mismatch)\n",
2295*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2296*49cdfc7eSAndroid Build Coastguard Worker Iter_cnt, (long)(off_tmp - grow_incr));
2297*49cdfc7eSAndroid Build Coastguard Worker }
2298*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 4) {
2299*49cdfc7eSAndroid Build Coastguard Worker printf
2300*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG5 %s/%d: about to chop Woffset. "
2301*49cdfc7eSAndroid Build Coastguard Worker "tmp=%ld, grow_incr=%d, Woffset was %ld\n",
2302*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__,
2303*49cdfc7eSAndroid Build Coastguard Worker (long)off_tmp, grow_incr, (long)Woffset);
2304*49cdfc7eSAndroid Build Coastguard Worker }
2305*49cdfc7eSAndroid Build Coastguard Worker Woffset = off_tmp - grow_incr;
2306*49cdfc7eSAndroid Build Coastguard Worker if (Woffset < 0)
2307*49cdfc7eSAndroid Build Coastguard Worker Woffset = 0;
2308*49cdfc7eSAndroid Build Coastguard Worker }
2309*49cdfc7eSAndroid Build Coastguard Worker
2310*49cdfc7eSAndroid Build Coastguard Worker } /* end of grow by write */
2311*49cdfc7eSAndroid Build Coastguard Worker
2312*49cdfc7eSAndroid Build Coastguard Worker /*
2313*49cdfc7eSAndroid Build Coastguard Worker * Woffset - holds start of grow (start of write expect in grow by lseek)
2314*49cdfc7eSAndroid Build Coastguard Worker * Grow_incr - holds size of grow (write).
2315*49cdfc7eSAndroid Build Coastguard Worker * fsize - holds size of file before write
2316*49cdfc7eSAndroid Build Coastguard Worker */
2317*49cdfc7eSAndroid Build Coastguard Worker size_grew = (Woffset + Grow_incr) - fsize;
2318*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 1) {
2319*49cdfc7eSAndroid Build Coastguard Worker if (Mode & MODE_FIFO) {
2320*49cdfc7eSAndroid Build Coastguard Worker printf
2321*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG2 %s/%d: file is fifo, %d wrote %d bytes\n",
2322*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, Grow_incr,
2323*49cdfc7eSAndroid Build Coastguard Worker Iter_cnt);
2324*49cdfc7eSAndroid Build Coastguard Worker }
2325*49cdfc7eSAndroid Build Coastguard Worker
2326*49cdfc7eSAndroid Build Coastguard Worker else if (size_grew > 0)
2327*49cdfc7eSAndroid Build Coastguard Worker printf
2328*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG2 %s/%d: %d wrote %d bytes(off:%ld), "
2329*49cdfc7eSAndroid Build Coastguard Worker "grew file by %d bytes\n", Progname, Pid, __FILE__,
2330*49cdfc7eSAndroid Build Coastguard Worker __LINE__, Iter_cnt, Grow_incr, (long)Woffset,
2331*49cdfc7eSAndroid Build Coastguard Worker size_grew);
2332*49cdfc7eSAndroid Build Coastguard Worker else
2333*49cdfc7eSAndroid Build Coastguard Worker printf
2334*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG2 %s/%d: %d wrote %d bytes(off:%ld), "
2335*49cdfc7eSAndroid Build Coastguard Worker "did not grow file\n", Progname, Pid, __FILE__,
2336*49cdfc7eSAndroid Build Coastguard Worker __LINE__, Iter_cnt, Grow_incr, (long)Woffset);
2337*49cdfc7eSAndroid Build Coastguard Worker }
2338*49cdfc7eSAndroid Build Coastguard Worker
2339*49cdfc7eSAndroid Build Coastguard Worker bytes_consumed += size_grew;
2340*49cdfc7eSAndroid Build Coastguard Worker return 0;
2341*49cdfc7eSAndroid Build Coastguard Worker
2342*49cdfc7eSAndroid Build Coastguard Worker } /* end of growfile */
2343*49cdfc7eSAndroid Build Coastguard Worker
2344*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
2345*49cdfc7eSAndroid Build Coastguard Worker * shrinkfile file by trunc_incr. file can not be made smaller than
2346*49cdfc7eSAndroid Build Coastguard Worker * size zero. Therefore, if trunc_incr is larger than file size,
2347*49cdfc7eSAndroid Build Coastguard Worker * file will be truncated to zero.
2348*49cdfc7eSAndroid Build Coastguard Worker * The file descriptor current offset is assumed to be the end of the
2349*49cdfc7eSAndroid Build Coastguard Worker * file.
2350*49cdfc7eSAndroid Build Coastguard Worker *
2351*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
2352*49cdfc7eSAndroid Build Coastguard Worker int
shrinkfile(int fd,char * filename,int trunc_incr,int trunc_inter,int just_trunc)2353*49cdfc7eSAndroid Build Coastguard Worker shrinkfile(int fd, char *filename, int trunc_incr, int trunc_inter,
2354*49cdfc7eSAndroid Build Coastguard Worker int just_trunc)
2355*49cdfc7eSAndroid Build Coastguard Worker {
2356*49cdfc7eSAndroid Build Coastguard Worker static int shrink_cnt = 0;
2357*49cdfc7eSAndroid Build Coastguard Worker int cur_offset;
2358*49cdfc7eSAndroid Build Coastguard Worker int new_offset;
2359*49cdfc7eSAndroid Build Coastguard Worker int ret;
2360*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
2361*49cdfc7eSAndroid Build Coastguard Worker int offset;
2362*49cdfc7eSAndroid Build Coastguard Worker #endif
2363*49cdfc7eSAndroid Build Coastguard Worker
2364*49cdfc7eSAndroid Build Coastguard Worker shrink_cnt++;
2365*49cdfc7eSAndroid Build Coastguard Worker
2366*49cdfc7eSAndroid Build Coastguard Worker if (trunc_inter == 0 || (shrink_cnt % trunc_inter != 0)) {
2367*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 3)
2368*49cdfc7eSAndroid Build Coastguard Worker printf
2369*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG4 %s/%d: Not shrinking file - not time, iter=%d, cnt=%d\n",
2370*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, trunc_inter,
2371*49cdfc7eSAndroid Build Coastguard Worker shrink_cnt);
2372*49cdfc7eSAndroid Build Coastguard Worker return 0; /* not this time */
2373*49cdfc7eSAndroid Build Coastguard Worker }
2374*49cdfc7eSAndroid Build Coastguard Worker
2375*49cdfc7eSAndroid Build Coastguard Worker if (Mode & MODE_FIFO) {
2376*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 5)
2377*49cdfc7eSAndroid Build Coastguard Worker printf
2378*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG5 %s/%d: Not attempting to shrink a FIFO\n",
2379*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__);
2380*49cdfc7eSAndroid Build Coastguard Worker return 0; /* can not truncate fifo */
2381*49cdfc7eSAndroid Build Coastguard Worker }
2382*49cdfc7eSAndroid Build Coastguard Worker
2383*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_EX, LKLVL0);
2384*49cdfc7eSAndroid Build Coastguard Worker
2385*49cdfc7eSAndroid Build Coastguard Worker if ((cur_offset = lseek(fd, 0, SEEK_CUR)) == -1) {
2386*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %d %s/%d: tell(%d) failed: %s\n",
2387*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__, fd,
2388*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
2389*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2390*49cdfc7eSAndroid Build Coastguard Worker return -1;
2391*49cdfc7eSAndroid Build Coastguard Worker }
2392*49cdfc7eSAndroid Build Coastguard Worker
2393*49cdfc7eSAndroid Build Coastguard Worker if (Mode & MODE_RAND_LSEEK) {
2394*49cdfc7eSAndroid Build Coastguard Worker if (max_lseek <= -1) {
2395*49cdfc7eSAndroid Build Coastguard Worker if ((new_offset = file_size(fd)) == -1) {
2396*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2397*49cdfc7eSAndroid Build Coastguard Worker return -1;
2398*49cdfc7eSAndroid Build Coastguard Worker }
2399*49cdfc7eSAndroid Build Coastguard Worker
2400*49cdfc7eSAndroid Build Coastguard Worker if (new_offset < min_lseek)
2401*49cdfc7eSAndroid Build Coastguard Worker new_offset = min_lseek;
2402*49cdfc7eSAndroid Build Coastguard Worker else
2403*49cdfc7eSAndroid Build Coastguard Worker new_offset =
2404*49cdfc7eSAndroid Build Coastguard Worker random_range(min_lseek, new_offset, 1,
2405*49cdfc7eSAndroid Build Coastguard Worker NULL);
2406*49cdfc7eSAndroid Build Coastguard Worker } else {
2407*49cdfc7eSAndroid Build Coastguard Worker new_offset =
2408*49cdfc7eSAndroid Build Coastguard Worker random_range(min_lseek, max_lseek, 1, NULL);
2409*49cdfc7eSAndroid Build Coastguard Worker }
2410*49cdfc7eSAndroid Build Coastguard Worker
2411*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
2412*49cdfc7eSAndroid Build Coastguard Worker if ((offset = lseek(fd, new_offset, SEEK_SET)) == -1) {
2413*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2414*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: lseek(%d, %d, SEEK_SET) l3 failed: %s\n",
2415*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__, fd,
2416*49cdfc7eSAndroid Build Coastguard Worker new_offset, strerror(errno));
2417*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2418*49cdfc7eSAndroid Build Coastguard Worker return -1;
2419*49cdfc7eSAndroid Build Coastguard Worker } else if (Debug > 3)
2420*49cdfc7eSAndroid Build Coastguard Worker printf
2421*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG4 %s/%d: lseeked to random offset %d\n",
2422*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, offset);
2423*49cdfc7eSAndroid Build Coastguard Worker
2424*49cdfc7eSAndroid Build Coastguard Worker #endif
2425*49cdfc7eSAndroid Build Coastguard Worker }
2426*49cdfc7eSAndroid Build Coastguard Worker
2427*49cdfc7eSAndroid Build Coastguard Worker else { /* remove trunc_incr from file */
2428*49cdfc7eSAndroid Build Coastguard Worker
2429*49cdfc7eSAndroid Build Coastguard Worker new_offset = cur_offset - trunc_incr;
2430*49cdfc7eSAndroid Build Coastguard Worker
2431*49cdfc7eSAndroid Build Coastguard Worker if (new_offset < 0)
2432*49cdfc7eSAndroid Build Coastguard Worker new_offset = 0;
2433*49cdfc7eSAndroid Build Coastguard Worker
2434*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
2435*49cdfc7eSAndroid Build Coastguard Worker if (lseek(fd, new_offset, SEEK_SET) == -1) {
2436*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2437*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: lseek(fd, %d, SEEK_SET) l4 failed: %s\n",
2438*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2439*49cdfc7eSAndroid Build Coastguard Worker new_offset, strerror(errno));
2440*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2441*49cdfc7eSAndroid Build Coastguard Worker return -1;
2442*49cdfc7eSAndroid Build Coastguard Worker } else if (Debug > 3)
2443*49cdfc7eSAndroid Build Coastguard Worker printf
2444*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG4 %s/%d: lseeked to offset %d, %d bytes from end\n",
2445*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, new_offset,
2446*49cdfc7eSAndroid Build Coastguard Worker trunc_incr);
2447*49cdfc7eSAndroid Build Coastguard Worker #endif
2448*49cdfc7eSAndroid Build Coastguard Worker }
2449*49cdfc7eSAndroid Build Coastguard Worker
2450*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
2451*49cdfc7eSAndroid Build Coastguard Worker ret = trunc(fd);
2452*49cdfc7eSAndroid Build Coastguard Worker #else
2453*49cdfc7eSAndroid Build Coastguard Worker ret = ftruncate(fd, new_offset);
2454*49cdfc7eSAndroid Build Coastguard Worker if (ret == 0 && Debug > 3) {
2455*49cdfc7eSAndroid Build Coastguard Worker printf
2456*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG4 %s/%d: ftruncated to offset %d, %d bytes from end\n",
2457*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, new_offset, trunc_incr);
2458*49cdfc7eSAndroid Build Coastguard Worker }
2459*49cdfc7eSAndroid Build Coastguard Worker #endif
2460*49cdfc7eSAndroid Build Coastguard Worker
2461*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2462*49cdfc7eSAndroid Build Coastguard Worker
2463*49cdfc7eSAndroid Build Coastguard Worker if (ret == -1) {
2464*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
2465*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %d %s/%d: trunc failed: %s\n",
2466*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2467*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
2468*49cdfc7eSAndroid Build Coastguard Worker #else
2469*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %d %s/%d: ftruncate failed: %s\n",
2470*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2471*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
2472*49cdfc7eSAndroid Build Coastguard Worker #endif
2473*49cdfc7eSAndroid Build Coastguard Worker return -1;
2474*49cdfc7eSAndroid Build Coastguard Worker }
2475*49cdfc7eSAndroid Build Coastguard Worker
2476*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2) {
2477*49cdfc7eSAndroid Build Coastguard Worker printf
2478*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG2 %s/%d: trunc file by %d bytes, to size of = %d bytes\n",
2479*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, cur_offset - new_offset,
2480*49cdfc7eSAndroid Build Coastguard Worker new_offset);
2481*49cdfc7eSAndroid Build Coastguard Worker }
2482*49cdfc7eSAndroid Build Coastguard Worker
2483*49cdfc7eSAndroid Build Coastguard Worker bytes_consumed -= (cur_offset - new_offset);
2484*49cdfc7eSAndroid Build Coastguard Worker return 0;
2485*49cdfc7eSAndroid Build Coastguard Worker
2486*49cdfc7eSAndroid Build Coastguard Worker } /* end of shrinkfile */
2487*49cdfc7eSAndroid Build Coastguard Worker
2488*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
2489*49cdfc7eSAndroid Build Coastguard Worker *
2490*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
check_write(int fd,int cf_inter,char * filename,int mode)2491*49cdfc7eSAndroid Build Coastguard Worker int check_write(int fd, int cf_inter, char *filename, int mode)
2492*49cdfc7eSAndroid Build Coastguard Worker {
2493*49cdfc7eSAndroid Build Coastguard Worker int fsize;
2494*49cdfc7eSAndroid Build Coastguard Worker static int cf_count = 0;
2495*49cdfc7eSAndroid Build Coastguard Worker int ret = 0;
2496*49cdfc7eSAndroid Build Coastguard Worker int tmp;
2497*49cdfc7eSAndroid Build Coastguard Worker char *errmsg;
2498*49cdfc7eSAndroid Build Coastguard Worker char *ptr;
2499*49cdfc7eSAndroid Build Coastguard Worker
2500*49cdfc7eSAndroid Build Coastguard Worker cf_count++;
2501*49cdfc7eSAndroid Build Coastguard Worker
2502*49cdfc7eSAndroid Build Coastguard Worker if (cf_inter == 0 || (cf_count % cf_inter != 0)) {
2503*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 4)
2504*49cdfc7eSAndroid Build Coastguard Worker printf
2505*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG5 %s/%d: no write check, not time iter=%d, cnt=%d\n",
2506*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, cf_inter,
2507*49cdfc7eSAndroid Build Coastguard Worker cf_count);
2508*49cdfc7eSAndroid Build Coastguard Worker return 0; /* no check done */
2509*49cdfc7eSAndroid Build Coastguard Worker }
2510*49cdfc7eSAndroid Build Coastguard Worker
2511*49cdfc7eSAndroid Build Coastguard Worker if (Grow_incr <= 0) {
2512*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 3)
2513*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG4 %s/%d: No write validation, "
2514*49cdfc7eSAndroid Build Coastguard Worker "Grow_incr = %d, offset = %ld\n",
2515*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, Grow_incr,
2516*49cdfc7eSAndroid Build Coastguard Worker (long)Woffset);
2517*49cdfc7eSAndroid Build Coastguard Worker return 0; /* no check */
2518*49cdfc7eSAndroid Build Coastguard Worker }
2519*49cdfc7eSAndroid Build Coastguard Worker
2520*49cdfc7eSAndroid Build Coastguard Worker /*
2521*49cdfc7eSAndroid Build Coastguard Worker * Get the shared file lock. We need to hold the lock from before
2522*49cdfc7eSAndroid Build Coastguard Worker * we do the stat until after the read.
2523*49cdfc7eSAndroid Build Coastguard Worker */
2524*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_SH, LKLVL0);
2525*49cdfc7eSAndroid Build Coastguard Worker
2526*49cdfc7eSAndroid Build Coastguard Worker if ((fsize = file_size(fd)) == -1) {
2527*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2528*49cdfc7eSAndroid Build Coastguard Worker return -1;
2529*49cdfc7eSAndroid Build Coastguard Worker
2530*49cdfc7eSAndroid Build Coastguard Worker } else if (fsize <= Woffset) {
2531*49cdfc7eSAndroid Build Coastguard Worker /*
2532*49cdfc7eSAndroid Build Coastguard Worker * The file was truncated between write and now.
2533*49cdfc7eSAndroid Build Coastguard Worker * The contents of our last write is totally gone, no check.
2534*49cdfc7eSAndroid Build Coastguard Worker */
2535*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 1)
2536*49cdfc7eSAndroid Build Coastguard Worker printf
2537*49cdfc7eSAndroid Build Coastguard Worker ("%s%s: %d DEBUG2 %s/%d: %d File size (%d) smaller than "
2538*49cdfc7eSAndroid Build Coastguard Worker "where last wrote (%ld)- no write validation\n",
2539*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2540*49cdfc7eSAndroid Build Coastguard Worker Iter_cnt, fsize, (long)Woffset);
2541*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2542*49cdfc7eSAndroid Build Coastguard Worker return 0; /* no validation, but not an error */
2543*49cdfc7eSAndroid Build Coastguard Worker
2544*49cdfc7eSAndroid Build Coastguard Worker } else if (fsize < (Woffset + Grow_incr)) {
2545*49cdfc7eSAndroid Build Coastguard Worker /*
2546*49cdfc7eSAndroid Build Coastguard Worker * The file was truncated between write and now.
2547*49cdfc7eSAndroid Build Coastguard Worker * Part of our last write has been truncated, adjust our Grow_incr
2548*49cdfc7eSAndroid Build Coastguard Worker * to reflect this.
2549*49cdfc7eSAndroid Build Coastguard Worker */
2550*49cdfc7eSAndroid Build Coastguard Worker
2551*49cdfc7eSAndroid Build Coastguard Worker tmp = Grow_incr;
2552*49cdfc7eSAndroid Build Coastguard Worker Grow_incr = fsize - Woffset;
2553*49cdfc7eSAndroid Build Coastguard Worker
2554*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 1) {
2555*49cdfc7eSAndroid Build Coastguard Worker
2556*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: %d DEBUG2 %s/%d: %d fsz:%d, lost(%d)of "
2557*49cdfc7eSAndroid Build Coastguard Worker "wrt(off:%ld, sz:%d), adj=%d\n", Progname,
2558*49cdfc7eSAndroid Build Coastguard Worker TagName, Pid, __FILE__, __LINE__, Iter_cnt,
2559*49cdfc7eSAndroid Build Coastguard Worker fsize, tmp - Grow_incr, (long)Woffset, tmp,
2560*49cdfc7eSAndroid Build Coastguard Worker Grow_incr);
2561*49cdfc7eSAndroid Build Coastguard Worker }
2562*49cdfc7eSAndroid Build Coastguard Worker
2563*49cdfc7eSAndroid Build Coastguard Worker }
2564*49cdfc7eSAndroid Build Coastguard Worker
2565*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2)
2566*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 %s/%d: about to do write validation, "
2567*49cdfc7eSAndroid Build Coastguard Worker "offset = %ld, size = %d\n",
2568*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, (long)Woffset,
2569*49cdfc7eSAndroid Build Coastguard Worker Grow_incr);
2570*49cdfc7eSAndroid Build Coastguard Worker
2571*49cdfc7eSAndroid Build Coastguard Worker if (!(mode & MODE_FIFO)) {
2572*49cdfc7eSAndroid Build Coastguard Worker
2573*49cdfc7eSAndroid Build Coastguard Worker if (lseek(fd, Woffset, 0) == -1) {
2574*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2575*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: lseek(fd, %ld, 0) failed: %s\n",
2576*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2577*49cdfc7eSAndroid Build Coastguard Worker (long)Woffset, strerror(errno));
2578*49cdfc7eSAndroid Build Coastguard Worker }
2579*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 3)
2580*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG4 %s/%d: lseeked to offset:%ld\n",
2581*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__,
2582*49cdfc7eSAndroid Build Coastguard Worker (long)Woffset);
2583*49cdfc7eSAndroid Build Coastguard Worker }
2584*49cdfc7eSAndroid Build Coastguard Worker
2585*49cdfc7eSAndroid Build Coastguard Worker /*
2586*49cdfc7eSAndroid Build Coastguard Worker * Read last writes data
2587*49cdfc7eSAndroid Build Coastguard Worker */
2588*49cdfc7eSAndroid Build Coastguard Worker #if NEWIO
2589*49cdfc7eSAndroid Build Coastguard Worker ret =
2590*49cdfc7eSAndroid Build Coastguard Worker lio_read_buffer(fd, io_type, Buffer, Grow_incr, SIGUSR1, &errmsg,
2591*49cdfc7eSAndroid Build Coastguard Worker 0);
2592*49cdfc7eSAndroid Build Coastguard Worker #else
2593*49cdfc7eSAndroid Build Coastguard Worker ret = read_buffer(fd, io_type, Buffer, Grow_incr, 0, &errmsg);
2594*49cdfc7eSAndroid Build Coastguard Worker #endif
2595*49cdfc7eSAndroid Build Coastguard Worker
2596*49cdfc7eSAndroid Build Coastguard Worker /*
2597*49cdfc7eSAndroid Build Coastguard Worker * report the error and debug information before releasing
2598*49cdfc7eSAndroid Build Coastguard Worker * the file lock
2599*49cdfc7eSAndroid Build Coastguard Worker */
2600*49cdfc7eSAndroid Build Coastguard Worker if (ret != Grow_incr) {
2601*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %d %s/%d: %d CW %s\n", Progname, TagName,
2602*49cdfc7eSAndroid Build Coastguard Worker Pid, __FILE__, __LINE__, Iter_cnt, errmsg);
2603*49cdfc7eSAndroid Build Coastguard Worker {
2604*49cdfc7eSAndroid Build Coastguard Worker struct stat stbuf;
2605*49cdfc7eSAndroid Build Coastguard Worker fstat(fd, &stbuf);
2606*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2)
2607*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: %d DEBUG3 %s/%d: fd:%d, offset:%d, fsize:%d, openflags:%#o\n", Progname, TagName, Pid, __FILE__, __LINE__, fd, (int)lseek(fd, SEEK_CUR, 0), /* FIXME: 64bit/LFS ? */
2608*49cdfc7eSAndroid Build Coastguard Worker (int)stbuf.st_size, Fileinfo.openflags);
2609*49cdfc7eSAndroid Build Coastguard Worker }
2610*49cdfc7eSAndroid Build Coastguard Worker
2611*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2612*49cdfc7eSAndroid Build Coastguard Worker return 1;
2613*49cdfc7eSAndroid Build Coastguard Worker }
2614*49cdfc7eSAndroid Build Coastguard Worker
2615*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2616*49cdfc7eSAndroid Build Coastguard Worker
2617*49cdfc7eSAndroid Build Coastguard Worker if (Mode & MODE_GROW_BY_LSEEK) {
2618*49cdfc7eSAndroid Build Coastguard Worker /* check that all zeros upto last character */
2619*49cdfc7eSAndroid Build Coastguard Worker for (ptr = Buffer; ptr < (Buffer + Grow_incr - 1); ptr++) {
2620*49cdfc7eSAndroid Build Coastguard Worker if (*ptr != '\0') {
2621*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2622*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: data mismatch at offset %d, exp:%#o(zerofilled), act:%#o in file %s\n",
2623*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__,
2624*49cdfc7eSAndroid Build Coastguard Worker __LINE__,
2625*49cdfc7eSAndroid Build Coastguard Worker (int)(Woffset +
2626*49cdfc7eSAndroid Build Coastguard Worker (Grow_incr - (Buffer - ptr))), 0,
2627*49cdfc7eSAndroid Build Coastguard Worker *ptr, filename);
2628*49cdfc7eSAndroid Build Coastguard Worker fflush(stderr);
2629*49cdfc7eSAndroid Build Coastguard Worker return 1;
2630*49cdfc7eSAndroid Build Coastguard Worker }
2631*49cdfc7eSAndroid Build Coastguard Worker }
2632*49cdfc7eSAndroid Build Coastguard Worker /* check that the last char is a 'w' */
2633*49cdfc7eSAndroid Build Coastguard Worker if (*ptr != 'w') {
2634*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2635*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: data mismatch at offset %d, exp:%#o(zerofilled), act:%#o in file %s\n",
2636*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2637*49cdfc7eSAndroid Build Coastguard Worker (int)(Woffset + (Grow_incr - (Buffer - ptr))),
2638*49cdfc7eSAndroid Build Coastguard Worker 'w', *ptr, filename);
2639*49cdfc7eSAndroid Build Coastguard Worker fflush(stderr);
2640*49cdfc7eSAndroid Build Coastguard Worker return 1;
2641*49cdfc7eSAndroid Build Coastguard Worker }
2642*49cdfc7eSAndroid Build Coastguard Worker return 0; /* all is well */
2643*49cdfc7eSAndroid Build Coastguard Worker
2644*49cdfc7eSAndroid Build Coastguard Worker } else if (Pattern == PATTERN_OFFSET)
2645*49cdfc7eSAndroid Build Coastguard Worker ret =
2646*49cdfc7eSAndroid Build Coastguard Worker datapidchk(STATIC_NUM, Buffer, Grow_incr, Woffset, &errmsg);
2647*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_PID)
2648*49cdfc7eSAndroid Build Coastguard Worker ret = datapidchk(Pid, Buffer, Grow_incr, Woffset, &errmsg);
2649*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ASCII)
2650*49cdfc7eSAndroid Build Coastguard Worker ret = dataasciichk(NULL, Buffer, Grow_incr, Woffset, &errmsg);
2651*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_RANDOM) ; /* no check for random */
2652*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ALT)
2653*49cdfc7eSAndroid Build Coastguard Worker ret = databinchk('a', Buffer, Grow_incr, Woffset, &errmsg);
2654*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_CHKER)
2655*49cdfc7eSAndroid Build Coastguard Worker ret = databinchk('c', Buffer, Grow_incr, Woffset, &errmsg);
2656*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_CNTING)
2657*49cdfc7eSAndroid Build Coastguard Worker ret = databinchk('C', Buffer, Grow_incr, Woffset, &errmsg);
2658*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ZEROS)
2659*49cdfc7eSAndroid Build Coastguard Worker ret = databinchk('z', Buffer, Grow_incr, Woffset, &errmsg);
2660*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ONES)
2661*49cdfc7eSAndroid Build Coastguard Worker ret = databinchk('o', Buffer, Grow_incr, Woffset, &errmsg);
2662*49cdfc7eSAndroid Build Coastguard Worker else
2663*49cdfc7eSAndroid Build Coastguard Worker ret = dataasciichk(NULL, Buffer, Grow_incr, Woffset, &errmsg);
2664*49cdfc7eSAndroid Build Coastguard Worker
2665*49cdfc7eSAndroid Build Coastguard Worker if (ret >= 0) {
2666*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %d %s/%d: %d CW %s in file %s\n",
2667*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__, Iter_cnt,
2668*49cdfc7eSAndroid Build Coastguard Worker errmsg, filename);
2669*49cdfc7eSAndroid Build Coastguard Worker
2670*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 0)
2671*49cdfc7eSAndroid Build Coastguard Worker printf("%s%s: %d DEBUG1 %s/%d: **fd:%d, lk:%d, "
2672*49cdfc7eSAndroid Build Coastguard Worker "offset:%ld, sz:%d open flags:%#o %s\n",
2673*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__, fd,
2674*49cdfc7eSAndroid Build Coastguard Worker lockfile, (long)Woffset, Grow_incr,
2675*49cdfc7eSAndroid Build Coastguard Worker Fileinfo.openflags,
2676*49cdfc7eSAndroid Build Coastguard Worker openflags2symbols(Fileinfo.openflags, ",", 0));
2677*49cdfc7eSAndroid Build Coastguard Worker
2678*49cdfc7eSAndroid Build Coastguard Worker fflush(stderr);
2679*49cdfc7eSAndroid Build Coastguard Worker return 1;
2680*49cdfc7eSAndroid Build Coastguard Worker }
2681*49cdfc7eSAndroid Build Coastguard Worker
2682*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 6)
2683*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG7 %s/%d: No corruption detected on "
2684*49cdfc7eSAndroid Build Coastguard Worker "write validation , offset = %ld, size = %d\n",
2685*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, (long)Woffset,
2686*49cdfc7eSAndroid Build Coastguard Worker Grow_incr);
2687*49cdfc7eSAndroid Build Coastguard Worker
2688*49cdfc7eSAndroid Build Coastguard Worker return 0; /* all is well */
2689*49cdfc7eSAndroid Build Coastguard Worker }
2690*49cdfc7eSAndroid Build Coastguard Worker
2691*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
2692*49cdfc7eSAndroid Build Coastguard Worker *
2693*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
check_file(int fd,int cf_inter,char * filename,int no_file_check)2694*49cdfc7eSAndroid Build Coastguard Worker int check_file(int fd, int cf_inter, char *filename, int no_file_check)
2695*49cdfc7eSAndroid Build Coastguard Worker {
2696*49cdfc7eSAndroid Build Coastguard Worker int fsize;
2697*49cdfc7eSAndroid Build Coastguard Worker static int cf_count = 0;
2698*49cdfc7eSAndroid Build Coastguard Worker char *buf;
2699*49cdfc7eSAndroid Build Coastguard Worker int ret;
2700*49cdfc7eSAndroid Build Coastguard Worker int ret_val = 0;
2701*49cdfc7eSAndroid Build Coastguard Worker int rd_cnt;
2702*49cdfc7eSAndroid Build Coastguard Worker int rd_size;
2703*49cdfc7eSAndroid Build Coastguard Worker char *errmsg;
2704*49cdfc7eSAndroid Build Coastguard Worker
2705*49cdfc7eSAndroid Build Coastguard Worker cf_count++;
2706*49cdfc7eSAndroid Build Coastguard Worker
2707*49cdfc7eSAndroid Build Coastguard Worker if (cf_inter == 0 || (cf_count % cf_inter != 0)) {
2708*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 4)
2709*49cdfc7eSAndroid Build Coastguard Worker printf
2710*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG5 %s/%d: No file check - not time, iter=%d, cnt=%d\n",
2711*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, cf_inter,
2712*49cdfc7eSAndroid Build Coastguard Worker cf_count);
2713*49cdfc7eSAndroid Build Coastguard Worker return 0; /* no check done */
2714*49cdfc7eSAndroid Build Coastguard Worker }
2715*49cdfc7eSAndroid Build Coastguard Worker
2716*49cdfc7eSAndroid Build Coastguard Worker /*
2717*49cdfc7eSAndroid Build Coastguard Worker * if we can't determine file content, don't bother checking
2718*49cdfc7eSAndroid Build Coastguard Worker */
2719*49cdfc7eSAndroid Build Coastguard Worker if (no_file_check) {
2720*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 4)
2721*49cdfc7eSAndroid Build Coastguard Worker printf
2722*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG5 %s/%d: No file check, lseek grow or random lseeks\n",
2723*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__);
2724*49cdfc7eSAndroid Build Coastguard Worker return 0;
2725*49cdfc7eSAndroid Build Coastguard Worker }
2726*49cdfc7eSAndroid Build Coastguard Worker
2727*49cdfc7eSAndroid Build Coastguard Worker /*
2728*49cdfc7eSAndroid Build Coastguard Worker * Lock the file. We need to have the file lock before
2729*49cdfc7eSAndroid Build Coastguard Worker * the stat and until after the last read to prevent
2730*49cdfc7eSAndroid Build Coastguard Worker * a trunc/truncate from "corrupting" our data.
2731*49cdfc7eSAndroid Build Coastguard Worker */
2732*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_SH, LKLVL0);
2733*49cdfc7eSAndroid Build Coastguard Worker
2734*49cdfc7eSAndroid Build Coastguard Worker if ((fsize = file_size(fd)) == -1) {
2735*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2736*49cdfc7eSAndroid Build Coastguard Worker return -1;
2737*49cdfc7eSAndroid Build Coastguard Worker }
2738*49cdfc7eSAndroid Build Coastguard Worker
2739*49cdfc7eSAndroid Build Coastguard Worker if (fsize == 0) {
2740*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2)
2741*49cdfc7eSAndroid Build Coastguard Worker printf
2742*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %s/%d: No file validation, file size == 0\n",
2743*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__);
2744*49cdfc7eSAndroid Build Coastguard Worker
2745*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2746*49cdfc7eSAndroid Build Coastguard Worker return 0;
2747*49cdfc7eSAndroid Build Coastguard Worker }
2748*49cdfc7eSAndroid Build Coastguard Worker
2749*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2)
2750*49cdfc7eSAndroid Build Coastguard Worker printf("%s: %d DEBUG3 %s/%d: about to do file validation\n",
2751*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__);
2752*49cdfc7eSAndroid Build Coastguard Worker
2753*49cdfc7eSAndroid Build Coastguard Worker if (fsize > MAX_FC_READ) {
2754*49cdfc7eSAndroid Build Coastguard Worker /*
2755*49cdfc7eSAndroid Build Coastguard Worker * read the file in MAX_FC_READ chuncks.
2756*49cdfc7eSAndroid Build Coastguard Worker */
2757*49cdfc7eSAndroid Build Coastguard Worker
2758*49cdfc7eSAndroid Build Coastguard Worker if ((buf = malloc(MAX_FC_READ)) == NULL) {
2759*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %s/%d: malloc(%d) failed: %s\n",
2760*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, __FILE__, __LINE__,
2761*49cdfc7eSAndroid Build Coastguard Worker MAX_FC_READ, strerror(errno));
2762*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2763*49cdfc7eSAndroid Build Coastguard Worker return -1;
2764*49cdfc7eSAndroid Build Coastguard Worker }
2765*49cdfc7eSAndroid Build Coastguard Worker
2766*49cdfc7eSAndroid Build Coastguard Worker lseek(fd, 0, SEEK_SET);
2767*49cdfc7eSAndroid Build Coastguard Worker
2768*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_SH, LKLVL0); /* get lock on file before getting file size */
2769*49cdfc7eSAndroid Build Coastguard Worker
2770*49cdfc7eSAndroid Build Coastguard Worker rd_cnt = 0;
2771*49cdfc7eSAndroid Build Coastguard Worker while (rd_cnt < fsize) {
2772*49cdfc7eSAndroid Build Coastguard Worker rd_size = MIN(MAX_FC_READ, fsize - rd_cnt);
2773*49cdfc7eSAndroid Build Coastguard Worker
2774*49cdfc7eSAndroid Build Coastguard Worker #if NEWIO
2775*49cdfc7eSAndroid Build Coastguard Worker ret = lio_read_buffer(fd, io_type, buf, rd_size,
2776*49cdfc7eSAndroid Build Coastguard Worker SIGUSR1, &errmsg, 0);
2777*49cdfc7eSAndroid Build Coastguard Worker #else
2778*49cdfc7eSAndroid Build Coastguard Worker ret =
2779*49cdfc7eSAndroid Build Coastguard Worker read_buffer(fd, io_type, buf, rd_size, 0, &errmsg);
2780*49cdfc7eSAndroid Build Coastguard Worker #endif
2781*49cdfc7eSAndroid Build Coastguard Worker
2782*49cdfc7eSAndroid Build Coastguard Worker if (ret != rd_size) {
2783*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %d %s/%d: %d CFa %s\n",
2784*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__,
2785*49cdfc7eSAndroid Build Coastguard Worker __LINE__, Iter_cnt, errmsg);
2786*49cdfc7eSAndroid Build Coastguard Worker free(buf);
2787*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2788*49cdfc7eSAndroid Build Coastguard Worker return -1;
2789*49cdfc7eSAndroid Build Coastguard Worker }
2790*49cdfc7eSAndroid Build Coastguard Worker /**
2791*49cdfc7eSAndroid Build Coastguard Worker read(fd, buf, rd_size);
2792*49cdfc7eSAndroid Build Coastguard Worker ***/
2793*49cdfc7eSAndroid Build Coastguard Worker
2794*49cdfc7eSAndroid Build Coastguard Worker if (Pattern == PATTERN_OFFSET)
2795*49cdfc7eSAndroid Build Coastguard Worker ret =
2796*49cdfc7eSAndroid Build Coastguard Worker datapidchk(STATIC_NUM, buf, rd_size, rd_cnt,
2797*49cdfc7eSAndroid Build Coastguard Worker &errmsg);
2798*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_PID)
2799*49cdfc7eSAndroid Build Coastguard Worker ret =
2800*49cdfc7eSAndroid Build Coastguard Worker datapidchk(Pid, buf, rd_size, rd_cnt,
2801*49cdfc7eSAndroid Build Coastguard Worker &errmsg);
2802*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ASCII)
2803*49cdfc7eSAndroid Build Coastguard Worker ret =
2804*49cdfc7eSAndroid Build Coastguard Worker dataasciichk(NULL, buf, rd_size, rd_cnt,
2805*49cdfc7eSAndroid Build Coastguard Worker &errmsg);
2806*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_RANDOM) ; /* no checks for random */
2807*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ALT)
2808*49cdfc7eSAndroid Build Coastguard Worker ret =
2809*49cdfc7eSAndroid Build Coastguard Worker databinchk('a', buf, rd_size, rd_cnt,
2810*49cdfc7eSAndroid Build Coastguard Worker &errmsg);
2811*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_CHKER)
2812*49cdfc7eSAndroid Build Coastguard Worker ret =
2813*49cdfc7eSAndroid Build Coastguard Worker databinchk('c', buf, rd_size, rd_cnt,
2814*49cdfc7eSAndroid Build Coastguard Worker &errmsg);
2815*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_CNTING)
2816*49cdfc7eSAndroid Build Coastguard Worker ret =
2817*49cdfc7eSAndroid Build Coastguard Worker databinchk('C', buf, rd_size, rd_cnt,
2818*49cdfc7eSAndroid Build Coastguard Worker &errmsg);
2819*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ZEROS)
2820*49cdfc7eSAndroid Build Coastguard Worker ret =
2821*49cdfc7eSAndroid Build Coastguard Worker databinchk('z', buf, rd_size, rd_cnt,
2822*49cdfc7eSAndroid Build Coastguard Worker &errmsg);
2823*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ONES)
2824*49cdfc7eSAndroid Build Coastguard Worker ret =
2825*49cdfc7eSAndroid Build Coastguard Worker databinchk('o', buf, rd_size, rd_cnt,
2826*49cdfc7eSAndroid Build Coastguard Worker &errmsg);
2827*49cdfc7eSAndroid Build Coastguard Worker else
2828*49cdfc7eSAndroid Build Coastguard Worker ret =
2829*49cdfc7eSAndroid Build Coastguard Worker dataasciichk(NULL, buf, rd_size, rd_cnt,
2830*49cdfc7eSAndroid Build Coastguard Worker &errmsg);
2831*49cdfc7eSAndroid Build Coastguard Worker
2832*49cdfc7eSAndroid Build Coastguard Worker if (ret >= 0) {
2833*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2834*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: %d CFp %s in file %s\n",
2835*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__,
2836*49cdfc7eSAndroid Build Coastguard Worker __LINE__, Iter_cnt, errmsg, filename);
2837*49cdfc7eSAndroid Build Coastguard Worker fflush(stderr);
2838*49cdfc7eSAndroid Build Coastguard Worker ret_val = 1;
2839*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2840*49cdfc7eSAndroid Build Coastguard Worker break;
2841*49cdfc7eSAndroid Build Coastguard Worker }
2842*49cdfc7eSAndroid Build Coastguard Worker rd_cnt += rd_size;
2843*49cdfc7eSAndroid Build Coastguard Worker }
2844*49cdfc7eSAndroid Build Coastguard Worker
2845*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2846*49cdfc7eSAndroid Build Coastguard Worker
2847*49cdfc7eSAndroid Build Coastguard Worker free(buf);
2848*49cdfc7eSAndroid Build Coastguard Worker
2849*49cdfc7eSAndroid Build Coastguard Worker } else {
2850*49cdfc7eSAndroid Build Coastguard Worker /*
2851*49cdfc7eSAndroid Build Coastguard Worker * Read the whole file in a single read
2852*49cdfc7eSAndroid Build Coastguard Worker */
2853*49cdfc7eSAndroid Build Coastguard Worker if ((buf = malloc(fsize)) == NULL) {
2854*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %s/%d: malloc(%d) failed: %s\n",
2855*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, __FILE__, __LINE__, fsize,
2856*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
2857*49cdfc7eSAndroid Build Coastguard Worker fflush(stderr);
2858*49cdfc7eSAndroid Build Coastguard Worker return -1;
2859*49cdfc7eSAndroid Build Coastguard Worker }
2860*49cdfc7eSAndroid Build Coastguard Worker
2861*49cdfc7eSAndroid Build Coastguard Worker lseek(fd, 0, SEEK_SET);
2862*49cdfc7eSAndroid Build Coastguard Worker
2863*49cdfc7eSAndroid Build Coastguard Worker /****
2864*49cdfc7eSAndroid Build Coastguard Worker read(fd, buf, fsize);
2865*49cdfc7eSAndroid Build Coastguard Worker ****/
2866*49cdfc7eSAndroid Build Coastguard Worker #if NEWIO
2867*49cdfc7eSAndroid Build Coastguard Worker ret =
2868*49cdfc7eSAndroid Build Coastguard Worker lio_read_buffer(fd, io_type, buf, fsize, SIGUSR1, &errmsg,
2869*49cdfc7eSAndroid Build Coastguard Worker 0);
2870*49cdfc7eSAndroid Build Coastguard Worker #else
2871*49cdfc7eSAndroid Build Coastguard Worker ret = read_buffer(fd, io_type, buf, fsize, 0, &errmsg);
2872*49cdfc7eSAndroid Build Coastguard Worker #endif
2873*49cdfc7eSAndroid Build Coastguard Worker
2874*49cdfc7eSAndroid Build Coastguard Worker /* unlock the file as soon as we can */
2875*49cdfc7eSAndroid Build Coastguard Worker lkfile(fd, LOCK_UN, LKLVL0);
2876*49cdfc7eSAndroid Build Coastguard Worker
2877*49cdfc7eSAndroid Build Coastguard Worker if (ret != fsize) {
2878*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr, "%s%s: %d %s/%d: %d CFw %s\n",
2879*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2880*49cdfc7eSAndroid Build Coastguard Worker Iter_cnt, errmsg);
2881*49cdfc7eSAndroid Build Coastguard Worker ret_val = 1;
2882*49cdfc7eSAndroid Build Coastguard Worker } else {
2883*49cdfc7eSAndroid Build Coastguard Worker if (Pattern == PATTERN_OFFSET)
2884*49cdfc7eSAndroid Build Coastguard Worker ret =
2885*49cdfc7eSAndroid Build Coastguard Worker datapidchk(STATIC_NUM, buf, fsize, 0,
2886*49cdfc7eSAndroid Build Coastguard Worker &errmsg);
2887*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_PID)
2888*49cdfc7eSAndroid Build Coastguard Worker ret = datapidchk(Pid, buf, fsize, 0, &errmsg);
2889*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ASCII)
2890*49cdfc7eSAndroid Build Coastguard Worker ret =
2891*49cdfc7eSAndroid Build Coastguard Worker dataasciichk(NULL, buf, fsize, 0, &errmsg);
2892*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_RANDOM) ; /* no check for random */
2893*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ALT)
2894*49cdfc7eSAndroid Build Coastguard Worker ret = databinchk('a', buf, fsize, 0, &errmsg);
2895*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_CHKER)
2896*49cdfc7eSAndroid Build Coastguard Worker ret = databinchk('c', buf, fsize, 0, &errmsg);
2897*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_CNTING)
2898*49cdfc7eSAndroid Build Coastguard Worker ret = databinchk('C', buf, fsize, 0, &errmsg);
2899*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ZEROS)
2900*49cdfc7eSAndroid Build Coastguard Worker ret = databinchk('z', buf, fsize, 0, &errmsg);
2901*49cdfc7eSAndroid Build Coastguard Worker else if (Pattern == PATTERN_ONES)
2902*49cdfc7eSAndroid Build Coastguard Worker ret = databinchk('o', buf, fsize, 0, &errmsg);
2903*49cdfc7eSAndroid Build Coastguard Worker else
2904*49cdfc7eSAndroid Build Coastguard Worker ret =
2905*49cdfc7eSAndroid Build Coastguard Worker dataasciichk(NULL, buf, fsize, 0, &errmsg);
2906*49cdfc7eSAndroid Build Coastguard Worker
2907*49cdfc7eSAndroid Build Coastguard Worker if (ret >= 0) {
2908*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2909*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: %d CFw %s in file %s\n",
2910*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__,
2911*49cdfc7eSAndroid Build Coastguard Worker __LINE__, Iter_cnt, errmsg, filename);
2912*49cdfc7eSAndroid Build Coastguard Worker fflush(stderr);
2913*49cdfc7eSAndroid Build Coastguard Worker ret_val = 1;
2914*49cdfc7eSAndroid Build Coastguard Worker }
2915*49cdfc7eSAndroid Build Coastguard Worker }
2916*49cdfc7eSAndroid Build Coastguard Worker free(buf);
2917*49cdfc7eSAndroid Build Coastguard Worker }
2918*49cdfc7eSAndroid Build Coastguard Worker
2919*49cdfc7eSAndroid Build Coastguard Worker return ret_val;
2920*49cdfc7eSAndroid Build Coastguard Worker
2921*49cdfc7eSAndroid Build Coastguard Worker } /* end of check_file */
2922*49cdfc7eSAndroid Build Coastguard Worker
2923*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
2924*49cdfc7eSAndroid Build Coastguard Worker *
2925*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
file_size(int fd)2926*49cdfc7eSAndroid Build Coastguard Worker int file_size(int fd)
2927*49cdfc7eSAndroid Build Coastguard Worker {
2928*49cdfc7eSAndroid Build Coastguard Worker struct stat sb;
2929*49cdfc7eSAndroid Build Coastguard Worker
2930*49cdfc7eSAndroid Build Coastguard Worker if (fstat(fd, &sb) < 0) {
2931*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
2932*49cdfc7eSAndroid Build Coastguard Worker "%s%s: %d %s/%d: Unable to fstat(%d, &buf), errno:%d %s\n",
2933*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__, fd, errno,
2934*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
2935*49cdfc7eSAndroid Build Coastguard Worker return -1;
2936*49cdfc7eSAndroid Build Coastguard Worker
2937*49cdfc7eSAndroid Build Coastguard Worker }
2938*49cdfc7eSAndroid Build Coastguard Worker
2939*49cdfc7eSAndroid Build Coastguard Worker return sb.st_size;
2940*49cdfc7eSAndroid Build Coastguard Worker }
2941*49cdfc7eSAndroid Build Coastguard Worker
2942*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
2943*49cdfc7eSAndroid Build Coastguard Worker * do file lock/unlock action.
2944*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
lkfile(int fd,int operation,int lklevel)2945*49cdfc7eSAndroid Build Coastguard Worker int lkfile(int fd, int operation, int lklevel)
2946*49cdfc7eSAndroid Build Coastguard Worker {
2947*49cdfc7eSAndroid Build Coastguard Worker char *errmsg;
2948*49cdfc7eSAndroid Build Coastguard Worker
2949*49cdfc7eSAndroid Build Coastguard Worker if (lockfile == lklevel) {
2950*49cdfc7eSAndroid Build Coastguard Worker
2951*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 5) {
2952*49cdfc7eSAndroid Build Coastguard Worker switch (operation) {
2953*49cdfc7eSAndroid Build Coastguard Worker case LOCK_UN:
2954*49cdfc7eSAndroid Build Coastguard Worker printf
2955*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG6 %s/%d: Attempting to release lock on fd %d\n",
2956*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, fd);
2957*49cdfc7eSAndroid Build Coastguard Worker break;
2958*49cdfc7eSAndroid Build Coastguard Worker
2959*49cdfc7eSAndroid Build Coastguard Worker case LOCK_SH:
2960*49cdfc7eSAndroid Build Coastguard Worker printf
2961*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG6 %s/%d: Attempting to get read/shared lock on fd %d\n",
2962*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, fd);
2963*49cdfc7eSAndroid Build Coastguard Worker break;
2964*49cdfc7eSAndroid Build Coastguard Worker
2965*49cdfc7eSAndroid Build Coastguard Worker case LOCK_EX:
2966*49cdfc7eSAndroid Build Coastguard Worker printf
2967*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG6 %s/%d: Attempting to get write/exclusive lock on fd %d\n",
2968*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, fd);
2969*49cdfc7eSAndroid Build Coastguard Worker break;
2970*49cdfc7eSAndroid Build Coastguard Worker }
2971*49cdfc7eSAndroid Build Coastguard Worker }
2972*49cdfc7eSAndroid Build Coastguard Worker
2973*49cdfc7eSAndroid Build Coastguard Worker /*
2974*49cdfc7eSAndroid Build Coastguard Worker * Attempt to get/release desired lock.
2975*49cdfc7eSAndroid Build Coastguard Worker * file_lock will attempt to do action over and over again until
2976*49cdfc7eSAndroid Build Coastguard Worker * either an unretryable error or the action is completed.
2977*49cdfc7eSAndroid Build Coastguard Worker */
2978*49cdfc7eSAndroid Build Coastguard Worker
2979*49cdfc7eSAndroid Build Coastguard Worker if (file_lock(fd, operation, &errmsg) != 0) {
2980*49cdfc7eSAndroid Build Coastguard Worker printf
2981*49cdfc7eSAndroid Build Coastguard Worker ("%s%s: %d %s/%d: Unable to perform lock operation. %s\n",
2982*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, Pid, __FILE__, __LINE__,
2983*49cdfc7eSAndroid Build Coastguard Worker errmsg);
2984*49cdfc7eSAndroid Build Coastguard Worker
2985*49cdfc7eSAndroid Build Coastguard Worker /* do we count this as an error? handle_error(); */
2986*49cdfc7eSAndroid Build Coastguard Worker return -1;
2987*49cdfc7eSAndroid Build Coastguard Worker }
2988*49cdfc7eSAndroid Build Coastguard Worker
2989*49cdfc7eSAndroid Build Coastguard Worker if (Debug > 2) {
2990*49cdfc7eSAndroid Build Coastguard Worker switch (operation) {
2991*49cdfc7eSAndroid Build Coastguard Worker case LOCK_UN:
2992*49cdfc7eSAndroid Build Coastguard Worker printf
2993*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %s/%d: Released lock on fd %d\n",
2994*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, fd);
2995*49cdfc7eSAndroid Build Coastguard Worker break;
2996*49cdfc7eSAndroid Build Coastguard Worker
2997*49cdfc7eSAndroid Build Coastguard Worker case LOCK_SH:
2998*49cdfc7eSAndroid Build Coastguard Worker printf
2999*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %s/%d: Got read/shared lock on fd %d\n",
3000*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, fd);
3001*49cdfc7eSAndroid Build Coastguard Worker break;
3002*49cdfc7eSAndroid Build Coastguard Worker
3003*49cdfc7eSAndroid Build Coastguard Worker case LOCK_EX:
3004*49cdfc7eSAndroid Build Coastguard Worker printf
3005*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %s/%d: Got write/exclusive lock on fd %d\n",
3006*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__, fd);
3007*49cdfc7eSAndroid Build Coastguard Worker break;
3008*49cdfc7eSAndroid Build Coastguard Worker
3009*49cdfc7eSAndroid Build Coastguard Worker default:
3010*49cdfc7eSAndroid Build Coastguard Worker printf
3011*49cdfc7eSAndroid Build Coastguard Worker ("%s: %d DEBUG3 %s/%d: Completed action %d on fd %d\n",
3012*49cdfc7eSAndroid Build Coastguard Worker Progname, Pid, __FILE__, __LINE__,
3013*49cdfc7eSAndroid Build Coastguard Worker operation, fd);
3014*49cdfc7eSAndroid Build Coastguard Worker break;
3015*49cdfc7eSAndroid Build Coastguard Worker }
3016*49cdfc7eSAndroid Build Coastguard Worker }
3017*49cdfc7eSAndroid Build Coastguard Worker }
3018*49cdfc7eSAndroid Build Coastguard Worker
3019*49cdfc7eSAndroid Build Coastguard Worker return 0;
3020*49cdfc7eSAndroid Build Coastguard Worker }
3021*49cdfc7eSAndroid Build Coastguard Worker
3022*49cdfc7eSAndroid Build Coastguard Worker #ifndef linux
3023*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
3024*49cdfc7eSAndroid Build Coastguard Worker *
3025*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
pre_alloc(int fd,long size)3026*49cdfc7eSAndroid Build Coastguard Worker int pre_alloc(int fd, long size)
3027*49cdfc7eSAndroid Build Coastguard Worker {
3028*49cdfc7eSAndroid Build Coastguard Worker
3029*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
3030*49cdfc7eSAndroid Build Coastguard Worker long avl;
3031*49cdfc7eSAndroid Build Coastguard Worker
3032*49cdfc7eSAndroid Build Coastguard Worker if (ialloc(fd, size, IA_CONT, &avl) == -1) {
3033*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
3034*49cdfc7eSAndroid Build Coastguard Worker "%s%s %s/%d: Unable to pre-alloc space: ialloc failed: %d %s\n",
3035*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, __FILE__, __LINE__, errno,
3036*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
3037*49cdfc7eSAndroid Build Coastguard Worker return -1;
3038*49cdfc7eSAndroid Build Coastguard Worker }
3039*49cdfc7eSAndroid Build Coastguard Worker #endif
3040*49cdfc7eSAndroid Build Coastguard Worker
3041*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
3042*49cdfc7eSAndroid Build Coastguard Worker struct flock f;
3043*49cdfc7eSAndroid Build Coastguard Worker
3044*49cdfc7eSAndroid Build Coastguard Worker f.l_whence = 0;
3045*49cdfc7eSAndroid Build Coastguard Worker f.l_start = 0;
3046*49cdfc7eSAndroid Build Coastguard Worker f.l_len = size;
3047*49cdfc7eSAndroid Build Coastguard Worker
3048*49cdfc7eSAndroid Build Coastguard Worker /* non-zeroing reservation */
3049*49cdfc7eSAndroid Build Coastguard Worker if (fcntl(fd, F_RESVSP, &f) == -1) {
3050*49cdfc7eSAndroid Build Coastguard Worker fprintf(stderr,
3051*49cdfc7eSAndroid Build Coastguard Worker "%s%s %s/%d: Unable to pre-alloc space: fcntl(F_RESVSP) failed: %d %s\n",
3052*49cdfc7eSAndroid Build Coastguard Worker Progname, TagName, __FILE__, __LINE__, errno,
3053*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
3054*49cdfc7eSAndroid Build Coastguard Worker return -1;
3055*49cdfc7eSAndroid Build Coastguard Worker }
3056*49cdfc7eSAndroid Build Coastguard Worker #endif
3057*49cdfc7eSAndroid Build Coastguard Worker
3058*49cdfc7eSAndroid Build Coastguard Worker return 0;
3059*49cdfc7eSAndroid Build Coastguard Worker }
3060*49cdfc7eSAndroid Build Coastguard Worker #endif
3061