From 95f37fa61f0369de0371a6bf8130069d219f5fc6 Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Sun, 8 Mar 1998 14:50:04 +0000 Subject: [PATCH] If we are mounting the root filesystem, and we're accessing it through something that might refer to the compatability slice rather than the correct slice entry, try all the possible slice entries first. This is a compatability hack to deal with the case where the kernel has correctly mounted the root filesystem out of its slice, but the user has not updated their /etc/fstab file to reflect this. A diagnostic is emitted if the mount succeeds, indicating that the file should be updated. This is a prelude to fixing the kernel to behave as alluded to above. Reviewed by: (discussed with) julian, phk --- sbin/mount/Makefile | 5 ++++- sbin/mount/mount_ufs.c | 36 ++++++++++++++++++++++++++++++++++-- sbin/mount_ifs/Makefile | 5 ++++- sbin/mount_ifs/mount_ufs.c | 36 ++++++++++++++++++++++++++++++++++-- 4 files changed, 76 insertions(+), 6 deletions(-) diff --git a/sbin/mount/Makefile b/sbin/mount/Makefile index df4ebcf8d3c1..e899d4ed6f75 100644 --- a/sbin/mount/Makefile +++ b/sbin/mount/Makefile @@ -1,9 +1,12 @@ # @(#)Makefile 8.6 (Berkeley) 5/8/95 -# $Id: Makefile,v 1.5 1997/08/25 20:38:35 bde Exp $ +# $Id: Makefile,v 1.6 1998/01/20 10:39:57 bde Exp $ PROG= mount SRCS= mount.c mount_ufs.c getmntopts.c vfslist.c MAN8= mount.8 # We do NOT install the getmntopts.3 man page. +# We support the ROOTSLICE_HUNT hack +CFLAGS+=-DROOTSLICE_HUNT + .include diff --git a/sbin/mount/mount_ufs.c b/sbin/mount/mount_ufs.c index f40fe32f58bf..cefdd9665d76 100644 --- a/sbin/mount/mount_ufs.c +++ b/sbin/mount/mount_ufs.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)mount_ufs.c 8.4 (Berkeley) 4/26/95"; #else static const char rcsid[] = - "$Id: mount_ufs.c,v 1.9 1997/08/24 21:02:50 steve Exp $"; + "$Id: mount_ufs.c,v 1.10 1997/08/25 21:14:22 bde Exp $"; #endif #endif /* not lint */ @@ -83,6 +83,10 @@ mount_ufs(argc, argv) char *fs_name; struct vfsconf vfc; int error = 0; +#ifdef ROOTSLICE_HUNT + int slice, part, result; + char devbuf[MAXPATHLEN], devpfx[MAXPATHLEN]; +#endif mntflags = 0; optind = optreset = 1; /* Reset for parse of new argv. */ @@ -124,8 +128,36 @@ mount_ufs(argc, argv) warnx("ufs filesystem is not available"); return (1); } - +#ifdef ROOTSLICE_HUNT + result = -1; + /* + * If we are mounting root, and we have a mount of something that + * might be the compatability slice, try mounting other slices + * first. If the kernel has done the right thing and mounted + * the slice because the disk is really sliced, this will find + * the real root filesystem. If not, we'll try what was supplied. + */ + if (!strcmp(fs_name, "/") && + (sscanf(args.fspec, "%[^0-9]%d%c", devpfx, &unit, &part) == 3) && + (part >= 'a') && + (part <= 'h')) { + for (slice = 1; (slice < 32) && (result < 0); slice++) { + sprintf(devbuf, "%s%ds%d%c", + devpfx, unit, slice, part); + args.fspec = devbuf; + result = mount(vfc.vfc_name, fs_name, mntflags, &args); + } + args.fspec = argv[0]; + } + if (result == 0) + warnx("*** update /etc/fstab entry for %s to use %s ***", + fs_name, devbuf); + /* Try the mount as originally requested */ + if ((result < 0) && + (mount(vfc.vfc_name, fs_name, mntflags, &args < 0)) { +#else if (mount(vfc.vfc_name, fs_name, mntflags, &args) < 0) { +#endif (void)fprintf(stderr, "%s on %s: ", args.fspec, fs_name); switch (errno) { case EMFILE: diff --git a/sbin/mount_ifs/Makefile b/sbin/mount_ifs/Makefile index df4ebcf8d3c1..e899d4ed6f75 100644 --- a/sbin/mount_ifs/Makefile +++ b/sbin/mount_ifs/Makefile @@ -1,9 +1,12 @@ # @(#)Makefile 8.6 (Berkeley) 5/8/95 -# $Id: Makefile,v 1.5 1997/08/25 20:38:35 bde Exp $ +# $Id: Makefile,v 1.6 1998/01/20 10:39:57 bde Exp $ PROG= mount SRCS= mount.c mount_ufs.c getmntopts.c vfslist.c MAN8= mount.8 # We do NOT install the getmntopts.3 man page. +# We support the ROOTSLICE_HUNT hack +CFLAGS+=-DROOTSLICE_HUNT + .include diff --git a/sbin/mount_ifs/mount_ufs.c b/sbin/mount_ifs/mount_ufs.c index f40fe32f58bf..cefdd9665d76 100644 --- a/sbin/mount_ifs/mount_ufs.c +++ b/sbin/mount_ifs/mount_ufs.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)mount_ufs.c 8.4 (Berkeley) 4/26/95"; #else static const char rcsid[] = - "$Id: mount_ufs.c,v 1.9 1997/08/24 21:02:50 steve Exp $"; + "$Id: mount_ufs.c,v 1.10 1997/08/25 21:14:22 bde Exp $"; #endif #endif /* not lint */ @@ -83,6 +83,10 @@ mount_ufs(argc, argv) char *fs_name; struct vfsconf vfc; int error = 0; +#ifdef ROOTSLICE_HUNT + int slice, part, result; + char devbuf[MAXPATHLEN], devpfx[MAXPATHLEN]; +#endif mntflags = 0; optind = optreset = 1; /* Reset for parse of new argv. */ @@ -124,8 +128,36 @@ mount_ufs(argc, argv) warnx("ufs filesystem is not available"); return (1); } - +#ifdef ROOTSLICE_HUNT + result = -1; + /* + * If we are mounting root, and we have a mount of something that + * might be the compatability slice, try mounting other slices + * first. If the kernel has done the right thing and mounted + * the slice because the disk is really sliced, this will find + * the real root filesystem. If not, we'll try what was supplied. + */ + if (!strcmp(fs_name, "/") && + (sscanf(args.fspec, "%[^0-9]%d%c", devpfx, &unit, &part) == 3) && + (part >= 'a') && + (part <= 'h')) { + for (slice = 1; (slice < 32) && (result < 0); slice++) { + sprintf(devbuf, "%s%ds%d%c", + devpfx, unit, slice, part); + args.fspec = devbuf; + result = mount(vfc.vfc_name, fs_name, mntflags, &args); + } + args.fspec = argv[0]; + } + if (result == 0) + warnx("*** update /etc/fstab entry for %s to use %s ***", + fs_name, devbuf); + /* Try the mount as originally requested */ + if ((result < 0) && + (mount(vfc.vfc_name, fs_name, mntflags, &args < 0)) { +#else if (mount(vfc.vfc_name, fs_name, mntflags, &args) < 0) { +#endif (void)fprintf(stderr, "%s on %s: ", args.fspec, fs_name); switch (errno) { case EMFILE: