*BSD News Article 11270


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA1485 ; Tue, 23 Feb 93 14:43:48 EST
Path: sserve!manuel.anu.edu.au!munnari.oz.au!bruce.cs.monash.edu.au!monu6!escargot!minyos.xx.rmit.OZ.AU!s902113
From: s902113@minyos.xx.rmit.OZ.AU (Luke Mewburn)
Newsgroups: comp.unix.bsd
Subject: [386bsd & others] mtools 2.0.7 diffs
Date: 18 Feb 1993 16:32:59 GMT
Organization: RMIT Computer Centre
Lines: 409
Message-ID: <1m0dnsINNak0@escargot.xx.rmit.OZ.AU>
NNTP-Posting-Host: minyos.xx.rmit.oz.au

Here's the diffs to get mtools 2.0.7 running off your 386bsd box. Will
recognize your hard disk partitions too. I didn't write some of these
patches, I just cleaned it up, and also fixed some bugs regarding the
use of gets(), and a major prob in the mkmanifest.c stuff (would dump
core if a filename was > than a really small limit).

You can get mtools 2.0.7 from your favourite gnu site, in Australia
that is archie.au, /gnu

Just untar the source, patch in this file, and make it.

diff -c mtools-2.0.7/Makefile mtools/Makefile
*** mtools-2.0.7/Makefile	Thu Sep 10 15:10:46 1992
--- mtools/Makefile	Thu Jan 14 14:54:06 1993
***************
*** 125,131 ****
  	install -c -m 644 Mkmanifest.1 $(MANDIR)/mkmanifest.$(MANEXT)
  
  clean:
! 	rm $(PROGS) *.o core a.out tags TAGS
  
  lint:
  	$(LINT) mattrib.c buf_read.c buf_write.c devices.c dir_read.c \
--- 129,135 ----
  	install -c -m 644 Mkmanifest.1 $(MANDIR)/mkmanifest.$(MANEXT)
  
  clean:
! 	rm -f $(PROGS) *.o core a.out tags TAGS
  
  lint:
  	$(LINT) mattrib.c buf_read.c buf_write.c devices.c dir_read.c \
diff -c mtools-2.0.7/devices.c mtools/devices.c
*** mtools-2.0.7/devices.c	Thu Sep 10 15:11:17 1992
--- mtools/devices.c	Thu Jan 14 14:54:44 1993
***************
*** 173,175 ****
--- 173,198 ----
  	{'\0', (char *) NULL, 0L, 0, 0, (int (*) ()) 0, 0, 0, 0}
  };
  #endif /* XENIX */
+ 
+ 
+ #ifdef __386BSD__
+ struct device devices[] = {
+ 	{'A', "/dev/rfd0a", 0L, 12, 0, (int (*) ()) 0, 80, 2, 18}, /* 1.44m */
+ 	{'A', "/dev/rfd0b", 0L, 12, 0, (int (*) ()) 0, 80, 2, 15}, /* 1.2m */
+ 	{'A', "/dev/rfd0c", 0L, 12, 0, (int (*) ()) 0, 80, 2, 9},  /* 720k */
+ 	{'A', "/dev/rfd0d", 0L, 12, 0, (int (*) ()) 0, 40, 2, 9},  /* 360k */
+ 	{'A', "/dev/rfd0e", 0L, 12, 0, (int (*) ()) 0, 40, 2, 9},  /* 360k */
+ 	{'A', "/dev/rfd0f", 0L, 12, 0, (int (*) ()) 0, 40, 2, 8},  /* 320k */
+ 	{'B', "/dev/rfd1a", 0L, 12, 0, (int (*) ()) 0, 80, 2, 18}, /* 1.44m */
+ 	{'B', "/dev/rfd1b", 0L, 12, 0, (int (*) ()) 0, 80, 2, 15}, /* 1.2m */
+ 	{'B', "/dev/rfd1c", 0L, 12, 0, (int (*) ()) 0, 80, 2, 9},  /* 720k */
+ 	{'B', "/dev/rfd1d", 0L, 12, 0, (int (*) ()) 0, 40, 2, 9},  /* 360k */
+ 	{'B', "/dev/rfd1e", 0L, 12, 0, (int (*) ()) 0, 40, 2, 9},  /* 360k */
+ 	{'B', "/dev/rfd1f", 0L, 12, 0, (int (*) ()) 0, 40, 2, 8},  /* 320k */
+ 	{'C', "/dev/rwd0d", -1L, 16, 0, (int (*) ()) 0, 0, 0, 0},
+ 	{'C', "/dev/ras0d", -1L, 16, 0, (int (*) ()) 0, 0, 0, 0},
+ 	{'D', "/dev/rwd1d", -1L, 16, 0, (int (*) ()) 0, 0, 0, 0},
+ 	{'D', "/dev/ras1d", -1L, 16, 0, (int (*) ()) 0, 0, 0, 0},
+ 	{'\0', (char *) NULL, 0L, 0, 0, (int (*) ()) 0, 0, 0, 0}
+ };
+ #endif /* __386BSD__ */
diff -c mtools-2.0.7/dir_write.c mtools/dir_write.c
*** mtools-2.0.7/dir_write.c	Thu Sep 10 14:59:15 1992
--- mtools/dir_write.c	Wed Jan 20 16:51:24 1993
***************
*** 68,74 ****
  	int dot, modified, len;
  	register int i;
  
