diff options
-rw-r--r-- | sys/kern/vfs_conf.c | 18 | ||||
-rw-r--r-- | sys/kern/vfs_mount.c | 18 | ||||
-rw-r--r-- | sys/ufs/mfs/mfs_vfsops.c | 44 |
3 files changed, 50 insertions, 30 deletions
diff --git a/sys/kern/vfs_conf.c b/sys/kern/vfs_conf.c index 2de291f..b0f3646 100644 --- a/sys/kern/vfs_conf.c +++ b/sys/kern/vfs_conf.c @@ -70,7 +70,7 @@ static void gets(char *cp); char *rootdevnames[2] = {NULL, NULL}; static int setrootbyname(char *name); -SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, vfs_mountroot, NULL); +SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_SECOND, vfs_mountroot, NULL); /* * Find and mount the root filesystem @@ -119,8 +119,8 @@ vfs_mountroot(void *junk) */ #ifdef ROOTDEVNAME if (!(boothowto & RB_DFLTROOT)) - !vfs_mountroot_try(ROOTDEVNAME)) - return; + if (!vfs_mountroot_try(ROOTDEVNAME)) + return; #endif /* @@ -138,12 +138,12 @@ vfs_mountroot(void *junk) static int vfs_mountroot_try(char *mountfrom) { - struct mount *mp; + struct mount *mp; char *vfsname, *path; int error; char patt[16]; - vfsname = path = NULL; + vfsname = path = mp = NULL; error = EINVAL; if (mountfrom == NULL) @@ -154,8 +154,9 @@ vfs_mountroot_try(char *mountfrom) /* parse vfs name and path */ vfsname = malloc(MFSNAMELEN, M_MOUNT, M_WAITOK); path = malloc(MNAMELEN, M_MOUNT, M_WAITOK); + vfsname[0] = path[0] = 0; sprintf(patt, "%%%d[a-z]:%%%ds", MFSNAMELEN, MNAMELEN); - if (sscanf(mountfrom, patt, vfsname, path) != 2) + if (sscanf(mountfrom, patt, vfsname, path) < 1) goto done; /* allocate a root mount */ @@ -167,7 +168,7 @@ vfs_mountroot_try(char *mountfrom) mp->mnt_flag |= MNT_ROOTFS; /* do our best to set rootdev */ - if (setrootbyname(path)) + if ((path[0] != 0) && setrootbyname(path)) printf("setrootbyname failed\n"); strcpy(mp->mnt_stat.f_mntfromname, path); @@ -190,7 +191,8 @@ done: /* sanity check system clock against root filesystem timestamp */ inittodr(mp->mnt_time); } - vfs_unbusy(mp, curproc); + if (mp != NULL) + vfs_unbusy(mp, curproc); return(error); } diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 2de291f..b0f3646 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -70,7 +70,7 @@ static void gets(char *cp); char *rootdevnames[2] = {NULL, NULL}; static int setrootbyname(char *name); -SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, vfs_mountroot, NULL); +SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_SECOND, vfs_mountroot, NULL); /* * Find and mount the root filesystem @@ -119,8 +119,8 @@ vfs_mountroot(void *junk) */ #ifdef ROOTDEVNAME if (!(boothowto & RB_DFLTROOT)) - !vfs_mountroot_try(ROOTDEVNAME)) - return; + if (!vfs_mountroot_try(ROOTDEVNAME)) + return; #endif /* @@ -138,12 +138,12 @@ vfs_mountroot(void *junk) static int vfs_mountroot_try(char *mountfrom) { - struct mount *mp; + struct mount *mp; char *vfsname, *path; int error; char patt[16]; - vfsname = path = NULL; + vfsname = path = mp = NULL; error = EINVAL; if (mountfrom == NULL) @@ -154,8 +154,9 @@ vfs_mountroot_try(char *mountfrom) /* parse vfs name and path */ vfsname = malloc(MFSNAMELEN, M_MOUNT, M_WAITOK); path = malloc(MNAMELEN, M_MOUNT, M_WAITOK); + vfsname[0] = path[0] = 0; sprintf(patt, "%%%d[a-z]:%%%ds", MFSNAMELEN, MNAMELEN); - if (sscanf(mountfrom, patt, vfsname, path) != 2) + if (sscanf(mountfrom, patt, vfsname, path) < 1) goto done; /* allocate a root mount */ @@ -167,7 +168,7 @@ vfs_mountroot_try(char *mountfrom) mp->mnt_flag |= MNT_ROOTFS; /* do our best to set rootdev */ - if (setrootbyname(path)) + if ((path[0] != 0) && setrootbyname(path)) printf("setrootbyname failed\n"); strcpy(mp->mnt_stat.f_mntfromname, path); @@ -190,7 +191,8 @@ done: /* sanity check system clock against root filesystem timestamp */ inittodr(mp->mnt_time); } - vfs_unbusy(mp, curproc); + if (mp != NULL) + vfs_unbusy(mp, curproc); return(error); } diff --git a/sys/ufs/mfs/mfs_vfsops.c b/sys/ufs/mfs/mfs_vfsops.c index 9b35b46..dcd766e 100644 --- a/sys/ufs/mfs/mfs_vfsops.c +++ b/sys/ufs/mfs/mfs_vfsops.c @@ -78,6 +78,7 @@ static int mfs_start __P((struct mount *mp, int flags, struct proc *p)); static int mfs_statfs __P((struct mount *mp, struct statfs *sbp, struct proc *p)); static int mfs_init __P((struct vfsconf *)); +static void mfs_takeroot __P((void *)); static struct cdevsw mfs_cdevsw = { /* open */ noopen, @@ -228,8 +229,14 @@ mfs_mount(mp, path, data, ndp, p) mfs_rootbase = base; mfs_rootsize = fs->fs_fsize * fs->fs_size; - printf("rootfs is %ld Kbyte compiled in MFS\n", - mfs_rootsize/1024); + + /* remake rootdev, since vfs_mountroot will have it wrong */ + rootdev = make_dev(&mfs_cdevsw, mfs_minor, + 0, 0, 0, "MFS%d", mfs_minor); + rootdev->si_bsize_phys = DEV_BSIZE; + rootdev->si_iosize_max = DFLTPHYS; + mfs_minor++; + if ((err = bdevvp(rootdev, &rootvp))) { printf("mfs_mount: can't find rootvp\n"); return (err); @@ -486,19 +493,28 @@ mfs_init(vfsp) { cdevsw_add(&mfs_cdevsw); + return (0); +} + #ifdef MFS_ROOT +/* + * Just before root is mounted, check to see if we are a candidate + * to supply it. If we have an image available, override the guessed + * defaults. + */ +static void +mfs_takeroot(junk) + void *junk; +{ if (bootverbose) - printf("Considering MFS root f/s.\n"); + printf("Considering MFS root f/s..."); if (mfs_getimage()) { - mountrootfsname = "mfs"; - rootdev = make_dev(&mfs_cdevsw, mfs_minor, - 0, 0, 0, "MFS%d", mfs_minor); - /* It is not clear that these will get initialized otherwise */ - rootdev->si_bsize_phys = DEV_BSIZE; - rootdev->si_iosize_max = DFLTPHYS; - mfs_minor++; - } else if (bootverbose) - printf("No MFS image available as root f/s.\n"); -#endif - return (0); + rootdevnames[0] = "mfs:"; + printf("preloaded filesystem found.\n"); + } else if (bootverbose) { + printf("not found.\n"); + } } + +SYSINIT(mfs_root, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, mfs_takeroot, NULL); +#endif |