File:  [CSRG BSD Unix] / 43BSDReno / sys / nfs / TEST / mac-tests / Mac-Cthon.tar
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:57 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43reno
BSD 4.3reno

Mac-Cthon/   775    162     12           0  4542261416   5573 Mac-Cthon/basic-test-0.24   664    162     12           0  4542261053  10125 Mac-Cthon/log file   664    162     12         114  4542261055   7237 Macintosh NFS Revision 2 BASIC test suite (V0.24)	Fri Dec 15 16:23:11 1989

log.c�main.c�Makefilerad�README!�runtestse_�
stdio.full�subr.c�temp��test�	test.rsrcro�test1.c�test2.c�test3.c� test4.c�!test4a.c��"test5.c�#test5a.c�$test5b.cacl�%test6.c�&test7.c�'test7a.cils�(test7b.c�"�)test8.c�*test9.c�+tests.h�uMac-Cthon/log.c   664    162     12        1510  4542261057   6603 static int count = 0;
static char line[1024];
static int log_fd = 0;

extern void (*_echo_to_printer_)();	/* global Echo call variable for printer */

/*
	This routine is called by the LSC "printf" to echo chars
	to a printer. We redirect them to a file for logging.
	
	we also check the gatorbox for log info after each line.
*/

echo_to_file(ch)
register char ch;
{
	if (log_fd == 0)
		{
		log_fd = creat("log file", 0666);
		}
	
	if (log_fd < 0)
		return;

	if (count == 0)
		{
		_echo_to_printer_ = (void *)0;
		_echo_to_printer_ = (void *)echo_to_file;
		}

	if (ch != '\n')
		{
		line[ count++ ] = ch;
		return;
		}
	
	line[ count++ ] = '\r';
	write(log_fd, line, count);
	count = 0;
}

echo_line_to_file(line)
char *line;
{
	write(log_fd, line, strlen(line));
}

echo_to_file_done()
{
	if (log_fd)
		close(log_fd);
		
	log_fd = 0;
}
Mac-Cthon/main.c   664    162     12        4605  4542261060   6750 #include "tests.h"

int trace = 0;
int debug = 0;

int Tflag = 1;		/* print timing */
int Hflag = 0;		/* print help message */
int Sflag = 0;		/* don't print non-error messages */
int Fflag = 0;		/* test function only;  set count to 1, negate -t */
int Nflag = 0;		/* Suppress directory operations */
int Iflag = 0;		/* Ignore non-test files dir entries */

char TESTDIR[256];

int DDIRS = 2;
int DLEVS = 5;
int DFILS = 5;

long DSIZE = 1048576;

#define	OFF		if (0)

extern void (*_echo_to_printer_)();	/* global Echo call variable for printer */

char **argv(arg)
int arg;
{
	static char *vector[32];
	char **p, **from;
	
	p = vector;
	from = (char **)&arg;
	while (*p++ = *from++);

	*p++ = (char *)0;
	return vector;
}

main()
{
	int start = 0;
	int more = TRUE;

	extern echo_to_file();
	extern char *ctime();

	extern int default_vrefnum;

	_echo_to_printer_ = (void *)echo_to_file;

	printf("Macintosh NFS Revision 2 BASIC test suite (V0.24)\t%s\n", ctime(0L));

	/* ask were we should test */
	if (!askfordir(TESTDIR, &default_vrefnum))
		return;

	if (debug)
		{
		DDIRS = 1;
		DLEVS = 2;
		DFILS = 1;

		DSIZE = 8192;
		}

	if (0)
		{
		rmdir_recurse(TESTDIR);
		return;
		}

#ifdef DEBUG
	start = 1;
	more = TRUE;
	printf("**DEBUG VERSION**\n");
#endif

#define	FLAGS	"-n",

	if (start <= 1)
		{
		test1(1, argv("test1", FLAGS (char *)0));
		if (!more) goto done;
		}
	if (start <= 2)
		{
		test2(1, argv("test2", FLAGS (char *)0));
		if (!more) goto done;
		}
	if (start <= 3)
		{
		test3(1, argv("test3", FLAGS (char *)0));
		if (!more) goto done;
		}
	if (start <= 4)
		{
		test4(1, argv("test4", (char *)0));
OFF		test4a(1, argv("test4a", (char *)0));
		if (!more) goto done;
		}
		
	if (start <= 5)
		{
		test5(1, argv("test5", FLAGS (char *)0));
OFF		test5a(1, argv("test5a", (char *)0));
OFF		test5b(1, argv("test5b", (char *)0));
		if (!more) goto done;
		}

	if (start <= 6)
		{
		test6(1, argv("test6", FLAGS (char *)0));
		if (!more) goto done;
		}

	if (start <= 7)
		{
		test7(1, argv("test7", FLAGS (char *)0));
OFF		test7a(1, argv("test7a", (char *)0));
OFF		test7b(1, argv("test7b", (char *)0));
		if (!more) goto done;
		}
		
	if (start <= 8)
		{
		test8(1, argv("test8", FLAGS (char *)0));
		if (!more) goto done;
		}

	if (start <= 9)
		{
		test9(1, argv("test9", FLAGS (char *)0));
		if (!more) goto done;
		}

done:
	printf("All tests completed.\t%s\n", ctime(0L));

	echo_to_file_done();
}

usage()
{
}

Mac-Cthon/Makefile   664    162     12        2733  4542261062   7322 #
#       @(#)Makefile	1.4 89/01/13 NFS Rev 2 Testsuite
#
# to make tests, use 'make'
# to copy tests to another directory, use 'make copy DESTDIR=dir'
# to copy source to another directory, use 'make dist DESTDIR=dir'

TESTS = test1 test2 test3 test4 test5 test6 test7 test8 test9
AUXTESTS = test4a test5a test5b test7a test7b
DESTDIR = /no/such/path
#  Define NFS3_2 for NFS 3.2 compatibility - Comment out if not NFS 3.2
#COMPAT = -DNFS3_2
CFLAGS = $(COMPAT)

all: origtests auxtests

origtests: $(TESTS)
auxtests: $(AUXTESTS)

test1: test1.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test2: test2.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test3: test3.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test4: test4.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test4a: test4a.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test5: test5.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test5a: test5a.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test5b: test5b.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test6: test6.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test7: test7.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test7a: test7a.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test7b: test7b.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test8: test8.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

test9: test9.c subr.o
	$(CC) $(CFLAGS) -o $@ [email protected] subr.o

clean:
	-rm *.o $(TESTS) $(AUXTESTS)

copy: $(TESTS)
	cp runtests $(TESTS) $(AUXTESTS) $(DESTDIR)

dist:
	cp runtests Makefile *.c *.h $(DESTDIR)
ts auxtests

origtests: $(TESTS)
auxtMac-Cthon/README!   664    162     12         431  4542261064   6556 
This is a simple port of the "basic tests" code from the connect-a-thon '89
to the Macintosh. It compiles under LightSpeed C 3.0 (it *does not* compile
under 4.0; sorry)

Feel free to call me or send e-mail if you have questions.

Brad Parker
[email protected]
(617) 494-1999
12/89
test3.c� test4.c�!test4a.c��"test5.c�#test5a.c�$test5b.cacl�%test6.c�&test7.c�'test7a.cils�(test7b.c�"�)test8.c�*test9.c�+tests.h�uMac-Cthon/runtests   664    162     12        2134  4542261066   7473 #!/bin/sh
#
#       @(#)runtests	1.2 89/01/08 NFS Rev 2 testsuite
#
. ../startup.sh

#  see ../startup.sh for usage info
# 'ARGS=-f' for basic funtionality tests (one pass of each test)
# 'ARGS=  ' for longer tests without timing (1-3 minutes per test)
# 'ARGS=-t' for longer tests with timing

echo "Starting BASIC tests: test directory $NFSTESTDIR (arg: $ARGS)"

# File and Directory tree creation test
echo ""
test1 $ARGS
# File and Directory tree removal test
echo ""
test2 $ARGS
# Lookup across mount point
echo ""
test3 $ARGS
# Setattr, getattr and lookup tests
echo ""
test4 $ARGS
# Getattr and lookup tests
# echo ""
# test4a $ARGS
# Write and read tests
echo ""
test5 $ARGS
# Test 5a and 5b separate out the read and write tests into simpler components.
# echo ""
# test5a $ARGS
# echo ""
# test5b $ARGS
# Read Directory test
echo ""
test6 $ARGS
# Rename and Link Test
echo ""
test7 $ARGS
# Rename Test
# echo ""
# test7a $ARGS
# Link Test
# echo ""
# test7b $ARGS
# Symlink and readlink test
echo ""
test8 $ARGS
# Getfs test
echo ""
test9 $ARGS
echo ""

echo "Congratulations, you passed the basic tests!"
IZE = 8192;
		}

	if (0)
		{
		rmdir_recurse(TESTDIR);
		return;
		}

#ifdef DEBUG
	start = 1;
	more = TRUE;
	printf("**DEBUG VERSION**\n");
#endif

#define	FLAGS	"-n",

	if (start <= 1)
		{
		test1(1, argv("test1", FLAGS (char *)0));
		if (!more) goto done;
		}
	if (start <= 2)
		{
		test2(1, argv("test2", FLAGS (char *)0));
		if (!more) goto done;
		}
	if (start <= 3)
		{
		test3(1, argv("test3", FLAGS (char *)0));Mac-Cthon/stdio.full   664    162     12           0  4542261070   7570 Mac-Cthon/subr.c   664    162     12       12254  4542261072   7021 /*	@(#)subr.c	1.2 89/01/08 NFS Rev 2 Testsuite	*/
/*
 * Useful subroutines shared by all tests
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_stat.h"
#include <stdio.h>
#include "tests.h"

char *Myname;

/*
 * Build a directory tree "lev" levels deep
 * with "files" number of files in each directory
 * and "dirs" fan out.  Starts at the current directory.
 * "fname" and "dname" are the base of the names used for
 * files and directories.
 */
dirtree(lev, files, dirs, fname, dname, totfiles, totdirs)
	int lev;
	int files;
	int dirs;
	char *fname;
	char *dname;
	int *totfiles;
	int *totdirs;
{
	int fd;
	int f, d;
	char name[MAXPATHLEN];

	if (lev-- == 0) {
		return;
	}

{
extern int trace;
if (trace > 1)
printf("[dirtree] level %d, total files %d, total dirs %d\n", lev, *totfiles, *totdirs);
}

	for ( f = 0; f < files; f++) {
		sprintf(name, "%s%d", fname, f);
		if ((fd = creat(name, 0666)) < 0) {
			error("creat %s failed", name);
			exit(1);
		}
		(*totfiles)++;
		if (close(fd) < 0) {
			error("close %d failed", fd);
			exit(1);
		}
	}
	for ( d = 0; d < dirs; d++) {
		sprintf(name, "%s%d.l%d", dname, d,lev);
		if (mkdir(name, 0777) < 0) {
			error("mkdir %s failed", name);
			exit(1);
		}
		(*totdirs)++;
		if (chdir(name) < 0) {
			error("chdir %s failed", name);
			exit(1);
		}
		dirtree(lev, files, dirs, fname, dname, totfiles, totdirs);
		if (chdir("..") < 0) {
			error("chdir .. failed");
			exit(1);
		}
	}
}

/*
 * Remove a directory tree starting at the current directory.
 * "fname" and "dname" are the base of the names used for
 * files and directories to be removed - don't remove anything else!
 * "files" and "dirs" are used with fname and dname to generate
 * the file names to remove.
 *
 * This routine will fail if, say after removing known files,
 * the directory is not empty.
 *
 * This is used to test the unlink function and to clean up after tests.
 */
rmdirtree(lev, files, dirs, fname, dname, totfiles, totdirs, ignore)
	int lev;
	int files;
	int dirs;
	char *fname;
	char *dname;
	int *totfiles;		/* total removed */
	int *totdirs;		/* total removed */
	int ignore;
{
	int f, d;
	char name[MAXPATHLEN];

	if (lev-- == 0) {
		return;
	}
	for ( f = 0; f < files; f++) {
		sprintf(name, "%s%d", fname, f);
		if (unlink(name) < 0 && !ignore) {
			error("unlink %s failed", name);
			exit(1);
		}
		(*totfiles)++;
	}
	for ( d = 0; d < dirs; d++) {
		sprintf(name, "%s%d.l%d", dname, d, lev);
		if (chdir(name) < 0) {
			if (ignore)
				continue;
			error("chdir %s failed", name);
			exit(1);
		}
		rmdirtree(lev, files, dirs, fname, dname, totfiles, totdirs, ignore);
		if (chdir("..") < 0) {
			error("chdir .. failed");
			exit(1);
		}
		if (rmdir(name) < 0) {
			error("rmdir %s failed", name);
			exit(1);
		}
		(*totdirs)++;
	}
}

/* VARARGS */
error(str, ar1, ar2, ar3, ar4, ar5, ar6, ar7, ar8, ar9)
	char *str;
{
	char *ret, *getwd(), path[MAXPATHLEN];

	if ((ret = getwd(path)) == NULL)
		fprintf(stderr, "%s: getwd failed\n", Myname);
	else
		fprintf(stderr, "\t%s: (%s) ", Myname, path);

	fprintf(stderr, str, ar1, ar2, ar3, ar4, ar5, ar6, ar7, ar8, ar9);
	if (errno)
		perror(" ");
	else
		fprintf(stderr, "\n");
	fflush(stderr);
	if (ret == NULL)
		exit(1);
}

static struct timeval ts, te;

/*
 * save current time in struct ts
 */
starttime()
{
	gettimeofday(&ts, (struct timezone *)0);
}

/*
 * sets the struct tv to the difference in time between
 * current time and the time in struct ts.
 */
endtime(tv)
	struct timeval *tv;
{

	gettimeofday(&te, (struct timezone *)0);
	if (te.tv_usec < ts.tv_usec) {
		te.tv_sec--;
		te.tv_usec += 1000000;
	}
	tv->tv_usec = te.tv_usec - ts.tv_usec;
	tv->tv_sec = te.tv_sec - ts.tv_sec;
}

/*
 * Set up and move to a test directory
 */
testdir(dir)
char *dir;
{
	struct stat statb;
	char *getenv();

	/*
	 *  If dir is non-NULL, use that dir.  If NULL, first
	 *  check for env variable NFSTESTDIR.  If that is not
	 *  set, use the compiled-in TESTDIR.
	 */
	if (dir == NULL)
		if ((dir = getenv("NFSTESTDIR")) == NULL)
			dir = TESTDIR;

	if (stat(dir, &statb) == 0) {
		if (rmdir_recurse(dir) != 0) {
			error("can't remove old test directory %s", dir);
			exit(1);
		}
	}

	if (mkdir(dir, 0777) < 0) {
		error("can't create test directory %s", dir);
		exit(1);
	}
	if (chdir(dir) < 0) {
		error("can't chdir to test directory %s", dir);
		exit(1);
	}
}

/*
 * Move to a test directory
 */
mtestdir(dir)
char *dir;
{
	struct stat statb;
	char str[MAXPATHLEN];
	char *getenv();

	/*
	 *  If dir is non-NULL, use that dir.  If NULL, first
	 *  check for env variable NFSTESTDIR.  If that is not
	 *  set, use the compiled-in TESTDIR.
	 */
	if (dir == NULL)
		if ((dir = getenv("NFSTESTDIR")) == NULL)
			dir = TESTDIR;

	if (chdir(dir) < 0) {
		error("can't chdir to test directory %s", dir);
		return -1;
	}
	return 0;
}

/*
 *  get parameter at parm, convert to int, and make sure that
 *  it is at least min.
 */
getparm(parm, min, label)
char *parm, *label;
int min;
{
	int val = atoi(parm);
	if (val < min) {
		error("Illegal %s parameter %d, must be at least %d",
		    label, val, min);
		exit(1);
	}
	return val;
}

/*
 *  exit point for successful test
 */
complete()
{
	fprintf(stdout, "\t%s ok.\n", Myname);
	exit(0);
}
irs" are used with fname and dname to generate
 * the file names to remove.
 *
 * This routine will fail if, say after removing known files,
 * the directory is not empty.
 *
 * This is used to test the unlink function and to clean up after tests.
 */
rmdirtree(lev, files, dirs, fname, dname, totfiles, totdirs, ignore)
	int lev;
	int fileMac-Cthon/temp   664    162     12        2232  4542261074   6547 if (0)
{
char p[256];
p[0] = ':';
strcpy(p+1, path);
if (p[ strlen(p)-1 ] != ':')
	strcat(p, ":");
strcpy(path, p);
}

{
char p[256];
p[0] = ':';
strcpy(p+1, path);
strcpy(path, p);
}

if (0)
printf("[rmdir] default_dir_id %lx\n", default_dir_id);

/* remove any working dir info */
if (0)
{
	long dirid;
	CInfoPBRec iopb;
	int index;
	
	/* first get dir id */
	iopb.hFileInfo.ioNamePtr = pname(path);
	iopb.hFileInfo.ioVRefNum = default_vrefnum;
	iopb.hFileInfo.ioDirID = default_dir_id;
	
	iopb.hFileInfo.ioFDirIndex = 0;
	result = PBGetCatInfo(&iopb, FALSE);
	
	if (result != noErr)
		return result;

	dirid = iopb.hFileInfo.ioDirID;

	/* then scan wd's */
	for (index = 1;; index++)
		{
		WDPBRec wd_iopb;

		wd_iopb.ioVRefNum = default_vrefnum;
		wd_iopb.ioNamePtr = (StringPtr)0;
		wd_iopb.ioWDProcID = 0;
		wd_iopb.ioWDVRefNum = 0;
		wd_iopb.ioWDIndex = index;
		result = PBGetWDInfo(&wd_iopb, FALSE);
printf("[rmdir] index %d, result %d, got dirid %lx, want %lx\n",
index, result, wd_iopb.ioWDDirID, dirid);
		if (result != noErr)
			break;
		
		if (wd_iopb.ioWDDirID == dirid)
			{
printf("[rmdir] got wd, index %d\n", index);
			PBCloseWD(&wd_iopb, FALSE);
			}
		}
}
			dir = TESTDIR;

	if (chdir(dir) < 0) {
		error("can't chdir to test directory %s", dir);
		return -1;
	}
	return 0;
}

