xref: /aosp_15_r20/external/ltp/testcases/kernel/fs/fsstress/fsstress.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/SGIGPLNoticeExplan/
31*49cdfc7eSAndroid Build Coastguard Worker  */
32*49cdfc7eSAndroid Build Coastguard Worker 
33*49cdfc7eSAndroid Build Coastguard Worker #include "config.h"
34*49cdfc7eSAndroid Build Coastguard Worker #include "global.h"
35*49cdfc7eSAndroid Build Coastguard Worker #include "tst_common.h"
36*49cdfc7eSAndroid Build Coastguard Worker 
37*49cdfc7eSAndroid Build Coastguard Worker #ifdef HAVE_SYS_PRCTL_H
38*49cdfc7eSAndroid Build Coastguard Worker # include <sys/prctl.h>
39*49cdfc7eSAndroid Build Coastguard Worker #endif
40*49cdfc7eSAndroid Build Coastguard Worker #include <limits.h>
41*49cdfc7eSAndroid Build Coastguard Worker 
42*49cdfc7eSAndroid Build Coastguard Worker #define XFS_ERRTAG_MAX		17
43*49cdfc7eSAndroid Build Coastguard Worker 
44*49cdfc7eSAndroid Build Coastguard Worker typedef enum {
45*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
46*49cdfc7eSAndroid Build Coastguard Worker 	OP_ALLOCSP,
47*49cdfc7eSAndroid Build Coastguard Worker 	OP_ATTR_REMOVE,
48*49cdfc7eSAndroid Build Coastguard Worker 	OP_ATTR_SET,
49*49cdfc7eSAndroid Build Coastguard Worker 	OP_BULKSTAT,
50*49cdfc7eSAndroid Build Coastguard Worker 	OP_BULKSTAT1,
51*49cdfc7eSAndroid Build Coastguard Worker #endif
52*49cdfc7eSAndroid Build Coastguard Worker 	OP_CHOWN,
53*49cdfc7eSAndroid Build Coastguard Worker 	OP_CREAT,
54*49cdfc7eSAndroid Build Coastguard Worker 	OP_DREAD,
55*49cdfc7eSAndroid Build Coastguard Worker 	OP_DWRITE,
56*49cdfc7eSAndroid Build Coastguard Worker 	OP_FDATASYNC,
57*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
58*49cdfc7eSAndroid Build Coastguard Worker 	OP_FREESP,
59*49cdfc7eSAndroid Build Coastguard Worker #endif
60*49cdfc7eSAndroid Build Coastguard Worker 	OP_FSYNC,
61*49cdfc7eSAndroid Build Coastguard Worker 	OP_GETDENTS,
62*49cdfc7eSAndroid Build Coastguard Worker 	OP_LINK,
63*49cdfc7eSAndroid Build Coastguard Worker 	OP_MKDIR,
64*49cdfc7eSAndroid Build Coastguard Worker 	OP_MKNOD,
65*49cdfc7eSAndroid Build Coastguard Worker 	OP_READ,
66*49cdfc7eSAndroid Build Coastguard Worker 	OP_READLINK,
67*49cdfc7eSAndroid Build Coastguard Worker 	OP_RENAME,
68*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
69*49cdfc7eSAndroid Build Coastguard Worker 	OP_RESVSP,
70*49cdfc7eSAndroid Build Coastguard Worker #endif
71*49cdfc7eSAndroid Build Coastguard Worker 	OP_RMDIR,
72*49cdfc7eSAndroid Build Coastguard Worker 	OP_STAT,
73*49cdfc7eSAndroid Build Coastguard Worker 	OP_SYMLINK,
74*49cdfc7eSAndroid Build Coastguard Worker 	OP_SYNC,
75*49cdfc7eSAndroid Build Coastguard Worker 	OP_TRUNCATE,
76*49cdfc7eSAndroid Build Coastguard Worker 	OP_UNLINK,
77*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
78*49cdfc7eSAndroid Build Coastguard Worker 	OP_UNRESVSP,
79*49cdfc7eSAndroid Build Coastguard Worker #endif
80*49cdfc7eSAndroid Build Coastguard Worker 	OP_WRITE,
81*49cdfc7eSAndroid Build Coastguard Worker 	OP_LAST
82*49cdfc7eSAndroid Build Coastguard Worker } opty_t;
83*49cdfc7eSAndroid Build Coastguard Worker 
84*49cdfc7eSAndroid Build Coastguard Worker typedef void (*opfnc_t) (int, long);
85*49cdfc7eSAndroid Build Coastguard Worker 
86*49cdfc7eSAndroid Build Coastguard Worker typedef struct opdesc {
87*49cdfc7eSAndroid Build Coastguard Worker 	opty_t op;
88*49cdfc7eSAndroid Build Coastguard Worker 	char *name;
89*49cdfc7eSAndroid Build Coastguard Worker 	opfnc_t func;
90*49cdfc7eSAndroid Build Coastguard Worker 	int freq;
91*49cdfc7eSAndroid Build Coastguard Worker 	int iswrite;
92*49cdfc7eSAndroid Build Coastguard Worker 	int isxfs;
93*49cdfc7eSAndroid Build Coastguard Worker } opdesc_t;
94*49cdfc7eSAndroid Build Coastguard Worker 
95*49cdfc7eSAndroid Build Coastguard Worker typedef struct fent {
96*49cdfc7eSAndroid Build Coastguard Worker 	int id;
97*49cdfc7eSAndroid Build Coastguard Worker 	int parent;
98*49cdfc7eSAndroid Build Coastguard Worker } fent_t;
99*49cdfc7eSAndroid Build Coastguard Worker 
100*49cdfc7eSAndroid Build Coastguard Worker typedef struct flist {
101*49cdfc7eSAndroid Build Coastguard Worker 	int nfiles;
102*49cdfc7eSAndroid Build Coastguard Worker 	int nslots;
103*49cdfc7eSAndroid Build Coastguard Worker 	int tag;
104*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fents;
105*49cdfc7eSAndroid Build Coastguard Worker } flist_t;
106*49cdfc7eSAndroid Build Coastguard Worker 
107*49cdfc7eSAndroid Build Coastguard Worker typedef struct pathname {
108*49cdfc7eSAndroid Build Coastguard Worker 	int len;
109*49cdfc7eSAndroid Build Coastguard Worker 	char *path;
110*49cdfc7eSAndroid Build Coastguard Worker } pathname_t;
111*49cdfc7eSAndroid Build Coastguard Worker 
112*49cdfc7eSAndroid Build Coastguard Worker #define	FT_DIR	0
113*49cdfc7eSAndroid Build Coastguard Worker #define	FT_DIRm	(1 << FT_DIR)
114*49cdfc7eSAndroid Build Coastguard Worker #define	FT_REG	1
115*49cdfc7eSAndroid Build Coastguard Worker #define	FT_REGm	(1 << FT_REG)
116*49cdfc7eSAndroid Build Coastguard Worker #define	FT_SYM	2
117*49cdfc7eSAndroid Build Coastguard Worker #define	FT_SYMm	(1 << FT_SYM)
118*49cdfc7eSAndroid Build Coastguard Worker #define	FT_DEV	3
119*49cdfc7eSAndroid Build Coastguard Worker #define	FT_DEVm	(1 << FT_DEV)
120*49cdfc7eSAndroid Build Coastguard Worker #define	FT_RTF	4
121*49cdfc7eSAndroid Build Coastguard Worker #define	FT_RTFm	(1 << FT_RTF)
122*49cdfc7eSAndroid Build Coastguard Worker #define	FT_nft	5
123*49cdfc7eSAndroid Build Coastguard Worker #define	FT_ANYm	((1 << FT_nft) - 1)
124*49cdfc7eSAndroid Build Coastguard Worker #define	FT_REGFILE	(FT_REGm | FT_RTFm)
125*49cdfc7eSAndroid Build Coastguard Worker #define	FT_NOTDIR	(FT_ANYm & ~FT_DIRm)
126*49cdfc7eSAndroid Build Coastguard Worker 
127*49cdfc7eSAndroid Build Coastguard Worker #define	FLIST_SLOT_INCR	16
128*49cdfc7eSAndroid Build Coastguard Worker #define	NDCACHE	64
129*49cdfc7eSAndroid Build Coastguard Worker 
130*49cdfc7eSAndroid Build Coastguard Worker #define	MAXFSIZE	((1ULL << 63) - 1ULL)
131*49cdfc7eSAndroid Build Coastguard Worker #define	MAXFSIZE32	((1ULL << 40) - 1ULL)
132*49cdfc7eSAndroid Build Coastguard Worker 
133*49cdfc7eSAndroid Build Coastguard Worker void allocsp_f(int, long);
134*49cdfc7eSAndroid Build Coastguard Worker void attr_remove_f(int, long);
135*49cdfc7eSAndroid Build Coastguard Worker void attr_set_f(int, long);
136*49cdfc7eSAndroid Build Coastguard Worker void bulkstat_f(int, long);
137*49cdfc7eSAndroid Build Coastguard Worker void bulkstat1_f(int, long);
138*49cdfc7eSAndroid Build Coastguard Worker void chown_f(int, long);
139*49cdfc7eSAndroid Build Coastguard Worker void creat_f(int, long);
140*49cdfc7eSAndroid Build Coastguard Worker void dread_f(int, long);
141*49cdfc7eSAndroid Build Coastguard Worker void dwrite_f(int, long);
142*49cdfc7eSAndroid Build Coastguard Worker void fdatasync_f(int, long);
143*49cdfc7eSAndroid Build Coastguard Worker void freesp_f(int, long);
144*49cdfc7eSAndroid Build Coastguard Worker void fsync_f(int, long);
145*49cdfc7eSAndroid Build Coastguard Worker void getdents_f(int, long);
146*49cdfc7eSAndroid Build Coastguard Worker void link_f(int, long);
147*49cdfc7eSAndroid Build Coastguard Worker void mkdir_f(int, long);
148*49cdfc7eSAndroid Build Coastguard Worker void mknod_f(int, long);
149*49cdfc7eSAndroid Build Coastguard Worker void read_f(int, long);
150*49cdfc7eSAndroid Build Coastguard Worker void readlink_f(int, long);
151*49cdfc7eSAndroid Build Coastguard Worker void rename_f(int, long);
152*49cdfc7eSAndroid Build Coastguard Worker void resvsp_f(int, long);
153*49cdfc7eSAndroid Build Coastguard Worker void rmdir_f(int, long);
154*49cdfc7eSAndroid Build Coastguard Worker void stat_f(int, long);
155*49cdfc7eSAndroid Build Coastguard Worker void symlink_f(int, long);
156*49cdfc7eSAndroid Build Coastguard Worker void sync_f(int, long);
157*49cdfc7eSAndroid Build Coastguard Worker void truncate_f(int, long);
158*49cdfc7eSAndroid Build Coastguard Worker void unlink_f(int, long);
159*49cdfc7eSAndroid Build Coastguard Worker void unresvsp_f(int, long);
160*49cdfc7eSAndroid Build Coastguard Worker void write_f(int, long);
161*49cdfc7eSAndroid Build Coastguard Worker 
162*49cdfc7eSAndroid Build Coastguard Worker opdesc_t ops[] = {
163*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
164*49cdfc7eSAndroid Build Coastguard Worker 	{OP_ALLOCSP, "allocsp", allocsp_f, 1, 1, 1},
165*49cdfc7eSAndroid Build Coastguard Worker 	{OP_ATTR_REMOVE, "attr_remove", attr_remove_f, /* 1 */ 0, 1, 1},
166*49cdfc7eSAndroid Build Coastguard Worker 	{OP_ATTR_SET, "attr_set", attr_set_f, /* 2 */ 0, 1, 1},
167*49cdfc7eSAndroid Build Coastguard Worker 	{OP_BULKSTAT, "bulkstat", bulkstat_f, 1, 0, 1},
168*49cdfc7eSAndroid Build Coastguard Worker 	{OP_BULKSTAT1, "bulkstat1", bulkstat1_f, 1, 0, 1},
169*49cdfc7eSAndroid Build Coastguard Worker #endif
170*49cdfc7eSAndroid Build Coastguard Worker 	{OP_CHOWN, "chown", chown_f, 3, 1, 0},
171*49cdfc7eSAndroid Build Coastguard Worker 	{OP_CREAT, "creat", creat_f, 4, 1, 0},
172*49cdfc7eSAndroid Build Coastguard Worker 	{OP_DREAD, "dread", dread_f, 4, 0, 0},
173*49cdfc7eSAndroid Build Coastguard Worker 	{OP_DWRITE, "dwrite", dwrite_f, 4, 1, 0},
174*49cdfc7eSAndroid Build Coastguard Worker 	{OP_FDATASYNC, "fdatasync", fdatasync_f, 1, 1, 0},
175*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
176*49cdfc7eSAndroid Build Coastguard Worker 	{OP_FREESP, "freesp", freesp_f, 1, 1, 1},
177*49cdfc7eSAndroid Build Coastguard Worker #endif
178*49cdfc7eSAndroid Build Coastguard Worker 	{OP_FSYNC, "fsync", fsync_f, 1, 1, 0},
179*49cdfc7eSAndroid Build Coastguard Worker 	{OP_GETDENTS, "getdents", getdents_f, 1, 0, 0},
180*49cdfc7eSAndroid Build Coastguard Worker 	{OP_LINK, "link", link_f, 1, 1, 0},
181*49cdfc7eSAndroid Build Coastguard Worker 	{OP_MKDIR, "mkdir", mkdir_f, 2, 1, 0},
182*49cdfc7eSAndroid Build Coastguard Worker 	{OP_MKNOD, "mknod", mknod_f, 2, 1, 0},
183*49cdfc7eSAndroid Build Coastguard Worker 	{OP_READ, "read", read_f, 1, 0, 0},
184*49cdfc7eSAndroid Build Coastguard Worker 	{OP_READLINK, "readlink", readlink_f, 1, 0, 0},
185*49cdfc7eSAndroid Build Coastguard Worker 	{OP_RENAME, "rename", rename_f, 2, 1, 0},
186*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
187*49cdfc7eSAndroid Build Coastguard Worker 	{OP_RESVSP, "resvsp", resvsp_f, 1, 1, 1},
188*49cdfc7eSAndroid Build Coastguard Worker #endif
189*49cdfc7eSAndroid Build Coastguard Worker 	{OP_RMDIR, "rmdir", rmdir_f, 1, 1, 0},
190*49cdfc7eSAndroid Build Coastguard Worker 	{OP_STAT, "stat", stat_f, 1, 0, 0},
191*49cdfc7eSAndroid Build Coastguard Worker 	{OP_SYMLINK, "symlink", symlink_f, 2, 1, 0},
192*49cdfc7eSAndroid Build Coastguard Worker 	{OP_SYNC, "sync", sync_f, 1, 0, 0},
193*49cdfc7eSAndroid Build Coastguard Worker 	{OP_TRUNCATE, "truncate", truncate_f, 2, 1, 0},
194*49cdfc7eSAndroid Build Coastguard Worker 	{OP_UNLINK, "unlink", unlink_f, 1, 1, 0},
195*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
196*49cdfc7eSAndroid Build Coastguard Worker 	{OP_UNRESVSP, "unresvsp", unresvsp_f, 1, 1, 1},
197*49cdfc7eSAndroid Build Coastguard Worker #endif
198*49cdfc7eSAndroid Build Coastguard Worker 	{OP_WRITE, "write", write_f, 4, 1, 0},
199*49cdfc7eSAndroid Build Coastguard Worker }, *ops_end;
200*49cdfc7eSAndroid Build Coastguard Worker 
201*49cdfc7eSAndroid Build Coastguard Worker flist_t flist[FT_nft] = {
202*49cdfc7eSAndroid Build Coastguard Worker 	{0, 0, 'd', NULL},
203*49cdfc7eSAndroid Build Coastguard Worker 	{0, 0, 'f', NULL},
204*49cdfc7eSAndroid Build Coastguard Worker 	{0, 0, 'l', NULL},
205*49cdfc7eSAndroid Build Coastguard Worker 	{0, 0, 'c', NULL},
206*49cdfc7eSAndroid Build Coastguard Worker 	{0, 0, 'r', NULL},
207*49cdfc7eSAndroid Build Coastguard Worker };
208*49cdfc7eSAndroid Build Coastguard Worker 
209*49cdfc7eSAndroid Build Coastguard Worker int dcache[NDCACHE];
210*49cdfc7eSAndroid Build Coastguard Worker int errrange;
211*49cdfc7eSAndroid Build Coastguard Worker int errtag;
212*49cdfc7eSAndroid Build Coastguard Worker opty_t *freq_table;
213*49cdfc7eSAndroid Build Coastguard Worker int freq_table_size;
214*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
215*49cdfc7eSAndroid Build Coastguard Worker xfs_fsop_geom_t geom;
216*49cdfc7eSAndroid Build Coastguard Worker #endif
217*49cdfc7eSAndroid Build Coastguard Worker char *homedir;
218*49cdfc7eSAndroid Build Coastguard Worker int *ilist;
219*49cdfc7eSAndroid Build Coastguard Worker int ilistlen;
220*49cdfc7eSAndroid Build Coastguard Worker off64_t maxfsize;
221*49cdfc7eSAndroid Build Coastguard Worker char *myprog;
222*49cdfc7eSAndroid Build Coastguard Worker int namerand;
223*49cdfc7eSAndroid Build Coastguard Worker int nameseq;
224*49cdfc7eSAndroid Build Coastguard Worker int nops;
225*49cdfc7eSAndroid Build Coastguard Worker int nproc = 1;
226*49cdfc7eSAndroid Build Coastguard Worker int operations = 1;
227*49cdfc7eSAndroid Build Coastguard Worker int procid;
228*49cdfc7eSAndroid Build Coastguard Worker int rtpct;
229*49cdfc7eSAndroid Build Coastguard Worker unsigned long seed = 0;
230*49cdfc7eSAndroid Build Coastguard Worker ino_t top_ino;
231*49cdfc7eSAndroid Build Coastguard Worker int verbose = 0;
232*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
233*49cdfc7eSAndroid Build Coastguard Worker int no_xfs = 0;
234*49cdfc7eSAndroid Build Coastguard Worker #else
235*49cdfc7eSAndroid Build Coastguard Worker int no_xfs = 1;
236*49cdfc7eSAndroid Build Coastguard Worker #endif
237*49cdfc7eSAndroid Build Coastguard Worker sig_atomic_t should_stop = 0;
238*49cdfc7eSAndroid Build Coastguard Worker 
239*49cdfc7eSAndroid Build Coastguard Worker void add_to_flist(int, int, int);
240*49cdfc7eSAndroid Build Coastguard Worker void append_pathname(pathname_t *, char *);
241*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
242*49cdfc7eSAndroid Build Coastguard Worker int attr_list_path(pathname_t *, char *, const int, int, attrlist_cursor_t *);
243*49cdfc7eSAndroid Build Coastguard Worker int attr_remove_path(pathname_t *, const char *, int);
244*49cdfc7eSAndroid Build Coastguard Worker int attr_set_path(pathname_t *, const char *, const char *, const int, int);
245*49cdfc7eSAndroid Build Coastguard Worker #endif
246*49cdfc7eSAndroid Build Coastguard Worker void check_cwd(void);
247*49cdfc7eSAndroid Build Coastguard Worker int creat_path(pathname_t *, mode_t);
248*49cdfc7eSAndroid Build Coastguard Worker void dcache_enter(int, int);
249*49cdfc7eSAndroid Build Coastguard Worker void dcache_init(void);
250*49cdfc7eSAndroid Build Coastguard Worker fent_t *dcache_lookup(int);
251*49cdfc7eSAndroid Build Coastguard Worker void dcache_purge(int);
252*49cdfc7eSAndroid Build Coastguard Worker void del_from_flist(int, int);
253*49cdfc7eSAndroid Build Coastguard Worker int dirid_to_name(char *, int);
254*49cdfc7eSAndroid Build Coastguard Worker void doproc(void);
255*49cdfc7eSAndroid Build Coastguard Worker void fent_to_name(pathname_t *, flist_t *, fent_t *);
256*49cdfc7eSAndroid Build Coastguard Worker void fix_parent(int, int);
257*49cdfc7eSAndroid Build Coastguard Worker void free_pathname(pathname_t *);
258*49cdfc7eSAndroid Build Coastguard Worker int generate_fname(fent_t *, int, pathname_t *, int *, int *);
259*49cdfc7eSAndroid Build Coastguard Worker int get_fname(int, long, pathname_t *, flist_t **, fent_t **, int *);
260*49cdfc7eSAndroid Build Coastguard Worker void init_pathname(pathname_t *);
261*49cdfc7eSAndroid Build Coastguard Worker int lchown_path(pathname_t *, uid_t, gid_t);
262*49cdfc7eSAndroid Build Coastguard Worker int link_path(pathname_t *, pathname_t *);
263*49cdfc7eSAndroid Build Coastguard Worker int lstat64_path(pathname_t *, struct stat64 *);
264*49cdfc7eSAndroid Build Coastguard Worker void make_freq_table(void);
265*49cdfc7eSAndroid Build Coastguard Worker int mkdir_path(pathname_t *, mode_t);
266*49cdfc7eSAndroid Build Coastguard Worker int mknod_path(pathname_t *, mode_t, dev_t);
267*49cdfc7eSAndroid Build Coastguard Worker void namerandpad(int, char *, int);
268*49cdfc7eSAndroid Build Coastguard Worker int open_path(pathname_t *, int);
269*49cdfc7eSAndroid Build Coastguard Worker DIR *opendir_path(pathname_t *);
270*49cdfc7eSAndroid Build Coastguard Worker void process_freq(char *);
271*49cdfc7eSAndroid Build Coastguard Worker int readlink_path(pathname_t *, char *, size_t);
272*49cdfc7eSAndroid Build Coastguard Worker int rename_path(pathname_t *, pathname_t *);
273*49cdfc7eSAndroid Build Coastguard Worker int rmdir_path(pathname_t *);
274*49cdfc7eSAndroid Build Coastguard Worker void separate_pathname(pathname_t *, char *, pathname_t *);
275*49cdfc7eSAndroid Build Coastguard Worker void show_ops(int, char *);
276*49cdfc7eSAndroid Build Coastguard Worker int stat64_path(pathname_t *, struct stat64 *);
277*49cdfc7eSAndroid Build Coastguard Worker int symlink_path(const char *, pathname_t *);
278*49cdfc7eSAndroid Build Coastguard Worker int truncate64_path(pathname_t *, off64_t);
279*49cdfc7eSAndroid Build Coastguard Worker int unlink_path(pathname_t *);
280*49cdfc7eSAndroid Build Coastguard Worker void usage(void);
281*49cdfc7eSAndroid Build Coastguard Worker void write_freq(void);
282*49cdfc7eSAndroid Build Coastguard Worker void zero_freq(void);
283*49cdfc7eSAndroid Build Coastguard Worker 
sg_handler(int signum)284*49cdfc7eSAndroid Build Coastguard Worker void sg_handler(int signum __attribute__((unused)))
285*49cdfc7eSAndroid Build Coastguard Worker {
286*49cdfc7eSAndroid Build Coastguard Worker 	should_stop = 1;
287*49cdfc7eSAndroid Build Coastguard Worker }
288*49cdfc7eSAndroid Build Coastguard Worker 
main(int argc,char ** argv)289*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char **argv)
290*49cdfc7eSAndroid Build Coastguard Worker {
291*49cdfc7eSAndroid Build Coastguard Worker 	char buf[10];
292*49cdfc7eSAndroid Build Coastguard Worker 	int c;
293*49cdfc7eSAndroid Build Coastguard Worker 	char *dirname = NULL;
294*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
295*49cdfc7eSAndroid Build Coastguard Worker 	int i;
296*49cdfc7eSAndroid Build Coastguard Worker 	int cleanup = 0;
297*49cdfc7eSAndroid Build Coastguard Worker 	int loops = 1;
298*49cdfc7eSAndroid Build Coastguard Worker 	int loopcntr = 1;
299*49cdfc7eSAndroid Build Coastguard Worker 	char cmd[256];
300*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
301*49cdfc7eSAndroid Build Coastguard Worker 	int j;
302*49cdfc7eSAndroid Build Coastguard Worker #endif
303*49cdfc7eSAndroid Build Coastguard Worker 	char *p;
304*49cdfc7eSAndroid Build Coastguard Worker 	int stat;
305*49cdfc7eSAndroid Build Coastguard Worker 	struct timeval t;
306*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
307*49cdfc7eSAndroid Build Coastguard Worker 	ptrdiff_t srval;
308*49cdfc7eSAndroid Build Coastguard Worker #endif
309*49cdfc7eSAndroid Build Coastguard Worker 	int nousage = 0;
310*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
311*49cdfc7eSAndroid Build Coastguard Worker 	xfs_error_injection_t err_inj;
312*49cdfc7eSAndroid Build Coastguard Worker #endif
313*49cdfc7eSAndroid Build Coastguard Worker 	struct sigaction action;
314*49cdfc7eSAndroid Build Coastguard Worker 
315*49cdfc7eSAndroid Build Coastguard Worker 	errrange = errtag = 0;
316*49cdfc7eSAndroid Build Coastguard Worker 	umask(0);
317*49cdfc7eSAndroid Build Coastguard Worker 	nops = ARRAY_SIZE(ops);
318*49cdfc7eSAndroid Build Coastguard Worker 	ops_end = &ops[nops];
319*49cdfc7eSAndroid Build Coastguard Worker 	myprog = argv[0];
320*49cdfc7eSAndroid Build Coastguard Worker 	while ((c = getopt(argc, argv, "cd:e:f:i:l:n:p:rs:vwzHSX")) != -1) {
321*49cdfc7eSAndroid Build Coastguard Worker 		switch (c) {
322*49cdfc7eSAndroid Build Coastguard Worker 		case 'c':
323*49cdfc7eSAndroid Build Coastguard Worker 			/*Don't cleanup */
324*49cdfc7eSAndroid Build Coastguard Worker 			cleanup = 1;
325*49cdfc7eSAndroid Build Coastguard Worker 			break;
326*49cdfc7eSAndroid Build Coastguard Worker 		case 'd':
327*49cdfc7eSAndroid Build Coastguard Worker 			dirname = optarg;
328*49cdfc7eSAndroid Build Coastguard Worker 			break;
329*49cdfc7eSAndroid Build Coastguard Worker 		case 'e':
330*49cdfc7eSAndroid Build Coastguard Worker 			sscanf(optarg, "%d", &errtag);
331*49cdfc7eSAndroid Build Coastguard Worker 			if (errtag < 0) {
332*49cdfc7eSAndroid Build Coastguard Worker 				errtag = -errtag;
333*49cdfc7eSAndroid Build Coastguard Worker 				errrange = 1;
334*49cdfc7eSAndroid Build Coastguard Worker 			} else if (errtag == 0)
335*49cdfc7eSAndroid Build Coastguard Worker 				errtag = -1;
336*49cdfc7eSAndroid Build Coastguard Worker 			if (errtag >= XFS_ERRTAG_MAX) {
337*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr,
338*49cdfc7eSAndroid Build Coastguard Worker 					"error tag %d too large (max %d)\n",
339*49cdfc7eSAndroid Build Coastguard Worker 					errtag, XFS_ERRTAG_MAX - 1);
340*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
341*49cdfc7eSAndroid Build Coastguard Worker 			}
342*49cdfc7eSAndroid Build Coastguard Worker 			break;
343*49cdfc7eSAndroid Build Coastguard Worker 		case 'f':
344*49cdfc7eSAndroid Build Coastguard Worker 			process_freq(optarg);
345*49cdfc7eSAndroid Build Coastguard Worker 			break;
346*49cdfc7eSAndroid Build Coastguard Worker 		case 'i':
347*49cdfc7eSAndroid Build Coastguard Worker 			ilist = realloc(ilist, ++ilistlen * sizeof(*ilist));
348*49cdfc7eSAndroid Build Coastguard Worker 			ilist[ilistlen - 1] = strtol(optarg, &p, 16);
349*49cdfc7eSAndroid Build Coastguard Worker 			break;
350*49cdfc7eSAndroid Build Coastguard Worker 		case 'l':
351*49cdfc7eSAndroid Build Coastguard Worker 			loops = atoi(optarg);
352*49cdfc7eSAndroid Build Coastguard Worker 			break;
353*49cdfc7eSAndroid Build Coastguard Worker 		case 'n':
354*49cdfc7eSAndroid Build Coastguard Worker 			operations = atoi(optarg);
355*49cdfc7eSAndroid Build Coastguard Worker 			break;
356*49cdfc7eSAndroid Build Coastguard Worker 		case 'p':
357*49cdfc7eSAndroid Build Coastguard Worker 			nproc = atoi(optarg);
358*49cdfc7eSAndroid Build Coastguard Worker 			break;
359*49cdfc7eSAndroid Build Coastguard Worker 		case 'r':
360*49cdfc7eSAndroid Build Coastguard Worker 			namerand = 1;
361*49cdfc7eSAndroid Build Coastguard Worker 			break;
362*49cdfc7eSAndroid Build Coastguard Worker 		case 's':
363*49cdfc7eSAndroid Build Coastguard Worker 			seed = strtoul(optarg, NULL, 0);
364*49cdfc7eSAndroid Build Coastguard Worker 			break;
365*49cdfc7eSAndroid Build Coastguard Worker 		case 'v':
366*49cdfc7eSAndroid Build Coastguard Worker 			verbose = 1;
367*49cdfc7eSAndroid Build Coastguard Worker 			break;
368*49cdfc7eSAndroid Build Coastguard Worker 		case 'w':
369*49cdfc7eSAndroid Build Coastguard Worker 			write_freq();
370*49cdfc7eSAndroid Build Coastguard Worker 			break;
371*49cdfc7eSAndroid Build Coastguard Worker 		case 'z':
372*49cdfc7eSAndroid Build Coastguard Worker 			zero_freq();
373*49cdfc7eSAndroid Build Coastguard Worker 			break;
374*49cdfc7eSAndroid Build Coastguard Worker 		case 'S':
375*49cdfc7eSAndroid Build Coastguard Worker 			show_ops(0, NULL);
376*49cdfc7eSAndroid Build Coastguard Worker 			printf("\n");
377*49cdfc7eSAndroid Build Coastguard Worker 			nousage = 1;
378*49cdfc7eSAndroid Build Coastguard Worker 			break;
379*49cdfc7eSAndroid Build Coastguard Worker 		case '?':
380*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(stderr, "%s - invalid parameters\n", myprog);
381*49cdfc7eSAndroid Build Coastguard Worker 			/* fall through */
382*49cdfc7eSAndroid Build Coastguard Worker 		case 'H':
383*49cdfc7eSAndroid Build Coastguard Worker 			usage();
384*49cdfc7eSAndroid Build Coastguard Worker 			exit(1);
385*49cdfc7eSAndroid Build Coastguard Worker 		case 'X':
386*49cdfc7eSAndroid Build Coastguard Worker 			no_xfs = 1;
387*49cdfc7eSAndroid Build Coastguard Worker 			break;
388*49cdfc7eSAndroid Build Coastguard Worker 		}
389*49cdfc7eSAndroid Build Coastguard Worker 	}
390*49cdfc7eSAndroid Build Coastguard Worker 
391*49cdfc7eSAndroid Build Coastguard Worker 	if (no_xfs && errtag) {
392*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr, "error injection only works on XFS\n");
393*49cdfc7eSAndroid Build Coastguard Worker 		exit(1);
394*49cdfc7eSAndroid Build Coastguard Worker 	}
395*49cdfc7eSAndroid Build Coastguard Worker 
396*49cdfc7eSAndroid Build Coastguard Worker 	if (no_xfs) {
397*49cdfc7eSAndroid Build Coastguard Worker 		int i;
398*49cdfc7eSAndroid Build Coastguard Worker 		for (i = 0; ops + i < ops_end; ++i) {
399*49cdfc7eSAndroid Build Coastguard Worker 			if (ops[i].isxfs)
400*49cdfc7eSAndroid Build Coastguard Worker 				ops[i].freq = 0;
401*49cdfc7eSAndroid Build Coastguard Worker 		}
402*49cdfc7eSAndroid Build Coastguard Worker 	}
403*49cdfc7eSAndroid Build Coastguard Worker 
404*49cdfc7eSAndroid Build Coastguard Worker 	make_freq_table();
405*49cdfc7eSAndroid Build Coastguard Worker 
406*49cdfc7eSAndroid Build Coastguard Worker 	while (((loopcntr <= loops) || (loops == 0)) && !should_stop) {
407*49cdfc7eSAndroid Build Coastguard Worker 		if (!dirname) {
408*49cdfc7eSAndroid Build Coastguard Worker 			/* no directory specified */
409*49cdfc7eSAndroid Build Coastguard Worker 			if (!nousage)
410*49cdfc7eSAndroid Build Coastguard Worker 				usage();
411*49cdfc7eSAndroid Build Coastguard Worker 			exit(1);
412*49cdfc7eSAndroid Build Coastguard Worker 		}
413*49cdfc7eSAndroid Build Coastguard Worker 
414*49cdfc7eSAndroid Build Coastguard Worker 		(void)mkdir(dirname, 0777);
415*49cdfc7eSAndroid Build Coastguard Worker 		if (chdir(dirname) < 0) {
416*49cdfc7eSAndroid Build Coastguard Worker 			perror(dirname);
417*49cdfc7eSAndroid Build Coastguard Worker 			exit(1);
418*49cdfc7eSAndroid Build Coastguard Worker 		}
419*49cdfc7eSAndroid Build Coastguard Worker 		sprintf(buf, "fss%x", getpid());
420*49cdfc7eSAndroid Build Coastguard Worker 		fd = creat(buf, 0666);
421*49cdfc7eSAndroid Build Coastguard Worker 		if (lseek64(fd, (off64_t) (MAXFSIZE32 + 1ULL), SEEK_SET) < 0)
422*49cdfc7eSAndroid Build Coastguard Worker 			maxfsize = (off64_t) MAXFSIZE32;
423*49cdfc7eSAndroid Build Coastguard Worker 		else
424*49cdfc7eSAndroid Build Coastguard Worker 			maxfsize = (off64_t) MAXFSIZE;
425*49cdfc7eSAndroid Build Coastguard Worker 		dcache_init();
426*49cdfc7eSAndroid Build Coastguard Worker 		setlinebuf(stdout);
427*49cdfc7eSAndroid Build Coastguard Worker 		if (!seed) {
428*49cdfc7eSAndroid Build Coastguard Worker 			gettimeofday(&t, NULL);
429*49cdfc7eSAndroid Build Coastguard Worker 			seed = (int)t.tv_sec ^ (int)t.tv_usec;
430*49cdfc7eSAndroid Build Coastguard Worker 			printf("seed = %ld\n", seed);
431*49cdfc7eSAndroid Build Coastguard Worker 		}
432*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
433*49cdfc7eSAndroid Build Coastguard Worker 		if (!no_xfs) {
434*49cdfc7eSAndroid Build Coastguard Worker 			memset(&geom, 0, sizeof(geom));
435*49cdfc7eSAndroid Build Coastguard Worker 			i = ioctl(fd, XFS_IOC_FSGEOMETRY, &geom);
436*49cdfc7eSAndroid Build Coastguard Worker 			if (i >= 0 && geom.rtblocks)
437*49cdfc7eSAndroid Build Coastguard Worker 				rtpct = MIN(MAX(geom.rtblocks * 100 /
438*49cdfc7eSAndroid Build Coastguard Worker 						(geom.rtblocks +
439*49cdfc7eSAndroid Build Coastguard Worker 						 geom.datablocks), 1), 99);
440*49cdfc7eSAndroid Build Coastguard Worker 			else
441*49cdfc7eSAndroid Build Coastguard Worker 				rtpct = 0;
442*49cdfc7eSAndroid Build Coastguard Worker 		}
443*49cdfc7eSAndroid Build Coastguard Worker 		if (errtag != 0) {
444*49cdfc7eSAndroid Build Coastguard Worker 			if (errrange == 0) {
445*49cdfc7eSAndroid Build Coastguard Worker 				if (errtag <= 0) {
446*49cdfc7eSAndroid Build Coastguard Worker 					srandom(seed);
447*49cdfc7eSAndroid Build Coastguard Worker 					j = random() % 100;
448*49cdfc7eSAndroid Build Coastguard Worker 
449*49cdfc7eSAndroid Build Coastguard Worker 					for (i = 0; i < j; i++)
450*49cdfc7eSAndroid Build Coastguard Worker 						(void)random();
451*49cdfc7eSAndroid Build Coastguard Worker 
452*49cdfc7eSAndroid Build Coastguard Worker 					errtag =
453*49cdfc7eSAndroid Build Coastguard Worker 					    (random() % (XFS_ERRTAG_MAX - 1)) +
454*49cdfc7eSAndroid Build Coastguard Worker 					    1;
455*49cdfc7eSAndroid Build Coastguard Worker 				}
456*49cdfc7eSAndroid Build Coastguard Worker 			} else {
457*49cdfc7eSAndroid Build Coastguard Worker 				srandom(seed);
458*49cdfc7eSAndroid Build Coastguard Worker 				j = random() % 100;
459*49cdfc7eSAndroid Build Coastguard Worker 
460*49cdfc7eSAndroid Build Coastguard Worker 				for (i = 0; i < j; i++)
461*49cdfc7eSAndroid Build Coastguard Worker 					(void)random();
462*49cdfc7eSAndroid Build Coastguard Worker 
463*49cdfc7eSAndroid Build Coastguard Worker 				errtag +=
464*49cdfc7eSAndroid Build Coastguard Worker 				    (random() % (XFS_ERRTAG_MAX - errtag));
465*49cdfc7eSAndroid Build Coastguard Worker 			}
466*49cdfc7eSAndroid Build Coastguard Worker 			printf("Injecting failure on tag #%d\n", errtag);
467*49cdfc7eSAndroid Build Coastguard Worker 			memset(&err_inj, 0, sizeof(err_inj));
468*49cdfc7eSAndroid Build Coastguard Worker 			err_inj.errtag = errtag;
469*49cdfc7eSAndroid Build Coastguard Worker 			err_inj.fd = fd;
470*49cdfc7eSAndroid Build Coastguard Worker 			srval = ioctl(fd, XFS_IOC_ERROR_INJECTION, &err_inj);
471*49cdfc7eSAndroid Build Coastguard Worker 			if (srval < -1) {
472*49cdfc7eSAndroid Build Coastguard Worker 				perror
473*49cdfc7eSAndroid Build Coastguard Worker 				    ("fsstress - XFS_SYSSGI error injection call");
474*49cdfc7eSAndroid Build Coastguard Worker 				close(fd);
475*49cdfc7eSAndroid Build Coastguard Worker 				unlink(buf);
476*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
477*49cdfc7eSAndroid Build Coastguard Worker 			}
478*49cdfc7eSAndroid Build Coastguard Worker 		} else
479*49cdfc7eSAndroid Build Coastguard Worker #endif
480*49cdfc7eSAndroid Build Coastguard Worker 			close(fd);
481*49cdfc7eSAndroid Build Coastguard Worker 		unlink(buf);
482*49cdfc7eSAndroid Build Coastguard Worker 
483*49cdfc7eSAndroid Build Coastguard Worker 
484*49cdfc7eSAndroid Build Coastguard Worker 		if (nproc == 1) {
485*49cdfc7eSAndroid Build Coastguard Worker 			procid = 0;
486*49cdfc7eSAndroid Build Coastguard Worker 			doproc();
487*49cdfc7eSAndroid Build Coastguard Worker 		} else {
488*49cdfc7eSAndroid Build Coastguard Worker 			setpgid(0, 0);
489*49cdfc7eSAndroid Build Coastguard Worker 			action.sa_handler = sg_handler;
490*49cdfc7eSAndroid Build Coastguard Worker 			sigemptyset(&action.sa_mask);
491*49cdfc7eSAndroid Build Coastguard Worker 			action.sa_flags = 0;
492*49cdfc7eSAndroid Build Coastguard Worker 			if (sigaction(SIGTERM, &action, 0)) {
493*49cdfc7eSAndroid Build Coastguard Worker 				perror("sigaction failed");
494*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
495*49cdfc7eSAndroid Build Coastguard Worker 			}
496*49cdfc7eSAndroid Build Coastguard Worker 
497*49cdfc7eSAndroid Build Coastguard Worker 			for (i = 0; i < nproc; i++) {
498*49cdfc7eSAndroid Build Coastguard Worker 				if (fork() == 0) {
499*49cdfc7eSAndroid Build Coastguard Worker 
500*49cdfc7eSAndroid Build Coastguard Worker 					action.sa_handler = SIG_DFL;
501*49cdfc7eSAndroid Build Coastguard Worker 					sigemptyset(&action.sa_mask);
502*49cdfc7eSAndroid Build Coastguard Worker 					if (sigaction(SIGTERM, &action, 0))
503*49cdfc7eSAndroid Build Coastguard Worker 						return 1;
504*49cdfc7eSAndroid Build Coastguard Worker #ifdef HAVE_SYS_PRCTL_H
505*49cdfc7eSAndroid Build Coastguard Worker 					prctl(PR_SET_PDEATHSIG, SIGKILL);
506*49cdfc7eSAndroid Build Coastguard Worker 					if (getppid() == 1) /* parent died already? */
507*49cdfc7eSAndroid Build Coastguard Worker 						return 0;
508*49cdfc7eSAndroid Build Coastguard Worker #endif
509*49cdfc7eSAndroid Build Coastguard Worker 					procid = i;
510*49cdfc7eSAndroid Build Coastguard Worker 					doproc();
511*49cdfc7eSAndroid Build Coastguard Worker 					return 0;
512*49cdfc7eSAndroid Build Coastguard Worker 				}
513*49cdfc7eSAndroid Build Coastguard Worker 			}
514*49cdfc7eSAndroid Build Coastguard Worker 			while (wait(&stat) > 0 && !should_stop) {
515*49cdfc7eSAndroid Build Coastguard Worker 				continue;
516*49cdfc7eSAndroid Build Coastguard Worker 			}
517*49cdfc7eSAndroid Build Coastguard Worker 			if (should_stop) {
518*49cdfc7eSAndroid Build Coastguard Worker 				action.sa_flags = SA_RESTART;
519*49cdfc7eSAndroid Build Coastguard Worker 				sigaction(SIGTERM, &action, 0);
520*49cdfc7eSAndroid Build Coastguard Worker 				kill(-getpid(), SIGTERM);
521*49cdfc7eSAndroid Build Coastguard Worker 				while (wait(&stat) > 0)
522*49cdfc7eSAndroid Build Coastguard Worker 					continue;
523*49cdfc7eSAndroid Build Coastguard Worker 			}
524*49cdfc7eSAndroid Build Coastguard Worker 		}
525*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
526*49cdfc7eSAndroid Build Coastguard Worker 		if (errtag != 0) {
527*49cdfc7eSAndroid Build Coastguard Worker 			memset(&err_inj, 0, sizeof(err_inj));
528*49cdfc7eSAndroid Build Coastguard Worker 			err_inj.errtag = 0;
529*49cdfc7eSAndroid Build Coastguard Worker 			err_inj.fd = fd;
530*49cdfc7eSAndroid Build Coastguard Worker 			if ((srval =
531*49cdfc7eSAndroid Build Coastguard Worker 			     ioctl(fd, XFS_IOC_ERROR_CLEARALL,
532*49cdfc7eSAndroid Build Coastguard Worker 				   &err_inj)) != 0) {
533*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr, "Bad ej clear on %d (%d).\n",
534*49cdfc7eSAndroid Build Coastguard Worker 					fd, errno);
535*49cdfc7eSAndroid Build Coastguard Worker 				perror
536*49cdfc7eSAndroid Build Coastguard Worker 				    ("fsstress - XFS_SYSSGI clear error injection call");
537*49cdfc7eSAndroid Build Coastguard Worker 				close(fd);
538*49cdfc7eSAndroid Build Coastguard Worker 				exit(1);
539*49cdfc7eSAndroid Build Coastguard Worker 			}
540*49cdfc7eSAndroid Build Coastguard Worker 			close(fd);
541*49cdfc7eSAndroid Build Coastguard Worker 		}
542*49cdfc7eSAndroid Build Coastguard Worker #endif
543*49cdfc7eSAndroid Build Coastguard Worker 		if (cleanup == 0) {
544*49cdfc7eSAndroid Build Coastguard Worker 			sprintf(cmd, "rm -rf %s/*", dirname);
545*49cdfc7eSAndroid Build Coastguard Worker 			system(cmd);
546*49cdfc7eSAndroid Build Coastguard Worker 			for (i = 0; i < FT_nft; i++) {
547*49cdfc7eSAndroid Build Coastguard Worker 				flist[i].nslots = 0;
548*49cdfc7eSAndroid Build Coastguard Worker 				flist[i].nfiles = 0;
549*49cdfc7eSAndroid Build Coastguard Worker 				free(flist[i].fents);
550*49cdfc7eSAndroid Build Coastguard Worker 				flist[i].fents = NULL;
551*49cdfc7eSAndroid Build Coastguard Worker 			}
552*49cdfc7eSAndroid Build Coastguard Worker 		}
553*49cdfc7eSAndroid Build Coastguard Worker 		loopcntr++;
554*49cdfc7eSAndroid Build Coastguard Worker 	}
555*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
556*49cdfc7eSAndroid Build Coastguard Worker }
557*49cdfc7eSAndroid Build Coastguard Worker 
add_to_flist(int ft,int id,int parent)558*49cdfc7eSAndroid Build Coastguard Worker void add_to_flist(int ft, int id, int parent)
559*49cdfc7eSAndroid Build Coastguard Worker {
560*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
561*49cdfc7eSAndroid Build Coastguard Worker 	flist_t *ftp;
562*49cdfc7eSAndroid Build Coastguard Worker 
563*49cdfc7eSAndroid Build Coastguard Worker 	ftp = &flist[ft];
564*49cdfc7eSAndroid Build Coastguard Worker 	if (ftp->nfiles == ftp->nslots) {
565*49cdfc7eSAndroid Build Coastguard Worker 		ftp->nslots += FLIST_SLOT_INCR;
566*49cdfc7eSAndroid Build Coastguard Worker 		ftp->fents = realloc(ftp->fents, ftp->nslots * sizeof(fent_t));
567*49cdfc7eSAndroid Build Coastguard Worker 	}
568*49cdfc7eSAndroid Build Coastguard Worker 	fep = &ftp->fents[ftp->nfiles++];
569*49cdfc7eSAndroid Build Coastguard Worker 	fep->id = id;
570*49cdfc7eSAndroid Build Coastguard Worker 	fep->parent = parent;
571*49cdfc7eSAndroid Build Coastguard Worker }
572*49cdfc7eSAndroid Build Coastguard Worker 
append_pathname(pathname_t * name,char * str)573*49cdfc7eSAndroid Build Coastguard Worker void append_pathname(pathname_t * name, char *str)
574*49cdfc7eSAndroid Build Coastguard Worker {
575*49cdfc7eSAndroid Build Coastguard Worker 	int len;
576*49cdfc7eSAndroid Build Coastguard Worker 
577*49cdfc7eSAndroid Build Coastguard Worker 	len = strlen(str);
578*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
579*49cdfc7eSAndroid Build Coastguard Worker 	if (len && *str == '/' && name->len == 0) {
580*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr, "fsstress: append_pathname failure\n");
581*49cdfc7eSAndroid Build Coastguard Worker 		chdir(homedir);
582*49cdfc7eSAndroid Build Coastguard Worker 		abort();
583*49cdfc7eSAndroid Build Coastguard Worker 
584*49cdfc7eSAndroid Build Coastguard Worker 	}
585*49cdfc7eSAndroid Build Coastguard Worker #endif
586*49cdfc7eSAndroid Build Coastguard Worker 	name->path = realloc(name->path, name->len + 1 + len);
587*49cdfc7eSAndroid Build Coastguard Worker 	strcpy(&name->path[name->len], str);
588*49cdfc7eSAndroid Build Coastguard Worker 	name->len += len;
589*49cdfc7eSAndroid Build Coastguard Worker }
590*49cdfc7eSAndroid Build Coastguard Worker 
591*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
592*49cdfc7eSAndroid Build Coastguard Worker int
attr_list_path(pathname_t * name,char * buffer,const int buffersize,int flags,attrlist_cursor_t * cursor)593*49cdfc7eSAndroid Build Coastguard Worker attr_list_path(pathname_t * name, char *buffer, const int buffersize, int flags,
594*49cdfc7eSAndroid Build Coastguard Worker 	       attrlist_cursor_t * cursor)
595*49cdfc7eSAndroid Build Coastguard Worker {
596*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
597*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
598*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
599*49cdfc7eSAndroid Build Coastguard Worker 
600*49cdfc7eSAndroid Build Coastguard Worker 	rval = attr_list(name->path, buffer, buffersize, flags, cursor);
601*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
602*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
603*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
604*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
605*49cdfc7eSAndroid Build Coastguard Worker 		rval = attr_list_path(&newname, buffer, buffersize, flags,
606*49cdfc7eSAndroid Build Coastguard Worker 				      cursor);
607*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
608*49cdfc7eSAndroid Build Coastguard Worker 	}
609*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
610*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
611*49cdfc7eSAndroid Build Coastguard Worker }
612*49cdfc7eSAndroid Build Coastguard Worker 
attr_remove_path(pathname_t * name,const char * attrname,int flags)613*49cdfc7eSAndroid Build Coastguard Worker int attr_remove_path(pathname_t * name, const char *attrname, int flags)
614*49cdfc7eSAndroid Build Coastguard Worker {
615*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
616*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
617*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
618*49cdfc7eSAndroid Build Coastguard Worker 
619*49cdfc7eSAndroid Build Coastguard Worker 	rval = attr_remove(name->path, attrname, flags);
620*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
621*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
622*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
623*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
624*49cdfc7eSAndroid Build Coastguard Worker 		rval = attr_remove_path(&newname, attrname, flags);
625*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
626*49cdfc7eSAndroid Build Coastguard Worker 	}
627*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
628*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
629*49cdfc7eSAndroid Build Coastguard Worker }
630*49cdfc7eSAndroid Build Coastguard Worker 
631*49cdfc7eSAndroid Build Coastguard Worker int
attr_set_path(pathname_t * name,const char * attrname,const char * attrvalue,const int valuelength,int flags)632*49cdfc7eSAndroid Build Coastguard Worker attr_set_path(pathname_t * name, const char *attrname, const char *attrvalue,
633*49cdfc7eSAndroid Build Coastguard Worker 	      const int valuelength, int flags)
634*49cdfc7eSAndroid Build Coastguard Worker {
635*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
636*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
637*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
638*49cdfc7eSAndroid Build Coastguard Worker 
639*49cdfc7eSAndroid Build Coastguard Worker 	rval = attr_set(name->path, attrname, attrvalue, valuelength, flags);
640*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
641*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
642*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
643*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
644*49cdfc7eSAndroid Build Coastguard Worker 		rval = attr_set_path(&newname, attrname, attrvalue, valuelength,
645*49cdfc7eSAndroid Build Coastguard Worker 				     flags);
646*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
647*49cdfc7eSAndroid Build Coastguard Worker 	}
648*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
649*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
650*49cdfc7eSAndroid Build Coastguard Worker }
651*49cdfc7eSAndroid Build Coastguard Worker #endif
652*49cdfc7eSAndroid Build Coastguard Worker 
check_cwd(void)653*49cdfc7eSAndroid Build Coastguard Worker void check_cwd(void)
654*49cdfc7eSAndroid Build Coastguard Worker {
655*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
656*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 statbuf;
657*49cdfc7eSAndroid Build Coastguard Worker 
658*49cdfc7eSAndroid Build Coastguard Worker 	if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino)
659*49cdfc7eSAndroid Build Coastguard Worker 		return;
660*49cdfc7eSAndroid Build Coastguard Worker 	chdir(homedir);
661*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stderr, "fsstress: check_cwd failure\n");
662*49cdfc7eSAndroid Build Coastguard Worker 	abort();
663*49cdfc7eSAndroid Build Coastguard Worker 
664*49cdfc7eSAndroid Build Coastguard Worker #endif
665*49cdfc7eSAndroid Build Coastguard Worker }
666*49cdfc7eSAndroid Build Coastguard Worker 
creat_path(pathname_t * name,mode_t mode)667*49cdfc7eSAndroid Build Coastguard Worker int creat_path(pathname_t * name, mode_t mode)
668*49cdfc7eSAndroid Build Coastguard Worker {
669*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
670*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
671*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
672*49cdfc7eSAndroid Build Coastguard Worker 
673*49cdfc7eSAndroid Build Coastguard Worker 	rval = creat(name->path, mode);
674*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
675*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
676*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
677*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
678*49cdfc7eSAndroid Build Coastguard Worker 		rval = creat_path(&newname, mode);
679*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
680*49cdfc7eSAndroid Build Coastguard Worker 	}
681*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
682*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
683*49cdfc7eSAndroid Build Coastguard Worker }
684*49cdfc7eSAndroid Build Coastguard Worker 
dcache_enter(int dirid,int slot)685*49cdfc7eSAndroid Build Coastguard Worker void dcache_enter(int dirid, int slot)
686*49cdfc7eSAndroid Build Coastguard Worker {
687*49cdfc7eSAndroid Build Coastguard Worker 	dcache[dirid % NDCACHE] = slot;
688*49cdfc7eSAndroid Build Coastguard Worker }
689*49cdfc7eSAndroid Build Coastguard Worker 
dcache_init(void)690*49cdfc7eSAndroid Build Coastguard Worker void dcache_init(void)
691*49cdfc7eSAndroid Build Coastguard Worker {
692*49cdfc7eSAndroid Build Coastguard Worker 	int i;
693*49cdfc7eSAndroid Build Coastguard Worker 
694*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < NDCACHE; i++)
695*49cdfc7eSAndroid Build Coastguard Worker 		dcache[i] = -1;
696*49cdfc7eSAndroid Build Coastguard Worker }
697*49cdfc7eSAndroid Build Coastguard Worker 
dcache_lookup(int dirid)698*49cdfc7eSAndroid Build Coastguard Worker fent_t *dcache_lookup(int dirid)
699*49cdfc7eSAndroid Build Coastguard Worker {
700*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
701*49cdfc7eSAndroid Build Coastguard Worker 	int i;
702*49cdfc7eSAndroid Build Coastguard Worker 
703*49cdfc7eSAndroid Build Coastguard Worker 	i = dcache[dirid % NDCACHE];
704*49cdfc7eSAndroid Build Coastguard Worker 	if (i >= 0 && (fep = &flist[FT_DIR].fents[i])->id == dirid)
705*49cdfc7eSAndroid Build Coastguard Worker 		return fep;
706*49cdfc7eSAndroid Build Coastguard Worker 	return NULL;
707*49cdfc7eSAndroid Build Coastguard Worker }
708*49cdfc7eSAndroid Build Coastguard Worker 
dcache_purge(int dirid)709*49cdfc7eSAndroid Build Coastguard Worker void dcache_purge(int dirid)
710*49cdfc7eSAndroid Build Coastguard Worker {
711*49cdfc7eSAndroid Build Coastguard Worker 	int *dcp;
712*49cdfc7eSAndroid Build Coastguard Worker 
713*49cdfc7eSAndroid Build Coastguard Worker 	dcp = &dcache[dirid % NDCACHE];
714*49cdfc7eSAndroid Build Coastguard Worker 	if (*dcp >= 0 && flist[FT_DIR].fents[*dcp].id == dirid)
715*49cdfc7eSAndroid Build Coastguard Worker 		*dcp = -1;
716*49cdfc7eSAndroid Build Coastguard Worker }
717*49cdfc7eSAndroid Build Coastguard Worker 
del_from_flist(int ft,int slot)718*49cdfc7eSAndroid Build Coastguard Worker void del_from_flist(int ft, int slot)
719*49cdfc7eSAndroid Build Coastguard Worker {
720*49cdfc7eSAndroid Build Coastguard Worker 	flist_t *ftp;
721*49cdfc7eSAndroid Build Coastguard Worker 
722*49cdfc7eSAndroid Build Coastguard Worker 	ftp = &flist[ft];
723*49cdfc7eSAndroid Build Coastguard Worker 	if (ft == FT_DIR)
724*49cdfc7eSAndroid Build Coastguard Worker 		dcache_purge(ftp->fents[slot].id);
725*49cdfc7eSAndroid Build Coastguard Worker 	if (slot != ftp->nfiles - 1) {
726*49cdfc7eSAndroid Build Coastguard Worker 		if (ft == FT_DIR)
727*49cdfc7eSAndroid Build Coastguard Worker 			dcache_purge(ftp->fents[ftp->nfiles - 1].id);
728*49cdfc7eSAndroid Build Coastguard Worker 		ftp->fents[slot] = ftp->fents[--ftp->nfiles];
729*49cdfc7eSAndroid Build Coastguard Worker 	} else
730*49cdfc7eSAndroid Build Coastguard Worker 		ftp->nfiles--;
731*49cdfc7eSAndroid Build Coastguard Worker }
732*49cdfc7eSAndroid Build Coastguard Worker 
dirid_to_fent(int dirid)733*49cdfc7eSAndroid Build Coastguard Worker fent_t *dirid_to_fent(int dirid)
734*49cdfc7eSAndroid Build Coastguard Worker {
735*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *efep;
736*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
737*49cdfc7eSAndroid Build Coastguard Worker 	flist_t *flp;
738*49cdfc7eSAndroid Build Coastguard Worker 
739*49cdfc7eSAndroid Build Coastguard Worker 	if ((fep = dcache_lookup(dirid)))
740*49cdfc7eSAndroid Build Coastguard Worker 		return fep;
741*49cdfc7eSAndroid Build Coastguard Worker 	flp = &flist[FT_DIR];
742*49cdfc7eSAndroid Build Coastguard Worker 	for (fep = flp->fents, efep = &fep[flp->nfiles]; fep < efep; fep++) {
743*49cdfc7eSAndroid Build Coastguard Worker 		if (fep->id == dirid) {
744*49cdfc7eSAndroid Build Coastguard Worker 			dcache_enter(dirid, fep - flp->fents);
745*49cdfc7eSAndroid Build Coastguard Worker 			return fep;
746*49cdfc7eSAndroid Build Coastguard Worker 		}
747*49cdfc7eSAndroid Build Coastguard Worker 	}
748*49cdfc7eSAndroid Build Coastguard Worker 	return NULL;
749*49cdfc7eSAndroid Build Coastguard Worker }
750*49cdfc7eSAndroid Build Coastguard Worker 
doproc(void)751*49cdfc7eSAndroid Build Coastguard Worker void doproc(void)
752*49cdfc7eSAndroid Build Coastguard Worker {
753*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 statbuf;
754*49cdfc7eSAndroid Build Coastguard Worker 	char buf[10];
755*49cdfc7eSAndroid Build Coastguard Worker 	int opno;
756*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
757*49cdfc7eSAndroid Build Coastguard Worker 	opdesc_t *p;
758*49cdfc7eSAndroid Build Coastguard Worker 
759*49cdfc7eSAndroid Build Coastguard Worker 	sprintf(buf, "p%x", procid);
760*49cdfc7eSAndroid Build Coastguard Worker 	(void)mkdir(buf, 0777);
761*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) {
762*49cdfc7eSAndroid Build Coastguard Worker 		perror(buf);
763*49cdfc7eSAndroid Build Coastguard Worker 		_exit(1);
764*49cdfc7eSAndroid Build Coastguard Worker 	}
765*49cdfc7eSAndroid Build Coastguard Worker 	top_ino = statbuf.st_ino;
766*49cdfc7eSAndroid Build Coastguard Worker 	homedir = getcwd(NULL, -1);
767*49cdfc7eSAndroid Build Coastguard Worker 	seed += procid;
768*49cdfc7eSAndroid Build Coastguard Worker 	srandom(seed);
769*49cdfc7eSAndroid Build Coastguard Worker 	if (namerand)
770*49cdfc7eSAndroid Build Coastguard Worker 		namerand = random();
771*49cdfc7eSAndroid Build Coastguard Worker 	for (opno = 0; opno < operations; opno++) {
772*49cdfc7eSAndroid Build Coastguard Worker 		p = &ops[freq_table[random() % freq_table_size]];
773*49cdfc7eSAndroid Build Coastguard Worker 		if ((unsigned long)p->func < 4096)
774*49cdfc7eSAndroid Build Coastguard Worker 			abort();
775*49cdfc7eSAndroid Build Coastguard Worker 
776*49cdfc7eSAndroid Build Coastguard Worker 		p->func(opno, random());
777*49cdfc7eSAndroid Build Coastguard Worker 		/*
778*49cdfc7eSAndroid Build Coastguard Worker 		 * test for forced shutdown by stat'ing the test
779*49cdfc7eSAndroid Build Coastguard Worker 		 * directory.  If this stat returns EIO, assume
780*49cdfc7eSAndroid Build Coastguard Worker 		 * the forced shutdown happened.
781*49cdfc7eSAndroid Build Coastguard Worker 		 */
782*49cdfc7eSAndroid Build Coastguard Worker 		if (errtag != 0 && opno % 100 == 0) {
783*49cdfc7eSAndroid Build Coastguard Worker 			rval = stat64(".", &statbuf);
784*49cdfc7eSAndroid Build Coastguard Worker 			if (rval == EIO) {
785*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(stderr, "Detected EIO\n");
786*49cdfc7eSAndroid Build Coastguard Worker 				return;
787*49cdfc7eSAndroid Build Coastguard Worker 			}
788*49cdfc7eSAndroid Build Coastguard Worker 		}
789*49cdfc7eSAndroid Build Coastguard Worker 	}
790*49cdfc7eSAndroid Build Coastguard Worker }
791*49cdfc7eSAndroid Build Coastguard Worker 
fent_to_name(pathname_t * name,flist_t * flp,fent_t * fep)792*49cdfc7eSAndroid Build Coastguard Worker void fent_to_name(pathname_t * name, flist_t * flp, fent_t * fep)
793*49cdfc7eSAndroid Build Coastguard Worker {
794*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
795*49cdfc7eSAndroid Build Coastguard Worker 	int i;
796*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *pfep;
797*49cdfc7eSAndroid Build Coastguard Worker 
798*49cdfc7eSAndroid Build Coastguard Worker 	if (fep == NULL)
799*49cdfc7eSAndroid Build Coastguard Worker 		return;
800*49cdfc7eSAndroid Build Coastguard Worker 	if (fep->parent != -1) {
801*49cdfc7eSAndroid Build Coastguard Worker 		pfep = dirid_to_fent(fep->parent);
802*49cdfc7eSAndroid Build Coastguard Worker 		fent_to_name(name, &flist[FT_DIR], pfep);
803*49cdfc7eSAndroid Build Coastguard Worker 		append_pathname(name, "/");
804*49cdfc7eSAndroid Build Coastguard Worker 	}
805*49cdfc7eSAndroid Build Coastguard Worker 	i = sprintf(buf, "%c%x", flp->tag, fep->id);
806*49cdfc7eSAndroid Build Coastguard Worker 	namerandpad(fep->id, buf, i);
807*49cdfc7eSAndroid Build Coastguard Worker 	append_pathname(name, buf);
808*49cdfc7eSAndroid Build Coastguard Worker }
809*49cdfc7eSAndroid Build Coastguard Worker 
fix_parent(int oldid,int newid)810*49cdfc7eSAndroid Build Coastguard Worker void fix_parent(int oldid, int newid)
811*49cdfc7eSAndroid Build Coastguard Worker {
812*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
813*49cdfc7eSAndroid Build Coastguard Worker 	flist_t *flp;
814*49cdfc7eSAndroid Build Coastguard Worker 	int i;
815*49cdfc7eSAndroid Build Coastguard Worker 	int j;
816*49cdfc7eSAndroid Build Coastguard Worker 
817*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
818*49cdfc7eSAndroid Build Coastguard Worker 		for (j = 0, fep = flp->fents; j < flp->nfiles; j++, fep++) {
819*49cdfc7eSAndroid Build Coastguard Worker 			if (fep->parent == oldid)
820*49cdfc7eSAndroid Build Coastguard Worker 				fep->parent = newid;
821*49cdfc7eSAndroid Build Coastguard Worker 		}
822*49cdfc7eSAndroid Build Coastguard Worker 	}
823*49cdfc7eSAndroid Build Coastguard Worker }
824*49cdfc7eSAndroid Build Coastguard Worker 
free_pathname(pathname_t * name)825*49cdfc7eSAndroid Build Coastguard Worker void free_pathname(pathname_t * name)
826*49cdfc7eSAndroid Build Coastguard Worker {
827*49cdfc7eSAndroid Build Coastguard Worker 	if (name->path) {
828*49cdfc7eSAndroid Build Coastguard Worker 		free(name->path);
829*49cdfc7eSAndroid Build Coastguard Worker 		name->path = NULL;
830*49cdfc7eSAndroid Build Coastguard Worker 		name->len = 0;
831*49cdfc7eSAndroid Build Coastguard Worker 	}
832*49cdfc7eSAndroid Build Coastguard Worker }
833*49cdfc7eSAndroid Build Coastguard Worker 
generate_fname(fent_t * fep,int ft,pathname_t * name,int * idp,int * v)834*49cdfc7eSAndroid Build Coastguard Worker int generate_fname(fent_t * fep, int ft, pathname_t * name, int *idp, int *v)
835*49cdfc7eSAndroid Build Coastguard Worker {
836*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
837*49cdfc7eSAndroid Build Coastguard Worker 	flist_t *flp;
838*49cdfc7eSAndroid Build Coastguard Worker 	int id;
839*49cdfc7eSAndroid Build Coastguard Worker 	int j;
840*49cdfc7eSAndroid Build Coastguard Worker 	int len;
841*49cdfc7eSAndroid Build Coastguard Worker 
842*49cdfc7eSAndroid Build Coastguard Worker 	flp = &flist[ft];
843*49cdfc7eSAndroid Build Coastguard Worker 	len = sprintf(buf, "%c%x", flp->tag, id = nameseq++);
844*49cdfc7eSAndroid Build Coastguard Worker 	namerandpad(id, buf, len);
845*49cdfc7eSAndroid Build Coastguard Worker 	if (fep) {
846*49cdfc7eSAndroid Build Coastguard Worker 		fent_to_name(name, &flist[FT_DIR], fep);
847*49cdfc7eSAndroid Build Coastguard Worker 		append_pathname(name, "/");
848*49cdfc7eSAndroid Build Coastguard Worker 	}
849*49cdfc7eSAndroid Build Coastguard Worker 	append_pathname(name, buf);
850*49cdfc7eSAndroid Build Coastguard Worker 	*idp = id;
851*49cdfc7eSAndroid Build Coastguard Worker 	*v = verbose;
852*49cdfc7eSAndroid Build Coastguard Worker 	for (j = 0; !*v && j < ilistlen; j++) {
853*49cdfc7eSAndroid Build Coastguard Worker 		if (ilist[j] == id) {
854*49cdfc7eSAndroid Build Coastguard Worker 			*v = 1;
855*49cdfc7eSAndroid Build Coastguard Worker 			break;
856*49cdfc7eSAndroid Build Coastguard Worker 		}
857*49cdfc7eSAndroid Build Coastguard Worker 	}
858*49cdfc7eSAndroid Build Coastguard Worker 	return 1;
859*49cdfc7eSAndroid Build Coastguard Worker }
860*49cdfc7eSAndroid Build Coastguard Worker 
861*49cdfc7eSAndroid Build Coastguard Worker int
get_fname(int which,long r,pathname_t * name,flist_t ** flpp,fent_t ** fepp,int * v)862*49cdfc7eSAndroid Build Coastguard Worker get_fname(int which, long r, pathname_t * name, flist_t ** flpp, fent_t ** fepp,
863*49cdfc7eSAndroid Build Coastguard Worker 	  int *v)
864*49cdfc7eSAndroid Build Coastguard Worker {
865*49cdfc7eSAndroid Build Coastguard Worker 	int c;
866*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
867*49cdfc7eSAndroid Build Coastguard Worker 	flist_t *flp;
868*49cdfc7eSAndroid Build Coastguard Worker 	int i;
869*49cdfc7eSAndroid Build Coastguard Worker 	int j;
870*49cdfc7eSAndroid Build Coastguard Worker 	int x;
871*49cdfc7eSAndroid Build Coastguard Worker 
872*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
873*49cdfc7eSAndroid Build Coastguard Worker 		if (which & (1 << i))
874*49cdfc7eSAndroid Build Coastguard Worker 			c += flp->nfiles;
875*49cdfc7eSAndroid Build Coastguard Worker 	}
876*49cdfc7eSAndroid Build Coastguard Worker 	if (c == 0) {
877*49cdfc7eSAndroid Build Coastguard Worker 		if (flpp)
878*49cdfc7eSAndroid Build Coastguard Worker 			*flpp = NULL;
879*49cdfc7eSAndroid Build Coastguard Worker 		if (fepp)
880*49cdfc7eSAndroid Build Coastguard Worker 			*fepp = NULL;
881*49cdfc7eSAndroid Build Coastguard Worker 		*v = verbose;
882*49cdfc7eSAndroid Build Coastguard Worker 		return 0;
883*49cdfc7eSAndroid Build Coastguard Worker 	}
884*49cdfc7eSAndroid Build Coastguard Worker 	x = (int)(r % c);
885*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
886*49cdfc7eSAndroid Build Coastguard Worker 		if (which & (1 << i)) {
887*49cdfc7eSAndroid Build Coastguard Worker 			if (x < c + flp->nfiles) {
888*49cdfc7eSAndroid Build Coastguard Worker 				fep = &flp->fents[x - c];
889*49cdfc7eSAndroid Build Coastguard Worker 				if (name)
890*49cdfc7eSAndroid Build Coastguard Worker 					fent_to_name(name, flp, fep);
891*49cdfc7eSAndroid Build Coastguard Worker 				if (flpp)
892*49cdfc7eSAndroid Build Coastguard Worker 					*flpp = flp;
893*49cdfc7eSAndroid Build Coastguard Worker 				if (fepp)
894*49cdfc7eSAndroid Build Coastguard Worker 					*fepp = fep;
895*49cdfc7eSAndroid Build Coastguard Worker 				*v = verbose;
896*49cdfc7eSAndroid Build Coastguard Worker 				for (j = 0; !*v && j < ilistlen; j++) {
897*49cdfc7eSAndroid Build Coastguard Worker 					if (ilist[j] == fep->id) {
898*49cdfc7eSAndroid Build Coastguard Worker 						*v = 1;
899*49cdfc7eSAndroid Build Coastguard Worker 						break;
900*49cdfc7eSAndroid Build Coastguard Worker 					}
901*49cdfc7eSAndroid Build Coastguard Worker 				}
902*49cdfc7eSAndroid Build Coastguard Worker 				return 1;
903*49cdfc7eSAndroid Build Coastguard Worker 			}
904*49cdfc7eSAndroid Build Coastguard Worker 			c += flp->nfiles;
905*49cdfc7eSAndroid Build Coastguard Worker 		}
906*49cdfc7eSAndroid Build Coastguard Worker 	}
907*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
908*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stderr, "fsstress: get_fname failure\n");
909*49cdfc7eSAndroid Build Coastguard Worker 	abort();
910*49cdfc7eSAndroid Build Coastguard Worker #endif
911*49cdfc7eSAndroid Build Coastguard Worker 	return -1;
912*49cdfc7eSAndroid Build Coastguard Worker 
913*49cdfc7eSAndroid Build Coastguard Worker }
914*49cdfc7eSAndroid Build Coastguard Worker 
init_pathname(pathname_t * name)915*49cdfc7eSAndroid Build Coastguard Worker void init_pathname(pathname_t * name)
916*49cdfc7eSAndroid Build Coastguard Worker {
917*49cdfc7eSAndroid Build Coastguard Worker 	name->len = 0;
918*49cdfc7eSAndroid Build Coastguard Worker 	name->path = NULL;
919*49cdfc7eSAndroid Build Coastguard Worker }
920*49cdfc7eSAndroid Build Coastguard Worker 
lchown_path(pathname_t * name,uid_t owner,gid_t group)921*49cdfc7eSAndroid Build Coastguard Worker int lchown_path(pathname_t * name, uid_t owner, gid_t group)
922*49cdfc7eSAndroid Build Coastguard Worker {
923*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
924*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
925*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
926*49cdfc7eSAndroid Build Coastguard Worker 
927*49cdfc7eSAndroid Build Coastguard Worker 	rval = lchown(name->path, owner, group);
928*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
929*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
930*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
931*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
932*49cdfc7eSAndroid Build Coastguard Worker 		rval = lchown_path(&newname, owner, group);
933*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
934*49cdfc7eSAndroid Build Coastguard Worker 	}
935*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
936*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
937*49cdfc7eSAndroid Build Coastguard Worker }
938*49cdfc7eSAndroid Build Coastguard Worker 
link_path(pathname_t * name1,pathname_t * name2)939*49cdfc7eSAndroid Build Coastguard Worker int link_path(pathname_t * name1, pathname_t * name2)
940*49cdfc7eSAndroid Build Coastguard Worker {
941*49cdfc7eSAndroid Build Coastguard Worker 	char buf1[MAXNAMELEN];
942*49cdfc7eSAndroid Build Coastguard Worker 	char buf2[MAXNAMELEN];
943*49cdfc7eSAndroid Build Coastguard Worker 	int down1;
944*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname1;
945*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname2;
946*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
947*49cdfc7eSAndroid Build Coastguard Worker 
948*49cdfc7eSAndroid Build Coastguard Worker 	rval = link(name1->path, name2->path);
949*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
950*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
951*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name1, buf1, &newname1);
952*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name2, buf2, &newname2);
953*49cdfc7eSAndroid Build Coastguard Worker 	if (strcmp(buf1, buf2) == 0) {
954*49cdfc7eSAndroid Build Coastguard Worker 		if (chdir(buf1) == 0) {
955*49cdfc7eSAndroid Build Coastguard Worker 			rval = link_path(&newname1, &newname2);
956*49cdfc7eSAndroid Build Coastguard Worker 			chdir("..");
957*49cdfc7eSAndroid Build Coastguard Worker 		}
958*49cdfc7eSAndroid Build Coastguard Worker 	} else {
959*49cdfc7eSAndroid Build Coastguard Worker 		if (strcmp(buf1, "..") == 0)
960*49cdfc7eSAndroid Build Coastguard Worker 			down1 = 0;
961*49cdfc7eSAndroid Build Coastguard Worker 		else if (strcmp(buf2, "..") == 0)
962*49cdfc7eSAndroid Build Coastguard Worker 			down1 = 1;
963*49cdfc7eSAndroid Build Coastguard Worker 		else if (strlen(buf1) == 0)
964*49cdfc7eSAndroid Build Coastguard Worker 			down1 = 0;
965*49cdfc7eSAndroid Build Coastguard Worker 		else if (strlen(buf2) == 0)
966*49cdfc7eSAndroid Build Coastguard Worker 			down1 = 1;
967*49cdfc7eSAndroid Build Coastguard Worker 		else
968*49cdfc7eSAndroid Build Coastguard Worker 			down1 = MAX(newname1.len, 3 + name2->len) <=
969*49cdfc7eSAndroid Build Coastguard Worker 			    MAX(3 + name1->len, newname2.len);
970*49cdfc7eSAndroid Build Coastguard Worker 		if (down1) {
971*49cdfc7eSAndroid Build Coastguard Worker 			free_pathname(&newname2);
972*49cdfc7eSAndroid Build Coastguard Worker 			append_pathname(&newname2, "../");
973*49cdfc7eSAndroid Build Coastguard Worker 			append_pathname(&newname2, name2->path);
974*49cdfc7eSAndroid Build Coastguard Worker 			if (chdir(buf1) == 0) {
975*49cdfc7eSAndroid Build Coastguard Worker 				rval = link_path(&newname1, &newname2);
976*49cdfc7eSAndroid Build Coastguard Worker 				chdir("..");
977*49cdfc7eSAndroid Build Coastguard Worker 			}
978*49cdfc7eSAndroid Build Coastguard Worker 		} else {
979*49cdfc7eSAndroid Build Coastguard Worker 			free_pathname(&newname1);
980*49cdfc7eSAndroid Build Coastguard Worker 			append_pathname(&newname1, "../");
981*49cdfc7eSAndroid Build Coastguard Worker 			append_pathname(&newname1, name1->path);
982*49cdfc7eSAndroid Build Coastguard Worker 			if (chdir(buf2) == 0) {
983*49cdfc7eSAndroid Build Coastguard Worker 				rval = link_path(&newname1, &newname2);
984*49cdfc7eSAndroid Build Coastguard Worker 				chdir("..");
985*49cdfc7eSAndroid Build Coastguard Worker 			}
986*49cdfc7eSAndroid Build Coastguard Worker 		}
987*49cdfc7eSAndroid Build Coastguard Worker 	}
988*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname1);
989*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname2);
990*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
991*49cdfc7eSAndroid Build Coastguard Worker }
992*49cdfc7eSAndroid Build Coastguard Worker 
lstat64_path(pathname_t * name,struct stat64 * sbuf)993*49cdfc7eSAndroid Build Coastguard Worker int lstat64_path(pathname_t * name, struct stat64 *sbuf)
994*49cdfc7eSAndroid Build Coastguard Worker {
995*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
996*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
997*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
998*49cdfc7eSAndroid Build Coastguard Worker 
999*49cdfc7eSAndroid Build Coastguard Worker 	rval = lstat64(name->path, sbuf);
1000*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
1001*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
1002*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
1003*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
1004*49cdfc7eSAndroid Build Coastguard Worker 		rval = lstat64_path(&newname, sbuf);
1005*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
1006*49cdfc7eSAndroid Build Coastguard Worker 	}
1007*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
1008*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
1009*49cdfc7eSAndroid Build Coastguard Worker }
1010*49cdfc7eSAndroid Build Coastguard Worker 
make_freq_table(void)1011*49cdfc7eSAndroid Build Coastguard Worker void make_freq_table(void)
1012*49cdfc7eSAndroid Build Coastguard Worker {
1013*49cdfc7eSAndroid Build Coastguard Worker 	int f;
1014*49cdfc7eSAndroid Build Coastguard Worker 	int i;
1015*49cdfc7eSAndroid Build Coastguard Worker 	opdesc_t *p;
1016*49cdfc7eSAndroid Build Coastguard Worker 
1017*49cdfc7eSAndroid Build Coastguard Worker 	for (p = ops, f = 0; p < ops_end; p++)
1018*49cdfc7eSAndroid Build Coastguard Worker 		f += p->freq;
1019*49cdfc7eSAndroid Build Coastguard Worker 	freq_table = malloc(f * sizeof(*freq_table));
1020*49cdfc7eSAndroid Build Coastguard Worker 	freq_table_size = f;
1021*49cdfc7eSAndroid Build Coastguard Worker 	for (p = ops, i = 0; p < ops_end; p++) {
1022*49cdfc7eSAndroid Build Coastguard Worker 		for (f = 0; f < p->freq; f++, i++)
1023*49cdfc7eSAndroid Build Coastguard Worker 			freq_table[i] = p->op;
1024*49cdfc7eSAndroid Build Coastguard Worker 	}
1025*49cdfc7eSAndroid Build Coastguard Worker }
1026*49cdfc7eSAndroid Build Coastguard Worker 
mkdir_path(pathname_t * name,mode_t mode)1027*49cdfc7eSAndroid Build Coastguard Worker int mkdir_path(pathname_t * name, mode_t mode)
1028*49cdfc7eSAndroid Build Coastguard Worker {
1029*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
1030*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
1031*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
1032*49cdfc7eSAndroid Build Coastguard Worker 
1033*49cdfc7eSAndroid Build Coastguard Worker 	rval = mkdir(name->path, mode);
1034*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
1035*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
1036*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
1037*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
1038*49cdfc7eSAndroid Build Coastguard Worker 		rval = mkdir_path(&newname, mode);
1039*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
1040*49cdfc7eSAndroid Build Coastguard Worker 	}
1041*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
1042*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
1043*49cdfc7eSAndroid Build Coastguard Worker }
1044*49cdfc7eSAndroid Build Coastguard Worker 
mknod_path(pathname_t * name,mode_t mode,dev_t dev)1045*49cdfc7eSAndroid Build Coastguard Worker int mknod_path(pathname_t * name, mode_t mode, dev_t dev)
1046*49cdfc7eSAndroid Build Coastguard Worker {
1047*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
1048*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
1049*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
1050*49cdfc7eSAndroid Build Coastguard Worker 
1051*49cdfc7eSAndroid Build Coastguard Worker 	rval = mknod(name->path, mode, dev);
1052*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
1053*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
1054*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
1055*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
1056*49cdfc7eSAndroid Build Coastguard Worker 		rval = mknod_path(&newname, mode, dev);
1057*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
1058*49cdfc7eSAndroid Build Coastguard Worker 	}
1059*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
1060*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
1061*49cdfc7eSAndroid Build Coastguard Worker }
1062*49cdfc7eSAndroid Build Coastguard Worker 
namerandpad(int id,char * buf,int i)1063*49cdfc7eSAndroid Build Coastguard Worker void namerandpad(int id, char *buf, int i)
1064*49cdfc7eSAndroid Build Coastguard Worker {
1065*49cdfc7eSAndroid Build Coastguard Worker 	int bucket;
1066*49cdfc7eSAndroid Build Coastguard Worker 	static int buckets[] = { 2, 4, 8, 16, 32, 64, 128, MAXNAMELEN - 1 };
1067*49cdfc7eSAndroid Build Coastguard Worker 	int padlen;
1068*49cdfc7eSAndroid Build Coastguard Worker 	int padmod;
1069*49cdfc7eSAndroid Build Coastguard Worker 
1070*49cdfc7eSAndroid Build Coastguard Worker 	if (namerand == 0)
1071*49cdfc7eSAndroid Build Coastguard Worker 		return;
1072*49cdfc7eSAndroid Build Coastguard Worker 	bucket = (id ^ namerand) % ARRAY_SIZE(buckets);
1073*49cdfc7eSAndroid Build Coastguard Worker 	padmod = buckets[bucket] + 1 - i;
1074*49cdfc7eSAndroid Build Coastguard Worker 	if (padmod <= 0)
1075*49cdfc7eSAndroid Build Coastguard Worker 		return;
1076*49cdfc7eSAndroid Build Coastguard Worker 	padlen = (id ^ namerand) % padmod;
1077*49cdfc7eSAndroid Build Coastguard Worker 	if (padlen) {
1078*49cdfc7eSAndroid Build Coastguard Worker 		memset(&buf[i], 'X', padlen);
1079*49cdfc7eSAndroid Build Coastguard Worker 		buf[i + padlen] = '\0';
1080*49cdfc7eSAndroid Build Coastguard Worker 	}
1081*49cdfc7eSAndroid Build Coastguard Worker }
1082*49cdfc7eSAndroid Build Coastguard Worker 
open_path(pathname_t * name,int oflag)1083*49cdfc7eSAndroid Build Coastguard Worker int open_path(pathname_t * name, int oflag)
1084*49cdfc7eSAndroid Build Coastguard Worker {
1085*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
1086*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
1087*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
1088*49cdfc7eSAndroid Build Coastguard Worker 
1089*49cdfc7eSAndroid Build Coastguard Worker 	rval = open(name->path, oflag);
1090*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
1091*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
1092*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
1093*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
1094*49cdfc7eSAndroid Build Coastguard Worker 		rval = open_path(&newname, oflag);
1095*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
1096*49cdfc7eSAndroid Build Coastguard Worker 	}
1097*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
1098*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
1099*49cdfc7eSAndroid Build Coastguard Worker }
1100*49cdfc7eSAndroid Build Coastguard Worker 
opendir_path(pathname_t * name)1101*49cdfc7eSAndroid Build Coastguard Worker DIR *opendir_path(pathname_t * name)
1102*49cdfc7eSAndroid Build Coastguard Worker {
1103*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
1104*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
1105*49cdfc7eSAndroid Build Coastguard Worker 	DIR *rval;
1106*49cdfc7eSAndroid Build Coastguard Worker 
1107*49cdfc7eSAndroid Build Coastguard Worker 	rval = opendir(name->path);
1108*49cdfc7eSAndroid Build Coastguard Worker 	if (rval || errno != ENAMETOOLONG)
1109*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
1110*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
1111*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
1112*49cdfc7eSAndroid Build Coastguard Worker 		rval = opendir_path(&newname);
1113*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
1114*49cdfc7eSAndroid Build Coastguard Worker 	}
1115*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
1116*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
1117*49cdfc7eSAndroid Build Coastguard Worker }
1118*49cdfc7eSAndroid Build Coastguard Worker 
process_freq(char * arg)1119*49cdfc7eSAndroid Build Coastguard Worker void process_freq(char *arg)
1120*49cdfc7eSAndroid Build Coastguard Worker {
1121*49cdfc7eSAndroid Build Coastguard Worker 	opdesc_t *p;
1122*49cdfc7eSAndroid Build Coastguard Worker 	char *s;
1123*49cdfc7eSAndroid Build Coastguard Worker 
1124*49cdfc7eSAndroid Build Coastguard Worker 	s = strchr(arg, '=');
1125*49cdfc7eSAndroid Build Coastguard Worker 	if (s == NULL) {
1126*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr, "bad argument '%s'\n", arg);
1127*49cdfc7eSAndroid Build Coastguard Worker 		exit(1);
1128*49cdfc7eSAndroid Build Coastguard Worker 	}
1129*49cdfc7eSAndroid Build Coastguard Worker 	*s++ = '\0';
1130*49cdfc7eSAndroid Build Coastguard Worker 	for (p = ops; p < ops_end; p++) {
1131*49cdfc7eSAndroid Build Coastguard Worker 		if (strcmp(arg, p->name) == 0) {
1132*49cdfc7eSAndroid Build Coastguard Worker 			p->freq = atoi(s);
1133*49cdfc7eSAndroid Build Coastguard Worker 			return;
1134*49cdfc7eSAndroid Build Coastguard Worker 		}
1135*49cdfc7eSAndroid Build Coastguard Worker 	}
1136*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(stderr, "can't find op type %s for -f\n", arg);
1137*49cdfc7eSAndroid Build Coastguard Worker 	exit(1);
1138*49cdfc7eSAndroid Build Coastguard Worker }
1139*49cdfc7eSAndroid Build Coastguard Worker 
readlink_path(pathname_t * name,char * lbuf,size_t lbufsiz)1140*49cdfc7eSAndroid Build Coastguard Worker int readlink_path(pathname_t * name, char *lbuf, size_t lbufsiz)
1141*49cdfc7eSAndroid Build Coastguard Worker {
1142*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
1143*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
1144*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
1145*49cdfc7eSAndroid Build Coastguard Worker 
1146*49cdfc7eSAndroid Build Coastguard Worker 	rval = readlink(name->path, lbuf, lbufsiz-1);
1147*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0)
1148*49cdfc7eSAndroid Build Coastguard Worker 		lbuf[rval] = '\0';
1149*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
1150*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
1151*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
1152*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
1153*49cdfc7eSAndroid Build Coastguard Worker 		rval = readlink_path(&newname, lbuf, lbufsiz);
1154*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
1155*49cdfc7eSAndroid Build Coastguard Worker 	}
1156*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
1157*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
1158*49cdfc7eSAndroid Build Coastguard Worker }
1159*49cdfc7eSAndroid Build Coastguard Worker 
rename_path(pathname_t * name1,pathname_t * name2)1160*49cdfc7eSAndroid Build Coastguard Worker int rename_path(pathname_t * name1, pathname_t * name2)
1161*49cdfc7eSAndroid Build Coastguard Worker {
1162*49cdfc7eSAndroid Build Coastguard Worker 	char buf1[MAXNAMELEN];
1163*49cdfc7eSAndroid Build Coastguard Worker 	char buf2[MAXNAMELEN];
1164*49cdfc7eSAndroid Build Coastguard Worker 	int down1;
1165*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname1;
1166*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname2;
1167*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
1168*49cdfc7eSAndroid Build Coastguard Worker 
1169*49cdfc7eSAndroid Build Coastguard Worker 	rval = rename(name1->path, name2->path);
1170*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
1171*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
1172*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name1, buf1, &newname1);
1173*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name2, buf2, &newname2);
1174*49cdfc7eSAndroid Build Coastguard Worker 	if (strcmp(buf1, buf2) == 0) {
1175*49cdfc7eSAndroid Build Coastguard Worker 		if (chdir(buf1) == 0) {
1176*49cdfc7eSAndroid Build Coastguard Worker 			rval = rename_path(&newname1, &newname2);
1177*49cdfc7eSAndroid Build Coastguard Worker 			chdir("..");
1178*49cdfc7eSAndroid Build Coastguard Worker 		}
1179*49cdfc7eSAndroid Build Coastguard Worker 	} else {
1180*49cdfc7eSAndroid Build Coastguard Worker 		if (strcmp(buf1, "..") == 0)
1181*49cdfc7eSAndroid Build Coastguard Worker 			down1 = 0;
1182*49cdfc7eSAndroid Build Coastguard Worker 		else if (strcmp(buf2, "..") == 0)
1183*49cdfc7eSAndroid Build Coastguard Worker 			down1 = 1;
1184*49cdfc7eSAndroid Build Coastguard Worker 		else if (strlen(buf1) == 0)
1185*49cdfc7eSAndroid Build Coastguard Worker 			down1 = 0;
1186*49cdfc7eSAndroid Build Coastguard Worker 		else if (strlen(buf2) == 0)
1187*49cdfc7eSAndroid Build Coastguard Worker 			down1 = 1;
1188*49cdfc7eSAndroid Build Coastguard Worker 		else
1189*49cdfc7eSAndroid Build Coastguard Worker 			down1 = MAX(newname1.len, 3 + name2->len) <=
1190*49cdfc7eSAndroid Build Coastguard Worker 			    MAX(3 + name1->len, newname2.len);
1191*49cdfc7eSAndroid Build Coastguard Worker 		if (down1) {
1192*49cdfc7eSAndroid Build Coastguard Worker 			free_pathname(&newname2);
1193*49cdfc7eSAndroid Build Coastguard Worker 			append_pathname(&newname2, "../");
1194*49cdfc7eSAndroid Build Coastguard Worker 			append_pathname(&newname2, name2->path);
1195*49cdfc7eSAndroid Build Coastguard Worker 			if (chdir(buf1) == 0) {
1196*49cdfc7eSAndroid Build Coastguard Worker 				rval = rename_path(&newname1, &newname2);
1197*49cdfc7eSAndroid Build Coastguard Worker 				chdir("..");
1198*49cdfc7eSAndroid Build Coastguard Worker 			}
1199*49cdfc7eSAndroid Build Coastguard Worker 		} else {
1200*49cdfc7eSAndroid Build Coastguard Worker 			free_pathname(&newname1);
1201*49cdfc7eSAndroid Build Coastguard Worker 			append_pathname(&newname1, "../");
1202*49cdfc7eSAndroid Build Coastguard Worker 			append_pathname(&newname1, name1->path);
1203*49cdfc7eSAndroid Build Coastguard Worker 			if (chdir(buf2) == 0) {
1204*49cdfc7eSAndroid Build Coastguard Worker 				rval = rename_path(&newname1, &newname2);
1205*49cdfc7eSAndroid Build Coastguard Worker 				chdir("..");
1206*49cdfc7eSAndroid Build Coastguard Worker 			}
1207*49cdfc7eSAndroid Build Coastguard Worker 		}
1208*49cdfc7eSAndroid Build Coastguard Worker 	}
1209*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname1);
1210*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname2);
1211*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
1212*49cdfc7eSAndroid Build Coastguard Worker }
1213*49cdfc7eSAndroid Build Coastguard Worker 
rmdir_path(pathname_t * name)1214*49cdfc7eSAndroid Build Coastguard Worker int rmdir_path(pathname_t * name)
1215*49cdfc7eSAndroid Build Coastguard Worker {
1216*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
1217*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
1218*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
1219*49cdfc7eSAndroid Build Coastguard Worker 
1220*49cdfc7eSAndroid Build Coastguard Worker 	rval = rmdir(name->path);
1221*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
1222*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
1223*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
1224*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
1225*49cdfc7eSAndroid Build Coastguard Worker 		rval = rmdir_path(&newname);
1226*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
1227*49cdfc7eSAndroid Build Coastguard Worker 	}
1228*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
1229*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
1230*49cdfc7eSAndroid Build Coastguard Worker }
1231*49cdfc7eSAndroid Build Coastguard Worker 
separate_pathname(pathname_t * name,char * buf,pathname_t * newname)1232*49cdfc7eSAndroid Build Coastguard Worker void separate_pathname(pathname_t * name, char *buf, pathname_t * newname)
1233*49cdfc7eSAndroid Build Coastguard Worker {
1234*49cdfc7eSAndroid Build Coastguard Worker 	char *slash;
1235*49cdfc7eSAndroid Build Coastguard Worker 
1236*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(newname);
1237*49cdfc7eSAndroid Build Coastguard Worker 	slash = strchr(name->path, '/');
1238*49cdfc7eSAndroid Build Coastguard Worker 	if (slash == NULL) {
1239*49cdfc7eSAndroid Build Coastguard Worker 		buf[0] = '\0';
1240*49cdfc7eSAndroid Build Coastguard Worker 		return;
1241*49cdfc7eSAndroid Build Coastguard Worker 	}
1242*49cdfc7eSAndroid Build Coastguard Worker 	*slash = '\0';
1243*49cdfc7eSAndroid Build Coastguard Worker 	strcpy(buf, name->path);
1244*49cdfc7eSAndroid Build Coastguard Worker 	*slash = '/';
1245*49cdfc7eSAndroid Build Coastguard Worker 	append_pathname(newname, slash + 1);
1246*49cdfc7eSAndroid Build Coastguard Worker }
1247*49cdfc7eSAndroid Build Coastguard Worker 
1248*49cdfc7eSAndroid Build Coastguard Worker #define WIDTH 80
1249*49cdfc7eSAndroid Build Coastguard Worker 
show_ops(int flag,char * lead_str)1250*49cdfc7eSAndroid Build Coastguard Worker void show_ops(int flag, char *lead_str)
1251*49cdfc7eSAndroid Build Coastguard Worker {
1252*49cdfc7eSAndroid Build Coastguard Worker 	opdesc_t *p;
1253*49cdfc7eSAndroid Build Coastguard Worker 
1254*49cdfc7eSAndroid Build Coastguard Worker 	if (flag < 0) {
1255*49cdfc7eSAndroid Build Coastguard Worker 		/* print in list form */
1256*49cdfc7eSAndroid Build Coastguard Worker 		int x = WIDTH;
1257*49cdfc7eSAndroid Build Coastguard Worker 
1258*49cdfc7eSAndroid Build Coastguard Worker 		for (p = ops; p < ops_end; p++) {
1259*49cdfc7eSAndroid Build Coastguard Worker 			if (lead_str != NULL
1260*49cdfc7eSAndroid Build Coastguard Worker 			    && x + strlen(p->name) >= WIDTH - 5)
1261*49cdfc7eSAndroid Build Coastguard Worker 				x = printf("%s%s", (p == ops) ? "" : "\n",
1262*49cdfc7eSAndroid Build Coastguard Worker 					   lead_str);
1263*49cdfc7eSAndroid Build Coastguard Worker 			x += printf("%s ", p->name);
1264*49cdfc7eSAndroid Build Coastguard Worker 		}
1265*49cdfc7eSAndroid Build Coastguard Worker 		printf("\n");
1266*49cdfc7eSAndroid Build Coastguard Worker 	} else {
1267*49cdfc7eSAndroid Build Coastguard Worker 		int f;
1268*49cdfc7eSAndroid Build Coastguard Worker 		for (f = 0, p = ops; p < ops_end; p++)
1269*49cdfc7eSAndroid Build Coastguard Worker 			f += p->freq;
1270*49cdfc7eSAndroid Build Coastguard Worker 
1271*49cdfc7eSAndroid Build Coastguard Worker 		if (f == 0)
1272*49cdfc7eSAndroid Build Coastguard Worker 			flag = 1;
1273*49cdfc7eSAndroid Build Coastguard Worker 
1274*49cdfc7eSAndroid Build Coastguard Worker 		for (p = ops; p < ops_end; p++) {
1275*49cdfc7eSAndroid Build Coastguard Worker 			if (flag != 0 || p->freq > 0) {
1276*49cdfc7eSAndroid Build Coastguard Worker 				if (lead_str != NULL)
1277*49cdfc7eSAndroid Build Coastguard Worker 					printf("%s", lead_str);
1278*49cdfc7eSAndroid Build Coastguard Worker 				printf("%20s %d/%d %s\n",
1279*49cdfc7eSAndroid Build Coastguard Worker 				       p->name, p->freq, f,
1280*49cdfc7eSAndroid Build Coastguard Worker 				       (p->iswrite == 0) ? " " : "write op");
1281*49cdfc7eSAndroid Build Coastguard Worker 			}
1282*49cdfc7eSAndroid Build Coastguard Worker 		}
1283*49cdfc7eSAndroid Build Coastguard Worker 	}
1284*49cdfc7eSAndroid Build Coastguard Worker }
1285*49cdfc7eSAndroid Build Coastguard Worker 
stat64_path(pathname_t * name,struct stat64 * sbuf)1286*49cdfc7eSAndroid Build Coastguard Worker int stat64_path(pathname_t * name, struct stat64 *sbuf)
1287*49cdfc7eSAndroid Build Coastguard Worker {
1288*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
1289*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
1290*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
1291*49cdfc7eSAndroid Build Coastguard Worker 
1292*49cdfc7eSAndroid Build Coastguard Worker 	rval = stat64(name->path, sbuf);
1293*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
1294*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
1295*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
1296*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
1297*49cdfc7eSAndroid Build Coastguard Worker 		rval = stat64_path(&newname, sbuf);
1298*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
1299*49cdfc7eSAndroid Build Coastguard Worker 	}
1300*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
1301*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
1302*49cdfc7eSAndroid Build Coastguard Worker }
1303*49cdfc7eSAndroid Build Coastguard Worker 
symlink_path(const char * name1,pathname_t * name)1304*49cdfc7eSAndroid Build Coastguard Worker int symlink_path(const char *name1, pathname_t * name)
1305*49cdfc7eSAndroid Build Coastguard Worker {
1306*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
1307*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
1308*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
1309*49cdfc7eSAndroid Build Coastguard Worker 
1310*49cdfc7eSAndroid Build Coastguard Worker 	if (!strcmp(name1, name->path)) {
1311*49cdfc7eSAndroid Build Coastguard Worker 		printf("yikes! %s %s\n", name1, name->path);
1312*49cdfc7eSAndroid Build Coastguard Worker 		return 0;
1313*49cdfc7eSAndroid Build Coastguard Worker 	}
1314*49cdfc7eSAndroid Build Coastguard Worker 
1315*49cdfc7eSAndroid Build Coastguard Worker 	rval = symlink(name1, name->path);
1316*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
1317*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
1318*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
1319*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
1320*49cdfc7eSAndroid Build Coastguard Worker 		rval = symlink_path(name1, &newname);
1321*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
1322*49cdfc7eSAndroid Build Coastguard Worker 	}
1323*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
1324*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
1325*49cdfc7eSAndroid Build Coastguard Worker }
1326*49cdfc7eSAndroid Build Coastguard Worker 
truncate64_path(pathname_t * name,off64_t length)1327*49cdfc7eSAndroid Build Coastguard Worker int truncate64_path(pathname_t * name, off64_t length)
1328*49cdfc7eSAndroid Build Coastguard Worker {
1329*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
1330*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
1331*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
1332*49cdfc7eSAndroid Build Coastguard Worker 
1333*49cdfc7eSAndroid Build Coastguard Worker 	rval = truncate64(name->path, length);
1334*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
1335*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
1336*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
1337*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
1338*49cdfc7eSAndroid Build Coastguard Worker 		rval = truncate64_path(&newname, length);
1339*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
1340*49cdfc7eSAndroid Build Coastguard Worker 	}
1341*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
1342*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
1343*49cdfc7eSAndroid Build Coastguard Worker }
1344*49cdfc7eSAndroid Build Coastguard Worker 
unlink_path(pathname_t * name)1345*49cdfc7eSAndroid Build Coastguard Worker int unlink_path(pathname_t * name)
1346*49cdfc7eSAndroid Build Coastguard Worker {
1347*49cdfc7eSAndroid Build Coastguard Worker 	char buf[MAXNAMELEN];
1348*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newname;
1349*49cdfc7eSAndroid Build Coastguard Worker 	int rval;
1350*49cdfc7eSAndroid Build Coastguard Worker 
1351*49cdfc7eSAndroid Build Coastguard Worker 	rval = unlink(name->path);
1352*49cdfc7eSAndroid Build Coastguard Worker 	if (rval >= 0 || errno != ENAMETOOLONG)
1353*49cdfc7eSAndroid Build Coastguard Worker 		return rval;
1354*49cdfc7eSAndroid Build Coastguard Worker 	separate_pathname(name, buf, &newname);
1355*49cdfc7eSAndroid Build Coastguard Worker 	if (chdir(buf) == 0) {
1356*49cdfc7eSAndroid Build Coastguard Worker 		rval = unlink_path(&newname);
1357*49cdfc7eSAndroid Build Coastguard Worker 		chdir("..");
1358*49cdfc7eSAndroid Build Coastguard Worker 	}
1359*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newname);
1360*49cdfc7eSAndroid Build Coastguard Worker 	return rval;
1361*49cdfc7eSAndroid Build Coastguard Worker }
1362*49cdfc7eSAndroid Build Coastguard Worker 
usage(void)1363*49cdfc7eSAndroid Build Coastguard Worker void usage(void)
1364*49cdfc7eSAndroid Build Coastguard Worker {
1365*49cdfc7eSAndroid Build Coastguard Worker 	printf("Usage: %s -H   or\n", myprog);
1366*49cdfc7eSAndroid Build Coastguard Worker 	printf
1367*49cdfc7eSAndroid Build Coastguard Worker 	    ("       %s [-c][-d dir][-e errtg][-f op_name=freq][-l loops][-n nops]\n",
1368*49cdfc7eSAndroid Build Coastguard Worker 	     myprog);
1369*49cdfc7eSAndroid Build Coastguard Worker 	printf("          [-p nproc][-r len][-s seed][-v][-w][-z][-S]\n");
1370*49cdfc7eSAndroid Build Coastguard Worker 	printf("where\n");
1371*49cdfc7eSAndroid Build Coastguard Worker 	printf
1372*49cdfc7eSAndroid Build Coastguard Worker 	    ("   -c               specifies not to remove files(cleanup) after execution\n");
1373*49cdfc7eSAndroid Build Coastguard Worker 	printf
1374*49cdfc7eSAndroid Build Coastguard Worker 	    ("   -d dir           specifies the base directory for operations\n");
1375*49cdfc7eSAndroid Build Coastguard Worker 	printf("   -e errtg         specifies error injection stuff\n");
1376*49cdfc7eSAndroid Build Coastguard Worker 	printf
1377*49cdfc7eSAndroid Build Coastguard Worker 	    ("   -f op_name=freq  changes the frequency of option name to freq\n");
1378*49cdfc7eSAndroid Build Coastguard Worker 	printf("                    the valid operation names are:\n");
1379*49cdfc7eSAndroid Build Coastguard Worker 	show_ops(-1, "                        ");
1380*49cdfc7eSAndroid Build Coastguard Worker 	printf
1381*49cdfc7eSAndroid Build Coastguard Worker 	    ("   -l loops         specifies the no. of times the testrun should loop.\n");
1382*49cdfc7eSAndroid Build Coastguard Worker 	printf("                     *use 0 for infinite (default 1)\n");
1383*49cdfc7eSAndroid Build Coastguard Worker 	printf
1384*49cdfc7eSAndroid Build Coastguard Worker 	    ("   -n nops          specifies the no. of operations per process (default 1)\n");
1385*49cdfc7eSAndroid Build Coastguard Worker 	printf
1386*49cdfc7eSAndroid Build Coastguard Worker 	    ("   -p nproc         specifies the no. of processes (default 1)\n");
1387*49cdfc7eSAndroid Build Coastguard Worker 	printf("   -r               specifies random name padding\n");
1388*49cdfc7eSAndroid Build Coastguard Worker 	printf
1389*49cdfc7eSAndroid Build Coastguard Worker 	    ("   -s seed          specifies the seed for the random generator (default random)\n");
1390*49cdfc7eSAndroid Build Coastguard Worker 	printf("   -v               specifies verbose mode\n");
1391*49cdfc7eSAndroid Build Coastguard Worker 	printf
1392*49cdfc7eSAndroid Build Coastguard Worker 	    ("   -w               zeros frequencies of non-write operations\n");
1393*49cdfc7eSAndroid Build Coastguard Worker 	printf("   -z               zeros frequencies of all operations\n");
1394*49cdfc7eSAndroid Build Coastguard Worker 	printf
1395*49cdfc7eSAndroid Build Coastguard Worker 	    ("   -S               prints the table of operations (omitting zero frequency)\n");
1396*49cdfc7eSAndroid Build Coastguard Worker 	printf("   -H               prints usage and exits\n");
1397*49cdfc7eSAndroid Build Coastguard Worker 	printf
1398*49cdfc7eSAndroid Build Coastguard Worker 	    ("   -X               don't do anything XFS specific (default with -DNO_XFS)\n");
1399*49cdfc7eSAndroid Build Coastguard Worker }
1400*49cdfc7eSAndroid Build Coastguard Worker 
write_freq(void)1401*49cdfc7eSAndroid Build Coastguard Worker void write_freq(void)
1402*49cdfc7eSAndroid Build Coastguard Worker {
1403*49cdfc7eSAndroid Build Coastguard Worker 	opdesc_t *p;
1404*49cdfc7eSAndroid Build Coastguard Worker 
1405*49cdfc7eSAndroid Build Coastguard Worker 	for (p = ops; p < ops_end; p++) {
1406*49cdfc7eSAndroid Build Coastguard Worker 		if (!p->iswrite)
1407*49cdfc7eSAndroid Build Coastguard Worker 			p->freq = 0;
1408*49cdfc7eSAndroid Build Coastguard Worker 	}
1409*49cdfc7eSAndroid Build Coastguard Worker }
1410*49cdfc7eSAndroid Build Coastguard Worker 
zero_freq(void)1411*49cdfc7eSAndroid Build Coastguard Worker void zero_freq(void)
1412*49cdfc7eSAndroid Build Coastguard Worker {
1413*49cdfc7eSAndroid Build Coastguard Worker 	opdesc_t *p;
1414*49cdfc7eSAndroid Build Coastguard Worker 
1415*49cdfc7eSAndroid Build Coastguard Worker 	for (p = ops; p < ops_end; p++)
1416*49cdfc7eSAndroid Build Coastguard Worker 		p->freq = 0;
1417*49cdfc7eSAndroid Build Coastguard Worker }
1418*49cdfc7eSAndroid Build Coastguard Worker 
1419*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
1420*49cdfc7eSAndroid Build Coastguard Worker 
allocsp_f(int opno,long r)1421*49cdfc7eSAndroid Build Coastguard Worker void allocsp_f(int opno, long r)
1422*49cdfc7eSAndroid Build Coastguard Worker {
1423*49cdfc7eSAndroid Build Coastguard Worker 	int e;
1424*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
1425*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
1426*49cdfc7eSAndroid Build Coastguard Worker 	struct xfs_flock64 fl;
1427*49cdfc7eSAndroid Build Coastguard Worker 	__s64 lr;
1428*49cdfc7eSAndroid Build Coastguard Worker 	__s64 off;
1429*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 stb;
1430*49cdfc7eSAndroid Build Coastguard Worker 	int v;
1431*49cdfc7eSAndroid Build Coastguard Worker 
1432*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
1433*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1434*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1435*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: allocsp - no filename\n", procid, opno);
1436*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1437*49cdfc7eSAndroid Build Coastguard Worker 		return;
1438*49cdfc7eSAndroid Build Coastguard Worker 	}
1439*49cdfc7eSAndroid Build Coastguard Worker 	fd = open_path(&f, O_RDWR);
1440*49cdfc7eSAndroid Build Coastguard Worker 	e = fd < 0 ? errno : 0;
1441*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
1442*49cdfc7eSAndroid Build Coastguard Worker 	if (fd < 0) {
1443*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1444*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: allocsp - open %s failed %d\n",
1445*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, e);
1446*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1447*49cdfc7eSAndroid Build Coastguard Worker 		return;
1448*49cdfc7eSAndroid Build Coastguard Worker 	}
1449*49cdfc7eSAndroid Build Coastguard Worker 	if (fstat64(fd, &stb) < 0) {
1450*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1451*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: allocsp - fstat64 %s failed %d\n",
1452*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, errno);
1453*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1454*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
1455*49cdfc7eSAndroid Build Coastguard Worker 		return;
1456*49cdfc7eSAndroid Build Coastguard Worker 	}
1457*49cdfc7eSAndroid Build Coastguard Worker 	lr = ((__s64) random() << 32) + random();
1458*49cdfc7eSAndroid Build Coastguard Worker 	off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
1459*49cdfc7eSAndroid Build Coastguard Worker 	off %= maxfsize;
1460*49cdfc7eSAndroid Build Coastguard Worker 	memset(&fl, 0, sizeof(fl));
1461*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_whence = SEEK_SET;
1462*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_start = off;
1463*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_len = 0;
1464*49cdfc7eSAndroid Build Coastguard Worker 	e = ioctl(fd, XFS_IOC_ALLOCSP64, &fl) < 0 ? errno : 0;
1465*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
1466*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: ioctl(XFS_IOC_ALLOCSP64) %s %lld 0 %d\n",
1467*49cdfc7eSAndroid Build Coastguard Worker 		       procid, opno, f.path, (long long)off, e);
1468*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
1469*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
1470*49cdfc7eSAndroid Build Coastguard Worker }
1471*49cdfc7eSAndroid Build Coastguard Worker 
attr_remove_f(int opno,long r)1472*49cdfc7eSAndroid Build Coastguard Worker void attr_remove_f(int opno, long r)
1473*49cdfc7eSAndroid Build Coastguard Worker {
1474*49cdfc7eSAndroid Build Coastguard Worker 	attrlist_ent_t *aep;
1475*49cdfc7eSAndroid Build Coastguard Worker 	attrlist_t *alist;
1476*49cdfc7eSAndroid Build Coastguard Worker 	char *aname;
1477*49cdfc7eSAndroid Build Coastguard Worker 	char buf[4096];
1478*49cdfc7eSAndroid Build Coastguard Worker 	attrlist_cursor_t cursor;
1479*49cdfc7eSAndroid Build Coastguard Worker 	int e;
1480*49cdfc7eSAndroid Build Coastguard Worker 	int ent;
1481*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
1482*49cdfc7eSAndroid Build Coastguard Worker 	int total;
1483*49cdfc7eSAndroid Build Coastguard Worker 	int v;
1484*49cdfc7eSAndroid Build Coastguard Worker 	int which;
1485*49cdfc7eSAndroid Build Coastguard Worker 
1486*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
1487*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1488*49cdfc7eSAndroid Build Coastguard Worker 		append_pathname(&f, ".");
1489*49cdfc7eSAndroid Build Coastguard Worker 	total = 0;
1490*49cdfc7eSAndroid Build Coastguard Worker 	memset(&cursor, 0x00, sizeof(cursor));
1491*49cdfc7eSAndroid Build Coastguard Worker 	do {
1492*49cdfc7eSAndroid Build Coastguard Worker 		e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW,
1493*49cdfc7eSAndroid Build Coastguard Worker 				   &cursor);
1494*49cdfc7eSAndroid Build Coastguard Worker 		check_cwd();
1495*49cdfc7eSAndroid Build Coastguard Worker 		if (e)
1496*49cdfc7eSAndroid Build Coastguard Worker 			break;
1497*49cdfc7eSAndroid Build Coastguard Worker 		alist = (attrlist_t *) buf;
1498*49cdfc7eSAndroid Build Coastguard Worker 		total += alist->al_count;
1499*49cdfc7eSAndroid Build Coastguard Worker 	} while (alist->al_more);
1500*49cdfc7eSAndroid Build Coastguard Worker 	if (total == 0) {
1501*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1502*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: attr_remove - no attrs for %s\n",
1503*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path);
1504*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1505*49cdfc7eSAndroid Build Coastguard Worker 		return;
1506*49cdfc7eSAndroid Build Coastguard Worker 	}
1507*49cdfc7eSAndroid Build Coastguard Worker 	which = (int)(random() % total);
1508*49cdfc7eSAndroid Build Coastguard Worker 	memset(&cursor, 0x00, sizeof(cursor));
1509*49cdfc7eSAndroid Build Coastguard Worker 	ent = 0;
1510*49cdfc7eSAndroid Build Coastguard Worker 	aname = NULL;
1511*49cdfc7eSAndroid Build Coastguard Worker 	do {
1512*49cdfc7eSAndroid Build Coastguard Worker 		e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW,
1513*49cdfc7eSAndroid Build Coastguard Worker 				   &cursor);
1514*49cdfc7eSAndroid Build Coastguard Worker 		check_cwd();
1515*49cdfc7eSAndroid Build Coastguard Worker 		if (e)
1516*49cdfc7eSAndroid Build Coastguard Worker 			break;
1517*49cdfc7eSAndroid Build Coastguard Worker 		alist = (attrlist_t *) buf;
1518*49cdfc7eSAndroid Build Coastguard Worker 		if (which < ent + alist->al_count) {
1519*49cdfc7eSAndroid Build Coastguard Worker 			aep = (attrlist_ent_t *)
1520*49cdfc7eSAndroid Build Coastguard Worker 			    & buf[alist->al_offset[which - ent]];
1521*49cdfc7eSAndroid Build Coastguard Worker 			aname = aep->a_name;
1522*49cdfc7eSAndroid Build Coastguard Worker 			break;
1523*49cdfc7eSAndroid Build Coastguard Worker 		}
1524*49cdfc7eSAndroid Build Coastguard Worker 		ent += alist->al_count;
1525*49cdfc7eSAndroid Build Coastguard Worker 	} while (alist->al_more);
1526*49cdfc7eSAndroid Build Coastguard Worker 	if (aname == NULL) {
1527*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1528*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: attr_remove - name %d not found at %s\n",
1529*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, which, f.path);
1530*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1531*49cdfc7eSAndroid Build Coastguard Worker 		return;
1532*49cdfc7eSAndroid Build Coastguard Worker 	}
1533*49cdfc7eSAndroid Build Coastguard Worker 	e = attr_remove_path(&f, aname, ATTR_DONTFOLLOW) < 0 ? errno : 0;
1534*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
1535*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
1536*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: attr_remove %s %s %d\n",
1537*49cdfc7eSAndroid Build Coastguard Worker 		       procid, opno, f.path, aname, e);
1538*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
1539*49cdfc7eSAndroid Build Coastguard Worker }
1540*49cdfc7eSAndroid Build Coastguard Worker 
attr_set_f(int opno,long r)1541*49cdfc7eSAndroid Build Coastguard Worker void attr_set_f(int opno, long r)
1542*49cdfc7eSAndroid Build Coastguard Worker {
1543*49cdfc7eSAndroid Build Coastguard Worker 	char aname[10];
1544*49cdfc7eSAndroid Build Coastguard Worker 	char *aval;
1545*49cdfc7eSAndroid Build Coastguard Worker 	int e;
1546*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
1547*49cdfc7eSAndroid Build Coastguard Worker 	int len;
1548*49cdfc7eSAndroid Build Coastguard Worker 	static int lengths[] = { 10, 100, 1000, 10000 };
1549*49cdfc7eSAndroid Build Coastguard Worker 	int li;
1550*49cdfc7eSAndroid Build Coastguard Worker 	int v;
1551*49cdfc7eSAndroid Build Coastguard Worker 
1552*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
1553*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1554*49cdfc7eSAndroid Build Coastguard Worker 		append_pathname(&f, ".");
1555*49cdfc7eSAndroid Build Coastguard Worker 	sprintf(aname, "a%x", nameseq++);
1556*49cdfc7eSAndroid Build Coastguard Worker 	li = (int)(random() % ARRAY_SIZE(lengths));
1557*49cdfc7eSAndroid Build Coastguard Worker 	len = (int)(random() % lengths[li]);
1558*49cdfc7eSAndroid Build Coastguard Worker 	if (len == 0)
1559*49cdfc7eSAndroid Build Coastguard Worker 		len = 1;
1560*49cdfc7eSAndroid Build Coastguard Worker 	aval = malloc(len);
1561*49cdfc7eSAndroid Build Coastguard Worker 	memset(aval, nameseq & 0xff, len);
1562*49cdfc7eSAndroid Build Coastguard Worker 	e = attr_set_path(&f, aname, aval, len, ATTR_DONTFOLLOW) < 0 ?
1563*49cdfc7eSAndroid Build Coastguard Worker 	    errno : 0;
1564*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
1565*49cdfc7eSAndroid Build Coastguard Worker 	free(aval);
1566*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
1567*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: attr_set %s %s %d\n", procid, opno, f.path,
1568*49cdfc7eSAndroid Build Coastguard Worker 		       aname, e);
1569*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
1570*49cdfc7eSAndroid Build Coastguard Worker }
1571*49cdfc7eSAndroid Build Coastguard Worker 
bulkstat_f(int opno,long r)1572*49cdfc7eSAndroid Build Coastguard Worker void bulkstat_f(int opno, long r)
1573*49cdfc7eSAndroid Build Coastguard Worker {
1574*49cdfc7eSAndroid Build Coastguard Worker 	__s32 count;
1575*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
1576*49cdfc7eSAndroid Build Coastguard Worker 	__u64 last;
1577*49cdfc7eSAndroid Build Coastguard Worker 	__s32 nent;
1578*49cdfc7eSAndroid Build Coastguard Worker 	xfs_bstat_t *t;
1579*49cdfc7eSAndroid Build Coastguard Worker 	int64_t total;
1580*49cdfc7eSAndroid Build Coastguard Worker 	xfs_fsop_bulkreq_t bsr;
1581*49cdfc7eSAndroid Build Coastguard Worker 
1582*49cdfc7eSAndroid Build Coastguard Worker 	last = 0;
1583*49cdfc7eSAndroid Build Coastguard Worker 	nent = (r % 999) + 2;
1584*49cdfc7eSAndroid Build Coastguard Worker 	t = malloc(nent * sizeof(*t));
1585*49cdfc7eSAndroid Build Coastguard Worker 	fd = open(".", O_RDONLY);
1586*49cdfc7eSAndroid Build Coastguard Worker 	total = 0;
1587*49cdfc7eSAndroid Build Coastguard Worker 
1588*49cdfc7eSAndroid Build Coastguard Worker 	memset(&bsr, 0, sizeof(bsr));
1589*49cdfc7eSAndroid Build Coastguard Worker 	bsr.lastip = &last;
1590*49cdfc7eSAndroid Build Coastguard Worker 	bsr.icount = nent;
1591*49cdfc7eSAndroid Build Coastguard Worker 	bsr.ubuffer = t;
1592*49cdfc7eSAndroid Build Coastguard Worker 	bsr.ocount = &count;
1593*49cdfc7eSAndroid Build Coastguard Worker 
1594*49cdfc7eSAndroid Build Coastguard Worker 	while (ioctl(fd, XFS_IOC_FSBULKSTAT, &bsr) == 0 && count > 0)
1595*49cdfc7eSAndroid Build Coastguard Worker 		total += count;
1596*49cdfc7eSAndroid Build Coastguard Worker 	free(t);
1597*49cdfc7eSAndroid Build Coastguard Worker 	if (verbose)
1598*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: bulkstat nent %d total %lld\n",
1599*49cdfc7eSAndroid Build Coastguard Worker 		       procid, opno, (int)nent, (long long)total);
1600*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
1601*49cdfc7eSAndroid Build Coastguard Worker }
1602*49cdfc7eSAndroid Build Coastguard Worker 
bulkstat1_f(int opno,long r)1603*49cdfc7eSAndroid Build Coastguard Worker void bulkstat1_f(int opno, long r)
1604*49cdfc7eSAndroid Build Coastguard Worker {
1605*49cdfc7eSAndroid Build Coastguard Worker 	int e;
1606*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
1607*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
1608*49cdfc7eSAndroid Build Coastguard Worker 	int good;
1609*49cdfc7eSAndroid Build Coastguard Worker 	__u64 ino;
1610*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 s;
1611*49cdfc7eSAndroid Build Coastguard Worker 	xfs_bstat_t t;
1612*49cdfc7eSAndroid Build Coastguard Worker 	int v;
1613*49cdfc7eSAndroid Build Coastguard Worker 	xfs_fsop_bulkreq_t bsr;
1614*49cdfc7eSAndroid Build Coastguard Worker 
1615*49cdfc7eSAndroid Build Coastguard Worker 	good = random() & 1;
1616*49cdfc7eSAndroid Build Coastguard Worker 	if (good) {
1617*49cdfc7eSAndroid Build Coastguard Worker 		/* use an inode we know exists */
1618*49cdfc7eSAndroid Build Coastguard Worker 		init_pathname(&f);
1619*49cdfc7eSAndroid Build Coastguard Worker 		if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1620*49cdfc7eSAndroid Build Coastguard Worker 			append_pathname(&f, ".");
1621*49cdfc7eSAndroid Build Coastguard Worker 		ino = stat64_path(&f, &s) < 0 ? (ino64_t) r : s.st_ino;
1622*49cdfc7eSAndroid Build Coastguard Worker 		check_cwd();
1623*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1624*49cdfc7eSAndroid Build Coastguard Worker 	} else {
1625*49cdfc7eSAndroid Build Coastguard Worker 		/*
1626*49cdfc7eSAndroid Build Coastguard Worker 		 * pick a random inode
1627*49cdfc7eSAndroid Build Coastguard Worker 		 *
1628*49cdfc7eSAndroid Build Coastguard Worker 		 * note this can generate kernel warning messages
1629*49cdfc7eSAndroid Build Coastguard Worker 		 * since bulkstat_one will read the disk block that
1630*49cdfc7eSAndroid Build Coastguard Worker 		 * would contain a given inode even if that disk
1631*49cdfc7eSAndroid Build Coastguard Worker 		 * block doesn't contain inodes.
1632*49cdfc7eSAndroid Build Coastguard Worker 		 *
1633*49cdfc7eSAndroid Build Coastguard Worker 		 * this is detected later, but not until after the
1634*49cdfc7eSAndroid Build Coastguard Worker 		 * warning is displayed.
1635*49cdfc7eSAndroid Build Coastguard Worker 		 *
1636*49cdfc7eSAndroid Build Coastguard Worker 		 * "XFS: device 0x825- bad inode magic/vsn daddr 0x0 #0"
1637*49cdfc7eSAndroid Build Coastguard Worker 		 *
1638*49cdfc7eSAndroid Build Coastguard Worker 		 */
1639*49cdfc7eSAndroid Build Coastguard Worker 		ino = (ino64_t) r;
1640*49cdfc7eSAndroid Build Coastguard Worker 		v = verbose;
1641*49cdfc7eSAndroid Build Coastguard Worker 	}
1642*49cdfc7eSAndroid Build Coastguard Worker 	fd = open(".", O_RDONLY);
1643*49cdfc7eSAndroid Build Coastguard Worker 
1644*49cdfc7eSAndroid Build Coastguard Worker 	memset(&bsr, 0, sizeof(bsr));
1645*49cdfc7eSAndroid Build Coastguard Worker 	bsr.lastip = &ino;
1646*49cdfc7eSAndroid Build Coastguard Worker 	bsr.icount = 1;
1647*49cdfc7eSAndroid Build Coastguard Worker 	bsr.ubuffer = &t;
1648*49cdfc7eSAndroid Build Coastguard Worker 	bsr.ocount = NULL;
1649*49cdfc7eSAndroid Build Coastguard Worker 
1650*49cdfc7eSAndroid Build Coastguard Worker 	e = ioctl(fd, XFS_IOC_FSBULKSTAT_SINGLE, &bsr) < 0 ? errno : 0;
1651*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
1652*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: bulkstat1 %s ino %lld %d\n",
1653*49cdfc7eSAndroid Build Coastguard Worker 		       procid, opno, good ? "real" : "random",
1654*49cdfc7eSAndroid Build Coastguard Worker 		       (long long)ino, e);
1655*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
1656*49cdfc7eSAndroid Build Coastguard Worker }
1657*49cdfc7eSAndroid Build Coastguard Worker 
1658*49cdfc7eSAndroid Build Coastguard Worker #endif
1659*49cdfc7eSAndroid Build Coastguard Worker 
chown_f(int opno,long r)1660*49cdfc7eSAndroid Build Coastguard Worker void chown_f(int opno, long r)
1661*49cdfc7eSAndroid Build Coastguard Worker {
1662*49cdfc7eSAndroid Build Coastguard Worker 	int e;
1663*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
1664*49cdfc7eSAndroid Build Coastguard Worker 	int nbits;
1665*49cdfc7eSAndroid Build Coastguard Worker 	uid_t u;
1666*49cdfc7eSAndroid Build Coastguard Worker 	int v;
1667*49cdfc7eSAndroid Build Coastguard Worker 
1668*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
1669*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1670*49cdfc7eSAndroid Build Coastguard Worker 		append_pathname(&f, ".");
1671*49cdfc7eSAndroid Build Coastguard Worker 	u = (uid_t) random();
1672*49cdfc7eSAndroid Build Coastguard Worker 	nbits = (int)(random() % 32);
1673*49cdfc7eSAndroid Build Coastguard Worker 	u &= (1 << nbits) - 1;
1674*49cdfc7eSAndroid Build Coastguard Worker 	e = lchown_path(&f, u, -1) < 0 ? errno : 0;
1675*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
1676*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
1677*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: chown %s %d %d\n", procid, opno, f.path, u, e);
1678*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
1679*49cdfc7eSAndroid Build Coastguard Worker }
1680*49cdfc7eSAndroid Build Coastguard Worker 
creat_f(int opno,long r)1681*49cdfc7eSAndroid Build Coastguard Worker void creat_f(int opno, long r)
1682*49cdfc7eSAndroid Build Coastguard Worker {
1683*49cdfc7eSAndroid Build Coastguard Worker 	int e;
1684*49cdfc7eSAndroid Build Coastguard Worker 	int e1;
1685*49cdfc7eSAndroid Build Coastguard Worker 	int extsize;
1686*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
1687*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
1688*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
1689*49cdfc7eSAndroid Build Coastguard Worker 	int id;
1690*49cdfc7eSAndroid Build Coastguard Worker 	int parid;
1691*49cdfc7eSAndroid Build Coastguard Worker 	int type;
1692*49cdfc7eSAndroid Build Coastguard Worker 	int v;
1693*49cdfc7eSAndroid Build Coastguard Worker 	int v1;
1694*49cdfc7eSAndroid Build Coastguard Worker 	int esz = 0;
1695*49cdfc7eSAndroid Build Coastguard Worker 
1696*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v1))
1697*49cdfc7eSAndroid Build Coastguard Worker 		parid = -1;
1698*49cdfc7eSAndroid Build Coastguard Worker 	else
1699*49cdfc7eSAndroid Build Coastguard Worker 		parid = fep->id;
1700*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
1701*49cdfc7eSAndroid Build Coastguard Worker 	type = rtpct ? ((random() % 100) > rtpct ? FT_REG : FT_RTF) : FT_REG;
1702*49cdfc7eSAndroid Build Coastguard Worker 	if (type == FT_RTF)
1703*49cdfc7eSAndroid Build Coastguard Worker 		extsize = (random() % 10) + 1;
1704*49cdfc7eSAndroid Build Coastguard Worker 	else
1705*49cdfc7eSAndroid Build Coastguard Worker 		extsize = 0;
1706*49cdfc7eSAndroid Build Coastguard Worker 	e = generate_fname(fep, type, &f, &id, &v);
1707*49cdfc7eSAndroid Build Coastguard Worker 	v |= v1;
1708*49cdfc7eSAndroid Build Coastguard Worker 	if (!e) {
1709*49cdfc7eSAndroid Build Coastguard Worker 		if (v) {
1710*49cdfc7eSAndroid Build Coastguard Worker 			fent_to_name(&f, &flist[FT_DIR], fep);
1711*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: creat - no filename from %s\n",
1712*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path);
1713*49cdfc7eSAndroid Build Coastguard Worker 		}
1714*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1715*49cdfc7eSAndroid Build Coastguard Worker 		return;
1716*49cdfc7eSAndroid Build Coastguard Worker 	}
1717*49cdfc7eSAndroid Build Coastguard Worker 	fd = creat_path(&f, 0666);
1718*49cdfc7eSAndroid Build Coastguard Worker 	e = fd < 0 ? errno : 0;
1719*49cdfc7eSAndroid Build Coastguard Worker 	e1 = 0;
1720*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
1721*49cdfc7eSAndroid Build Coastguard Worker 	esz = 0;
1722*49cdfc7eSAndroid Build Coastguard Worker 	if (fd >= 0) {
1723*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
1724*49cdfc7eSAndroid Build Coastguard Worker 		struct fsxattr a;
1725*49cdfc7eSAndroid Build Coastguard Worker 		memset(&a, 0, sizeof(a));
1726*49cdfc7eSAndroid Build Coastguard Worker 		if (extsize && ioctl(fd, XFS_IOC_FSGETXATTR, &a) >= 0) {
1727*49cdfc7eSAndroid Build Coastguard Worker 			a.fsx_xflags |= XFS_XFLAG_REALTIME;
1728*49cdfc7eSAndroid Build Coastguard Worker 			a.fsx_extsize =
1729*49cdfc7eSAndroid Build Coastguard Worker 			    geom.rtextsize * geom.blocksize * extsize;
1730*49cdfc7eSAndroid Build Coastguard Worker 			if (ioctl(fd, XFS_IOC_FSSETXATTR, &a) < 0)
1731*49cdfc7eSAndroid Build Coastguard Worker 				e1 = errno;
1732*49cdfc7eSAndroid Build Coastguard Worker 			esz = a.fsx_extsize;
1733*49cdfc7eSAndroid Build Coastguard Worker 
1734*49cdfc7eSAndroid Build Coastguard Worker 		}
1735*49cdfc7eSAndroid Build Coastguard Worker #endif
1736*49cdfc7eSAndroid Build Coastguard Worker 		add_to_flist(type, id, parid);
1737*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
1738*49cdfc7eSAndroid Build Coastguard Worker 	}
1739*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
1740*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: creat %s x:%d %d %d\n", procid, opno, f.path,
1741*49cdfc7eSAndroid Build Coastguard Worker 		       esz, e, e1);
1742*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
1743*49cdfc7eSAndroid Build Coastguard Worker }
1744*49cdfc7eSAndroid Build Coastguard Worker 
setdirect(int fd)1745*49cdfc7eSAndroid Build Coastguard Worker int setdirect(int fd)
1746*49cdfc7eSAndroid Build Coastguard Worker {
1747*49cdfc7eSAndroid Build Coastguard Worker 	static int no_direct;
1748*49cdfc7eSAndroid Build Coastguard Worker 	int flags;
1749*49cdfc7eSAndroid Build Coastguard Worker 
1750*49cdfc7eSAndroid Build Coastguard Worker 	if (no_direct)
1751*49cdfc7eSAndroid Build Coastguard Worker 		return 0;
1752*49cdfc7eSAndroid Build Coastguard Worker 
1753*49cdfc7eSAndroid Build Coastguard Worker 	flags = fcntl(fd, F_GETFL, 0);
1754*49cdfc7eSAndroid Build Coastguard Worker 	if (flags < 0)
1755*49cdfc7eSAndroid Build Coastguard Worker 		return 0;
1756*49cdfc7eSAndroid Build Coastguard Worker 
1757*49cdfc7eSAndroid Build Coastguard Worker 	if (fcntl(fd, F_SETFL, flags | O_DIRECT) < 0) {
1758*49cdfc7eSAndroid Build Coastguard Worker 		if (no_xfs) {
1759*49cdfc7eSAndroid Build Coastguard Worker 			no_direct = 1;
1760*49cdfc7eSAndroid Build Coastguard Worker 			return 0;
1761*49cdfc7eSAndroid Build Coastguard Worker 		}
1762*49cdfc7eSAndroid Build Coastguard Worker 		printf("cannot set O_DIRECT: %s\n", strerror(errno));
1763*49cdfc7eSAndroid Build Coastguard Worker 		return 0;
1764*49cdfc7eSAndroid Build Coastguard Worker 	}
1765*49cdfc7eSAndroid Build Coastguard Worker 
1766*49cdfc7eSAndroid Build Coastguard Worker 	return 1;
1767*49cdfc7eSAndroid Build Coastguard Worker }
1768*49cdfc7eSAndroid Build Coastguard Worker 
dread_f(int opno,long r)1769*49cdfc7eSAndroid Build Coastguard Worker void dread_f(int opno, long r)
1770*49cdfc7eSAndroid Build Coastguard Worker {
1771*49cdfc7eSAndroid Build Coastguard Worker 	int64_t align;
1772*49cdfc7eSAndroid Build Coastguard Worker 	char *buf = NULL;
1773*49cdfc7eSAndroid Build Coastguard Worker 	struct dioattr diob;
1774*49cdfc7eSAndroid Build Coastguard Worker 	int e;
1775*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
1776*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
1777*49cdfc7eSAndroid Build Coastguard Worker 	size_t len;
1778*49cdfc7eSAndroid Build Coastguard Worker 	int64_t lr;
1779*49cdfc7eSAndroid Build Coastguard Worker 	off64_t off;
1780*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 stb;
1781*49cdfc7eSAndroid Build Coastguard Worker 	int v;
1782*49cdfc7eSAndroid Build Coastguard Worker 
1783*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
1784*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1785*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1786*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: dread - no filename\n", procid, opno);
1787*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1788*49cdfc7eSAndroid Build Coastguard Worker 		return;
1789*49cdfc7eSAndroid Build Coastguard Worker 	}
1790*49cdfc7eSAndroid Build Coastguard Worker 	fd = open_path(&f, O_RDONLY);
1791*49cdfc7eSAndroid Build Coastguard Worker 
1792*49cdfc7eSAndroid Build Coastguard Worker 	e = fd < 0 ? errno : 0;
1793*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
1794*49cdfc7eSAndroid Build Coastguard Worker 	if (fd < 0) {
1795*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1796*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: dread - open %s failed %d\n",
1797*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, e);
1798*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1799*49cdfc7eSAndroid Build Coastguard Worker 		return;
1800*49cdfc7eSAndroid Build Coastguard Worker 	}
1801*49cdfc7eSAndroid Build Coastguard Worker 
1802*49cdfc7eSAndroid Build Coastguard Worker 	if (!setdirect(fd)) {
1803*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
1804*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1805*49cdfc7eSAndroid Build Coastguard Worker 		return;
1806*49cdfc7eSAndroid Build Coastguard Worker 	}
1807*49cdfc7eSAndroid Build Coastguard Worker 
1808*49cdfc7eSAndroid Build Coastguard Worker 	if (fstat64(fd, &stb) < 0) {
1809*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1810*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: dread - fstat64 %s failed %d\n",
1811*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, errno);
1812*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1813*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
1814*49cdfc7eSAndroid Build Coastguard Worker 		return;
1815*49cdfc7eSAndroid Build Coastguard Worker 	}
1816*49cdfc7eSAndroid Build Coastguard Worker 	if (stb.st_size == 0) {
1817*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1818*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: dread - %s zero size\n", procid, opno,
1819*49cdfc7eSAndroid Build Coastguard Worker 			       f.path);
1820*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1821*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
1822*49cdfc7eSAndroid Build Coastguard Worker 		return;
1823*49cdfc7eSAndroid Build Coastguard Worker 	}
1824*49cdfc7eSAndroid Build Coastguard Worker 
1825*49cdfc7eSAndroid Build Coastguard Worker 	memset(&diob, 0, sizeof(diob));
1826*49cdfc7eSAndroid Build Coastguard Worker 	if (no_xfs) {
1827*49cdfc7eSAndroid Build Coastguard Worker 		diob.d_miniosz = stb.st_blksize;
1828*49cdfc7eSAndroid Build Coastguard Worker 		diob.d_maxiosz = stb.st_blksize * 256;	/* good number ? */
1829*49cdfc7eSAndroid Build Coastguard Worker 		diob.d_mem = stb.st_blksize;
1830*49cdfc7eSAndroid Build Coastguard Worker 	}
1831*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
1832*49cdfc7eSAndroid Build Coastguard Worker 	else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
1833*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1834*49cdfc7eSAndroid Build Coastguard Worker 			printf
1835*49cdfc7eSAndroid Build Coastguard Worker 			    ("%d/%d: dread - ioctl(fd, XFS_IOC_DIOINFO) %s failed %d\n",
1836*49cdfc7eSAndroid Build Coastguard Worker 			     procid, opno, f.path, errno);
1837*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1838*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
1839*49cdfc7eSAndroid Build Coastguard Worker 		return;
1840*49cdfc7eSAndroid Build Coastguard Worker 	}
1841*49cdfc7eSAndroid Build Coastguard Worker #endif
1842*49cdfc7eSAndroid Build Coastguard Worker 	align = (int64_t) diob.d_miniosz;
1843*49cdfc7eSAndroid Build Coastguard Worker 	lr = ((int64_t) random() << 32) + random();
1844*49cdfc7eSAndroid Build Coastguard Worker 	off = (off64_t) (lr % stb.st_size);
1845*49cdfc7eSAndroid Build Coastguard Worker 	off -= (off % align);
1846*49cdfc7eSAndroid Build Coastguard Worker 	lseek64(fd, off, SEEK_SET);
1847*49cdfc7eSAndroid Build Coastguard Worker 	len = (random() % (getpagesize() * 32)) + 1;
1848*49cdfc7eSAndroid Build Coastguard Worker 	len -= (len % align);
1849*49cdfc7eSAndroid Build Coastguard Worker 	if (len <= 0)
1850*49cdfc7eSAndroid Build Coastguard Worker 		len = align;
1851*49cdfc7eSAndroid Build Coastguard Worker 	else if (len > diob.d_maxiosz)
1852*49cdfc7eSAndroid Build Coastguard Worker 		len = diob.d_maxiosz;
1853*49cdfc7eSAndroid Build Coastguard Worker 	if ((e = posix_memalign((void **)&buf, diob.d_mem, len)) != 0) {
1854*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr, "posix_memalign: %s\n", strerror(e));
1855*49cdfc7eSAndroid Build Coastguard Worker 		exit(1);
1856*49cdfc7eSAndroid Build Coastguard Worker 	}
1857*49cdfc7eSAndroid Build Coastguard Worker 	if (buf == NULL) {
1858*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr, "posix_memalign: buf is NULL\n");
1859*49cdfc7eSAndroid Build Coastguard Worker 		exit(1);
1860*49cdfc7eSAndroid Build Coastguard Worker 	}
1861*49cdfc7eSAndroid Build Coastguard Worker 	e = read(fd, buf, len) < 0 ? errno : 0;
1862*49cdfc7eSAndroid Build Coastguard Worker 	free(buf);
1863*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
1864*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: dread %s [%lld,%ld] %d\n",
1865*49cdfc7eSAndroid Build Coastguard Worker 		       procid, opno, f.path, (long long int)off, (long)len, e);
1866*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
1867*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
1868*49cdfc7eSAndroid Build Coastguard Worker }
1869*49cdfc7eSAndroid Build Coastguard Worker 
dwrite_f(int opno,long r)1870*49cdfc7eSAndroid Build Coastguard Worker void dwrite_f(int opno, long r)
1871*49cdfc7eSAndroid Build Coastguard Worker {
1872*49cdfc7eSAndroid Build Coastguard Worker 	int64_t align;
1873*49cdfc7eSAndroid Build Coastguard Worker 	char *buf = NULL;
1874*49cdfc7eSAndroid Build Coastguard Worker 	struct dioattr diob;
1875*49cdfc7eSAndroid Build Coastguard Worker 	int e;
1876*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
1877*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
1878*49cdfc7eSAndroid Build Coastguard Worker 	size_t len;
1879*49cdfc7eSAndroid Build Coastguard Worker 	int64_t lr;
1880*49cdfc7eSAndroid Build Coastguard Worker 	off64_t off;
1881*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 stb;
1882*49cdfc7eSAndroid Build Coastguard Worker 	int v;
1883*49cdfc7eSAndroid Build Coastguard Worker 
1884*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
1885*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1886*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1887*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: dwrite - no filename\n", procid, opno);
1888*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1889*49cdfc7eSAndroid Build Coastguard Worker 		return;
1890*49cdfc7eSAndroid Build Coastguard Worker 	}
1891*49cdfc7eSAndroid Build Coastguard Worker 	fd = open_path(&f, O_WRONLY);
1892*49cdfc7eSAndroid Build Coastguard Worker 	e = fd < 0 ? errno : 0;
1893*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
1894*49cdfc7eSAndroid Build Coastguard Worker 	if (fd < 0) {
1895*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1896*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: dwrite - open %s failed %d\n",
1897*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, e);
1898*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1899*49cdfc7eSAndroid Build Coastguard Worker 		return;
1900*49cdfc7eSAndroid Build Coastguard Worker 	}
1901*49cdfc7eSAndroid Build Coastguard Worker 
1902*49cdfc7eSAndroid Build Coastguard Worker 	if (!setdirect(fd)) {
1903*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
1904*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1905*49cdfc7eSAndroid Build Coastguard Worker 		return;
1906*49cdfc7eSAndroid Build Coastguard Worker 	}
1907*49cdfc7eSAndroid Build Coastguard Worker 	if (fstat64(fd, &stb) < 0) {
1908*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1909*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: dwrite - fstat64 %s failed %d\n",
1910*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, errno);
1911*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1912*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
1913*49cdfc7eSAndroid Build Coastguard Worker 		return;
1914*49cdfc7eSAndroid Build Coastguard Worker 	}
1915*49cdfc7eSAndroid Build Coastguard Worker 	memset(&diob, 0, sizeof(diob));
1916*49cdfc7eSAndroid Build Coastguard Worker 	if (no_xfs) {
1917*49cdfc7eSAndroid Build Coastguard Worker 		diob.d_miniosz = stb.st_blksize;
1918*49cdfc7eSAndroid Build Coastguard Worker 		diob.d_maxiosz = stb.st_blksize * 256;	/* good number ? */
1919*49cdfc7eSAndroid Build Coastguard Worker 		diob.d_mem = stb.st_blksize;
1920*49cdfc7eSAndroid Build Coastguard Worker 	}
1921*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
1922*49cdfc7eSAndroid Build Coastguard Worker 	else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
1923*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1924*49cdfc7eSAndroid Build Coastguard Worker 			printf
1925*49cdfc7eSAndroid Build Coastguard Worker 			    ("%d/%d: dwrite - ioctl(fd, XFS_IOC_DIOINFO) %s failed %d\n",
1926*49cdfc7eSAndroid Build Coastguard Worker 			     procid, opno, f.path, errno);
1927*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1928*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
1929*49cdfc7eSAndroid Build Coastguard Worker 		return;
1930*49cdfc7eSAndroid Build Coastguard Worker 	}
1931*49cdfc7eSAndroid Build Coastguard Worker #endif
1932*49cdfc7eSAndroid Build Coastguard Worker 	align = (int64_t) diob.d_miniosz;
1933*49cdfc7eSAndroid Build Coastguard Worker 	lr = ((int64_t) random() << 32) + random();
1934*49cdfc7eSAndroid Build Coastguard Worker 	off = (off64_t) (lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
1935*49cdfc7eSAndroid Build Coastguard Worker 	off -= (off % align);
1936*49cdfc7eSAndroid Build Coastguard Worker 	lseek64(fd, off, SEEK_SET);
1937*49cdfc7eSAndroid Build Coastguard Worker 	len = (random() % (getpagesize() * 32)) + 1;
1938*49cdfc7eSAndroid Build Coastguard Worker 	len -= (len % align);
1939*49cdfc7eSAndroid Build Coastguard Worker 	if (len <= 0)
1940*49cdfc7eSAndroid Build Coastguard Worker 		len = align;
1941*49cdfc7eSAndroid Build Coastguard Worker 	else if (len > diob.d_maxiosz)
1942*49cdfc7eSAndroid Build Coastguard Worker 		len = diob.d_maxiosz;
1943*49cdfc7eSAndroid Build Coastguard Worker 	if ((e = posix_memalign((void **)&buf, diob.d_mem, len)) != 0) {
1944*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr, "posix_memalign: %s\n", strerror(e));
1945*49cdfc7eSAndroid Build Coastguard Worker 		exit(1);
1946*49cdfc7eSAndroid Build Coastguard Worker 	}
1947*49cdfc7eSAndroid Build Coastguard Worker 	if (buf == NULL) {
1948*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(stderr, "posix_memalign: buf is NULL\n");
1949*49cdfc7eSAndroid Build Coastguard Worker 		exit(1);
1950*49cdfc7eSAndroid Build Coastguard Worker 	}
1951*49cdfc7eSAndroid Build Coastguard Worker 	off %= maxfsize;
1952*49cdfc7eSAndroid Build Coastguard Worker 	lseek64(fd, off, SEEK_SET);
1953*49cdfc7eSAndroid Build Coastguard Worker 	memset(buf, nameseq & 0xff, len);
1954*49cdfc7eSAndroid Build Coastguard Worker 	e = write(fd, buf, len) < 0 ? errno : 0;
1955*49cdfc7eSAndroid Build Coastguard Worker 	free(buf);
1956*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
1957*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: dwrite %s [%lld,%ld] %d\n",
1958*49cdfc7eSAndroid Build Coastguard Worker 		       procid, opno, f.path, (long long)off, (long int)len, e);
1959*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
1960*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
1961*49cdfc7eSAndroid Build Coastguard Worker }
1962*49cdfc7eSAndroid Build Coastguard Worker 
fdatasync_f(int opno,long r)1963*49cdfc7eSAndroid Build Coastguard Worker void fdatasync_f(int opno, long r)
1964*49cdfc7eSAndroid Build Coastguard Worker {
1965*49cdfc7eSAndroid Build Coastguard Worker 	int e;
1966*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
1967*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
1968*49cdfc7eSAndroid Build Coastguard Worker 	int v;
1969*49cdfc7eSAndroid Build Coastguard Worker 
1970*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
1971*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1972*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1973*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: fdatasync - no filename\n",
1974*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno);
1975*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1976*49cdfc7eSAndroid Build Coastguard Worker 		return;
1977*49cdfc7eSAndroid Build Coastguard Worker 	}
1978*49cdfc7eSAndroid Build Coastguard Worker 	fd = open_path(&f, O_WRONLY);
1979*49cdfc7eSAndroid Build Coastguard Worker 	e = fd < 0 ? errno : 0;
1980*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
1981*49cdfc7eSAndroid Build Coastguard Worker 	if (fd < 0) {
1982*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
1983*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: fdatasync - open %s failed %d\n",
1984*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, e);
1985*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
1986*49cdfc7eSAndroid Build Coastguard Worker 		return;
1987*49cdfc7eSAndroid Build Coastguard Worker 	}
1988*49cdfc7eSAndroid Build Coastguard Worker 	e = fdatasync(fd) < 0 ? errno : 0;
1989*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
1990*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: fdatasync %s %d\n", procid, opno, f.path, e);
1991*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
1992*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
1993*49cdfc7eSAndroid Build Coastguard Worker }
1994*49cdfc7eSAndroid Build Coastguard Worker 
1995*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
freesp_f(int opno,long r)1996*49cdfc7eSAndroid Build Coastguard Worker void freesp_f(int opno, long r)
1997*49cdfc7eSAndroid Build Coastguard Worker {
1998*49cdfc7eSAndroid Build Coastguard Worker 	int e;
1999*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2000*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
2001*49cdfc7eSAndroid Build Coastguard Worker 	struct xfs_flock64 fl;
2002*49cdfc7eSAndroid Build Coastguard Worker 	__s64 lr;
2003*49cdfc7eSAndroid Build Coastguard Worker 	__s64 off;
2004*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 stb;
2005*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2006*49cdfc7eSAndroid Build Coastguard Worker 
2007*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2008*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2009*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2010*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: freesp - no filename\n", procid, opno);
2011*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2012*49cdfc7eSAndroid Build Coastguard Worker 		return;
2013*49cdfc7eSAndroid Build Coastguard Worker 	}
2014*49cdfc7eSAndroid Build Coastguard Worker 	fd = open_path(&f, O_RDWR);
2015*49cdfc7eSAndroid Build Coastguard Worker 	e = fd < 0 ? errno : 0;
2016*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2017*49cdfc7eSAndroid Build Coastguard Worker 	if (fd < 0) {
2018*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2019*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: freesp - open %s failed %d\n",
2020*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, e);
2021*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2022*49cdfc7eSAndroid Build Coastguard Worker 		return;
2023*49cdfc7eSAndroid Build Coastguard Worker 	}
2024*49cdfc7eSAndroid Build Coastguard Worker 	if (fstat64(fd, &stb) < 0) {
2025*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2026*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: freesp - fstat64 %s failed %d\n",
2027*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, errno);
2028*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2029*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
2030*49cdfc7eSAndroid Build Coastguard Worker 		return;
2031*49cdfc7eSAndroid Build Coastguard Worker 	}
2032*49cdfc7eSAndroid Build Coastguard Worker 	lr = ((__s64) random() << 32) + random();
2033*49cdfc7eSAndroid Build Coastguard Worker 	off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
2034*49cdfc7eSAndroid Build Coastguard Worker 	off %= maxfsize;
2035*49cdfc7eSAndroid Build Coastguard Worker 	memset(&fl, 0, sizeof(fl));
2036*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_whence = SEEK_SET;
2037*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_start = off;
2038*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_len = 0;
2039*49cdfc7eSAndroid Build Coastguard Worker 	e = ioctl(fd, XFS_IOC_FREESP64, &fl) < 0 ? errno : 0;
2040*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2041*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: ioctl(XFS_IOC_FREESP64) %s %lld 0 %d\n",
2042*49cdfc7eSAndroid Build Coastguard Worker 		       procid, opno, f.path, (long long)off, e);
2043*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2044*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
2045*49cdfc7eSAndroid Build Coastguard Worker }
2046*49cdfc7eSAndroid Build Coastguard Worker 
2047*49cdfc7eSAndroid Build Coastguard Worker #endif
2048*49cdfc7eSAndroid Build Coastguard Worker 
fsync_f(int opno,long r)2049*49cdfc7eSAndroid Build Coastguard Worker void fsync_f(int opno, long r)
2050*49cdfc7eSAndroid Build Coastguard Worker {
2051*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2052*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2053*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
2054*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2055*49cdfc7eSAndroid Build Coastguard Worker 
2056*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2057*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2058*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2059*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: fsync - no filename\n", procid, opno);
2060*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2061*49cdfc7eSAndroid Build Coastguard Worker 		return;
2062*49cdfc7eSAndroid Build Coastguard Worker 	}
2063*49cdfc7eSAndroid Build Coastguard Worker 	fd = open_path(&f, O_WRONLY);
2064*49cdfc7eSAndroid Build Coastguard Worker 	e = fd < 0 ? errno : 0;
2065*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2066*49cdfc7eSAndroid Build Coastguard Worker 	if (fd < 0) {
2067*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2068*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: fsync - open %s failed %d\n",
2069*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, e);
2070*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2071*49cdfc7eSAndroid Build Coastguard Worker 		return;
2072*49cdfc7eSAndroid Build Coastguard Worker 	}
2073*49cdfc7eSAndroid Build Coastguard Worker 	e = fsync(fd) < 0 ? errno : 0;
2074*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2075*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: fsync %s %d\n", procid, opno, f.path, e);
2076*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2077*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
2078*49cdfc7eSAndroid Build Coastguard Worker }
2079*49cdfc7eSAndroid Build Coastguard Worker 
getdents_f(int opno,long r)2080*49cdfc7eSAndroid Build Coastguard Worker void getdents_f(int opno, long r)
2081*49cdfc7eSAndroid Build Coastguard Worker {
2082*49cdfc7eSAndroid Build Coastguard Worker 	DIR *dir;
2083*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2084*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2085*49cdfc7eSAndroid Build Coastguard Worker 
2086*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2087*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_DIRm, r, &f, NULL, NULL, &v))
2088*49cdfc7eSAndroid Build Coastguard Worker 		append_pathname(&f, ".");
2089*49cdfc7eSAndroid Build Coastguard Worker 	dir = opendir_path(&f);
2090*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2091*49cdfc7eSAndroid Build Coastguard Worker 	if (dir == NULL) {
2092*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2093*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: getdents - can't open %s\n",
2094*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path);
2095*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2096*49cdfc7eSAndroid Build Coastguard Worker 		return;
2097*49cdfc7eSAndroid Build Coastguard Worker 	}
2098*49cdfc7eSAndroid Build Coastguard Worker 	while (readdir64(dir) != NULL)
2099*49cdfc7eSAndroid Build Coastguard Worker 		continue;
2100*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2101*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: getdents %s 0\n", procid, opno, f.path);
2102*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2103*49cdfc7eSAndroid Build Coastguard Worker 	closedir(dir);
2104*49cdfc7eSAndroid Build Coastguard Worker }
2105*49cdfc7eSAndroid Build Coastguard Worker 
link_f(int opno,long r)2106*49cdfc7eSAndroid Build Coastguard Worker void link_f(int opno, long r)
2107*49cdfc7eSAndroid Build Coastguard Worker {
2108*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2109*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2110*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
2111*49cdfc7eSAndroid Build Coastguard Worker 	flist_t *flp;
2112*49cdfc7eSAndroid Build Coastguard Worker 	int id;
2113*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t l;
2114*49cdfc7eSAndroid Build Coastguard Worker 	int parid;
2115*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2116*49cdfc7eSAndroid Build Coastguard Worker 	int v1;
2117*49cdfc7eSAndroid Build Coastguard Worker 
2118*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2119*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_NOTDIR, r, &f, &flp, NULL, &v1)) {
2120*49cdfc7eSAndroid Build Coastguard Worker 		if (v1)
2121*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: link - no file\n", procid, opno);
2122*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2123*49cdfc7eSAndroid Build Coastguard Worker 		return;
2124*49cdfc7eSAndroid Build Coastguard Worker 	}
2125*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_DIRm, random(), NULL, NULL, &fep, &v))
2126*49cdfc7eSAndroid Build Coastguard Worker 		parid = -1;
2127*49cdfc7eSAndroid Build Coastguard Worker 	else
2128*49cdfc7eSAndroid Build Coastguard Worker 		parid = fep->id;
2129*49cdfc7eSAndroid Build Coastguard Worker 	v |= v1;
2130*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&l);
2131*49cdfc7eSAndroid Build Coastguard Worker 	e = generate_fname(fep, flp - flist, &l, &id, &v1);
2132*49cdfc7eSAndroid Build Coastguard Worker 	v |= v1;
2133*49cdfc7eSAndroid Build Coastguard Worker 	if (!e) {
2134*49cdfc7eSAndroid Build Coastguard Worker 		if (v) {
2135*49cdfc7eSAndroid Build Coastguard Worker 			fent_to_name(&l, &flist[FT_DIR], fep);
2136*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: link - no filename from %s\n",
2137*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, l.path);
2138*49cdfc7eSAndroid Build Coastguard Worker 		}
2139*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&l);
2140*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2141*49cdfc7eSAndroid Build Coastguard Worker 		return;
2142*49cdfc7eSAndroid Build Coastguard Worker 	}
2143*49cdfc7eSAndroid Build Coastguard Worker 	e = link_path(&f, &l) < 0 ? errno : 0;
2144*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2145*49cdfc7eSAndroid Build Coastguard Worker 	if (e == 0)
2146*49cdfc7eSAndroid Build Coastguard Worker 		add_to_flist(flp - flist, id, parid);
2147*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2148*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: link %s %s %d\n", procid, opno, f.path, l.path,
2149*49cdfc7eSAndroid Build Coastguard Worker 		       e);
2150*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&l);
2151*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2152*49cdfc7eSAndroid Build Coastguard Worker }
2153*49cdfc7eSAndroid Build Coastguard Worker 
mkdir_f(int opno,long r)2154*49cdfc7eSAndroid Build Coastguard Worker void mkdir_f(int opno, long r)
2155*49cdfc7eSAndroid Build Coastguard Worker {
2156*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2157*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2158*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
2159*49cdfc7eSAndroid Build Coastguard Worker 	int id;
2160*49cdfc7eSAndroid Build Coastguard Worker 	int parid;
2161*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2162*49cdfc7eSAndroid Build Coastguard Worker 	int v1;
2163*49cdfc7eSAndroid Build Coastguard Worker 
2164*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
2165*49cdfc7eSAndroid Build Coastguard Worker 		parid = -1;
2166*49cdfc7eSAndroid Build Coastguard Worker 	else
2167*49cdfc7eSAndroid Build Coastguard Worker 		parid = fep->id;
2168*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2169*49cdfc7eSAndroid Build Coastguard Worker 	e = generate_fname(fep, FT_DIR, &f, &id, &v1);
2170*49cdfc7eSAndroid Build Coastguard Worker 	v |= v1;
2171*49cdfc7eSAndroid Build Coastguard Worker 	if (!e) {
2172*49cdfc7eSAndroid Build Coastguard Worker 		if (v) {
2173*49cdfc7eSAndroid Build Coastguard Worker 			fent_to_name(&f, &flist[FT_DIR], fep);
2174*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: mkdir - no filename from %s\n",
2175*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path);
2176*49cdfc7eSAndroid Build Coastguard Worker 		}
2177*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2178*49cdfc7eSAndroid Build Coastguard Worker 		return;
2179*49cdfc7eSAndroid Build Coastguard Worker 	}
2180*49cdfc7eSAndroid Build Coastguard Worker 	e = mkdir_path(&f, 0777) < 0 ? errno : 0;
2181*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2182*49cdfc7eSAndroid Build Coastguard Worker 	if (e == 0)
2183*49cdfc7eSAndroid Build Coastguard Worker 		add_to_flist(FT_DIR, id, parid);
2184*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2185*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: mkdir %s %d\n", procid, opno, f.path, e);
2186*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2187*49cdfc7eSAndroid Build Coastguard Worker }
2188*49cdfc7eSAndroid Build Coastguard Worker 
mknod_f(int opno,long r)2189*49cdfc7eSAndroid Build Coastguard Worker void mknod_f(int opno, long r)
2190*49cdfc7eSAndroid Build Coastguard Worker {
2191*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2192*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2193*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
2194*49cdfc7eSAndroid Build Coastguard Worker 	int id;
2195*49cdfc7eSAndroid Build Coastguard Worker 	int parid;
2196*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2197*49cdfc7eSAndroid Build Coastguard Worker 	int v1;
2198*49cdfc7eSAndroid Build Coastguard Worker 
2199*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
2200*49cdfc7eSAndroid Build Coastguard Worker 		parid = -1;
2201*49cdfc7eSAndroid Build Coastguard Worker 	else
2202*49cdfc7eSAndroid Build Coastguard Worker 		parid = fep->id;
2203*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2204*49cdfc7eSAndroid Build Coastguard Worker 	e = generate_fname(fep, FT_DEV, &f, &id, &v1);
2205*49cdfc7eSAndroid Build Coastguard Worker 	v |= v1;
2206*49cdfc7eSAndroid Build Coastguard Worker 	if (!e) {
2207*49cdfc7eSAndroid Build Coastguard Worker 		if (v) {
2208*49cdfc7eSAndroid Build Coastguard Worker 			fent_to_name(&f, &flist[FT_DIR], fep);
2209*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: mknod - no filename from %s\n",
2210*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path);
2211*49cdfc7eSAndroid Build Coastguard Worker 		}
2212*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2213*49cdfc7eSAndroid Build Coastguard Worker 		return;
2214*49cdfc7eSAndroid Build Coastguard Worker 	}
2215*49cdfc7eSAndroid Build Coastguard Worker 	e = mknod_path(&f, S_IFCHR | 0444, 0) < 0 ? errno : 0;
2216*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2217*49cdfc7eSAndroid Build Coastguard Worker 	if (e == 0)
2218*49cdfc7eSAndroid Build Coastguard Worker 		add_to_flist(FT_DEV, id, parid);
2219*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2220*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: mknod %s %d\n", procid, opno, f.path, e);
2221*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2222*49cdfc7eSAndroid Build Coastguard Worker }
2223*49cdfc7eSAndroid Build Coastguard Worker 
read_f(int opno,long r)2224*49cdfc7eSAndroid Build Coastguard Worker void read_f(int opno, long r)
2225*49cdfc7eSAndroid Build Coastguard Worker {
2226*49cdfc7eSAndroid Build Coastguard Worker 	char *buf;
2227*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2228*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2229*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
2230*49cdfc7eSAndroid Build Coastguard Worker 	size_t len;
2231*49cdfc7eSAndroid Build Coastguard Worker 	int64_t lr;
2232*49cdfc7eSAndroid Build Coastguard Worker 	off64_t off;
2233*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 stb;
2234*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2235*49cdfc7eSAndroid Build Coastguard Worker 
2236*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2237*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2238*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2239*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: read - no filename\n", procid, opno);
2240*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2241*49cdfc7eSAndroid Build Coastguard Worker 		return;
2242*49cdfc7eSAndroid Build Coastguard Worker 	}
2243*49cdfc7eSAndroid Build Coastguard Worker 	fd = open_path(&f, O_RDONLY);
2244*49cdfc7eSAndroid Build Coastguard Worker 	e = fd < 0 ? errno : 0;
2245*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2246*49cdfc7eSAndroid Build Coastguard Worker 	if (fd < 0) {
2247*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2248*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: read - open %s failed %d\n",
2249*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, e);
2250*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2251*49cdfc7eSAndroid Build Coastguard Worker 		return;
2252*49cdfc7eSAndroid Build Coastguard Worker 	}
2253*49cdfc7eSAndroid Build Coastguard Worker 	if (fstat64(fd, &stb) < 0) {
2254*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2255*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: read - fstat64 %s failed %d\n",
2256*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, errno);
2257*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2258*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
2259*49cdfc7eSAndroid Build Coastguard Worker 		return;
2260*49cdfc7eSAndroid Build Coastguard Worker 	}
2261*49cdfc7eSAndroid Build Coastguard Worker 	if (stb.st_size == 0) {
2262*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2263*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: read - %s zero size\n", procid, opno,
2264*49cdfc7eSAndroid Build Coastguard Worker 			       f.path);
2265*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2266*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
2267*49cdfc7eSAndroid Build Coastguard Worker 		return;
2268*49cdfc7eSAndroid Build Coastguard Worker 	}
2269*49cdfc7eSAndroid Build Coastguard Worker 	lr = ((int64_t) random() << 32) + random();
2270*49cdfc7eSAndroid Build Coastguard Worker 	off = (off64_t) (lr % stb.st_size);
2271*49cdfc7eSAndroid Build Coastguard Worker 	lseek64(fd, off, SEEK_SET);
2272*49cdfc7eSAndroid Build Coastguard Worker 	len = (random() % (getpagesize() * 32)) + 1;
2273*49cdfc7eSAndroid Build Coastguard Worker 	buf = malloc(len);
2274*49cdfc7eSAndroid Build Coastguard Worker 	e = read(fd, buf, len) < 0 ? errno : 0;
2275*49cdfc7eSAndroid Build Coastguard Worker 	free(buf);
2276*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2277*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: read %s [%lld,%ld] %d\n",
2278*49cdfc7eSAndroid Build Coastguard Worker 		       procid, opno, f.path, (long long)off, (long int)len, e);
2279*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2280*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
2281*49cdfc7eSAndroid Build Coastguard Worker }
2282*49cdfc7eSAndroid Build Coastguard Worker 
readlink_f(int opno,long r)2283*49cdfc7eSAndroid Build Coastguard Worker void readlink_f(int opno, long r)
2284*49cdfc7eSAndroid Build Coastguard Worker {
2285*49cdfc7eSAndroid Build Coastguard Worker 	char buf[PATH_MAX];
2286*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2287*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2288*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2289*49cdfc7eSAndroid Build Coastguard Worker 
2290*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2291*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_SYMm, r, &f, NULL, NULL, &v)) {
2292*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2293*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: readlink - no filename\n", procid, opno);
2294*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2295*49cdfc7eSAndroid Build Coastguard Worker 		return;
2296*49cdfc7eSAndroid Build Coastguard Worker 	}
2297*49cdfc7eSAndroid Build Coastguard Worker 	e = readlink_path(&f, buf, PATH_MAX) < 0 ? errno : 0;
2298*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2299*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2300*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: readlink %s %d\n", procid, opno, f.path, e);
2301*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2302*49cdfc7eSAndroid Build Coastguard Worker }
2303*49cdfc7eSAndroid Build Coastguard Worker 
rename_f(int opno,long r)2304*49cdfc7eSAndroid Build Coastguard Worker void rename_f(int opno, long r)
2305*49cdfc7eSAndroid Build Coastguard Worker {
2306*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *dfep;
2307*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2308*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2309*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
2310*49cdfc7eSAndroid Build Coastguard Worker 	flist_t *flp;
2311*49cdfc7eSAndroid Build Coastguard Worker 	int id;
2312*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t newf;
2313*49cdfc7eSAndroid Build Coastguard Worker 	int oldid;
2314*49cdfc7eSAndroid Build Coastguard Worker 	int parid;
2315*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2316*49cdfc7eSAndroid Build Coastguard Worker 	int v1;
2317*49cdfc7eSAndroid Build Coastguard Worker 
2318*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2319*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_ANYm, r, &f, &flp, &fep, &v1)) {
2320*49cdfc7eSAndroid Build Coastguard Worker 		if (v1)
2321*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: rename - no filename\n", procid, opno);
2322*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2323*49cdfc7eSAndroid Build Coastguard Worker 		return;
2324*49cdfc7eSAndroid Build Coastguard Worker 	}
2325*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_DIRm, random(), NULL, NULL, &dfep, &v))
2326*49cdfc7eSAndroid Build Coastguard Worker 		parid = -1;
2327*49cdfc7eSAndroid Build Coastguard Worker 	else
2328*49cdfc7eSAndroid Build Coastguard Worker 		parid = dfep->id;
2329*49cdfc7eSAndroid Build Coastguard Worker 	v |= v1;
2330*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&newf);
2331*49cdfc7eSAndroid Build Coastguard Worker 	e = generate_fname(dfep, flp - flist, &newf, &id, &v1);
2332*49cdfc7eSAndroid Build Coastguard Worker 	v |= v1;
2333*49cdfc7eSAndroid Build Coastguard Worker 	if (!e) {
2334*49cdfc7eSAndroid Build Coastguard Worker 		if (v) {
2335*49cdfc7eSAndroid Build Coastguard Worker 			fent_to_name(&f, &flist[FT_DIR], dfep);
2336*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: rename - no filename from %s\n",
2337*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path);
2338*49cdfc7eSAndroid Build Coastguard Worker 		}
2339*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&newf);
2340*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2341*49cdfc7eSAndroid Build Coastguard Worker 		return;
2342*49cdfc7eSAndroid Build Coastguard Worker 	}
2343*49cdfc7eSAndroid Build Coastguard Worker 	e = rename_path(&f, &newf) < 0 ? errno : 0;
2344*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2345*49cdfc7eSAndroid Build Coastguard Worker 	if (e == 0) {
2346*49cdfc7eSAndroid Build Coastguard Worker 		if (flp - flist == FT_DIR) {
2347*49cdfc7eSAndroid Build Coastguard Worker 			oldid = fep->id;
2348*49cdfc7eSAndroid Build Coastguard Worker 			fix_parent(oldid, id);
2349*49cdfc7eSAndroid Build Coastguard Worker 		}
2350*49cdfc7eSAndroid Build Coastguard Worker 		del_from_flist(flp - flist, fep - flp->fents);
2351*49cdfc7eSAndroid Build Coastguard Worker 		add_to_flist(flp - flist, id, parid);
2352*49cdfc7eSAndroid Build Coastguard Worker 	}
2353*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2354*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: rename %s to %s %d\n", procid, opno, f.path,
2355*49cdfc7eSAndroid Build Coastguard Worker 		       newf.path, e);
2356*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&newf);
2357*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2358*49cdfc7eSAndroid Build Coastguard Worker }
2359*49cdfc7eSAndroid Build Coastguard Worker 
2360*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
resvsp_f(int opno,long r)2361*49cdfc7eSAndroid Build Coastguard Worker void resvsp_f(int opno, long r)
2362*49cdfc7eSAndroid Build Coastguard Worker {
2363*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2364*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2365*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
2366*49cdfc7eSAndroid Build Coastguard Worker 	struct xfs_flock64 fl;
2367*49cdfc7eSAndroid Build Coastguard Worker 	__s64 lr;
2368*49cdfc7eSAndroid Build Coastguard Worker 	__s64 off;
2369*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 stb;
2370*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2371*49cdfc7eSAndroid Build Coastguard Worker 
2372*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2373*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2374*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2375*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: resvsp - no filename\n", procid, opno);
2376*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2377*49cdfc7eSAndroid Build Coastguard Worker 		return;
2378*49cdfc7eSAndroid Build Coastguard Worker 	}
2379*49cdfc7eSAndroid Build Coastguard Worker 	fd = open_path(&f, O_RDWR);
2380*49cdfc7eSAndroid Build Coastguard Worker 	e = fd < 0 ? errno : 0;
2381*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2382*49cdfc7eSAndroid Build Coastguard Worker 	if (fd < 0) {
2383*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2384*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: resvsp - open %s failed %d\n",
2385*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, e);
2386*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2387*49cdfc7eSAndroid Build Coastguard Worker 		return;
2388*49cdfc7eSAndroid Build Coastguard Worker 	}
2389*49cdfc7eSAndroid Build Coastguard Worker 	if (fstat64(fd, &stb) < 0) {
2390*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2391*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: resvsp - fstat64 %s failed %d\n",
2392*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, errno);
2393*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2394*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
2395*49cdfc7eSAndroid Build Coastguard Worker 		return;
2396*49cdfc7eSAndroid Build Coastguard Worker 	}
2397*49cdfc7eSAndroid Build Coastguard Worker 	lr = ((__s64) random() << 32) + random();
2398*49cdfc7eSAndroid Build Coastguard Worker 	off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
2399*49cdfc7eSAndroid Build Coastguard Worker 	off %= maxfsize;
2400*49cdfc7eSAndroid Build Coastguard Worker 	memset(&fl, 0, sizeof(fl));
2401*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_whence = SEEK_SET;
2402*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_start = off;
2403*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_len = (__s64) (random() % (1024 * 1024));
2404*49cdfc7eSAndroid Build Coastguard Worker 	e = ioctl(fd, XFS_IOC_RESVSP64, &fl) < 0 ? errno : 0;
2405*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2406*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: ioctl(XFS_IOC_RESVSP64) %s %lld %lld %d\n",
2407*49cdfc7eSAndroid Build Coastguard Worker 		       procid, opno, f.path, (long long)off,
2408*49cdfc7eSAndroid Build Coastguard Worker 		       (long long)fl.l_len, e);
2409*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2410*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
2411*49cdfc7eSAndroid Build Coastguard Worker }
2412*49cdfc7eSAndroid Build Coastguard Worker #endif
2413*49cdfc7eSAndroid Build Coastguard Worker 
rmdir_f(int opno,long r)2414*49cdfc7eSAndroid Build Coastguard Worker void rmdir_f(int opno, long r)
2415*49cdfc7eSAndroid Build Coastguard Worker {
2416*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2417*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2418*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
2419*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2420*49cdfc7eSAndroid Build Coastguard Worker 
2421*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2422*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_DIRm, r, &f, NULL, &fep, &v)) {
2423*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2424*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: rmdir - no directory\n", procid, opno);
2425*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2426*49cdfc7eSAndroid Build Coastguard Worker 		return;
2427*49cdfc7eSAndroid Build Coastguard Worker 	}
2428*49cdfc7eSAndroid Build Coastguard Worker 	e = rmdir_path(&f) < 0 ? errno : 0;
2429*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2430*49cdfc7eSAndroid Build Coastguard Worker 	if (e == 0)
2431*49cdfc7eSAndroid Build Coastguard Worker 		del_from_flist(FT_DIR, fep - flist[FT_DIR].fents);
2432*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2433*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: rmdir %s %d\n", procid, opno, f.path, e);
2434*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2435*49cdfc7eSAndroid Build Coastguard Worker }
2436*49cdfc7eSAndroid Build Coastguard Worker 
stat_f(int opno,long r)2437*49cdfc7eSAndroid Build Coastguard Worker void stat_f(int opno, long r)
2438*49cdfc7eSAndroid Build Coastguard Worker {
2439*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2440*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2441*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 stb;
2442*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2443*49cdfc7eSAndroid Build Coastguard Worker 
2444*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2445*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v)) {
2446*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2447*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: stat - no entries\n", procid, opno);
2448*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2449*49cdfc7eSAndroid Build Coastguard Worker 		return;
2450*49cdfc7eSAndroid Build Coastguard Worker 	}
2451*49cdfc7eSAndroid Build Coastguard Worker 	e = lstat64_path(&f, &stb) < 0 ? errno : 0;
2452*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2453*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2454*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: stat %s %d\n", procid, opno, f.path, e);
2455*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2456*49cdfc7eSAndroid Build Coastguard Worker }
2457*49cdfc7eSAndroid Build Coastguard Worker 
symlink_f(int opno,long r)2458*49cdfc7eSAndroid Build Coastguard Worker void symlink_f(int opno, long r)
2459*49cdfc7eSAndroid Build Coastguard Worker {
2460*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2461*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2462*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
2463*49cdfc7eSAndroid Build Coastguard Worker 	int i;
2464*49cdfc7eSAndroid Build Coastguard Worker 	int id;
2465*49cdfc7eSAndroid Build Coastguard Worker 	int len;
2466*49cdfc7eSAndroid Build Coastguard Worker 	int parid;
2467*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2468*49cdfc7eSAndroid Build Coastguard Worker 	int v1;
2469*49cdfc7eSAndroid Build Coastguard Worker 	char *val;
2470*49cdfc7eSAndroid Build Coastguard Worker 
2471*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
2472*49cdfc7eSAndroid Build Coastguard Worker 		parid = -1;
2473*49cdfc7eSAndroid Build Coastguard Worker 	else
2474*49cdfc7eSAndroid Build Coastguard Worker 		parid = fep->id;
2475*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2476*49cdfc7eSAndroid Build Coastguard Worker 	e = generate_fname(fep, FT_SYM, &f, &id, &v1);
2477*49cdfc7eSAndroid Build Coastguard Worker 	v |= v1;
2478*49cdfc7eSAndroid Build Coastguard Worker 	if (!e) {
2479*49cdfc7eSAndroid Build Coastguard Worker 		if (v) {
2480*49cdfc7eSAndroid Build Coastguard Worker 			fent_to_name(&f, &flist[FT_DIR], fep);
2481*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: symlink - no filename from %s\n",
2482*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path);
2483*49cdfc7eSAndroid Build Coastguard Worker 		}
2484*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2485*49cdfc7eSAndroid Build Coastguard Worker 		return;
2486*49cdfc7eSAndroid Build Coastguard Worker 	}
2487*49cdfc7eSAndroid Build Coastguard Worker 	len = (int)(random() % PATH_MAX);
2488*49cdfc7eSAndroid Build Coastguard Worker 	val = malloc(len + 1);
2489*49cdfc7eSAndroid Build Coastguard Worker 	if (len)
2490*49cdfc7eSAndroid Build Coastguard Worker 		memset(val, 'x', len);
2491*49cdfc7eSAndroid Build Coastguard Worker 	val[len] = '\0';
2492*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 10; i < len - 1; i += 10)
2493*49cdfc7eSAndroid Build Coastguard Worker 		val[i] = '/';
2494*49cdfc7eSAndroid Build Coastguard Worker 	e = symlink_path(val, &f) < 0 ? errno : 0;
2495*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2496*49cdfc7eSAndroid Build Coastguard Worker 	if (e == 0)
2497*49cdfc7eSAndroid Build Coastguard Worker 		add_to_flist(FT_SYM, id, parid);
2498*49cdfc7eSAndroid Build Coastguard Worker 	free(val);
2499*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2500*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: symlink %s %d\n", procid, opno, f.path, e);
2501*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2502*49cdfc7eSAndroid Build Coastguard Worker }
2503*49cdfc7eSAndroid Build Coastguard Worker 
2504*49cdfc7eSAndroid Build Coastguard Worker /* ARGSUSED */
sync_f(int opno,long r)2505*49cdfc7eSAndroid Build Coastguard Worker void sync_f(int opno, long r __attribute__((unused)))
2506*49cdfc7eSAndroid Build Coastguard Worker {
2507*49cdfc7eSAndroid Build Coastguard Worker 	sync();
2508*49cdfc7eSAndroid Build Coastguard Worker 	if (verbose)
2509*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: sync\n", procid, opno);
2510*49cdfc7eSAndroid Build Coastguard Worker }
2511*49cdfc7eSAndroid Build Coastguard Worker 
truncate_f(int opno,long r)2512*49cdfc7eSAndroid Build Coastguard Worker void truncate_f(int opno, long r)
2513*49cdfc7eSAndroid Build Coastguard Worker {
2514*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2515*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2516*49cdfc7eSAndroid Build Coastguard Worker 	int64_t lr;
2517*49cdfc7eSAndroid Build Coastguard Worker 	off64_t off;
2518*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 stb;
2519*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2520*49cdfc7eSAndroid Build Coastguard Worker 
2521*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2522*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2523*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2524*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: truncate - no filename\n", procid, opno);
2525*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2526*49cdfc7eSAndroid Build Coastguard Worker 		return;
2527*49cdfc7eSAndroid Build Coastguard Worker 	}
2528*49cdfc7eSAndroid Build Coastguard Worker 	e = stat64_path(&f, &stb) < 0 ? errno : 0;
2529*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2530*49cdfc7eSAndroid Build Coastguard Worker 	if (e > 0) {
2531*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2532*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: truncate - stat64 %s failed %d\n",
2533*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, e);
2534*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2535*49cdfc7eSAndroid Build Coastguard Worker 		return;
2536*49cdfc7eSAndroid Build Coastguard Worker 	}
2537*49cdfc7eSAndroid Build Coastguard Worker 	lr = ((int64_t) random() << 32) + random();
2538*49cdfc7eSAndroid Build Coastguard Worker 	off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
2539*49cdfc7eSAndroid Build Coastguard Worker 	off %= maxfsize;
2540*49cdfc7eSAndroid Build Coastguard Worker 	e = truncate64_path(&f, off) < 0 ? errno : 0;
2541*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2542*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2543*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: truncate %s %lld %d\n", procid, opno, f.path,
2544*49cdfc7eSAndroid Build Coastguard Worker 		       (long long)off, e);
2545*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2546*49cdfc7eSAndroid Build Coastguard Worker }
2547*49cdfc7eSAndroid Build Coastguard Worker 
unlink_f(int opno,long r)2548*49cdfc7eSAndroid Build Coastguard Worker void unlink_f(int opno, long r)
2549*49cdfc7eSAndroid Build Coastguard Worker {
2550*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2551*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2552*49cdfc7eSAndroid Build Coastguard Worker 	fent_t *fep;
2553*49cdfc7eSAndroid Build Coastguard Worker 	flist_t *flp;
2554*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2555*49cdfc7eSAndroid Build Coastguard Worker 
2556*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2557*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_NOTDIR, r, &f, &flp, &fep, &v)) {
2558*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2559*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: unlink - no file\n", procid, opno);
2560*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2561*49cdfc7eSAndroid Build Coastguard Worker 		return;
2562*49cdfc7eSAndroid Build Coastguard Worker 	}
2563*49cdfc7eSAndroid Build Coastguard Worker 	e = unlink_path(&f) < 0 ? errno : 0;
2564*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2565*49cdfc7eSAndroid Build Coastguard Worker 	if (e == 0)
2566*49cdfc7eSAndroid Build Coastguard Worker 		del_from_flist(flp - flist, fep - flp->fents);
2567*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2568*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: unlink %s %d\n", procid, opno, f.path, e);
2569*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2570*49cdfc7eSAndroid Build Coastguard Worker }
2571*49cdfc7eSAndroid Build Coastguard Worker 
2572*49cdfc7eSAndroid Build Coastguard Worker #ifndef NO_XFS
unresvsp_f(int opno,long r)2573*49cdfc7eSAndroid Build Coastguard Worker void unresvsp_f(int opno, long r)
2574*49cdfc7eSAndroid Build Coastguard Worker {
2575*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2576*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2577*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
2578*49cdfc7eSAndroid Build Coastguard Worker 	struct xfs_flock64 fl;
2579*49cdfc7eSAndroid Build Coastguard Worker 	__s64 lr;
2580*49cdfc7eSAndroid Build Coastguard Worker 	__s64 off;
2581*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 stb;
2582*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2583*49cdfc7eSAndroid Build Coastguard Worker 
2584*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2585*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2586*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2587*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: unresvsp - no filename\n", procid, opno);
2588*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2589*49cdfc7eSAndroid Build Coastguard Worker 		return;
2590*49cdfc7eSAndroid Build Coastguard Worker 	}
2591*49cdfc7eSAndroid Build Coastguard Worker 	fd = open_path(&f, O_RDWR);
2592*49cdfc7eSAndroid Build Coastguard Worker 	e = fd < 0 ? errno : 0;
2593*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2594*49cdfc7eSAndroid Build Coastguard Worker 	if (fd < 0) {
2595*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2596*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: unresvsp - open %s failed %d\n",
2597*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, e);
2598*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2599*49cdfc7eSAndroid Build Coastguard Worker 		return;
2600*49cdfc7eSAndroid Build Coastguard Worker 	}
2601*49cdfc7eSAndroid Build Coastguard Worker 	if (fstat64(fd, &stb) < 0) {
2602*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2603*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: unresvsp - fstat64 %s failed %d\n",
2604*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, errno);
2605*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2606*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
2607*49cdfc7eSAndroid Build Coastguard Worker 		return;
2608*49cdfc7eSAndroid Build Coastguard Worker 	}
2609*49cdfc7eSAndroid Build Coastguard Worker 	lr = ((__s64) random() << 32) + random();
2610*49cdfc7eSAndroid Build Coastguard Worker 	off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
2611*49cdfc7eSAndroid Build Coastguard Worker 	off %= maxfsize;
2612*49cdfc7eSAndroid Build Coastguard Worker 	memset(&fl, 0, sizeof(fl));
2613*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_whence = SEEK_SET;
2614*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_start = off;
2615*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_len = (__s64) (random() % (1 << 20));
2616*49cdfc7eSAndroid Build Coastguard Worker 	e = ioctl(fd, XFS_IOC_UNRESVSP64, &fl) < 0 ? errno : 0;
2617*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2618*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: ioctl(XFS_IOC_UNRESVSP64) %s %lld %lld %d\n",
2619*49cdfc7eSAndroid Build Coastguard Worker 		       procid, opno, f.path, (long long)off,
2620*49cdfc7eSAndroid Build Coastguard Worker 		       (long long)fl.l_len, e);
2621*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2622*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
2623*49cdfc7eSAndroid Build Coastguard Worker }
2624*49cdfc7eSAndroid Build Coastguard Worker #endif
2625*49cdfc7eSAndroid Build Coastguard Worker 
write_f(int opno,long r)2626*49cdfc7eSAndroid Build Coastguard Worker void write_f(int opno, long r)
2627*49cdfc7eSAndroid Build Coastguard Worker {
2628*49cdfc7eSAndroid Build Coastguard Worker 	char *buf;
2629*49cdfc7eSAndroid Build Coastguard Worker 	int e;
2630*49cdfc7eSAndroid Build Coastguard Worker 	pathname_t f;
2631*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
2632*49cdfc7eSAndroid Build Coastguard Worker 	size_t len;
2633*49cdfc7eSAndroid Build Coastguard Worker 	int64_t lr;
2634*49cdfc7eSAndroid Build Coastguard Worker 	off64_t off;
2635*49cdfc7eSAndroid Build Coastguard Worker 	struct stat64 stb;
2636*49cdfc7eSAndroid Build Coastguard Worker 	int v;
2637*49cdfc7eSAndroid Build Coastguard Worker 
2638*49cdfc7eSAndroid Build Coastguard Worker 	init_pathname(&f);
2639*49cdfc7eSAndroid Build Coastguard Worker 	if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
2640*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2641*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: write - no filename\n", procid, opno);
2642*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2643*49cdfc7eSAndroid Build Coastguard Worker 		return;
2644*49cdfc7eSAndroid Build Coastguard Worker 	}
2645*49cdfc7eSAndroid Build Coastguard Worker 	fd = open_path(&f, O_WRONLY);
2646*49cdfc7eSAndroid Build Coastguard Worker 	e = fd < 0 ? errno : 0;
2647*49cdfc7eSAndroid Build Coastguard Worker 	check_cwd();
2648*49cdfc7eSAndroid Build Coastguard Worker 	if (fd < 0) {
2649*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2650*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: write - open %s failed %d\n",
2651*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, e);
2652*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2653*49cdfc7eSAndroid Build Coastguard Worker 		return;
2654*49cdfc7eSAndroid Build Coastguard Worker 	}
2655*49cdfc7eSAndroid Build Coastguard Worker 	if (fstat64(fd, &stb) < 0) {
2656*49cdfc7eSAndroid Build Coastguard Worker 		if (v)
2657*49cdfc7eSAndroid Build Coastguard Worker 			printf("%d/%d: write - fstat64 %s failed %d\n",
2658*49cdfc7eSAndroid Build Coastguard Worker 			       procid, opno, f.path, errno);
2659*49cdfc7eSAndroid Build Coastguard Worker 		free_pathname(&f);
2660*49cdfc7eSAndroid Build Coastguard Worker 		close(fd);
2661*49cdfc7eSAndroid Build Coastguard Worker 		return;
2662*49cdfc7eSAndroid Build Coastguard Worker 	}
2663*49cdfc7eSAndroid Build Coastguard Worker 	lr = ((int64_t) random() << 32) + random();
2664*49cdfc7eSAndroid Build Coastguard Worker 	off = (off64_t) (lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
2665*49cdfc7eSAndroid Build Coastguard Worker 	off %= maxfsize;
2666*49cdfc7eSAndroid Build Coastguard Worker 	lseek64(fd, off, SEEK_SET);
2667*49cdfc7eSAndroid Build Coastguard Worker 	len = (random() % (getpagesize() * 32)) + 1;
2668*49cdfc7eSAndroid Build Coastguard Worker 	buf = malloc(len);
2669*49cdfc7eSAndroid Build Coastguard Worker 	memset(buf, nameseq & 0xff, len);
2670*49cdfc7eSAndroid Build Coastguard Worker 	e = write(fd, buf, len) < 0 ? errno : 0;
2671*49cdfc7eSAndroid Build Coastguard Worker 	free(buf);
2672*49cdfc7eSAndroid Build Coastguard Worker 	if (v)
2673*49cdfc7eSAndroid Build Coastguard Worker 		printf("%d/%d: write %s [%lld,%ld] %d\n",
2674*49cdfc7eSAndroid Build Coastguard Worker 		       procid, opno, f.path, (long long)off, (long int)len, e);
2675*49cdfc7eSAndroid Build Coastguard Worker 	free_pathname(&f);
2676*49cdfc7eSAndroid Build Coastguard Worker 	close(fd);
2677*49cdfc7eSAndroid Build Coastguard Worker }
2678