owned this note changed a year ago
Published Linked with GitHub

In x86/x86_autoconf.c.
findroot() attempts to find the device (a device_t) from which the kernel was loaded and changes rootdev (another device_t), if allowed to do so.
It does this in 6 steps:

  1. If booted_device (a device_t) is already set, it just returns, not setting rootdev. The assumption seems to be, that the kernel was booted from the network and device_register() already has set booted_device.
  2. If BTINFO_NETIF is available (but booted_device isn't set), it just returns, logging a message that the netboot interface wasn't found.
  3. BTINFO_ROOTDEVICE is non-NULL.
    biv->devname is expected to be of the form "drivername<unitdigit><partitionletter>".
    It loops over all disk devices looking for a device who's cfname is the same as drivername.
    Iff such a device is found it sets the following variables:
var name description
booted_device device_t that the kernel was loaded from
booted_partition the partition number derived from the partitionletter
booted_nblks 0, indicating that no geometry information was passed
booted_method "bootinfo/rootdevice"

If it does not find a matching device(dv being NULL after exiting the loop) and biv->devname is not the empty string (biv->devname[0] != '\0') it copies the devname to bootspec and returns.

var name description
bootspec name of the booted device if not found in device list

BUGS Note that we can't boot off e.g. sd10 and that the nonsense is stored in booted_partition if the last character of biv->devname is not a valid partition letter ('a'-'v' c.f. sys/disklabel.h). In particular: "sd0z" and "sd0", in the latter case the "partition letter" is the NUL character terminating the device name.
This is handled better in the xen_machdep.c.
XXX there was other code that converted device unit with strtod(). But where?
4. BTINFO_BOOTWEDGE is non-NULL
biw->biosdev is expected to have the 0x80 bit set, indicating a hard disk. XXX why? Possibly because we floppies don't have wedges.
BTINFO_BOOTDISK should be available.
It loops over all the disk devices looking for disk with is_valid_disk() that match_bootwedge() the device.
match_bootwedge() calculates the MD5 hash of the device blocks biw->matchblk to biw->matchblk+biw->matchnblks returning true if that hash is equal to biw->matchhash.
biw->matchblk == -1 indicates that no sector(block) was specified, hence no match.
XXX why not compare just devclass as in BTINFO_ROOTDEVICE case?
If a matching device was found the following variables are set:

var name description
booted_device device_t that the kernel was loaded from
booted_partition bid->partition if BTINFO_BOOTDISK was available, else 0
booted_nblks biw->nblks (possibly 0) XXX when?
booted_startblk biw->startblk, the starting block of the partition
booted_method "bootinfo/bootwedge"
  1. BTINFO_BOOTDISK is non-NULL
    It loops over all disk and floppy devices, looking for either a floppy device who's device_unit is equal to bid->biosdev or a disk who's disklabel's type, checksum, and packname match the information passed in bid->label (via match_bootdisk()).
    It sets the following variables:
var name description
booted_device the device_t of the device that the kernel was loaded from
booted_partition bid->partition
booted_nblks 0, indicating that no geometry was passed
booted_method "bootinfo/bootdisk"
  1. BTINFO_BIOSGEOM is non-NULL and bid->biosdev indicates a CDROM (by being bigger than the number of biosgeom entries declared by the BIOS).
    It find the first CDROM device and sets the following variables:
var name description
booted_device the device_t of the first probed CDROM
booted_partition 0
booted_nblks 0, indicating that bios geometry is not relevant
booted_method "bootinfo/biosgeom"
  1. if nothing matched, findroot() return without setting any variables.

Summary: it stores the device from where the system was booted from, in booted_device, along with other device associated variables. it does this in one of 4 cases (types of booting method) . those cases are true if bootinfo of bootloader has information corresponding to their type. if the bootinfo has no information regarding those types of bootmethod it returns without setting any varibles.

Select a repo