/*
 *  get parameter at parm, convert to int, and make sure that
 *  it is at least min.
 */
getparm(parm, min, label)
char *parm, *label;
int min;
{
	int val = atoi(parm);
	if (val < min) {
		error("Illegal %s parameter %d, must be at Mac-Cthon/test   664    162     12           0  4542261075   6471 Mac-Cthon/test.rsrc   664    162     12           0  4542261077   7443 Mac-Cthon/test1.c   664    162     12        4715  4542261101   7062 /*	@(#)test1.c	1.3 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test file and directory creation.
 * Builds a tree on the server.
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	mkdir()		(if creating directories, level > 1)
 *	creat()
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_stat.h"
#include "sys_time.h"
#include <stdio.h>
#include "tests.h"

test1(argc, argv)
	int argc;
	char *argv[];
{
	int files = DFILS;	/* number of files in each dir */
	int totfiles = 0;
	int dirs = DDIRS;	/* directories in each dir */
	int totdirs = 0;
	int levels = DLEVS;	/* levels deep */
	char *fname = FNAME;
	char *dname = DNAME;
	struct timeval time;
	char command[MAXPATHLEN];
	struct stat statb;
	char *opts;

	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 's':	/* silent */
					Sflag++;
					break;

				case 't':	/* time */
					Tflag++;
					break;

				case 'f':	/* funtionality */
					Fflag++;
					break;

				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		levels = getparm(*argv, 1, "levels");
		argv++;
		argc--;
	}
	if (argc) {
		files = getparm(*argv, 0, "files");
		argv++;
		argc--;
	}
	if (argc) {
		dirs = getparm(*argv, 0, "dirs");
		if (dirs == 0 && levels != 1) {
			error("Illegal dirs parameter, must be at least 1");
			exit(1);
		}
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argc--;
		argv++;
	}
	if (argc) {
		dname = *argv;
		argc--;
		argv++;
	}
	if (argc != 0) {
		error("too many parameters");
		usage();
		exit(1);
	}

	if (Fflag) {
		Tflag = 0;
		levels = 2;
		files = 2;
		dirs = 2;
	}

	if (!Sflag) {
		fprintf(stdout, "%s: File and directory creation test\n",
		    Myname);
	}

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	if (Tflag && !Sflag) {
		starttime();
	}
	dirtree(levels, files, dirs, fname, dname, &totfiles, &totdirs);
	if (Tflag && !Sflag) {
		endtime(&time);
	}
	if (!Sflag) {
		fprintf(stdout,
		    "\tcreated %d files %d directories %d levels deep",
		    totfiles, totdirs, levels);
	}
	if (Tflag && !Sflag) {
		fprintf(stdout, " in %ld.%-2l]d seconds",
		    time.tv_sec, time.tv_usec / 10000);
	}
	if (!Sflag) {
		fprintf(stdout, "\n");
	}
	complete();
}
name) < 0) {
			if (ignore)
				continue;
			error(Mac-Cthon/test2.c   664    162     12        5112  4542261103   7055 /*	@(#)test2.c	1.3 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test file and directory removal.
 * Builds a tree on the server.
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	rmdir()		(if removing directories, level > 1)
 *	unlink()
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_stat.h"
#include <stdio.h>
#include "tests.h"

test2(argc, argv)
	int argc;
	char *argv[];
{
	int files = DFILS;	/* number of files in each dir */
	int totfiles = 0;
	int dirs = DDIRS;	/* directories in each dir */
	int totdirs = 0;
	int levels = DLEVS;	/* levels deep */
	char *fname = FNAME;
	char *dname = DNAME;
	struct timeval time;
	char command[MAXPATHLEN];
	struct stat statb;
	char *opts;
	char str[256];

	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;

				case 'f':	/* funtionality */
					Fflag++;
					break;

				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		levels = getparm(*argv, 1, "levels");
		argv++;
		argc--;
	}
	if (argc) {
		files = getparm(*argv, 0, "files");
		argv++;
		argc--;
	}
	if (argc) {
		dirs = getparm(*argv, 0, "dirs");
		if (dirs == 0 && levels != 1) {
			error("Illegal dirs parameter, must be at least 1");
			exit(1);
		}
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argc--;
		argv++;
	}
	if (argc) {
		dname = *argv;
		argc--;
		argv++;
	}
	if (argc != 0) {
		error("too many parameters");
		usage();
		exit(1);
	}

	if (Fflag) {
		Tflag = 0;
		levels = 2;
		files = 2;
		dirs = 2;
	}

	fprintf(stdout, "%s: File and directory removal test\n", Myname);

	if (mtestdir(NULL)) {
		sprintf(str, "test1 -s %s %d %d %d %s %s",
			Nflag ? "-n" : "",
			levels, files, dirs, fname, dname);
		if (system(str) != 0) {
			error("can't make directroy tree to remove");
			exit(1);
		}
		if (mtestdir(NULL)) {
			error("still can't go to test directory");
			exit(1);
		}
	}

	if (Tflag) {
		starttime();
	}
	rmdirtree(levels, files, dirs, fname, dname, &totfiles, &totdirs, 0);
	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout,
	    "\tremoved %d files %d directories %d levels deep",
	    totfiles, totdirs, levels);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds",
		    time.tv_sec, time.tv_usec / 10000);
	}
	fprintf(stdout, "\n");
	complete();
}
ame, dname, totfiles, totdirs, ignore);
		if (chdir("..") < 0) {
			error("chdir .. failed");
			exit(1);
		}
		if (rmdir(name) < 0) {
			error("rmdir %s failed", name);
			exit(1);
		}
		(*totdirs)++;
	}
}

/* VARARGS */
error(str, ar1, ar2, ar3, ar4, ar5, ar6, ar7, ar8, ar9)
	char *str;
{
	char *ret, *getwd(), path[MAXPATHLEN];

	if ((ret = getwd(path)) == NULL)
		fprintf(stderr, "%s: getwd failed\n", Myname);
	else
		fprintf(stderrMac-Cthon/test3.c   664    162     12        3501  4542261104   7057 /*	@(#)test3.c	1.3 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test lookup up and down across mount points
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	getwd()
 *	stat()
 */

#include "sys_param.h"
#include "sys_vfs.h"
#include "sys_time.h"
#include "sys_stat.h"
#include "sys_errno.h"

#include <stdio.h>
#include "tests.h"

test3(argc, argv)
	int argc;
	char *argv[];
{
	int count = 250;		/* times to do test */
	int ct;
	struct timeval time;
	struct statfs sfsb;
	int ret;
	struct stat statb;
	char *opts;
	char path[MAXPATHLEN];

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		usage();
		exit(1);
	}

	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	fprintf(stdout, "%s: lookups across mount point\n", Myname);

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		if (getwd(path) == NULL) {
			fprintf(stderr, "%s: getwd failed\n", Myname);
			exit(1);
		}
		if (stat(path, &statb) < 0) {
			error("can't stat %s after getwd", path);
			exit(1);
		}
	}

	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout, "\t%d getwd and stat calls", count * 2);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds",
		    time.tv_sec, time.tv_usec / 10000);
	}
	fprintf(stdout, "\n");
	complete();
}
irs = 2;
	}

	fprintf(stdout, "%s: File and directory removal test\n", Myname);

	if (mtestdir(NULL)) {
		sprintf(str, "test1 -s %s %d %d %d %s %s",
			Nflag ? "-n" : "",
			levels, files, diMac-Cthon/test4.c   664    162     12        5431  4542261106   7066 /*	@(#)test4.c	1.3 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test setattr, getattr and lookup
 *
 * Creates the files in the test directory - does not create a directory
 * tree.
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	mkdir()		(for initial directory creation if not -m)
 *	creat()
 *	chmod()
 *	stat()
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_stat.h"
#include <stdio.h>
#include "tests.h"

test4(argc, argv)
	int argc;
	char *argv[];
{
	int files = 10;		/* number of files in each dir */
	int fi;
	int count = 50;	/* times to do each file */
	int ct;
	int totfiles = 0;
	int totdirs = 0;
	char *fname = FNAME;
	struct timeval time;
	char str[MAXPATHLEN];
	struct stat statb;
	char *opts;

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* suppress initial directory */
					Nflag++;
					break;
				
				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		files = getparm(*argv, 1, "files");
		argv++;
		argc--;
	}
	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argc--;
		argv++;
	}
	if (argc) {
		usage();
		exit(1);
	}

	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	dirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs);

	fprintf(stdout, "%s: setattr, getattr, and lookup\n", Myname);

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		for (fi = 0; fi < files; fi++) {
			sprintf(str, "%s%d", fname, fi);
			if (chmod(str, 0) < 0) {
				error("can't chmod 0 %s", str);
				exit(0);
			}
			if (stat(str, &statb) < 0) {
				error("can't stat %s", str);
				exit(1);
			}
			if ((statb.st_mode & 0777) != 0) {
				error("%s has mode %o after chmod 0",
				    str, (statb.st_mode & 0777));
				exit(1);
			}
			if (chmod(str, 0666) < 0) {
				error("can't chmod 0666 %s", str);
				exit(0);
			}
			if (stat(str, &statb) < 0) {
				error("can't stat %s", str);
				exit(1);
			}
			if ((statb.st_mode & 0777) != 0666) {
				error("%s has mode %o after chmod 0666",
				    str, (statb.st_mode & 0777));
				exit(1);
			}
		}
	}

	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout, "\t%d chmods and stats on %d files",
		files * count * 2, files);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds",
		    time.tv_sec, time.tv_usec / 10000);
	}
	fprintf(stdout, "\n");
	/* XXX REMOVE DIRECTORY TREE? */
	complete();
}
gc--;
		argv++;
	}

	if (argc) {
		files = getparm(*argv, 1, "files");
		argv++;
		argc--;
	}
	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argc--;
		argv++;
	}
	if (argc)Mac-Cthon/test4a.c   664    162     12        4337  4542261110   7226 /*	@(#)test4a.c	1.2 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test getattr and lookup
 *
 * Creates the files in the test directory - does not create a directory
 * tree.
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	mkdir()		(for initial directory creation if not -m)
 *	creat()
 *	stat()
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_stat.h"
#include <stdio.h>
#include "tests.h"

test4a(argc, argv)
	int argc;
	char *argv[];
{
	int files = 10;		/* number of files in each dir */
	int fi;
	int count = 50;	/* times to do each file */
	int ct;
	int totfiles = 0;
	int totdirs = 0;
	char *fname = FNAME;
	struct timeval time;
	char str[MAXPATHLEN];
	struct stat statb;
	char *opts;

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* suppress initial directory */
					Nflag++;
					break;
				
				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		files = getparm(*argv, 1, "files");
		argv++;
		argc--;
	}
	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argc--;
		argv++;
	}
	if (argc) {
		usage();
		exit(1);
	}

	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	dirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs);

	fprintf(stdout, "%s: getattr and lookup\n", Myname);

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		for (fi = 0; fi < files; fi++) {
			sprintf(str, "%s%d", fname, fi);
			if (stat(str, &statb) < 0) {
				error("can't stat %s", str);
				exit(1);
			}
		}
	}

	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout, "\t%d stats on %d files",
		files * count * 2, files);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds",
		    time.tv_sec, time.tv_usec / 10000);
	}
	fprintf(stdout, "\n");
	/* XXX REMOVE DIRECTORY TREE? */
	complete();
}
me();
	}
	rmdirtree(levels, files, dirs, fname, dname, &totfiles, &totdirs, 0);
	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout,
	    "\tremoved %d files %d directories %d levels deep",
	    totfiles, totdirs, levels);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds",
		    timeMac-Cthon/test5.c   664    162     12        7601  4542261112   7065 /*	@(#)test5.c	1.4 89/01/13 NFS Rev 2 Testsuite	*/
