[PATCH] fix /boot/loader for extended slices

walt wa1ter at myrealbox.com
Sun Dec 19 11:11:37 PST 2004


This is a revision of the patch I posted a few days ago.  The
last extended slice never showed when doing an lsdev from the
loader prompt.

--- sys/boot/i386/libi386/biosdisk.c.orig	2004-10-24 11:36:05.000000000 -0700
+++ sys/boot/i386/libi386/biosdisk.c	2004-12-19 10:45:51.000000000 -0800
@@ -135,7 +135,7 @@
 static int	bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev);
 static void	bd_closedisk(struct open_disk *od);
 static int	bd_bestslice(struct open_disk *od);
-static void	bd_checkextended(struct open_disk *od, int slicenum);
+static void	bd_chainextended(struct open_disk *od, u_int32_t base, u_int32_t offset);

 /*
  * Translate between BIOS device numbers and our private unit numbers.
@@ -521,11 +521,18 @@
      */
     bcopy(buf + DOSPARTOFF, &od->od_slicetab,
       sizeof(struct dos_partition) * NDOSPART);
-    od->od_nslices = 4;			/* extended slices start here */
-    for (i = 0; i < NDOSPART; i++)
-        bd_checkextended(od, i);
+    od->od_nslices = 3;			/* extended slices start here */
+
+    dptr = &od->od_slicetab[0];
+    for (i = 0; i < NDOSPART; i++, dptr++)
+	{
+	if ((dptr->dp_typ == DOSPTYP_EXT) || (dptr->dp_typ == DOSPTYP_EXTLBA))
+	bd_chainextended(od, dptr->dp_start, 0); /* 1st offset is zero */
+	}
+    od->od_nslices++; /* else the last slice won't display */
     od->od_flags |= BD_PARTTABOK;
     dptr = &od->od_slicetab[0];
+

     /* Is this a request for the whole disk? */
     if (dev->d_kind.biosdisk.slice == -1) {
@@ -637,46 +644,34 @@
     return(error);
 }

+
 static void
-bd_checkextended(struct open_disk *od, int slicenum)
+bd_chainextended(struct open_disk *od, u_int32_t base, u_int32_t offset)
 {
-	char	buf[BIOSDISK_SECSIZE];
-	struct dos_partition *dp;
-	u_int base;
-	int i, start, end;
+        char   buf[BIOSDISK_SECSIZE];
+        struct dos_partition *dp1, *dp2;

-	dp = &od->od_slicetab[slicenum];
-	start = od->od_nslices;
-
-	if (dp->dp_size == 0)
-		goto done;
-	if (dp->dp_typ != DOSPTYP_EXT)
-		goto done;
-	if (bd_read(od, (daddr_t)dp->dp_start, 1, buf))
-		goto done;
-	if (((u_char)buf[0x1fe] != 0x55) || ((u_char)buf[0x1ff] != 0xaa)) {
-		DEBUG("no magic in extended table");
-		goto done;
-	}
-	base = dp->dp_start;
-	dp = (struct dos_partition *)(&buf[DOSPARTOFF]);
-	for (i = 0; i < NDOSPART; i++, dp++) {
-		if (dp->dp_size == 0)
-			continue;
-		if (od->od_nslices == NEXTDOSPART)
-			goto done;
-		dp->dp_start += base;
-		bcopy(dp, &od->od_slicetab[od->od_nslices], sizeof(*dp));
-		od->od_nslices++;
+	if (bd_read(od, (daddr_t)(base + offset), 1, buf)) {
+                printf("\nerror reading extended partition table");
+		return;
 	}
-	end = od->od_nslices;
+
+	od->od_nslices++;	/* number of slices */
+	dp2 = &od->od_slicetab[od->od_nslices];  /* ptr to in-memory partition table */
+
+	dp1 = (struct dos_partition *)(&buf[DOSPARTOFF]); /* 1st record in on-disk XPT*/
+	/* set up in-memory PT record */
+	/* I left out cyl/head fields.  Do we need them? */
+	dp2->dp_typ = dp1->dp_typ;
+	dp2->dp_start = base + offset + dp1->dp_start;  /* first sector of XP */
+	dp2->dp_size = dp1->dp_size;
+
+	dp1++ ;		/* 2nd record in XPT has offset to next XPT */
+
+	/* a pox on recursion */
+	if ((dp1->dp_typ == DOSPTYP_EXT) || (dp1->dp_typ == DOSPTYP_EXTLBA))
+		bd_chainextended(od, base, dp1->dp_start);

-	/*
-	 * now, recursively check the slices we just added
-	 */
-	for (i = start; i < end; i++)
-		bd_checkextended(od, i);
-done:
 	return;
 }






More information about the Submit mailing list