[unix-pc.sources] Patch #3 to Mtools v1.5

egray@fthood.UUCP (01/31/89)

This is a cosmetic patch to the Mtools v1.5 release.  If you're running
Mtools on a AT&T Unix PC, there are no coding changes!  This patch is
necessary only to make the current release match what is going to be
posted in comp.sources.unix.  However, since future patches may depend
on these changes, it's probably a good idea to install these patches.

The patch includes changes to Makefile, init.c, and msdos.h.  But since
I can't be sure which version of these files your using (the ones in
Unixpc.shar perhaps?), I've included a duplicate Unixpc.shar file.

Emmet P. Gray				US Army, HQ III Corps & Fort Hood
...!uunet!uiucuxc!fthood!egray		Attn: AFZF-DE-ENV
					Directorate of Engineering & Housing
					Environmental Management Office
					Fort Hood, TX 76544-5057

-----------------------------------------------------------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	patches
#	Unixpc.shar
# This archive created: Mon Jan 30 18:07:43 1989
export PATH; PATH=/bin:/usr/bin:$PATH
echo shar: "extracting 'patches'" '(10114 characters)'
if test -f 'patches'
then
	echo shar: "will not over-write existing file 'patches'"
else
sed 's/^X//' << \SHAR_EOF > 'patches'
X*** old/Customize	Sun Oct 30 13:04:24 1988
X--- Customize	Mon Jan 30 09:36:04 1989
X***************
X*** 69,92
X  	there are 633 clusters		num_clus = 633
X  
X- How to get incompatible Unix systems to transfer diskette files...
X- 
X- You can use an IBM PC compatible computer as an intermediate step to
X- convert diskettes.  The IBM clone would have an external disk drive for
X- each of the different drive types.  For example, suppose you have a Unix
X- box with an 80 track drive and another Unix box with a 40 track drive.
X- The following flow chart shows how you'd transfer a file from Unix box
X- #1 to Unix box #2 using mtools and the DOS COPY command.
X- 
X-          +--------+          +-----------+          +--------+
X-     +--> | Unix   |          |  IBM PC   |          | Unix   | <--+
X-     |    | box #1 |          |  clone    |          | box #2 |    |
X-   mtools +--------+          +-----+-----+          +--------+  mtools
X-     |    | 80 trk |          | 80  | 40  |          | 40     |    |
X-     +--> | track  | <------> | trk | trk | <------> | track  | <--+
X-          +--------+          +-----+-----+          +--------+
X-                               ^         ^
X-                               |  MSDOS  |
X-                               +- COPY --+
X- 
X  Emmet P. Gray				US Army, HQ III Corps & Fort Hood
X  ...!unnet!uiucuxc!fthood!egray		Attn: AFZF-DE-ENV
X
X--- 69,72 -----
X  	there are 633 clusters		num_clus = 633
X  
X  Emmet P. Gray				US Army, HQ III Corps & Fort Hood
X  ...!unnet!uiucuxc!fthood!egray		Attn: AFZF-DE-ENV
X*** old/Makefile	Tue Nov  1 11:11:18 1988
X--- Makefile	Mon Jan 30 09:49:11 1989
X***************
X*** 49,53
X  	$(CC) $(LDFLAGS) $(MREN) -o mren
X  
X! install:	$(PROGS)
X  	cp mdir $(BINDIR)/mdir
X  	rm mdir
X
X--- 49,53 -----
X  	$(CC) $(LDFLAGS) $(MREN) -o mren
X  
X! install:
X  	cp mdir $(BINDIR)/mdir
X  	rm mdir
X***************
X*** 96,97
X  	$(SHAR) mdir.c mkentry.c mmd.c mrd.c mread.c mren.c mtype.c \
X  	mwrite.c putfat.c search.c subdir.c unixname.c > mtools_sh.2
X
X--- 96,99 -----
X  	$(SHAR) mdir.c mkentry.c mmd.c mrd.c mread.c mren.c mtype.c \
X  	mwrite.c putfat.c search.c subdir.c unixname.c > mtools_sh.2
X+ 
X+ init.o:	msdos.h
X*** old/Readme	Sun Oct 30 13:16:50 1988
X--- Readme	Mon Jan 30 09:39:18 1989
X***************
X*** 1,3
X! 				MTOOLS v1.5
X  
X  This is a collection of MSDOS tools to allow you to read and write to
X
X--- 1,3 -----
X! 			      MTOOLS v1.5.3
X  
X  This is a collection of MSDOS tools to allow you to read and write to
X***************
X*** 30,34
X       512         9          40        2        360k      5.25      2.0
X       512        15          80        2        1.2M      5.25      3.0
X-      512         9          80        2        720k       3.5      3.2
X  
X  
X
X--- 30,33 -----
X       512         9          40        2        360k      5.25      2.0
X       512        15          80        2        1.2M      5.25      3.0
X  
X  
X***************
X*** 41,45
X  	/dev/rflp40t9s2s	40 track 9 sector double sided
X  	/dev/rflp80t15s2s	80 track 15 sector double sided
X- 	/dev/rflp80t9s2s	3.5 inch 80 track 9 sector double sided
X  
X  These device names are in the msdos.h file as #defines and must be
X
X--- 40,43 -----
X  	/dev/rflp40t9s2s	40 track 9 sector double sided
X  	/dev/rflp80t15s2s	80 track 15 sector double sided
X  
X  These device names are in the msdos.h file as #defines and must be
X*** old/init.c	Mon Jan 30 09:40:35 1989
X--- init.c	Mon Jan 30 18:02:53 1989
X***************
X*** 33,36
X  	}
X  					/* read media signature (1st FAT) */
X  	code = 0;
X  	fat = read_fat();
X
X--- 33,51 -----
X  	}
X  					/* read media signature (1st FAT) */
X+ 	if (!(fat = read_fat())) {
X+ #ifdef FLP_80_15_2
X+ 		close(fd);
X+ 					/* OK, try the 1.2M version */
X+ 		if ((fd = open(FLP_80_15_2, mode)) < 0) {
X+ 			perror("init: open");
X+ 			exit(1);
X+ 		}
X+ 		fat = read_fat();
X+ #else /* FLP_80_15_2 */
X+ 		perror("init: read");
X+ 		exit(1);
X+ #endif /* FLP_80_15_2 */
X+ 	}
X+ 					/* what kind of disk do we have? */
X  	code = 0;
X  	switch(fat) {
X***************
X*** 34,38
X  					/* read media signature (1st FAT) */
X  	code = 0;
X- 	fat = read_fat();
X  	switch(fat) {
X  		case 0xfe:
X
X--- 49,52 -----
X  					/* what kind of disk do we have? */
X  	code = 0;
X  	switch(fat) {
X  		case 0:			/* I hope errno hasn't been clobbered */
X***************
X*** 36,39
X  	fat = read_fat();
X  	switch(fat) {
X  		case 0xfe:
X  #ifndef FLP_40_8_1
X
X--- 50,56 -----
X  	code = 0;
X  	switch(fat) {
X+ 		case 0:			/* I hope errno hasn't been clobbered */
X+ 			perror("init: read");
X+ 			exit(1);
X  		case 0xfe:
X  #ifndef FLP_40_8_1
X***************
X*** 40,44
X  			fprintf(stderr, "40 track, 8 sector, single sided: not supported\n");
X  			code = 1;
X! #else FLP_40_8_1
X  			dir_start = 3;
X  			dir_len = 4;
X
X--- 57,61 -----
X  			fprintf(stderr, "40 track, 8 sector, single sided: not supported\n");
X  			code = 1;
X! #else /* FLP_40_8_1 */
X  			dir_start = 3;
X  			dir_len = 4;
X***************
X*** 51,55
X  				return(1);
X  			}
X! #endif FLP_40_8_1
X  			break;
X  		case 0xff:
X
X--- 68,72 -----
X  				return(1);
X  			}
X! #endif /* FLP_40_8_1 */
X  			break;
X  		case 0xff:
X***************
X*** 57,61
X  			fprintf(stderr, "40 track, 8 sector, double sided: not supported\n");
X  			code = 1;
X! #else FLP_40_8_2
X  			dir_start = 3;
X  			dir_len = 7;
X
X--- 74,78 -----
X  			fprintf(stderr, "40 track, 8 sector, double sided: not supported\n");
X  			code = 1;
X! #else /* FLP_40_8_2 */
X  			dir_start = 3;
X  			dir_len = 7;
X***************
X*** 68,72
X  				return(1);
X  			}
X! #endif FLP_40_8_2
X  			break;
X  		case 0xfc:
X
X--- 85,89 -----
X  				return(1);
X  			}
X! #endif /* FLP_40_8_2 */
X  			break;
X  		case 0xfc:
X***************
X*** 74,78
X  			fprintf(stderr, "40 track, 9 sector, single sided: not supported\n");
X  			code = 1;
X! #else FLP_40_9_1
X  			dir_start = 5;
X  			dir_len = 4;
X
X--- 91,95 -----
X  			fprintf(stderr, "40 track, 9 sector, single sided: not supported\n");
X  			code = 1;
X! #else /* FLP_40_9_1 */
X  			dir_start = 5;
X  			dir_len = 4;
X***************
X*** 85,89
X  				return(1);
X  			}
X! #endif FLP_40_9_1
X  			break;
X  		case 0xfd:
X
X--- 102,106 -----
X  				return(1);
X  			}
X! #endif /* FLP_40_9_1 */
X  			break;
X  		case 0xfd:
X***************
X*** 91,95
X  			fprintf(stderr, "40 track, 9 sector, double sided: not supported\n");
X  			code = 1;
X! #else FLP_40_9_2
X  			dir_start = 5;
X  			dir_len = 7;
X
X--- 108,112 -----
X  			fprintf(stderr, "40 track, 9 sector, double sided: not supported\n");
X  			code = 1;
X! #else /* FLP_40_9_2 */
X  			dir_start = 5;
X  			dir_len = 7;
X***************
X*** 102,106
X  				return(1);
X  			}
X! #endif FLP_40_9_2
X  			break;
X  		case 0xf9:		/* all 80 track disks */
X
X--- 119,123 -----
X  				return(1);
X  			}
X! #endif /* FLP_40_9_2 */
X  			break;
X  		case 0xf9:		/* all 80 track disks */
X***************
X*** 105,112
X  			break;
X  		case 0xf9:		/* all 80 track disks */
X! 			version = get_dos_ver();
X! 			switch (version) {
X! 				case '0':
X! 				case '1':
X  #ifndef FLP_80_15_2
X  					fprintf(stderr, "80 track, 15 sector, double sided: not supported\n");
X
X--- 122,133 -----
X  			break;
X  		case 0xf9:		/* all 80 track disks */
X! 			/*
X! 			 * All 80 track disk use the same media signature,
X! 			 * so you'll have to come up with some way of figuring
X! 			 * out what the drive type is.  I've included a crude
X! 			 * "get_dos_ver()" routine to help assist in this
X! 			 * determination.  If you've only got one 80 track
X! 			 * drive, this is a moot point.
X! 			 */
X  #ifndef FLP_80_15_2
X  			fprintf(stderr, "80 track, 15 sector, double sided: not supported\n");
X***************
X*** 110,149
X  				case '1':
X  #ifndef FLP_80_15_2
X! 					fprintf(stderr, "80 track, 15 sector, double sided: not supported\n");
X! 					code = 1;
X! #else FLP_80_15_2
X! 					dir_start = 15;
X! 					dir_len = 14;
X! 					clus_size = 1;
X! 					fat_len = 7;
X! 					num_clus = 1193;
X! 					close(fd);
X! 					if ((fd = open(FLP_80_15_2, mode)) < 0) {
X! 						perror("init: open");
X! 						return(1);
X! 					}
X! #endif FLP_80_15_2
X! 					break;
X! 				case '2':
X! #ifndef FLP_80_9_2
X! 					fprintf(stderr, "3.5 inch 80 track, 9 sector, double sided: not supported\n");
X! 					code = 1;
X! #else FLP_80_9_2
X! 					dir_start = 7;
X! 					dir_len = 7;
X! 					clus_size = 2;
X! 					fat_len = 3;
X! 					num_clus = 713;
X! 					close(fd);
X! 					if ((fd = open(FLP_80_9_2, mode)) < 0) {
X! 						perror("init: open");
X! 						return(1);
X! 					}
X! #endif FLP_80_9_2
X! 					break;
X! 				default:
X! 					fprintf(stderr, "Unknown DOS version '%02x'\n", version);
X! 					code = 1;
X! 					break;
X  			}
X  			break;
X
X--- 131,146 -----
X  			 */
X  #ifndef FLP_80_15_2
X! 			fprintf(stderr, "80 track, 15 sector, double sided: not supported\n");
X! 			code = 1;
X! #else /* FLP_80_15_2 */
X! 			dir_start = 15;
X! 			dir_len = 14;
X! 			clus_size = 1;
X! 			fat_len = 7;
X! 			num_clus = 1193;
X! 			close(fd);
X! 			if ((fd = open(FLP_80_15_2, mode)) < 0) {
X! 				perror("init: open");
X! 				return(1);
X  			}
X  #endif /* FLP_80_15_2 */
X***************
X*** 147,150
X  					break;
X  			}
X  			break;
X  		default:
X
X--- 144,148 -----
X  				return(1);
X  			}
X+ #endif /* FLP_80_15_2 */
X  			break;
X  		default:
X***************
X*** 263,270
X  	}
X  					/* read the first FAT sector */
X! 	if (read(fd, (char *) buf, MSECSIZ) != MSECSIZ) {
X! 		perror("init: read");
X! 		exit(1);
X! 	}
X  	return(buf[0]);
X  }
X
X--- 261,267 -----
X  	}
X  					/* read the first FAT sector */
X! 	if (read(fd, (char *) buf, MSECSIZ) != MSECSIZ)
X! 		return('\0');
X! 
X  	return(buf[0]);
X  }
X***************
X*** 274,278
X   */
X  
X! unsigned char
X  get_dos_ver()
X  {
X
X--- 271,275 -----
X   */
X  
X! char
X  get_dos_ver()
X  {
X***************
X*** 331,335
X  		exit(1);
X  	}
X! #endif DUP_FAT
X  	return;
X  }
X
X--- 328,332 -----
X  		exit(1);
X  	}
X! #endif /* DUP_FAT */
X  	return;
X  }
X*** old/msdos.h	Tue Nov  1 11:10:54 1988
X--- msdos.h	Mon Jan 30 09:49:11 1989
X***************
X*** 19,23
X  #define	FLP_40_9_2	"/dev/rflp40t9s2s"
X  #define FLP_80_15_2	"/dev/rflp80t15s2s"
X- #define FLP_80_9_2	"/dev/rflp80t9s2s"
X  
X  struct directory {
X
X--- 19,22 -----
X  #define	FLP_40_9_2	"/dev/rflp40t9s2s"
X  #define FLP_80_15_2	"/dev/rflp80t15s2s"
X  
X  struct directory {
SHAR_EOF
if test 10114 -ne "`wc -c < 'patches'`"
then
	echo shar: "error transmitting 'patches'" '(should have been 10114 characters)'
fi
fi
echo shar: "extracting 'Unixpc.shar'" '(11252 characters)'
if test -f 'Unixpc.shar'
then
	echo shar: "will not over-write existing file 'Unixpc.shar'"
else
sed 's/^X//' << \SHAR_EOF > 'Unixpc.shar'
X#! /bin/sh
X# This is a shell archive, meaning:
X# 1. Remove everything above the #! /bin/sh line.
X# 2. Save the resulting text in a file.
X# 3. Execute the file with /bin/sh (not csh) to create:
X#	Makefile
X#	init.c
X#	msdos.h
X# This archive created: Mon Jan 30 09:49:03 1989
Xexport PATH; PATH=/bin:/usr/bin:$PATH
Xecho shar: "extracting 'Makefile'" '(2845 characters)'
Xif test -f 'Makefile'
Xthen
X	echo shar: "will not over-write existing file 'Makefile'"
Xelse
Xsed 's/^X//' << \SHAR_EOF > 'Makefile'
XX#
XX#       Makefile for MSDOS tools
XX#
XX
XXCFLAGS	= -O
XXLD	= ld -s
XXLINT	= lint -p
XXSHAR	= shar -a
XXBINDIR	= /usr/local/bin
XXPROGS	= mdir mread mwrite mdel mtype mmd mrd mren
XXSHAREDLIB = /lib/crt0s.o /lib/shlib.ifile
XX
XXMDIR	= mdir.o getfat.o init.o search.o match.o convdate.o unixname.o \
XX	subdir.o isdir.o
XXMREAD	= mread.o getfat.o init.o search.o match.o unixname.o subdir.o
XXMWRITE	= mwrite.o getfat.o init.o search.o fixname.o unixname.o putfat.o \
XX	subdir.o mkentry.o isdir.o
XXMDEL	= mdel.o getfat.o init.o search.o match.o unixname.o putfat.o subdir.o
XXMTYPE	= mtype.o getfat.o init.o search.o match.o unixname.o subdir.o
XXMMD	= mmd.o getfat.o init.o search.o fixname.o unixname.o putfat.o \
XX	subdir.o mkentry.o
XXMRD	= mrd.o getfat.o init.o search.o unixname.o putfat.o subdir.o
XXMREN	= mren.o getfat.o init.o search.o fixname.o unixname.o putfat.o \
XX	subdir.o isdir.o
XX
XXall:	$(PROGS)
XX
XXmdir:	$(MDIR)
XX	$(LD) $(MDIR) $(SHAREDLIB) -o mdir
XX
XXmread:	$(MREAD)
XX	$(LD) $(MREAD) $(SHAREDLIB) -o mread
XX
XXmwrite:	$(MWRITE)
XX	$(LD) $(MWRITE) $(SHAREDLIB) -o mwrite
XX
XXmdel:	$(MDEL)
XX	$(LD) $(MDEL) $(SHAREDLIB) -o mdel
XX
XXmtype:	$(MTYPE)
XX	$(LD) $(MTYPE) $(SHAREDLIB) -o mtype
XX
XXmmd:	$(MMD)
XX	$(LD) $(MMD) $(SHAREDLIB) -o mmd
XX
XXmrd:	$(MRD)
XX	$(LD) $(MRD) $(SHAREDLIB) -o mrd
XX
XXmren:	$(MREN)
XX	$(LD) $(MREN) $(SHAREDLIB) -o mren
XX
XXinstall:
XX	cp mdir $(BINDIR)/mdir
XX	rm mdir
XX#	cp Mdir.1 /usr/man/man1/mdir.1
XX	cp mread $(BINDIR)/mread
XX	rm mread
XX#	cp Mread.1 /usr/man/man1/mread.1
XX	cp mwrite $(BINDIR)/mwrite
XX	rm mwrite
XX#	cp Mwrite.1 /usr/man/man1/mwrite.1
XX	cp mdel $(BINDIR)/mdel
XX	rm mdel
XX#	cp Mdel.1 /usr/man/man1/mdel.1
XX	cp mtype $(BINDIR)/mtype
XX	rm mtype
XX#	cp Mtype.1 /usr/man/man1/mtype.1
XX	cp mmd $(BINDIR)/mmd
XX	rm mmd
XX#	cp Mmd.1 /usr/man/man1/mmd.1
XX	cp mrd $(BINDIR)/mrd
XX	rm mrd
XX#	cp Mrd.1 /usr/man/man1/mrd.1
XX	cp mren $(BINDIR)/mren
XX	rm mren
XX#	cp Mren.1 /usr/man/man1/mren.1
XX
XXlint:
XX	$(LINT) mdir.c getfat.c init.c search.c match.c convdate.c subdir.c \
XX	unixname.c isdir.c
XX	$(LINT) mread.c getfat.c init.c search.c match.c unixname.c subdir.c
XX	$(LINT) mwrite.c getfat.c init.c search.c fixname.c unixname.c \
XX	putfat.c subdir.c mkentry.c isdir.c
XX	$(LINT) mdel.c getfat.c init.c search.c match.c unixname.c putfat.c \
XX	subdir.c
XX	$(LINT) mtype.c getfat.c init.c search.c match.c unixname.c subdir.c
XX	$(LINT) mmd.c getfat.c init.c search.c fixname.c unixname.c putfat.c \
XX	subdir.c mkentry.c
XX	$(LINT) mrd.c getfat.c init.c search.c unixname.c putfat.c subdir.c
XX	$(LINT) mren.c getfat.c init.c search.c fixname.c unixname.c putfat.c \
XX	subdir.c
XX
XXshar:
XX	$(SHAR) Readme Customize Makefile Mdel.1 Mdir.1 Mmd.1 Mrd.1 Mread.1 \
XX	Mren.1 Mtype.1 Mwrite.1 Unixpc.shar msdos.h convdate.c fixname.c \
XX	getfat.c init.c isdir.c match.c mdel.c > mtools_sh.1
XX	$(SHAR) mdir.c mkentry.c mmd.c mrd.c mread.c mren.c mtype.c \
XX	mwrite.c putfat.c search.c subdir.c unixname.c > mtools_sh.2
XX
XXinit.o:	msdos.h
XSHAR_EOF
Xif test 2845 -ne "`wc -c < 'Makefile'`"
Xthen
X	echo shar: "error transmitting 'Makefile'" '(should have been 2845 characters)'
Xfi
Xfi
Xecho shar: "extracting 'init.c'" '(6148 characters)'
Xif test -f 'init.c'
Xthen
X	echo shar: "will not over-write existing file 'init.c'"
Xelse
Xsed 's/^X//' << \SHAR_EOF > 'init.c'
XX/*
XX * Initialize a MSDOS diskette.  Get the media signature (1st FAT
XX * entry) and alter the floppy disk controller via 'gdisk' ioctl calls
XX * to match the format of the disk.  Sets a bunch of global variables.
XX * Returns 0 on success, or 1 on failure.
XX */
XX
XX#include <stdio.h>
XX#include <sys/gdioctl.h>
XX#include <ctype.h>
XX#include <signal.h>
XX#include "msdos.h"
XX
XX#undef DUP_FAT
XX
XXextern int fd, dir_len, dir_start, clus_size, fat_len, num_clus;
XXextern unsigned char *fatbuf;
XXextern char *mcwd;
XX
XXint
XXinit(mode)
XXint mode;
XX{
XX	int code, buflen, intr();
XX	unsigned char read_fat(), fat;
XX	char *getenv(), *fixmcwd(), *malloc();
XX	long lseek();
XX	void perror(), exit(), dismount(), move(), reset_dir();
XX	struct gdctl gdbuf;
XX
XX	if ((fd = open(FLOPPY, mode)) < 0) {
XX		perror("init: open");
XX		exit(1);
XX	}
XX					/* get the disk controller info */
XX	if (ioctl(fd, GDGETA, &gdbuf) < 0) {
XX		perror("init: ioctl");
XX		dismount();
XX	}
XX					/* assume some defaults */
XX	gdbuf.params.cyls = 40;		/* number of cylinders */
XX	gdbuf.params.heads = 1;		/* number of heads */
XX	gdbuf.params.psectrk = 8;	/* physical sectors per track */
XX	gdbuf.params.pseccyl = 8;	/* physical sectors per cylinder */
XX	gdbuf.params.flags = 1;		/* disk type flag */
XX	gdbuf.params.step = 0;		/* step rate for controller */
XX	gdbuf.params.sectorsz = 512;	/* sector size */
XX
XX					/* set the default parameters */
XX	if (ioctl(fd, GDSETA, &gdbuf) < 0) {
XX		perror("init: ioctl");
XX		dismount();
XX	}
XX					/* read media signature (1st FAT) */
XX	code = 0;
XX	fat = read_fat();
XX	switch(fat) {
XX		case 0xfe:		/* 40 trk, 8 sect, 1 side */
XX			dir_start = 3;
XX			dir_len = 4;
XX			clus_size = 1;
XX			fat_len = 1;
XX			num_clus = 313;
XX			gdbuf.params.heads = 1;
XX			gdbuf.params.psectrk = 8;
XX			gdbuf.params.pseccyl = 8;
XX			break;
XX		case 0xff:		/* 40 trk, 8 sect, 2 sides */
XX			dir_start = 3;
XX			dir_len = 7;
XX			clus_size = 2;
XX			fat_len = 1;
XX			num_clus = 315;
XX			gdbuf.params.heads = 2;
XX			gdbuf.params.psectrk = 8;
XX			gdbuf.params.pseccyl = 16;
XX			break;
XX		case 0xfc:		/* 40 trk, 9 sect, 1 side */
XX			dir_start = 5;
XX			dir_len = 4;
XX			clus_size = 1;
XX			fat_len = 2;
XX			num_clus = 351;
XX			gdbuf.params.heads = 1;
XX			gdbuf.params.psectrk = 9;
XX			gdbuf.params.pseccyl = 9;
XX			break;
XX		case 0xfd:		/* 40 trk, 9 sect, 2 sides */
XX			dir_start = 5;
XX			dir_len = 7;
XX			clus_size = 2;
XX			fat_len = 2;
XX			num_clus = 354;
XX			gdbuf.params.heads = 2;
XX			gdbuf.params.psectrk = 9;
XX			gdbuf.params.pseccyl = 18;
XX			break;
XX		default:
XX			fprintf(stderr, "Unknown format '%02x'\n", fat);
XX			code = 1;
XX			break;
XX	}
XX	if (code)
XX		return(1);
XX					/* set the new-found parameters */
XX	if (ioctl(fd, GDSETA, &gdbuf) < 0) {
XX		perror("init: ioctl");
XX		dismount();
XX	}
XX
XX	buflen = fat_len * MSECSIZ;
XX	fatbuf = (unsigned char *) malloc((unsigned int) buflen);
XX	move(1);
XX					/* read the FAT sectors */
XX	if (read(fd, (char *) fatbuf, buflen) != buflen) {
XX		perror("init: read");
XX		exit(1);
XX	}
XX					/* set dir_chain to root directory */
XX	reset_dir();
XX					/* get Current Working Directory */
XX	mcwd = fixmcwd(getenv("MCWD"));
XX					/* test it out.. */
XX	if (subdir("")) {
XX		fprintf(stderr, "Environmental variable MCWD needs updating\n");
XX		exit(1);
XX	}
XX					/* catch signals if open for write */
XX	if (mode == 2) {
XX		signal(SIGINT, intr);
XX		signal(SIGTERM, intr);
XX		signal(SIGQUIT, intr);
XX	}
XX	return(0);
XX}
XX
XX/*
XX * Dismount the floppy.  Useful only if one of the above ioctls fail
XX * and leaves the drive light turned on.
XX */
XX
XXvoid
XXdismount()
XX{
XX	struct gdctl gdbuf;
XX	void exit();
XX
XX	ioctl(fd, GDDISMNT, &gdbuf);
XX	exit(1);
XX}
XX
XX/*
XX * Move the read/write head to the next location.  Tries to optimize
XX * the movement by moving relative to current location.  The argument
XX * is a logical sector number.  All errors are fatal.
XX */
XX
XXvoid
XXmove(sector)
XXint sector;
XX{
XX	long cur_loc, next, lseek();
XX	void exit(), perror();
XX					/* get current location */
XX	if ((cur_loc = lseek(fd, 0L, 1)) < 0) {
XX		perror("move: lseek");
XX		exit(1);
XX	}
XX	next = (long) (MSECSIZ * sector) - cur_loc;
XX					/* we're already there */
XX	if (next == 0L)
XX		return;
XX					/* move to next location */
XX	if (lseek(fd, next, 1) < 0) {
XX		perror("move: lseek");
XX		exit(1);
XX	}
XX	return;
XX}
XX
XX/*
XX * Fix MCWD to be a proper directory name.  Always has a leading separator.
XX * Never has a trailing separator (unless it is the path itself).
XX */
XX
XXchar *
XXfixmcwd(dirname)
XXchar *dirname;
XX{
XX	char *s, *ans, *strcpy(), *strcat(), *malloc();
XX
XX	if (dirname == NULL)
XX		return("/");
XX
XX	ans = malloc((unsigned int) strlen(dirname)+2);
XX
XX					/* add a leading separator */
XX	if (*dirname != '/' && *dirname != '\\') {
XX		strcpy(ans, "/");
XX		strcat(ans, dirname);
XX	}
XX	else
XX		strcpy(ans, dirname);
XX					/* translate to upper case */
XX	for (s = ans; *s; ++s) {
XX		if (islower(*s))
XX			*s = toupper(*s);
XX	}
XX					/* if separator alone */
XX	if (strlen(ans) == 1)
XX		return(ans);
XX					/* zap the trailing separator */
XX	s--;
XX	if (*s == '/' || *s == '\\')
XX		*s = '\0';
XX	return(ans);
XX}
XX
XX/*
XX * Read the first byte of the FAT table.  This code serves as a media
XX * signature for the diskette.
XX */
XX
XXunsigned char
XXread_fat()
XX{
XX	unsigned char buf[MSECSIZ];
XX					/* move to boot sector */
XX	if (lseek(fd, (long) MSECSIZ, 0) < 0) {
XX		perror("init: lseek");
XX		exit(1);
XX	}
XX					/* read the first FAT sector */
XX	if (read(fd, (char *) buf, MSECSIZ) != MSECSIZ) {
XX		fprintf(stderr, "Drive empty or latch not closed\n");
XX		exit(1);
XX	}
XX	return(buf[0]);
XX}
XX
XX/*
XX * Do a graceful exit if the program is interupted.  This will reduce
XX * (but not eliminate) the risk of generating a corrupted disk on
XX * a user abort.
XX */
XX
XXint
XXintr()
XX{
XX	void writefat();
XX
XX	writefat();
XX	close(fd);
XX	exit(1);
XX}
XX
XX/*
XX * Write the FAT table to the disk.  Up to now the FAT manipulation has
XX * been done in memory.  All errors are fatal.  (Might not be too smart
XX * to wait till the end of the program to write the table.  Oh well...)
XX */
XX
XXvoid
XXwritefat()
XX{
XX	int buflen;
XX	void move();
XX
XX	move(1);
XX	buflen = fat_len * MSECSIZ;
XX	if (write(fd, (char *) fatbuf, buflen) != buflen) {
XX		perror("writefat: write");
XX		exit(1);
XX	}
XX#ifdef DUP_FAT
XX					/* the duplicate FAT table */
XX	if (write(fd, (char *) fatbuf, buflen) != buflen) {
XX		perror("writefat: write");
XX		exit(1);
XX	}
XX#endif /* DUP_FAT */
XX	return;
XX}
XSHAR_EOF
Xif test 6148 -ne "`wc -c < 'init.c'`"
Xthen
X	echo shar: "error transmitting 'init.c'" '(should have been 6148 characters)'
Xfi
Xfi
Xecho shar: "extracting 'msdos.h'" '(558 characters)'
Xif test -f 'msdos.h'
Xthen
X	echo shar: "will not over-write existing file 'msdos.h'"
Xelse
Xsed 's/^X//' << \SHAR_EOF > 'msdos.h'
XX/*
XX * msdos common header file
XX */
XX
XX#define MSECSIZ	512			/* sector size */
XX#define MDIRSIZ	32			/* directory size */
XX#define CLSTRBUF 1024			/* largest cluster size */
XX#define MAX_PATH 128
XX
XX#define	FLOPPY	"/dev/rfp020"
XX
XXstruct directory {
XX	unsigned char	name[8];	/* file name */
XX	unsigned char	ext[3];		/* file extent */
XX	unsigned char	attr;		/* attribute byte */
XX	unsigned char	reserved[10];	/* ?? */
XX	unsigned char	time[2];		
XX	unsigned char	date[2];
XX	unsigned char	start[2];	/* starting cluster number */
XX	unsigned char	size[4];	/* size of the file */
XX};
XSHAR_EOF
Xif test 558 -ne "`wc -c < 'msdos.h'`"
Xthen
X	echo shar: "error transmitting 'msdos.h'" '(should have been 558 characters)'
Xfi
Xfi
Xexit 0
X#	End of shell archive
SHAR_EOF
if test 11252 -ne "`wc -c < 'Unixpc.shar'`"
then
	echo shar: "error transmitting 'Unixpc.shar'" '(should have been 11252 characters)'
fi
fi
exit 0
#	End of shell archive