Patch #3 to Mtools v2.0

Emmet P. Gray egray at osiris.cso.uiuc.edu
Thu Nov 29 01:26:00 AEST 1990


This is patch #3 to the Mtools v2.0 distribution package.  This patch
will fix a bug where Mtools sometimes bypasses the disk "cache" and
reads/writes to the disk directly.  Many thanks to Mike Pearlman
for pointing this out to me.

Mtools was posted to the unix-pc.sources news group (and mailed to the
moderator of comp.sources.unix) on the 17th of September 1990.  Since
then, patch #1 and #2 have been posted to unix-pc.sources,
comp.sources.bugs, and emailed to Rich Salz.

In addition, the current version of Mtools and all the patch are
available via anonymous ftp from cerl.cecer.army.mil (129.229.1.101).

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

-------------------------------------------------------------------------------
Prereq: 2.0.2
*** old/patchlevel.h	Thu Nov 22 04:53:31 1990
--- patchlevel.h	Mon Nov 26 09:52:26 1990
***************
*** 1
! #define VERSION 2.0.2

--- 1 -----
! #define VERSION 2.0.3
*** old/Configure	Thu Nov 22 04:53:16 1990
--- Configure	Thu Nov 22 18:31:15 1990
***************
*** 99,103
  		{'B', "/dev/rdsk/f13ht", 0L, 12, 0, (int (*)()) 0, 80, 2, 18},
  		{'B', "/dev/rdsk/f13dt", 0L, 12, 0, (int (*)()) 0, 80, 2, 9},
! 		{'C', "/dev/rdsk/0p1", 0L, 12, 0, (int (*)()) 0, 0, 0, 0},
  		{'D', "/usr/vpix/defaults/C:", 8704L, 12, 0, (int (*)()) 0, 0, 0, 0},
  		{'E', "$HOME/vpix/C:", 8704L, 12, 0, (int (*)()) 0, 0, 0, 0},

--- 99,103 -----
  		{'B', "/dev/rdsk/f13ht", 0L, 12, 0, (int (*)()) 0, 80, 2, 18},
  		{'B', "/dev/rdsk/f13dt", 0L, 12, 0, (int (*)()) 0, 80, 2, 9},
! 		{'C', "/dev/rdsk/0p1", 0L, 16, 0, (int (*)()) 0, 0, 0, 0},
  		{'D', "/usr/vpix/defaults/C:", 8704L, 12, 0, (int (*)()) 0, 0, 0, 0},
  		{'E', "$HOME/vpix/C:", 8704L, 12, 0, (int (*)()) 0, 0, 0, 0},
*** old/buf_read.c	Thu Nov 22 04:53:22 1990
--- buf_read.c	Mon Nov 26 09:24:25 1990
***************
*** 16,20
  
  void
! disk_read(start, buf, len, cache)
  long start;
  unsigned char *buf;

--- 16,20 -----
  
  void
! disk_read(start, buf, len)
  long start;
  unsigned char *buf;
***************
*** 19,23
  long start;
  unsigned char *buf;