! 	strcpy(buf, filename);
  	name = buf;
  					/* skip drive letter */
  	if (buf[0] && buf[1] == ':')
--- 68,75 ----
  	int dot, modified, len;
  	register int i;
  
! 	strncpy(buf, filename, MAX_PATH);
! 	buf[MAX_PATH-1] = '\0';		/* just in case */
  	name = buf;
  					/* skip drive letter */
  	if (buf[0] && buf[1] == ':')
diff -c mtools-2.0.7/expand.c mtools/expand.c
*** mtools-2.0.7/expand.c	Thu Sep 10 14:59:12 1992
--- mtools/expand.c	Wed Jan 20 16:43:58 1993
***************
*** 57,63 ****
   * Miscellaneous routines probably missing from Bezerkely
   */
  
! #ifdef BSD
  /*
   * Return ptr to first occurrence of any character from `brkset'
   * in the character string `string'; NULL if none exists.
--- 57,63 ----
   * Miscellaneous routines probably missing from Bezerkely
   */
  
! #if defined(BSD) && !defined(__386BSD__)
  /*
   * Return ptr to first occurrence of any character from `brkset'
   * in the character string `string'; NULL if none exists.
***************
*** 111,114 ****
  	bcopy(s2, s1, n);
  	return(s1);
  }
! #endif /* BSD */
--- 111,114 ----
  	bcopy(s2, s1, n);
  	return(s1);
  }
! #endif /* BSD && !__386BSD__ */
diff -c mtools-2.0.7/init.c mtools/init.c
*** mtools-2.0.7/init.c	Thu Sep 10 14:59:47 1992
--- mtools/init.c	Tue Feb 16 13:39:48 1993
***************
*** 26,31 ****
--- 26,33 ----
  extern unsigned char *fat_buf, *disk_buf, *dir_buf;
  extern struct device devices[];
  static struct bootsector *read_boot();
+ static long find_partition ();
+ static int lock_dev ();
  
  int
  init(drive, mode)
***************
*** 61,71 ****
  			break;
  
  		name = expand(dev->name);
! 		if ((fd = open(name, mode | dev->mode)) < 0) {
! 			sprintf(buf, "init: open \"%s\"", name);
! 			perror(buf);
! 			exit(1);
! 		}
  					/* lock the device on writes */
  		if (mode == 2 && lock_dev(fd)) {
  			fprintf(stderr, "Device \"%s\" is busy\n", dev->name);
--- 63,78 ----
  			break;
  
  		name = expand(dev->name);
! #if 0
!  		if ((fd = open(name, mode | dev->mode)) < 0) {
!  			sprintf(buf, "init: open \"%s\"", name);
!  			perror(buf);
!  			exit(1);
!  		}
! #else
! 		if ((fd = open(name, mode | dev->mode)) < 0)
! 			goto try_again;
! #endif
  					/* lock the device on writes */
  		if (mode == 2 && lock_dev(fd)) {
  			fprintf(stderr, "Device \"%s\" is busy\n", dev->name);
***************
*** 77,82 ****
--- 84,94 ----
  				goto try_again;
  		}
  					/* read the boot sector */
+ 		if (dev->offset < 0)
+ 			dev->offset = find_partition (fd);
+ 		if (dev->offset < 0)
+ 			goto try_again;
+ 
  		disk_offset = dev->offset;
  		if ((boot = read_boot()) == NULL)
  			goto try_again;
***************
*** 158,164 ****
  		else
  			break;
  
! try_again:	close(fd);
  		fd = -1;
  		dev++;
  	}
