*BSD News Article 6418


Return to BSD News archive

Path: sserve!manuel.anu.edu.au!munnari.oz.au!spool.mu.edu!agate!doc.ic.ac.uk!uknet!mcsun!fuug!kiae!rdrel!guam.relcom.msk.su!vak
From: vak@guam.relcom.msk.su.rd.relcom.msk.su (Serge V.Vakulenko)
Newsgroups: comp.unix.bsd
Subject: [386BSD] patch for mtools to find C and D automagically
Message-ID: <1992Oct12.161622.4425@rdrel.relcom.msk.su>
Date: 12 Oct 92 16:16:22 GMT
Sender: usenet@rdrel.relcom.msk.su (Usenet News Administrator)
Organization: Relcom R&D
Lines: 103
X-Newsreader: Tin 1.1 PL4

Here is my patch for mtools from 386bsd srcdist,
which makes it possible to work with DOS partitions
on hard disks without recompiling mtools every time
you change partition table.  C and D disks are marked
in devices table as having offset -1, and
DOS partition then is searched through partition table.

Serge Vakulenko

*** /tmp/mtools/devices.c	Mon Oct 12 19:06:10 1992
--- ./devices.c	Tue Oct 13 07:12:08 1992
***************
*** 30,33 ****
--- 30,37 ----
  	{'B', "/dev/rfd1a", 0L, 12, 0, (int (*) ()) 0, 40, 2, 9},  /* 360k */
  	{'B', "/dev/rfd1a", 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}
  };
*** /tmp/mtools/init.c	Mon Oct 12 19:06:06 1992
--- ./init.c	Tue Oct 13 07:12:59 1992
***************
*** 27,30 ****
--- 27,31 ----
  extern struct device devices[];
  static struct bootsector *read_boot();
+ static long find_partition ();
  
  int
***************
*** 62,69 ****
  
  		name = expand(dev->name);
! 		if ((fd = open(name, mode | dev->mode)) < 0) {
! 			perror("init: open");
! 			exit(1);
! 		}
  					/* set default parameters, if needed */
  		if (dev->gioctl) {
--- 63,68 ----
  
  		name = expand(dev->name);
! 		if ((fd = open(name, mode | dev->mode)) < 0)
! 			goto try_again;
  					/* set default parameters, if needed */
  		if (dev->gioctl) {
***************
*** 72,75 ****
--- 71,79 ----
  		}
  					/* 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)
***************
*** 153,157 ****
  			break;
  
! try_again:	close(fd);
  		fd = -1;
  		dev++;
--- 157,162 ----
  			break;
  
! try_again:      if (fd >= 0)
! 			close(fd);
  		fd = -1;
  		dev++;
***************
*** 323,325 ****
--- 328,352 ----
  
  	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);
  }