! int len, cache;
  {
  	register long i;

--- 19,23 -----
  long start;
  unsigned char *buf;
! int len;
  {
  	register long i;
***************
*** 29,33
  
  					/* don't use cache? */
! 	if (disk_size == 1 || !cache) {
  		where = (start * MSECTOR_SIZE) + disk_offset;
  		if (lseek(fd, where, 0) < 0) {

--- 29,33 -----
  
  					/* don't use cache? */
! 	if (disk_size == 1) {
  		where = (start * MSECTOR_SIZE) + disk_offset;
  		if (lseek(fd, where, 0) < 0) {
*** old/buf_write.c	Thu Nov 22 04:53:22 1990
--- buf_write.c	Tue Nov 27 09:28:09 1990
***************
*** 13,17
  
  void
! disk_write(start, buf, len, cache)
  long start;
  unsigned char *buf;

--- 13,17 -----
  
  void
! disk_write(start, buf, len)
  long start;
  unsigned char *buf;
***************
*** 16,20
  long start;
  unsigned char *buf;
! int len, cache;
  {
  	register long i;

--- 16,20 -----
  long start;
  unsigned char *buf;
! int len;
  {
  	register long i;
***************
*** 26,30
  
  					/* don't use cache? */
! 	if (disk_size == 1 || !cache) {
  		where = (start * MSECTOR_SIZE) + disk_offset;
  		if (lseek(fd, where, 0) < 0) {

--- 26,30 -----
  
  					/* don't use cache? */
! 	if (disk_size == 1) {
  		where = (start * MSECTOR_SIZE) + disk_offset;
  		if (lseek(fd, where, 0) < 0) {
*** old/devices.c	Thu Nov 22 04:53:22 1990
--- devices.c	Tue Nov 27 09:16:54 1990
***************
*** 13,17
  	{'B', "/dev/rdsk/f13ht", 0L, 12, 0, (int (*) ()) 0, 80, 2, 18},
  	{'B', "/dev/rdsk/f13dt", 0L, 12, 0, (int (*) ()) 0, 80, 2, 9},
! 	{'C', "/dev/rdsk/0p1", 0L, 12, 0, (int (*) ()) 0, 0, 0, 0},
  	{'D', "/usr/vpix/defaults/C:", 8704L, 12, 0, (int (*) ()) 0, 0, 0, 0},
  	{'E', "$HOME/vpix/C:", 8704L, 12, 0, (int (*) ()) 0, 0, 0, 0},

--- 13,17 -----
  	{'B', "/dev/rdsk/f13ht", 0L, 12, 0, (int (*) ()) 0, 80, 2, 18},
  	{'B', "/dev/rdsk/f13dt", 0L, 12, 0, (int (*) ()) 0, 80, 2, 9},
! 	{'C', "/dev/rdsk/0p1", 0L, 16, 0, (int (*) ()) 0, 0, 0, 0},
  	{'D', "/usr/vpix/defaults/C:", 8704L, 12, 0, (int (*) ()) 0, 0, 0, 0},
  	{'E', "$HOME/vpix/C:", 8704L, 12, 0, (int (*) ()) 0, 0, 0, 0},
***************
*** 22,26
  #ifdef MASSCOMP
  struct device devices[] = {
! 	{'A', "/dev/flp", 0L, 12, 0, (int (*) ()) 0, 80, 2, 8},
  	{'\0', (char *) NULL, 0L, 0, 0, (int (*) ()) 0, 0, 0, 0}
  };

--- 22,26 -----
  #ifdef MASSCOMP
  struct device devices[] = {
! 	{'A', "/dev/rflp", 0L, 12, 0, (int (*) ()) 0, 80, 2, 8},
  	{'\0', (char *) NULL, 0L, 0, 0, (int (*) ()) 0, 0, 0, 0}
  };
*** old/dir_make.c	Thu Nov 22 04:53:22 1990
--- dir_make.c	Mon Nov 26 09:23:20 1990
***************
*** 50,54
  					/* write the cluster */
  	sector = (long) (last - 2) * clus_size + dir_start + dir_len;
! 	disk_write(sector, tbuf, buflen, DIRECT);
  
  					/* fix up the globals.... */

--- 50,54 -----
  					/* write the cluster */
  	sector = (long) (last - 2) * clus_size + dir_start + dir_len;
! 	disk_write(sector, tbuf, buflen);
  
  					/* fix up the globals.... */
***************
*** 66,70
  	}
  	offset = dir_buf + (num * MSECTOR_SIZE);
! 	disk_read(dir_chain[num], offset, clus_size * MSECTOR_SIZE, DIRECT);
  	return(0);
  }

--- 66,70 -----
  	}
  	offset = dir_buf + (num * MSECTOR_SIZE);
! 	disk_read(dir_chain[num], offset, clus_size * MSECTOR_SIZE);
  	return(0);
  }
*** old/dir_read.c	Thu Nov 22 04:53:23 1990
--- dir_read.c	Mon Nov 26 09:25:25 1990
***************
*** 79,83
  	for (i = 0; i < length; i++) {
  		offset = dir_buf + (i * MSECTOR_SIZE);
! 		disk_read(dir_chain[i], offset, MSECTOR_SIZE, DIRECT);
  	}
  

--- 79,83 -----
  	for (i = 0; i < length; i++) {
  		offset = dir_buf + (i * MSECTOR_SIZE);
! 		disk_read(dir_chain[i], offset, MSECTOR_SIZE);
  	}
  
***************
*** 112,116
  		exit(1);
  	}
! 	disk_read((long) dir_start, dir_buf, dir_len * MSECTOR_SIZE, DIRECT);
  
  	dir_entries = dir_len * 16;

--- 112,116 -----
  		exit(1);
  	}
! 	disk_read((long) dir_start, dir_buf, dir_len * MSECTOR_SIZE);
  
  	dir_entries = dir_len * 16;
*** old/dir_write.c	Thu Nov 22 04:53:23 1990
--- dir_write.c	Mon Nov 26 11:37:39 1990
***************
*** 45,49
  	for (i = 0; i < length; i++) {
  		offset = dir_buf + (i * MSECTOR_SIZE);
! 		disk_write(dir_chain[i], offset, MSECTOR_SIZE, DIRECT);
  	}
  	dir_dirty = 0;

--- 45,49 -----
  	for (i = 0; i < length; i++) {
  		offset = dir_buf + (i * MSECTOR_SIZE);
! 		disk_write(dir_chain[i], offset, MSECTOR_SIZE);
  	}
  	dir_dirty = 0;
*** old/fat_read.c	Thu Nov 22 04:53:23 1990
--- fat_read.c	Mon Nov 26 09:25:49 1990
***************
*** 60,64
  		 */
  					/* which bytes contain the entry */
! 		start = num / 2;
  		if (start <= 3 || start + 1 > (fat_len * MSECTOR_SIZE))
  			return(1);

--- 60,64 -----
  		 */
  					/* which bytes contain the entry */
! 		start = num * 2;
  		if (start <= 3 || start + 1 > (fat_len * MSECTOR_SIZE))
  			return(1);
***************
*** 88,92
  	}
  					/* read the FAT sectors */
! 	disk_read((long) start, fat_buf, buflen, DIRECT);
  
  					/* the encoding scheme */

--- 88,92 -----
  	}
  					/* read the FAT sectors */
! 	disk_read((long) start, fat_buf, buflen);
  
  					/* the encoding scheme */
*** old/fat_write.c	Thu Nov 22 04:53:24 1990
--- fat_write.c	Mon Nov 26 12:15:12 1990
***************
*** 52,56
  		 */
  					/* which bytes contain the entry */
! 		start = num / 2;
  		if (start <= 3 || start + 1 > (fat_len * MSECTOR_SIZE))
  			return(1);

--- 52,56 -----
  		 */
  					/* which bytes contain the entry */
! 		start = num * 2;
  		if (start <= 3 || start + 1 > (fat_len * MSECTOR_SIZE))
  			return(1);
***************
*** 80,84
  	buflen = fat_len * MSECTOR_SIZE;
  
! 	disk_write((long) fat_start, fat_buf, buflen, DIRECT);
  
  	/*

--- 80,84 -----
  	buflen = fat_len * MSECTOR_SIZE;
  
! 	disk_write((long) fat_start, fat_buf, buflen);
  
  	/*
***************
*** 89,93
  		while (dups--) {
  			fat_start += fat_len;
! 			disk_write((long) fat_start, fat_buf, buflen, DIRECT);
  		}
  	}

--- 89,93 -----
  		while (dups--) {
  			fat_start += fat_len;
! 			disk_write((long) fat_start, fat_buf, buflen);
  		}
  	}
*** old/file_read.c	Thu Nov 22 04:53:24 1990
--- file_read.c	Mon Nov 26 09:26:20 1990
***************
*** 28,32
  	while (1) {
  		start = (long) (fat - 2) * clus_size + dir_start + dir_len;
! 		disk_read(start, in_buf, in_len, CACHE);
  
  					/* do the translations */

--- 28,32 -----
  	while (1) {
  		start = (long) (fat - 2) * clus_size + dir_start + dir_len;
! 		disk_read(start, in_buf, in_len);
  
  					/* do the translations */
*** old/file_write.c	Thu Nov 22 04:53:24 1990
--- file_write.c	Mon Nov 26 09:26:31 1990
***************
*** 115,119
  	}
  
! 	disk_write(start, tbuf, buflen, CACHE);
  	return(i);
  }

--- 115,119 -----
  	}
  
! 	disk_write(start, tbuf, buflen);
  	return(i);
  }
*** old/mattrib.c	Thu Nov 22 04:53:25 1990
--- mattrib.c	Mon Nov 26 09:28:54 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
*** old/mcd.c	Thu Nov 22 04:53:26 1990
--- mcd.c	Mon Nov 26 08:01:34 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
*** old/mcopy.c	Thu Nov 22 04:53:27 1990
--- mcopy.c	Mon Nov 26 08:01:41 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
*** old/mdel.c	Thu Nov 22 04:53:27 1990
--- mdel.c	Mon Nov 26 09:29:26 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
*** old/mdir.c	Thu Nov 22 04:53:27 1990
--- mdir.c	Mon Nov 26 08:01:54 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
*** old/mformat.c	Thu Nov 22 04:53:28 1990
--- mformat.c	Mon Nov 26 08:02:00 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
*** old/mlabel.c	Thu Nov 22 04:53:28 1990
--- mlabel.c	Mon Nov 26 09:29:36 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
*** old/mmd.c	Thu Nov 22 04:53:28 1990
--- mmd.c	Mon Nov 26 09:29:53 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
***************
*** 184,188
  
  					/* write the cluster */
! 	disk_write(start, (unsigned char *) buf, buflen, DIRECT);
  	return;
  }

