Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Nov 1996 10:59:30 +0100
From:      Poul-Henning Kamp <phk@critter.tfs.com>
To:        joerg@freebsd.org, rgrimes@freebsd.org, bde@freebsd.org
Cc:        current@freebsd.org
Subject:   libdisk patch
Message-ID:  <1471.848915970@critter.tfs.com>

next in thread | raw e-mail | index | archive | help

Could you guys please try out this patch to libdisk ?

You will have to use the horrible "tst01" program for it.

Basically what I do is this:  When asked to "dedicate" a disk to 
FreeBSD, I will "sanitize" the bios-geometry, to at least make some
sense, provided that it doesn't already make sense, in whatever 
narrow sense of that concept I have chosen.

People can still go in manually and set the geometry afterwards if 
they don't like my choice.

Next I need to look at sysinstall and all the "magic= X/1/1" stuff.

Poul-Henning

Index: change.c
===================================================================
RCS file: /home/ncvs/src/lib/libdisk/change.c,v
retrieving revision 1.10
diff -u -r1.10 change.c
--- change.c	1995/12/07 10:33:18	1.10
+++ change.c	1996/11/25 09:06:58
@@ -19,23 +19,6 @@
 #include <sys/types.h>
 #include "libdisk.h"
 
-#if 0
-struct disk *
-Set_Phys_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect)
-{
-	struct disk *d = Int_Open_Disk(disk->name,cyl*hd*sect);
-	d->real_cyl = cyl;
-	d->real_hd = hd;
-	d->real_sect = sect;
-	d->bios_cyl = disk->bios_cyl;
-	d->bios_hd = disk->bios_hd;
-	d->bios_sect = disk->bios_sect;
-	d->flags = disk->flags;
-	Free_Disk(disk);
-	return d;
-}
-#endif
-
 void
 Set_Bios_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect)
 {
@@ -46,6 +29,38 @@
 }
 
 void
+Sanitize_Bios_Geom(struct disk *disk)
+{
+	int sane = 1;
+
+	if (disk->bios_cyl > 1024)
+		sane = 0;
+	if (disk->bios_hd > 16)
+		sane = 0;
+	if (disk->bios_sect > 63)
+		sane = 0;
+	if (disk->bios_cyl*disk->bios_hd*disk->bios_sect != 
+	    disk->chunks->size)
+		sane = 0;
+	if (sane)
+		return;
+
+	/* First try something that IDE can handle */
+	disk->bios_sect = 63;
+	disk->bios_hd = 16;
+	disk->bios_cyl = disk->chunks->size/(disk->bios_sect*disk->bios_hd);
+
+	if (disk->bios_cyl < 1024)
+		return;
+
+	/* Hmm, try harder... */
+	disk->bios_hd = 255;
+	disk->bios_cyl = disk->chunks->size/(disk->bios_sect*disk->bios_hd);
+
+	return;
+}
+
+void
 All_FreeBSD(struct disk *d, int force_all)
 {
 	struct chunk *c;
@@ -57,6 +72,11 @@
 			goto again;
 		}
 	c=d->chunks;
-	Create_Chunk(d,c->offset,c->size,freebsd,0xa5,
-		     force_all? CHUNK_FORCE_ALL: 0);
+	if (force_all) {
+		Sanitize_Bios_Geom(d);
+		Create_Chunk(d,c->offset,c->size,freebsd,0xa5,
+		     CHUNK_FORCE_ALL);
+	} else {
+		Create_Chunk(d,c->offset,c->size,freebsd,0xa5, 0);
+	}
 }
Index: disk.c
===================================================================
RCS file: /home/ncvs/src/lib/libdisk/disk.c,v
retrieving revision 1.22
diff -u -r1.22 disk.c
--- disk.c	1996/04/29 05:03:02	1.22
+++ disk.c	1996/11/25 09:37:49
@@ -231,7 +231,9 @@
 #if 0
 	printf("  real_geom=%lu/%lu/%lu",d->real_cyl,d->real_hd,d->real_sect);
 #endif
-	printf("  bios_geom=%lu/%lu/%lu\n",d->bios_cyl,d->bios_hd,d->bios_sect);
+	printf("  bios_geom=%lu/%lu/%lu = %lu\n",
+		d->bios_cyl,d->bios_hd,d->bios_sect,
+		d->bios_cyl*d->bios_hd*d->bios_sect);
 	printf("  boot1=%p, boot2=%p, bootmgr=%p\n",
 		d->boot1,d->boot2,d->bootmgr);
 	Debug_Chunk(d->chunks);
Index: libdisk.h
===================================================================
RCS file: /home/ncvs/src/lib/libdisk/libdisk.h,v
retrieving revision 1.22
diff -u -r1.22 libdisk.h
--- libdisk.h	1996/04/29 06:45:33	1.22
+++ libdisk.h	1996/11/25 09:36:55
@@ -28,11 +28,6 @@
 	char		*name;
 	u_long		flags;
 #		define DISK_ON_TRACK	1
