Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Mar 2002 02:00:09 -0800
From:      Luigi Rizzo <rizzo@icir.org>
To:        arch@FreeBSD.ORG
Subject:   Proposed patch: kern.bootdev* sysctl variables
Message-ID:  <20020308020009.A6535@iguana.icir.org>

next in thread | raw e-mail | index | archive | help
Any objection to the following patch to i386/i386/autoconf.c
to let userland apps know [an approximation of] the name
of the device the kernel was booted from ?

The main use would be for startup scripts, such as
/etc/rc, which could this way differentiate their
behaviour based on the returned result.

(I know it can be perfected by not assuming that
any hard disk is /dev/ad, but you get the idea...)

	cheers
	luigi

Index: autoconf.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/autoconf.c,v
retrieving revision 1.146.2.2
diff -u -r1.146.2.2 autoconf.c
--- autoconf.c  7 Jun 2001 06:05:58 -0000       1.146.2.2
+++ autoconf.c  8 Mar 2002 09:32:36 -0000
@@ -66,6 +66,7 @@
 #include <sys/malloc.h>
 #include <sys/mount.h>
 #include <sys/cons.h>
+#include <sys/sysctl.h>
 
 #include <machine/bootinfo.h>
 #include <machine/ipl.h>
@@ -105,6 +106,11 @@
 
 device_t nexus_dev;
 
+SYSCTL_ULONG(_kern, OID_AUTO, bootdev, CTLFLAG_RD, &bootdev, 0, "");
+static char bootdevname[MAXPATHLEN];
+SYSCTL_STRING(_kern, OID_AUTO, bootdevname, CTLFLAG_RD,
+    bootdevname, 0, "Boot device name");
+
 /*
  * Determine i/o configuration for a machine.
  */
@@ -300,9 +306,13 @@
                slice = COMPATIBILITY_SLICE;
                part = RAW_PART;
                mindev = unit << FDUNITSHIFT;
+               sprintf(bootdevname, "/dev/fd%d", unit);
        } else {
                part = B_PARTITION(bootdev);
                mindev = dkmakeminor(unit, slice, part);
+               sprintf(bootdevname,
+                   (slice < BASE_SLICE ? "/dev/ad%d" : "/dev/ad%ds%d"),
+                   unit, slice - BASE_SLICE + 1);
        }
 
        newrootdev = makebdev(majdev, mindev);


On Mon, Feb 25, 2002 at 02:30:13PM -0800, Luigi Rizzo wrote:
> [bcc-ed to some recent committers to boot2.c]
> Hi,
> for some stuff I am doing with picobsd (and i think in general this
> is useful) it would be nice to know where the kernel was loaded
> from.  In /sys/boot/i386/boot2/boot2.c this information is stored
> in three 8-bit variables:
> 
> 	dsk.drive	also goes into	bootinfo.bi_bios_dev
> 	dsk.slice
> 	dsk.part
> 
> Although the latter two are not made available to the kernel,
> there are two empty 8-bit fields in struct bootinfo
> 
> 	u_int8_t        bi_pad[2];
> 
> which could do the job without breaking binary compatibility.
> 
> Any objection on exporting dsk.slice and dsk.part into the bi_pad
> fields, possibly starting from 1 so the kernel can tell an uninitialized
> value from a good one ?
> 
> (and together with this, perhaps a sysctl variable which builds a
> device name from these three values...)
> 
> 	cheers
> 	luigi
> ----------------------------------+-----------------------------------------
>  Luigi RIZZO, luigi@iet.unipi.it  . ICSI (on leave from Univ. di Pisa)
>  http://www.iet.unipi.it/~luigi/  . 1947 Center St, Berkeley CA 94704
>  Phone: (510) 666 2927
> ----------------------------------+-----------------------------------------
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-hackers" in the body of the message

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020308020009.A6535>