--- 185,189 -----
  
  					/* write the cluster */
! 	disk_write(start, (unsigned char *) buf, buflen);
  	return;
  }
*** old/mrd.c	Thu Nov 22 04:53:28 1990
--- mrd.c	Mon Nov 26 09:30:09 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
***************
*** 140,144
  		sector = (long) (fat - 2) * clus_size + dir_start + dir_len;
  		buflen = clus_size * MSECTOR_SIZE;
! 		disk_read(sector, tbuf, buflen, DIRECT);
  
  					/* check first character of name */

--- 141,145 -----
  		sector = (long) (fat - 2) * clus_size + dir_start + dir_len;
  		buflen = clus_size * MSECTOR_SIZE;
! 		disk_read(sector, tbuf, buflen);
  
  					/* check first character of name */
*** old/mread.c	Thu Nov 22 04:53:29 1990
--- mread.c	Mon Nov 26 08:02:28 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
*** old/mren.c	Thu Nov 22 04:53:29 1990
--- mren.c	Mon Nov 26 09:30:20 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
*** old/msdos.h	Thu Nov 22 04:53:29 1990
--- msdos.h	Mon Nov 26 15:08:43 1990
***************
*** 9,14
  #define MAX_DIR_SECS	64		/* largest directory (in sectors) */
  
