[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#80325: Installer misreports partition numbers



Here we go again.

The attached patch reverts to the old behaviour (first in best dressed)
if the kernel version is pre 2.4.0 and if 2.4.0 or later will put
extended partitions first.

BUGS: I guess the behaviour changed somewhere in the 2.3.x series, so if
they are using a 2.3 series it may behave incorectly. It will be simple
to update it to behave correctly once we know the exact version that
this new behaviour was implemented.


Glenn
Only in boot-floppies.working/utilities/libfdisk: .depend
diff -r -U 3 boot-floppies.orig/utilities/libfdisk/partbl_msdos.c boot-floppies.working/utilities/libfdisk/partbl_msdos.c
--- boot-floppies.orig/utilities/libfdisk/partbl_msdos.c	Mon Jan 15 13:43:23 2001
+++ boot-floppies.working/utilities/libfdisk/partbl_msdos.c	Mon Jan 15 13:53:53 2001
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <asm/types.h>
+#include <sys/utsname.h>
 #include "byteorder.h"
 
 #include "fdisk.h"
@@ -302,12 +303,33 @@
 }
 #endif
 
+/* this function taken from busybox/utility.c 
+ * Returns kernel version encoded as major*65536 + minor*256 + patch,  
+ * so, for example,  to check if the kernel is greater than 2.2.11: 
+ *     if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> }
+ */
+int get_kernel_revision(void)
+{
+        struct utsname name;
+        int major = 0, minor = 0, patch = 0;
+
+        if (uname(&name) == -1) {
+                fprintf(stderr, "cannot get system information");  
+                return (0);
+        }
+        major = atoi(strtok(name.release, "."));
+        minor = atoi(strtok(NULL, "."));
+        patch = atoi(strtok(NULL, "."));
+        return major * 65536 + minor * 256 + patch;
+}
+
 int parse_msdos_partition(char *device, int fd)
 {
     int i, minor = 1;
     struct partition *p;
     unsigned char data[512];
-
+    int kernel_version = get_kernel_revision();
+ 
     if (!sread( fd, 0, data ))
 	return -1;
     if (*(unsigned short *) (0x1fe + data) != __cpu_to_le16(MSDOS_LABEL_MAGIC))
@@ -322,26 +344,40 @@
 	if (is_extended_partition(p)) {
 	    extended_partition(device, fd, START_SECT(p), NR_SECTS(p));
 	}
+	/* if kernel version is less than version 2.4.0 */
+	if (kernel_version < (2*65536 + 4*256)) {
+	    if (SYS_IND(p) == BSD_PARTITION) {
+                bsd_disklabel_partition(device, fd, START_SECT(p));
+            }
+            /* james@bpgc.com: Solaris has a nasty indicator: 0x82
+             * which also means linux swap.  For that reason, all
+             * of the prints are done inside the
+             * solaris_x86_partition routine */
+            if (SYS_IND(p) == SOLARIS_X86_PARTITION) {
+                solaris_x86_partition(device, fd, START_SECT(p));
+            }
+	}
     }
+
+    /* if kernel is 2.4 or better */
+    if (kernel_version >= (2*65536 + 4*256)) {
 #if HAVE_BSD_DISKLABEL | HAVE_SOLARIS_X86_PARTITION
-    p = (struct partition *) (0x1be + data);
-    for (i=1 ; i<=4 ; minor++,i++,p++) {
+        p = (struct partition *) (0x1be + data);
+        for (i=1 ; i<=4 ; minor++,i++,p++) {
 #if HAVE_BSD_DISKLABEL
-	if (SYS_IND(p) == BSD_PARTITION) {
-	    bsd_disklabel_partition(device, fd, START_SECT(p));
-	}
+           if (SYS_IND(p) == BSD_PARTITION) {
+	        bsd_disklabel_partition(device, fd, START_SECT(p));
+	    }
 #endif
 #if HAVE_SOLARIS_X86_PARTITION
-    /* james@bpgc.com: Solaris has a nasty indicator: 0x82
-     * which also means linux swap.  For that reason, all
-     * of the prints are done inside the
-     * solaris_x86_partition routine */
-	if (SYS_IND(p) == SOLARIS_X86_PARTITION) {
-	    solaris_x86_partition(device, fd, START_SECT(p));
-	}
+           if (SYS_IND(p) == SOLARIS_X86_PARTITION) {
+	        solaris_x86_partition(device, fd, START_SECT(p));
+	    }
 #endif
-    }
+        }
 #endif 
+    }
+
     /*
      *  Check for old-style Disk Manager partition table
      */

Reply to: