From decwrl!ucbvax!ucsd!swrinde!cs.utexas.edu!uunet!allbery Wed May 16 08:31:50 PDT 1990
Article 1531 of comp.sources.misc:
Path: decwrl!ucbvax!ucsd!swrinde!cs.utexas.edu!uunet!allbery
From: viktor@melon.princeton.edu (Viktor Dukhovni)
Newsgroups: comp.sources.misc
Subject: v12i051: Recent mtools,  official patches.
Keywords: DOS, floppy
Message-ID: <88353@uunet.UU.NET>
Date: 12 May 90 01:49:43 GMT
Sender: allbery@uunet.UU.NET
Lines: 440
Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)

Posting-number: Volume 12, Issue 51
Submitted-by: viktor@melon.princeton.edu (Viktor Dukhovni)
Archive-name: sparc-mtools/patch01

	I have had such a flood of requests for the mtools patches
that posting them here seems mandatory.  I have been holding back,  for
though the code works,  and is reasonably fast,  there is room for improvement.
I wanted to take a closer look at it after the initial posting,  and see
what improvements would come back from net.readers.

	Anyway,  I've not had the time for the next round of changes,  and
may never get to it now.  Here is a short list of suggested improvements for the
next volunteer:

i)  "mkdfs" is a gross badly written hack!  I had to write it very quickly,
as I do not convenient access to DOS machines for formatting disks,  and 
could not get off the ground without it.  It needs to be driven by an external
table of disk descriptions,  giving the physical and file system layout.
The name of the system low level format program should also come from this
table,  or the "-f" flag can be dropped without much loss.  Disk types should
be *named*  the "-h" flag needs to be retired.  The bootblock should be built
by filling in the structure in "msdos.h".  Finally an option for actual boot
code needs to exist for compatibility with some older DOS systems.  (Perhaps
a "-b" flag to load a custom boot file,  though a UNIX "expert" would simply
use "dd" and bypass "mkdfs" altogether in this case.)

ii)  Mtools should gracefully handle interrupts,  zap the working FAT chain,
and write out the FAT table.

iii)  Directory caching would be sensible,  but only if done carefully.

iv)  Mfsck!!!

	---------------
	Anyway here are all the patches:  1,2 are the ones that were posted
