From owner-freebsd-arch Fri Mar 8 2: 0:29 2002 Delivered-To: freebsd-arch@freebsd.org Received: from iguana.icir.org (iguana.icir.org [192.150.187.36]) by hub.freebsd.org (Postfix) with ESMTP id 1C5EF37B433 for ; Fri, 8 Mar 2002 02:00:10 -0800 (PST) Received: (from rizzo@localhost) by iguana.icir.org (8.11.6/8.11.3) id g28A09H06836; Fri, 8 Mar 2002 02:00:09 -0800 (PST) (envelope-from rizzo) Date: Fri, 8 Mar 2002 02:00:09 -0800 From: Luigi Rizzo To: arch@FreeBSD.ORG Subject: Proposed patch: kern.bootdev* sysctl variables Message-ID: <20020308020009.A6535@iguana.icir.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.23i Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 #include #include +#include #include #include @@ -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