/*
 * Test read and write
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	mkdir()		(for initial directory creation if not -m)
 *	creat()
 *	open()
 *	read()
 *	write()
 *	stat()
 *	fstat()
 *	unlink()
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_stat.h"
#include <stdio.h>
#include "tests.h"

test5(argc, argv)
	int argc;
	char *argv[];
{
	int count = DCOUNT;	/* times to do each file */
	int ct;
	long size = DSIZE;
	long si;
	int i;
	int fd;
	int bytes;
	char *bigfile = "bigfile";
	struct timeval time;
	char str[MAXPATHLEN];
	struct stat statb;
	char *opts;
	char buf[BUFSZ];

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
                size = getparm(*argv, 1, "size");
		argv++;
		argc--;
	}
	if (argc) {
                count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
                bigfile = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		usage();
		exit(1);
	}
	
	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	fprintf(stdout, "%s: read and write\n", Myname);

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	for (i=0; i < BUFSZ / sizeof(int); i++) {
		((int *)buf)[i] = i;
	}

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		if ((fd = creat(bigfile, 0666)) < 0) {
			error("can't create '%s'", bigfile);
			exit(1);
		}
		if (fstat(fd, &statb) < 0) {
			error("can't stat '%s'", bigfile);
			exit(1);
		}
		if (statb.st_size != 0) {
			error("'%s' has size %ld, should be 0",
			    bigfile, statb.st_size);
			exit(1);
		}
                for (si = size; si > 0; si -= BUFSZ) {
			bytes = MIN(BUFSZ, si);
			if (write(fd, buf, bytes) != bytes) {
				error("'%s' write failed", bigfile);
				exit(1);
			}
		}
		close(fd);
		if (stat(bigfile, &statb) < 0) {
			error("can't stat '%s'", bigfile);
			exit(1);
		}
		if (statb.st_size != size) {
			error("'%s' has size %d, should be %d",
			    bigfile, statb.st_size, size);
			exit(1);
		}
	}

	if (Tflag) {
		endtime(&time);
	}

	if ((fd = open(bigfile, 0)) < 0) {
		error("can't open '%s'", bigfile);
		exit(1);
	}
	for (si = size; si; si -= BUFSZ) {
		bytes = MIN(BUFSZ, si);
		if (read(fd, buf, bytes) != bytes) {
			error("'%s' read failed", bigfile);
			exit(1);
		}
		for (i = 0; i < bytes / sizeof(int); i++) {
			if (((int *)buf)[i] != i) {
printf("i %d, buf %x, i %x\n", i, ((int *)buf)[i], i);
				error("bad data in '%s'", bigfile);
				exit(1);
			}
		}
	}
	close(fd);

	fprintf(stdout, "\twrote %ld byte file %d times", size, count);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds (%ld bytes/sec)",
		    time.tv_sec, time.tv_usec / 10000, size*count/time.tv_sec);
	}
	fprintf(stdout, "\n");
	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		if ((fd = open(bigfile, 0)) < 0) {
			error("can't open '%s'", bigfile);
			exit(1);
		}
		for (si = size; si; si -= BUFSZ) {
			bytes = MIN(BUFSZ, si);
			if (read(fd, buf, bytes) != bytes) {
				error("'%s' read failed", bigfile);
				exit(1);
			}
		}
		close(fd);
	}

	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout, "\tread %ld byte file %d times", size, 2*count);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds (%ld bytes/sec)",
		    time.tv_sec, time.tv_usec / 10000, size*count/time.tv_sec);
	}
	fprintf(stdout, "\n");

	if (unlink(bigfile) < 0) {
		error("can't unlink '%s'", bigfile);
		exit(1);
	}
	complete();
}
se 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtioMac-Cthon/test5a.c   664    162     12        5456  4542261114   7236 /*	@(#)test5a.c	1.2 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test write - DOES NOT VERIFY WRITE CONTENTS
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	mkdir()		(for initial directory creation if not -m)
 *	creat()
 *	write()
 *	stat()
 *	fstat()
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_stat.h"
#include <stdio.h>
#include "tests.h"

test5a(argc, argv)
	int argc;
	char *argv[];
{
	int count = DCOUNT;	/* times to do each file */
	int ct;
	long size = DSIZE;
	long si;
	int i;
	int fd;
	int bytes;
	char *bigfile = "bigfile";
	struct timeval time;
	char str[MAXPATHLEN];
	struct stat statb;
	char *opts;
	char buf[BUFSZ];

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
                size = getparm(*argv, 1, "size");
		argv++;
		argc--;
	}
	if (argc) {
                count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
                bigfile = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		usage();
		exit(1);
	}
	
	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	fprintf(stdout, "%s: write\n", Myname);

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	/* Set up contents, however we won't verify. */
	for (i=0; i < BUFSZ / sizeof(int); i++) {
		((int *)buf)[i] = i;
	}

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		if ((fd = creat(bigfile, 0666)) < 0) {
			error("can't create '%s'", bigfile);
			exit(1);
		}
		if (fstat(fd, &statb) < 0) {
			error("can't stat '%s'", bigfile);
			exit(1);
		}
		if (statb.st_size != 0) {
			error("'%s' has size %ld, should be 0",
			    bigfile, statb.st_size);
			exit(1);
		}
                for (si = size; si > 0; si -= BUFSZ) {
			bytes = MIN(BUFSZ, si);
			if (write(fd, buf, bytes) != bytes) {
				error("'%s' write failed", bigfile);
				exit(1);
			}
		}
		close(fd);
		if (stat(bigfile, &statb) < 0) {
			error("can't stat '%s'", bigfile);
			exit(1);
		}
		if (statb.st_size != size) {
			error("'%s' has size %ld, should be %d",
			    bigfile, statb.st_size, size);
			exit(1);
		}
	}

	if (Tflag) {
		endtime(&time);
	}

	fprintf(stdout, "\twrote %ld byte file %d times", size, count);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds (%ld bytes/sec)",
		    time.tv_sec, time.tv_usec / 10000, size*count/time.tv_sec);
	}
	fprintf(stdout, "\n");

	complete();
}
i++) {
			if (((int *)buf)[i] != i) {
printf("i %d, buf %x, i %x\n", i, ((int *)buf)[i], i);
				error("bad data in '%s'", bigfile);
				exit(1);
			}
		}
	}
	close(fd);

	fprintf(stdout, "\twrote %ld byte fileMac-Cthon/test5b.c   664    162     12        4460  4542261116   7233 /*	@(#)test5b.c	1.2 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test read - will read a file of specified size, contents not looked at
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	mkdir()		(for initial directory creation if not -m)
 *	open()
 *	read()
 *	unlink()
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_stat.h"
#include <stdio.h>
#include "tests.h"

test5b(argc, argv)
	int argc;
	char *argv[];
{
	int count = DCOUNT;	/* times to do each file */
	int ct;
	long size = DSIZE;
	long si;
	int i;
	int fd;
	int bytes;
	char *bigfile = "bigfile";
	struct timeval time;
	char str[MAXPATHLEN];
	struct stat statb;
	char *opts;
	char buf[BUFSZ];

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
                size = getparm(*argv, 1, "size");
		argv++;
		argc--;
	}
	if (argc) {
                count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
                bigfile = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		usage();
		exit(1);
	}
	
	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	fprintf(stdout, "%s: read\n", Myname);

	mtestdir(NULL);

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		if ((fd = open(bigfile, 0)) < 0) {
			error("can't open '%s'", bigfile);
			exit(1);
		}
		for (si = size; si; si -= BUFSZ) {
			bytes = MIN(BUFSZ, si);
			if (read(fd, buf, bytes) != bytes) {
				error("'%s' read failed", bigfile);
				exit(1);
			}
		}
		close(fd);
	}

	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout, "\tread %ld byte file %d times", size, count);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds (%ld bytes/sec)",
		    time.tv_sec, time.tv_usec / 10000, size*count/time.tv_sec);
	}
	fprintf(stdout, "\n");

	if (unlink(bigfile) < 0) {
		error("can't unlink '%s'", bigfile);
		exit(1);
	}
	complete();
}
fd);
		if (stat(bigfile, &statb) < 0) {
			error("can't stat '%s'", bigfile);
			exit(1);
		}
		if (statb.st_size != size) {
			error("'%s' has size %ld, should be %d",
			    bigfile, statb.st_size, size);
	Mac-Cthon/test6.c   664    162     12       11777  4542261120   7116 /*	@(#)test6.c	1.3 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test readdir
 *
 * Uses the following important system/library calls against the server:
 *
 *	chdir()
 *	mkdir()		(for initial directory creation if not -m)
 *	creat()
 *	unlink()
 *	opendir(), rewinddir(), readdir(), closedir()
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_dir.h"
#include <stdio.h>
#include "tests.h"


#define MAXFILES 512		/* maximum files allowed for this test */
#define BITMOD	 8		/* bits per u_char */
u_char bitmap[MAXFILES / BITMOD];
#define BIT(x)    (bitmap[(x) / BITMOD] &   (1 << ((x) % BITMOD)) )
#define SETBIT(x) (bitmap[(x) / BITMOD] |=  (1 << ((x) % BITMOD)) )
#define CLRBIT(x) (bitmap[(x) / BITMOD] &= ~(1 << ((x) % BITMOD)) )

test6(argc, argv)
	int argc;
	char *argv[];
{
#ifdef DEBUG
	int files = 5;	/* number of files in each dir */
	int count = 5;	/* times to read dir */
#else
	int files = 20 /* 200 */;	/* number of files in each dir */
	int count = 200;	/* times to read dir */
#endif
	int fi;
	int ct;
	int entries = 0;
	int totfiles = 0;
	int totdirs = 0;
	DIR *dir;
	struct direct *dp;
	char *fname = FNAME;
	struct timeval time;
	char *p, str[MAXPATHLEN];
	char *opts;
	int err, i, dot, dotdot;
	int nmoffset;

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				case 'i':	/* ignore spurious files */
					Iflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		files = getparm(*argv, 1, "files");
		argv++;
		argc--;
	}
	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		usage();
		exit(1);
	}

