summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1999-01-01 14:14:44 +0000
committerbde <bde@FreeBSD.org>1999-01-01 14:14:44 +0000
commitb25ed083ef8bf818ef3d10e347f92aa1f7fd091b (patch)
tree0e9f132d124bffff55741f670b68101d9f59ee23
parent591704d5a61874d1f83f92347b630f55bcdecd8a (diff)
downloadFreeBSD-src-b25ed083ef8bf818ef3d10e347f92aa1f7fd091b.zip
FreeBSD-src-b25ed083ef8bf818ef3d10e347f92aa1f7fd091b.tar.gz
Ignore the fs_spec entry for "/" in /etc/fstab if the device which
is actually mounted on "/" can be determined using statfs() and is in /dev. This fixes fsck operating on the wrong device when the fs_spec entry is only an alias. The aliased case became more dangerous when the ROOTSLICE_HUNT hack was committed in mount(8). ROOTSLICE_HUNT may be unnecessary now.
-rw-r--r--lib/libc/gen/fstab.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c
index a526068..65b02c1 100644
--- a/lib/libc/gen/fstab.c
+++ b/lib/libc/gen/fstab.c
@@ -35,8 +35,13 @@
static char sccsid[] = "@(#)fstab.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+
#include <errno.h>
#include <fstab.h>
+#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -47,8 +52,30 @@ static struct fstab _fs_fstab;
static int LineNo = 0;
static void error __P((int));
+static void fixfsfile __P((void));
static int fstabscan __P((void));
+static void
+fixfsfile()
+{
+ static char buf[sizeof(_PATH_DEV) + MNAMELEN];
+ struct stat sb;
+ struct statfs sf;
+
+ if (strcmp(_fs_fstab.fs_file, "/") != 0)
+ return;
+ if (statfs("/", &sf) != 0)
+ return;
+ if (sf.f_mntfromname[0] == '/')
+ buf[0] = '\0';
+ else
+ strcpy(buf, _PATH_DEV);
+ strcat(buf, sf.f_mntfromname);
+ if (stat(buf, &sb) != 0 || !S_ISBLK(sb.st_mode))
+ return;
+ _fs_fstab.fs_spec = buf;
+}
+
static int
fstabscan()
{
@@ -69,6 +96,7 @@ fstabscan()
if (!strpbrk(p, " \t")) {
_fs_fstab.fs_spec = strsep(&p, ":\n");
_fs_fstab.fs_file = strsep(&p, ":\n");
+ fixfsfile();
_fs_fstab.fs_type = strsep(&p, ":\n");
if (_fs_fstab.fs_type) {
if (!strcmp(_fs_fstab.fs_type, FSTAB_XX))
@@ -96,6 +124,7 @@ fstabscan()
while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
;
_fs_fstab.fs_file = cp;
+ fixfsfile();
while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
;
_fs_fstab.fs_vfstype = cp;
OpenPOWER on IntegriCloud