to comp.sources.bugs soon after release,  3 fixes a problem with "-l"
(custom labels),  and wrong media byte in "mkdfs".  bootblk.h  is made
byte order independent, though I would like to see it disappear altogether
in the long run.
	---------------

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  patch1 patch2 patch3
# Wrapped by viktor@melon on Sat Apr 28 02:34:17 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'patch1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'patch1'\"
else
echo shar: Extracting \"'patch1'\" \(4811 characters\)
sed "s/^X//" >'patch1' <<'END_OF_FILE'
XNewsgroups: comp.sources.bugs
XSubject: Mtools Patch1,  (Priority High)
X
X	Patch1 fixes fixes alignment dependency problems in
Xmsdos.h that made the code fail on the 3/80.  Somehow this worked
Xon the SparcStation,  I hang my head in shame.  Also minor change in
Xmkdfs.c allowing custom disk labels,  and defaulting to blank.
X
X*** /tmp/,RCSt1a17064	Mon Mar 26 17:32:44 1990
X--- mkdfs.c	Mon Mar 26 17:32:43 1990
X***************
X*** 27,33 ****
X  #define FAT720 0xf9
X  #define FAT1440 0xf0
X  static char floppy[] = "/dev/rfd0c" ;
X! static char disklabel[] = "ANYDSKLABEL" ;
X  
X  void move(), Write(), usage(), formatit() ;
X  
X--- 27,33 ----
X  #define FAT720 0xf9
X  #define FAT1440 0xf0
X  static char floppy[] = "/dev/rfd0c" ;
X! char disklabel[12] = "" ;
X  
X  void move(), Write(), usage(), formatit() ;
X  
X***************
X*** 41,50 ****
X    int fat = FAT720 ;
X    int dir_len = 7 ;
X    int hdflag=0, fflag = 0 ;
X  
X    progname = argv[0] ;
X  
X!   while( (c=getopt(argc,argv,"hf")) != EOF ) {
X      switch(c) {
X      case 'f' :
X        fflag++ ;
X--- 41,51 ----
X    int fat = FAT720 ;
X    int dir_len = 7 ;
X    int hdflag=0, fflag = 0 ;
X+   extern char *optarg;
X  
X    progname = argv[0] ;
X  
X!   while( (c=getopt(argc,argv,"hfl:")) != EOF ) {
X      switch(c) {
X      case 'f' :
X        fflag++ ;
X***************
X*** 51,56 ****
X--- 52,60 ----
X        break;
X      case 'h' :
X        hdflag++ ;
X+       break;
X+     case 'l' :
X+       strncpy(disklabel, optarg, 11) ;
X        break;
X      case '?':
X      default:
X*** /tmp/,RCSt1a17064	Mon Mar 26 17:32:45 1990
X--- msdos.h	Mon Mar 26 17:18:43 1990
X***************
X*** 18,42 ****
X  	unsigned char	size[4];	/* size of the file */
X  };
X  
X- struct dos_word {
X-   unsigned char dw_low ;		/* LSB */
X-   unsigned char dw_high ;		/* MSB */
X- } ;
X- 
X  struct superblock {
X    unsigned char jump[3] ;       /* Jump to boot code */
X!   unsigned char banner[8];      /* OEM name & version */
X!   struct dos_word secsiz;       /* Bytes per sector hopefully 512 */
X    unsigned char clsiz ;         /* Cluster size in sectors */
X!   struct dos_word nrsvsect;     /* Number of reserved (boot) sectors */
X    unsigned char nfat;           /* Number of FAT tables hopefully 2 */
X!   struct dos_word dirents;      /* Number of directory slots */
X!   struct dos_word psect;        /* Total sectors on disk */
X    unsigned char descr;          /* Media descriptor=first byte of FAT */
X!   struct dos_word fatlen;       /* Sectors in FAT */
X!   struct dos_word nsect;        /* Sectors/track */
X!   struct dos_word ntrack;       /* tracks/cyl */
X!   struct dos_word nhs;          /* number of hidden sectors ? */
X  } ;
X  
X  union bootblock {
X--- 18,37 ----
X  	unsigned char	size[4];	/* size of the file */
X  };
X  
X  struct superblock {
X    unsigned char jump[3] ;       /* Jump to boot code */
X!   unsigned char banner[8];	/* OEM name & version */
X!   unsigned char secsiz[2];	/* Bytes per sector hopefully 512 */
X    unsigned char clsiz ;         /* Cluster size in sectors */
X!   unsigned char nrsvsect[2];	/* Number of reserved (boot) sectors */
X    unsigned char nfat;           /* Number of FAT tables hopefully 2 */
X!   unsigned char dirents[2];	/* Number of directory slots */
X!   unsigned char psect[2];	/* Total sectors on disk */
X    unsigned char descr;          /* Media descriptor=first byte of FAT */
X!   unsigned char fatlen[2];	/* Sectors in FAT */
X!   unsigned char nsect[2];	/* Sectors/track */
X!   unsigned char ntrack[2];	/* tracks/cyl */
X!   unsigned char nhs[2];		/* number of hidden sectors ? */
X  } ;
X  
X  union bootblock {
X***************
X*** 44,50 ****
X    struct superblock sb ;
X  } ;
X  
X! #define WORD_VAL(x) (x.dw_low + (x.dw_high <<8))
X  
X  #define SECSIZ(x)	WORD_VAL(x.secsiz)
X  #define CLSIZ(x)	(x.clsiz)
X--- 39,45 ----
X    struct superblock sb ;
X  } ;
X  
X! #define WORD_VAL(x) ((x)[0] + ((x)[1] << 8))
X  
X  #define SECSIZ(x)	WORD_VAL(x.secsiz)
X  #define CLSIZ(x)	(x.clsiz)
X*** /tmp/,RCSt1a17064	Mon Mar 26 17:32:45 1990
X--- Mkdfs.1	Mon Mar 26 17:32:44 1990
X***************
X*** 9,14 ****
X--- 9,18 ----
X  [
X  .B -f
X  ]
X+ [
X+ .B -l
X+ .I label
X+ ]
X  .SH DESCRIPTION
X  .I Mkdfs
X  Mkdfs formats and initializes a DOS file system on a 3.5 inch Sun 4/60 or
X***************
X*** 25,31 ****
X  .TP
X  .B f
X  First reformat the drive,  useful for new or abused drives.  (Using the drive
X! in a Mac counts in the last category)
X  .SH SEE ALSO
X  mdir(1), mread(1), mtype(1), mren(1), mkd(1), mrd(1), mdel(1), mcopy(1)
X  .SH AUTHOR
X--- 29,38 ----
X  .TP
X  .B f
X  First reformat the drive,  useful for new or abused drives.  (Using the drive
X! in a Mac counts in the last category).
X! .TP
X! .B l \fIlabel\fR
X! Use \fIlabel\fR as the disk volume label (up to 11 characters).
X  .SH SEE ALSO
X  mdir(1), mread(1), mtype(1), mren(1), mkd(1), mrd(1), mdel(1), mcopy(1)
X  .SH AUTHOR
END_OF_FILE
if test 4811 -ne `wc -c <'patch1'`; then
    echo shar: \"'patch1'\" unpacked with wrong size!
fi
# end of 'patch1'
fi
if test -f 'patch2' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'patch2'\"
else
echo shar: Extracting \"'patch2'\" \(1854 characters\)
sed "s/^X//" >'patch2' <<'END_OF_FILE'
XNewsgroups: comp.sources.bugs
XSubject: Mtools official patch 2,  please apply.
X
X	A number of people complained about problems with binary files,
Xthis was due a small slip in wmrite.c introduced while cleaning up the code.
XIt continued to work on High Density disks where clus_size = 1,  but
Xbroke badly on 720K disks where clus_size = 2,  the effect was that only 8
Xout of 9 blocks made it to the floppy.  I also changed the makefile to install
Xthe Mkdfs.1 man-page,  and to correct the object list for MREN.
X
X*** /tmp/,RCSt1a06212	Mon Mar 26 20:03:16 1990
X--- Makefile	Mon Mar 26 18:20:15 1990
X***************
X*** 23,29 ****
X  MTYPE	= mtype.o match.o $(CMNOBJ)
X  MMD	= mmd.o fixname.o putfat.o mkentry.o $(CMNOBJ)
X  MRD	= mrd.o putfat.o $(CMNOBJ)
X! MREN	= mren.o fixname.o putfat.c isdir.o $(CMNOBJ)
X  MCOPY	= mcopy.o
X  
X  all:	$(PROGS)
X--- 23,29 ----
X  MTYPE	= mtype.o match.o $(CMNOBJ)
X  MMD	= mmd.o fixname.o putfat.o mkentry.o $(CMNOBJ)
X  MRD	= mrd.o putfat.o $(CMNOBJ)
X! MREN	= mren.o fixname.o putfat.o isdir.o $(CMNOBJ)
X  MCOPY	= mcopy.o
X  
X  all:	$(PROGS)
X***************
X*** 74,79 ****
X--- 74,80 ----
X  	cp Mread.1 $(MANDIR)/mread.1
X  	cp Mdir.1 $(MANDIR)/mdir.1
X  	cp Mwrite.1 $(MANDIR)/mwrite.1
X+ 	cp Mkdfs.1 $(MANDIR)/mkdfs.1
X  	cp Mdel.1 $(MANDIR)/mdel.1
X  	cp Mtype.1 $(MANDIR)/mtype.1
X  	cp Mmd.1 $(MANDIR)/mmd.1
X*** /tmp/,RCSt1a06212	Mon Mar 26 20:03:16 1990
X--- mwrite.c	Mon Mar 26 19:57:58 1990
X***************
X*** 351,357 ****
X  {
X  	static int blk;
X  	int c, nclust, current, eof=0;
X! 	int buflen = ( end - start ) * MSECSIZ ;
X  	register char *tbuf=outbuf;
X  
X  	blk = (start - 2)*clus_size + dir_start + dir_len;
X--- 351,357 ----
X  {
X  	static int blk;
X  	int c, nclust, current, eof=0;
X! 	int buflen = ( end - start ) * MSECSIZ * clus_size ;
X  	register char *tbuf=outbuf;
X  
X  	blk = (start - 2)*clus_size + dir_start + dir_len;
END_OF_FILE
if test 1854 -ne `wc -c <'patch2'`; then
    echo shar: \"'patch2'\" unpacked with wrong size!
fi
# end of 'patch2'
fi
if test -f 'patch3' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'patch3'\"
else
echo shar: Extracting \"'patch3'\" \(3052 characters\)
sed "s/^X//" >'patch3' <<'END_OF_FILE'
X*** /tmp/,RCSt1a26646	Wed Apr 25 17:18:31 1990
X--- mkdfs.c	Wed Apr 25 17:16:46 1990
X***************
X*** 9,15 ****
X  	 * table parsing routines etc.,  not too hard,  just unpleasant.
X  	 */
X  	main() {
X! 		printf("Do not know how to format disks on your system\n";
X  		exit(1) ;
X  	}
X  #else
X--- 9,15 ----
X  	 * table parsing routines etc.,  not too hard,  just unpleasant.
X  	 */
X  	main() {
X! 		printf("Do not know how to format disks on your system\n");
X  		exit(1) ;
X  	}
X  #else
X***************
X*** 24,33 ****
X  #include "bootblk.h"
X  
X  #define VOLLBL 0x8
X! #define FAT720 0xf9
X! #define FAT1440 0xf0
X  static char floppy[] = "/dev/rfd0c" ;
X! char disklabel[12] = "" ;
X  
X  void move(), Write(), usage(), formatit() ;
X  
X--- 24,33 ----
X  #include "bootblk.h"
X  
X  #define VOLLBL 0x8
X! #define FAT 0xf9
X! 
X  static char floppy[] = "/dev/rfd0c" ;
X! static char disklabel[12] ;
X  
X  void move(), Write(), usage(), formatit() ;
X  
X***************
X*** 38,44 ****
X  {
X    int c, fd, sec ;
X    int fat_len = 3 ;
X!   int fat = FAT720 ;
X    int dir_len = 7 ;
X    int hdflag=0, fflag = 0 ;
X    extern char *optarg;
X--- 38,44 ----
X  {
X    int c, fd, sec ;
X    int fat_len = 3 ;
X!   int fat = FAT ;
X    int dir_len = 7 ;
X    int hdflag=0, fflag = 0 ;
X    extern char *optarg;
X***************
X*** 45,50 ****
X--- 45,53 ----
X  
X    progname = argv[0] ;
X  
X+   /* Initialize with spaces */
X+   sprintf(disklabel,"%-11.11s","") ;
X+ 
X    while( (c=getopt(argc,argv,"hfl:")) != EOF ) {
X      switch(c) {
X      case 'f' :
X***************
X*** 54,60 ****
X        hdflag++ ;
X        break;
X      case 'l' :
X!       strncpy(disklabel, optarg, 11) ;
X        break;
X      case '?':
X      default:
X--- 57,63 ----
X        hdflag++ ;
X        break;
X      case 'l' :
X!       sprintf(disklabel,"%-11.11s",optarg) ;
X        break;
X      case '?':
X      default:
X***************
X*** 77,83 ****
X    if ( hdflag ) {
X      dir_len=14 ;
X      fat_len=9 ;
X-     fat=FAT1440 ;
X    }
X    
X    bzero(buf,sizeof(buf)) ;
X--- 80,85 ----
X*** /tmp/,RCSt1a26649	Wed Apr 25 17:18:59 1990
X--- bootblk.h	Mon Apr 23 13:47:39 1990
X***************
X*** 6,17 ****
X   * and make sure to create the "hidden" files in mkdfs.c
X   * (this is not easy!)
X   */
X! static unsigned short hdboot[] = {
X! 0xeb34,0x9020,0x2020,0x2020,0x2020,0x2000,0x0201,0x0100,
X! 0x02e0,0x0040,0x0bf0,0x0900,0x1200,0x0200,0x0000,0x0000,
X  } ;
X  
X! static unsigned short ldboot[] = {
X! 0xeb34,0x9020,0x2020,0x2020,0x2020,0x2000,0x0202,0x0100,
X! 0x0270,0x00a0,0x05f9,0x0300,0x0900,0x0200,0x0000,0x0000,
X  } ;
X--- 6,17 ----
X   * and make sure to create the "hidden" files in mkdfs.c
X   * (this is not easy!)
X   */
X! static unsigned char hdboot[] = {
X! 0xeb,0x34,0x90,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x02,0x01,0x01,0x00,
X! 0x02,0xe0,0x00,0x40,0x0b,0xf9,0x09,0x00,0x12,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
X  } ;
X  
X! static unsigned char ldboot[] = {
X! 0xeb,0x34,0x90,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x02,0x02,0x01,0x00,
X! 0x02,0x70,0x00,0xa0,0x05,0xf9,0x03,0x00,0x09,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
X  } ;
END_OF_FILE
if test 3052 -ne `wc -c <'patch3'`; then
    echo shar: \"'patch3'\" unpacked with wrong size!
fi
# end of 'patch3'
fi
echo shar: End of shell archive.
exit 0
	Viktor Dukhovni <viktor@math.princeton.edu>	: ARPA
		<...!uunet!princeton!math!viktor>	: UUCP
	Fine Hall, Washington Rd., Princeton, NJ 08544  : US-Post
		+1-(609)-258-5792		 	: VOICE


