tech-kern archive

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

[patch] MI root filesystem detection



This change to sys/kern/init_main.c:rootconf_handle_wedges()
lets the kernel select a partition in a BSD disklabel using the
BTINFO_BOOTWEDGE-type information from the bootloader if the _BOOTWEDGE
information matches no dk(4) instance.

At least on i386, the bootloader passes both BTINFO_BOOTWEDGE-
and BTINFO_BOOTDISK-type information to the kernel, but the
_BOOTWEDGE information supercedes the _BOOTDISK information: thus the
booted_partition is left at 0, and if the kernel fails to match the
_BOOTWEDGE info to a wedge it blithely selects the 0th partition on the
booted_device for its root filesystem.

Dave

-- 
David Young
dyoung%pobox.com@localhost    Urbana, IL    (217) 721-9981
--- sys/kern/init_main.c        2012/09/05 20:48:18
+++ sys/kern/init_main.c        2012/10/02 19:59:05
@@ -835,7 +853,7 @@
        daddr_t startblk;
        uint64_t nblks;
        device_t dev; 
-       int error;
+       int error, partition;
 
        if (booted_nblks) {
                /*
@@ -882,6 +900,36 @@
        if (dev != NULL) {
                booted_device = dev;
                booted_partition = 0;
+               return;
+       }
+       if (booted_nblks == 0)
+               return;
+
+       /*
+        * Use the geometry to try to locate a partition.
+        */
+       vp = opendisk(booted_device);
+
+       if (vp == NULL)
+               return;
+
+       error = VOP_IOCTL(vp, DIOCGPART, &dpart, FREAD, NOCRED);
+       VOP_CLOSE(vp, FREAD, NOCRED);
+       vput(vp);
+       if (error)
+               return;
+
+       for (partition = 0; partition < MAXPARTITIONS; partition++) {
+
+               p = &dpart.disklab->d_partitions[partition];
+
+               startblk = p->p_offset;
+               nblks    = p->p_size;
+
+               if (startblk == booted_startblk && nblks == booted_nblks) {
+                       booted_partition = partition;
+                       break;
+               }
        }
 }
 


Home | Main Index | Thread Index | Old Index