--- 170,177 ----
  		else
  			break;
  
! try_again:      if (fd >= 0)
! 			close(fd);
  		fd = -1;
  		dev++;
  	}
***************
*** 321,326 ****
--- 334,361 ----
  		return(NULL);
  
  	return(&boot);
+ }
+ 
+ static long find_partition (fd)
+ {
+ 	char buf [512];
+ 	int i;
+ 	struct partition {
+ 		unsigned char flag, bhead, bsect, bcyl;
+ 		unsigned char system, ehead, esect, ecyl;
+ 		unsigned long relsect, numsect;
+ 	} *p;
+ 
+ 	if (read (fd, buf, 512) != 512 ||
+ 	    ((unsigned short *) buf) [255] != 0xaa55)
+ 		return (-1);
+ 	p = (struct partition *) (buf + 0x1be);
+ 	for (i=0; i<4; ++i, ++p)
+ 		if (p->flag != 0 && p->flag != 0x80)
+ 			return (-1);
+ 		else if (p->system == 4)        /* find DOS-16 partition */
+ 			return (p->relsect * 512);
+ 	return (-1);
  }
  
  /*
diff -c mtools-2.0.7/mdel.c mtools/mdel.c
*** mtools-2.0.7/mdel.c	Thu Sep 10 14:59:47 1992
--- mtools/mdel.c	Thu Jan 14 15:23:36 1993
***************
*** 103,109 ****
  				if (dir->attr & 0x01) {
  					while (!nogo) {
  						printf("%s: \"%s\" is read only, erase anyway (y/n) ? ", argv[0], newfile);
! 						gets(ans);
  						if (ans[0] == 'y' || ans[0] == 'Y')
  							break;
  						if (ans[0] == 'n' || ans[0] == 'N')
--- 103,109 ----
  				if (dir->attr & 0x01) {
  					while (!nogo) {
  						printf("%s: \"%s\" is read only, erase anyway (y/n) ? ", argv[0], newfile);
! 						fgets(ans, 9, stdin);
  						if (ans[0] == 'y' || ans[0] == 'Y')
  							break;
  						if (ans[0] == 'n' || ans[0] == 'N')
diff -c mtools-2.0.7/mkmanifest.c mtools/mkmanifest.c
*** mtools-2.0.7/mkmanifest.c	Thu Sep 10 14:59:13 1992
--- mtools/mkmanifest.c	Wed Jan 20 16:55:32 1993
***************
*** 12,18 ****
--- 12,24 ----
  
  #include <stdio.h>
  #include <ctype.h>
+ #include <sys/param.h>		/* for MAXPATHLEN */
  
+ #ifndef MAXPATHLEN
+ #define MAXPATHLEN 1024
+ #endif
+ 
+ 
  main(argc, argv)
  int argc;
  char *argv[];
***************
*** 48,54 ****
  	static char *dev[9] = {"con", "aux", "com1", "com2", "lpt1", "prn",
  	"lpt2", "lpt3", "nul"};
  	char *s, *temp, *ext, *strcpy(), *strpbrk(), *strcat();
! 	char buf[15];
  	int i, dot;
  	static char ans[13];
  
--- 54,60 ----
  	static char *dev[9] = {"con", "aux", "com1", "com2", "lpt1", "prn",
  	"lpt2", "lpt3", "nul"};
  	char *s, *temp, *ext, *strcpy(), *strpbrk(), *strcat();
! 	char buf[MAXPATHLEN];
  	int i, dot;
  	static char ans[13];
  
***************
*** 95,101 ****
  	return(ans);
  }
  
! #ifdef BSD
  /*
   * Return ptr to first occurrence of any character from `brkset'
   * in the character string `string'; NULL if none exists.
--- 101,107 ----
  	return(ans);
  }
  
! #if defined(BSD) && ! defined(__386BSD__)
  /*
   * Return ptr to first occurrence of any character from `brkset'
   * in the character string `string'; NULL if none exists.
***************
*** 118,121 ****
  	while (*string++);
  	return(0);
  }
! #endif /* BSD */
--- 124,127 ----
  	while (*string++);
  	return(0);
  }