{
	extern int debug;
	if (debug)
	{
		files = 5;	/* number of files in each dir */
		count = 5;	/* times to read dir */
	}
}

	nmoffset = strlen(fname);

	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	if (count > files) {
		error("count (%d) can't be greater than files (%d)",
			count, files);
		exit(1);
	}

	if (files > MAXFILES) {
		error("too many files requested (max is %d)", MAXFILES);
		exit(1);
	}

	fprintf(stdout, "%s: readdir\n", Myname);

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	dirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs);

	if (Tflag) {
		starttime();
	}

	if ((dir = opendir(".")) == NULL) {
		error("can't opendir %s", ".");
		exit(1);
	}

	for (ct = 0; ct < count; ct++) {
printf("\tread count %d\n", ct);
		rewinddir(dir);
		dot = 0;
		dotdot = 0;
		err = 0;
		for (i = 0; i < sizeof(bitmap); i++)
			bitmap[i] = 0;
		while ((dp = readdir(dir)) != NULL) {
			entries++;
			if (strcmp(".", dp->d_name) == 0) {
				if (dot) {
					/* already read dot */
					error("'.' dir entry read twice");
					exit(1);
				}
				dot++;
				continue;
			} else if (strcmp("..", dp->d_name) == 0) {
				if (dotdot) {
					/* already read dotdot */
					error("'..' dir entry read twice");
					exit(1);
				}
				dotdot++;
				continue;
			}

			/*
			 * at this point, should have entry of the form
			 *  fname%d
			 */
			/* If we don't have our own directory, ignore
			   such errors (if Iflag set). */
			if (strncmp(dp->d_name, fname, nmoffset)) {
				if (Iflag)
					continue;
				else {
					error("unexpected dir entry '%s'",
						dp->d_name);
					exit(1);
				}
			}

			/* get ptr to numeric part of name */
			p = dp->d_name + nmoffset;
			fi = atoi(p);
			if (fi < 0 || fi >= MAXFILES) {
				error("unexpected dir entry '%s'",
					dp->d_name);
				exit(1);
			}
			if (BIT(fi)) {
				error("duplicate '%s' dir entry read",
					dp->d_name);
				err++;
			} else
				SETBIT(fi);
		}	/* end readdir loop */

#ifdef CHECK_DOTS
		if (!dot) {
			error("didn't read '.' dir entry, pass %d", ct);
			err++;
		}
		if (!dotdot) {
			error("didn't read '..' dir entry, pass %d", ct);
			err++;
		}
#endif
		for (fi = 0; fi < ct; fi++) {
			if (BIT(fi)) {
				sprintf(str, "%s%d", fname, fi);
				error("unlinked '%s' dir entry read pass %d",
					str, ct);
				err++;
			}
		}
		for (fi = ct; fi < files; fi++) {
			if (!BIT(fi)) {
				sprintf(str, "%s%d", fname, fi);
				error("\
didn't read expected '%s' dir entry, pass %d", str, ct);
				err++;
			}
		}
		if (err) {
			error("Test failed with %d errors", err);
			exit(1);
		}
		sprintf(str, "%s%d", fname, ct);
		if (unlink(str) < 0) {
			error("can't unlink %s", str);
			exit(1);
		}
	}

	closedir(dir);

	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout, "\t%d entries read, %d files",
		entries, files);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds",
		    time.tv_sec, time.tv_usec / 10000);
	}
	fprintf(stdout, "\n");
	rmdirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs, 1);
	complete();
}
Mac-Cthon/test7.c   664    162     12        7346  4542261122   7076 /*	@(#)test7.c	1.3 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test rename, link
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	creat()
 *	stat()
 *	rename()
 *	link()
 *	unlink()
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_stat.h"
#include <stdio.h>
#include "tests.h"

#define NNAME "newfile."	/* new filename for rename and link */


test7(argc, argv)
	int argc;
	char *argv[];
{
	int files = 10;		/* number of files in each dir */
	int fi;
	int count = 10;	/* times to do each file */
	int ct;
	int totfiles = 0;
	int totdirs = 0;
	char *fname = FNAME;
	char *nname = NNAME;
	struct timeval time;
	char str[MAXPATHLEN];
	char new[MAXPATHLEN];
	struct stat statb;
	char *opts;

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		files = getparm(*argv, 1, "files");
		argv++;
		argc--;
	}
	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		nname = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		usage();
		exit(1);
	}

	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	fprintf(stdout, "%s: link and rename\n", Myname);

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	dirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs);

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		for (fi = 0; fi < files; fi++) {
			sprintf(str, "%s%d", fname, fi);
			sprintf(new, "%s%d", nname, fi);
			if (rename(str, new) < 0) {
				error("can't rename %s to %s", str, new);
				exit(1);
			}
			if (stat(str, &statb) == 0) {
				error("%s exists after rename", str);
				exit(1);
			}
			if (stat(new, &statb) < 0) {
				error("can't stat %s after rename", new);
				exit(1);
			}
			if (statb.st_nlink != 1) {
				error("%s has %d links after rename (expect 1)",
					new, statb.st_nlink);
				exit(1);
			}
/*
			if (link(new, str) < 0) {
				error("can't link %s to %s", new, str);
				exit(1);
			}
			if (stat(new, &statb) < 0) {
				error("can't stat %s after link", new);
				exit(1);
			}
			if (statb.st_nlink != 2) {
				error("%s has %d links after link (expect 2)",
					new, statb.st_nlink);
				exit(1);
			}
			if (stat(str, &statb) < 0) {
				error("can't stat %s after link", str);
				exit(1);
			}
			if (statb.st_nlink != 2) {
				error("%s has %d links after link (expect 2)",
					str, statb.st_nlink);
				exit(1);
			}
			if (unlink(new) < 0) {
				error("can't unlink %s", new);
				exit(1);
			}
			if (stat(str, &statb) < 0) {
				error("can't stat %s after unlink %s",
					str, new);
				exit(1);
			}
			if (statb.st_nlink != 1) {
				error("%s has %d links after unlink (expect 1)",
					str, statb.st_nlink);
				exit(1);
			}
*/
			if (rename(new, str) < 0) {
				error("can't rename %s to %s", str, new);
				exit(1);
			}
			if (stat(str, &statb) < 0) {
				error("can't stat %s after 2nd rename %s",
					str, new);
				exit(1);
			}
		}
	}

	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout, "\t%d renames and links on %d files",
		files * count * 2, files);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds",
		    time.tv_sec, time.tv_usec / 10000);
	}
	fprintf(stdout, "\n");

	/* Cleanup files left around */
	rmdirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs, 1);

	complete();
}
		exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		files = getparm(*argv, 1, "files");
		argv++;
		argc--;
	}
	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		nname = *argv;
		argv+Mac-Cthon/test7a.c   664    162     12        5552  4542261124   7236 /*	@(#)test7a.c	1.2 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test rename
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	mkdir()		(for initial directory creation if not -m)
 *	creat()
 *	stat()
 *	rename()
 *	unlink()
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_stat.h"
#include <stdio.h>
#include "tests.h"

#define NNAME "newfile."	/* new filename for rename */


test7a(argc, argv)
	int argc;
	char *argv[];
{
	int files = 10;		/* number of files in each dir */
	int fi;
	int count = 10;	/* times to do each file */
	int ct;
	int totfiles = 0;
	int totdirs = 0;
	char *fname = FNAME;
	char *nname = NNAME;
	struct timeval time;
	char str[MAXPATHLEN];
	char new[MAXPATHLEN];
	struct stat statb;
	char *opts;

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		files = getparm(*argv, 1, "files");
		argv++;
		argc--;
	}
	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		nname = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		usage();
		exit(1);
	}

	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	fprintf(stdout, "%s: rename\n", Myname);

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	dirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs);

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		for (fi = 0; fi < files; fi++) {
			sprintf(str, "%s%d", fname, fi);
			sprintf(new, "%s%d", nname, fi);
			if (rename(str, new) < 0) {
				error("can't rename %s to %s", str, new);
				exit(1);
			}
			if (stat(str, &statb) == 0) {
				error("%s exists after rename", str);
				exit(1);
			}
			if (stat(new, &statb) < 0) {
				error("can't stat %s after rename", new);
				exit(1);
			}
			if (rename(new, str) < 0) {
				error("can't rename %s to %s", new, str);
				exit(1);
			}
			if (stat(new, &statb) == 0) {
				error("%s exists after rename", new);
				exit(1);
			}
			if (stat(str, &statb) < 0) {
				error("can't stat %s after rename", str);
				exit(1);
			}
		}
	}

	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout, "\t%d renames on %d files",
		files * count * 2, files);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds",
		    time.tv_sec, time.tv_usec / 10000);
	}
	fprintf(stdout, "\n");

	/* Cleanup files left around */
	rmdirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs, 1);

	complete();
}
(i = 0; i < sizeof(bitmap); i++)
			bitmap[i] = 0;
		while ((dp = readdir(dir)) != NULL) {
			entries++;
			if (strcmp(".", dp->d_name) == 0) {
				ifMac-Cthon/test7b.c   664    162     12        6163  4542261126   7240 /*	@(#)test7b.c	1.2 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test link
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	mkdir()		(for initial directory creation if not -m)
 *	creat()
 *	stat()
 *	link()
 *	unlink()
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_stat.h"
#include <stdio.h>
#include "tests.h"

#define NNAME "newfile."	/* new filename for link */


test7b(argc, argv)
	int argc;
	char *argv[];
{
	int files = 10;		/* number of files in each dir */
	int fi;
	int count = 10;	/* times to do each file */
	int ct;
	int totfiles = 0;
	int totdirs = 0;
	char *fname = FNAME;
	char *nname = NNAME;
	struct timeval time;
	char str[MAXPATHLEN];
	char new[MAXPATHLEN];
	struct stat statb;
	char *opts;

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		files = getparm(*argv, 1, "files");
		argv++;
		argc--;
	}
	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		nname = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		usage();
		exit(1);
	}

	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	fprintf(stdout, "%s: link\n", Myname);

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	dirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs);

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		for (fi = 0; fi < files; fi++) {
			sprintf(str, "%s%d", fname, fi);
			sprintf(new, "%s%d", nname, fi);
			if (link(str, new) < 0) {
				error("can't link %s to %s", str, new);
				exit(1);
			}
			if (stat(new, &statb) < 0) {
				error("can't stat %s after link", new);
				exit(1);
			}
			if (statb.st_nlink != 2) {
				error("%s has %d links after link (expect 2)",
					new, statb.st_nlink);
				exit(1);
			}
			if (stat(str, &statb) < 0) {
				error("can't stat %s after link", str);
				exit(1);
			}
			if (statb.st_nlink != 2) {
				error("%s has %d links after link (expect 2)",
					str, statb.st_nlink);
				exit(1);
			}
			if (unlink(new) < 0) {
				error("can't unlink %s", new);
				exit(1);
			}
			if (stat(str, &statb) < 0) {
				error("can't stat %s after unlink %s",
					str, new);
				exit(1);
			}
			if (statb.st_nlink != 1) {
				error("%s has %d links after unlink (expect 1)",
					str, statb.st_nlink);
				exit(1);
			}
		}
	}

	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout, "\t%d links on %d files",
		files * count, files);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds",
		    time.tv_sec, time.tv_usec / 10000);
	}
	fprintf(stdout, "\n");

	/* Cleanup files left around */
	rmdirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs, 1);

	complete();
}
tfiles = 0;
	int totdirs = 0;
	char *fname = FNAME;
	char *nname = NNAME;
	struct timeval time;
	char str[MAXPATHLEN];
	char new[MAXPATHLEN];
	struct stat statb;
	char *opts;

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				caseMac-Cthon/test8.c   664    162     12        6251  4542261127   7076 /*	@(#)test8.c	1.3 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test symlink, readlink
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	mkdir()		(for initial directory creation if not -m)
 *	creat()
 *	symlink()
 *	readlink()
 *	lstat()
 *	unlink()
 */

#include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_stat.h"
#include "sys_errno.h"
#include <stdio.h>
#include "tests.h"

#define SNAME "/this/is/a/symlink"	/* symlink prefix */

test8(argc, argv)
	int argc;
	char *argv[];
{
	int files = 10;		/* number of files in each dir */
	int fi;
	int count = 20;	/* times to do each file */
	int ct;
	int totfiles = 0;
	int totdirs = 0;
	char *fname = FNAME;
	char *sname = SNAME;
	struct timeval time;
	char str[MAXPATHLEN];
	char new[MAXPATHLEN];
	char buf[MAXPATHLEN];
	int ret;
	struct stat statb;
	char *opts;

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		files = getparm(*argv, 1, "files");
		argv++;
		argc--;
	}
	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		sname = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		usage();
		exit(1);
	}

#ifndef S_IFLNK
	fprintf(stdout, "\
%s: symlink and readlink not supported on this client\n", Myname);
#else S_IFLNK
	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	fprintf(stdout, "%s: symlink and readlink\n", Myname);

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		for (fi = 0; fi < files; fi++) {
			sprintf(str, "%s%d", fname, fi);
			sprintf(new, "%s%d", sname, fi);
			if (symlink(new, str) < 0) {
				error("can't make symlink %s", str);
				if (errno == EOPNOTSUPP)
					complete();
				else
					exit(1);
			}
                        if (lstat(str, &statb) < 0) {
                                error("can't stat %s after symlink", str);
                                exit(1);
                        }
			if ((statb.st_mode & S_IFMT) != S_IFLNK) {
				error("mode of %s not symlink");
				exit(1);
			}
			if ((ret = readlink(str, buf, MAXPATHLEN))
			     != strlen(new)) {
				error("readlink %s ret %d, expect %d",
					str, ret, strlen(new));
				exit(1);
			}
			if (strncmp(new, buf, ret) != NULL) {
				error("readlink %s returned bad linkname",
					str);
				exit(1);
			}
			if (unlink(str) < 0) {
				error("can't unlink %s", str);
				exit(1);
			}
		}
	}

	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout, "\t%d symlinks and readlinks on %d files",
		files * count * 2, files);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds",
		    time.tv_sec, time.tv_usec / 10000);
	}
	fprintf(stdout, "\n");
#endif S_IFLNK
	complete();
}
				if (dotdot) {
					/* already read dotdot */
					error("'..' dir entry read twice");
					exit(1);
				}
				dotdot++;
				continue;
			}

			/*
			 * at this point, should have entry of the form
			 *  fname%d
			 */
			/* If we don't have our own directory, ignore
			   such errors (if Iflag set). */
			if (strncmp(dp->d_name, fname, Mac-Cthon/test9.c   664    162     12        4050  4542261131   7065 /*	@(#)test9.c	1.3 89/01/10 NFS Rev 2 Testsuite	*/
/*
 * Test statfs
 *
 * Uses the following important system calls against the server:
 *
 *	chdir()
 *	mkdir()		(for initial directory creation if not -m)
 *	statfs()
 */

#include "sys_param.h"
#include "sys_vfs.h"
#include "sys_time.h"
#include "sys_stat.h"
#include "sys_errno.h"
#include <stdio.h>
#include "tests.h"

test9(argc, argv)
	int argc;
	char *argv[];
{
	int count = 1500;	/* times to do statfs call */
	int ct;
	struct timeval time;
	struct statfs sfsb;
	int ret;
	struct stat statb;
	char *opts;

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		usage();
		exit(1);
	}

	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	fprintf(stdout, "%s: statfs\n", Myname);

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		if (statfs(".", &sfsb) < 0) {
			error("can't do statfs on \".\"");
			exit(1);
		}
	}

	if (Tflag) {
		endtime(&time);
	}
#ifdef DEBUG
	fprintf(stdout, "\ttype=%ld, bsize=%ld, blocks=%ld, bfree=%ld\n\
\t  bavail=%ld, files=%ld, ffree=%ld, fsid=%ld %ld\n",
		sfsb.f_type, sfsb.f_bsize, sfsb.f_blocks, sfsb.f_bfree,
		sfsb.f_bavail, sfsb.f_files, sfsb.f_ffree,
#ifdef NFS3_2
		sfsb.f_fsid.val[0], sfsb.f_fsid.val[1]);
#else NFS3_2
		sfsb.f_fsid[0], sfsb.f_fsid[1]);
