Export a (machine dependent) kernel variable bootdev as
machdep.guessed_bootdev, and add code to sysctl to parse its value and give a (not necessarily correct) name to the device we booted from (the main motivation for this code is to use the info in the PicoBSD boot scripts, and the impact on the kernel is minimal). NOTE: the information available in bootdev is not always reliable, so you should not trust it too much. The parsing code is the same as in boot2.c, and cannot cover all cases -- as it is, it seems to work fine with floppies and IDE disks recognised by the BIOS. It _should_ work as well with SCSI disks recognised by the BIOS. Booting from a CDROM in floppy emulation will return /dev/fd0 (because this is what the BIOS tells us). Booting off the network (e.g. with etherboot) leaves bootdev unset so the value will be printed as "invalid (0xffffffff)". Finally, this feature might go away at some point, hopefully when we have a more reliable way to get the same information. MFC-after: 5 days
This commit is contained in:
parent
832af2d5ed
commit
60cf2c1254
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=92018
@ -45,8 +45,10 @@ static const char rcsid[] =
|
|||||||
"$FreeBSD$";
|
"$FreeBSD$";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#include <sys/diskslice.h> /* used for bootdev parsing */
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <sys/reboot.h> /* used for bootdev parsing */
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
@ -403,6 +405,53 @@ oidfmt(int *oid, int len, char *fmt, u_int *kind)
|
|||||||
return 0;
|
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
|
* This formats and outputs the value of one variable
|
||||||
*
|
*
|
||||||
@ -496,6 +545,8 @@ show_var(int *oid, int nlen)
|
|||||||
if (!nflag)
|
if (!nflag)
|
||||||
printf("%s%s", name, sep);
|
printf("%s%s", name, sep);
|
||||||
fmt++;
|
fmt++;
|
||||||
|
if (!strcmp(name, "machdep.guessed_bootdev"))
|
||||||
|
return machdep_bootdev(*(unsigned long *)p);
|
||||||
val = "";
|
val = "";
|
||||||
while (len >= sizeof(long)) {
|
while (len >= sizeof(long)) {
|
||||||
if(*fmt == 'U')
|
if(*fmt == 'U')
|
||||||
|
@ -238,8 +238,6 @@ cpu_rootconf()
|
|||||||
}
|
}
|
||||||
SYSINIT(cpu_rootconf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, cpu_rootconf, NULL)
|
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)
|
#if defined(NFSCLIENT) && defined(NFS_ROOT) && !defined(BOOTP_NFSROOT)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -985,6 +985,10 @@ SYSCTL_STRUCT(_machdep, CPU_BOOTINFO, bootinfo,
|
|||||||
SYSCTL_INT(_machdep, CPU_WALLCLOCK, wall_cmos_clock,
|
SYSCTL_INT(_machdep, CPU_WALLCLOCK, wall_cmos_clock,
|
||||||
CTLFLAG_RW, &wall_cmos_clock, 0, "");
|
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
|
* Initialize 386 and configure to run kernel
|
||||||
*/
|
*/
|
||||||
|
@ -238,8 +238,6 @@ cpu_rootconf()
|
|||||||
}
|
}
|
||||||
SYSINIT(cpu_rootconf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, cpu_rootconf, NULL)
|
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)
|
#if defined(NFSCLIENT) && defined(NFS_ROOT) && !defined(BOOTP_NFSROOT)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -985,6 +985,10 @@ SYSCTL_STRUCT(_machdep, CPU_BOOTINFO, bootinfo,
|
|||||||
SYSCTL_INT(_machdep, CPU_WALLCLOCK, wall_cmos_clock,
|
SYSCTL_INT(_machdep, CPU_WALLCLOCK, wall_cmos_clock,
|
||||||
CTLFLAG_RW, &wall_cmos_clock, 0, "");
|
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
|
* Initialize 386 and configure to run kernel
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user