*BSD News Article 29991


Return to BSD News archive

Xref: sserve comp.os.386bsd.apps:1154 comp.os.misc:2962
Newsgroups: comp.os.386bsd.apps,comp.os.misc
Path: sserve!cspyr0.cs.adfa.oz.au!wkt
From: wkt@cspyr0.cs.adfa.oz.au (Warren Toomey)
Subject: Patch to mtools 2.07 -- runtime configuration
Message-ID: <1994May4.052027.17265@sserve.cc.adfa.oz.au>
Keywords: mtooslls 2.07 patch runtime config unofficial
Sender: news@sserve.cc.adfa.oz.au
Organization: Australian Defence Force Academy, Canberra, Australia
Date: Wed, 4 May 1994 05:20:27 GMT

This is a short, simple patch to mtools-2.07 to allow the devices used by
mtools to be described in a file which is read at run-time, instead of
being hardwired into the programs.

This is an unofficial patch to mtools-2.07. The author, Emmet Gray, has not
seen these patches yet, although I will email them to him.

	Warren Toomey	wkt@cs.adfa.oz.au


# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	Readme
#	devices.diff
#	init.diff
#	mtools.cf
#
echo x - Readme
sed 's/^X//' >Readme << 'END-of-Readme'
XThis is a short, simple patch to mtools-2.07 to allow the devices used by
Xmtools to be described in a file which is read at run-time, instead of
Xbeing hardwired into the programs.
X
XThis is an unofficial patch to mtools-2.07. The author, Emmet Gray, has not
Xseen these patches yet, although I will email them to him.
X
X	Warren Toomey	wkt@cs.adfa.oz.au
X
XInstalling the Patches
X----------------------
X
XPatch devices.c and init.c with the diffs in this archive. Edit the Makefile
Xto use the define -DMTOOLS_CF instead of whatever define you normally use to
Xspecify your devices in devices.c. Recompile mtools; hopefully this will work.
XEdit the supplied mtools.cf file, defining the drives you want, and copy this
Xinto /etc.
X
XYou should now be able to use the mtools programs.
X
XNotes and Gotchas
X-----------------
X
XYou need the strsep() function in your C library.
X
XDevice mode values and gioctl functions cannot be specified. If you need
Xthese, you won't be able to use these patches.
END-of-Readme
echo x - devices.diff
sed 's/^X//' >devices.diff << 'END-of-devices.diff'
X*** mtools-2.0.7/devices.c	Thu Sep 10 15:11:00 1992
X--- mtools/devices.c	Fri Apr 29 02:53:01 1994
X***************
X*** 173,175 ****
X--- 173,243 ----
X  	{'\0', (char *) NULL, 0L, 0, 0, (int (*) ()) 0, 0, 0, 0}
X  };
X  #endif /* XENIX */
X+ 
X+ #ifdef MTOOLS_CF
X+ #define NUM_CFDEVS	20		/* Ok, so a compiled limit */
X+ struct device devices[NUM_CFDEVS];
X+ 
X+ /* Read_mtools_cf: Reads the file /etc/mtools.cf, extracting the devices
X+  * described there.
X+  * If sucessful, returns 0. Otherwise, returns 1.
X+  */
X+ 
X+ int read_mtools_cf()
X+  {
X+   FILE *cf;
X+   char *a, *val, buf[200], *strsep();
X+   int ndev,i,numcolons;
X+ 
X+   cf= fopen("/etc/mtools.cf", "r");
X+   if (cf==NULL) {
X+  	fprintf(stderr,"Cannot open /etc/mtools.cf to read devices\n");
X+ 	return(1);
X+   }
X+   ndev=0;
X+   while (fgets(buf, 198, cf)) {
X+ 	if (*buf=='#') continue;
X+ 	if (ndev== NUM_CFDEVS-1) {
X+ 		fprintf(stderr,"Too many devices in /etc/mtools.cf\n");
X+ 		fclose(cf); return(1);
X+ 	}
X+   	for (i=0,numcolons=0;i<strlen(buf);i++)
X+ 		if (buf[i]==':') numcolons++;
X+  	if (numcolons!=6) {
X+ 		fprintf(stderr,"Error in /etc/mtools.cf, wrong number of fields on the line:\n");
X+ 		fputs(buf, stderr);
X+ 		fclose(cf); return(1);
X+  	}
X+ 	a= buf;
X+ 	val= strsep(&a, ":");
X+ 	devices[ndev].drive=val[0];
X+ 
X+ 	val= strsep(&a, ":");
X+ 	devices[ndev].name= (char *)malloc(strlen(val)+1);
X+ 	if (devices[ndev].name==NULL) { fclose(cf); return(1); }
X+ 	strcpy(devices[ndev].name, val);
X+ 
X+ 	val= strsep(&a, ":");
X+ 	devices[ndev].offset= atol(val);
X+ 
X+ 	val= strsep(&a, ":");
X+ 	devices[ndev].fat_bits= atoi(val);
X+ 
X+ 	val= strsep(&a, ":");
X+ 	devices[ndev].tracks= atoi(val);
X+ 
X+ 	val= strsep(&a, ":");
X+ 	devices[ndev].heads= atoi(val);
X+ 
X+ 	val= strsep(&a, ":");
X+ 	devices[ndev].sectors= atoi(val);
X+ 
X+ 	devices[ndev].mode=0;
X+ 	devices[ndev].gioctl=NULL;
X+ 	ndev++;
X+   }
X+   devices[ndev].name='\0';
X+   fclose(cf);
X+   return(0);
X+  }
X+ #endif	/* MTOOLS_CF */
END-of-devices.diff
echo x - init.diff
sed 's/^X//' >init.diff << 'END-of-init.diff'
X*** mtools-2.0.7/init.c	Thu Sep 10 14:59:30 1992
X--- mtools/init.c	Fri Apr 29 02:26:29 1994
X***************
X*** 10,15 ****
X--- 10,18 ----
X  #include <sys/stat.h>
X  #include "msdos.h"
X  
X+ #ifdef MTOOLS_CF
X+ extern int read_mtools_cf();
X+ #endif
X  #define FULL_CYL
X  #define WORD(x) ((boot->x)[0] + ((boot->x)[1] << 8))
X  #define DWORD(x) ((boot->x)[0] + ((boot->x)[1] << 8) + ((boot->x)[2] << 16) + ((boot->x)[3] << 24))
X***************
X*** 45,50 ****
X--- 48,56 ----
X  		free((char *) dir_buf);
X  	}
X  					/* check out the drive letter */
X+ #ifdef MTOOLS_CF
X+ 	if (read_mtools_cf()) exit(1);
X+ #endif
X  	dev = devices;
X  	while (dev->drive) {
X  		if (dev->drive == drive)
END-of-init.diff
echo x - mtools.cf
sed 's/^X//' >mtools.cf << 'END-of-mtools.cf'
X# Device configuration file for mtools 2.07. Comment lines begin with a #.
X# Other lines describe the layout of a file/special device which mtools can
X# use as an MS-DOS disk image. Each line has seven colon-separated fields.
X# These fields are:
X#
X#	drive	The drive letter (in uppercase) that you want to associate
X#		to this device.
X#
X#	name	Full path to the device.  Shell expansion is done on the
X#		name so things like $HOME/vpix/C: will work.
X#
X#	offset	Offset in bytes from the beginning of the device.  Useful
X#		for msdos disk "images"	such as those VP/ix uses.
X#
X#	fat_bits The encoding scheme for the File Allocation Table.  Currently
X#		supports only 12 and 16 bit FATs.  Hard disks usually use
X#		16 bit FATs, while all diskettes use 12 bit FATs.
X#
X#	tracks	The number of tracks supported by this device or zero if
X#		this type of sanity checking is not required.  Do NOT use
X#		this field for hard disks or disk "images".
X#
X#	heads	The number of heads supported by this device or zero if
X#		this type of sanity checking is not required.
X#
X#	sectors	The number of sectors supported by this device or zero if
X#		this type of sanity checking is not required.
X#
X#
X#	If a device supports more than one disk capacity (1.2m and
X#	360k), then you should place the most frequently used capacity
X#	first.  You may get an error message from the device driver when
X#	the disk capacity doesn't match the device, but these can be
X#	safely ignored.
X#
XA:/dev/rfd0a:0:12:80:2:15		# 5.25" 1.2Meg  floppy
XB:/dev/rfd1a:0:12:80:2:18		# 3.5"  1.44Meg floppy
XC:/dev/rwd0d:28672:16:0:0:0		# Hard disk, skipping first 28672 bytes
END-of-mtools.cf
exit