#endif NFS3_2
#endif DEBUG
	fprintf(stdout, "\t%d statfs calls", count);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds",
		    time.tv_sec, time.tv_usec / 10000);
	}
	fprintf(stdout, "\n");
	complete();
}
f(str, "%s%d", fname, fi);
			sprintf(new, "%s%d", sname, fi);
			if (symlink(new, str) < 0) {
				error("can't make symlink %s", str);
				if (errno == EOPNOTSUPP)
					complete();
				else
					exit(1);
			}
                        if (lstat(str, &statb) < 0) {
                                error("can't stat %s after symlink", str);
                                exit(1);
                        }
			if ((statb.st_mode & S_IFMT) != S_IFLNK) {
				error("mode of %Mac-Cthon/tests.h   664    162     12        1605  4542261133   7171 /*	@(#)tests.h	1.2 89/01/08 NFS Rev 2 Testsuite	*/

/* #define DEBUG */

extern char TESTDIR[];

#define	DNAME	"dir."
#define	FNAME	"file."
#define	DCOUNT	10

extern int DDIRS;
extern int DLEVS;
extern int DFILS;

#define	BUFSZ	8192
extern long DSIZE;

/*
#ifdef DEBUG
#define	DDIRS	1
#define	DLEVS	2
#define	DFILS	1
#else
#define	DDIRS	2
#define	DLEVS	5
#define	DFILS	5
#endif

#ifdef DEBUG
#define	BUFSZ	512
#define	DSIZE	8192
#else
#define	BUFSZ	8192
#define	DSIZE	1048576
#endif
*/

extern int errno;

extern char *Myname;		/* name I was invoked with (for error msgs */


extern int Tflag;		/* print timing */
extern int Hflag;		/* print help message */
extern int Fflag;		/* test function only;  set count to 1, negate -t */
extern int Nflag;		/* Suppress directory operations */
extern int Sflag;		/* don't print non-error messages */
extern int Iflag;		/* Ignore non-test files dir entries */

case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
Mac-Cthon/unix/   775    162     12           0  4542261504   6554 Mac-Cthon/unix/macdir.c   664    162     12       12737  4542261453  10301 #include <HFS.h>
#include "sys_param.h"
#include "tests.h"

extern int trace;

struct {
	char	dir[33];
	} dirs[100];

extract_path(path)
char *path;
{
	ioParam	pb;			/* my parameter block for PB's	*/
	int dcount = 0;
	int vrefnum;
	CInfoPBRec iopb;
	int result;
	long dirid;
	int i;
	WDPBRec gv_iopb;
	char root[33];
	
	extern int default_vrefnum;

	/* get basic info */
	gv_iopb.ioNamePtr = (StringPtr)root;
	result = PBHGetVol(&gv_iopb, FALSE);

    dirid = gv_iopb.ioWDDirID;
	PtoCstr(root);

	if (trace)
		printf("\t[extract_path] vol name '%s', working dirid 0x%lx\n", root, dirid);

	/* pop back up following parent id's */
	while (dirid != 2)
		{
		iopb.hFileInfo.ioVRefNum = default_vrefnum;
		iopb.hFileInfo.ioFDirIndex = -1;
		iopb.hFileInfo.ioDirID = dirid;
		dirs[dcount].dir[0] = '\0';
		iopb.hFileInfo.ioNamePtr = (StringPtr)dirs[dcount].dir;
		result = PBGetCatInfo(&iopb, FALSE);

		PtoCstr(dirs[dcount].dir);
		dirid = iopb.dirInfo.ioDrParID;

		if (trace)
			printf("\t[extract_path] dir '%s', dirid 0x%lx\n",
				dirs[dcount].dir, iopb.dirInfo.ioDrDirID);

		dcount++;
		}

	
	/* build ascii path name */
	path[0] = '\0';
	strcat(path, root);
	strcat(path, ":");

	if (trace) printf("\t[extract_path] root '%s'\n", path);

	for (i = dcount-1; i >= 0; i--)
		{
		if (strlen(dirs[i].dir) > 0)
			{
			strcat(path, dirs[i].dir);
			if (i > 0)
				strcat(path, ":");

			if (trace) 
				printf("\t[extract_path] adding '%s' to make '%s'\n",
					   dirs[i].dir, path);
			}
		}

	return 1;
}

int rmdir_recurse(dir)
char *dir;
{
	char str[MAXPATHLEN], path[MAXPATHLEN];
	long dirid;
	CInfoPBRec iopb;
	int result;
	
	extern StringPtr pnamecpy();
	extern long default_dir_id;
	extern int default_vrefnum;

	if (trace)
		printf("\t[rmdir_recurse] '%s'\n", dir);

#ifdef SYSTEM
	sprintf(str, "rm -r %s", dir);
	return system(str);
#else
	
	/* close default wd #2 */
	{
	WDPBRec cw_iopb;
	
	cw_iopb.ioVRefNum = 0x8013;
	result = PBCloseWD(&cw_iopb, FALSE);
    }

	/* reset default dir */
	{
	WDPBRec cd_iopb;
	
	cd_iopb.ioNamePtr = (StringPtr)0;
	cd_iopb.ioVRefNum = default_vrefnum;
	cd_iopb.ioWDDirID = 2;
	result = PBHSetVol(&cd_iopb, FALSE);

	if (result != noErr)
		merror(result, "rmdir_recurse - PBHSetVol", path);
    }

	unix_to_mac_path(str, dir, TRUE);
	
	/* use name to get dir's dir id */
	iopb.hFileInfo.ioNamePtr = pnamecpy(path, str);
	iopb.hFileInfo.ioVRefNum = default_vrefnum;
	iopb.hFileInfo.ioDirID = default_dir_id;
	
	iopb.hFileInfo.ioFDirIndex = 0;
	result = PBGetCatInfo(&iopb, FALSE);
	
	/* delete the dir's contents recursively */
	rm_recurse_dir(iopb.dirInfo.ioDrDirID);

	/* then, delete the dir */
	PtoCstr((char *)iopb.hFileInfo.ioNamePtr);

	/* place us in parent of dir to delete */
	chdir(iopb.hFileInfo.ioNamePtr);
	chdir("..");

	remove_id(2L, iopb.hFileInfo.ioNamePtr);

#endif

	if (trace)
		printf("\t[rmdir_recurse] done.\n");

	return 0;
}

rm_recurse_dir(dirid)
long dirid;
{
	CInfoPBRec iopb;
	int result;
	char name[33];
	int index;
	
	extern int default_vrefnum;

	if (trace) printf("\t[rm_recurse_dir] dirid 0x%lx\n", dirid);

	/* re-scan dir until it's empty */
	for (index = 1; TRUE;)
		{
		iopb.hFileInfo.ioVRefNum = default_vrefnum;
		iopb.hFileInfo.ioFDirIndex = index;
		iopb.hFileInfo.ioDirID = dirid;
		name[0] = '\0';
		iopb.hFileInfo.ioNamePtr = (StringPtr)name;
		result = PBGetCatInfo(&iopb, FALSE);
	
		if (trace) printf("index %d, PBGetCatInfo result %d\n", index, result);

		if (result != noErr)
			return result;

		PtoCstr(name);

#define ReturnIfError(expr)		if ((result = (expr)) != noErr) return result;

		/* delete if not dir */
		if (iopb.hFileInfo.ioFlAttrib & 0x10)
			{
			if (trace)
				printf("\tdir '%s' (id 0x%lx)...\n",
					   name, iopb.dirInfo.ioDrDirID);
			
			rm_recurse_dir(iopb.dirInfo.ioDrDirID);

			ReturnIfError( remove_id(dirid, name) );
			}
		else
			{
			if (trace) printf("\tfile '%s'...\n", name);

			ReturnIfError( remove_id(dirid, name) );
			}
		}

if (trace) printf("\n\n");
	return noErr;
}

remove_id(dirid, name)
long dirid;
char *name;
{
	HFileParam pb;
	int result;
	
	extern int default_vrefnum;

	CtoPstr(name);
	pb.ioNamePtr	= (StringPtr)name;
	pb.ioVRefNum	= default_vrefnum;
	pb.ioDirID		= dirid;
	pb.ioFVersNum	= 0;
	
	result = PBHDelete(&pb, FALSE);

	PtoCstr(name);
	if (trace || result != noErr)
		printf("\t[remove_id] failed: dirid 0x%lx, name '%s', result %d\n",
				dirid, name, result);

	return result;
}

askfordir(path, pVrefnum)
char *path;
int *pVrefnum;
{
	Point point;
	SFReply reply;
	char name[256];
	
	point.h =
	point.v = 40;

	strcpy(name, "\pTestFile");
	
	SFPutFile(point, "\pTest directory", name, (ProcPtr)0, &reply);
	
	if (!reply.good)
		return FALSE;
	
	/* set default vol and dir */
	{
	WDPBRec cd_iopb;
	int result;

	cd_iopb.ioNamePtr = (StringPtr)0;
	cd_iopb.ioVRefNum = reply.vRefNum;
	cd_iopb.ioWDDirID = 2;
	result = PBHSetVol(&cd_iopb, FALSE);

	if (result != noErr)
		merror(result, "askfordir - PBHSetVol", path);
    }

	/* generate base path */
	{
	WDPBRec gv_iopb;
	int result;

	/* get basic info */
	gv_iopb.ioNamePtr = (StringPtr)path;
	result = PBHGetVol(&gv_iopb, FALSE);
	PtoCstr(path);

	*pVrefnum = gv_iopb.ioVRefNum;
	}

	/* set default vol and dir */
	{
	WDPBRec cd_iopb;
	int result;

	cd_iopb.ioNamePtr = (StringPtr)0;
	cd_iopb.ioVRefNum = *pVrefnum;
	cd_iopb.ioWDDirID = 2;
	result = PBHSetVol(&cd_iopb, FALSE);

	if (result != noErr)
		merror(result, "askfordir - PBHSetVol", path);
    }

if (0)
	strcat(path, "/cayman");

	if (trace)
		printf("\t[askfordir] vrefnum %d, path '%s'\n", *pVrefnum, path);
	return TRUE;
}

Mac-Cthon/unix/macsubr.c   664    162     12        3537  4542261455  10456 
int atoi(s)
register char *s;
{
	register int number = 0, radix = 10, sign = 1;
	register char ch;

	if (*s == '-')
		sign = -1, s++;

	if (*s == '+')
		s++;

	while (ch = *s++)
		{
		ch = toupper(ch);

		if ('0' <= ch && ch <= '9')
			number = (number * radix) + (ch - '0');
		else
		if ( ('A' <= ch && ch <= 'F') && radix == 16 )
			number = (number * radix) + 10 + (ch - 'A');
		else
		if (ch == 'X')
			{ number = 0; radix = 16; }
		else
			break;
		}
	
	return number * sign;
}

int strlen(s)
register char *s;
{
	register int len;
	
	for (len = 0; *s; ++len, ++s);
	return len;
}

char *strcpy(to, from)
register char *to, *from;
{
	while (*to++ = *from++);
	return to;
}

char *strcat(to, from)
register char *to, *from;
{
	to += strlen(to);
	while (*to++ = *from++);
	return to;
}


int strncmp(s1, s2, n)
register char *s1, *s2;
int n;
{
	while (*s1 == *s2 && *s1 != '\0')
		{
		if (--n == 0)
			return 0;
			
		++s1, ++s2;
		}

	return *s1 - *s2;
}

int strcmp(s1, s2)
register char *s1, *s2;
{
	while (*s1 == *s2 && *s1 != '\0')
		++s1, ++s2;
	
	return *s1 - *s2;
}

exit(code)
int code;
{
	if (0)
		printf("\t[exit]");

	if (code != 0)
		ExitToShell();
}

char *getenv(word)
char *word;
{
	return (char *)0;
}

perror(s)
char *s;
{
if (0)	printf("\t[perror] %s\n", s);
}

setbuf()
{
	return 0;
}

system(string)
char *string;
{
	printf("\t[system] %s\n", string);
	return 0;
}

bcopy(from, to, size)
register char *from, *to;
register int size;
{
	while (size--)
		{
		*to = *from;
		++to, ++from;
		}
}

bclear(to, size)
register char *to;
register int size;
{
	while (size--)
		{ *to = '\0'; ++to; }
}


ctopcpy(to, from)
register char *to, *from;
{
	register char *plen = to++;
	
	*plen = 0;
	while (*to++ = *from++)
		(*plen)++;
}

pstrcpy(to, from)
register char *to, *from;
{
	register int size = *from + 1;
	
	while (size--)
		{
		*to = *from;
		++to, ++from;
		}
}

ec cw_iopb;
	
	cw_iopb.ioVRefNum = 0x8013;
	result = PBCloseWD(&cw_iopb, FALSE);
    }

	/* reset default dir */
	{
	WDPBRec cd_iopb;
	
	cd_iopb.ioNamePtr = (StrMac-Cthon/unix/sys_dir.h   664    162     12         402  4542261457  10451 #define u_char unsigned char

struct direct {
	char d_name[256];	
};

typedef struct {
	long dir_id;
	int dir_index;
	struct direct dir_entry;
} DIR;

DIR *opendir();
struct direct *readdir();

#define NO_DIR	((DIR *)0)
#define NO_ENTRY ((struct direct *)0)

unixtime.ct��unix_stdopen.c <= ch && ch <= 'F') && radix == 16 )
			number = (number * radix) + 10 + (ch - 'A');
		else
		if (ch == 'X')
			{ number = 0; radix = 16; }
		else
			break;
		}
	
	return number * sign;
}