-#if 0
-	u_long		real_cyl;
-	u_long		real_hd;
-	u_long		real_sect;
-#endif
 	u_long		bios_cyl;
 	u_long		bios_hd;
 	u_long		bios_sect;
@@ -111,19 +106,16 @@
 /* Print the content of the tree to stdout
  */
 
-#if 0
-struct disk *
-Set_Phys_Geom(struct disk *disk, u_long cyl, u_long heads, u_long sects);
-/* Use a different physical geometry.  Makes sense for ST506 disks only.
- * The tree returned is read from the disk, using this geometry.
- */
-#endif
-
 void
 Set_Bios_Geom(struct disk *disk, u_long cyl, u_long heads, u_long sects);
 /* Set the geometry the bios uses.
  */
 
+void
+Sanitize_Bios_Geom(struct disk *disk);
+/* Set the bios geometry to something sane
+ */
+
 int
 Delete_Chunk(struct disk *disk, struct chunk *);
 /* Free a chunk of disk_space
@@ -278,7 +270,7 @@
  *
  *Sample output from tst01:
  *
- * Debug_Disk(wd0)  flags=0  real_geom=0/0/0  bios_geom=0/0/0
+ * Debug_Disk(wd0)  flags=0  bios_geom=0/0/0
  * >>        0x3d040          0    1411200    1411199 wd0      0 whole    0 0
  * >>>>      0x3d080          0     960120     960119 wd0s1    3 freebsd  0 8
  * >>>>>>    0x3d100          0      40960      40959 wd0s1a   5 part     0 0
Index: tst01.c
===================================================================
RCS file: /home/ncvs/src/lib/libdisk/tst01.c,v
retrieving revision 1.18
diff -u -r1.18 tst01.c
--- tst01.c	1996/07/09 12:17:46	1.18
+++ tst01.c	1996/11/25 09:14:59
@@ -196,33 +196,17 @@
 			All_FreeBSD(d, 1);
 			continue;
 		}
-		if (!strcasecmp(*cmds,"bios") && ncmd == 4) {
-			Set_Bios_Geom(d,
-				strtol(cmds[1],0,0),
-				strtol(cmds[2],0,0),
-				strtol(cmds[3],0,0));
+		if (!strcasecmp(*cmds,"sanitize")) {
+			Sanitize_Bios_Geom(d);
 			continue;
 		}
-#if 0
-		if (!strcasecmp(*cmds,"phys") && ncmd == 4) {
-			d = Set_Phys_Geom(d,
+		if (!strcasecmp(*cmds,"bios") && ncmd == 4) {
+			Set_Bios_Geom(d,
 				strtol(cmds[1],0,0),
 				strtol(cmds[2],0,0),
 				strtol(cmds[3],0,0));
 			continue;
 		}
-#endif
-#if 0
-		if (!strcasecmp(*cmds,"collapse")) {
-			if (cmds[1])
-				while (Collapse_Chunk(d,
-				    (struct chunk *)strtol(cmds[1],0,0)))
-					;
-			else
-				Collapse_Disk(d);
-			continue;
-		}
-#endif
 		if (!strcasecmp(*cmds,"list")) {
 			cp = Disk_Names();
 			printf("Disks:");
Index: write_disk.c
===================================================================
RCS file: /home/ncvs/src/lib/libdisk/write_disk.c,v
retrieving revision 1.17
diff -u -r1.17 write_disk.c
--- write_disk.c	1996/04/29 05:03:02	1.17
+++ write_disk.c	1996/11/25 09:37:03
@@ -80,15 +80,9 @@
 
 	dl->d_secsize = 512;
 	dl->d_secperunit = new->chunks->size;
-#if 0
-	dl->d_ncylinders = new->real_cyl ? new->real_cyl : new->bios_cyl;
-	dl->d_ntracks = new->real_hd ? new->real_hd : new->bios_hd;
-	dl->d_nsectors = new->real_sect ? new->real_sect : new->bios_sect;
-#else
 	dl->d_ncylinders =  new->bios_cyl;
 	dl->d_ntracks =  new->bios_hd;
 	dl->d_nsectors =  new->bios_sect;
-#endif
 	dl->d_secpercyl = dl->d_ntracks * dl->d_nsectors;
 
 	dl->d_npartitions = MAXPARTITIONS;
--
Poul-Henning Kamp           | phk@FreeBSD.ORG       FreeBSD Core-team.
http://www.freebsd.org/~phk | phk@login.dknet.dk    Private mailbox.
whois: [PHK]                | phk@ref.tfs.com       TRW Financial Systems, Inc.
Future will arrive by its own means, progress not so.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1471.848915970>