ftest03.c revision bdbaec51a423e715c2b03ed9e497e9a1fba6103e
124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew/*
224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *
324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *   Copyright (c) International Business Machines  Corp., 2002
424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *
524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *   This program is free software;  you can redistribute it and/or modify
624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *   it under the terms of the GNU General Public License as published by
724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *   the Free Software Foundation; either version 2 of the License, or
824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *   (at your option) any later version.
924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *
1024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *   This program is distributed in the hope that it will be useful,
1124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
1224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
1324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *   the GNU General Public License for more details.
1424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *
1524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *   You should have received a copy of the GNU General Public License
1624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *   along with this program;  if not, write to the Free Software
1724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew */
1924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
2024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew/*
2124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew * NAME
2224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	ftest03.c -- test file I/O with readv and writev (ported from SPIE section2/filesuite/ftest4.c, by Airong Zhang)
2324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *
2424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew * CALLS
2524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	lseek, readv, writev,
2624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	truncate, ftruncate, fsync, sync, fstat
2724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *
2824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew * ALGORITHM
2924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	A bitmap is used to map pieces of a file.
3024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *      Loop: pick a random piece of the file
3124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *            if we haven't seen it before make sure it is zero,
3224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *            write pattern
3324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *            if we have seen it before make sure correct pattern.
3424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *
3524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *      This was originally written by rbk - was program tfio.c
3624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	Modified by dale to integrate with test suites.
3724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	Modified by G. Stevens to use readv and writev.
3824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	Modofied by K. Hakim to integrate with SPIES.
3924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *
4024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew * RESTRICTIONS
4124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *  1.  Runs a long time with default args - can take others on input
4224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	line.  Use with "term mode".
4324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	If run on vax the ftruncate will not be random - will always go to
4424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	start of file.  NOTE: produces a very high load average!!
4524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *
4624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *  2.  The "csize" argument must be evenly divisible by MAXIOVCNT.
4724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *
4824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew * CAUTION!!
4924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	If a file is supplied to this program with the "-f" option
5024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	it will be removed with a system("rm -rf filename") call.
51bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak *
5224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew */
5324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
5424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#define _XOPEN_SOURCE 500
5524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#include <sys/types.h>
5624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#include <sys/param.h>
5724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#include <sys/wait.h>
5824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#include <sys/stat.h>
59f81795e0876f9dd0d95b42aec99a9a5de04d883dvapier#include <errno.h>
6024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#include <sys/uio.h>
6124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#include <fcntl.h>
6224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#include <signal.h>		/* DEM - added SIGTERM support */
6324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#include <stdio.h>		/* needed by testhead.h		*/
6424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#include "test.h"
6524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#include "usctest.h"
6624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
6724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewchar *TCID = "ftest03";
6824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint TST_TOTAL = 1;
6924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewextern int Tst_count;
7024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
7124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#define PASSED 1
7224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#define FAILED 0
7324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
7424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewvoid setup();
7524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint runtest();
7624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint dotest(int, int, int);
7724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint domisc(int, int, char*);
7824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint bfill(char*, char, int);
7924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint dumpiov(struct iovec*);
8024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint dumpbits(char*, int);
8124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint orbits(char*, char*, int);
8224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint term();
8324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
8424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#define MAXCHILD	25	/* max number of children to allow */
8524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#define K_1		1024
8624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#define K_2		2048
8724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#define K_4		4096
8824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#define	MAXIOVCNT	16
8924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
9024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
9124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	csize;				/* chunk size */
9224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	iterations;			/* # total iterations */
9324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	max_size;			/* max file size */
9424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	misc_intvl;			/* for doing misc things; 0 ==> no */
9524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	nchild;				/* how many children */
9624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	nwait;
9724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	fd;				/* file descriptor used by child */
9824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	parent_pid;
9924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	pidlist[MAXCHILD];
10024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewchar	test_name[2];			/* childs test directory name */
10124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewchar	*prog, *getcwd() ;
10224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
10324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewchar	fuss[40] = "";		/* directory to do this in */
10424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewchar	homedir[200]= "";	/* where we started */
10524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
10624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint 	local_flag;
10724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew/*--------------------------------------------------------------*/
10824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint main (ac, av)
10924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int  ac;
11024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	char *av[];
11124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew{
11224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew        int lc;                 /* loop counter */
11324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew        char *msg;              /* message returned from parse_opts */
11424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
11524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew        /*
11624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew         * parse standard options
11724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew         */
11824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew        if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
11924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	                tst_resm(TBROK, "OPTION PARSING ERROR - %s", msg);
12024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tst_exit();
12124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew                        /*NOTREACHED*/
12224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew        }
12324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
12424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	setup();
125bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak
12624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	for (lc = 0; TEST_LOOPING(lc); lc++) {
12724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
12824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		local_flag = PASSED;
12924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
13024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 	runtest();
13124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
13224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if (local_flag == PASSED) {
133af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier                        tst_resm(TPASS, "Test passed.");
13424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew                } else {
135af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier                        tst_resm(TFAIL, "Test failed.");
13624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew                }
137bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak
13824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		tst_rmdir();
13924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		tst_exit();
14024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	} /* end for */
14143337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak	return 0;
14224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew}
14324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew/*--------------------------------------------------------------*/
14424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
14524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewvoid
14624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewsetup()
14724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew{
14824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	char wdbuf[MAXPATHLEN],  *cwd ;
14924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int term();
15024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
15124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	/*
15224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 * Make a directory to do this in; ignore error if already exists.
15324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 * Save starting directory.
15424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 */
15524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	tst_tmpdir();
15624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if ( (cwd = getcwd(homedir, sizeof( homedir))) == NULL ) {
157af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier	  tst_resm(TBROK, "pwd") ;
15824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	  tst_exit() ;
15924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
16024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
16124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	parent_pid = getpid();
16224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
16324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if (!fuss[0])
16424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		sprintf(fuss, "%s/ftest03.%d", getcwd(wdbuf, sizeof( wdbuf)), getpid());
16524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
16624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	mkdir(fuss, 0755);
16724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
16824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if (chdir(fuss) < 0) {
169af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		tst_resm(TBROK,"\tCan't chdir(%s), error %d.", fuss, errno);
17024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		tst_exit() ;
17124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
17224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
173bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak
17424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	/*
17524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 * Default values for run conditions.
17624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 */
17724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
17824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	iterations = 10;
17924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	nchild = 5;
18024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	csize = K_2;		/* should run with 1, 2, and 4 K sizes */
18124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	max_size = K_1 * K_1;
18224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	misc_intvl = 10;
18324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
18424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if (sigset(SIGTERM, (void (*)())term) == SIG_ERR) {
18524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		perror("sigset failed");
186af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		tst_resm(TBROK, " sigset failed: signo = 15") ;
18724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		tst_exit() ;
18824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
18924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
19024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew}
19124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
19224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
19324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint runtest()
19424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew{
19524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register int i;
19624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	pid;
19724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	child;
19824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	status;
19924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	count;
20024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
20124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
20224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
20324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	for(i = 0; i < nchild; i++) {
20424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		test_name[0] = 'a' + i;
20524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		test_name[1] = '\0';
20624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		fd = open(test_name, O_RDWR|O_CREAT|O_TRUNC, 0666);
20724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if (fd < 0) {
208af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_resm(TBROK, "\tError %d creating %s/%s.", errno, fuss, test_name);
20924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tst_exit();
21024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
21124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if ((child = fork()) == 0) {		/* child */
21224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			dotest(nchild, i, fd);		/* do it! */
21324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tst_exit();			/* when done, exit */
21424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
21524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
21624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		close(fd);
21724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
21824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if (child < 0) {
21924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tst_resm(TINFO, "System resource may be too low, fork() malloc()"
220af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier					      " etc are likely to fail.");
221af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		        tst_resm(TBROK, "Test broken due to inability of fork.");
22224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		        tst_exit();
22324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
22424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		} else {
22524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			pidlist[i] = child;
22624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			nwait++;
22724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
22824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
22924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
23024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	/*
23124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 * Wait for children to finish.
23224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 */
23324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
23424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	count = 0;
23524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	while(1)
23624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	{
23724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if ((child = wait(&status)) >= 0) {
238af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		//tst_resm(TINFO, "\tTest{%d} exited status = 0x%x", child, status);
23924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if (status) {
240af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_resm(TFAIL, "\tTest{%d} failed, expected 0 exit.", child);
24124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			local_flag = FAILED;
24224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
24324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		++count;
24424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
24524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	else
24624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	{
24724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if (errno != EINTR)
24824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			break;
24924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
25024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
25124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
25224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	/*
25324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 * Should have collected all children.
25424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 */
25524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
25624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if (count != nwait) {
257af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		tst_resm(TFAIL, "\tWrong # children waited on, count = %d", count);
25824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		local_flag = FAILED;
25924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
26024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
26124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	chdir(homedir);
26224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
26324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	pid = fork();
26424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if (pid < 0) {
26524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		tst_resm(TINFO, "System resource may be too low, fork() malloc()"
266af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier                              " etc are likely to fail.");
267af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier                tst_resm(TBROK, "Test broken due to inability of fork.");
26824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		sync();				/* safeness */
26924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		tst_exit();
27024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
27124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
27224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if (pid == 0) {
2737fdd5140a541cba0961c35161e2fa43426dce653robbiew		execl("/bin/rm", "rm", "-rf", fuss, NULL);
27424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		tst_exit();
27524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	} else
27624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		wait(&status);
27724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if (status) {
278af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		tst_resm(TINFO, "CAUTION - ftest03, '%s' may not be removed", fuss);
279af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		tst_resm(TINFO, "CAUTION - ftest03, '%s' may not be removed",
28024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		  fuss);
28124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
282bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak
28324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	sync();				/* safeness */
28443337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak	return 0;
28524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew}
28624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
28724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew/*
28824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew * dotest()
28924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	Children execute this.
29024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *
29124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew * Randomly read/mod/write chunks with known pattern and check.
29224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew * When fill sectors, iterate.
29324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew */
29424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
29524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#define	NMISC	4
29624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewenum	m_type { m_fsync, m_trunc, m_fstat };
29724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewchar	*m_str[] = {
29824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		"fsync",   "trunc", "sync", "fstat"
29924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew};
30024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
30124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	misc_cnt[NMISC];		/* counts # of each kind of misc */
30224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	file_max;			/* file-max size */
30324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	nchunks;
30424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	last_trunc = -1;
30524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint	tr_flag;
30624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewenum	m_type type = m_fsync;
30724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
30824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#define	CHUNK(i)	((i) * csize)
30924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew#define	NEXTMISC	((rand() % misc_intvl) + 5)
31024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
31124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint dotest(testers, me, fd)
31224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	testers;
31324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	me;
31424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	fd;
31524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew{
31624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register int	i;
31724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	char	*bits;
31824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	char	*hold_bits;
31924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	count;
32024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	collide;
32124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	char	val;
32224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	chunk;
32324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	whenmisc;
32424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	xfr;
32524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
32624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	/* Stuff for the readv call */
32724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	struct	iovec	r_iovec[MAXIOVCNT];
32824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	r_ioveclen;
32924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
33024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	/* Stuff for the writev call */
33124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	struct	iovec	val_iovec[MAXIOVCNT];
33224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
33324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	struct	iovec	zero_iovec[MAXIOVCNT];
33424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	w_ioveclen;
33524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
33624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	nchunks = max_size / csize;
33724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if( (bits = (char*)malloc((nchunks+7) / 8)) == 0) {
338af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		tst_resm(TBROK, "\tmalloc failed");
33924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		tst_exit();
34024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
34124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if( (hold_bits = (char*)malloc((nchunks+7) / 8)) == 0) {
342af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		tst_resm(TBROK, "\tmalloc failed");
34324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		tst_exit();
34424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
34524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
34624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	/*Allocate memory for the iovec buffers and init the iovec arrays
34724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 */
34824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	r_ioveclen = w_ioveclen = csize / MAXIOVCNT;
34924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
35024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		/* Please note that the above statement implies that csize
35124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		 * be evenly divisible by MAXIOVCNT.
35224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		 */
35324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
35424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	for (i = 0; i < MAXIOVCNT; i++) {
3551530d9c99454f0c6aa79340c17b2e821fd6bf46erobbiew		if( (r_iovec[i].iov_base = (char*)calloc(r_ioveclen, 1)) == 0) {
356af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_brkm(TBROK, NULL, "\tmalloc failed");
35724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			/* tst_exit(); */
35824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
35924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		r_iovec[i].iov_len = r_ioveclen;
36024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
36124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		/* Allocate unused memory areas between all the buffers to
36224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		 * make things more diffult for the OS.
36324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		 */
36424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
36524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if(malloc((i+1)*8) == 0) {
366af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_brkm(TBROK,NULL, "\tmalloc failed");
36724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
3681530d9c99454f0c6aa79340c17b2e821fd6bf46erobbiew		if( (val_iovec[i].iov_base = (char*)calloc(w_ioveclen, 1)) == 0) {
369af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_resm(TBROK, "\tmalloc failed");
37024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tst_exit();
37124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
37224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		val_iovec[i].iov_len = w_ioveclen;
373bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak
37424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if(malloc((i+1)*8) == 0) {
375af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_resm(TBROK, "\tmalloc failed");
37624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tst_exit();
37724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
3781530d9c99454f0c6aa79340c17b2e821fd6bf46erobbiew		if( (zero_iovec[i].iov_base = (char*)calloc(w_ioveclen, 1)) == 0) {
379af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_resm(TBROK, "\tmalloc failed");
38024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tst_exit();
38124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
38224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		zero_iovec[i].iov_len = w_ioveclen;
38324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
38424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if(malloc((i+1)*8) == 0) {
385af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_resm(TBROK, "\tmalloc failed");
38624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tst_exit();
38724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
38824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
38924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	/*
39024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 * No init sectors; allow file to be sparse.
39124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 */
39224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	val = (64/testers) * me + 1;
39324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
3944bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	/*
3954bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	 * For each iteration:
3964bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	 *	zap bits array
3974bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	 *	loop
3984bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	 *		pick random chunk, read it.
3994bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	 *		if corresponding bit off {
40024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 *			verify = 0. (sparse file)
40124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 *			++count;
40224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 *		} else
40324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 *			verify = val.
40424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 *		write "val" on it.
40524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 *		repeat unitl count = nchunks.
40624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 *	++val.
40724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew         */
40824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
40924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 srand(getpid());
41024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 if (misc_intvl) whenmisc = NEXTMISC;
41124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew 	while(iterations-- > 0) {
41224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		for(i = 0; i < NMISC; i++)
41324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			misc_cnt[i] = 0;
41424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		ftruncate(fd,0);
41524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		file_max = 0;
41624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		bfill(bits, 0, (nchunks+7) / 8);
41724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		bfill(hold_bits, 0, (nchunks+7) / 8);
41824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
41924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		/* Have to fill the val and zero iov buffers in a different manner
42024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		 */
42124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		for(i = 0; i < MAXIOVCNT; i++) {
42224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			bfill(val_iovec[i].iov_base,val,val_iovec[i].iov_len);
42324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			bfill(zero_iovec[i].iov_base,0,zero_iovec[i].iov_len);
42424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
42524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
42624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		count = 0;
42724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		collide = 0;
42824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		while(count < nchunks) {
42924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			chunk = rand() % nchunks;
43024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			/*
43124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			 * Read it.
43224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			 */
43324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			if (lseek(fd, (long)CHUNK(chunk), 0) < 0) {
434af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier				tst_resm(TFAIL, "\tTest[%d]: lseek(0) fail at %x, errno = %d.",
43524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew					me, CHUNK(chunk), errno);
43624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				tst_exit();
43724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			}
43824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			if ((xfr = readv(fd, &r_iovec[0], MAXIOVCNT)) < 0) {
439af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier				tst_resm(TFAIL, "\tTest[%d]: readv fail at %x, errno = %d.",
44024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew					me, CHUNK(chunk), errno);
44124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				tst_exit();
44224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			}
44324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			/*
44424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			 * If chunk beyond EOF just write on it.
44524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			 * Else if bit off, haven't seen it yet.
44624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			 * Else, have.  Verify values.
44724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			 */
44824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			if (CHUNK(chunk) >= file_max) {
44924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				bits[chunk/8] |= (1<<(chunk%8));
45024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				++count;
45124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			} else if ((bits[chunk/8] & (1<<(chunk%8))) == 0) {
45224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				if (xfr != csize) {
453af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier					tst_resm(TFAIL, "\tTest[%d]: xfr=%d != %d, zero read.",
45424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						me, xfr, csize);
45524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew					tst_exit();
45624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				}
45724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				for(i=0;i<MAXIOVCNT; i++) {
45824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew					if (memcmp(r_iovec[i].iov_base, zero_iovec[i].iov_base, r_iovec[i].iov_len)) {
45924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						tst_resm(TFAIL,
460af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier					  	"\tTest[%d] bad verify @ 0x%x for val %d count %d xfr %d file_max 0x%x, should be 0.",
46124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew							me, CHUNK(chunk), val, count, xfr, file_max);
462af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier						tst_resm(TINFO, "\tTest[%d]: last_trunc = 0x%x.",
46324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew							me, last_trunc);
46424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						sync();
46524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						dumpiov(&r_iovec[i]);
46624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						dumpbits(bits, (nchunks+7)/8);
46724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						orbits(hold_bits, bits, (nchunks+7)/8);
4684bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak						tst_resm(TINFO, "\tHold ");
46924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						dumpbits(hold_bits, (nchunks+7)/8);
47024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						tst_exit();
47124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew					}
47224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				}
47324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				bits[chunk/8] |= (1<<(chunk%8));
47424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				++count;
47524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			} else {
47624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				if (xfr != csize) {
477af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier					tst_resm(TFAIL, "\tTest[%d]: xfr=%d != %d, val read.",
47824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						me, xfr, csize);
47924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew					tst_exit();
48024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				}
48124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				++collide;
48224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				for(i=0; i<MAXIOVCNT; i++) {
48324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew					if (memcmp(r_iovec[i].iov_base, val_iovec[i].iov_base, r_iovec[i].iov_len)) {
484af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier						tst_resm(TFAIL, "\tTest[%d] bad verify @ 0x%x for val %d count %d xfr %d file_max 0x%x.",
48524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew							me, CHUNK(chunk), val, count, xfr, file_max);
486af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier						tst_resm(TINFO, "\tTest[%d]: last_trunc = 0x%x.",
48724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew							me, last_trunc);
48824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						sync();
48924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						dumpiov(&r_iovec[i]);
49024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						dumpbits(bits, (nchunks+7)/8);
49124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						orbits(hold_bits, bits, (nchunks+7)/8);
4924bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak						tst_resm(TINFO, "\tHold ");
49324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						dumpbits(hold_bits, (nchunks+7)/8);
49424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew						tst_exit();
49524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew					}
49624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				}
49724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			}
49824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			/*
49924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			 * Writev it.
50024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			 */
50124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			if (lseek(fd, -((long)xfr), 1) <  0) {
502af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier				tst_resm(TFAIL, "\tTest[%d]: lseek(1) fail at %x, errno = %d.",
50324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew					me, CHUNK(chunk), errno);
50424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				tst_exit();
50524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			}
50624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			if ((xfr = writev(fd, &val_iovec[0], MAXIOVCNT)) < csize) {
50724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				if (errno == ENOSPC) {
508af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier					tst_resm(TFAIL, "\tTest[%d]: no space, exiting.", me);
50924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew					fsync(fd);
51024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew					tst_exit();
51124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				}
512af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier				tst_resm(TFAIL, "\tTest[%d]: writev fail at %x xfr %d, errno = %d.",
51324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew					me, CHUNK(chunk), xfr, errno);
51424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				tst_exit();
51524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			}
51624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			if (CHUNK(chunk) + csize > file_max)
51724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				file_max = CHUNK(chunk) + csize;
51824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			/*
51924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			 * If hit "misc" interval, do it.
52024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			 */
52124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			if (misc_intvl && --whenmisc <= 0) {
52224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				orbits(hold_bits, bits, (nchunks+7)/8);
52324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				domisc(me, fd, bits);
52424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				whenmisc = NEXTMISC;
52524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			}
52624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			if (count + collide > 2 * nchunks)
52724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				break;
52824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
52924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
53024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		/*
53124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		 * End of iteration, maybe before doing all chunks.
53224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		 */
53324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
53424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		fsync(fd);
53524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		++misc_cnt[(int)m_fsync];
536af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		//tst_resm(TINFO, "\tTest{%d} val %d done, count = %d, collide = {%d}",
53724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	        //		me, val, count, collide);
53824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		//for(i = 0; i < NMISC; i++)
539af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		//	tst_resm(TINFO, "\t\tTest{%d}: {%d} %s's.", me, misc_cnt[i], m_str[i]);
54024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		++val;
54124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
54243337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak	return 0;
54324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew}
54424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
54524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew/*
54624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew * domisc()
54724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	Inject misc syscalls into the thing.
54824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew */
54924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
55024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint domisc(me, fd, bits)
55124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	me;
55224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	fd;
55324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	char	*bits;
55424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew{
55524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register int	chunk;
55624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	struct	stat sb;
55724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
55824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if ((int) type > (int) m_fstat)
55924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		type = m_fsync;
56024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	switch(type) {
56124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	case m_fsync:
56224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if (fsync(fd) < 0) {
563af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_resm(TFAIL, "\tTest[%d]: fsync error %d.", me, errno);
56424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tst_exit();
56524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
56624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		break;
56724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	case m_trunc:
56824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		chunk = rand() % (file_max / csize);
56924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		file_max = CHUNK(chunk);
57024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		last_trunc = file_max;
57124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if (tr_flag) {
57224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			if (ftruncate(fd, file_max) < 0) {
573af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier				tst_resm(TFAIL, "\tTest[%d]: ftruncate error %d @ 0x%x.", me, errno, file_max);
57424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				tst_exit();
57524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			}
57624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tr_flag = 0;
57724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		} else {
57824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			if (truncate(test_name, file_max) < 0) {
579af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier				tst_resm(TFAIL, "\tTest[%d]: truncate error %d @ 0x%x.", me, errno, file_max);
58024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				tst_exit();
58124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			}
58224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tr_flag = 1;
58324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
58424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		for(; chunk%8 != 0; chunk++)
58524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			bits[chunk/8] &= ~(1<<(chunk%8));
58624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		for(; chunk < nchunks; chunk += 8)
58724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			bits[chunk/8] = 0;
58824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		break;
58924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	case m_fstat:
59024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if (fstat(fd, &sb) < 0) {
591af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_resm(TFAIL, "\tTest[%d]: fstat() error %d.", me, errno);
59224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tst_exit();
59324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
59424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if (sb.st_size != file_max) {
595af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_resm(TFAIL, "\tTest[%d]: fstat() mismatch; st_size=%x,file_max=%x.",
59624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				me, sb.st_size, file_max);
59724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			tst_exit();
59824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
59924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		break;
60024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
60124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	++misc_cnt[(int)type];
60224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	type = (enum m_type) ((int) type + 1);
60343337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak	return 0;
60424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew}
60524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
60624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint bfill(buf, val, size)
60724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register char *buf;
60824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	char	val;
60924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register int size;
61024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew{
61124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register int i;
61224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
61324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	for(i = 0; i < size; i++)
61424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		buf[i] = val;
61543337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak	return 0;
61624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew}
61724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
61824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew/*
61924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew * dumpiov
62024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	Dump the contents of the r_iovec buffer.
62124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew */
62224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
62324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint dumpiov(iovptr)
62424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register struct iovec *iovptr;
62524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew{
62624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register int i;
62724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	char	val;
62824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	idx;
62924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	int	nout;
63024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
63124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	nout = 0;
63224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	idx = 0;
63324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	val = ((char *)iovptr->iov_base)[0];
63424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	for(i = 0; i < iovptr->iov_len; i++) {
63524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if (((char *)iovptr->iov_base)[i] != val) {
63624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			if (i == idx+1)
63724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				tst_resm(TINFO, "\t%x, ", ((char *)iovptr->iov_base)[idx] & 0xff);
63824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			else
63924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				tst_resm(TINFO, "\t%d*%x, ", i-idx, ((char *)iovptr->iov_base)[idx] & 0xff);
64024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			idx = i;
64124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			++nout;
64224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
64324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if (nout > 10) {
644af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_resm(TINFO, "\t ... more");
64543337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak			return 0;
64624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		}
64724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
64824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if (i == idx+1)
649af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		tst_resm(TINFO, "\t%x", ((char *)iovptr->iov_base)[idx] & 0xff);
65024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	else
651af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		tst_resm(TINFO, "\t%d*%x", i-idx, ((char *)iovptr->iov_base)[idx]);
65243337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak	return 0;
65324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew}
65424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
65524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew/*
65624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew * dumpbits
65724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	Dump the bit-map.
65824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew */
65924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
66024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint dumpbits(bits, size)
66124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	char	*bits;
66224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register int size;
66324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew{
66424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register char *buf;
66524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
66624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	for(buf = bits; size > 0; --size, ++buf) {
66724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		if ((buf-bits) % 16 == 0)
668af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier			tst_resm(TINFO, "\t%04x:\t", 8*(buf-bits));
66924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		tst_resm(TINFO, "\t%02x ", (int)*buf & 0xff);
67024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
67143337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak	return 0;
67224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew}
67324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
67424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint orbits(hold, bits, count)
67524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register char *hold;
67624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register char *bits;
67724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register int count;
67824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew{
67924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	while(count-- > 0)
68024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		*hold++ |= *bits++;
68143337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak	return 0;
68224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew}
68324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
68424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
68524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew/* term()
68624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *
68724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew *	This is called when a SIGTERM signal arrives.
68824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew */
68924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
69024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiewint term()
69124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew{
69224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	register int i;
69324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
694af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier	tst_resm(TINFO, "\tterm -[%d]- got sig term.", getpid());
69524e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
69624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	/*
69724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 * If run by hand we like to have the parent send the signal to
69824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 * the child processes.  This makes life easy.
69924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	 */
70024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
70124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if (parent_pid == getpid()) {
70224e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		for (i=0; i < nchild; i++)
70324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew			if (pidlist[i])		/* avoid embarassment */
70424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew				kill(pidlist[i], SIGTERM);
70543337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak		return 0;
70624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	}
70724e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
708af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier	tst_resm(TINFO, "\tunlinking '%s'", test_name);
70924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
71024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	close(fd);
71124e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	if (unlink(test_name))
712af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		tst_resm(TBROK, "Unlink of '%s' failed, errno = %d.",
71324e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew		  test_name, errno);
71424e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	else
715af64a878a5f86f98675e1d00691f12f9fa57bd8fvapier		tst_resm(TBROK, "Unlink of '%s' successful.", test_name);
71624e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew	tst_exit();
71743337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak	return 0;
71824e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew}
71924e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
72024e30ab69eb6e1b128ea1eb2dc12df4066c2227erobbiew
721