int strlen(s)
register charMac-Cthon/unix/sys_errno.h   664    162     12           1  4542261461  10746 
�u.r��..�vmacdir.ct-0�w	macsubr.cle�x	sys_dir.h�ysys_errno.h�zsys_param.h�{
sys_stat.h�|
sys_time.h
�}	sys_vfs.h�~	unixdir.cmp�unixfileio.c���
unixreaddir.c��
unixtime.ct��unix_stdopen.c <= ch && ch <= 'F') && radix == 16 )
			number = (number * radix) + 10 + (ch - 'A');
		else
		if (ch == 'X')
			{ number = 0; radix = 16; }
		else
			break;
		}
	
	return number * sign;
}

int strlen(s)
register charMac-Cthon/unix/sys_param.h   664    162     12          46  4542261464  10755 #define major

#define MAXPATHLEN	255
.ct-0�w	macsubr.cle�x	sys_dir.h�ysys_errno.h�zsys_param.h�{
sys_stat.h�|
sys_time.h
�}	sys_vfs.h�~	unixdir.cmp�unixfileio.c���
unixreaddir.c��
unixtime.ct��unix_stdopen.c <= ch && ch <= 'F') && radix == 16 )
			number = (number * radix) + 10 + (ch - 'A');
		else
		if (ch == 'X')
			{ number = 0; radix = 16; }
		else
			break;
		}
	
	return number * sign;
}

int strlen(s)
register charMac-Cthon/unix/sys_stat.h   664    162     12         106  4542261466  10647 struct stat {
	int st_mode;
	int st_nlink;
	unsigned long st_size;
};
	sys_dir.h�ysys_errno.h�zsys_param.h�{
sys_stat.h�|
sys_time.h
�}	sys_vfs.h�~	unixdir.cmp�unixfileio.c���
unixreaddir.c��
unixtime.ct��unix_stdopen.c <= ch && ch <= 'F') && radix == 16 )
			number = (number * radix) + 10 + (ch - 'A');
		else
		if (ch == 'X')
			{ number = 0; radix = 16; }
		else
			break;
		}
	
	return number * sign;
}

int strlen(s)
register charMac-Cthon/unix/sys_time.h   664    162     12          63  4542261470  10607 struct timeval {
unsigned long tv_sec, tv_usec;
};
	macsubr.cle�x	sys_dir.h�ysys_errno.h�zsys_param.h�{
sys_stat.h�|
sys_time.h
�}	sys_vfs.h�~	unixdir.cmp�unixfileio.c���
unixreaddir.c��
unixtime.ct��unix_stdopen.c <= ch && ch <= 'F') && radix == 16 )
			number = (number * radix) + 10 + (ch - 'A');
		else
		if (ch == 'X')
			{ number = 0; radix = 16; }
		else
			break;
		}
	
	return number * sign;
}

int strlen(s)
register charMac-Cthon/unix/sys_vfs.h   664    162     12         270  4542261472  10471 struct statfs {
	long f_type, f_bsize, f_blocks, f_bfree;
	long f_bavail, f_files, f_ffree;
#ifdef NFS3_2
	struct {
		long val;
		} f_fsid[2];
#else NFS3_2
	long f_fsid[2];
#endif
};

�~	unixdir.cmp�unixfileio.c���
unixreaddir.c��
unixtime.ct��unix_stdopen.c <= ch && ch <= 'F') && radix == 16 )
			number = (number * radix) + 10 + (ch - 'A');
		else
		if (ch == 'X')
			{ number = 0; radix = 16; }
		else
			break;
		}
	
	return number * sign;
}

int strlen(s)
register charMac-Cthon/unix/unixdir.c   664    162     12       15755  4542261474  10532 #include <HFS.h>
#include "sys_stat.h"
#include "sys_vfs.h"
#include <stdio.h>

/* #define NOCWD */

char working_dir[1024] = '\0';
int default_vrefnum = 0;
unsigned long default_dir_id = 0;
int default_umask = 0;

extern int trace;

merror(result, where, what)
int result;
char *where;
char *what;
{
	char path[1024];
	
	extract_path(path);
	printf("**Mac I/O Error** result %d, in '%s', on '%s' (%s)\n",
		result, where, what, path);
	
	printf("                  default_vrefnum %d, default_dir_id 0x%lx\n",
		default_vrefnum, default_dir_id);
		
if (1)
	exit(-1);
}

StringPtr pname(cname)
char *cname;
{
	static char name[256];
	
	strcpy(name, cname);
	CtoPstr(name);
	return (StringPtr)name;
}

StringPtr pnamecpy(pname, cname)
StringPtr pname;
char *cname;
{	
	strcpy(pname, cname);
	CtoPstr((char *)pname);
	return pname;
}

statfs(path, pstat)
char *path;
struct statfs *pstat;
{
	HParamBlockRec iopb;
	
	iopb.volumeParam.ioNamePtr = (StringPtr)0;
	iopb.volumeParam.ioVRefNum = default_vrefnum;
	iopb.volumeParam.ioVolIndex = 0;
	PBHGetVInfo(&iopb, FALSE);
	
	pstat->f_type = 0;
	pstat->f_bsize = (unsigned)iopb.volumeParam.ioVAlBlkSiz;
	pstat->f_blocks = (unsigned)iopb.volumeParam.ioVNmAlBlks;
	pstat->f_bfree = (unsigned)iopb.volumeParam.ioVFrBlk;
	pstat->f_bavail = (unsigned)iopb.volumeParam.ioVFrBlk;
	pstat->f_files = (unsigned)iopb.volumeParam.ioVFilCnt;
	pstat->f_ffree = 0;

#ifdef NFS3_2
	pstat->f_fsid[0].val = iopb.volumeParam.ioVFSID;
	pstat->f_fsid[1].val = 0;
#else NFS3_2
	pstat->f_fsid[0] = iopb.volumeParam.ioVFSID;
	pstat->f_fsid[1] = 0;
#endif

	return 0;
};

fstat(fd, pstat)
int fd;
struct stat *pstat;
{
	register int		free_slot;

	/* look thru FILE array for slots in use	*/
	for (free_slot=STDERRNO+1;
		((free_slot<_NFILE));
		free_slot++)
		if (_file[free_slot].InUse && _file[free_slot].fileno == fd)
			{
			pstat->st_mode = 0;
			pstat->st_nlink = 1;
			pstat->st_size = 0;

			return 0;
			}
	
	return -1;
}

link(from, to)
char *from, *to;
{
	printf("\t[link] '%s' to '%s'\n", from, to);
}


umask(mask)
int mask;
{
	default_umask = mask;
}

int last_mode;

chmod(name, mode)
char *name;
int mode;
{
	last_mode = mode;
}

stat(name, pstat)
char *name;
struct stat *pstat;
{
	char path[256];
	CInfoPBRec iopb;
	int result;
	
	if (trace) printf("\t[stat] %s\n", name);
	unix_to_mac_path(path, name, TRUE);

	iopb.hFileInfo.ioNamePtr = pname(path);
	iopb.hFileInfo.ioVRefNum = default_vrefnum;
	iopb.hFileInfo.ioDirID = default_dir_id;
	
	iopb.hFileInfo.ioFDirIndex = 0;
	result = PBGetCatInfo(&iopb, FALSE);

	if (result == dirNFErr || result == fnfErr)
		return result;

	if (result != noErr)
		merror(result, "mkdir", path);

	pstat->st_mode = last_mode;
	pstat->st_nlink = 1;
	pstat->st_size = iopb.hFileInfo.ioFlLgLen;
	
	return 0;
}

mkdir(name, mode)
char *name;
int mode;
{
	char path[256];
	HParamBlockRec iopb;
	int result;

	if (trace) printf("\t[mkdir] %s, mode %o\n", name, mode);
	unix_to_mac_path(path, name, TRUE);

	iopb.ioParam.ioNamePtr = pname(path);
	iopb.ioParam.ioVRefNum = default_vrefnum;
	iopb.fileParam.ioDirID = default_dir_id;
	result = PBDirCreate(&iopb, FALSE);

	if (result != noErr)
		merror(result, "mkdir", path);
}

rmdir(name)
char *name;
{
	char path[256];
	HParamBlockRec iopb;
	int result;

	if (trace) printf("\t[rmdir] %s\n", name);
	unix_to_mac_path(path, name, TRUE);

	/* close default wd #2 */
	{
	WDPBRec cw_iopb;
	
	cw_iopb.ioVRefNum = 0x8013;
	result = PBCloseWD(&cw_iopb, FALSE);
    }

	/* reset default dir */
	{
	WDPBRec cd_iopb;
	
	cd_iopb.ioNamePtr = (StringPtr)0;
	cd_iopb.ioVRefNum = default_vrefnum;
	cd_iopb.ioWDDirID = default_dir_id;
	result = PBHSetVol(&cd_iopb, FALSE);

	if (result != noErr)
		merror(result, "rmdir - PBHSetVol", path);
    }

	iopb.ioParam.ioNamePtr = pname(path);
	iopb.ioParam.ioVRefNum = default_vrefnum;
	iopb.fileParam.ioDirID = default_dir_id;
	result = PBHDelete(&iopb, FALSE);

	if (result != noErr)
		merror(result, "rmdir", path);

	if (trace) printf("\t[rmdir] ok\n");
	return 0;
}

chdir(new)
char *new;
{
	char path[256];
	CInfoPBRec iopb;
	int result;
		
	unix_to_mac_path(path, new, FALSE);
	
#ifdef NOCWD
	if (path[0] != ':' && working_dir[ strlen(working_dir)-1 ] != ':')
		strcat(working_dir, ":");

	strcat(working_dir, path);
#endif

#ifdef NODOTDOT
	if (strcmp(path, "..") == 0)
		{
		iopb.hFileInfo.ioNamePtr = (StringPtr)0;
		iopb.hFileInfo.ioVRefNum = default_vrefnum;
		iopb.hFileInfo.ioDirID = default_dir_id;
		
		iopb.hFileInfo.ioFDirIndex = 0;
		result = PBGetCatInfo(&iopb, FALSE);
			
		{
		WDPBRec cd_iopb;
		
		cd_iopb.ioNamePtr = (StringPtr)0;
		cd_iopb.ioVRefNum = default_vrefnum;
		default_dir_id = cd_iopb.ioWDDirID = iopb.dirInfo.ioDrParID;
		result = PBHSetVol(&cd_iopb, FALSE);
	
		if (result != noErr)
			merror(result, "chdir - nodots PBHSetVol", path);
	    }			

		return 0;
		}
#endif

	iopb.hFileInfo.ioNamePtr = pname(path);
	iopb.hFileInfo.ioVRefNum = default_vrefnum;
	iopb.hFileInfo.ioDirID = default_dir_id;
	
	iopb.hFileInfo.ioFDirIndex = 0;
	result = PBGetCatInfo(&iopb, FALSE);

	if (result == dirNFErr || result == fnfErr)
		{
		if (trace) printf("\t[chdir] to '%s' failed\n", path);
		return result;
		}
		
	if (result != noErr)
		merror(result, "chdir - PBGetCatInfo", path);

	default_dir_id = iopb.hFileInfo.ioDirID;

	{
	WDPBRec cd_iopb;
	
	cd_iopb.ioNamePtr = (StringPtr)0;
	cd_iopb.ioVRefNum = default_vrefnum;
	cd_iopb.ioWDDirID = default_dir_id;
	result = PBHSetVol(&cd_iopb, FALSE);

	if (result != noErr)
		merror(result, "chdir - PBHSetVol", path);
    }
   
	if (trace)
		printf("\t[chdir] to '%s', dirID 0x%lx\n", path, default_dir_id);

	{
	WDPBRec cd_iopb;
	char path2[256];
	
	extract_path(path2);

	if (trace)
		printf("\t[chdir] trying hsetvol with path '%s'\n", path2);

	CtoPstr(path2);
	cd_iopb.ioNamePtr = (StringPtr)path2;
	cd_iopb.ioVRefNum = default_vrefnum;
	cd_iopb.ioWDDirID = 0 /* 2 */;
	result = PBHSetVol(&cd_iopb, FALSE);

	if (result != noErr)
		{
		PtoCstr(path2);
		merror(result, "chdir - PBHSetVol", path2);
		}
    }
   
	return 0;
}

char *getwd(name)
char *name;
{
	extract_path(working_dir);
	mac_to_unix_path(name, working_dir);
	if (trace) printf("\t[getwd] %s\n", name);
	return name;
}

unix_to_mac_path(new, old, add_default)
register char *new, *old;
int add_default;
{
	register char ch;
	char *result = new;
	int pos = 0;

#ifdef NOCWD
	if (add_default)
		{
		strcpy(new, working_dir);
		new += strlen(working_dir);
		if (working_dir[0])
			*new++ = ':';
		}
#endif

	if (strcmp(old, ".") == 0)
		{
		extract_path(new);
		}
	else
	if (strcmp(old, "..") == 0)
		{
		strcpy(new, "::");
		return;
		}
	else
		{	
		while (ch = *old++)
			{
			if (ch == '/' && pos > 0) ch = ':';
			*new++ = ch;
			pos++;
			}
	
		*new = '\0';
		}

	if (trace > 1) printf("\t[unix_to_mac_path] '%s'\n", result);
}

mac_to_unix_path(new, old)
register char *new, *old;
{
	register char ch;
	char *result = new;
	
	if (strcmp(old, "::") == 0)
		{
		strcpy(new, "..");
		}
	else
		{
		while (ch = *old++)
			{
			if (ch == ':') ch = '/';
			*new++ = ch;
			}
		
		*new = '\0';
		}

	if (trace > 1) printf("\t[mac_to_unix_path] '%s'\n", result);
}
Mac-Cthon/unix/unixfileio.c   664    162     12       12547  4542261476  11221 /*	(C) Copyright 1986. THINK Technologies, Inc.  All rights reserved. */	