- #define CACHE		1
- #define DIRECT		0
  #define NEW		1
  #define OLD		0

--- 9,12 -----
  #define MAX_DIR_SECS	64		/* largest directory (in sectors) */
  
  #define NEW		1
  #define OLD		0
*** old/mtype.c	Thu Nov 22 04:53:30 1990
--- mtype.c	Mon Nov 26 08:02:42 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
*** old/mwrite.c	Thu Nov 22 04:53:30 1990
--- mwrite.c	Mon Nov 26 13:09:15 1990
***************
*** 10,13
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
   */
  

--- 10,14 -----
   *  patch #1		12 Oct 90
   *  patch #2		21 Nov 90
+  *  patch #3		28 Nov 90
   */
  
***************
*** 247,251
  	FILE *fp;
  	unsigned int fat, next_fat();
! 	long filesize, file_write(), size, time(), now;
  	struct directory *dir, *mk_entry();
  	struct stat stbuf;

--- 248,252 -----
  	FILE *fp;
  	unsigned int fat, next_fat();
! 	long filesize, file_write(), size, time(), now, free_space();
  	struct directory *dir, *mk_entry();
  	struct stat stbuf;
***************
*** 266,269
  		return(NULL);
  	}
  	filesize = stbuf.st_size;
  					/* preserve mod time? */

--- 267,271 -----
  		return(NULL);
  	}
+ 					/* will it fit? */
  	filesize = stbuf.st_size;
  	if (filesize > free_space()) {
***************
*** 267,270
  	}
  	filesize = stbuf.st_size;
  					/* preserve mod time? */
  	if (mod_time)

--- 269,276 -----
  					/* will it fit? */
  	filesize = stbuf.st_size;
+ 	if (filesize > free_space()) {
+ 		full = 1;
+ 		return(NULL);
+ 	}
  					/* preserve mod time? */
  	if (mod_time)
***************
*** 310,312
  	close(fd);
  	exit(1);
  }

--- 316,341 -----
  	close(fd);
  	exit(1);
+ }
+ 
+ 
+ /*
+  * Get the amount of remaining free space
+  */
+ 
+ static long
+ free_space()
+ {
+ 	register unsigned int i;
+ 	long total;
+ 	extern unsigned int num_clus;
+ 	unsigned int fat_decode();
+ 
+ 	total = 0L;
+ 	for (i = 2; i < num_clus + 2; i++) {
+ 					/* if fat_decode returns zero */
+ 		if (!fat_decode(i))
+ 			total += clus_size;
+ 	}
+ 	total *= MSECTOR_SIZE;
+ 	return(total);
  }
End of Patch



More information about the Comp.sources.bugs mailing list