! #endif /* BSD  && ! __386BSD__ */
diff -c mtools-2.0.7/mlabel.c mtools/mlabel.c
*** mtools-2.0.7/mlabel.c	Thu Sep 10 14:59:16 1992
--- mtools/mlabel.c	Thu Jan 14 15:24:26 1993
***************
*** 98,104 ****
  
  					/* ask for new label */
  	printf("Enter the new volume label (11 characters): ");
! 	gets(filename);
  	if (filename[0] != '\0') {
  		sprintf((char *) fixed, "%-11.11s", filename);
  		if (strlen(filename) > 11 && verbose)
--- 98,104 ----
  
  					/* ask for new label */
  	printf("Enter the new volume label (11 characters): ");
! 	fgets(filename, 29, stdin);
  	if (filename[0] != '\0') {
  		sprintf((char *) fixed, "%-11.11s", filename);
  		if (strlen(filename) > 11 && verbose)
***************
*** 109,115 ****
  			exit(0);
  
  		printf("Delete volume label (y/n): ");
! 		gets(ans);
  		if (ans[0] == 'y' || ans[0] == 'Y') {
  			strcpy((char *) fixed, (char *) vol);
  			fixed[0] = 0xe5;
--- 109,115 ----
  			exit(0);
  
  		printf("Delete volume label (y/n): ");
! 		fgets(ans, 9, stdin);
  		if (ans[0] == 'y' || ans[0] == 'Y') {
  			strcpy((char *) fixed, (char *) vol);
  			fixed[0] = 0xe5;
diff -c mtools-2.0.7/mread.c mtools/mread.c
*** mtools-2.0.7/mread.c	Thu Sep 10 14:59:48 1992
--- mtools/mread.c	Thu Jan 14 15:24:55 1993
***************
*** 230,236 ****
  			/* CONSTCOND */
  			while (1) {
  				printf("File \"%s\" exists, overwrite (y/n) ? ", target);
! 				gets(ans);
  				if (ans[0] == 'n' || ans[0] == 'N')
  					return(NULL);
  				if (ans[0] == 'y' || ans[0] == 'Y')
--- 230,236 ----
  			/* CONSTCOND */
  			while (1) {
  				printf("File \"%s\" exists, overwrite (y/n) ? ", target);
! 				fgets(ans, 9, stdin);
  				if (ans[0] == 'n' || ans[0] == 'N')
  					return(NULL);
  				if (ans[0] == 'y' || ans[0] == 'Y')
diff -c mtools-2.0.7/mren.c mtools/mren.c
*** mtools-2.0.7/mren.c	Thu Sep 10 14:59:16 1992
--- mtools/mren.c	Thu Jan 14 15:25:11 1993
***************
*** 66,72 ****
  	if (strcmp(temp, new) && verbose) {
  		while (!nogo) {
  			printf("Do you accept \"%s\" as the new filename (y/n) ? ", new);
! 			gets(ans);
  			if (ans[0] == 'y' || ans[0] == 'Y')
  				break;
  			if (ans[0] == 'n' || ans[0] == 'N')
--- 66,72 ----
  	if (strcmp(temp, new) && verbose) {
  		while (!nogo) {
  			printf("Do you accept \"%s\" as the new filename (y/n) ? ", new);
! 			fgets(ans, 9, stdin);
  			if (ans[0] == 'y' || ans[0] == 'Y')
  				break;
  			if (ans[0] == 'n' || ans[0] == 'N')
diff -c mtools-2.0.7/mwrite.c mtools/mwrite.c
*** mtools-2.0.7/mwrite.c	Thu Sep 10 14:59:48 1992
--- mtools/mwrite.c	Thu Jan 14 15:25:31 1993
***************
*** 177,183 ****
  					/* CONSTCOND */
  					while (1) {
  						printf("File \"%s\" exists, overwrite (y/n) ? ", target);
! 						gets(ans);
  						if (ans[0] == 'n' || ans[0] == 'N') {
  							nogo = 1;
  							break;
--- 177,183 ----
  					/* CONSTCOND */
  					while (1) {
  						printf("File \"%s\" exists, overwrite (y/n) ? ", target);
! 						fgets(ans, 9, stdin);
  						if (ans[0] == 'n' || ans[0] == 'N') {
  							nogo = 1;
  							break;


--
               Luke Mewburn [Zak]     zak@rmit.edu.au
   "Nobody dies on the Discworld, they just become dimensionally
    disadvantaged."         Terry Pratchett in alt.fan.pratchett