/* This module translates UNIX I/O style calls to STDIO calls */

#ifndef	_stdioh_
#include	"stdio.h"
#endif

#ifndef	_ctypeh_
#include	"ctype.h"
#endif

#ifndef	_unixh_
#include "unix.h"
#endif

#ifndef	_FileMgr_
#include "FileMgr.h"
#endif

FILE	*unix_fopen();		/* open a file */

Boolean _unix_file_exists(filename)
char *filename;
{
	FILE *who;
	fileParam pb2;
	
			CtoPstr(filename);
			
			pb2.ioFDirIndex = 0;
			pb2.ioNamePtr	= (StringPtr)filename;
			pb2.ioVRefNum	= 0;
			pb2.ioFVersNum	= 0;
			
			if (PBGetFInfo(&pb2,false) == fnfErr)
			{
				PtoCstr(filename); 
				return(false);
			}
 			PtoCstr(filename); 
			return(true);
}


static char *cvtmode(mode,filename)
register int mode;
char *filename;
{
register int i=0;
static char stdmode[5];

	if ((mode & O_EXCL) && (mode & O_CREAT))
		if (_unix_file_exists(filename))
		{
			errno = EEXIST;
			return(NULL);
		}

	switch (mode & (O_RDONLY | O_WRONLY | O_RDWR))
	{
		case O_RDONLY:
			if (mode & O_APPEND)
			{
				errno = EINVAL;
				return (NULL);
			}
			
			if (mode & O_TRUNC)
			{
				stdmode[i++] = 'w';
				stdmode[i++] = '+';
			}
			else
				stdmode[i++] = 'r';
			break;
				
		case O_WRONLY:
			if (mode & O_APPEND)
			{
				if (mode & O_TRUNC)
					stdmode[i++] = 'w';
				else
					stdmode[i++] = 'a';
			}
			else
				stdmode[i++] = 'w';
			break;
				
		case O_RDWR:
nonstdmode:
			if ((mode & O_CREAT) || (mode & O_TRUNC))
				stdmode[i++] = 'w';
			else
			if (mode & O_APPEND)
				stdmode[i++] = 'a';
			else
				stdmode[i++] = 'r';
			
			stdmode[i++] = '+';
			break;
			
		default:
			/* if no mode was selected, append is a legal mode in this
				implementation and is treated as RDWR append */
				
			if (mode & O_APPEND) goto nonstdmode;
				
			errno = EINVAL;
			return (NULL);			
	}

	if (mode & O_BINARY)
		stdmode[i++] = 'b';
		
	stdmode[i++] = '\0';
	
	return (stdmode);
}

static int invalidfildes(fildes)
register int fildes;
{
	if ((fildes >= _NFILE) || (!_file[fildes].InUse))
	{
		errno = EBADF;
		return (1);
	}
	
	return (0);
}	

/* searches thru the file descriptors for a free file
   and returns the file position of a free file. */

static int findfreefileref()
{
register int i;

	for (i=0; i<_NFILE; i++)
		if (! _file[i].InUse)
			return i;

	return (-1);
}

int fread();
int fwrite();

static unsigned int fileop(fildes, buffer, nbytes, op)
register int fildes;
char *buffer;
unsigned nbytes;
unsigned int (*op)();
{
unsigned int actcount;
extern Boolean _unsignedbytes;

	if (invalidfildes(fildes))
		return (-1);

	_unsignedbytes = true;	/* one-shot flag for unsigned nbytes */
	
	if (actcount = (*op)(buffer, sizeof(*buffer), nbytes, &_file[fildes]))
		return (actcount);
	
	/* pdg - 6/10/86 - supposed to return zero on eof, not error! */
	
	if (_file[fildes].last_error == eofErr)
		return (0);
		
	errno = EIO;
	return (-1);
}

#line 0 fileno

int	fileno(who)
register FILE *who;
{
	if ((!who)||(!who->InUse))
		return(-1);
		
	return(who->fileno);
}

#line 0 open

int open(filename, mode)
char *filename;
int mode;
{
char *type;
FILE *who;

	if (findfreefileref() == -1)
	{
		errno = EMFILE;
		return(-1);
	}
	
	if ((type = cvtmode(mode,filename)) == NULL)
		return(-1);
		
	if ((who = unix_fopen(filename, type))==NULL)
	{
		errno = errno == fnfErr ? ENOENT : EACCES;
		return(-1);
	}
		return (who->fileno);
}

#line 0 close

int close(fildes)
register int fildes;
{
	if (invalidfildes(fildes))
		return (-1);
	
	return (fclose(&_file[fildes]));
}


#line 0 read

int read(fildes, buffer, nbytes)
int fildes;
char *buffer;
unsigned nbytes;
{
	return (fileop(fildes, buffer, nbytes, fread));
}

#line 0 write

int write(fildes, buffer, nbytes)
int fildes;
char *buffer;
unsigned nbytes;
{
	return (fileop(fildes, buffer, nbytes, fwrite));
}

#line 0 lseek

long lseek(fildes, offset, offsetmode)
register int fildes;
long int offset;
register unsigned int offsetmode;
{
	if (invalidfildes(fildes))
		return (-1L);
	
	if (offsetmode>2)
	{
		errno = EINVAL;
		return(-1L);
	}
	
	if (fseek(&_file[fildes], offset, offsetmode))
	{
		errno = EIO;
		return (-1L);
	}
	
	return (ftell(&_file[fildes]));
}

/*
		This is an old Unix seek which returns an int instead of a long and
		is commented out unless you really want to bother uncommenting it!

#line 0 seek

int seek(fildes, offset, origin)
int fildes;
register int offset;
int origin;
{
long longoffset;
int neworigin;
	
	longoffset = ((neworigin = origin % 3) == origin) ? offset : (long)offset*512;

	return ((int) lseek(fildes, longoffset, neworigin));
}
*/

#line 0 tell

long tell(fildes)
int fildes;
{
	return (ftell(&_file[fildes]));
}

#line 0 rename

int	rename(old,new)
char *old,*new;
{
ioParam pb;
	
	CtoPstr(old);
	CtoPstr(new);
	pb.ioNamePtr	= (StringPtr)old;
	pb.ioVRefNum	= 0;
	pb.ioVersNum	= 0;
	pb.ioMisc		= new; 
	
	if (PBRename(&pb,false))
	{
		errno = EIO;
		PtoCstr(old);
		PtoCstr(new);
		return(-1);
	}
	
		PtoCstr(old);
		PtoCstr(new);
		
	return(0);
}

#line 0 remove

int	remove(name)
char *name;
{
	ioParam pb;
	
	CtoPstr(name);
	pb.ioNamePtr	= (StringPtr)name;
	pb.ioVRefNum	= 0;
	pb.ioVersNum	= 0;
	
	if (PBDelete(&pb,false))
	{
		errno = EIO;
		PtoCstr(name);
		return(-1);
	}
	PtoCstr(name);
	return(0);
}

#line 0 unlink

int	unlink(name)
char *name;
{
	return(remove(name));
}

#line 0 creat

int creat(filename, mode)
char *filename;
int mode;
{
	return (open(filename, mode | O_CREAT));
}		 


