xref: /aosp_15_r20/external/ltp/testcases/kernel/fs/doio/iogen.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
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  * iogen - a tool for generating file/sds io for a doio process
34*49cdfc7eSAndroid Build Coastguard Worker  */
35*49cdfc7eSAndroid Build Coastguard Worker 
36*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
37*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
38*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
39*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
40*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
41*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
42*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
43*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
44*49cdfc7eSAndroid Build Coastguard Worker #include <time.h>
45*49cdfc7eSAndroid Build Coastguard Worker #include <sys/param.h>
46*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
47*49cdfc7eSAndroid Build Coastguard Worker #include <sys/time.h>
48*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
49*49cdfc7eSAndroid Build Coastguard Worker #include <sys/sysmacros.h>
50*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
51*49cdfc7eSAndroid Build Coastguard Worker #include <sys/file.h>
52*49cdfc7eSAndroid Build Coastguard Worker #include <sys/iosw.h>
53*49cdfc7eSAndroid Build Coastguard Worker #include <sys/listio.h>
54*49cdfc7eSAndroid Build Coastguard Worker #endif
55*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
56*49cdfc7eSAndroid Build Coastguard Worker #include <sys/statvfs.h>
57*49cdfc7eSAndroid Build Coastguard Worker #include <sys/fs/xfs_itable.h>
58*49cdfc7eSAndroid Build Coastguard Worker #endif
59*49cdfc7eSAndroid Build Coastguard Worker 
60*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
61*49cdfc7eSAndroid Build Coastguard Worker #include "libkern.h"
62*49cdfc7eSAndroid Build Coastguard Worker #endif
63*49cdfc7eSAndroid Build Coastguard Worker #include "doio.h"
64*49cdfc7eSAndroid Build Coastguard Worker #include "bytes_by_prefix.h"
65*49cdfc7eSAndroid Build Coastguard Worker #include "string_to_tokens.h"
66*49cdfc7eSAndroid Build Coastguard Worker #include "open_flags.h"
67*49cdfc7eSAndroid Build Coastguard Worker #include "random_range.h"
68*49cdfc7eSAndroid Build Coastguard Worker 
69*49cdfc7eSAndroid Build Coastguard Worker #ifndef PATH_MAX
70*49cdfc7eSAndroid Build Coastguard Worker #define	PATH_MAX 512		/* ??? */
71*49cdfc7eSAndroid Build Coastguard Worker #endif
72*49cdfc7eSAndroid Build Coastguard Worker 
73*49cdfc7eSAndroid Build Coastguard Worker #ifndef BSIZE
74*49cdfc7eSAndroid Build Coastguard Worker #ifdef linux
75*49cdfc7eSAndroid Build Coastguard Worker #define BSIZE DEV_BSIZE
76*49cdfc7eSAndroid Build Coastguard Worker #else
77*49cdfc7eSAndroid Build Coastguard Worker #define BSIZE 512
78*49cdfc7eSAndroid Build Coastguard Worker #endif
79*49cdfc7eSAndroid Build Coastguard Worker #endif
80*49cdfc7eSAndroid Build Coastguard Worker 
81*49cdfc7eSAndroid Build Coastguard Worker #define RAW_IO(_flags_)	((_flags_) & (O_RAW | O_SSD))
82*49cdfc7eSAndroid Build Coastguard Worker 
83*49cdfc7eSAndroid Build Coastguard Worker #ifndef __linux__
84*49cdfc7eSAndroid Build Coastguard Worker extern char *sys_errlist[];
85*49cdfc7eSAndroid Build Coastguard Worker #endif
86*49cdfc7eSAndroid Build Coastguard Worker #define SYSERR	strerror(errno)
87*49cdfc7eSAndroid Build Coastguard Worker 
88*49cdfc7eSAndroid Build Coastguard Worker /*
89*49cdfc7eSAndroid Build Coastguard Worker  * Structure for retaining test file information
90*49cdfc7eSAndroid Build Coastguard Worker  */
91*49cdfc7eSAndroid Build Coastguard Worker 
92*49cdfc7eSAndroid Build Coastguard Worker struct file_info {
93*49cdfc7eSAndroid Build Coastguard Worker 	char f_path[MAX_FNAME_LENGTH + 1];	/* file name (full path)    */
94*49cdfc7eSAndroid Build Coastguard Worker 	int f_length;		/* length in bytes                      */
95*49cdfc7eSAndroid Build Coastguard Worker 	int f_iou;		/* file iounit                          */
96*49cdfc7eSAndroid Build Coastguard Worker 	int f_riou;		/* file raw iounit (for O_RAW/O_SSD)    */
97*49cdfc7eSAndroid Build Coastguard Worker 	int f_dalign;		/* direct I/O alignment                 */
98*49cdfc7eSAndroid Build Coastguard Worker 	int f_nextoff;		/* offset of end of last io operation   */
99*49cdfc7eSAndroid Build Coastguard Worker 	int f_type;		/* file type S_IFREG, etc...            */
100*49cdfc7eSAndroid Build Coastguard Worker 	int f_lastoffset;	/* offset of last io operation          */
101*49cdfc7eSAndroid Build Coastguard Worker 	int f_lastlength;	/* length of last io operation          */
102*49cdfc7eSAndroid Build Coastguard Worker };
103*49cdfc7eSAndroid Build Coastguard Worker 
104*49cdfc7eSAndroid Build Coastguard Worker /*
105*49cdfc7eSAndroid Build Coastguard Worker  * Simple structure for associating strings with values - useful for converting
106*49cdfc7eSAndroid Build Coastguard Worker  * cmdline args to internal values, as well as printing internal values in
107*49cdfc7eSAndroid Build Coastguard Worker  * a human readable form.
108*49cdfc7eSAndroid Build Coastguard Worker  */
109*49cdfc7eSAndroid Build Coastguard Worker 
110*49cdfc7eSAndroid Build Coastguard Worker struct strmap {
111*49cdfc7eSAndroid Build Coastguard Worker 	char *m_string;
112*49cdfc7eSAndroid Build Coastguard Worker 	int m_value;
113*49cdfc7eSAndroid Build Coastguard Worker 	int m_flags;
114*49cdfc7eSAndroid Build Coastguard Worker };
115*49cdfc7eSAndroid Build Coastguard Worker 
116*49cdfc7eSAndroid Build Coastguard Worker void startup_info(FILE * stream, int seed);
117*49cdfc7eSAndroid Build Coastguard Worker int init_output(void);
118*49cdfc7eSAndroid Build Coastguard Worker int form_iorequest(struct io_req *req);
119*49cdfc7eSAndroid Build Coastguard Worker int get_file_info(struct file_info *rec);
120*49cdfc7eSAndroid Build Coastguard Worker int create_file(char *path, int nbytes);
121*49cdfc7eSAndroid Build Coastguard Worker int str_to_value(struct strmap *map, char *str);
122*49cdfc7eSAndroid Build Coastguard Worker struct strmap *str_lookup(struct strmap *map, char *str);
123*49cdfc7eSAndroid Build Coastguard Worker char *value_to_string(struct strmap *map, int val);
124*49cdfc7eSAndroid Build Coastguard Worker int parse_cmdline(int argc, char **argv, char *opts);
125*49cdfc7eSAndroid Build Coastguard Worker int help(FILE * stream);
126*49cdfc7eSAndroid Build Coastguard Worker int usage(FILE * stream);
127*49cdfc7eSAndroid Build Coastguard Worker 
128*49cdfc7eSAndroid Build Coastguard Worker /*
129*49cdfc7eSAndroid Build Coastguard Worker  * Declare cmdline option flags/variables initialized in parse_cmdline()
130*49cdfc7eSAndroid Build Coastguard Worker  */
131*49cdfc7eSAndroid Build Coastguard Worker 
132*49cdfc7eSAndroid Build Coastguard Worker #define OPTS	"a:dhf:i:L:m:op:qr:s:t:T:O:N:"
133*49cdfc7eSAndroid Build Coastguard Worker 
134*49cdfc7eSAndroid Build Coastguard Worker int a_opt = 0;			/* async io comp. types supplied            */
135*49cdfc7eSAndroid Build Coastguard Worker int o_opt = 0;			/* form overlapping requests                */
136*49cdfc7eSAndroid Build Coastguard Worker int f_opt = 0;			/* test flags                               */
137*49cdfc7eSAndroid Build Coastguard Worker int i_opt = 0;			/* iterations - 0 implies infinite          */
138*49cdfc7eSAndroid Build Coastguard Worker int L_opt = 0;			/* listio min-max nstrides & nents          */
139*49cdfc7eSAndroid Build Coastguard Worker int m_opt = 0;			/* offset mode                              */
140*49cdfc7eSAndroid Build Coastguard Worker int O_opt = 0;			/* file creation Open flags                 */
141*49cdfc7eSAndroid Build Coastguard Worker int p_opt = 0;			/* output pipe - default is stdout          */
142*49cdfc7eSAndroid Build Coastguard Worker int r_opt = 0;			/* specify raw io multiple instead of       */
143*49cdfc7eSAndroid Build Coastguard Worker 				/* getting it from the mounted on device.   */
144*49cdfc7eSAndroid Build Coastguard Worker 				/* Only applies to regular files.           */
145*49cdfc7eSAndroid Build Coastguard Worker int s_opt = 0;			/* syscalls                                 */
146*49cdfc7eSAndroid Build Coastguard Worker int t_opt = 0;			/* min transfer size (bytes)                */
147*49cdfc7eSAndroid Build Coastguard Worker int T_opt = 0;			/* max transfer size (bytes)                */
148*49cdfc7eSAndroid Build Coastguard Worker int q_opt = 0;			/* quiet operation on startup               */
149*49cdfc7eSAndroid Build Coastguard Worker char TagName[40];		/* name of this iogen (see Monster)         */
150*49cdfc7eSAndroid Build Coastguard Worker struct strmap *Offset_Mode;	/* M_SEQUENTIAL, M_RANDOM, etc.             */
151*49cdfc7eSAndroid Build Coastguard Worker int Iterations;			/* # requests to generate (0 --> infinite)  */
152*49cdfc7eSAndroid Build Coastguard Worker int Time_Mode = 0;		/* non-zero if Iterations is in seconds     */
153*49cdfc7eSAndroid Build Coastguard Worker 				/* (ie. -i arg was suffixed with 's')       */
154*49cdfc7eSAndroid Build Coastguard Worker char *Outpipe;			/* Pipe to write output to if p_opt         */
155*49cdfc7eSAndroid Build Coastguard Worker int Mintrans;			/* min io transfer size                     */
156*49cdfc7eSAndroid Build Coastguard Worker int Maxtrans;			/* max io transfer size                     */
157*49cdfc7eSAndroid Build Coastguard Worker int Rawmult;			/* raw/ssd io multiple (from -r)            */
158*49cdfc7eSAndroid Build Coastguard Worker int Minstrides;			/* min # of listio strides per request      */
159*49cdfc7eSAndroid Build Coastguard Worker int Maxstrides;			/* max # of listio strides per request      */
160*49cdfc7eSAndroid Build Coastguard Worker int Oflags;			/* open(2) flags for creating files         */
161*49cdfc7eSAndroid Build Coastguard Worker int Ocbits;			/* open(2) cbits for creating files         */
162*49cdfc7eSAndroid Build Coastguard Worker int Ocblks;			/* open(2) cblks for creating files         */
163*49cdfc7eSAndroid Build Coastguard Worker int Orealtime = 0;		/* flag set for -O REALTIME                 */
164*49cdfc7eSAndroid Build Coastguard Worker int Oextsize = 0;		/* real-time extent size                    */
165*49cdfc7eSAndroid Build Coastguard Worker int Oreserve = 1;		/* flag for -O [no]reserve                  */
166*49cdfc7eSAndroid Build Coastguard Worker int Oallocate = 0;		/* flag for -O allocate                     */
167*49cdfc7eSAndroid Build Coastguard Worker int Owrite = 1;			/* flag for -O nowrite                      */
168*49cdfc7eSAndroid Build Coastguard Worker 
169*49cdfc7eSAndroid Build Coastguard Worker int Nfiles = 0;			/* # files on cmdline                       */
170*49cdfc7eSAndroid Build Coastguard Worker struct file_info *File_List;	/* info about each file                     */
171*49cdfc7eSAndroid Build Coastguard Worker int Nflags = 0;			/* # flags on cmdline                       */
172*49cdfc7eSAndroid Build Coastguard Worker struct strmap *Flag_List[128];	/* flags selected from cmdline              */
173*49cdfc7eSAndroid Build Coastguard Worker int Nsyscalls = 0;		/* # syscalls on cmdline                    */
174*49cdfc7eSAndroid Build Coastguard Worker struct strmap *Syscall_List[128];	/* syscalls selected on cmdline          */
175*49cdfc7eSAndroid Build Coastguard Worker int Fileio = 0;			/* flag indicating that a file              */
176*49cdfc7eSAndroid Build Coastguard Worker 				/* io syscall has been chosen.              */
177*49cdfc7eSAndroid Build Coastguard Worker int Naio_Strat_Types = 0;	/* # async io completion types              */
178*49cdfc7eSAndroid Build Coastguard Worker struct strmap *Aio_Strat_List[128];	/* Async io completion types           */
179*49cdfc7eSAndroid Build Coastguard Worker 
180*49cdfc7eSAndroid Build Coastguard Worker /*
181*49cdfc7eSAndroid Build Coastguard Worker  * Map async io completion modes (-a args) names to values.  Macros are
182*49cdfc7eSAndroid Build Coastguard Worker  * defined in doio.h.
183*49cdfc7eSAndroid Build Coastguard Worker  */
184*49cdfc7eSAndroid Build Coastguard Worker 
185*49cdfc7eSAndroid Build Coastguard Worker struct strmap Aio_Strat_Map[] = {
186*49cdfc7eSAndroid Build Coastguard Worker #ifndef linux
187*49cdfc7eSAndroid Build Coastguard Worker 	{"poll", A_POLL},
188*49cdfc7eSAndroid Build Coastguard Worker 	{"signal", A_SIGNAL},
189*49cdfc7eSAndroid Build Coastguard Worker #else
190*49cdfc7eSAndroid Build Coastguard Worker 	{"none", 0},
191*49cdfc7eSAndroid Build Coastguard Worker #endif /* !linux */
192*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
193*49cdfc7eSAndroid Build Coastguard Worker #if _UMK || RELEASE_LEVEL >= 8000
194*49cdfc7eSAndroid Build Coastguard Worker 	{"recall", A_RECALL},
195*49cdfc7eSAndroid Build Coastguard Worker #endif
196*49cdfc7eSAndroid Build Coastguard Worker 
197*49cdfc7eSAndroid Build Coastguard Worker #ifdef RECALL_SIZEOF
198*49cdfc7eSAndroid Build Coastguard Worker 	{"recalla", A_RECALLA},
199*49cdfc7eSAndroid Build Coastguard Worker #endif
200*49cdfc7eSAndroid Build Coastguard Worker 	{"recalls", A_RECALLS},
201*49cdfc7eSAndroid Build Coastguard Worker #endif /* CRAY */
202*49cdfc7eSAndroid Build Coastguard Worker 
203*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
204*49cdfc7eSAndroid Build Coastguard Worker 	{"suspend", A_SUSPEND},
205*49cdfc7eSAndroid Build Coastguard Worker 	{"callback", A_CALLBACK},
206*49cdfc7eSAndroid Build Coastguard Worker #endif
207*49cdfc7eSAndroid Build Coastguard Worker 	{NULL, -1}
208*49cdfc7eSAndroid Build Coastguard Worker };
209*49cdfc7eSAndroid Build Coastguard Worker 
210*49cdfc7eSAndroid Build Coastguard Worker /*
211*49cdfc7eSAndroid Build Coastguard Worker  * Offset_Mode #defines
212*49cdfc7eSAndroid Build Coastguard Worker  */
213*49cdfc7eSAndroid Build Coastguard Worker 
214*49cdfc7eSAndroid Build Coastguard Worker #define M_RANDOM    	1
215*49cdfc7eSAndroid Build Coastguard Worker #define M_SEQUENTIAL	2
216*49cdfc7eSAndroid Build Coastguard Worker #define M_REVERSE   	3
217*49cdfc7eSAndroid Build Coastguard Worker 
218*49cdfc7eSAndroid Build Coastguard Worker /*
219*49cdfc7eSAndroid Build Coastguard Worker  * Map offset mode (-m args) names to values
220*49cdfc7eSAndroid Build Coastguard Worker  */
221*49cdfc7eSAndroid Build Coastguard Worker 
222*49cdfc7eSAndroid Build Coastguard Worker struct strmap Omode_Map[] = {
223*49cdfc7eSAndroid Build Coastguard Worker 	{"random", M_RANDOM},
224*49cdfc7eSAndroid Build Coastguard Worker 	{"sequential", M_SEQUENTIAL},
225*49cdfc7eSAndroid Build Coastguard Worker 	{"reverse", M_REVERSE},
226*49cdfc7eSAndroid Build Coastguard Worker 	{NULL, -1}
227*49cdfc7eSAndroid Build Coastguard Worker };
228*49cdfc7eSAndroid Build Coastguard Worker 
229*49cdfc7eSAndroid Build Coastguard Worker /*
230*49cdfc7eSAndroid Build Coastguard Worker  * Map syscall names (-s args) to values - macros are defined in doio.h.
231*49cdfc7eSAndroid Build Coastguard Worker  */
232*49cdfc7eSAndroid Build Coastguard Worker #define	SY_ASYNC	00001
233*49cdfc7eSAndroid Build Coastguard Worker #define	SY_WRITE	00002
234*49cdfc7eSAndroid Build Coastguard Worker #define	SY_SDS		00010
235*49cdfc7eSAndroid Build Coastguard Worker #define	SY_LISTIO	00020
236*49cdfc7eSAndroid Build Coastguard Worker #define	SY_NENT		00100	/* multi entry vs multi stride >>> */
237*49cdfc7eSAndroid Build Coastguard Worker 
238*49cdfc7eSAndroid Build Coastguard Worker struct strmap Syscall_Map[] = {
239*49cdfc7eSAndroid Build Coastguard Worker 	{"read", READ, 0},
240*49cdfc7eSAndroid Build Coastguard Worker 	{"write", WRITE, SY_WRITE},
241*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
242*49cdfc7eSAndroid Build Coastguard Worker 	{"reada", READA, SY_ASYNC},
243*49cdfc7eSAndroid Build Coastguard Worker 	{"writea", WRITEA, SY_WRITE | SY_ASYNC},
244*49cdfc7eSAndroid Build Coastguard Worker #ifndef _CRAYMPP
245*49cdfc7eSAndroid Build Coastguard Worker 	{"ssread", SSREAD, SY_SDS},
246*49cdfc7eSAndroid Build Coastguard Worker 	{"sswrite", SSWRITE, SY_WRITE | SY_SDS},
247*49cdfc7eSAndroid Build Coastguard Worker #endif
248*49cdfc7eSAndroid Build Coastguard Worker 	{"listio", LISTIO, SY_ASYNC},
249*49cdfc7eSAndroid Build Coastguard Worker 
250*49cdfc7eSAndroid Build Coastguard Worker 	/* listio as 4 system calls */
251*49cdfc7eSAndroid Build Coastguard Worker 	{"lread", LREAD, 0},
252*49cdfc7eSAndroid Build Coastguard Worker 	{"lreada", LREADA, SY_ASYNC},
253*49cdfc7eSAndroid Build Coastguard Worker 	{"lwrite", LWRITE, SY_WRITE},
254*49cdfc7eSAndroid Build Coastguard Worker 	{"lwritea", LWRITEA, SY_WRITE | SY_ASYNC},
255*49cdfc7eSAndroid Build Coastguard Worker 
256*49cdfc7eSAndroid Build Coastguard Worker 	/* listio with nstrides > 1 */
257*49cdfc7eSAndroid Build Coastguard Worker 	{"lsread", LSREAD, 0},
258*49cdfc7eSAndroid Build Coastguard Worker 	{"lsreada", LSREADA, SY_ASYNC},
259*49cdfc7eSAndroid Build Coastguard Worker 	{"lswrite", LSWRITE, SY_WRITE},
260*49cdfc7eSAndroid Build Coastguard Worker 	{"lswritea", LSWRITEA, SY_WRITE | SY_ASYNC},
261*49cdfc7eSAndroid Build Coastguard Worker 
262*49cdfc7eSAndroid Build Coastguard Worker 	/* listio with nents > 1 */
263*49cdfc7eSAndroid Build Coastguard Worker 	{"leread", LEREAD, 0 | SY_NENT},
264*49cdfc7eSAndroid Build Coastguard Worker 	{"lereada", LEREADA, SY_ASYNC | SY_NENT},
265*49cdfc7eSAndroid Build Coastguard Worker 	{"lewrite", LEWRITE, SY_WRITE | SY_NENT},
266*49cdfc7eSAndroid Build Coastguard Worker 	{"lewritea", LEWRITEA, SY_WRITE | SY_ASYNC | SY_NENT},
267*49cdfc7eSAndroid Build Coastguard Worker 
268*49cdfc7eSAndroid Build Coastguard Worker 	/* listio with nents > 1 & nstrides > 1 */
269*49cdfc7eSAndroid Build Coastguard Worker 
270*49cdfc7eSAndroid Build Coastguard Worker 	/* all listio system calls under one name */
271*49cdfc7eSAndroid Build Coastguard Worker 	{"listio+", LREAD, 0},
272*49cdfc7eSAndroid Build Coastguard Worker 	{"listio+", LREADA, SY_ASYNC},
273*49cdfc7eSAndroid Build Coastguard Worker 	{"listio+", LWRITE, SY_WRITE},
274*49cdfc7eSAndroid Build Coastguard Worker 	{"listio+", LWRITEA, SY_WRITE | SY_ASYNC},
275*49cdfc7eSAndroid Build Coastguard Worker 	{"listio+", LSREAD, 0},
276*49cdfc7eSAndroid Build Coastguard Worker 	{"listio+", LSREADA, SY_ASYNC},
277*49cdfc7eSAndroid Build Coastguard Worker 	{"listio+", LSWRITE, SY_WRITE},
278*49cdfc7eSAndroid Build Coastguard Worker 	{"listio+", LSWRITEA, SY_WRITE | SY_ASYNC},
279*49cdfc7eSAndroid Build Coastguard Worker 	{"listio+", LEREAD, 0 | SY_NENT},
280*49cdfc7eSAndroid Build Coastguard Worker 	{"listio+", LEREADA, SY_ASYNC | SY_NENT},
281*49cdfc7eSAndroid Build Coastguard Worker 	{"listio+", LEWRITE, SY_WRITE | SY_NENT},
282*49cdfc7eSAndroid Build Coastguard Worker 	{"listio+", LEWRITEA, SY_WRITE | SY_ASYNC | SY_NENT},
283*49cdfc7eSAndroid Build Coastguard Worker #endif
284*49cdfc7eSAndroid Build Coastguard Worker 
285*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
286*49cdfc7eSAndroid Build Coastguard Worker 	{"pread", PREAD},
287*49cdfc7eSAndroid Build Coastguard Worker 	{"pwrite", PWRITE, SY_WRITE},
288*49cdfc7eSAndroid Build Coastguard Worker 	{"aread", AREAD, SY_ASYNC},
289*49cdfc7eSAndroid Build Coastguard Worker 	{"awrite", AWRITE, SY_WRITE | SY_ASYNC},
290*49cdfc7eSAndroid Build Coastguard Worker #if 0
291*49cdfc7eSAndroid Build Coastguard Worker 	/* not written yet */
292*49cdfc7eSAndroid Build Coastguard Worker 	{"llread", LLREAD, 0},
293*49cdfc7eSAndroid Build Coastguard Worker 	{"llaread", LLAREAD, SY_ASYNC},
294*49cdfc7eSAndroid Build Coastguard Worker 	{"llwrite", LLWRITE, 0},
295*49cdfc7eSAndroid Build Coastguard Worker 	{"llawrite", LLAWRITE, SY_ASYNC},
296*49cdfc7eSAndroid Build Coastguard Worker #endif
297*49cdfc7eSAndroid Build Coastguard Worker 	{"resvsp", RESVSP, SY_WRITE},
298*49cdfc7eSAndroid Build Coastguard Worker 	{"unresvsp", UNRESVSP, SY_WRITE},
299*49cdfc7eSAndroid Build Coastguard Worker 	{"reserve", RESVSP, SY_WRITE},
300*49cdfc7eSAndroid Build Coastguard Worker 	{"unreserve", UNRESVSP, SY_WRITE},
301*49cdfc7eSAndroid Build Coastguard Worker 	{"ffsync", DFFSYNC, SY_WRITE},
302*49cdfc7eSAndroid Build Coastguard Worker #endif /* SGI */
303*49cdfc7eSAndroid Build Coastguard Worker 
304*49cdfc7eSAndroid Build Coastguard Worker #ifndef CRAY
305*49cdfc7eSAndroid Build Coastguard Worker 	{"readv", READV},
306*49cdfc7eSAndroid Build Coastguard Worker 	{"writev", WRITEV, SY_WRITE},
307*49cdfc7eSAndroid Build Coastguard Worker 	{"mmread", MMAPR},
308*49cdfc7eSAndroid Build Coastguard Worker 	{"mmwrite", MMAPW, SY_WRITE},
309*49cdfc7eSAndroid Build Coastguard Worker 	{"fsync2", FSYNC2, SY_WRITE},
310*49cdfc7eSAndroid Build Coastguard Worker 	{"fdatasync", FDATASYNC, SY_WRITE},
311*49cdfc7eSAndroid Build Coastguard Worker #endif
312*49cdfc7eSAndroid Build Coastguard Worker 
313*49cdfc7eSAndroid Build Coastguard Worker 	{NULL, -1}
314*49cdfc7eSAndroid Build Coastguard Worker };
315*49cdfc7eSAndroid Build Coastguard Worker 
316*49cdfc7eSAndroid Build Coastguard Worker /*
317*49cdfc7eSAndroid Build Coastguard Worker  * Map open flags (-f args) to values
318*49cdfc7eSAndroid Build Coastguard Worker  */
319*49cdfc7eSAndroid Build Coastguard Worker #define	FLG_RAW		00001
320*49cdfc7eSAndroid Build Coastguard Worker 
321*49cdfc7eSAndroid Build Coastguard Worker struct strmap Flag_Map[] = {
322*49cdfc7eSAndroid Build Coastguard Worker 	{"buffered", 0, 0},
323*49cdfc7eSAndroid Build Coastguard Worker 	{"sync", O_SYNC, 0},
324*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
325*49cdfc7eSAndroid Build Coastguard Worker 	{"raw", O_RAW, FLG_RAW},
326*49cdfc7eSAndroid Build Coastguard Worker 	{"raw+wf", O_RAW | O_WELLFORMED, FLG_RAW},
327*49cdfc7eSAndroid Build Coastguard Worker 	{"raw+wf+ldraw", O_RAW | O_WELLFORMED | O_LDRAW, FLG_RAW},
328*49cdfc7eSAndroid Build Coastguard Worker 	{"raw+wf+ldraw+sync", O_RAW | O_WELLFORMED | O_LDRAW | O_SYNC, FLG_RAW},
329*49cdfc7eSAndroid Build Coastguard Worker #ifdef O_SSD
330*49cdfc7eSAndroid Build Coastguard Worker 	{"ssd", O_SSD, FLG_RAW},
331*49cdfc7eSAndroid Build Coastguard Worker #endif
332*49cdfc7eSAndroid Build Coastguard Worker #ifdef O_LDRAW
333*49cdfc7eSAndroid Build Coastguard Worker 	{"ldraw", O_LDRAW, 0},
334*49cdfc7eSAndroid Build Coastguard Worker #endif
335*49cdfc7eSAndroid Build Coastguard Worker #ifdef O_PARALLEL
336*49cdfc7eSAndroid Build Coastguard Worker 	{"parallel", O_PARALLEL | O_RAW | O_WELLFORMED,
337*49cdfc7eSAndroid Build Coastguard Worker 	 FLG_RAW},
338*49cdfc7eSAndroid Build Coastguard Worker 	{"parallel+sync", O_PARALLEL | O_RAW | O_WELLFORMED | O_SYNC,
339*49cdfc7eSAndroid Build Coastguard Worker 	 FLG_RAW},
340*49cdfc7eSAndroid Build Coastguard Worker 	{"parallel+ldraw", O_PARALLEL | O_RAW | O_WELLFORMED | O_LDRAW,
341*49cdfc7eSAndroid Build Coastguard Worker 	 FLG_RAW},
342*49cdfc7eSAndroid Build Coastguard Worker 	{"parallel+ldraw+sync",
343*49cdfc7eSAndroid Build Coastguard Worker 	 O_PARALLEL | O_RAW | O_WELLFORMED | O_LDRAW | O_SYNC,
344*49cdfc7eSAndroid Build Coastguard Worker 	 FLG_RAW},
345*49cdfc7eSAndroid Build Coastguard Worker #endif
346*49cdfc7eSAndroid Build Coastguard Worker #endif /* CRAY */
347*49cdfc7eSAndroid Build Coastguard Worker 
348*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
349*49cdfc7eSAndroid Build Coastguard Worker 	{"direct", O_DIRECT, FLG_RAW},
350*49cdfc7eSAndroid Build Coastguard Worker 	{"dsync", O_DSYNC},	/* affects writes */
351*49cdfc7eSAndroid Build Coastguard Worker 	{"rsync", O_RSYNC},	/* affects reads */
352*49cdfc7eSAndroid Build Coastguard Worker 	{"rsync+dsync", O_RSYNC | O_DSYNC},
353*49cdfc7eSAndroid Build Coastguard Worker #endif
354*49cdfc7eSAndroid Build Coastguard Worker 	{NULL, -1}
355*49cdfc7eSAndroid Build Coastguard Worker };
356*49cdfc7eSAndroid Build Coastguard Worker 
357*49cdfc7eSAndroid Build Coastguard Worker /*
358*49cdfc7eSAndroid Build Coastguard Worker  * Map file types to strings
359*49cdfc7eSAndroid Build Coastguard Worker  */
360*49cdfc7eSAndroid Build Coastguard Worker 
361*49cdfc7eSAndroid Build Coastguard Worker struct strmap Ftype_Map[] = {
362*49cdfc7eSAndroid Build Coastguard Worker 	{"regular", S_IFREG},
363*49cdfc7eSAndroid Build Coastguard Worker 	{"blk-spec", S_IFBLK},
364*49cdfc7eSAndroid Build Coastguard Worker 	{"chr-spec", S_IFCHR},
365*49cdfc7eSAndroid Build Coastguard Worker 	{NULL, 0}
366*49cdfc7eSAndroid Build Coastguard Worker };
367*49cdfc7eSAndroid Build Coastguard Worker 
368*49cdfc7eSAndroid Build Coastguard Worker /*
369*49cdfc7eSAndroid Build Coastguard Worker  * Misc declarations
370*49cdfc7eSAndroid Build Coastguard Worker  */
371*49cdfc7eSAndroid Build Coastguard Worker 
372*49cdfc7eSAndroid Build Coastguard Worker int Sds_Avail;
373*49cdfc7eSAndroid Build Coastguard Worker 
374*49cdfc7eSAndroid Build Coastguard Worker char Byte_Patterns[26] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
375*49cdfc7eSAndroid Build Coastguard Worker 	'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
376*49cdfc7eSAndroid Build Coastguard Worker 	'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
377*49cdfc7eSAndroid Build Coastguard Worker 	'Y', 'Z'
378*49cdfc7eSAndroid Build Coastguard Worker };
379*49cdfc7eSAndroid Build Coastguard Worker 
main(int argc,char ** argv)380*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char **argv)
381*49cdfc7eSAndroid Build Coastguard Worker {
382*49cdfc7eSAndroid Build Coastguard Worker 	int rseed, outfd, infinite;
383*49cdfc7eSAndroid Build Coastguard Worker 	time_t start_time;
384*49cdfc7eSAndroid Build Coastguard Worker 	struct io_req req;
385*49cdfc7eSAndroid Build Coastguard Worker 
386*49cdfc7eSAndroid Build Coastguard Worker 	umask(0);
387*49cdfc7eSAndroid Build Coastguard Worker 
388*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
389*49cdfc7eSAndroid Build Coastguard Worker 	Sds_Avail = sysconf(_SC_CRAY_SDS);
390*49cdfc7eSAndroid Build Coastguard Worker #else
391*49cdfc7eSAndroid Build Coastguard Worker 	Sds_Avail = 0;
392*49cdfc7eSAndroid Build Coastguard Worker #endif
393*49cdfc7eSAndroid Build Coastguard Worker 
394*49cdfc7eSAndroid Build Coastguard Worker 	TagName[0] = '\0';
395*49cdfc7eSAndroid Build Coastguard Worker 	parse_cmdline(argc, argv, OPTS);
396*49cdfc7eSAndroid Build Coastguard Worker 
397*49cdfc7eSAndroid Build Coastguard Worker 	/*
398*49cdfc7eSAndroid Build Coastguard Worker 	 * Initialize output descriptor.
399*49cdfc7eSAndroid Build Coastguard Worker 	 */
400*49cdfc7eSAndroid Build Coastguard Worker 	if (!p_opt) {
401*49cdfc7eSAndroid Build Coastguard Worker 		outfd = 1;
402*49cdfc7eSAndroid Build Coastguard Worker 	} else {
403*49cdfc7eSAndroid Build Coastguard Worker 		outfd = init_output();
404*49cdfc7eSAndroid Build Coastguard Worker 	}
405*49cdfc7eSAndroid Build Coastguard Worker 
406*49cdfc7eSAndroid Build Coastguard Worker 	rseed = getpid();
407*49cdfc7eSAndroid Build Coastguard Worker 	random_range_seed(rseed);	/* initialize random number generator */
408*49cdfc7eSAndroid Build Coastguard Worker 
409*49cdfc7eSAndroid Build Coastguard Worker 	/*
410*49cdfc7eSAndroid Build Coastguard Worker 	 * Print out startup information, unless we're running in quiet mode
411*49cdfc7eSAndroid Build Coastguard Worker 	 */
412*49cdfc7eSAndroid Build Coastguard Worker 	if (!q_opt)
413*49cdfc7eSAndroid Build Coastguard Worker 		startup_info(stderr, rseed);
414*49cdfc7eSAndroid Build Coastguard Worker 	{
415*49cdfc7eSAndroid Build Coastguard Worker 		struct timeval ts;
416*49cdfc7eSAndroid Build Coastguard Worker 		gettimeofday(&ts, NULL);
417*49cdfc7eSAndroid Build Coastguard Worker 		start_time = ts.tv_sec;
418*49cdfc7eSAndroid Build Coastguard Worker 	}
419*49cdfc7eSAndroid Build Coastguard Worker 	/*
420*49cdfc7eSAndroid Build Coastguard Worker 	 * While iterations (or forever if Iterations == 0) - compute an
421*49cdfc7eSAndroid Build Coastguard Worker 	 * io request, and write the structure to the output descriptor
422*49cdfc7eSAndroid Build Coastguard Worker 	 */
423*49cdfc7eSAndroid Build Coastguard Worker 
424*49cdfc7eSAndroid Build Coastguard Worker 	infinite = !Iterations;
425*49cdfc7eSAndroid Build Coastguard Worker 	struct timeval ts;
426*49cdfc7eSAndroid Build Coastguard Worker 	gettimeofday(&ts, NULL);
427*49cdfc7eSAndroid Build Coastguard Worker 	while (infinite ||
428*49cdfc7eSAndroid Build Coastguard Worker 	       (!Time_Mode && Iterations--) ||
429*49cdfc7eSAndroid Build Coastguard Worker 	       (Time_Mode && (ts.tv_sec - start_time <= Iterations))) {
430*49cdfc7eSAndroid Build Coastguard Worker 		gettimeofday(&ts, NULL);
431*49cdfc7eSAndroid Build Coastguard Worker 		memset(&req, 0, sizeof(struct io_req));
432*49cdfc7eSAndroid Build Coastguard Worker 		if (form_iorequest(&req) == -1) {
433*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr, "iogen%s:  form_iorequest() failed\n",
434*49cdfc7eSAndroid Build Coastguard Worker 				TagName);
435*49cdfc7eSAndroid Build Coastguard Worker 			continue;
436*49cdfc7eSAndroid Build Coastguard Worker 		}
437*49cdfc7eSAndroid Build Coastguard Worker 
438*49cdfc7eSAndroid Build Coastguard Worker 		req.r_magic = DOIO_MAGIC;
439*49cdfc7eSAndroid Build Coastguard Worker 		if (write(outfd, (char *)&req, sizeof(req)) == -1)
440*49cdfc7eSAndroid Build Coastguard Worker 			perror("Warning: Could not write");
441*49cdfc7eSAndroid Build Coastguard Worker 	}
442*49cdfc7eSAndroid Build Coastguard Worker 
443*49cdfc7eSAndroid Build Coastguard Worker 	exit(0);
444*49cdfc7eSAndroid Build Coastguard Worker 
445*49cdfc7eSAndroid Build Coastguard Worker }				/* main */
446*49cdfc7eSAndroid Build Coastguard Worker 
startup_info(FILE * stream,int seed)447*49cdfc7eSAndroid Build Coastguard Worker void startup_info(FILE * stream, int seed)
448*49cdfc7eSAndroid Build Coastguard Worker {
449*49cdfc7eSAndroid Build Coastguard Worker 	char *value_to_string(), *type;
450*49cdfc7eSAndroid Build Coastguard Worker 	int i;
451*49cdfc7eSAndroid Build Coastguard Worker 
452*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\n");
453*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "iogen%s starting up with the following:\n", TagName);
454*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\n");
455*49cdfc7eSAndroid Build Coastguard Worker 
456*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "Out-pipe:              %s\n",
457*49cdfc7eSAndroid Build Coastguard Worker 		p_opt ? Outpipe : "stdout");
458*49cdfc7eSAndroid Build Coastguard Worker 
459*49cdfc7eSAndroid Build Coastguard Worker 	if (Iterations) {
460*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream, "Iterations:            %d", Iterations);
461*49cdfc7eSAndroid Build Coastguard Worker 		if (Time_Mode)
462*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stream, " seconds");
463*49cdfc7eSAndroid Build Coastguard Worker 
464*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream, "\n");
465*49cdfc7eSAndroid Build Coastguard Worker 	} else {
466*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream, "Iterations:            Infinite\n");
467*49cdfc7eSAndroid Build Coastguard Worker 	}
468*49cdfc7eSAndroid Build Coastguard Worker 
469*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "Seed:                  %d\n", seed);
470*49cdfc7eSAndroid Build Coastguard Worker 
471*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "Offset-Mode:           %s\n", Offset_Mode->m_string);
472*49cdfc7eSAndroid Build Coastguard Worker 
473*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "Overlap Flag:          %s\n", o_opt ? "on" : "off");
474*49cdfc7eSAndroid Build Coastguard Worker 
475*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
476*49cdfc7eSAndroid Build Coastguard Worker 		"Mintrans:              %-11d (%d blocks)\n",
477*49cdfc7eSAndroid Build Coastguard Worker 		Mintrans, (Mintrans + BSIZE - 1) / BSIZE);
478*49cdfc7eSAndroid Build Coastguard Worker 
479*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
480*49cdfc7eSAndroid Build Coastguard Worker 		"Maxtrans:              %-11d (%d blocks)\n",
481*49cdfc7eSAndroid Build Coastguard Worker 		Maxtrans, (Maxtrans + BSIZE - 1) / BSIZE);
482*49cdfc7eSAndroid Build Coastguard Worker 
483*49cdfc7eSAndroid Build Coastguard Worker 	if (!r_opt)
484*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream,
485*49cdfc7eSAndroid Build Coastguard Worker 			"O_RAW/O_SSD Multiple:  (Determined by device)\n");
486*49cdfc7eSAndroid Build Coastguard Worker 	else
487*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream,
488*49cdfc7eSAndroid Build Coastguard Worker 			"O_RAW/O_SSD Multiple:  %-11d (%d blocks)\n",
489*49cdfc7eSAndroid Build Coastguard Worker 			Rawmult, (Rawmult + BSIZE - 1) / BSIZE);
490*49cdfc7eSAndroid Build Coastguard Worker 
491*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "Syscalls:              ");
492*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < Nsyscalls; i++)
493*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream, "%s ", Syscall_List[i]->m_string);
494*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\n");
495*49cdfc7eSAndroid Build Coastguard Worker 
496*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "Aio completion types:  ");
497*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < Naio_Strat_Types; i++)
498*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream, "%s ", Aio_Strat_List[i]->m_string);
499*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\n");
500*49cdfc7eSAndroid Build Coastguard Worker 
501*49cdfc7eSAndroid Build Coastguard Worker 	if (Fileio) {
502*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream, "Flags:                 ");
503*49cdfc7eSAndroid Build Coastguard Worker 		for (i = 0; i < Nflags; i++)
504*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stream, "%s ", Flag_List[i]->m_string);
505*49cdfc7eSAndroid Build Coastguard Worker 
506*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream, "\n");
507*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream, "\n");
508*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream, "Test Files:  \n");
509*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream, "\n");
510*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream,
511*49cdfc7eSAndroid Build Coastguard Worker 			"Path                                          Length    iou   raw iou file\n");
512*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream,
513*49cdfc7eSAndroid Build Coastguard Worker 			"                                              (bytes) (bytes) (bytes) type\n");
514*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stream,
515*49cdfc7eSAndroid Build Coastguard Worker 			"-----------------------------------------------------------------------------\n");
516*49cdfc7eSAndroid Build Coastguard Worker 
517*49cdfc7eSAndroid Build Coastguard Worker 		for (i = 0; i < Nfiles; i++) {
518*49cdfc7eSAndroid Build Coastguard Worker 			type = value_to_string(Ftype_Map, File_List[i].f_type);
519*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stream, "%-40s %12d %7d %7d %s\n",
520*49cdfc7eSAndroid Build Coastguard Worker 				File_List[i].f_path, File_List[i].f_length,
521*49cdfc7eSAndroid Build Coastguard Worker 				File_List[i].f_iou, File_List[i].f_riou, type);
522*49cdfc7eSAndroid Build Coastguard Worker 		}
523*49cdfc7eSAndroid Build Coastguard Worker 	}
524*49cdfc7eSAndroid Build Coastguard Worker }
525*49cdfc7eSAndroid Build Coastguard Worker 
526*49cdfc7eSAndroid Build Coastguard Worker /*
527*49cdfc7eSAndroid Build Coastguard Worker  * Initialize output descriptor.  If going to stdout, its easy,
528*49cdfc7eSAndroid Build Coastguard Worker  * otherwise, attempt to create a FIFO on path Outpipe.  Exit with an
529*49cdfc7eSAndroid Build Coastguard Worker  * error code if this cannot be done.
530*49cdfc7eSAndroid Build Coastguard Worker  */
init_output(void)531*49cdfc7eSAndroid Build Coastguard Worker int init_output(void)
532*49cdfc7eSAndroid Build Coastguard Worker {
533*49cdfc7eSAndroid Build Coastguard Worker 	int outfd;
534*49cdfc7eSAndroid Build Coastguard Worker 	struct stat sbuf;
535*49cdfc7eSAndroid Build Coastguard Worker 
536*49cdfc7eSAndroid Build Coastguard Worker 	if (stat(Outpipe, &sbuf) == -1) {
537*49cdfc7eSAndroid Build Coastguard Worker 		if (errno == ENOENT) {
538*49cdfc7eSAndroid Build Coastguard Worker 			if (mkfifo(Outpipe, 0666) == -1) {
539*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
540*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s:  Could not mkfifo %s:  %s\n",
541*49cdfc7eSAndroid Build Coastguard Worker 					TagName, Outpipe, SYSERR);
542*49cdfc7eSAndroid Build Coastguard Worker 				exit(2);
543*49cdfc7eSAndroid Build Coastguard Worker 			}
544*49cdfc7eSAndroid Build Coastguard Worker 		} else {
545*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
546*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  Could not stat outpipe %s:  %s\n",
547*49cdfc7eSAndroid Build Coastguard Worker 				TagName, Outpipe, SYSERR);
548*49cdfc7eSAndroid Build Coastguard Worker 			exit(2);
549*49cdfc7eSAndroid Build Coastguard Worker 		}
550*49cdfc7eSAndroid Build Coastguard Worker 	} else {
551*49cdfc7eSAndroid Build Coastguard Worker 		if (!S_ISFIFO(sbuf.st_mode)) {
552*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
553*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  Output file %s exists, but is not a FIFO\n",
554*49cdfc7eSAndroid Build Coastguard Worker 				TagName, Outpipe);
555*49cdfc7eSAndroid Build Coastguard Worker 			exit(2);
556*49cdfc7eSAndroid Build Coastguard Worker 		}
557*49cdfc7eSAndroid Build Coastguard Worker 	}
558*49cdfc7eSAndroid Build Coastguard Worker 
559*49cdfc7eSAndroid Build Coastguard Worker 	if ((outfd = open(Outpipe, O_RDWR)) == -1) {
560*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr,
561*49cdfc7eSAndroid Build Coastguard Worker 			"iogen%s:  Couldn't open outpipe %s with flags O_RDWR: %s\n",
562*49cdfc7eSAndroid Build Coastguard Worker 			TagName, Outpipe, SYSERR);
563*49cdfc7eSAndroid Build Coastguard Worker 		exit(2);
564*49cdfc7eSAndroid Build Coastguard Worker 	}
565*49cdfc7eSAndroid Build Coastguard Worker 
566*49cdfc7eSAndroid Build Coastguard Worker 	return (outfd);
567*49cdfc7eSAndroid Build Coastguard Worker }
568*49cdfc7eSAndroid Build Coastguard Worker 
569*49cdfc7eSAndroid Build Coastguard Worker /*
570*49cdfc7eSAndroid Build Coastguard Worker  * Main io generation function.  form_iorequest() selects a system call to
571*49cdfc7eSAndroid Build Coastguard Worker  * do based on cmdline arguments, and proceeds to select parameters for that
572*49cdfc7eSAndroid Build Coastguard Worker  * system call.
573*49cdfc7eSAndroid Build Coastguard Worker  *
574*49cdfc7eSAndroid Build Coastguard Worker  * Returns 0 if req is filled in with a complete doio request, otherwise
575*49cdfc7eSAndroid Build Coastguard Worker  * returns -1.
576*49cdfc7eSAndroid Build Coastguard Worker  */
577*49cdfc7eSAndroid Build Coastguard Worker 
form_iorequest(struct io_req * req)578*49cdfc7eSAndroid Build Coastguard Worker int form_iorequest(struct io_req *req)
579*49cdfc7eSAndroid Build Coastguard Worker {
580*49cdfc7eSAndroid Build Coastguard Worker 	int mult, offset = 0, length = 0, slength;
581*49cdfc7eSAndroid Build Coastguard Worker 	int minlength, maxlength, laststart, lastend;
582*49cdfc7eSAndroid Build Coastguard Worker 	int minoffset, maxoffset;
583*49cdfc7eSAndroid Build Coastguard Worker 	int maxstride, nstrides;
584*49cdfc7eSAndroid Build Coastguard Worker 	char pattern, *errp;
585*49cdfc7eSAndroid Build Coastguard Worker 	struct strmap *flags, *sc, *aio_strat;
586*49cdfc7eSAndroid Build Coastguard Worker 	struct file_info *fptr;
587*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
588*49cdfc7eSAndroid Build Coastguard Worker 	int opcode, cmd;
589*49cdfc7eSAndroid Build Coastguard Worker #endif
590*49cdfc7eSAndroid Build Coastguard Worker 
591*49cdfc7eSAndroid Build Coastguard Worker 	/*
592*49cdfc7eSAndroid Build Coastguard Worker 	 * Choose system call, flags, and file
593*49cdfc7eSAndroid Build Coastguard Worker 	 */
594*49cdfc7eSAndroid Build Coastguard Worker 
595*49cdfc7eSAndroid Build Coastguard Worker 	sc = Syscall_List[random_range(0, Nsyscalls - 1, 1, NULL)];
596*49cdfc7eSAndroid Build Coastguard Worker 	req->r_type = sc->m_value;
597*49cdfc7eSAndroid Build Coastguard Worker 
598*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
599*49cdfc7eSAndroid Build Coastguard Worker 	if (sc->m_value == LISTIO) {
600*49cdfc7eSAndroid Build Coastguard Worker 		opcode = random_range(0, 1, 1, NULL) ? LO_READ : LO_WRITE;
601*49cdfc7eSAndroid Build Coastguard Worker 		cmd = random_range(0, 1, 1, NULL) ? LC_START : LC_WAIT;
602*49cdfc7eSAndroid Build Coastguard Worker 	}
603*49cdfc7eSAndroid Build Coastguard Worker #endif
604*49cdfc7eSAndroid Build Coastguard Worker 
605*49cdfc7eSAndroid Build Coastguard Worker 	if (sc->m_flags & SY_WRITE)
606*49cdfc7eSAndroid Build Coastguard Worker 		pattern =
607*49cdfc7eSAndroid Build Coastguard Worker 		    Byte_Patterns[random_range
608*49cdfc7eSAndroid Build Coastguard Worker 				  (0, sizeof(Byte_Patterns) - 1, 1, NULL)];
609*49cdfc7eSAndroid Build Coastguard Worker 	else
610*49cdfc7eSAndroid Build Coastguard Worker 		pattern = 0;
611*49cdfc7eSAndroid Build Coastguard Worker 
612*49cdfc7eSAndroid Build Coastguard Worker #if CRAY
613*49cdfc7eSAndroid Build Coastguard Worker 	/*
614*49cdfc7eSAndroid Build Coastguard Worker 	 * If sds io, simply choose a length (possibly pattern) and return
615*49cdfc7eSAndroid Build Coastguard Worker 	 */
616*49cdfc7eSAndroid Build Coastguard Worker 
617*49cdfc7eSAndroid Build Coastguard Worker 	if (sc->m_flags & SY_SDS) {
618*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.ssread.r_nbytes =
619*49cdfc7eSAndroid Build Coastguard Worker 		    random_range(Mintrans, Maxtrans, BSIZE, NULL);
620*49cdfc7eSAndroid Build Coastguard Worker 		if (sc->m_flags & SY_WRITE)
621*49cdfc7eSAndroid Build Coastguard Worker 			req->r_data.sswrite.r_pattern = pattern;
622*49cdfc7eSAndroid Build Coastguard Worker 
623*49cdfc7eSAndroid Build Coastguard Worker 		return 0;
624*49cdfc7eSAndroid Build Coastguard Worker 	}
625*49cdfc7eSAndroid Build Coastguard Worker #endif
626*49cdfc7eSAndroid Build Coastguard Worker 
627*49cdfc7eSAndroid Build Coastguard Worker 	/*
628*49cdfc7eSAndroid Build Coastguard Worker 	 * otherwise, we're doing file io.  Choose starting offset, length,
629*49cdfc7eSAndroid Build Coastguard Worker 	 * open flags, and possibly a pattern (for write/writea).
630*49cdfc7eSAndroid Build Coastguard Worker 	 */
631*49cdfc7eSAndroid Build Coastguard Worker 
632*49cdfc7eSAndroid Build Coastguard Worker 	fptr = &File_List[random_range(0, Nfiles - 1, 1, NULL)];
633*49cdfc7eSAndroid Build Coastguard Worker 	flags = Flag_List[random_range(0, Nflags - 1, 1, NULL)];
634*49cdfc7eSAndroid Build Coastguard Worker 
635*49cdfc7eSAndroid Build Coastguard Worker 	/*
636*49cdfc7eSAndroid Build Coastguard Worker 	 * Choose offset/length multiple.  IO going to a device, or regular
637*49cdfc7eSAndroid Build Coastguard Worker 	 * IO that is O_RAW or O_SSD must be aligned on the file r_iou.  Otherwise
638*49cdfc7eSAndroid Build Coastguard Worker 	 * it must be aligned on the regular iou (normally 1).
639*49cdfc7eSAndroid Build Coastguard Worker 	 */
640*49cdfc7eSAndroid Build Coastguard Worker 
641*49cdfc7eSAndroid Build Coastguard Worker 	if (fptr->f_type == S_IFREG && (flags->m_flags & FLG_RAW))
642*49cdfc7eSAndroid Build Coastguard Worker 		mult = fptr->f_riou;
643*49cdfc7eSAndroid Build Coastguard Worker 	else
644*49cdfc7eSAndroid Build Coastguard Worker 		mult = fptr->f_iou;
645*49cdfc7eSAndroid Build Coastguard Worker 
646*49cdfc7eSAndroid Build Coastguard Worker 	/*
647*49cdfc7eSAndroid Build Coastguard Worker 	 * Choose offset and length.  Both must be a multiple of mult
648*49cdfc7eSAndroid Build Coastguard Worker 	 */
649*49cdfc7eSAndroid Build Coastguard Worker 
650*49cdfc7eSAndroid Build Coastguard Worker 	/*
651*49cdfc7eSAndroid Build Coastguard Worker 	 * Choose length first - it must be a multiple of mult
652*49cdfc7eSAndroid Build Coastguard Worker 	 */
653*49cdfc7eSAndroid Build Coastguard Worker 
654*49cdfc7eSAndroid Build Coastguard Worker 	laststart = fptr->f_lastoffset;
655*49cdfc7eSAndroid Build Coastguard Worker 	lastend = fptr->f_lastoffset + fptr->f_lastlength - 1;
656*49cdfc7eSAndroid Build Coastguard Worker 
657*49cdfc7eSAndroid Build Coastguard Worker 	minlength = (Mintrans > mult) ? Mintrans : mult;
658*49cdfc7eSAndroid Build Coastguard Worker 
659*49cdfc7eSAndroid Build Coastguard Worker 	switch (Offset_Mode->m_value) {
660*49cdfc7eSAndroid Build Coastguard Worker 	case M_SEQUENTIAL:
661*49cdfc7eSAndroid Build Coastguard Worker 		if (o_opt && lastend > laststart)
662*49cdfc7eSAndroid Build Coastguard Worker 			offset = random_range(laststart, lastend, 1, NULL);
663*49cdfc7eSAndroid Build Coastguard Worker 		else
664*49cdfc7eSAndroid Build Coastguard Worker 			offset = lastend + 1;
665*49cdfc7eSAndroid Build Coastguard Worker 		if (offset && (offset % mult))
666*49cdfc7eSAndroid Build Coastguard Worker 			offset += mult - (offset % mult);
667*49cdfc7eSAndroid Build Coastguard Worker 
668*49cdfc7eSAndroid Build Coastguard Worker 		if (minlength > fptr->f_length - offset)
669*49cdfc7eSAndroid Build Coastguard Worker 			offset = 0;
670*49cdfc7eSAndroid Build Coastguard Worker 
671*49cdfc7eSAndroid Build Coastguard Worker 		maxlength = fptr->f_length - offset;
672*49cdfc7eSAndroid Build Coastguard Worker 		if (maxlength > Maxtrans)
673*49cdfc7eSAndroid Build Coastguard Worker 			maxlength = Maxtrans;
674*49cdfc7eSAndroid Build Coastguard Worker 
675*49cdfc7eSAndroid Build Coastguard Worker 		length = random_range(minlength, maxlength, mult, &errp);
676*49cdfc7eSAndroid Build Coastguard Worker 		if (errp != NULL) {
677*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
678*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  random_range(%d, %d, %d) failed\n",
679*49cdfc7eSAndroid Build Coastguard Worker 				TagName, minlength, maxlength, mult);
680*49cdfc7eSAndroid Build Coastguard Worker 			return -1;
681*49cdfc7eSAndroid Build Coastguard Worker 		}
682*49cdfc7eSAndroid Build Coastguard Worker 
683*49cdfc7eSAndroid Build Coastguard Worker 		break;
684*49cdfc7eSAndroid Build Coastguard Worker 
685*49cdfc7eSAndroid Build Coastguard Worker 	case M_REVERSE:
686*49cdfc7eSAndroid Build Coastguard Worker 		maxlength = laststart;
687*49cdfc7eSAndroid Build Coastguard Worker 
688*49cdfc7eSAndroid Build Coastguard Worker 		if (maxlength > Maxtrans)
689*49cdfc7eSAndroid Build Coastguard Worker 			maxlength = Maxtrans;
690*49cdfc7eSAndroid Build Coastguard Worker 
691*49cdfc7eSAndroid Build Coastguard Worker 		if (minlength > maxlength) {
692*49cdfc7eSAndroid Build Coastguard Worker 			laststart = fptr->f_length;
693*49cdfc7eSAndroid Build Coastguard Worker 			lastend = fptr->f_length;
694*49cdfc7eSAndroid Build Coastguard Worker 			maxlength = Maxtrans;
695*49cdfc7eSAndroid Build Coastguard Worker 		}
696*49cdfc7eSAndroid Build Coastguard Worker 
697*49cdfc7eSAndroid Build Coastguard Worker 		length = random_range(minlength, maxlength, mult, &errp);
698*49cdfc7eSAndroid Build Coastguard Worker 		if (errp != NULL) {
699*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
700*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  random_range(%d, %d, %d) failed\n",
701*49cdfc7eSAndroid Build Coastguard Worker 				TagName, minlength, maxlength, mult);
702*49cdfc7eSAndroid Build Coastguard Worker 			return -1;
703*49cdfc7eSAndroid Build Coastguard Worker 		}
704*49cdfc7eSAndroid Build Coastguard Worker 
705*49cdfc7eSAndroid Build Coastguard Worker 		offset = laststart - length;
706*49cdfc7eSAndroid Build Coastguard Worker 
707*49cdfc7eSAndroid Build Coastguard Worker 		if (o_opt && lastend > laststart)
708*49cdfc7eSAndroid Build Coastguard Worker 			offset += random_range(1, lastend - laststart, 1, NULL);
709*49cdfc7eSAndroid Build Coastguard Worker 
710*49cdfc7eSAndroid Build Coastguard Worker 		if (offset && (offset % mult))
711*49cdfc7eSAndroid Build Coastguard Worker 			offset -= offset % mult;
712*49cdfc7eSAndroid Build Coastguard Worker 
713*49cdfc7eSAndroid Build Coastguard Worker 		break;
714*49cdfc7eSAndroid Build Coastguard Worker 
715*49cdfc7eSAndroid Build Coastguard Worker 	case M_RANDOM:
716*49cdfc7eSAndroid Build Coastguard Worker 		length = random_range(Mintrans, Maxtrans, mult, NULL);
717*49cdfc7eSAndroid Build Coastguard Worker 
718*49cdfc7eSAndroid Build Coastguard Worker 		if (o_opt && lastend > laststart) {
719*49cdfc7eSAndroid Build Coastguard Worker 			minoffset = laststart - length + 1;
720*49cdfc7eSAndroid Build Coastguard Worker 			if (minoffset < 0) {
721*49cdfc7eSAndroid Build Coastguard Worker 				minoffset = 0;
722*49cdfc7eSAndroid Build Coastguard Worker 			}
723*49cdfc7eSAndroid Build Coastguard Worker 
724*49cdfc7eSAndroid Build Coastguard Worker 			if (lastend + length > fptr->f_length) {
725*49cdfc7eSAndroid Build Coastguard Worker 				maxoffset = fptr->f_length - length;
726*49cdfc7eSAndroid Build Coastguard Worker 			} else {
727*49cdfc7eSAndroid Build Coastguard Worker 				maxoffset = lastend;
728*49cdfc7eSAndroid Build Coastguard Worker 			}
729*49cdfc7eSAndroid Build Coastguard Worker 		} else {
730*49cdfc7eSAndroid Build Coastguard Worker 			minoffset = 0;
731*49cdfc7eSAndroid Build Coastguard Worker 			maxoffset = fptr->f_length - length;
732*49cdfc7eSAndroid Build Coastguard Worker 		}
733*49cdfc7eSAndroid Build Coastguard Worker 
734*49cdfc7eSAndroid Build Coastguard Worker 		if (minoffset < 0)
735*49cdfc7eSAndroid Build Coastguard Worker 			minoffset = 0;
736*49cdfc7eSAndroid Build Coastguard Worker 
737*49cdfc7eSAndroid Build Coastguard Worker 		offset = random_range(minoffset, maxoffset, mult, &errp);
738*49cdfc7eSAndroid Build Coastguard Worker 		if (errp != NULL) {
739*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
740*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  random_range(%d, %d, %d) failed\n",
741*49cdfc7eSAndroid Build Coastguard Worker 				TagName, minoffset, maxoffset, mult);
742*49cdfc7eSAndroid Build Coastguard Worker 			return -1;
743*49cdfc7eSAndroid Build Coastguard Worker 		}
744*49cdfc7eSAndroid Build Coastguard Worker 	}
745*49cdfc7eSAndroid Build Coastguard Worker 
746*49cdfc7eSAndroid Build Coastguard Worker 	fptr->f_lastoffset = offset;
747*49cdfc7eSAndroid Build Coastguard Worker 	fptr->f_lastlength = length;
748*49cdfc7eSAndroid Build Coastguard Worker 
749*49cdfc7eSAndroid Build Coastguard Worker 	/*
750*49cdfc7eSAndroid Build Coastguard Worker 	 * Choose an async io completion strategy if necessary
751*49cdfc7eSAndroid Build Coastguard Worker 	 */
752*49cdfc7eSAndroid Build Coastguard Worker 	if (sc->m_flags & SY_ASYNC)
753*49cdfc7eSAndroid Build Coastguard Worker 		aio_strat = Aio_Strat_List[random_range(0, Naio_Strat_Types - 1,
754*49cdfc7eSAndroid Build Coastguard Worker 							1, NULL)];
755*49cdfc7eSAndroid Build Coastguard Worker 	else
756*49cdfc7eSAndroid Build Coastguard Worker 		aio_strat = NULL;
757*49cdfc7eSAndroid Build Coastguard Worker 
758*49cdfc7eSAndroid Build Coastguard Worker 	/*
759*49cdfc7eSAndroid Build Coastguard Worker 	 * fill in specific syscall record data
760*49cdfc7eSAndroid Build Coastguard Worker 	 */
761*49cdfc7eSAndroid Build Coastguard Worker 	switch (sc->m_value) {
762*49cdfc7eSAndroid Build Coastguard Worker 	case READ:
763*49cdfc7eSAndroid Build Coastguard Worker 	case READA:
764*49cdfc7eSAndroid Build Coastguard Worker 		strcpy(req->r_data.read.r_file, fptr->f_path);
765*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.read.r_oflags = O_RDONLY | flags->m_value;
766*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.read.r_offset = offset;
767*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.read.r_nbytes = length;
768*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.read.r_uflags =
769*49cdfc7eSAndroid Build Coastguard Worker 		    (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
770*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.read.r_aio_strat =
771*49cdfc7eSAndroid Build Coastguard Worker 		    (aio_strat == NULL) ? 0 : aio_strat->m_value;
772*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.read.r_nstrides = 1;
773*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.read.r_nent = 1;
774*49cdfc7eSAndroid Build Coastguard Worker 		break;
775*49cdfc7eSAndroid Build Coastguard Worker 
776*49cdfc7eSAndroid Build Coastguard Worker 	case WRITE:
777*49cdfc7eSAndroid Build Coastguard Worker 	case WRITEA:
778*49cdfc7eSAndroid Build Coastguard Worker 		strcpy(req->r_data.write.r_file, fptr->f_path);
779*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.write.r_oflags = O_WRONLY | flags->m_value;
780*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.write.r_offset = offset;
781*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.write.r_nbytes = length;
782*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.write.r_pattern = pattern;
783*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.write.r_uflags =
784*49cdfc7eSAndroid Build Coastguard Worker 		    (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
785*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.write.r_aio_strat =
786*49cdfc7eSAndroid Build Coastguard Worker 		    (aio_strat == NULL) ? 0 : aio_strat->m_value;
787*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.write.r_nstrides = 1;
788*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.write.r_nent = 1;
789*49cdfc7eSAndroid Build Coastguard Worker 		break;
790*49cdfc7eSAndroid Build Coastguard Worker 
791*49cdfc7eSAndroid Build Coastguard Worker 	case READV:
792*49cdfc7eSAndroid Build Coastguard Worker 	case AREAD:
793*49cdfc7eSAndroid Build Coastguard Worker 	case PREAD:
794*49cdfc7eSAndroid Build Coastguard Worker 	case WRITEV:
795*49cdfc7eSAndroid Build Coastguard Worker 	case AWRITE:
796*49cdfc7eSAndroid Build Coastguard Worker 	case PWRITE:
797*49cdfc7eSAndroid Build Coastguard Worker 
798*49cdfc7eSAndroid Build Coastguard Worker 	case LREAD:
799*49cdfc7eSAndroid Build Coastguard Worker 	case LREADA:
800*49cdfc7eSAndroid Build Coastguard Worker 	case LWRITE:
801*49cdfc7eSAndroid Build Coastguard Worker 	case LWRITEA:
802*49cdfc7eSAndroid Build Coastguard Worker 
803*49cdfc7eSAndroid Build Coastguard Worker 	case RESVSP:
804*49cdfc7eSAndroid Build Coastguard Worker 	case UNRESVSP:
805*49cdfc7eSAndroid Build Coastguard Worker 	case DFFSYNC:
806*49cdfc7eSAndroid Build Coastguard Worker 	case FSYNC2:
807*49cdfc7eSAndroid Build Coastguard Worker 	case FDATASYNC:
808*49cdfc7eSAndroid Build Coastguard Worker 
809*49cdfc7eSAndroid Build Coastguard Worker 		strcpy(req->r_data.io.r_file, fptr->f_path);
810*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_oflags =
811*49cdfc7eSAndroid Build Coastguard Worker 		    ((sc->m_flags & SY_WRITE) ? O_WRONLY : O_RDONLY) | flags->
812*49cdfc7eSAndroid Build Coastguard Worker 		    m_value;
813*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_offset = offset;
814*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_nbytes = length;
815*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_pattern = pattern;
816*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_uflags =
817*49cdfc7eSAndroid Build Coastguard Worker 		    (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
818*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_aio_strat =
819*49cdfc7eSAndroid Build Coastguard Worker 		    (aio_strat == NULL) ? 0 : aio_strat->m_value;
820*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_nstrides = 1;
821*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_nent = 1;
822*49cdfc7eSAndroid Build Coastguard Worker 		break;
823*49cdfc7eSAndroid Build Coastguard Worker 
824*49cdfc7eSAndroid Build Coastguard Worker 	case MMAPR:
825*49cdfc7eSAndroid Build Coastguard Worker 	case MMAPW:
826*49cdfc7eSAndroid Build Coastguard Worker 		strcpy(req->r_data.io.r_file, fptr->f_path);
827*49cdfc7eSAndroid Build Coastguard Worker 		/* a subtle "feature" of mmap: a write-map requires
828*49cdfc7eSAndroid Build Coastguard Worker 		   the file open read/write */
829*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_oflags =
830*49cdfc7eSAndroid Build Coastguard Worker 		    ((sc->m_flags & SY_WRITE) ? O_RDWR : O_RDONLY) | flags->
831*49cdfc7eSAndroid Build Coastguard Worker 		    m_value;
832*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_offset = offset;
833*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_nbytes = length;
834*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_pattern = pattern;
835*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_uflags =
836*49cdfc7eSAndroid Build Coastguard Worker 		    (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
837*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_aio_strat =
838*49cdfc7eSAndroid Build Coastguard Worker 		    (aio_strat == NULL) ? 0 : aio_strat->m_value;
839*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_nstrides = 1;
840*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_nent = 1;
841*49cdfc7eSAndroid Build Coastguard Worker 		break;
842*49cdfc7eSAndroid Build Coastguard Worker 
843*49cdfc7eSAndroid Build Coastguard Worker 	case LSREAD:
844*49cdfc7eSAndroid Build Coastguard Worker 	case LSREADA:
845*49cdfc7eSAndroid Build Coastguard Worker 	case LEREAD:
846*49cdfc7eSAndroid Build Coastguard Worker 	case LEREADA:
847*49cdfc7eSAndroid Build Coastguard Worker 	case LSWRITE:
848*49cdfc7eSAndroid Build Coastguard Worker 	case LSWRITEA:
849*49cdfc7eSAndroid Build Coastguard Worker 	case LEWRITE:
850*49cdfc7eSAndroid Build Coastguard Worker 	case LEWRITEA:
851*49cdfc7eSAndroid Build Coastguard Worker 		/* multi-strided */
852*49cdfc7eSAndroid Build Coastguard Worker 		strcpy(req->r_data.io.r_file, fptr->f_path);
853*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_oflags =
854*49cdfc7eSAndroid Build Coastguard Worker 		    ((sc->m_flags & SY_WRITE) ? O_WRONLY : O_RDONLY) | flags->
855*49cdfc7eSAndroid Build Coastguard Worker 		    m_value;
856*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_offset = offset;
857*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_uflags =
858*49cdfc7eSAndroid Build Coastguard Worker 		    (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
859*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_aio_strat =
860*49cdfc7eSAndroid Build Coastguard Worker 		    (aio_strat == NULL) ? 0 : aio_strat->m_value;
861*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_pattern = pattern;
862*49cdfc7eSAndroid Build Coastguard Worker 
863*49cdfc7eSAndroid Build Coastguard Worker 		/* multi-strided request...
864*49cdfc7eSAndroid Build Coastguard Worker 		 *  random number of strides (1...MaxStrides)
865*49cdfc7eSAndroid Build Coastguard Worker 		 *  length of stride must be > minlength
866*49cdfc7eSAndroid Build Coastguard Worker 		 *  length of stride must be % mult
867*49cdfc7eSAndroid Build Coastguard Worker 		 *
868*49cdfc7eSAndroid Build Coastguard Worker 		 * maxstrides = min(length / mult, overall.max#strides)
869*49cdfc7eSAndroid Build Coastguard Worker 		 * nstrides = random #
870*49cdfc7eSAndroid Build Coastguard Worker 		 * while (length / nstrides < minlength)
871*49cdfc7eSAndroid Build Coastguard Worker 		 *      nstrides = new random #
872*49cdfc7eSAndroid Build Coastguard Worker 		 */
873*49cdfc7eSAndroid Build Coastguard Worker 		maxstride = length / mult;
874*49cdfc7eSAndroid Build Coastguard Worker 		if (maxstride > Maxstrides)
875*49cdfc7eSAndroid Build Coastguard Worker 			maxstride = Maxstrides;
876*49cdfc7eSAndroid Build Coastguard Worker 
877*49cdfc7eSAndroid Build Coastguard Worker 		if (!Minstrides)
878*49cdfc7eSAndroid Build Coastguard Worker 			Minstrides = 1;
879*49cdfc7eSAndroid Build Coastguard Worker 		nstrides = random_range(Minstrides, maxstride, 1, &errp);
880*49cdfc7eSAndroid Build Coastguard Worker 		if (errp != NULL) {
881*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
882*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  random_range(%d, %d, %d) failed\n",
883*49cdfc7eSAndroid Build Coastguard Worker 				TagName, Minstrides, maxstride, 1);
884*49cdfc7eSAndroid Build Coastguard Worker 			return -1;
885*49cdfc7eSAndroid Build Coastguard Worker 		}
886*49cdfc7eSAndroid Build Coastguard Worker 
887*49cdfc7eSAndroid Build Coastguard Worker 		slength = length / nstrides;
888*49cdfc7eSAndroid Build Coastguard Worker 		if (slength % mult != 0) {
889*49cdfc7eSAndroid Build Coastguard Worker 			if (mult > slength) {
890*49cdfc7eSAndroid Build Coastguard Worker 				slength = mult;
891*49cdfc7eSAndroid Build Coastguard Worker 			} else {
892*49cdfc7eSAndroid Build Coastguard Worker 				slength -= slength % mult;
893*49cdfc7eSAndroid Build Coastguard Worker 			}
894*49cdfc7eSAndroid Build Coastguard Worker 			nstrides = length / slength;
895*49cdfc7eSAndroid Build Coastguard Worker 			if (nstrides > Maxstrides)
896*49cdfc7eSAndroid Build Coastguard Worker 				nstrides = Maxstrides;
897*49cdfc7eSAndroid Build Coastguard Worker 		}
898*49cdfc7eSAndroid Build Coastguard Worker 
899*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.io.r_nbytes = slength;
900*49cdfc7eSAndroid Build Coastguard Worker 		if (sc->m_flags & SY_NENT) {
901*49cdfc7eSAndroid Build Coastguard Worker 			req->r_data.io.r_nstrides = 1;
902*49cdfc7eSAndroid Build Coastguard Worker 			req->r_data.io.r_nent = nstrides;
903*49cdfc7eSAndroid Build Coastguard Worker 		} else {
904*49cdfc7eSAndroid Build Coastguard Worker 			req->r_data.io.r_nstrides = nstrides;
905*49cdfc7eSAndroid Build Coastguard Worker 			req->r_data.io.r_nent = 1;
906*49cdfc7eSAndroid Build Coastguard Worker 		}
907*49cdfc7eSAndroid Build Coastguard Worker 		break;
908*49cdfc7eSAndroid Build Coastguard Worker 
909*49cdfc7eSAndroid Build Coastguard Worker 	case LISTIO:
910*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
911*49cdfc7eSAndroid Build Coastguard Worker 		strcpy(req->r_data.listio.r_file, fptr->f_path);
912*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.listio.r_offset = offset;
913*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.listio.r_cmd = cmd;
914*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.listio.r_aio_strat =
915*49cdfc7eSAndroid Build Coastguard Worker 		    (aio_strat == NULL) ? 0 : aio_strat->m_value;
916*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.listio.r_filestride = 0;
917*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.listio.r_memstride = 0;
918*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.listio.r_opcode = opcode;
919*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.listio.r_nstrides = 1;
920*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.listio.r_nbytes = length;
921*49cdfc7eSAndroid Build Coastguard Worker 		req->r_data.listio.r_uflags =
922*49cdfc7eSAndroid Build Coastguard Worker 		    (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
923*49cdfc7eSAndroid Build Coastguard Worker 
924*49cdfc7eSAndroid Build Coastguard Worker 		if (opcode == LO_WRITE) {
925*49cdfc7eSAndroid Build Coastguard Worker 			req->r_data.listio.r_pattern = pattern;
926*49cdfc7eSAndroid Build Coastguard Worker 			req->r_data.listio.r_oflags = O_WRONLY | flags->m_value;
927*49cdfc7eSAndroid Build Coastguard Worker 		} else {
928*49cdfc7eSAndroid Build Coastguard Worker 			req->r_data.listio.r_oflags = O_RDONLY | flags->m_value;
929*49cdfc7eSAndroid Build Coastguard Worker 		}
930*49cdfc7eSAndroid Build Coastguard Worker #endif
931*49cdfc7eSAndroid Build Coastguard Worker 		break;
932*49cdfc7eSAndroid Build Coastguard Worker 	}
933*49cdfc7eSAndroid Build Coastguard Worker 
934*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
935*49cdfc7eSAndroid Build Coastguard Worker }
936*49cdfc7eSAndroid Build Coastguard Worker 
937*49cdfc7eSAndroid Build Coastguard Worker /*
938*49cdfc7eSAndroid Build Coastguard Worker  * Get information about a file that iogen uses to choose io length and
939*49cdfc7eSAndroid Build Coastguard Worker  * offset.  Information gathered is file length, iounit, and raw iounit.
940*49cdfc7eSAndroid Build Coastguard Worker  * For regurlar files, iounit is 1, and raw iounit is the iounit of the
941*49cdfc7eSAndroid Build Coastguard Worker  * device on which the file resides.  For block/character special files
942*49cdfc7eSAndroid Build Coastguard Worker  * the iounit and raw iounit are both the iounit of the device.
943*49cdfc7eSAndroid Build Coastguard Worker  *
944*49cdfc7eSAndroid Build Coastguard Worker  * Note:	buffered and osync io must be iounit aligned
945*49cdfc7eSAndroid Build Coastguard Worker  *		raw and ossd io must be raw iounit aligned
946*49cdfc7eSAndroid Build Coastguard Worker  */
947*49cdfc7eSAndroid Build Coastguard Worker 
get_file_info(struct file_info * rec)948*49cdfc7eSAndroid Build Coastguard Worker int get_file_info(struct file_info *rec)
949*49cdfc7eSAndroid Build Coastguard Worker {
950*49cdfc7eSAndroid Build Coastguard Worker 	struct stat sbuf;
951*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
952*49cdfc7eSAndroid Build Coastguard Worker 	struct lk_device_info dinfo;
953*49cdfc7eSAndroid Build Coastguard Worker #endif
954*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
955*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
956*49cdfc7eSAndroid Build Coastguard Worker 	struct dioattr finfo;
957*49cdfc7eSAndroid Build Coastguard Worker #endif
958*49cdfc7eSAndroid Build Coastguard Worker 
959*49cdfc7eSAndroid Build Coastguard Worker 	/*
960*49cdfc7eSAndroid Build Coastguard Worker 	 * Figure out if the files is regular, block or character special.  Any
961*49cdfc7eSAndroid Build Coastguard Worker 	 * other type is an error.
962*49cdfc7eSAndroid Build Coastguard Worker 	 */
963*49cdfc7eSAndroid Build Coastguard Worker 
964*49cdfc7eSAndroid Build Coastguard Worker 	if (stat(rec->f_path, &sbuf) == -1) {
965*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr,
966*49cdfc7eSAndroid Build Coastguard Worker 			"iogen%s: get_file_info():  Could not stat() %s:  %s\n",
967*49cdfc7eSAndroid Build Coastguard Worker 			TagName, rec->f_path, SYSERR);
968*49cdfc7eSAndroid Build Coastguard Worker 		return -1;
969*49cdfc7eSAndroid Build Coastguard Worker 	}
970*49cdfc7eSAndroid Build Coastguard Worker #if _CRAY2
971*49cdfc7eSAndroid Build Coastguard Worker 	if ((!S_ISREG(sbuf.st_mode)) || strncmp(rec->f_path, "/dev/", 5) == 0) {
972*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr,
973*49cdfc7eSAndroid Build Coastguard Worker 			"iogen%s:  device level io not supported on cray2\n",
974*49cdfc7eSAndroid Build Coastguard Worker 			TagName);
975*49cdfc7eSAndroid Build Coastguard Worker 		return -1;
976*49cdfc7eSAndroid Build Coastguard Worker 	}
977*49cdfc7eSAndroid Build Coastguard Worker #endif
978*49cdfc7eSAndroid Build Coastguard Worker 
979*49cdfc7eSAndroid Build Coastguard Worker 	rec->f_type = sbuf.st_mode & S_IFMT;
980*49cdfc7eSAndroid Build Coastguard Worker 
981*49cdfc7eSAndroid Build Coastguard Worker 	/*
982*49cdfc7eSAndroid Build Coastguard Worker 	 * If regular, iou is 1, and we must figure out the device on
983*49cdfc7eSAndroid Build Coastguard Worker 	 * which the file resides.  riou is the iou (logical sector size) of
984*49cdfc7eSAndroid Build Coastguard Worker 	 * this device.
985*49cdfc7eSAndroid Build Coastguard Worker 	 */
986*49cdfc7eSAndroid Build Coastguard Worker 
987*49cdfc7eSAndroid Build Coastguard Worker 	if (S_ISREG(sbuf.st_mode)) {
988*49cdfc7eSAndroid Build Coastguard Worker 		rec->f_iou = 1;
989*49cdfc7eSAndroid Build Coastguard Worker 		rec->f_length = sbuf.st_size;
990*49cdfc7eSAndroid Build Coastguard Worker 
991*49cdfc7eSAndroid Build Coastguard Worker 		/*
992*49cdfc7eSAndroid Build Coastguard Worker 		 * If -r used, take Rawmult as the raw/ssd io multiple.  Otherwise
993*49cdfc7eSAndroid Build Coastguard Worker 		 * attempt to determine it by looking at the device the file
994*49cdfc7eSAndroid Build Coastguard Worker 		 * resides on.
995*49cdfc7eSAndroid Build Coastguard Worker 		 */
996*49cdfc7eSAndroid Build Coastguard Worker 
997*49cdfc7eSAndroid Build Coastguard Worker 		if (r_opt) {
998*49cdfc7eSAndroid Build Coastguard Worker 			rec->f_riou = Rawmult;
999*49cdfc7eSAndroid Build Coastguard Worker 			return 0;
1000*49cdfc7eSAndroid Build Coastguard Worker 		}
1001*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
1002*49cdfc7eSAndroid Build Coastguard Worker 		if (lk_rawdev(rec->f_path, dinfo.path, sizeof(dinfo.path), 0) ==
1003*49cdfc7eSAndroid Build Coastguard Worker 		    -1)
1004*49cdfc7eSAndroid Build Coastguard Worker 			return -1;
1005*49cdfc7eSAndroid Build Coastguard Worker 
1006*49cdfc7eSAndroid Build Coastguard Worker 		if (lk_devinfo(&dinfo, 0) == -1) {
1007*49cdfc7eSAndroid Build Coastguard Worker 			/* can't get raw I/O unit -- use stat to fudge it */
1008*49cdfc7eSAndroid Build Coastguard Worker 			rec->f_riou = sbuf.st_blksize;
1009*49cdfc7eSAndroid Build Coastguard Worker 		} else {
1010*49cdfc7eSAndroid Build Coastguard Worker 			rec->f_riou = ctob(dinfo.iou);
1011*49cdfc7eSAndroid Build Coastguard Worker 		}
1012*49cdfc7eSAndroid Build Coastguard Worker #endif
1013*49cdfc7eSAndroid Build Coastguard Worker #ifdef linux
1014*49cdfc7eSAndroid Build Coastguard Worker 		rec->f_riou = BSIZE;
1015*49cdfc7eSAndroid Build Coastguard Worker #endif
1016*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
1017*49cdfc7eSAndroid Build Coastguard Worker 		if ((fd = open(rec->f_path, O_RDWR | O_DIRECT, 0)) != -1) {
1018*49cdfc7eSAndroid Build Coastguard Worker 			if (fcntl(fd, F_DIOINFO, &finfo) != -1) {
1019*49cdfc7eSAndroid Build Coastguard Worker 				rec->f_riou = finfo.d_miniosz;
1020*49cdfc7eSAndroid Build Coastguard Worker 			} else {
1021*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1022*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s: Error %s (%d) getting direct I/O info of file %s\n",
1023*49cdfc7eSAndroid Build Coastguard Worker 					TagName, strerror(errno), errno,
1024*49cdfc7eSAndroid Build Coastguard Worker 					rec->f_path);
1025*49cdfc7eSAndroid Build Coastguard Worker 			}
1026*49cdfc7eSAndroid Build Coastguard Worker 			close(fd);
1027*49cdfc7eSAndroid Build Coastguard Worker 		} else {
1028*49cdfc7eSAndroid Build Coastguard Worker 			rec->f_riou = BBSIZE;
1029*49cdfc7eSAndroid Build Coastguard Worker 		}
1030*49cdfc7eSAndroid Build Coastguard Worker #endif /* SGI */
1031*49cdfc7eSAndroid Build Coastguard Worker 
1032*49cdfc7eSAndroid Build Coastguard Worker 	} else {
1033*49cdfc7eSAndroid Build Coastguard Worker 
1034*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
1035*49cdfc7eSAndroid Build Coastguard Worker 		/*
1036*49cdfc7eSAndroid Build Coastguard Worker 		 * Otherwise, file is a device.  Use lk_devinfo() to get its logical
1037*49cdfc7eSAndroid Build Coastguard Worker 		 * sector size.  This is the iou and riou
1038*49cdfc7eSAndroid Build Coastguard Worker 		 */
1039*49cdfc7eSAndroid Build Coastguard Worker 
1040*49cdfc7eSAndroid Build Coastguard Worker 		strcpy(dinfo.path, rec->f_path);
1041*49cdfc7eSAndroid Build Coastguard Worker 
1042*49cdfc7eSAndroid Build Coastguard Worker 		if (lk_devinfo(&dinfo, 0) == -1) {
1043*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr, "iogen%s: %s:  %s\n", TagName,
1044*49cdfc7eSAndroid Build Coastguard Worker 				Lk_err_func, Lk_err_mesg);
1045*49cdfc7eSAndroid Build Coastguard Worker 			return -1;
1046*49cdfc7eSAndroid Build Coastguard Worker 		}
1047*49cdfc7eSAndroid Build Coastguard Worker 
1048*49cdfc7eSAndroid Build Coastguard Worker 		rec->f_iou = ctob(dinfo.iou);
1049*49cdfc7eSAndroid Build Coastguard Worker 		rec->f_riou = ctob(dinfo.iou);
1050*49cdfc7eSAndroid Build Coastguard Worker 		rec->f_length = ctob(dinfo.length);
1051*49cdfc7eSAndroid Build Coastguard Worker #else
1052*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
1053*49cdfc7eSAndroid Build Coastguard Worker 		rec->f_riou = BBSIZE;
1054*49cdfc7eSAndroid Build Coastguard Worker 		rec->f_length = BBSIZE;
1055*49cdfc7eSAndroid Build Coastguard Worker #else
1056*49cdfc7eSAndroid Build Coastguard Worker 		rec->f_riou = BSIZE;
1057*49cdfc7eSAndroid Build Coastguard Worker 		rec->f_length = BSIZE;
1058*49cdfc7eSAndroid Build Coastguard Worker #endif /* sgi */
1059*49cdfc7eSAndroid Build Coastguard Worker #endif /* CRAY */
1060*49cdfc7eSAndroid Build Coastguard Worker 	}
1061*49cdfc7eSAndroid Build Coastguard Worker 
1062*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
1063*49cdfc7eSAndroid Build Coastguard Worker }
1064*49cdfc7eSAndroid Build Coastguard Worker 
1065*49cdfc7eSAndroid Build Coastguard Worker /*
1066*49cdfc7eSAndroid Build Coastguard Worker  * Create file path as nbytes long.  If path exists, the file will either be
1067*49cdfc7eSAndroid Build Coastguard Worker  * extended or truncated to be nbytes long.  Returns final size of file,
1068*49cdfc7eSAndroid Build Coastguard Worker  * or -1 if there was a failure.
1069*49cdfc7eSAndroid Build Coastguard Worker  */
1070*49cdfc7eSAndroid Build Coastguard Worker 
create_file(char * path,int nbytes)1071*49cdfc7eSAndroid Build Coastguard Worker int create_file(char *path, int nbytes)
1072*49cdfc7eSAndroid Build Coastguard Worker {
1073*49cdfc7eSAndroid Build Coastguard Worker 	int fd, rval;
1074*49cdfc7eSAndroid Build Coastguard Worker 	char c;
1075*49cdfc7eSAndroid Build Coastguard Worker 	struct stat sbuf;
1076*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
1077*49cdfc7eSAndroid Build Coastguard Worker 	int nb;
1078*49cdfc7eSAndroid Build Coastguard Worker 	struct flock f;
1079*49cdfc7eSAndroid Build Coastguard Worker 	struct fsxattr xattr;
1080*49cdfc7eSAndroid Build Coastguard Worker 	struct dioattr finfo;
1081*49cdfc7eSAndroid Build Coastguard Worker 	char *b, *buf;
1082*49cdfc7eSAndroid Build Coastguard Worker #endif
1083*49cdfc7eSAndroid Build Coastguard Worker 
1084*49cdfc7eSAndroid Build Coastguard Worker 	errno = 0;
1085*49cdfc7eSAndroid Build Coastguard Worker 	rval = stat(path, &sbuf);
1086*49cdfc7eSAndroid Build Coastguard Worker 
1087*49cdfc7eSAndroid Build Coastguard Worker 	if (rval == -1) {
1088*49cdfc7eSAndroid Build Coastguard Worker 		if (errno == ENOENT) {
1089*49cdfc7eSAndroid Build Coastguard Worker 			sbuf.st_size = 0;
1090*49cdfc7eSAndroid Build Coastguard Worker 		} else {
1091*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
1092*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  Could not stat file %s:  %s (%d)\n",
1093*49cdfc7eSAndroid Build Coastguard Worker 				TagName, path, SYSERR, errno);
1094*49cdfc7eSAndroid Build Coastguard Worker 			return -1;
1095*49cdfc7eSAndroid Build Coastguard Worker 		}
1096*49cdfc7eSAndroid Build Coastguard Worker 	} else {
1097*49cdfc7eSAndroid Build Coastguard Worker 		if (!S_ISREG(sbuf.st_mode)) {
1098*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
1099*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  file %s exists, but is not a regular file - cannot modify length\n",
1100*49cdfc7eSAndroid Build Coastguard Worker 				TagName, path);
1101*49cdfc7eSAndroid Build Coastguard Worker 			return -1;
1102*49cdfc7eSAndroid Build Coastguard Worker 		}
1103*49cdfc7eSAndroid Build Coastguard Worker 	}
1104*49cdfc7eSAndroid Build Coastguard Worker 
1105*49cdfc7eSAndroid Build Coastguard Worker 	if (sbuf.st_size == nbytes)
1106*49cdfc7eSAndroid Build Coastguard Worker 		return nbytes;
1107*49cdfc7eSAndroid Build Coastguard Worker 
1108*49cdfc7eSAndroid Build Coastguard Worker 	Oflags |= O_CREAT | O_WRONLY;
1109*49cdfc7eSAndroid Build Coastguard Worker 
1110*49cdfc7eSAndroid Build Coastguard Worker 	if ((fd = open(path, Oflags, 0666)) == -1) {
1111*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr,
1112*49cdfc7eSAndroid Build Coastguard Worker 			"iogen%s:  Could not create/open file %s: %s (%d)\n",
1113*49cdfc7eSAndroid Build Coastguard Worker 			TagName, path, SYSERR, errno);
1114*49cdfc7eSAndroid Build Coastguard Worker 		return -1;
1115*49cdfc7eSAndroid Build Coastguard Worker 	}
1116*49cdfc7eSAndroid Build Coastguard Worker 
1117*49cdfc7eSAndroid Build Coastguard Worker 	/*
1118*49cdfc7eSAndroid Build Coastguard Worker 	 * Truncate file if it is longer than nbytes, otherwise attempt to
1119*49cdfc7eSAndroid Build Coastguard Worker 	 * pre-allocate file blocks.
1120*49cdfc7eSAndroid Build Coastguard Worker 	 */
1121*49cdfc7eSAndroid Build Coastguard Worker 
1122*49cdfc7eSAndroid Build Coastguard Worker 	if (sbuf.st_size > nbytes) {
1123*49cdfc7eSAndroid Build Coastguard Worker 		if (ftruncate(fd, nbytes) == -1) {
1124*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
1125*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  Could not ftruncate() %s to %d bytes:  %s (%d)\n",
1126*49cdfc7eSAndroid Build Coastguard Worker 				TagName, path, nbytes, SYSERR, errno);
1127*49cdfc7eSAndroid Build Coastguard Worker 			close(fd);
1128*49cdfc7eSAndroid Build Coastguard Worker 			return -1;
1129*49cdfc7eSAndroid Build Coastguard Worker 		}
1130*49cdfc7eSAndroid Build Coastguard Worker 	} else {
1131*49cdfc7eSAndroid Build Coastguard Worker 
1132*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
1133*49cdfc7eSAndroid Build Coastguard Worker 		/*
1134*49cdfc7eSAndroid Build Coastguard Worker 		 *  The file must be designated as Real-Time before any data
1135*49cdfc7eSAndroid Build Coastguard Worker 		 *  is allocated to it.
1136*49cdfc7eSAndroid Build Coastguard Worker 		 *
1137*49cdfc7eSAndroid Build Coastguard Worker 		 */
1138*49cdfc7eSAndroid Build Coastguard Worker 		if (Orealtime != 0) {
1139*49cdfc7eSAndroid Build Coastguard Worker 			memset(&xattr, 0x00, sizeof(xattr));
1140*49cdfc7eSAndroid Build Coastguard Worker 			xattr.fsx_xflags = XFS_XFLAG_REALTIME;
1141*49cdfc7eSAndroid Build Coastguard Worker 			/*fprintf(stderr, "set: fsx_xflags = 0x%x\n", xattr.fsx_xflags); */
1142*49cdfc7eSAndroid Build Coastguard Worker 			if (fcntl(fd, F_FSSETXATTR, &xattr) == -1) {
1143*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1144*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s: Error %s (%d) setting XFS XATTR->Realtime on file %s\n",
1145*49cdfc7eSAndroid Build Coastguard Worker 					TagName, SYSERR, errno, path);
1146*49cdfc7eSAndroid Build Coastguard Worker 				close(fd);
1147*49cdfc7eSAndroid Build Coastguard Worker 				return -1;
1148*49cdfc7eSAndroid Build Coastguard Worker 			}
1149*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
1150*49cdfc7eSAndroid Build Coastguard Worker 			if (fcntl(fd, F_FSGETXATTR, &xattr) == -1) {
1151*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1152*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s: Error getting realtime flag %s (%d)\n",
1153*49cdfc7eSAndroid Build Coastguard Worker 					TagName, SYSERR, errno);
1154*49cdfc7eSAndroid Build Coastguard Worker 				close(fd);
1155*49cdfc7eSAndroid Build Coastguard Worker 				return -1;
1156*49cdfc7eSAndroid Build Coastguard Worker 			} else {
1157*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr, "get: fsx_xflags = 0x%x\n",
1158*49cdfc7eSAndroid Build Coastguard Worker 					xattr.fsx_xflags);
1159*49cdfc7eSAndroid Build Coastguard Worker 			}
1160*49cdfc7eSAndroid Build Coastguard Worker #endif
1161*49cdfc7eSAndroid Build Coastguard Worker 		}
1162*49cdfc7eSAndroid Build Coastguard Worker 
1163*49cdfc7eSAndroid Build Coastguard Worker 		/*
1164*49cdfc7eSAndroid Build Coastguard Worker 		 * Reserve space with F_RESVSP
1165*49cdfc7eSAndroid Build Coastguard Worker 		 *
1166*49cdfc7eSAndroid Build Coastguard Worker 		 * Failure is ignored since F_RESVSP only works on XFS and the
1167*49cdfc7eSAndroid Build Coastguard Worker 		 * filesystem could be on EFS or NFS
1168*49cdfc7eSAndroid Build Coastguard Worker 		 */
1169*49cdfc7eSAndroid Build Coastguard Worker 		if (Oreserve) {
1170*49cdfc7eSAndroid Build Coastguard Worker 			f.l_whence = SEEK_SET;
1171*49cdfc7eSAndroid Build Coastguard Worker 			f.l_start = 0;
1172*49cdfc7eSAndroid Build Coastguard Worker 			f.l_len = nbytes;
1173*49cdfc7eSAndroid Build Coastguard Worker 
1174*49cdfc7eSAndroid Build Coastguard Worker 			/*fprintf(stderr,
1175*49cdfc7eSAndroid Build Coastguard Worker 			   "create_file: fcntl(%d, F_RESVSP, { %d, %lld, %lld })\n",
1176*49cdfc7eSAndroid Build Coastguard Worker 			   fd, f.l_whence, (long long)f.l_start, (long long)f.l_len); */
1177*49cdfc7eSAndroid Build Coastguard Worker 
1178*49cdfc7eSAndroid Build Coastguard Worker 			/* non-zeroing reservation */
1179*49cdfc7eSAndroid Build Coastguard Worker 			if (fcntl(fd, F_RESVSP, &f) == -1) {
1180*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1181*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s:  Could not fcntl(F_RESVSP) %d bytes in file %s: %s (%d)\n",
1182*49cdfc7eSAndroid Build Coastguard Worker 					TagName, nbytes, path, SYSERR, errno);
1183*49cdfc7eSAndroid Build Coastguard Worker 				close(fd);
1184*49cdfc7eSAndroid Build Coastguard Worker 				return -1;
1185*49cdfc7eSAndroid Build Coastguard Worker 			}
1186*49cdfc7eSAndroid Build Coastguard Worker 		}
1187*49cdfc7eSAndroid Build Coastguard Worker 
1188*49cdfc7eSAndroid Build Coastguard Worker 		if (Oallocate) {
1189*49cdfc7eSAndroid Build Coastguard Worker 			/* F_ALLOCSP allocates from the start of the file to l_start */
1190*49cdfc7eSAndroid Build Coastguard Worker 			f.l_whence = SEEK_SET;
1191*49cdfc7eSAndroid Build Coastguard Worker 			f.l_start = nbytes;
1192*49cdfc7eSAndroid Build Coastguard Worker 			f.l_len = 0;
1193*49cdfc7eSAndroid Build Coastguard Worker 			/*fprintf(stderr,
1194*49cdfc7eSAndroid Build Coastguard Worker 			   "create_file: fcntl(%d, F_ALLOCSP, { %d, %lld, %lld })\n",
1195*49cdfc7eSAndroid Build Coastguard Worker 			   fd, f.l_whence, (long long)f.l_start,
1196*49cdfc7eSAndroid Build Coastguard Worker 			   (long long)f.l_len); */
1197*49cdfc7eSAndroid Build Coastguard Worker 
1198*49cdfc7eSAndroid Build Coastguard Worker 			/* zeroing reservation */
1199*49cdfc7eSAndroid Build Coastguard Worker 			if (fcntl(fd, F_ALLOCSP, &f) == -1) {
1200*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1201*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s:  Could not fcntl(F_ALLOCSP) %d bytes in file %s: %s (%d)\n",
1202*49cdfc7eSAndroid Build Coastguard Worker 					TagName, nbytes, path, SYSERR, errno);
1203*49cdfc7eSAndroid Build Coastguard Worker 				close(fd);
1204*49cdfc7eSAndroid Build Coastguard Worker 				return -1;
1205*49cdfc7eSAndroid Build Coastguard Worker 			}
1206*49cdfc7eSAndroid Build Coastguard Worker 		}
1207*49cdfc7eSAndroid Build Coastguard Worker #endif /* sgi */
1208*49cdfc7eSAndroid Build Coastguard Worker 
1209*49cdfc7eSAndroid Build Coastguard Worker 		/*
1210*49cdfc7eSAndroid Build Coastguard Worker 		 * Write a byte at the end of file so that stat() sets the right
1211*49cdfc7eSAndroid Build Coastguard Worker 		 * file size.
1212*49cdfc7eSAndroid Build Coastguard Worker 		 */
1213*49cdfc7eSAndroid Build Coastguard Worker 
1214*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
1215*49cdfc7eSAndroid Build Coastguard Worker 		if (Owrite == 2) {
1216*49cdfc7eSAndroid Build Coastguard Worker 			close(fd);
1217*49cdfc7eSAndroid Build Coastguard Worker 			if ((fd =
1218*49cdfc7eSAndroid Build Coastguard Worker 			     open(path, O_CREAT | O_RDWR | O_DIRECT,
1219*49cdfc7eSAndroid Build Coastguard Worker 				  0)) != -1) {
1220*49cdfc7eSAndroid Build Coastguard Worker 				if (fcntl(fd, F_DIOINFO, &finfo) == -1) {
1221*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1222*49cdfc7eSAndroid Build Coastguard Worker 						"iogen%s: Error %s (%d) getting direct I/O info for file %s\n",
1223*49cdfc7eSAndroid Build Coastguard Worker 						TagName, SYSERR, errno, path);
1224*49cdfc7eSAndroid Build Coastguard Worker 					return -1;
1225*49cdfc7eSAndroid Build Coastguard Worker 				} else {
1226*49cdfc7eSAndroid Build Coastguard Worker 					/*fprintf(stderr, "%s: miniosz=%d\n",
1227*49cdfc7eSAndroid Build Coastguard Worker 					   path, finfo.d_miniosz); */
1228*49cdfc7eSAndroid Build Coastguard Worker 				}
1229*49cdfc7eSAndroid Build Coastguard Worker 			} else {
1230*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1231*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s: Error %s (%d) opening file %s with flags O_CREAT|O_RDWR|O_DIRECT\n",
1232*49cdfc7eSAndroid Build Coastguard Worker 					TagName, SYSERR, errno, path);
1233*49cdfc7eSAndroid Build Coastguard Worker 				return -1;
1234*49cdfc7eSAndroid Build Coastguard Worker 			}
1235*49cdfc7eSAndroid Build Coastguard Worker 
1236*49cdfc7eSAndroid Build Coastguard Worker 			/*
1237*49cdfc7eSAndroid Build Coastguard Worker 			 * nb is nbytes adjusted down by an even d_miniosz block
1238*49cdfc7eSAndroid Build Coastguard Worker 			 *
1239*49cdfc7eSAndroid Build Coastguard Worker 			 * Note: the first adjustment can cause iogen to print a warning
1240*49cdfc7eSAndroid Build Coastguard Worker 			 *  about not being able to create a file of <nbytes> length,
1241*49cdfc7eSAndroid Build Coastguard Worker 			 *  since the file will be shorter.
1242*49cdfc7eSAndroid Build Coastguard Worker 			 */
1243*49cdfc7eSAndroid Build Coastguard Worker 			nb = nbytes - finfo.d_miniosz;
1244*49cdfc7eSAndroid Build Coastguard Worker 			nb = nb - nb % finfo.d_miniosz;
1245*49cdfc7eSAndroid Build Coastguard Worker 
1246*49cdfc7eSAndroid Build Coastguard Worker 			/*fprintf(stderr,
1247*49cdfc7eSAndroid Build Coastguard Worker 			   "create_file_ow2: lseek(%d, %d {%d %d}, SEEK_SET)\n",
1248*49cdfc7eSAndroid Build Coastguard Worker 			   fd, nb, nbytes, finfo.d_miniosz); */
1249*49cdfc7eSAndroid Build Coastguard Worker 
1250*49cdfc7eSAndroid Build Coastguard Worker 			if (lseek(fd, nb, SEEK_SET) == -1) {
1251*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1252*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s:  Could not lseek() to EOF of file %s: %s (%d)\n\tactual offset %d file size goal %d miniosz %lld\n",
1253*49cdfc7eSAndroid Build Coastguard Worker 					TagName, path, SYSERR, errno,
1254*49cdfc7eSAndroid Build Coastguard Worker 					nb, nbytes, (long long)finfo.d_miniosz);
1255*49cdfc7eSAndroid Build Coastguard Worker 				close(fd);
1256*49cdfc7eSAndroid Build Coastguard Worker 				return -1;
1257*49cdfc7eSAndroid Build Coastguard Worker 			}
1258*49cdfc7eSAndroid Build Coastguard Worker 
1259*49cdfc7eSAndroid Build Coastguard Worker 			b = buf = malloc(finfo.d_miniosz + finfo.d_mem);
1260*49cdfc7eSAndroid Build Coastguard Worker 
1261*49cdfc7eSAndroid Build Coastguard Worker 			if (((long)buf % finfo.d_mem != 0)) {
1262*49cdfc7eSAndroid Build Coastguard Worker 				buf += finfo.d_mem - ((long)buf % finfo.d_mem);
1263*49cdfc7eSAndroid Build Coastguard Worker 			}
1264*49cdfc7eSAndroid Build Coastguard Worker 
1265*49cdfc7eSAndroid Build Coastguard Worker 			memset(buf, 0, finfo.d_miniosz);
1266*49cdfc7eSAndroid Build Coastguard Worker 
1267*49cdfc7eSAndroid Build Coastguard Worker 			if ((rval =
1268*49cdfc7eSAndroid Build Coastguard Worker 			     write(fd, buf,
1269*49cdfc7eSAndroid Build Coastguard Worker 				   finfo.d_miniosz)) != finfo.d_miniosz) {
1270*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1271*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s:  Could not write %d byte length file %s: %s (%d)\n",
1272*49cdfc7eSAndroid Build Coastguard Worker 					TagName, nb, path, SYSERR, errno);
1273*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr, "\twrite(%d, 0x%lx, %d) = %d\n",
1274*49cdfc7eSAndroid Build Coastguard Worker 					fd, (long)buf, finfo.d_miniosz, rval);
1275*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1276*49cdfc7eSAndroid Build Coastguard Worker 					"\toffset %d file size goal %d, miniosz=%d\n",
1277*49cdfc7eSAndroid Build Coastguard Worker 					nb, nbytes, finfo.d_miniosz);
1278*49cdfc7eSAndroid Build Coastguard Worker 				close(fd);
1279*49cdfc7eSAndroid Build Coastguard Worker 				return -1;
1280*49cdfc7eSAndroid Build Coastguard Worker 			}
1281*49cdfc7eSAndroid Build Coastguard Worker 			free(b);
1282*49cdfc7eSAndroid Build Coastguard Worker 		} else
1283*49cdfc7eSAndroid Build Coastguard Worker #endif /* sgi */
1284*49cdfc7eSAndroid Build Coastguard Worker 		if (Owrite) {
1285*49cdfc7eSAndroid Build Coastguard Worker 			/*fprintf(stderr,
1286*49cdfc7eSAndroid Build Coastguard Worker 			   "create_file_Owrite: lseek(%d, %d {%d}, SEEK_SET)\n",
1287*49cdfc7eSAndroid Build Coastguard Worker 			   fd, nbytes-1, nbytes); */
1288*49cdfc7eSAndroid Build Coastguard Worker 
1289*49cdfc7eSAndroid Build Coastguard Worker 			if (lseek(fd, nbytes - 1, SEEK_SET) == -1) {
1290*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1291*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s:  Could not lseek() to EOF in file %s:  %s (%d)\n\toffset goal %d\n",
1292*49cdfc7eSAndroid Build Coastguard Worker 					TagName, path, SYSERR, errno,
1293*49cdfc7eSAndroid Build Coastguard Worker 					nbytes - 1);
1294*49cdfc7eSAndroid Build Coastguard Worker 				close(fd);
1295*49cdfc7eSAndroid Build Coastguard Worker 				return -1;
1296*49cdfc7eSAndroid Build Coastguard Worker 			}
1297*49cdfc7eSAndroid Build Coastguard Worker 
1298*49cdfc7eSAndroid Build Coastguard Worker 			if ((rval = write(fd, &c, 1)) != 1) {
1299*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1300*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s:  Could not create a %d byte length file %s: %s (%d)\n",
1301*49cdfc7eSAndroid Build Coastguard Worker 					TagName, nbytes, path, SYSERR, errno);
1302*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1303*49cdfc7eSAndroid Build Coastguard Worker 					"\twrite(%d, 0x%lx, %d) = %d\n",
1304*49cdfc7eSAndroid Build Coastguard Worker 					fd, (long)&c, 1, rval);
1305*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1306*49cdfc7eSAndroid Build Coastguard Worker 					"\toffset %d file size goal %d\n",
1307*49cdfc7eSAndroid Build Coastguard Worker 					nbytes - 1, nbytes);
1308*49cdfc7eSAndroid Build Coastguard Worker 				close(fd);
1309*49cdfc7eSAndroid Build Coastguard Worker 				return -1;
1310*49cdfc7eSAndroid Build Coastguard Worker 			}
1311*49cdfc7eSAndroid Build Coastguard Worker 		}
1312*49cdfc7eSAndroid Build Coastguard Worker 	}
1313*49cdfc7eSAndroid Build Coastguard Worker 
1314*49cdfc7eSAndroid Build Coastguard Worker 	fstat(fd, &sbuf);
1315*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
1316*49cdfc7eSAndroid Build Coastguard Worker 
1317*49cdfc7eSAndroid Build Coastguard Worker 	return sbuf.st_size;
1318*49cdfc7eSAndroid Build Coastguard Worker }
1319*49cdfc7eSAndroid Build Coastguard Worker 
1320*49cdfc7eSAndroid Build Coastguard Worker /*
1321*49cdfc7eSAndroid Build Coastguard Worker  * Function to convert a string to its corresponding value in a strmap array.
1322*49cdfc7eSAndroid Build Coastguard Worker  * If the string is not found in the array, the value corresponding to the
1323*49cdfc7eSAndroid Build Coastguard Worker  * NULL string (the last element in the array) is returned.
1324*49cdfc7eSAndroid Build Coastguard Worker  */
1325*49cdfc7eSAndroid Build Coastguard Worker 
str_to_value(struct strmap * map,char * str)1326*49cdfc7eSAndroid Build Coastguard Worker int str_to_value(struct strmap *map, char *str)
1327*49cdfc7eSAndroid Build Coastguard Worker {
1328*49cdfc7eSAndroid Build Coastguard Worker 	struct strmap *mp;
1329*49cdfc7eSAndroid Build Coastguard Worker 
1330*49cdfc7eSAndroid Build Coastguard Worker 	for (mp = map; mp->m_string != NULL; mp++)
1331*49cdfc7eSAndroid Build Coastguard Worker 		if (strcmp(mp->m_string, str) == 0)
1332*49cdfc7eSAndroid Build Coastguard Worker 			break;
1333*49cdfc7eSAndroid Build Coastguard Worker 
1334*49cdfc7eSAndroid Build Coastguard Worker 	return mp->m_value;
1335*49cdfc7eSAndroid Build Coastguard Worker }
1336*49cdfc7eSAndroid Build Coastguard Worker 
1337*49cdfc7eSAndroid Build Coastguard Worker /*
1338*49cdfc7eSAndroid Build Coastguard Worker  * Function to convert a string to its corresponding entry in a strmap array.
1339*49cdfc7eSAndroid Build Coastguard Worker  * If the string is not found in the array, a NULL is returned.
1340*49cdfc7eSAndroid Build Coastguard Worker  */
1341*49cdfc7eSAndroid Build Coastguard Worker 
str_lookup(struct strmap * map,char * str)1342*49cdfc7eSAndroid Build Coastguard Worker struct strmap *str_lookup(struct strmap *map, char *str)
1343*49cdfc7eSAndroid Build Coastguard Worker {
1344*49cdfc7eSAndroid Build Coastguard Worker 	struct strmap *mp;
1345*49cdfc7eSAndroid Build Coastguard Worker 
1346*49cdfc7eSAndroid Build Coastguard Worker 	for (mp = map; mp->m_string != NULL; mp++)
1347*49cdfc7eSAndroid Build Coastguard Worker 		if (strcmp(mp->m_string, str) == 0)
1348*49cdfc7eSAndroid Build Coastguard Worker 			break;
1349*49cdfc7eSAndroid Build Coastguard Worker 
1350*49cdfc7eSAndroid Build Coastguard Worker 	return ((mp->m_string == NULL) ? NULL : mp);
1351*49cdfc7eSAndroid Build Coastguard Worker }
1352*49cdfc7eSAndroid Build Coastguard Worker 
1353*49cdfc7eSAndroid Build Coastguard Worker /*
1354*49cdfc7eSAndroid Build Coastguard Worker  * Function to convert a value to its corresponding string in a strmap array.
1355*49cdfc7eSAndroid Build Coastguard Worker  * If the value is not found in the array, NULL is returned.
1356*49cdfc7eSAndroid Build Coastguard Worker  */
1357*49cdfc7eSAndroid Build Coastguard Worker 
value_to_string(struct strmap * map,int val)1358*49cdfc7eSAndroid Build Coastguard Worker char *value_to_string(struct strmap *map, int val)
1359*49cdfc7eSAndroid Build Coastguard Worker {
1360*49cdfc7eSAndroid Build Coastguard Worker 	struct strmap *mp;
1361*49cdfc7eSAndroid Build Coastguard Worker 
1362*49cdfc7eSAndroid Build Coastguard Worker 	for (mp = map; mp->m_string != NULL; mp++)
1363*49cdfc7eSAndroid Build Coastguard Worker 		if (mp->m_value == val)
1364*49cdfc7eSAndroid Build Coastguard Worker 			break;
1365*49cdfc7eSAndroid Build Coastguard Worker 
1366*49cdfc7eSAndroid Build Coastguard Worker 	return mp->m_string;
1367*49cdfc7eSAndroid Build Coastguard Worker }
1368*49cdfc7eSAndroid Build Coastguard Worker 
1369*49cdfc7eSAndroid Build Coastguard Worker /*
1370*49cdfc7eSAndroid Build Coastguard Worker  * Interpret cmdline options/arguments.  Exit with 1 if something on the
1371*49cdfc7eSAndroid Build Coastguard Worker  * cmdline isn't kosher.
1372*49cdfc7eSAndroid Build Coastguard Worker  */
1373*49cdfc7eSAndroid Build Coastguard Worker 
parse_cmdline(int argc,char ** argv,char * opts)1374*49cdfc7eSAndroid Build Coastguard Worker int parse_cmdline(int argc, char **argv, char *opts)
1375*49cdfc7eSAndroid Build Coastguard Worker {
1376*49cdfc7eSAndroid Build Coastguard Worker 	int o, len, nb, format_error;
1377*49cdfc7eSAndroid Build Coastguard Worker 	struct strmap *flgs, *sc;
1378*49cdfc7eSAndroid Build Coastguard Worker 	char *file, *cp, ch;
1379*49cdfc7eSAndroid Build Coastguard Worker 	extern int opterr;
1380*49cdfc7eSAndroid Build Coastguard Worker 	extern int optind;
1381*49cdfc7eSAndroid Build Coastguard Worker 	extern char *optarg;
1382*49cdfc7eSAndroid Build Coastguard Worker 	struct strmap *mp;
1383*49cdfc7eSAndroid Build Coastguard Worker 	struct file_info *fptr;
1384*49cdfc7eSAndroid Build Coastguard Worker 	int nopenargs;
1385*49cdfc7eSAndroid Build Coastguard Worker 	char *openargs[5];	/* Flags, cbits, cblks */
1386*49cdfc7eSAndroid Build Coastguard Worker 	char *errmsg;
1387*49cdfc7eSAndroid Build Coastguard Worker 	int str_to_int();
1388*49cdfc7eSAndroid Build Coastguard Worker 	opterr = 0;
1389*49cdfc7eSAndroid Build Coastguard Worker #ifndef linux
1390*49cdfc7eSAndroid Build Coastguard Worker 	char *ranges;
1391*49cdfc7eSAndroid Build Coastguard Worker 	struct strmap *type;
1392*49cdfc7eSAndroid Build Coastguard Worker #endif
1393*49cdfc7eSAndroid Build Coastguard Worker 
1394*49cdfc7eSAndroid Build Coastguard Worker 	while ((o = getopt(argc, argv, opts)) != EOF) {
1395*49cdfc7eSAndroid Build Coastguard Worker 		switch ((char)o) {
1396*49cdfc7eSAndroid Build Coastguard Worker 
1397*49cdfc7eSAndroid Build Coastguard Worker 		case 'a':
1398*49cdfc7eSAndroid Build Coastguard Worker #ifdef linux
1399*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
1400*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  Unrecognized option -a on this platform\n",
1401*49cdfc7eSAndroid Build Coastguard Worker 				TagName);
1402*49cdfc7eSAndroid Build Coastguard Worker 			exit(2);
1403*49cdfc7eSAndroid Build Coastguard Worker #else
1404*49cdfc7eSAndroid Build Coastguard Worker 			cp = strtok(optarg, ",");
1405*49cdfc7eSAndroid Build Coastguard Worker 			while (cp != NULL) {
1406*49cdfc7eSAndroid Build Coastguard Worker 				if ((type =
1407*49cdfc7eSAndroid Build Coastguard Worker 				     str_lookup(Aio_Strat_Map, cp)) == NULL) {
1408*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1409*49cdfc7eSAndroid Build Coastguard Worker 						"iogen%s:  Unrecognized aio completion strategy:  %s\n",
1410*49cdfc7eSAndroid Build Coastguard Worker 						TagName, cp);
1411*49cdfc7eSAndroid Build Coastguard Worker 					exit(2);
1412*49cdfc7eSAndroid Build Coastguard Worker 				}
1413*49cdfc7eSAndroid Build Coastguard Worker 
1414*49cdfc7eSAndroid Build Coastguard Worker 				Aio_Strat_List[Naio_Strat_Types++] = type;
1415*49cdfc7eSAndroid Build Coastguard Worker 				cp = strtok(NULL, ",");
1416*49cdfc7eSAndroid Build Coastguard Worker 			}
1417*49cdfc7eSAndroid Build Coastguard Worker 			a_opt++;
1418*49cdfc7eSAndroid Build Coastguard Worker #endif
1419*49cdfc7eSAndroid Build Coastguard Worker 			break;
1420*49cdfc7eSAndroid Build Coastguard Worker 
1421*49cdfc7eSAndroid Build Coastguard Worker 		case 'f':
1422*49cdfc7eSAndroid Build Coastguard Worker 			cp = strtok(optarg, ",");
1423*49cdfc7eSAndroid Build Coastguard Worker 			while (cp != NULL) {
1424*49cdfc7eSAndroid Build Coastguard Worker 				if ((flgs = str_lookup(Flag_Map, cp)) == NULL) {
1425*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1426*49cdfc7eSAndroid Build Coastguard Worker 						"iogen%s:  Unrecognized flags:  %s\n",
1427*49cdfc7eSAndroid Build Coastguard Worker 						TagName, cp);
1428*49cdfc7eSAndroid Build Coastguard Worker 					exit(2);
1429*49cdfc7eSAndroid Build Coastguard Worker 				}
1430*49cdfc7eSAndroid Build Coastguard Worker 
1431*49cdfc7eSAndroid Build Coastguard Worker 				cp = strtok(NULL, ",");
1432*49cdfc7eSAndroid Build Coastguard Worker 
1433*49cdfc7eSAndroid Build Coastguard Worker #ifdef O_SSD
1434*49cdfc7eSAndroid Build Coastguard Worker 				if (flgs->m_value & O_SSD && !Sds_Avail) {
1435*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1436*49cdfc7eSAndroid Build Coastguard Worker 						"iogen%s:  Warning - no sds available, ignoring ssd flag\n",
1437*49cdfc7eSAndroid Build Coastguard Worker 						TagName);
1438*49cdfc7eSAndroid Build Coastguard Worker 					continue;
1439*49cdfc7eSAndroid Build Coastguard Worker 				}
1440*49cdfc7eSAndroid Build Coastguard Worker #endif
1441*49cdfc7eSAndroid Build Coastguard Worker 
1442*49cdfc7eSAndroid Build Coastguard Worker 				Flag_List[Nflags++] = flgs;
1443*49cdfc7eSAndroid Build Coastguard Worker 			}
1444*49cdfc7eSAndroid Build Coastguard Worker 			f_opt++;
1445*49cdfc7eSAndroid Build Coastguard Worker 			break;
1446*49cdfc7eSAndroid Build Coastguard Worker 
1447*49cdfc7eSAndroid Build Coastguard Worker 		case 'h':
1448*49cdfc7eSAndroid Build Coastguard Worker 			help(stdout);
1449*49cdfc7eSAndroid Build Coastguard Worker 			exit(0);
1450*49cdfc7eSAndroid Build Coastguard Worker 			break;
1451*49cdfc7eSAndroid Build Coastguard Worker 
1452*49cdfc7eSAndroid Build Coastguard Worker 		case 'i':
1453*49cdfc7eSAndroid Build Coastguard Worker 			format_error = 0;
1454*49cdfc7eSAndroid Build Coastguard Worker 
1455*49cdfc7eSAndroid Build Coastguard Worker 			switch (sscanf(optarg, "%i%c", &Iterations, &ch)) {
1456*49cdfc7eSAndroid Build Coastguard Worker 			case 1:
1457*49cdfc7eSAndroid Build Coastguard Worker 				Time_Mode = 0;
1458*49cdfc7eSAndroid Build Coastguard Worker 				break;
1459*49cdfc7eSAndroid Build Coastguard Worker 
1460*49cdfc7eSAndroid Build Coastguard Worker 			case 2:
1461*49cdfc7eSAndroid Build Coastguard Worker 				if (ch == 's')
1462*49cdfc7eSAndroid Build Coastguard Worker 					Time_Mode = 1;
1463*49cdfc7eSAndroid Build Coastguard Worker 				else
1464*49cdfc7eSAndroid Build Coastguard Worker 					format_error = 1;
1465*49cdfc7eSAndroid Build Coastguard Worker 				break;
1466*49cdfc7eSAndroid Build Coastguard Worker 
1467*49cdfc7eSAndroid Build Coastguard Worker 			default:
1468*49cdfc7eSAndroid Build Coastguard Worker 				format_error = 1;
1469*49cdfc7eSAndroid Build Coastguard Worker 			}
1470*49cdfc7eSAndroid Build Coastguard Worker 
1471*49cdfc7eSAndroid Build Coastguard Worker 			if (Iterations < 0)
1472*49cdfc7eSAndroid Build Coastguard Worker 				format_error = 1;
1473*49cdfc7eSAndroid Build Coastguard Worker 
1474*49cdfc7eSAndroid Build Coastguard Worker 			if (format_error) {
1475*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1476*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s:  Illegal -i arg (%s):  Must be of the format:  number[s]\n",
1477*49cdfc7eSAndroid Build Coastguard Worker 					TagName, optarg);
1478*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1479*49cdfc7eSAndroid Build Coastguard Worker 					"        where 'number' is >= 0\n");
1480*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
1481*49cdfc7eSAndroid Build Coastguard Worker 			}
1482*49cdfc7eSAndroid Build Coastguard Worker 
1483*49cdfc7eSAndroid Build Coastguard Worker 			i_opt++;
1484*49cdfc7eSAndroid Build Coastguard Worker 			break;
1485*49cdfc7eSAndroid Build Coastguard Worker 
1486*49cdfc7eSAndroid Build Coastguard Worker 		case 'L':
1487*49cdfc7eSAndroid Build Coastguard Worker #ifdef linux
1488*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
1489*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  Unrecognized option -L on this platform\n",
1490*49cdfc7eSAndroid Build Coastguard Worker 				TagName);
1491*49cdfc7eSAndroid Build Coastguard Worker 			exit(2);
1492*49cdfc7eSAndroid Build Coastguard Worker #else
1493*49cdfc7eSAndroid Build Coastguard Worker 			if (parse_ranges(optarg, 1, 255, 1, NULL, &ranges,
1494*49cdfc7eSAndroid Build Coastguard Worker 					 &errmsg) == -1) {
1495*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1496*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s: error parsing listio range '%s': %s\n",
1497*49cdfc7eSAndroid Build Coastguard Worker 					TagName, optarg, errmsg);
1498*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
1499*49cdfc7eSAndroid Build Coastguard Worker 			}
1500*49cdfc7eSAndroid Build Coastguard Worker 
1501*49cdfc7eSAndroid Build Coastguard Worker 			Minstrides = range_min(ranges, 0);
1502*49cdfc7eSAndroid Build Coastguard Worker 			Maxstrides = range_max(ranges, 0);
1503*49cdfc7eSAndroid Build Coastguard Worker 
1504*49cdfc7eSAndroid Build Coastguard Worker 			free(ranges);
1505*49cdfc7eSAndroid Build Coastguard Worker 			L_opt++;
1506*49cdfc7eSAndroid Build Coastguard Worker #endif
1507*49cdfc7eSAndroid Build Coastguard Worker 			break;
1508*49cdfc7eSAndroid Build Coastguard Worker 
1509*49cdfc7eSAndroid Build Coastguard Worker 		case 'm':
1510*49cdfc7eSAndroid Build Coastguard Worker 			if ((Offset_Mode =
1511*49cdfc7eSAndroid Build Coastguard Worker 			     str_lookup(Omode_Map, optarg)) == NULL) {
1512*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1513*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s:  Illegal -m arg (%s)\n",
1514*49cdfc7eSAndroid Build Coastguard Worker 					TagName, optarg);
1515*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
1516*49cdfc7eSAndroid Build Coastguard Worker 			}
1517*49cdfc7eSAndroid Build Coastguard Worker 
1518*49cdfc7eSAndroid Build Coastguard Worker 			m_opt++;
1519*49cdfc7eSAndroid Build Coastguard Worker 			break;
1520*49cdfc7eSAndroid Build Coastguard Worker 
1521*49cdfc7eSAndroid Build Coastguard Worker 		case 'N':
1522*49cdfc7eSAndroid Build Coastguard Worker 			sprintf(TagName, "(%.39s)", optarg);
1523*49cdfc7eSAndroid Build Coastguard Worker 			break;
1524*49cdfc7eSAndroid Build Coastguard Worker 
1525*49cdfc7eSAndroid Build Coastguard Worker 		case 'o':
1526*49cdfc7eSAndroid Build Coastguard Worker 			o_opt++;
1527*49cdfc7eSAndroid Build Coastguard Worker 			break;
1528*49cdfc7eSAndroid Build Coastguard Worker 
1529*49cdfc7eSAndroid Build Coastguard Worker 		case 'O':
1530*49cdfc7eSAndroid Build Coastguard Worker 
1531*49cdfc7eSAndroid Build Coastguard Worker 			nopenargs = string_to_tokens(optarg, openargs, 4, ":/");
1532*49cdfc7eSAndroid Build Coastguard Worker 
1533*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
1534*49cdfc7eSAndroid Build Coastguard Worker 			if (nopenargs)
1535*49cdfc7eSAndroid Build Coastguard Worker 				sscanf(openargs[1], "%i", &Ocbits);
1536*49cdfc7eSAndroid Build Coastguard Worker 			if (nopenargs > 1)
1537*49cdfc7eSAndroid Build Coastguard Worker 				sscanf(openargs[2], "%i", &Ocblks);
1538*49cdfc7eSAndroid Build Coastguard Worker 
1539*49cdfc7eSAndroid Build Coastguard Worker 			Oflags = parse_open_flags(openargs[0], &errmsg);
1540*49cdfc7eSAndroid Build Coastguard Worker 			if (Oflags == -1) {
1541*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr, "iogen%s: -O %s error: %s\n",
1542*49cdfc7eSAndroid Build Coastguard Worker 					TagName, optarg, errmsg);
1543*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
1544*49cdfc7eSAndroid Build Coastguard Worker 			}
1545*49cdfc7eSAndroid Build Coastguard Worker #endif
1546*49cdfc7eSAndroid Build Coastguard Worker #ifdef linux
1547*49cdfc7eSAndroid Build Coastguard Worker 			Oflags = parse_open_flags(openargs[0], &errmsg);
1548*49cdfc7eSAndroid Build Coastguard Worker 			if (Oflags == -1) {
1549*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr, "iogen%s: -O %s error: %s\n",
1550*49cdfc7eSAndroid Build Coastguard Worker 					TagName, optarg, errmsg);
1551*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
1552*49cdfc7eSAndroid Build Coastguard Worker 			}
1553*49cdfc7eSAndroid Build Coastguard Worker #endif
1554*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
1555*49cdfc7eSAndroid Build Coastguard Worker 			if (!strcmp(openargs[0], "realtime")) {
1556*49cdfc7eSAndroid Build Coastguard Worker 				/*
1557*49cdfc7eSAndroid Build Coastguard Worker 				 * -O realtime:extsize
1558*49cdfc7eSAndroid Build Coastguard Worker 				 */
1559*49cdfc7eSAndroid Build Coastguard Worker 				Orealtime = 1;
1560*49cdfc7eSAndroid Build Coastguard Worker 				if (nopenargs > 1)
1561*49cdfc7eSAndroid Build Coastguard Worker 					sscanf(openargs[1], "%i", &Oextsize);
1562*49cdfc7eSAndroid Build Coastguard Worker 				else
1563*49cdfc7eSAndroid Build Coastguard Worker 					Oextsize = 0;
1564*49cdfc7eSAndroid Build Coastguard Worker 			} else if (!strcmp(openargs[0], "allocate") ||
1565*49cdfc7eSAndroid Build Coastguard Worker 				   !strcmp(openargs[0], "allocsp")) {
1566*49cdfc7eSAndroid Build Coastguard Worker 				/*
1567*49cdfc7eSAndroid Build Coastguard Worker 				 * -O allocate
1568*49cdfc7eSAndroid Build Coastguard Worker 				 */
1569*49cdfc7eSAndroid Build Coastguard Worker 				Oreserve = 0;
1570*49cdfc7eSAndroid Build Coastguard Worker 				Oallocate = 1;
1571*49cdfc7eSAndroid Build Coastguard Worker 			} else if (!strcmp(openargs[0], "reserve")) {
1572*49cdfc7eSAndroid Build Coastguard Worker 				/*
1573*49cdfc7eSAndroid Build Coastguard Worker 				 * -O [no]reserve
1574*49cdfc7eSAndroid Build Coastguard Worker 				 */
1575*49cdfc7eSAndroid Build Coastguard Worker 				Oallocate = 0;
1576*49cdfc7eSAndroid Build Coastguard Worker 				Oreserve = 1;
1577*49cdfc7eSAndroid Build Coastguard Worker 			} else if (!strcmp(openargs[0], "noreserve")) {
1578*49cdfc7eSAndroid Build Coastguard Worker 				/* Oreserve=1 by default; this clears that default */
1579*49cdfc7eSAndroid Build Coastguard Worker 				Oreserve = 0;
1580*49cdfc7eSAndroid Build Coastguard Worker 			} else if (!strcmp(openargs[0], "nowrite")) {
1581*49cdfc7eSAndroid Build Coastguard Worker 				/* Owrite=1 by default; this clears that default */
1582*49cdfc7eSAndroid Build Coastguard Worker 				Owrite = 0;
1583*49cdfc7eSAndroid Build Coastguard Worker 			} else if (!strcmp(openargs[0], "direct")) {
1584*49cdfc7eSAndroid Build Coastguard Worker 				/* this means "use direct i/o to preallocate file" */
1585*49cdfc7eSAndroid Build Coastguard Worker 				Owrite = 2;
1586*49cdfc7eSAndroid Build Coastguard Worker 			} else {
1587*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1588*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s: Error: -O %s error: unrecognized option\n",
1589*49cdfc7eSAndroid Build Coastguard Worker 					TagName, openargs[0]);
1590*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
1591*49cdfc7eSAndroid Build Coastguard Worker 			}
1592*49cdfc7eSAndroid Build Coastguard Worker #endif
1593*49cdfc7eSAndroid Build Coastguard Worker 
1594*49cdfc7eSAndroid Build Coastguard Worker 			O_opt++;
1595*49cdfc7eSAndroid Build Coastguard Worker 			break;
1596*49cdfc7eSAndroid Build Coastguard Worker 
1597*49cdfc7eSAndroid Build Coastguard Worker 		case 'p':
1598*49cdfc7eSAndroid Build Coastguard Worker 			Outpipe = optarg;
1599*49cdfc7eSAndroid Build Coastguard Worker 			p_opt++;
1600*49cdfc7eSAndroid Build Coastguard Worker 			break;
1601*49cdfc7eSAndroid Build Coastguard Worker 
1602*49cdfc7eSAndroid Build Coastguard Worker 		case 'r':
1603*49cdfc7eSAndroid Build Coastguard Worker 			if ((Rawmult = bytes_by_prefix(optarg)) == -1 ||
1604*49cdfc7eSAndroid Build Coastguard Worker 			    Rawmult < 11 || Rawmult % BSIZE) {
1605*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1606*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s:  Illegal -r arg (%s).  Must be > 0 and multipe of BSIZE (%d)\n",
1607*49cdfc7eSAndroid Build Coastguard Worker 					TagName, optarg, BSIZE);
1608*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
1609*49cdfc7eSAndroid Build Coastguard Worker 			}
1610*49cdfc7eSAndroid Build Coastguard Worker 
1611*49cdfc7eSAndroid Build Coastguard Worker 			r_opt++;
1612*49cdfc7eSAndroid Build Coastguard Worker 			break;
1613*49cdfc7eSAndroid Build Coastguard Worker 
1614*49cdfc7eSAndroid Build Coastguard Worker 		case 's':
1615*49cdfc7eSAndroid Build Coastguard Worker 			cp = strtok(optarg, ",");
1616*49cdfc7eSAndroid Build Coastguard Worker 			while (cp != NULL) {
1617*49cdfc7eSAndroid Build Coastguard Worker 				if ((sc = str_lookup(Syscall_Map, cp)) == NULL) {
1618*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1619*49cdfc7eSAndroid Build Coastguard Worker 						"iogen%s:  Unrecognized syscall:  %s\n",
1620*49cdfc7eSAndroid Build Coastguard Worker 						TagName, cp);
1621*49cdfc7eSAndroid Build Coastguard Worker 					exit(2);
1622*49cdfc7eSAndroid Build Coastguard Worker 				}
1623*49cdfc7eSAndroid Build Coastguard Worker 
1624*49cdfc7eSAndroid Build Coastguard Worker 				do {
1625*49cdfc7eSAndroid Build Coastguard Worker 					/* >>> sc->m_flags & FLG_SDS */
1626*49cdfc7eSAndroid Build Coastguard Worker 					if (sc->m_value != SSREAD
1627*49cdfc7eSAndroid Build Coastguard Worker 					    && sc->m_value != SSWRITE)
1628*49cdfc7eSAndroid Build Coastguard Worker 						Fileio++;
1629*49cdfc7eSAndroid Build Coastguard Worker 
1630*49cdfc7eSAndroid Build Coastguard Worker 					Syscall_List[Nsyscalls++] = sc;
1631*49cdfc7eSAndroid Build Coastguard Worker 				} while ((sc = str_lookup(++sc, cp)) != NULL);
1632*49cdfc7eSAndroid Build Coastguard Worker 
1633*49cdfc7eSAndroid Build Coastguard Worker 				cp = strtok(NULL, ",");
1634*49cdfc7eSAndroid Build Coastguard Worker 			}
1635*49cdfc7eSAndroid Build Coastguard Worker 			s_opt++;
1636*49cdfc7eSAndroid Build Coastguard Worker 			break;
1637*49cdfc7eSAndroid Build Coastguard Worker 
1638*49cdfc7eSAndroid Build Coastguard Worker 		case 't':
1639*49cdfc7eSAndroid Build Coastguard Worker 			if ((Mintrans = bytes_by_prefix(optarg)) == -1) {
1640*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1641*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s:  Illegal -t arg (%s):  Must have the form num[bkm]\n",
1642*49cdfc7eSAndroid Build Coastguard Worker 					TagName, optarg);
1643*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
1644*49cdfc7eSAndroid Build Coastguard Worker 			}
1645*49cdfc7eSAndroid Build Coastguard Worker 			t_opt++;
1646*49cdfc7eSAndroid Build Coastguard Worker 			break;
1647*49cdfc7eSAndroid Build Coastguard Worker 
1648*49cdfc7eSAndroid Build Coastguard Worker 		case 'T':
1649*49cdfc7eSAndroid Build Coastguard Worker 			if ((Maxtrans = bytes_by_prefix(optarg)) == -1) {
1650*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1651*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s:  Illegal -T arg (%s):  Must have the form num[bkm]\n",
1652*49cdfc7eSAndroid Build Coastguard Worker 					TagName, optarg);
1653*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
1654*49cdfc7eSAndroid Build Coastguard Worker 			}
1655*49cdfc7eSAndroid Build Coastguard Worker 			T_opt++;
1656*49cdfc7eSAndroid Build Coastguard Worker 			break;
1657*49cdfc7eSAndroid Build Coastguard Worker 
1658*49cdfc7eSAndroid Build Coastguard Worker 		case 'q':
1659*49cdfc7eSAndroid Build Coastguard Worker 			q_opt++;
1660*49cdfc7eSAndroid Build Coastguard Worker 			break;
1661*49cdfc7eSAndroid Build Coastguard Worker 
1662*49cdfc7eSAndroid Build Coastguard Worker 		case '?':
1663*49cdfc7eSAndroid Build Coastguard Worker 			usage(stderr);
1664*49cdfc7eSAndroid Build Coastguard Worker 			exit(1);
1665*49cdfc7eSAndroid Build Coastguard Worker 		}
1666*49cdfc7eSAndroid Build Coastguard Worker 	}
1667*49cdfc7eSAndroid Build Coastguard Worker 
1668*49cdfc7eSAndroid Build Coastguard Worker 	/*
1669*49cdfc7eSAndroid Build Coastguard Worker 	 * Supply defaults
1670*49cdfc7eSAndroid Build Coastguard Worker 	 */
1671*49cdfc7eSAndroid Build Coastguard Worker 
1672*49cdfc7eSAndroid Build Coastguard Worker 	if (!L_opt) {
1673*49cdfc7eSAndroid Build Coastguard Worker 		Minstrides = 1;
1674*49cdfc7eSAndroid Build Coastguard Worker 		Maxstrides = 255;
1675*49cdfc7eSAndroid Build Coastguard Worker 	}
1676*49cdfc7eSAndroid Build Coastguard Worker 
1677*49cdfc7eSAndroid Build Coastguard Worker 	if (!m_opt)
1678*49cdfc7eSAndroid Build Coastguard Worker 		Offset_Mode = str_lookup(Omode_Map, "sequential");
1679*49cdfc7eSAndroid Build Coastguard Worker 
1680*49cdfc7eSAndroid Build Coastguard Worker 	if (!i_opt)
1681*49cdfc7eSAndroid Build Coastguard Worker 		Iterations = 0;
1682*49cdfc7eSAndroid Build Coastguard Worker 
1683*49cdfc7eSAndroid Build Coastguard Worker 	if (!t_opt)
1684*49cdfc7eSAndroid Build Coastguard Worker 		Mintrans = 1;
1685*49cdfc7eSAndroid Build Coastguard Worker 
1686*49cdfc7eSAndroid Build Coastguard Worker 	if (!T_opt)
1687*49cdfc7eSAndroid Build Coastguard Worker 		Maxtrans = 256 * BSIZE;
1688*49cdfc7eSAndroid Build Coastguard Worker 
1689*49cdfc7eSAndroid Build Coastguard Worker 	if (!O_opt)
1690*49cdfc7eSAndroid Build Coastguard Worker 		Oflags = Ocbits = Ocblks = 0;
1691*49cdfc7eSAndroid Build Coastguard Worker 
1692*49cdfc7eSAndroid Build Coastguard Worker 	/*
1693*49cdfc7eSAndroid Build Coastguard Worker 	 * Supply default async io completion strategy types.
1694*49cdfc7eSAndroid Build Coastguard Worker 	 */
1695*49cdfc7eSAndroid Build Coastguard Worker 
1696*49cdfc7eSAndroid Build Coastguard Worker 	if (!a_opt) {
1697*49cdfc7eSAndroid Build Coastguard Worker 		for (mp = Aio_Strat_Map; mp->m_string != NULL; mp++) {
1698*49cdfc7eSAndroid Build Coastguard Worker 			Aio_Strat_List[Naio_Strat_Types++] = mp;
1699*49cdfc7eSAndroid Build Coastguard Worker 		}
1700*49cdfc7eSAndroid Build Coastguard Worker 	}
1701*49cdfc7eSAndroid Build Coastguard Worker 
1702*49cdfc7eSAndroid Build Coastguard Worker 	/*
1703*49cdfc7eSAndroid Build Coastguard Worker 	 * Supply default syscalls.  Default is read,write,reada,writea,listio.
1704*49cdfc7eSAndroid Build Coastguard Worker 	 */
1705*49cdfc7eSAndroid Build Coastguard Worker 
1706*49cdfc7eSAndroid Build Coastguard Worker 	if (!s_opt) {
1707*49cdfc7eSAndroid Build Coastguard Worker 		Nsyscalls = 0;
1708*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "read");
1709*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "write");
1710*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
1711*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "reada");
1712*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "writea");
1713*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "lread");
1714*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "lreada");
1715*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "lwrite");
1716*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "lwritea");
1717*49cdfc7eSAndroid Build Coastguard Worker #endif
1718*49cdfc7eSAndroid Build Coastguard Worker 
1719*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
1720*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "pread");
1721*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "pwrite");
1722*49cdfc7eSAndroid Build Coastguard Worker 		/*Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "aread"); */
1723*49cdfc7eSAndroid Build Coastguard Worker 		/*Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "awrite"); */
1724*49cdfc7eSAndroid Build Coastguard Worker #endif
1725*49cdfc7eSAndroid Build Coastguard Worker 
1726*49cdfc7eSAndroid Build Coastguard Worker #ifndef CRAY
1727*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "readv");
1728*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "writev");
1729*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "mmread");
1730*49cdfc7eSAndroid Build Coastguard Worker 		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "mmwrite");
1731*49cdfc7eSAndroid Build Coastguard Worker #endif
1732*49cdfc7eSAndroid Build Coastguard Worker 
1733*49cdfc7eSAndroid Build Coastguard Worker 		Fileio = 1;
1734*49cdfc7eSAndroid Build Coastguard Worker 	}
1735*49cdfc7eSAndroid Build Coastguard Worker 
1736*49cdfc7eSAndroid Build Coastguard Worker 	if (Fileio && (argc - optind < 1)) {
1737*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr, "iogen%s:  No files specified on the cmdline\n",
1738*49cdfc7eSAndroid Build Coastguard Worker 			TagName);
1739*49cdfc7eSAndroid Build Coastguard Worker 		exit(1);
1740*49cdfc7eSAndroid Build Coastguard Worker 	}
1741*49cdfc7eSAndroid Build Coastguard Worker 
1742*49cdfc7eSAndroid Build Coastguard Worker 	/*
1743*49cdfc7eSAndroid Build Coastguard Worker 	 * Supply default file io flags - defaut is 'buffered,raw,sync,ldraw'.
1744*49cdfc7eSAndroid Build Coastguard Worker 	 */
1745*49cdfc7eSAndroid Build Coastguard Worker 
1746*49cdfc7eSAndroid Build Coastguard Worker 	if (!f_opt && Fileio) {
1747*49cdfc7eSAndroid Build Coastguard Worker 		Nflags = 0;
1748*49cdfc7eSAndroid Build Coastguard Worker 		Flag_List[Nflags++] = str_lookup(Flag_Map, "buffered");
1749*49cdfc7eSAndroid Build Coastguard Worker 		Flag_List[Nflags++] = str_lookup(Flag_Map, "sync");
1750*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
1751*49cdfc7eSAndroid Build Coastguard Worker 		Flag_List[Nflags++] = str_lookup(Flag_Map, "raw+wf");
1752*49cdfc7eSAndroid Build Coastguard Worker 		Flag_List[Nflags++] = str_lookup(Flag_Map, "ldraw");
1753*49cdfc7eSAndroid Build Coastguard Worker #endif
1754*49cdfc7eSAndroid Build Coastguard Worker 
1755*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
1756*49cdfc7eSAndroid Build Coastguard Worker 		/* Warning: cannot mix direct i/o with others! */
1757*49cdfc7eSAndroid Build Coastguard Worker 		Flag_List[Nflags++] = str_lookup(Flag_Map, "dsync");
1758*49cdfc7eSAndroid Build Coastguard Worker 		Flag_List[Nflags++] = str_lookup(Flag_Map, "rsync");
1759*49cdfc7eSAndroid Build Coastguard Worker 		/* Flag_List[Nflags++] = str_lookup(Flag_Map, "rsync+sync"); */
1760*49cdfc7eSAndroid Build Coastguard Worker 		/* Flag_List[Nflags++] = str_lookup(Flag_Map, "rsync+dsync"); */
1761*49cdfc7eSAndroid Build Coastguard Worker #endif
1762*49cdfc7eSAndroid Build Coastguard Worker 	}
1763*49cdfc7eSAndroid Build Coastguard Worker 
1764*49cdfc7eSAndroid Build Coastguard Worker 	if (Fileio) {
1765*49cdfc7eSAndroid Build Coastguard Worker 		if (optind >= argc) {
1766*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
1767*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  No files listed on the cmdline\n",
1768*49cdfc7eSAndroid Build Coastguard Worker 				TagName);
1769*49cdfc7eSAndroid Build Coastguard Worker 			exit(1);
1770*49cdfc7eSAndroid Build Coastguard Worker 		}
1771*49cdfc7eSAndroid Build Coastguard Worker 
1772*49cdfc7eSAndroid Build Coastguard Worker 		/*
1773*49cdfc7eSAndroid Build Coastguard Worker 		 * Initialize File_List[] - only necessary if doing file io.  First
1774*49cdfc7eSAndroid Build Coastguard Worker 		 * space for the File_List array, then fill it in.
1775*49cdfc7eSAndroid Build Coastguard Worker 		 */
1776*49cdfc7eSAndroid Build Coastguard Worker 
1777*49cdfc7eSAndroid Build Coastguard Worker 		File_List = malloc((argc - optind) * sizeof(struct file_info));
1778*49cdfc7eSAndroid Build Coastguard Worker 
1779*49cdfc7eSAndroid Build Coastguard Worker 		if (File_List == NULL) {
1780*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
1781*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  Could not malloc space for %d file_info structures\n",
1782*49cdfc7eSAndroid Build Coastguard Worker 				TagName, argc - optind);
1783*49cdfc7eSAndroid Build Coastguard Worker 			exit(2);
1784*49cdfc7eSAndroid Build Coastguard Worker 		}
1785*49cdfc7eSAndroid Build Coastguard Worker 
1786*49cdfc7eSAndroid Build Coastguard Worker 		memset(File_List, 0,
1787*49cdfc7eSAndroid Build Coastguard Worker 		       (argc - optind) * sizeof(struct file_info));
1788*49cdfc7eSAndroid Build Coastguard Worker 
1789*49cdfc7eSAndroid Build Coastguard Worker 		Nfiles = 0;
1790*49cdfc7eSAndroid Build Coastguard Worker 		while (optind < argc) {
1791*49cdfc7eSAndroid Build Coastguard Worker 			len = -1;
1792*49cdfc7eSAndroid Build Coastguard Worker 
1793*49cdfc7eSAndroid Build Coastguard Worker 			/*
1794*49cdfc7eSAndroid Build Coastguard Worker 			 * Pick off leading len: if it's there and create/extend/trunc
1795*49cdfc7eSAndroid Build Coastguard Worker 			 * the file to the desired length.  Otherwise, just make sure
1796*49cdfc7eSAndroid Build Coastguard Worker 			 * the file is accessable.
1797*49cdfc7eSAndroid Build Coastguard Worker 			 */
1798*49cdfc7eSAndroid Build Coastguard Worker 
1799*49cdfc7eSAndroid Build Coastguard Worker 			if ((cp = strchr(argv[optind], ':')) != NULL) {
1800*49cdfc7eSAndroid Build Coastguard Worker 				*cp = '\0';
1801*49cdfc7eSAndroid Build Coastguard Worker 				if ((len = bytes_by_prefix(argv[optind])) == -1) {
1802*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1803*49cdfc7eSAndroid Build Coastguard Worker 						"iogen%s:  illegal file length (%s) for file %s\n",
1804*49cdfc7eSAndroid Build Coastguard Worker 						TagName, argv[optind], cp + 1);
1805*49cdfc7eSAndroid Build Coastguard Worker 					exit(2);
1806*49cdfc7eSAndroid Build Coastguard Worker 				}
1807*49cdfc7eSAndroid Build Coastguard Worker 				*cp = ':';
1808*49cdfc7eSAndroid Build Coastguard Worker 				file = cp + 1;
1809*49cdfc7eSAndroid Build Coastguard Worker 
1810*49cdfc7eSAndroid Build Coastguard Worker 				if (strlen(file) > MAX_FNAME_LENGTH) {
1811*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1812*49cdfc7eSAndroid Build Coastguard Worker 						"iogen%s:  Max fname length is %d chars - ignoring file %s\n",
1813*49cdfc7eSAndroid Build Coastguard Worker 						TagName, MAX_FNAME_LENGTH,
1814*49cdfc7eSAndroid Build Coastguard Worker 						file);
1815*49cdfc7eSAndroid Build Coastguard Worker 					optind++;
1816*49cdfc7eSAndroid Build Coastguard Worker 					continue;
1817*49cdfc7eSAndroid Build Coastguard Worker 				}
1818*49cdfc7eSAndroid Build Coastguard Worker 
1819*49cdfc7eSAndroid Build Coastguard Worker 				nb = create_file(file, len);
1820*49cdfc7eSAndroid Build Coastguard Worker 
1821*49cdfc7eSAndroid Build Coastguard Worker 				if (nb < len) {
1822*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1823*49cdfc7eSAndroid Build Coastguard Worker 						"iogen%s warning:  Couldn't create file %s of %d bytes\n",
1824*49cdfc7eSAndroid Build Coastguard Worker 						TagName, file, len);
1825*49cdfc7eSAndroid Build Coastguard Worker 
1826*49cdfc7eSAndroid Build Coastguard Worker 					if (nb <= 0) {
1827*49cdfc7eSAndroid Build Coastguard Worker 						optind++;
1828*49cdfc7eSAndroid Build Coastguard Worker 						continue;
1829*49cdfc7eSAndroid Build Coastguard Worker 					}
1830*49cdfc7eSAndroid Build Coastguard Worker 				}
1831*49cdfc7eSAndroid Build Coastguard Worker 			} else {
1832*49cdfc7eSAndroid Build Coastguard Worker 				file = argv[optind];
1833*49cdfc7eSAndroid Build Coastguard Worker 				if (access(file, R_OK | W_OK) == -1) {
1834*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1835*49cdfc7eSAndroid Build Coastguard Worker 						"iogen%s:  file %s cannot be accessed for reading and/or writing:  %s (%d)\n",
1836*49cdfc7eSAndroid Build Coastguard Worker 						TagName, file, SYSERR, errno);
1837*49cdfc7eSAndroid Build Coastguard Worker 					exit(2);
1838*49cdfc7eSAndroid Build Coastguard Worker 				}
1839*49cdfc7eSAndroid Build Coastguard Worker 			}
1840*49cdfc7eSAndroid Build Coastguard Worker 
1841*49cdfc7eSAndroid Build Coastguard Worker 			/*
1842*49cdfc7eSAndroid Build Coastguard Worker 			 * get per-file information
1843*49cdfc7eSAndroid Build Coastguard Worker 			 */
1844*49cdfc7eSAndroid Build Coastguard Worker 
1845*49cdfc7eSAndroid Build Coastguard Worker 			fptr = &File_List[Nfiles];
1846*49cdfc7eSAndroid Build Coastguard Worker 
1847*49cdfc7eSAndroid Build Coastguard Worker 			if (file[0] == '/') {
1848*49cdfc7eSAndroid Build Coastguard Worker 				strcpy(fptr->f_path, file);
1849*49cdfc7eSAndroid Build Coastguard Worker 			} else {
1850*49cdfc7eSAndroid Build Coastguard Worker 				if (getcwd
1851*49cdfc7eSAndroid Build Coastguard Worker 				    (fptr->f_path,
1852*49cdfc7eSAndroid Build Coastguard Worker 				     sizeof(fptr->f_path) - 1) == NULL)
1853*49cdfc7eSAndroid Build Coastguard Worker 					perror
1854*49cdfc7eSAndroid Build Coastguard Worker 					    ("Could not get current working directory");
1855*49cdfc7eSAndroid Build Coastguard Worker 				strcat(fptr->f_path, "/");
1856*49cdfc7eSAndroid Build Coastguard Worker 				strcat(fptr->f_path, file);
1857*49cdfc7eSAndroid Build Coastguard Worker 			}
1858*49cdfc7eSAndroid Build Coastguard Worker 
1859*49cdfc7eSAndroid Build Coastguard Worker 			if (get_file_info(fptr) == -1) {
1860*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
1861*49cdfc7eSAndroid Build Coastguard Worker 					"iogen%s warning:  Error getting file info for %s\n",
1862*49cdfc7eSAndroid Build Coastguard Worker 					TagName, file);
1863*49cdfc7eSAndroid Build Coastguard Worker 			} else {
1864*49cdfc7eSAndroid Build Coastguard Worker 
1865*49cdfc7eSAndroid Build Coastguard Worker 				/*
1866*49cdfc7eSAndroid Build Coastguard Worker 				 * If the file length is smaller than our min transfer size,
1867*49cdfc7eSAndroid Build Coastguard Worker 				 * ignore it.
1868*49cdfc7eSAndroid Build Coastguard Worker 				 */
1869*49cdfc7eSAndroid Build Coastguard Worker 
1870*49cdfc7eSAndroid Build Coastguard Worker 				if (fptr->f_length < Mintrans) {
1871*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1872*49cdfc7eSAndroid Build Coastguard Worker 						"iogen%s warning:  Ignoring file %s\n",
1873*49cdfc7eSAndroid Build Coastguard Worker 						TagName, fptr->f_path);
1874*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1875*49cdfc7eSAndroid Build Coastguard Worker 						"                length (%d) is < min transfer size (%d)\n",
1876*49cdfc7eSAndroid Build Coastguard Worker 						fptr->f_length, Mintrans);
1877*49cdfc7eSAndroid Build Coastguard Worker 					optind++;
1878*49cdfc7eSAndroid Build Coastguard Worker 					continue;
1879*49cdfc7eSAndroid Build Coastguard Worker 				}
1880*49cdfc7eSAndroid Build Coastguard Worker 
1881*49cdfc7eSAndroid Build Coastguard Worker 				/*
1882*49cdfc7eSAndroid Build Coastguard Worker 				 * If the file length is smaller than our max transfer size,
1883*49cdfc7eSAndroid Build Coastguard Worker 				 * ignore it.
1884*49cdfc7eSAndroid Build Coastguard Worker 				 */
1885*49cdfc7eSAndroid Build Coastguard Worker 
1886*49cdfc7eSAndroid Build Coastguard Worker 				if (fptr->f_length < Maxtrans) {
1887*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1888*49cdfc7eSAndroid Build Coastguard Worker 						"iogen%s warning:  Ignoring file %s\n",
1889*49cdfc7eSAndroid Build Coastguard Worker 						TagName, fptr->f_path);
1890*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(stderr,
1891*49cdfc7eSAndroid Build Coastguard Worker 						"                length (%d) is < max transfer size (%d)\n",
1892*49cdfc7eSAndroid Build Coastguard Worker 						fptr->f_length, Maxtrans);
1893*49cdfc7eSAndroid Build Coastguard Worker 					optind++;
1894*49cdfc7eSAndroid Build Coastguard Worker 					continue;
1895*49cdfc7eSAndroid Build Coastguard Worker 				}
1896*49cdfc7eSAndroid Build Coastguard Worker 
1897*49cdfc7eSAndroid Build Coastguard Worker 				if (fptr->f_length > 0) {
1898*49cdfc7eSAndroid Build Coastguard Worker 					switch (Offset_Mode->m_value) {
1899*49cdfc7eSAndroid Build Coastguard Worker 					case M_SEQUENTIAL:
1900*49cdfc7eSAndroid Build Coastguard Worker 						fptr->f_lastoffset = 0;
1901*49cdfc7eSAndroid Build Coastguard Worker 						fptr->f_lastlength = 0;
1902*49cdfc7eSAndroid Build Coastguard Worker 						break;
1903*49cdfc7eSAndroid Build Coastguard Worker 
1904*49cdfc7eSAndroid Build Coastguard Worker 					case M_REVERSE:
1905*49cdfc7eSAndroid Build Coastguard Worker 						fptr->f_lastoffset =
1906*49cdfc7eSAndroid Build Coastguard Worker 						    fptr->f_length;
1907*49cdfc7eSAndroid Build Coastguard Worker 						fptr->f_lastlength = 0;
1908*49cdfc7eSAndroid Build Coastguard Worker 						break;
1909*49cdfc7eSAndroid Build Coastguard Worker 
1910*49cdfc7eSAndroid Build Coastguard Worker 					case M_RANDOM:
1911*49cdfc7eSAndroid Build Coastguard Worker 						fptr->f_lastoffset =
1912*49cdfc7eSAndroid Build Coastguard Worker 						    fptr->f_length / 2;
1913*49cdfc7eSAndroid Build Coastguard Worker 						fptr->f_lastlength = 0;
1914*49cdfc7eSAndroid Build Coastguard Worker 						break;
1915*49cdfc7eSAndroid Build Coastguard Worker 					}
1916*49cdfc7eSAndroid Build Coastguard Worker 
1917*49cdfc7eSAndroid Build Coastguard Worker 					Nfiles++;
1918*49cdfc7eSAndroid Build Coastguard Worker 				}
1919*49cdfc7eSAndroid Build Coastguard Worker 			}
1920*49cdfc7eSAndroid Build Coastguard Worker 
1921*49cdfc7eSAndroid Build Coastguard Worker 			optind++;
1922*49cdfc7eSAndroid Build Coastguard Worker 		}
1923*49cdfc7eSAndroid Build Coastguard Worker 
1924*49cdfc7eSAndroid Build Coastguard Worker 		if (Nfiles == 0) {
1925*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr,
1926*49cdfc7eSAndroid Build Coastguard Worker 				"iogen%s:  Could not create, or gather info for any test files\n",
1927*49cdfc7eSAndroid Build Coastguard Worker 				TagName);
1928*49cdfc7eSAndroid Build Coastguard Worker 			exit(2);
1929*49cdfc7eSAndroid Build Coastguard Worker 		}
1930*49cdfc7eSAndroid Build Coastguard Worker 	}
1931*49cdfc7eSAndroid Build Coastguard Worker 
1932*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
1933*49cdfc7eSAndroid Build Coastguard Worker }
1934*49cdfc7eSAndroid Build Coastguard Worker 
help(FILE * stream)1935*49cdfc7eSAndroid Build Coastguard Worker int help(FILE * stream)
1936*49cdfc7eSAndroid Build Coastguard Worker {
1937*49cdfc7eSAndroid Build Coastguard Worker 	usage(stream);
1938*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\n");
1939*49cdfc7eSAndroid Build Coastguard Worker #ifndef linux
1940*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1941*49cdfc7eSAndroid Build Coastguard Worker 		"\t-a aio_type,...  Async io completion types to choose.  Supported types\n");
1942*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
1943*49cdfc7eSAndroid Build Coastguard Worker #if _UMK || RELEASE_LEVEL >= 8000
1944*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1945*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 are:  poll, signal, recall, recalla, and recalls.\n");
1946*49cdfc7eSAndroid Build Coastguard Worker #else
1947*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1948*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 are:  poll, signal, recalla, and recalls.\n");
1949*49cdfc7eSAndroid Build Coastguard Worker #endif
1950*49cdfc7eSAndroid Build Coastguard Worker #else
1951*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1952*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 are:  poll, signal, suspend, and callback.\n");
1953*49cdfc7eSAndroid Build Coastguard Worker #endif
1954*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t                 Default is all of the above.\n");
1955*49cdfc7eSAndroid Build Coastguard Worker #else /* !linux */
1956*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t-a               (Not used on Linux).\n");
1957*49cdfc7eSAndroid Build Coastguard Worker #endif /* !linux */
1958*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1959*49cdfc7eSAndroid Build Coastguard Worker 		"\t-f flag,...      Flags to use for file IO.  Supported flags are\n");
1960*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
1961*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1962*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 raw, ssd, buffered, ldraw, sync,\n");
1963*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1964*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 raw+wf, raw+wf+ldraw, raw+wf+ldraw+sync,\n");
1965*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1966*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 and parallel (unicos/mk on MPP only).\n");
1967*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1968*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 Default is 'raw,ldraw,sync,buffered'.\n");
1969*49cdfc7eSAndroid Build Coastguard Worker #else
1970*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
1971*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1972*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 buffered, direct, sync, dsync, rsync,\n");
1973*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t                 rsync+dsync.\n");
1974*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1975*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 Default is 'buffered,sync,dsync,rsync'.\n");
1976*49cdfc7eSAndroid Build Coastguard Worker #else
1977*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t                 buffered, sync.\n");
1978*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t                 Default is 'buffered,sync'.\n");
1979*49cdfc7eSAndroid Build Coastguard Worker #endif /* sgi */
1980*49cdfc7eSAndroid Build Coastguard Worker #endif /* CRAY */
1981*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t-h               This help.\n");
1982*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1983*49cdfc7eSAndroid Build Coastguard Worker 		"\t-i iterations[s] # of requests to generate.  0 means causes iogen\n");
1984*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1985*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 to run until it's killed.  If iterations is suffixed\n");
1986*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1987*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 with 's', then iterations is the number of seconds\n");
1988*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1989*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 that iogen should run for.  Default is '0'.\n");
1990*49cdfc7eSAndroid Build Coastguard Worker #ifndef linux
1991*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1992*49cdfc7eSAndroid Build Coastguard Worker 		"\t-L min:max       listio nstrides / nrequests range\n");
1993*49cdfc7eSAndroid Build Coastguard Worker #else
1994*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t-L               (Not used on Linux).\n");
1995*49cdfc7eSAndroid Build Coastguard Worker #endif /* !linux */
1996*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1997*49cdfc7eSAndroid Build Coastguard Worker 		"\t-m offset-mode   The mode by which iogen chooses the offset for\n");
1998*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
1999*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 consectutive transfers within a given file.\n");
2000*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2001*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 Allowed values are 'random', 'sequential',\n");
2002*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t                 and 'reverse'.\n");
2003*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t                 sequential is the default.\n");
2004*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t-N tagname       Tag name, for Monster.\n");
2005*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2006*49cdfc7eSAndroid Build Coastguard Worker 		"\t-o               Form overlapping consecutive requests.\n");
2007*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t-O               Open flags for creating files\n");
2008*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
2009*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2010*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 {O_PLACE,O_BIG,etc}[:CBITS[:CBLKS]]\n");
2011*49cdfc7eSAndroid Build Coastguard Worker #endif
2012*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
2013*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2014*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 realtime:extsize - put file on real-time volume\n");
2015*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2016*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 allocate - allocate space with F_ALLOCSP\n");
2017*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2018*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 reserve - reserve space with F_RESVSP (default)\n");
2019*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2020*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 noreserve - do not reserve with F_RESVSP\n");
2021*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2022*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 direct - use O_DIRECT I/O to write to the file\n");
2023*49cdfc7eSAndroid Build Coastguard Worker #endif
2024*49cdfc7eSAndroid Build Coastguard Worker #ifdef linux
2025*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t                 {O_SYNC,etc}\n");
2026*49cdfc7eSAndroid Build Coastguard Worker #endif
2027*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2028*49cdfc7eSAndroid Build Coastguard Worker 		"\t-p               Output pipe.  Default is stdout.\n");
2029*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2030*49cdfc7eSAndroid Build Coastguard Worker 		"\t-q               Quiet mode.  Normally iogen spits out info\n");
2031*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2032*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 about test files, options, etc. before starting.\n");
2033*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2034*49cdfc7eSAndroid Build Coastguard Worker 		"\t-s syscall,...   Syscalls to do.  Supported syscalls are\n");
2035*49cdfc7eSAndroid Build Coastguard Worker #ifdef sgi
2036*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2037*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 read, write, pread, pwrite, readv, writev\n");
2038*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2039*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 aread, awrite, resvsp, unresvsp, ffsync,\n");
2040*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2041*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 mmread, mmwrite, fsync2, fdatasync,\n");
2042*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2043*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 Default is 'read,write,pread,pwrite,readv,writev,mmread,mmwrite'.\n");
2044*49cdfc7eSAndroid Build Coastguard Worker #endif
2045*49cdfc7eSAndroid Build Coastguard Worker #ifdef CRAY
2046*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2047*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 read, write, reada, writea, listio,\n");
2048*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2049*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 ssread (PVP only), and sswrite (PVP only).\n");
2050*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2051*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 Default is 'read,write,reada,writea,listio'.\n");
2052*49cdfc7eSAndroid Build Coastguard Worker #endif
2053*49cdfc7eSAndroid Build Coastguard Worker #ifdef linux
2054*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t                 read, write, readv, writev,\n");
2055*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2056*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 mmread, mmwrite, fsync2, fdatasync,\n");
2057*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2058*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 Default is 'read,write,readv,writev,mmread,mmwrite'.\n");
2059*49cdfc7eSAndroid Build Coastguard Worker #endif
2060*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t-t mintrans      Min transfer length\n");
2061*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t-T maxtrans      Max transfer length\n");
2062*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\n");
2063*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2064*49cdfc7eSAndroid Build Coastguard Worker 		"\t[len:]file,...   Test files to do IO against (note ssread/sswrite\n");
2065*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2066*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 don't need a test file).  The len: syntax\n");
2067*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2068*49cdfc7eSAndroid Build Coastguard Worker 		"\t                 informs iogen to first create/expand/truncate the\n");
2069*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\t                 to the desired length.\n");
2070*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream, "\n");
2071*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2072*49cdfc7eSAndroid Build Coastguard Worker 		"\tNote:  The ssd flag causes sds transfers to also be done.\n");
2073*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2074*49cdfc7eSAndroid Build Coastguard Worker 		"\t       To totally eliminate sds transfers, you must eleminate sds\n");
2075*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2076*49cdfc7eSAndroid Build Coastguard Worker 		"\t       from the flags (-f) and ssread,ssrite from the syscalls (-s)\n");
2077*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2078*49cdfc7eSAndroid Build Coastguard Worker 		"\tThe mintrans, maxtrans, and len: parameters are numbers of the\n");
2079*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2080*49cdfc7eSAndroid Build Coastguard Worker 		"\tform [0-9]+[bkm].  The optional trailing b, k, or m multiplies\n");
2081*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2082*49cdfc7eSAndroid Build Coastguard Worker 		"\tthe number by blocks, kilobytes, or megabytes.  If no trailing\n");
2083*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2084*49cdfc7eSAndroid Build Coastguard Worker 		"\tmultiplier is present, the number is interpreted as bytes\n");
2085*49cdfc7eSAndroid Build Coastguard Worker 
2086*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
2087*49cdfc7eSAndroid Build Coastguard Worker }
2088*49cdfc7eSAndroid Build Coastguard Worker 
2089*49cdfc7eSAndroid Build Coastguard Worker /*
2090*49cdfc7eSAndroid Build Coastguard Worker  * Obvious - usage clause
2091*49cdfc7eSAndroid Build Coastguard Worker  */
2092*49cdfc7eSAndroid Build Coastguard Worker 
usage(FILE * stream)2093*49cdfc7eSAndroid Build Coastguard Worker int usage(FILE * stream)
2094*49cdfc7eSAndroid Build Coastguard Worker {
2095*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stream,
2096*49cdfc7eSAndroid Build Coastguard Worker 		"usage%s:  iogen [-hoq] [-a aio_type,...] [-f flag[,flag...]] [-i iterations] [-p outpipe] [-m offset-mode] [-s syscall[,syscall...]] [-t mintrans] [-T maxtrans] [ -O file-create-flags ] [[len:]file ...]\n",
2097*49cdfc7eSAndroid Build Coastguard Worker 		TagName);
2098*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
2099*49cdfc7eSAndroid Build Coastguard Worker }
2100