diff options
-rw-r--r-- | sys/alpha/alpha/autoconf.c | 62 | ||||
-rw-r--r-- | sys/amd64/amd64/autoconf.c | 285 | ||||
-rw-r--r-- | sys/i386/i386/autoconf.c | 285 | ||||
-rw-r--r-- | sys/kern/vfs_conf.c | 428 | ||||
-rw-r--r-- | sys/kern/vfs_mount.c | 428 |
5 files changed, 607 insertions, 881 deletions
diff --git a/sys/alpha/alpha/autoconf.c b/sys/alpha/alpha/autoconf.c index b0aa687..2f6fa13 100644 --- a/sys/alpha/alpha/autoconf.c +++ b/sys/alpha/alpha/autoconf.c @@ -69,7 +69,6 @@ static void configure_start __P((void)); device_t isa_bus_device = 0; #endif -struct cam_sim *boot_sim = 0; extern int nfs_diskless_valid; dev_t rootdev = NODEV; @@ -217,54 +216,23 @@ configure(void *dummy) cold = 0; } +/* + * Do legacy root filesystem discovery. This isn't really + * needed on the Alpha, which has always used the loader. + */ void cpu_rootconf() { -#ifdef BOOTP_NFSROOT - if (!strcmp(bootdev_protocol(), "BOOTP") - && !mountrootfsname && !nfs_diskless_valid) { - if (bootverbose) - printf("Considering BOOTP NFS root f/s.\n"); - mountrootfsname = "nfs"; - } -#endif /* BOOTP_NFSROOT */ -#if defined(NFS) || defined(NFS_ROOT) - if (!mountrootfsname && nfs_diskless_valid) { - if (bootverbose) - printf("Considering NFS root f/s.\n"); - mountrootfsname = "nfs"; - } -#endif /* NFS */ - - -#if defined(FFS) || defined(FFS_ROOT) - if (!mountrootfsname) { - static char rootname[] = "da0a"; - - if (bootverbose) - printf("Considering UFS root f/s.\n"); - mountrootfsname = "ufs"; - - if (boot_sim) { - struct cam_path *path; - struct cam_periph *periph; - - xpt_create_path(&path, NULL, - cam_sim_path(boot_sim), - bootdev_unit() / 100, 0); - periph = cam_periph_find(path, "da"); - - if (periph) - rootdev = makebdev - (4, dkmakeminor(periph->unit_number, - COMPATIBILITY_SLICE, 0)); - - xpt_free_path(path); - } - - rootdevs[0] = rootdev; - rootname[2] += dkunit(rootdev); - rootdevnames[0] = rootname; - } + int order = 0; +#if defined(NFS) && defined(NFS_ROOT) +#if !defined(BOOTP_NFSROOT) + if (nfs_diskless_valid) +#endif + rootdevnames[order++] = "nfs:"; +#endif + +#if defined(FFS) && defined(FFS_ROOT) + rootdevnames[order++] = "ufs:da0a"; #endif } +SYSINIT(cpu_rootconf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, cpu_rootconf, NULL) diff --git a/sys/amd64/amd64/autoconf.c b/sys/amd64/amd64/autoconf.c index e76758f..33e68b7 100644 --- a/sys/amd64/amd64/autoconf.c +++ b/sys/amd64/amd64/autoconf.c @@ -83,11 +83,10 @@ static void configure_final __P((void *)); static void configure_finish __P((void)); static void configure_start __P((void)); -#if defined(FFS) || defined(FFS_ROOT) + +#if defined(FFS) && defined(FFS_ROOT) static void setroot __P((void)); #endif -static int setrootbyname __P((char *name)); -static void gets __P((char *)); SYSINIT(configure1, SI_SUB_CONFIGURE, SI_ORDER_FIRST, configure_first, NULL); /* SI_ORDER_SECOND is hookable */ @@ -98,78 +97,6 @@ SYSINIT(configure3, SI_SUB_CONFIGURE, SI_ORDER_ANY, configure_final, NULL); dev_t rootdev = NODEV; dev_t dumpdev = NODEV; -#if defined(CD9660) || defined(CD9660_ROOT) - -#include <sys/fcntl.h> -#include <sys/proc.h> -#include <sys/stat.h> -#include <machine/clock.h> - -/* - * XXX All this CD-ROM root stuff is fairly messy. Ick. - * - * We need to try out all our potential CDROM drives, so we need a table. - */ -static struct { - char *name; - int major; -} try_cdrom[] = { - { "cd", 6 }, - { "mcd", 7 }, - { "scd", 16 }, - { "matcd", 17 }, - { "wcd", 19 }, - { 0, 0} -}; - -static int find_cdrom_root __P((void)); - -static int -find_cdrom_root() -{ - int i, j, error; - struct cdevsw *bd; - dev_t orootdev; - -#if CD9660_ROOTDELAY > 0 - DELAY(CD9660_ROOTDELAY * 1000000); -#endif - orootdev = rootdev; - for (i = 0 ; i < 2; i++) - for (j = 0 ; try_cdrom[j].name ; j++) { - if (try_cdrom[j].major >= NUMCDEVSW) - continue; - rootdev = makebdev(try_cdrom[j].major, i * 8); - bd = devsw(rootdev); - if (bd == NULL || bd->d_open == NULL) - continue; - if (bootverbose) - printf("trying %s%d as rootdev (%p)\n", - try_cdrom[j].name, i, (void *)rootdev); - error = (bd->d_open)(rootdev, FREAD, S_IFBLK, curproc); - if (error == 0) { - if (bd->d_close != NULL) - (bd->d_close)(rootdev, FREAD, S_IFBLK, - curproc); - return 0; - } - } - - rootdev = orootdev; - return EINVAL; -} -#endif /* CD9660 || CD9660_ROOT */ - -static void -configure_start() -{ -} - -static void -configure_finish() -{ -} - device_t nexus_dev; /* @@ -179,8 +106,6 @@ static void configure_first(dummy) void *dummy; { - - configure_start(); /* DDB hook? */ } static void @@ -248,8 +173,6 @@ configure_final(dummy) { int i; - configure_finish(); /* DDB hook? */ - cninit_finish(); if (bootverbose) { @@ -293,69 +216,42 @@ configure_final(dummy) cold = 0; } - +/* + * Do legacy root filesystem discovery. + */ void cpu_rootconf() { - /* - * XXX NetBSD has a much cleaner approach to finding root. - * XXX We should adopt their code. - */ -#if defined(CD9660) || defined(CD9660_ROOT) - if ((boothowto & RB_CDROM)) { - if (bootverbose) - printf("Considering CD-ROM root f/s.\n"); - /* NB: find_cdrom_root() sets rootdev if successful. */ - if (find_cdrom_root() == 0) - mountrootfsname = "cd9660"; - else if (bootverbose) - printf("No CD-ROM available as root f/s.\n"); - } +#if defined(NFS) && defined(NFS_ROOT) +#if !defined(BOOTP_NFSROOT) + if (nfs_diskless_valid) #endif - -#ifdef BOOTP_NFSROOT - if (!mountrootfsname && !nfs_diskless_valid) { - if (bootverbose) - printf("Considering BOOTP NFS root f/s.\n"); - mountrootfsname = "nfs"; - } -#endif /* BOOTP_NFSROOT */ -#if defined(NFS) || defined(NFS_ROOT) - if (!mountrootfsname && nfs_diskless_valid) { - if (bootverbose) - printf("Considering NFS root f/s.\n"); - mountrootfsname = "nfs"; - } -#endif /* NFS */ - -#if defined(FFS) || defined(FFS_ROOT) - if (!mountrootfsname) { - mountrootfsname = "ufs"; - if (bootverbose) - printf("Considering FFS root f/s.\n"); - if (boothowto & RB_ASKNAME) - setconf(); - else - setroot(); - } + rootdevnames[0] = "nfs:"; +#endif +#if defined(FFS) && defined(FFS_ROOT) + setroot(); #endif - - if (!mountrootfsname) { - panic("Nobody wants to mount my root for me"); - } } +SYSINIT(cpu_rootconf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, cpu_rootconf, NULL) u_long bootdev = 0; /* not a dev_t - encoding is different */ -#define FDMAJOR 2 +#if defined(FFS) && defined(FFS_ROOT) +#define FDMAJOR 2 #define FDUNITSHIFT 6 -#if defined(FFS) || defined(FFS_ROOT) /* * Attempt to find the device from which we were booted. * If we can do so, and not instructed not to do so, * set rootdevs[] and rootdevnames[] to correspond to the * boot device(s). + * + * This code survives in order to allow the system to be + * booted from legacy environments that do not correctly + * populate the kernel environment. There are significant + * restrictions on the bootability of the system in this + * situation; it can only be mounting root from a 'da' + * 'wd' or 'fd' device, and the root filesystem must be ufs. */ static void setroot() @@ -365,24 +261,14 @@ setroot() char partname[2]; char *sname; - if (boothowto & RB_DFLTROOT) { -#ifdef ROOTDEVNAME - setrootbyname(ROOTDEVNAME); -#else - setconf(); -#endif - return; - } if ((bootdev & B_MAGICMASK) != B_DEVMAGIC) { printf("no B_DEVMAGIC (bootdev=%#lx)\n", bootdev); - setconf(); return; } majdev = B_TYPE(bootdev); dev = makebdev(majdev, 0); if (devsw(dev) == NULL) { printf("no devsw (majdev=%d bootdev=%#lx)\n", majdev, bootdev); - setconf(); return; } unit = B_UNIT(bootdev); @@ -391,7 +277,6 @@ setroot() slice = COMPATIBILITY_SLICE; if (slice < 0 || slice >= MAX_SLICES) { printf("bad slice\n"); - setconf(); return; } @@ -409,10 +294,9 @@ setroot() } newrootdev = makebdev(majdev, mindev); - rootdevs[0] = newrootdev; sname = dsname(newrootdev, unit, slice, part, partname); - rootdevnames[0] = malloc(strlen(sname) + 2, M_DEVBUF, M_NOWAIT); - sprintf(rootdevnames[0], "%s%s", sname, partname); + rootdevnames[0] = malloc(strlen(sname) + 6, M_DEVBUF, M_NOWAIT); + sprintf(rootdevnames[0], "ufs:%s%s", sname, partname); /* * For properly dangerously dedicated disks (ones with a historical @@ -426,125 +310,8 @@ setroot() if (slice == COMPATIBILITY_SLICE) return; slice = COMPATIBILITY_SLICE; - rootdevs[1] = dkmodslice(newrootdev, slice); sname = dsname(newrootdev, unit, slice, part, partname); - rootdevnames[1] = malloc(strlen(sname) + 2, M_DEVBUF, M_NOWAIT); - sprintf(rootdevnames[1], "%s%s", sname, partname); + rootdevnames[1] = malloc(strlen(sname) + 6, M_DEVBUF, M_NOWAIT); + sprintf(rootdevnames[1], "ufs:%s%s", sname, partname); } #endif - - - -static int -setrootbyname(char *name) -{ - char *cp; - int bd, unit, slice, part; - dev_t dev; - - printf("setrootbyname(\"%s\")\n", name); - slice = 0; - part = 0; - cp = name; - while (cp != '\0' && (*cp < '0' || *cp > '9')) - cp++; - if (cp == name) { - printf("missing device name\n"); - return(1); - } - if (*cp == '\0') { - printf("missing unit number\n"); - return(1); - } - unit = *cp - '0'; - *cp++ = '\0'; - for (bd = 0; bd < NUMCDEVSW; bd++) { - dev = makebdev(bd, 0); - if (devsw(dev) != NULL && - strcmp(devsw(dev)->d_name, name) == 0) - goto gotit; - } - return (2); -gotit: - while (*cp >= '0' && *cp <= '9') - unit += 10 * unit + *cp++ - '0'; - if (*cp == 's' && cp[1] >= '0' && cp[1] <= '9') { - slice = cp[1] - '0' + 1; - cp += 2; - } - if (*cp >= 'a' && *cp <= 'h') { - part = *cp - 'a'; - cp++; - } - if (*cp != '\0') { - printf("junk after name\n"); - return (1); - } - rootdev = makebdev(bd, dkmakeminor(unit, slice, part)); - printf("driver=%s, unit=%d, slice=%d, part=%d -> rootdev=%p\n", - name, unit, slice, part, (void *)rootdev); - return 0; -} - -void -setconf() -{ - char name[128]; - int i; - dev_t dev; - - for(;;) { - printf("root device? "); - gets(name); - i = setrootbyname(name); - if (!i) - return; - - printf("use one of:\n"); - for (i = 0; i < NUMCDEVSW; i++) { - dev = makebdev(i, 0); - if (devsw(dev) != NULL) - printf(" \"%s\"", devsw(dev)->d_name); - } - printf("\nfollowed by a unit number...\n"); - } -} - -static void -gets(cp) - char *cp; -{ - register char *lp; - register int c; - - lp = cp; - for (;;) { - printf("%c", c = cngetc() & 0177); - switch (c) { - case -1: - case '\n': - case '\r': - *lp++ = '\0'; - return; - case '\b': - case '\177': - if (lp > cp) { - printf(" \b"); - lp--; - } - continue; - case '#': - lp--; - if (lp < cp) - lp = cp; - continue; - case '@': - case 'u' & 037: - lp = cp; - printf("%c", '\n'); - continue; - default: - *lp++ = c; - } - } -} diff --git a/sys/i386/i386/autoconf.c b/sys/i386/i386/autoconf.c index e76758f..33e68b7 100644 --- a/sys/i386/i386/autoconf.c +++ b/sys/i386/i386/autoconf.c @@ -83,11 +83,10 @@ static void configure_final __P((void *)); static void configure_finish __P((void)); static void configure_start __P((void)); -#if defined(FFS) || defined(FFS_ROOT) + +#if defined(FFS) && defined(FFS_ROOT) static void setroot __P((void)); #endif -static int setrootbyname __P((char *name)); -static void gets __P((char *)); SYSINIT(configure1, SI_SUB_CONFIGURE, SI_ORDER_FIRST, configure_first, NULL); /* SI_ORDER_SECOND is hookable */ @@ -98,78 +97,6 @@ SYSINIT(configure3, SI_SUB_CONFIGURE, SI_ORDER_ANY, configure_final, NULL); dev_t rootdev = NODEV; dev_t dumpdev = NODEV; -#if defined(CD9660) || defined(CD9660_ROOT) - -#include <sys/fcntl.h> -#include <sys/proc.h> -#include <sys/stat.h> -#include <machine/clock.h> - -/* - * XXX All this CD-ROM root stuff is fairly messy. Ick. - * - * We need to try out all our potential CDROM drives, so we need a table. - */ -static struct { - char *name; - int major; -} try_cdrom[] = { - { "cd", 6 }, - { "mcd", 7 }, - { "scd", 16 }, - { "matcd", 17 }, - { "wcd", 19 }, - { 0, 0} -}; - -static int find_cdrom_root __P((void)); - -static int -find_cdrom_root() -{ - int i, j, error; - struct cdevsw *bd; - dev_t orootdev; - -#if CD9660_ROOTDELAY > 0 - DELAY(CD9660_ROOTDELAY * 1000000); -#endif - orootdev = rootdev; - for (i = 0 ; i < 2; i++) - for (j = 0 ; try_cdrom[j].name ; j++) { - if (try_cdrom[j].major >= NUMCDEVSW) - continue; - rootdev = makebdev(try_cdrom[j].major, i * 8); - bd = devsw(rootdev); - if (bd == NULL || bd->d_open == NULL) - continue; - if (bootverbose) - printf("trying %s%d as rootdev (%p)\n", - try_cdrom[j].name, i, (void *)rootdev); - error = (bd->d_open)(rootdev, FREAD, S_IFBLK, curproc); - if (error == 0) { - if (bd->d_close != NULL) - (bd->d_close)(rootdev, FREAD, S_IFBLK, - curproc); - return 0; - } - } - - rootdev = orootdev; - return EINVAL; -} -#endif /* CD9660 || CD9660_ROOT */ - -static void -configure_start() -{ -} - -static void -configure_finish() -{ -} - device_t nexus_dev; /* @@ -179,8 +106,6 @@ static void configure_first(dummy) void *dummy; { - - configure_start(); /* DDB hook? */ } static void @@ -248,8 +173,6 @@ configure_final(dummy) { int i; - configure_finish(); /* DDB hook? */ - cninit_finish(); if (bootverbose) { @@ -293,69 +216,42 @@ configure_final(dummy) cold = 0; } - +/* + * Do legacy root filesystem discovery. + */ void cpu_rootconf() { - /* - * XXX NetBSD has a much cleaner approach to finding root. - * XXX We should adopt their code. - */ -#if defined(CD9660) || defined(CD9660_ROOT) - if ((boothowto & RB_CDROM)) { - if (bootverbose) - printf("Considering CD-ROM root f/s.\n"); - /* NB: find_cdrom_root() sets rootdev if successful. */ - if (find_cdrom_root() == 0) - mountrootfsname = "cd9660"; - else if (bootverbose) - printf("No CD-ROM available as root f/s.\n"); - } +#if defined(NFS) && defined(NFS_ROOT) +#if !defined(BOOTP_NFSROOT) + if (nfs_diskless_valid) #endif - -#ifdef BOOTP_NFSROOT - if (!mountrootfsname && !nfs_diskless_valid) { - if (bootverbose) - printf("Considering BOOTP NFS root f/s.\n"); - mountrootfsname = "nfs"; - } -#endif /* BOOTP_NFSROOT */ -#if defined(NFS) || defined(NFS_ROOT) - if (!mountrootfsname && nfs_diskless_valid) { - if (bootverbose) - printf("Considering NFS root f/s.\n"); - mountrootfsname = "nfs"; - } -#endif /* NFS */ - -#if defined(FFS) || defined(FFS_ROOT) - if (!mountrootfsname) { - mountrootfsname = "ufs"; - if (bootverbose) - printf("Considering FFS root f/s.\n"); - if (boothowto & RB_ASKNAME) - setconf(); - else - setroot(); - } + rootdevnames[0] = "nfs:"; +#endif +#if defined(FFS) && defined(FFS_ROOT) + setroot(); #endif - - if (!mountrootfsname) { - panic("Nobody wants to mount my root for me"); - } } +SYSINIT(cpu_rootconf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, cpu_rootconf, NULL) u_long bootdev = 0; /* not a dev_t - encoding is different */ -#define FDMAJOR 2 +#if defined(FFS) && defined(FFS_ROOT) +#define FDMAJOR 2 #define FDUNITSHIFT 6 -#if defined(FFS) || defined(FFS_ROOT) /* * Attempt to find the device from which we were booted. * If we can do so, and not instructed not to do so, * set rootdevs[] and rootdevnames[] to correspond to the * boot device(s). + * + * This code survives in order to allow the system to be + * booted from legacy environments that do not correctly + * populate the kernel environment. There are significant + * restrictions on the bootability of the system in this + * situation; it can only be mounting root from a 'da' + * 'wd' or 'fd' device, and the root filesystem must be ufs. */ static void setroot() @@ -365,24 +261,14 @@ setroot() char partname[2]; char *sname; - if (boothowto & RB_DFLTROOT) { -#ifdef ROOTDEVNAME - setrootbyname(ROOTDEVNAME); -#else - setconf(); -#endif - return; - } if ((bootdev & B_MAGICMASK) != B_DEVMAGIC) { printf("no B_DEVMAGIC (bootdev=%#lx)\n", bootdev); - setconf(); return; } majdev = B_TYPE(bootdev); dev = makebdev(majdev, 0); if (devsw(dev) == NULL) { printf("no devsw (majdev=%d bootdev=%#lx)\n", majdev, bootdev); - setconf(); return; } unit = B_UNIT(bootdev); @@ -391,7 +277,6 @@ setroot() slice = COMPATIBILITY_SLICE; if (slice < 0 || slice >= MAX_SLICES) { printf("bad slice\n"); - setconf(); return; } @@ -409,10 +294,9 @@ setroot() } newrootdev = makebdev(majdev, mindev); - rootdevs[0] = newrootdev; sname = dsname(newrootdev, unit, slice, part, partname); - rootdevnames[0] = malloc(strlen(sname) + 2, M_DEVBUF, M_NOWAIT); - sprintf(rootdevnames[0], "%s%s", sname, partname); + rootdevnames[0] = malloc(strlen(sname) + 6, M_DEVBUF, M_NOWAIT); + sprintf(rootdevnames[0], "ufs:%s%s", sname, partname); /* * For properly dangerously dedicated disks (ones with a historical @@ -426,125 +310,8 @@ setroot() if (slice == COMPATIBILITY_SLICE) return; slice = COMPATIBILITY_SLICE; - rootdevs[1] = dkmodslice(newrootdev, slice); sname = dsname(newrootdev, unit, slice, part, partname); - rootdevnames[1] = malloc(strlen(sname) + 2, M_DEVBUF, M_NOWAIT); - sprintf(rootdevnames[1], "%s%s", sname, partname); + rootdevnames[1] = malloc(strlen(sname) + 6, M_DEVBUF, M_NOWAIT); + sprintf(rootdevnames[1], "ufs:%s%s", sname, partname); } #endif - - - -static int -setrootbyname(char *name) -{ - char *cp; - int bd, unit, slice, part; - dev_t dev; - - printf("setrootbyname(\"%s\")\n", name); - slice = 0; - part = 0; - cp = name; - while (cp != '\0' && (*cp < '0' || *cp > '9')) - cp++; - if (cp == name) { - printf("missing device name\n"); - return(1); - } - if (*cp == '\0') { - printf("missing unit number\n"); - return(1); - } - unit = *cp - '0'; - *cp++ = '\0'; - for (bd = 0; bd < NUMCDEVSW; bd++) { - dev = makebdev(bd, 0); - if (devsw(dev) != NULL && - strcmp(devsw(dev)->d_name, name) == 0) - goto gotit; - } - return (2); -gotit: - while (*cp >= '0' && *cp <= '9') - unit += 10 * unit + *cp++ - '0'; - if (*cp == 's' && cp[1] >= '0' && cp[1] <= '9') { - slice = cp[1] - '0' + 1; - cp += 2; - } - if (*cp >= 'a' && *cp <= 'h') { - part = *cp - 'a'; - cp++; - } - if (*cp != '\0') { - printf("junk after name\n"); - return (1); - } - rootdev = makebdev(bd, dkmakeminor(unit, slice, part)); - printf("driver=%s, unit=%d, slice=%d, part=%d -> rootdev=%p\n", - name, unit, slice, part, (void *)rootdev); - return 0; -} - -void -setconf() -{ - char name[128]; - int i; - dev_t dev; - - for(;;) { - printf("root device? "); - gets(name); - i = setrootbyname(name); - if (!i) - return; - - printf("use one of:\n"); - for (i = 0; i < NUMCDEVSW; i++) { - dev = makebdev(i, 0); - if (devsw(dev) != NULL) - printf(" \"%s\"", devsw(dev)->d_name); - } - printf("\nfollowed by a unit number...\n"); - } -} - -static void -gets(cp) - char *cp; -{ - register char *lp; - register int c; - - lp = cp; - for (;;) { - printf("%c", c = cngetc() & 0177); - switch (c) { - case -1: - case '\n': - case '\r': - *lp++ = '\0'; - return; - case '\b': - case '\177': - if (lp > cp) { - printf(" \b"); - lp--; - } - continue; - case '#': - lp--; - if (lp < cp) - lp = cp; - continue; - case '@': - case 'u' & 037: - lp = cp; - printf("%c", '\n'); - continue; - default: - *lp++ = c; - } - } -} diff --git a/sys/kern/vfs_conf.c b/sys/kern/vfs_conf.c index 7c11af7..2de291f 100644 --- a/sys/kern/vfs_conf.c +++ b/sys/kern/vfs_conf.c @@ -1,7 +1,8 @@ -/* - * Copyright (c) 1989, 1993, 1995 - * The Regents of the University of California. All rights reserved. - * Copyright (c) 1995 Artisoft, Inc. All Rights Reserved. +/*- + * Copyright (c) 1999 Michael Smith + * All rights reserved. + * Copyright (c) 1999 Poul-Henning Kamp + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -11,18 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -31,184 +25,302 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)vfs_conf.c 8.8 (Berkeley) 3/31/94 - * $FreeBSD$ + * $FreeBSD$ */ /* - * PURPOSE: This file abstracts the root mounting interface from - * the per file system semantics for handling mounts, - * the overall intent of which is to move the BSD - * internals dependence out of the FS code, both to - * make the FS code more portable and to free up some - * of the BSD internals so that they may more easily - * be changed. + * Locate and mount the root filesystem. + * + * The root filesystem is detailed in the kernel environment variable + * vfs.root.mountfrom, which is expected to be in the general format * - * NOTE1: Code is single entry/single exit to aid debugging - * and conversion for kernel multithreading. + * <vfsname>:[<path>] + * vfsname := the name of a VFS known to the kernel and capable + * of being mounted as root + * path := disk device name or other data used by the filesystem + * to locate its physical store * - * NOTE2: Code notes lock state in headers on entry and exit - * as an aid to conversion for kernel multithreading - * on SMP reentrancy */ -#include "opt_bootp.h" -#include <sys/param.h> /* dev_t (types.h)*/ +#include <sys/param.h> #include <sys/kernel.h> -#include <sys/systm.h> /* rootvp*/ -#include <sys/proc.h> /* curproc*/ -#include <sys/vnode.h> /* NULLVP*/ -#include <sys/mount.h> /* struct mount*/ -#include <sys/malloc.h> /* M_MOUNT*/ +#include <sys/systm.h> +#include <sys/proc.h> +#include <sys/vnode.h> +#include <sys/mount.h> +#include <sys/malloc.h> +#include <sys/reboot.h> +#include <sys/diskslice.h> +#include <sys/disklabel.h> +#include <sys/conf.h> +#include <sys/cons.h> -/* - * GLOBALS - */ +MALLOC_DEFINE(M_MOUNT, "mount", "vfs mount structure"); -MALLOC_DEFINE(M_MOUNT, "mount", "vfs mount struct"); +#define ROOTNAME "root_device" -/* - * These define the root filesystem, device, and root filesystem type. - */ -dev_t rootdevs[] = { NODEV, NODEV }; -char *rootdevnames[2]; -struct vnode *rootvnode; -char *mountrootfsname; -#ifdef BOOTP -extern void bootpc_init __P((void)); -#endif +struct vnode *rootvnode; -/* - * vfs_init() will set maxvfsconf - * to the highest defined type number. - */ -int maxvfsconf; -struct vfsconf *vfsconf; +static void vfs_mountroot(void *junk); +static int vfs_mountroot_try(char *mountfrom); +static int vfs_mountroot_ask(void); +static void gets(char *cp); -/* - * Common root mount code shared by all filesystems - */ -#define ROOTNAME "root_device" +/* legacy find-root code */ +char *rootdevnames[2] = {NULL, NULL}; +static int setrootbyname(char *name); +SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, vfs_mountroot, NULL); + /* - * vfs_mountrootfs - * - * Common entry point for root mounts - * - * PARAMETERS: - * NONE - * - * RETURNS: 0 Success - * !0 error number (errno.h) - * - * LOCK STATE: - * ENTRY - * <no locks held> - * EXIT - * <no locks held> - * - * NOTES: - * This code is currently supported only for use for - * the FFS file system type. This is a matter of - * fixing the other file systems, not this code! + * Find and mount the root filesystem */ static void -vfs_mountrootfs(void *unused) +vfs_mountroot(void *junk) { - struct mount *mp; - int err; - struct proc *p = curproc; /* XXX */ - int s; - int i; - dev_t orootdev; - -#ifdef BOOTP - bootpc_init(); + /* + * The root filesystem information is compiled in, and we are + * booted with instructions to use it. + */ +#ifdef ROOTDEVNAME + if ((boothowto & RB_DFLTROOT) && + !vfs_mountroot_try(ROOTDEVNAME)) + return; #endif - /* - * New root mount structure + /* + * We are booted with instructions to prompt for the root filesystem, + * or to use the compiled-in default when it doesn't exist. */ - if ((err = vfs_rootmountalloc(mountrootfsname, ROOTNAME, &mp))) { - printf("rootdev=%p error=%d, ", (void *)rootdev, err); - panic("cannot mount root\n"); - return ; + if (boothowto & (RB_DFLTROOT | RB_ASKNAME)) { + if (!vfs_mountroot_ask()) + return; } - mp->mnt_flag |= MNT_ROOTFS; /* - * If we have no idea what the device is because the VFS root mount - * initialization code couldn't figure it out, take a guess by - * assuming that vfs_getnewfsid() will be called when we try the - * mount. For the moment this is necessary for NFS-baesd BOOTP - * boots. Ultimately we would like to get rid of 'rootdev' entirely - * and go with a linked list of possible roots and device-specific - * auxillary data that we do not try to interpret ourselves. + * Try to use the value read by the loader from /etc/fstab, or + * supplied via some other means. This is the preferred + * mechanism. */ - if (rootdev == NODEV && rootdevs[0] == NODEV) - rootdev = vfs_getrootfsid(mp); + if (!vfs_mountroot_try(getenv("vfs.root.mountfrom"))) + return; + + /* + * Try values that may have been computed by the machine-dependant + * legacy code. + */ + if (!vfs_mountroot_try(rootdevnames[0])) + return; + if (!vfs_mountroot_try(rootdevnames[1])) + return; /* - * Attempt the mount. This is rather messy due to many historical - * layers. Basically what it comes down to is that 'rootdev' is an - * override to the rootdevs[] array. The rootdevs[] array itself - * cannot normally be accessed directly by other modules, but FFS - * plays with it. NFS, on the otherhand, has no clue what the - * device assignment for a mount will be until it actually does it. - * - * During the loop we set rootdev to rootdevs[i]. This is used - * by FFS and a few other modules. It is ignored by NFS. + * If we have a compiled-in default, and haven't already tried it, try + * it now. */ - err = ENXIO; - orootdev = rootdev; - if (rootdevs[0] == NODEV) - rootdevs[0] = rootdev; - for (i = 0; i < sizeof(rootdevs) / sizeof(rootdevs[0]); i++) { - if (rootdevs[i] == NODEV) - break; - rootdev = rootdevs[i]; - if (rootdev != orootdev) { - s = splbio(); /* Overkill, but harmless.. */ - printf("changing root device to %s\n", rootdevnames[i]); - splx(s); - orootdev = rootdev; - } - strncpy(mp->mnt_stat.f_mntfromname, - rootdevnames[i] ? rootdevnames[i] : ROOTNAME, MNAMELEN - 1); - err = VFS_MOUNT(mp, NULL, NULL, NULL, p); - if (err != ENXIO) - break; - } - if (err) { - /* - * XXX should ask the user for the name in some cases. - * Why do we call vfs_unbusy() here and not after ENXIO - * is returned above? - */ - vfs_unbusy(mp, p); - /* - * free mount struct before failing - * (hardly worthwhile with the PANIC eh?) - */ - free( mp, M_MOUNT); - printf("rootdev=%p error=%d, ", (void *)rootdev, err); - panic("cannot mount root (2)\n"); +#ifdef ROOTDEVNAME + if (!(boothowto & RB_DFLTROOT)) + !vfs_mountroot_try(ROOTDEVNAME)) return; +#endif + + /* + * Everything so far has failed, prompt on the console if we haven't + * already tried that. + */ + if (!(boothowto & (RB_DFLTROOT | RB_ASKNAME)) && !vfs_mountroot_ask()) + return; + panic("Root mount failed, startup aborted."); +} + +/* + * Mount (mountfrom) as the root filesystem. + */ +static int +vfs_mountroot_try(char *mountfrom) +{ + struct mount *mp; + char *vfsname, *path; + int error; + char patt[16]; + + vfsname = path = NULL; + error = EINVAL; + + if (mountfrom == NULL) + goto done; + + printf("Mounting root from %s\n", mountfrom); + + /* parse vfs name and path */ + vfsname = malloc(MFSNAMELEN, M_MOUNT, M_WAITOK); + path = malloc(MNAMELEN, M_MOUNT, M_WAITOK); + sprintf(patt, "%%%d[a-z]:%%%ds", MFSNAMELEN, MNAMELEN); + if (sscanf(mountfrom, patt, vfsname, path) != 2) + goto done; + + /* allocate a root mount */ + if ((error = vfs_rootmountalloc(vfsname, ROOTNAME, &mp))) { + printf("Can't allocate root mount for filesystem '%s': %d\n", + vfsname, error); + goto done; } + mp->mnt_flag |= MNT_ROOTFS; - simple_lock(&mountlist_slock); + /* do our best to set rootdev */ + if (setrootbyname(path)) + printf("setrootbyname failed\n"); - /* - * Add fs to list of mounted file systems - */ - CIRCLEQ_INSERT_HEAD(&mountlist, mp, mnt_list); + strcpy(mp->mnt_stat.f_mntfromname, path); + error = VFS_MOUNT(mp, NULL, NULL, NULL, curproc); + +done: + free(vfsname, M_MOUNT); + free(path, M_MOUNT); + if (error != 0) { + if (mp != NULL) + free(mp, M_MOUNT); + printf("Root mount failed: %d\n", error); + } else { + + /* register with list of mounted filesystems */ + simple_lock(&mountlist_slock); + CIRCLEQ_INSERT_HEAD(&mountlist, mp, mnt_list); + simple_unlock(&mountlist_slock); + + /* sanity check system clock against root filesystem timestamp */ + inittodr(mp->mnt_time); + } + vfs_unbusy(mp, curproc); + return(error); +} + +/* + * Spin prompting on the console for a suitable root filesystem + */ +static int +vfs_mountroot_ask(void) +{ + char name[128]; + int i; + dev_t dev; + + for(;;) { + printf("\nManual root filesystem specification:\n"); + printf(" <fstype>:<device> Mount <device> using filesystem <fstype>\n"); + printf(" eg. ufs:/dev/da0s1a\n"); + printf(" ? List valid disk boot devices\n"); + printf(" <empty line> Abort manual input\n"); + printf("\n>>> "); + gets(name); + if (name[0] == 0) + return(1); + if (name[0] == '?') { + printf("Possibly valid devices for 'ufs' root:\n"); + for (i = 0; i < NUMCDEVSW; i++) { + dev = makebdev(i, 0); + if (devsw(dev) != NULL) + printf(" \"%s\"", devsw(dev)->d_name); + } + printf("\n"); + continue; + } + if (!vfs_mountroot_try(name)) + return(0); + } +} - simple_unlock(&mountlist_slock); - vfs_unbusy(mp, p); +static void +gets(char *cp) +{ + char *lp; + int c; - /* root mount, update system time from FS specific data*/ - inittodr(mp->mnt_time); - return; + lp = cp; + for (;;) { + printf("%c", c = cngetc() & 0177); + switch (c) { + case -1: + case '\n': + case '\r': + *lp++ = '\0'; + return; + case '\b': + case '\177': + if (lp > cp) { + printf(" \b"); + lp--; + } + continue; + case '#': + lp--; + if (lp < cp) + lp = cp; + continue; + case '@': + case 'u' & 037: + lp = cp; + printf("%c", '\n'); + continue; + default: + *lp++ = c; + } + } } -SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, vfs_mountrootfs, NULL) +/* + * Set rootdev to match (name), given that we expect it to + * refer to a disk-like device. + */ +static int +setrootbyname(char *name) +{ + char *cp; + int bd, unit, slice, part; + dev_t dev; + + slice = 0; + part = 0; + cp = rindex(name, '/'); + if (cp != NULL) { + name = cp + 1; + } + cp = name; + while (cp != '\0' && (*cp < '0' || *cp > '9')) + cp++; + if (cp == name) { + printf("missing device name\n"); + return(1); + } + if (*cp == '\0') { + printf("missing unit number\n"); + return(1); + } + unit = *cp - '0'; + *cp++ = '\0'; + for (bd = 0; bd < NUMCDEVSW; bd++) { + dev = makebdev(bd, 0); + if (devsw(dev) != NULL && + strcmp(devsw(dev)->d_name, name) == 0) + goto gotit; + } + printf("no such device '%s'\n", name); + return (2); +gotit: + while (*cp >= '0' && *cp <= '9') + unit += 10 * unit + *cp++ - '0'; + if (*cp == 's' && cp[1] >= '0' && cp[1] <= '9') { + slice = cp[1] - '0' + 1; + cp += 2; + } + if (*cp >= 'a' && *cp <= 'h') { + part = *cp - 'a'; + cp++; + } + if (*cp != '\0') { + printf("junk after name\n"); + return (1); + } + rootdev = makebdev(bd, dkmakeminor(unit, slice, part)); + return 0; +} diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 7c11af7..2de291f 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -1,7 +1,8 @@ -/* - * Copyright (c) 1989, 1993, 1995 - * The Regents of the University of California. All rights reserved. - * Copyright (c) 1995 Artisoft, Inc. All Rights Reserved. +/*- + * Copyright (c) 1999 Michael Smith + * All rights reserved. + * Copyright (c) 1999 Poul-Henning Kamp + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -11,18 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -31,184 +25,302 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)vfs_conf.c 8.8 (Berkeley) 3/31/94 - * $FreeBSD$ + * $FreeBSD$ */ /* - * PURPOSE: This file abstracts the root mounting interface from - * the per file system semantics for handling mounts, - * the overall intent of which is to move the BSD - * internals dependence out of the FS code, both to - * make the FS code more portable and to free up some - * of the BSD internals so that they may more easily - * be changed. + * Locate and mount the root filesystem. + * + * The root filesystem is detailed in the kernel environment variable + * vfs.root.mountfrom, which is expected to be in the general format * - * NOTE1: Code is single entry/single exit to aid debugging - * and conversion for kernel multithreading. + * <vfsname>:[<path>] + * vfsname := the name of a VFS known to the kernel and capable + * of being mounted as root + * path := disk device name or other data used by the filesystem + * to locate its physical store * - * NOTE2: Code notes lock state in headers on entry and exit - * as an aid to conversion for kernel multithreading - * on SMP reentrancy */ -#include "opt_bootp.h" -#include <sys/param.h> /* dev_t (types.h)*/ +#include <sys/param.h> #include <sys/kernel.h> -#include <sys/systm.h> /* rootvp*/ -#include <sys/proc.h> /* curproc*/ -#include <sys/vnode.h> /* NULLVP*/ -#include <sys/mount.h> /* struct mount*/ -#include <sys/malloc.h> /* M_MOUNT*/ +#include <sys/systm.h> +#include <sys/proc.h> +#include <sys/vnode.h> +#include <sys/mount.h> +#include <sys/malloc.h> +#include <sys/reboot.h> +#include <sys/diskslice.h> +#include <sys/disklabel.h> +#include <sys/conf.h> +#include <sys/cons.h> -/* - * GLOBALS - */ +MALLOC_DEFINE(M_MOUNT, "mount", "vfs mount structure"); -MALLOC_DEFINE(M_MOUNT, "mount", "vfs mount struct"); +#define ROOTNAME "root_device" -/* - * These define the root filesystem, device, and root filesystem type. - */ -dev_t rootdevs[] = { NODEV, NODEV }; -char *rootdevnames[2]; -struct vnode *rootvnode; -char *mountrootfsname; -#ifdef BOOTP -extern void bootpc_init __P((void)); -#endif +struct vnode *rootvnode; -/* - * vfs_init() will set maxvfsconf - * to the highest defined type number. - */ -int maxvfsconf; -struct vfsconf *vfsconf; +static void vfs_mountroot(void *junk); +static int vfs_mountroot_try(char *mountfrom); +static int vfs_mountroot_ask(void); +static void gets(char *cp); -/* - * Common root mount code shared by all filesystems - */ -#define ROOTNAME "root_device" +/* legacy find-root code */ +char *rootdevnames[2] = {NULL, NULL}; +static int setrootbyname(char *name); +SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, vfs_mountroot, NULL); + /* - * vfs_mountrootfs - * - * Common entry point for root mounts - * - * PARAMETERS: - * NONE - * - * RETURNS: 0 Success - * !0 error number (errno.h) - * - * LOCK STATE: - * ENTRY - * <no locks held> - * EXIT - * <no locks held> - * - * NOTES: - * This code is currently supported only for use for - * the FFS file system type. This is a matter of - * fixing the other file systems, not this code! + * Find and mount the root filesystem */ static void -vfs_mountrootfs(void *unused) +vfs_mountroot(void *junk) { - struct mount *mp; - int err; - struct proc *p = curproc; /* XXX */ - int s; - int i; - dev_t orootdev; - -#ifdef BOOTP - bootpc_init(); + /* + * The root filesystem information is compiled in, and we are + * booted with instructions to use it. + */ +#ifdef ROOTDEVNAME + if ((boothowto & RB_DFLTROOT) && + !vfs_mountroot_try(ROOTDEVNAME)) + return; #endif - /* - * New root mount structure + /* + * We are booted with instructions to prompt for the root filesystem, + * or to use the compiled-in default when it doesn't exist. */ - if ((err = vfs_rootmountalloc(mountrootfsname, ROOTNAME, &mp))) { - printf("rootdev=%p error=%d, ", (void *)rootdev, err); - panic("cannot mount root\n"); - return ; + if (boothowto & (RB_DFLTROOT | RB_ASKNAME)) { + if (!vfs_mountroot_ask()) + return; } - mp->mnt_flag |= MNT_ROOTFS; /* - * If we have no idea what the device is because the VFS root mount - * initialization code couldn't figure it out, take a guess by - * assuming that vfs_getnewfsid() will be called when we try the - * mount. For the moment this is necessary for NFS-baesd BOOTP - * boots. Ultimately we would like to get rid of 'rootdev' entirely - * and go with a linked list of possible roots and device-specific - * auxillary data that we do not try to interpret ourselves. + * Try to use the value read by the loader from /etc/fstab, or + * supplied via some other means. This is the preferred + * mechanism. */ - if (rootdev == NODEV && rootdevs[0] == NODEV) - rootdev = vfs_getrootfsid(mp); + if (!vfs_mountroot_try(getenv("vfs.root.mountfrom"))) + return; + + /* + * Try values that may have been computed by the machine-dependant + * legacy code. + */ + if (!vfs_mountroot_try(rootdevnames[0])) + return; + if (!vfs_mountroot_try(rootdevnames[1])) + return; /* - * Attempt the mount. This is rather messy due to many historical - * layers. Basically what it comes down to is that 'rootdev' is an - * override to the rootdevs[] array. The rootdevs[] array itself - * cannot normally be accessed directly by other modules, but FFS - * plays with it. NFS, on the otherhand, has no clue what the - * device assignment for a mount will be until it actually does it. - * - * During the loop we set rootdev to rootdevs[i]. This is used - * by FFS and a few other modules. It is ignored by NFS. + * If we have a compiled-in default, and haven't already tried it, try + * it now. */ - err = ENXIO; - orootdev = rootdev; - if (rootdevs[0] == NODEV) - rootdevs[0] = rootdev; - for (i = 0; i < sizeof(rootdevs) / sizeof(rootdevs[0]); i++) { - if (rootdevs[i] == NODEV) - break; - rootdev = rootdevs[i]; - if (rootdev != orootdev) { - s = splbio(); /* Overkill, but harmless.. */ - printf("changing root device to %s\n", rootdevnames[i]); - splx(s); - orootdev = rootdev; - } - strncpy(mp->mnt_stat.f_mntfromname, - rootdevnames[i] ? rootdevnames[i] : ROOTNAME, MNAMELEN - 1); - err = VFS_MOUNT(mp, NULL, NULL, NULL, p); - if (err != ENXIO) - break; - } - if (err) { - /* - * XXX should ask the user for the name in some cases. - * Why do we call vfs_unbusy() here and not after ENXIO - * is returned above? - */ - vfs_unbusy(mp, p); - /* - * free mount struct before failing - * (hardly worthwhile with the PANIC eh?) - */ - free( mp, M_MOUNT); - printf("rootdev=%p error=%d, ", (void *)rootdev, err); - panic("cannot mount root (2)\n"); +#ifdef ROOTDEVNAME + if (!(boothowto & RB_DFLTROOT)) + !vfs_mountroot_try(ROOTDEVNAME)) return; +#endif + + /* + * Everything so far has failed, prompt on the console if we haven't + * already tried that. + */ + if (!(boothowto & (RB_DFLTROOT | RB_ASKNAME)) && !vfs_mountroot_ask()) + return; + panic("Root mount failed, startup aborted."); +} + +/* + * Mount (mountfrom) as the root filesystem. + */ +static int +vfs_mountroot_try(char *mountfrom) +{ + struct mount *mp; + char *vfsname, *path; + int error; + char patt[16]; + + vfsname = path = NULL; + error = EINVAL; + + if (mountfrom == NULL) + goto done; + + printf("Mounting root from %s\n", mountfrom); + + /* parse vfs name and path */ + vfsname = malloc(MFSNAMELEN, M_MOUNT, M_WAITOK); + path = malloc(MNAMELEN, M_MOUNT, M_WAITOK); + sprintf(patt, "%%%d[a-z]:%%%ds", MFSNAMELEN, MNAMELEN); + if (sscanf(mountfrom, patt, vfsname, path) != 2) + goto done; + + /* allocate a root mount */ + if ((error = vfs_rootmountalloc(vfsname, ROOTNAME, &mp))) { + printf("Can't allocate root mount for filesystem '%s': %d\n", + vfsname, error); + goto done; } + mp->mnt_flag |= MNT_ROOTFS; - simple_lock(&mountlist_slock); + /* do our best to set rootdev */ + if (setrootbyname(path)) + printf("setrootbyname failed\n"); - /* - * Add fs to list of mounted file systems - */ - CIRCLEQ_INSERT_HEAD(&mountlist, mp, mnt_list); + strcpy(mp->mnt_stat.f_mntfromname, path); + error = VFS_MOUNT(mp, NULL, NULL, NULL, curproc); + +done: + free(vfsname, M_MOUNT); + free(path, M_MOUNT); + if (error != 0) { + if (mp != NULL) + free(mp, M_MOUNT); + printf("Root mount failed: %d\n", error); + } else { + + /* register with list of mounted filesystems */ + simple_lock(&mountlist_slock); + CIRCLEQ_INSERT_HEAD(&mountlist, mp, mnt_list); + simple_unlock(&mountlist_slock); + + /* sanity check system clock against root filesystem timestamp */ + inittodr(mp->mnt_time); + } + vfs_unbusy(mp, curproc); + return(error); +} + +/* + * Spin prompting on the console for a suitable root filesystem + */ +static int +vfs_mountroot_ask(void) +{ + char name[128]; + int i; + dev_t dev; + + for(;;) { + printf("\nManual root filesystem specification:\n"); + printf(" <fstype>:<device> Mount <device> using filesystem <fstype>\n"); + printf(" eg. ufs:/dev/da0s1a\n"); + printf(" ? List valid disk boot devices\n"); + printf(" <empty line> Abort manual input\n"); + printf("\n>>> "); + gets(name); + if (name[0] == 0) + return(1); + if (name[0] == '?') { + printf("Possibly valid devices for 'ufs' root:\n"); + for (i = 0; i < NUMCDEVSW; i++) { + dev = makebdev(i, 0); + if (devsw(dev) != NULL) + printf(" \"%s\"", devsw(dev)->d_name); + } + printf("\n"); + continue; + } + if (!vfs_mountroot_try(name)) + return(0); + } +} - simple_unlock(&mountlist_slock); - vfs_unbusy(mp, p); +static void +gets(char *cp) +{ + char *lp; + int c; - /* root mount, update system time from FS specific data*/ - inittodr(mp->mnt_time); - return; + lp = cp; + for (;;) { + printf("%c", c = cngetc() & 0177); + switch (c) { + case -1: + case '\n': + case '\r': + *lp++ = '\0'; + return; + case '\b': + case '\177': + if (lp > cp) { + printf(" \b"); + lp--; + } + continue; + case '#': + lp--; + if (lp < cp) + lp = cp; + continue; + case '@': + case 'u' & 037: + lp = cp; + printf("%c", '\n'); + continue; + default: + *lp++ = c; + } + } } -SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, vfs_mountrootfs, NULL) +/* + * Set rootdev to match (name), given that we expect it to + * refer to a disk-like device. + */ +static int +setrootbyname(char *name) +{ + char *cp; + int bd, unit, slice, part; + dev_t dev; + + slice = 0; + part = 0; + cp = rindex(name, '/'); + if (cp != NULL) { + name = cp + 1; + } + cp = name; + while (cp != '\0' && (*cp < '0' || *cp > '9')) + cp++; + if (cp == name) { + printf("missing device name\n"); + return(1); + } + if (*cp == '\0') { + printf("missing unit number\n"); + return(1); + } + unit = *cp - '0'; + *cp++ = '\0'; + for (bd = 0; bd < NUMCDEVSW; bd++) { + dev = makebdev(bd, 0); + if (devsw(dev) != NULL && + strcmp(devsw(dev)->d_name, name) == 0) + goto gotit; + } + printf("no such device '%s'\n", name); + return (2); +gotit: + while (*cp >= '0' && *cp <= '9') + unit += 10 * unit + *cp++ - '0'; + if (*cp == 's' && cp[1] >= '0' && cp[1] <= '9') { + slice = cp[1] - '0' + 1; + cp += 2; + } + if (*cp >= 'a' && *cp <= 'h') { + part = *cp - 'a'; + cp++; + } + if (*cp != '\0') { + printf("junk after name\n"); + return (1); + } + rootdev = makebdev(bd, dkmakeminor(unit, slice, part)); + return 0; +} |