lt != noErr)
		merror(result, "chdir - PBHSetVol", path);
    }
   
	if (trace)
		printf("\t[chdir] to '%s', dirID 0x%lx\n", path, default_dir_id);

	{
	Mac-Cthon/unix/unixreaddir.c   664    162     12        3122  4542261500  11315 #include "sys_param.h"
#ifndef major
#include "sys_types.h"
#endif
#include "sys_time.h"
#include "sys_dir.h"
#include <stdio.h>
#include <HFS.h>

extern int trace;

DIR *opendir(root)
char *root;
{
	char path[256];
	CInfoPBRec iopb;
	static DIR thedir;
	DIR *dir;
	int result;

	extern StringPtr pname();
	extern int default_vrefnum;
	extern long default_dir_id;
	
	unix_to_mac_path(path, root, FALSE);
	
	iopb.hFileInfo.ioNamePtr = pname(path);
	iopb.hFileInfo.ioVRefNum = default_vrefnum;
	iopb.hFileInfo.ioDirID = default_dir_id;
	
	iopb.hFileInfo.ioFDirIndex = 0;
	result = PBGetCatInfo(&iopb, FALSE);

	if (result == dirNFErr || result == fnfErr)
		return NO_DIR;

	if (result != noErr)
		merror(result, "opendir - PBGetCatInfo", path);

	dir = &thedir;
	dir->dir_index = 0;
	dir->dir_id = iopb.hFileInfo.ioDirID;

	if (trace)
		printf("\t[opendir] for '%s', dirID 0x%lx\n", path, default_dir_id);

	return dir;
}

closedir(dir)
DIR *dir;
{
}

rewinddir(dir)
DIR *dir;
{
	dir->dir_index = 0;
}

struct direct *readdir(dir)
DIR *dir;
{
	struct direct *entry = &dir->dir_entry;
	int result;
	CInfoPBRec iopb;
	char name[256];
	
	name[0] = '\0';
	iopb.hFileInfo.ioNamePtr = (StringPtr)name;
	iopb.hFileInfo.ioVRefNum = default_vrefnum;
	iopb.hFileInfo.ioFDirIndex = ++(dir->dir_index);
	iopb.hFileInfo.ioDirID = dir->dir_id;

	result = PBGetCatInfo(&iopb, FALSE);
	if (trace)
		printf("\t[readdir] index %d, result %d\n", dir->dir_index, result);

	if (result == fnfErr)
		return NO_ENTRY;

	PtoCstr(name);
	strcpy(entry->d_name, name);

	if (trace)
		printf("\t[readdir] returns '%s'\n", name);
	return entry;
}


ime.h"
#include "sys_dir.h"
#include <stdio.h>
#include <HFS.h>

extern int trace;

DIR *opendir(root)
char *root;
{
	char path[256];
	CInfoPBRec iopb;
	static DIR thedir;
	DIR *dir;
	int result;

	extern StringPtr pname();
	extern int default_vrefnum;
	extern long default_dir_id;
	
	unix_to_mac_path(path, root, FALSE);
	
	iopb.hFileInfo.ioNamePtr = pname(path);
	iopb.hFileInfo.ioVRefNum = default_vrefnum;
	iopb.hFileInfo.ioDiMac-Cthon/unix/unixtime.c   664    162     12        3700  4542261502  10645 #include "sys_time.h"

/* The Macintosh keeps a raw seconds count that begins at
	00:00:00 January 1, 1904 local time,
	UNIX uses 00:00:00 January 1, 1970 GMT */

/* seconds difference between EST & GMT time zones */
#define GMTzonedif	(5*60*60)

#define	TMacbaseyr	1904
#define	TUNIXbaseyr	1970

/* number of leap days between the two years -- Mac base was a leap year! */
#define	TLpD	((TUNIXbaseyr-TMacbaseyr-1)/4)

/* TimeBaseDif is the number of seconds between Mac and UNIX time (GMT) */
#define TimeBaseDif	((((TUNIXbaseyr-TMacbaseyr)*365)+TLpD)*24*60*60)

/* global variables for time computations */

long timezone = 0 /*GMTzonedif*/;	/* difference between GMT & local time */

int daylight = 0;			/* daylight savings time flag */

char *tzname[2] = {"EST", "EDT"};	/* names of time zones */

#line 0 time

/* This routine returns the time since Jan 1, 1970 00:00:00 GMT */

unsigned long time(clock)
unsigned long *clock;
{
	unsigned long GMTtimenow = Time-TimeBaseDif+timezone;

	if (clock)
		*clock = GMTtimenow;
		
	return (GMTtimenow);
}

gettimeofday(ptime, ptz)
struct timeval *ptime;
long *ptz;
{
	unsigned long t, ticks;
	
	time(&t);

	ticks = Ticks;
	ptime->tv_sec = ticks / 16;
	ptime->tv_usec = (ticks % 16) * (1000000L/16);
	return 0;
}

char *ctime(clock)
register unsigned long *clock;
{
static char timebuffer[26];
register char *tp;
DateTimeRec MacTimeRec;
register Intl1Hndl myHndl;
register int i;	

	Secs2Date((clock?(*clock+TimeBaseDif):(Time+timezone)),&MacTimeRec);
	
	myHndl = (Intl1Hndl)IUGetIntl(1);
	tp = timebuffer;
	
	for (i=1; i<4; i++)
		*tp++ = (*myHndl)->days[MacTimeRec.dayOfWeek-1][i]; /* make day of week */
	*tp++ = ' ';

	for (i=1; i<4; i++)
		*tp++ = (*myHndl)->months[MacTimeRec.month-1][i]; /* make month */
	*tp++ = ' ';

	sprintf(tp,"%02d ",MacTimeRec.day); /* now put in day of month */
	tp += 3;
	
	sprintf(tp,"%02d:%02d:%02d %d\n",
		MacTimeRec.hour,MacTimeRec.minute,MacTimeRec.second,MacTimeRec.year);

	return(timebuffer);
}

egister int fildes;
{
	if ((fildes >= _NFILE) || (!_file[fildes]Mac-Cthon/unix/unix_stdopen.c   664    162     12       11502  4542261504  11543 /*
	Routines for LightspeedC

	(C) Copyright 1985, 1986. THINK Technologies, Inc.  All rights reserved.
*/
 
#ifndef _stdioh_
#include "stdio.h"
#endif

#ifndef _FileMgr_
#include "FileMgr.h"
#endif

#ifndef	_SerialDvr_
#include "SerialDvr.h"
#endif

void _exit_closeall();

/*	This file contains the code for fopen, fclose, _closeall, freopen.	*/

#line 0 xfopen
static FILE	*unix_xfopen(nameptr,type,who)
char	*nameptr;
register char	*type;
register FILE	*who;

{
register int		new;
static	Boolean		_init_onexit = false;	/* flag to signal onexit was initalized */

	ioParam	pb;			/* my parameter block for PB's	*/
	fileParam pb2;
	register int err;
	int	refnum;
	Boolean	create;
	Boolean	add;
	register Boolean	delete;
	register Boolean bin_file;
	register Ptr	p;

	if(!who)
		{
		register int		free_slot;
		/* look thru FILE array for an open slot	*/
		for (free_slot=STDERRNO+1;
			((free_slot<_NFILE)&&(_file[free_slot].InUse));
			free_slot++)
			;

		if (free_slot >= _NFILE) {
			errno = tmfoErr;	/* too many files open	*/
			return (NULL);
		}

		who = &_file[free_slot];
	}

{
	register int		permission;

	permission = fsWrPerm;		/* default = write	*/
	create = delete = true;		/* default is true	*/
	bin_file = add = false;
	refnum = 0;

	if (type[1]=='\0')
	{
		if (type[0] == 'r') permission = fsRdPerm;
	}
	else
		if (type[1] == '+')
		{
			permission = fsRdWrPerm;
			if (type[2] == 'b') bin_file = true;
		}
		else
		{
			if (type[1] == 'b') bin_file = true;
		
			if (type[0] == 'r') permission = fsRdPerm;
			
		}

/* force these files to be binary */
bin_file = true;	

	switch (type[0])
	{
		case 'r':
					create = false;
					break;
		case 'w':
					delete = true;
					break;
		case 'a':
					add = true;
					break;
		default:
					return(NULL);
	}


	CtoPstr(nameptr);

	p = NewPtr((long)BUFSIZ);

	do	{
	
		/* pdg 7/29/86 - look only via default path */

		pb.ioNamePtr	= 0;
/*		if (PBGetVol(&pb, false)) */ pb.ioVRefNum	= 0;


		pb.ioNamePtr	= (StringPtr)nameptr;
		pb.ioVersNum	= 0;
		pb.ioPermssn	= permission;
		pb.ioMisc		= 0L;

		new = PBOpen(&pb,false);
		
		if ((new == fnfErr) && (create))
			{
			if (err = (PBCreate(&pb,false))) goto err_exit;

			pb2.ioFDirIndex = 0;
			pb2.ioNamePtr	= pb.ioNamePtr;
			pb2.ioVRefNum	= pb.ioVRefNum;
			pb2.ioFVersNum	= pb.ioVersNum;
			if (err = (PBGetFInfo(&pb2,false))) goto err_exit;

			pb2.ioFlFndrInfo.fdType		= 'TEXT';
			pb2.ioFlFndrInfo.fdCreator	= '????';
			if (err = (PBSetFInfo(&pb2,false))) goto err_exit;

			delete = false;	/* don't delete this file	*/
		}

		if (!new)
		{	/* no errors on open  */
			if (pb.ioRefNum > 0)
			{	/* don't do this stuff if a device driver */
			
				if (type[0]=='a')
				{
					if(err = (PBGetEOF(&pb,false))) goto err_exit;
	
					pb.ioPosOffset = (long)pb.ioMisc;
					pb.ioPosMode = fsFromStart;
					err = PBSetFPos(&pb,false);
					if ((err!=noErr) && (err!=eofErr)) goto err_exit;
				}
				
				if ((type[0]=='w') && (delete))
				{
					pb2.ioFDirIndex = 0;
					pb2.ioNamePtr	= pb.ioNamePtr;
					pb2.ioVRefNum	= pb.ioVRefNum;
					pb2.ioFVersNum	= pb.ioVersNum;
					if (err = (PBGetFInfo(&pb2,false))) goto err_exit;
	
					if (err = (PBClose(&pb,false))) goto err_exit;
	
					if (err = (PBDelete(&pb,false))) goto err_exit;
	
					if (err = (PBCreate(&pb,false))) goto err_exit;
	
					if (err = (PBSetFInfo(&pb2,false))) goto err_exit;
	
					new = PBOpen(&pb,false);
					create = false;
				}
			}
			
			if (!new)
			{
				refnum = pb.ioRefNum;
				who->refnum		= refnum;
				who->last_error	= noErr;
				who->user_buf	= false;
				who->StdStream	= false;
				who->filebuf	= p;
				who->InUse		= true;
				who->mod		= false;
				who->look_full	= false;
				who->rd			= false;
				who->wr			= false;
				who->window		= false;
				if((permission==fsRdWrPerm)||(permission==fsRdPerm))
					who->rd		= true;
				if((permission==fsRdWrPerm)||(permission==fsWrPerm))
					who->wr		= true;
				who->binary		= bin_file;
				who->fpos		= BUFSIZ+10;	/* force fread/fwrite to go to disk */
				who->inbuf		= 0;
				PtoCstr(nameptr);
				if (_init_onexit == false)
				{
					_init_onexit = true;
					onexit(_exit_closeall);
				}

				if ((who->rd)&&(who->wr))
					{
					if(err = read_into_buffer(who))
						if (err != eofErr)
							{
							who->last_error = errno = err;
							return(who);
						}
				}
				return(who);
			}
		}
	}
	while ((new == fnfErr) && (create));
	
	if (new) errno = new;
	
	goto exit_noset;
	
err_exit:
	errno = err;
	
exit_noset:

	DisposPtr(p);
	PtoCstr(nameptr);
	return(NULL);
} /* end of scope of permission */

}




#line 0 fopen
FILE	*unix_fopen(nameptr,type)
	char	*nameptr,*type;
{
	return(unix_xfopen(nameptr,type,NULL));
	
	(void) std_ver();

}



#line 0 freopen
FILE	*unix_freopen(nameptr,type,who)
	char	*nameptr,*type;
	FILE	*who;

{
	if(fclose(who)) return(NULL);
	return(unix_xfopen(nameptr,type,who));
}

static
void _exit_closeall()
{
	_closeall();
}e, _closeall, freopen.	*/

#line 0 xfopen
static FILE	*unix_xfopen(nameptr,type,who)
char	*nameptr;
register char	*type;
register FILE	*who;

{
register int		new;
static	Boolean		_init_onexif	((((TUNIXbaseyr-TMacbaseyr)*365)+TLpD)*24*60*60)

/* global variables for time computations */

long timezone = 0 /*GMTzonedif*/;	/* difference between GMT & local time */

int daylight = 0;			/* daylight savings time flag */

char *tzname[2] = {"EST", "EDT"};	/* names of time zones */

#line 0 time

/* This routine returns the time since Jan 1, 1970 00:00:00 GMT */

unsigned long time(clock)
unsigned long *clock;
{
	unsigned long GMTtimenow = Time-TimeBaseDif+timezone;

	if (clock)
		*clock = GMTtimenow;
		
	return (GMTtimenow);
}

gettimeofday(ptime, ptz)
struct timeval *ptime;
long *ptz;
{
	unsigned long t, ticks;
	
	time(&t);

	ticks = Ticks;
	ptime->tv_sec = ticks / 16;
	ptime->tv_usec = (ticks % 16) * (1000000L/16);
	return 0;
}

char *ctime(clock)
register unsigned long *clock;
{
static char timebuffer[26];
register char *tp;
DateTimeRec MacTimeRec;
register Intl1Hndl myHndl;
register int i;	

	Secs2Date((clock?(*clock+TimeBaseDif):(Time+timezone)),&MacTimeRec);
	
	myHndl = (Intl1Hndl)IUGetIntl(1);
	tp = timebuffer;
	
	for (i=1; i<4; i++)
		*tp++ = (*myHndl)->days[MacTimeRec.dayOfWeek-1][i]; /* make day of week */
	*tp++ = ' ';

	for (i=1; i<4; i++)
		*tp++ = (*myHndl)->months[MacTimeRec.month-1][i]; /* make month */
	*tp++ = ' ';

	sprintf(tp,"%02d ",MacTimeRec.day); /* now put in day of month */
	tp += 3;
	
	sprintf(tp,"%02d:%02d:%02d %d\n",
		MacTimeRec.hour,MacTimeRec.minute,MacTimeRec.second,MacTimeRec.year);

	return(timebuffer);
}

egister int fildes;
{
	if ((fildes >= _NFILE) || (!_file[fildes]Mac-Cthon/unix/unix_stdopen.c   664    162     12       11502  4542261504  11543 /*
	Routines for LightspeedC

	(C) Copyright 1985, 1986. THINK Technologies, Inc.  All rights reserved.
*/
 
#ifndef _stdioh_
#include "stdio.h"
#endif

#ifndef _FileMgr_
#include "FileMgr.h"
#endif

#ifndef	_SerialDvr_
#include "SerialDvr.h"
#endif

void _exit_closeall();

/*	This file contains the code for fopen, fclose, _closeall, freopen.	*/

#line 0 xfopen
static FILE	*unix_xfopen(nameptr,type,who)
char	*nameptr;
register char	*type;
register FILE	*who;

{
register int		new;
static	Boolean		_init_onexit = false;	/* flag to signal onexit was initalized */

	ioParam	pb;			/* my parameter block for PB's	*/
	fileParam pb2;
	register int err;
	int	refnum;
	Boolean	create;
	Boolean	add;
	register Boolean	delete;
	register Boolean bin_file;
	register Ptr	p;

	if(!who)
		{
		register int		free_slot;
		/* look thru FILE array for an open slot	*/
		for (free_slot=STDERRNO+1;
			((free_slot<_NFILE)&&(_file[free_slot].InUse));
			free_slot++)
			;

		if (free_slot >= _NFILE) {
			errno = tmfoErr;	/* too many files open	*/
			return (NULL);
		}

		who = &_file[free_slot];
	}

{
	register int		permission;

	permission = fsWrPerm;		/* default = write	*/
	create = delete = true;		/* default is true	*/
	bin_file = add = false;
	refnum = 0;

	if (type[1]=='\0')
	{
		if (type[0] == 'r') permission = fsRdPerm;
	}
	else
		if (type[1] == '+')
		{
			permission = fsRdWrPerm;
			if (type[2] == 'b') bin_file = true;
		}
		else
		{
			if (type[1] == 'b') bin_file = true;
		
			if (type[0] == 'r') permission = fsRdPerm;
			
		}

/* force these files to be binary */
bin_file = true;	

	switch (type[0])
	{
		case 'r':
					create = false;
					break;
		case 'w':
					delete = true;
					break;
		case 'a':
					add = true;
					break;
		default:
					return(NULL);
	}


	CtoPstr(nameptr);

	p = NewPtr((long)BUFSIZ);

	do	{
	
		/* pdg 7/29/86 - look only via default path */

		pb.ioNamePtr	= 0;
/*		if (PBGetVol(&pb, false)) */ pb.ioVRefNum	= 0;


		pb.ioNamePtr	= (StringPtr)nameptr;
		pb.ioVersNum	= 0;
		pb.ioPermssn	= permission;
		pb.ioMisc		= 0L;

		new = PBOpen(&pb,false);
		
		if ((new == fnfErr) && (create))
			{
			if (err = (PBCreate(&pb,false))) goto err_exit;

			pb2.ioFDirIndex = 0;
			pb2.ioNamePtr	= pb.ioNamePtr;
			pb2.ioVRefNum	= pb.ioVRefNum;
			pb2.ioFVersNum	= pb.ioVersNum;
			if (err = (PBGetFInfo(&pb2,false))) goto err_exit;

			pb2.ioFlFndrInfo.fdType		= 'TEXT';
			pb2.ioFlFndrInfo.fdCreator	= '????';
			if (err = (PBSetFInfo(&pb2,false))) goto err_exit;

			delete = false;	/* don't delete this file	*/
		}

		if (!new)
		{	/* no errors on open  */
			if (pb.ioRefNum > 0)
			{	/* don't do this stuff if a device driver */
			
				if (type[0]=='a')
				{
					if(err = (PBGetEOF(&pb,false))) goto err_exit;
	
					pb.ioPosOffset = (long)pb.ioMisc;
					pb.ioPosMode = fsFromStart;
					err = PBSetFPos(&pb,false);
					if ((err!=noErr) && (err!=eofErr)) goto err_exit;
				}
				
				if ((type[0]=='w') && (delete))
				{
					pb2.ioFDirIndex = 0;
					pb2.ioNamePtr	= pb.ioNamePtr;
					pb2.ioVRefNum	= pb.ioVRefNum;
					pb2.ioFVersNum	= pb.ioVersNum;
					if (err = (PBGetFInfo(&pb2,false))) goto err_exit;
	
					if (err = (PBClose(&pb,false))) goto err_exit;
	
					if (err = (PBDelete(&pb,false))) goto err_exit;
	
					if (err = (PBCreate(&pb,false))) goto err_exit;
	
					if (err = (PBSetFInfo(&pb2,false))) goto err_exit;
	
					new = PBOpen(&pb,false);
					create = false;
				}
			}
			
			if (!new)
			{
				refnum = pb.ioRefNum;
				who->refnum		= refnum;
				who->last_error	= noErr;
				who->user_buf	= false;
				who->StdStream	= false;
				who->filebuf	= p;
				who->InUse		= true;
				who->mod		= false;
				who->look_full	= false;
				who->rd			= false;
				who->wr			= false;
				who->window		= false;
				if((permission==fsRdWrPerm)||(permission==fsRdPerm))
					who->rd		= true;
				if((permission==fsRdWrPerm)||(permission==fsWrPerm))
					who->wr		= true;
				who->binary		= bin_file;
				who->fpos		= BUFSIZ+10;	/* force fread/fwrite to go to disk */
				who->inbuf		= 0;
				PtoCstr(nameptr);
				if (_init_onexit == false)
				{
					_init_onexit = true;
					onexit(_exit_closeall);
				}

				if ((who->rd)&&(who->wr))
					{
					if(err = read_into_buffer(who))
						if (err != eofErr)
							{
							who->last_error = errno = err;
							return(who);
						}
				}
				return(who);
			}
		}
	}
	while ((new == fnfErr) && (create));
	
	if (new) errno = new;
	
	goto exit_noset;
	
err_exit:
	errno = err;
	
exit_noset:

	DisposPtr(p);
	PtoCstr(nameptr);
	return(NULL);
} /* end of scope of permission */

}




#line 0 fopen
FILE	*unix_

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.