diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 4d5e3e14193f..7d66552c0c18 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -45,8 +45,10 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ +#include /* used for bootdev parsing */ #include #include +#include /* used for bootdev parsing */ #include #include #include @@ -403,6 +405,53 @@ oidfmt(int *oid, int len, char *fmt, u_int *kind) return 0; } +/* + * Code to map a bootdev major number into a suitable device name. + * Major numbers are mapped into names as in boot2.c + */ +struct _foo { + int majdev; + char *name; +} maj2name[] = { + 30, "ad", + 0, "wd", + 1, "wfd", + 2, "fd", + 4, "da", + -1, NULL /* terminator */ +}; + +static int +machdep_bootdev(u_long value) +{ + int majdev, unit, slice, part; + struct _foo *p; + + if (value & B_MAGICMASK != B_DEVMAGIC) { + printf("invalid (0x%08x)", value); + return 0; + } + majdev = B_TYPE(value); + unit = B_UNIT(value); + slice = B_SLICE(value); + part = B_PARTITION(value); + if (majdev == 2) { /* floppy, as known to the boot block... */ + printf("/dev/fd%d", unit); + return 0; + } + for (p = maj2name; p->name != NULL && p->majdev != majdev ; p++) ; + if (p->name != NULL) { /* found */ + if (slice == WHOLE_DISK_SLICE) + printf("/dev/%s%d%c", p->name, unit, part); + else + printf("/dev/%s%ds%d%c", + p->name, unit, slice - BASE_SLICE + 1, part + 'a'); + } else + printf("unknown (major %d unit %d slice %d part %d)", + majdev, unit, slice, part); + return 0; +} + /* * This formats and outputs the value of one variable * @@ -496,6 +545,8 @@ show_var(int *oid, int nlen) if (!nflag) printf("%s%s", name, sep); fmt++; + if (!strcmp(name, "machdep.guessed_bootdev")) + return machdep_bootdev(*(unsigned long *)p); val = ""; while (len >= sizeof(long)) { if(*fmt == 'U') diff --git a/sys/amd64/amd64/autoconf.c b/sys/amd64/amd64/autoconf.c index 618b2c69a621..af2cb5fb1d6b 100644 --- a/sys/amd64/amd64/autoconf.c +++ b/sys/amd64/amd64/autoconf.c @@ -238,8 +238,6 @@ cpu_rootconf() } SYSINIT(cpu_rootconf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, cpu_rootconf, NULL) -u_long bootdev = 0; /* not a dev_t - encoding is different */ - #if defined(NFSCLIENT) && defined(NFS_ROOT) && !defined(BOOTP_NFSROOT) static int diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 3c459d4c7b02..b9d51c71886a 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -985,6 +985,10 @@ SYSCTL_STRUCT(_machdep, CPU_BOOTINFO, bootinfo, SYSCTL_INT(_machdep, CPU_WALLCLOCK, wall_cmos_clock, CTLFLAG_RW, &wall_cmos_clock, 0, ""); +u_long bootdev; /* not a dev_t - encoding is different */ +SYSCTL_ULONG(_machdep, OID_AUTO, guessed_bootdev, + CTLFLAG_RD, &bootdev, 0, "Maybe the Boot device (not in dev_t format)"); + /* * Initialize 386 and configure to run kernel */ diff --git a/sys/i386/i386/autoconf.c b/sys/i386/i386/autoconf.c index 618b2c69a621..af2cb5fb1d6b 100644 --- a/sys/i386/i386/autoconf.c +++ b/sys/i386/i386/autoconf.c @@ -238,8 +238,6 @@ cpu_rootconf() } SYSINIT(cpu_rootconf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, cpu_rootconf, NULL) -u_long bootdev = 0; /* not a dev_t - encoding is different */ - #if defined(NFSCLIENT) && defined(NFS_ROOT) && !defined(BOOTP_NFSROOT) static int diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 3c459d4c7b02..b9d51c71886a 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -985,6 +985,10 @@ SYSCTL_STRUCT(_machdep, CPU_BOOTINFO, bootinfo, SYSCTL_INT(_machdep, CPU_WALLCLOCK, wall_cmos_clock, CTLFLAG_RW, &wall_cmos_clock, 0, ""); +u_long bootdev; /* not a dev_t - encoding is different */ +SYSCTL_ULONG(_machdep, OID_AUTO, guessed_bootdev, + CTLFLAG_RD, &bootdev, 0, "Maybe the Boot device (not in dev_t format)"); + /* * Initialize 386 and configure to run kernel */