summaryrefslogtreecommitdiff
path: root/lib/ext2fs
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2001-05-25 16:32:53 +0000
committerTheodore Ts'o <tytso@mit.edu>2001-05-25 16:32:53 +0000
commitcc86017b593ddfbd4d7a12ed8695e62998f30944 (patch)
treed38381cf6c20b61d87a24c8a06a71690044b64aa /lib/ext2fs
parenta9bc79add106f2c544c449f514a1113817deae2e (diff)
downloade2fsprogs-cc86017b593ddfbd4d7a12ed8695e62998f30944.tar.gz
ChangeLog, ismounted.c:
ismounted.c: Add check for root device which doesn't depend on /etc/fstab or /proc/mounts to be correct. Don't call endmntent() before we are done with mnt struct.
Diffstat (limited to 'lib/ext2fs')
-rw-r--r--lib/ext2fs/ChangeLog6
-rw-r--r--lib/ext2fs/ismounted.c41
2 files changed, 37 insertions, 10 deletions
diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog
index 273e5308..526a163a 100644
--- a/lib/ext2fs/ChangeLog
+++ b/lib/ext2fs/ChangeLog
@@ -1,3 +1,9 @@
+2001-05-24 Andreas Dilger <adilger@turbolinux.com>
+
+ * ismounted.c: Add check for root device which doesn't depend on
+ /etc/fstab or /proc/mounts to be correct. Don't call
+ endmntent() before we are done with mnt struct.
+
2001-05-23 Theodore Tso <tytso@valinux.com>
* ext2_err.et.in (EXT2_ET_JOURNAL_UNSUPP_VERSION): Added new error
diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c
index 7d10bd54..1b719de8 100644
--- a/lib/ext2fs/ismounted.c
+++ b/lib/ext2fs/ismounted.c
@@ -1,7 +1,7 @@
/*
* ismounted.c --- Check to see if the filesystem was mounted
*
- * Copyright (C) 1995 Theodore Ts'o.
+ * Copyright (C) 1995,1996,1997,1998,1999,2000 Theodore Ts'o.
*
* %Begin-Header%
* This file may be redistributed under the terms of the GNU Public
@@ -29,6 +29,7 @@
#include <sys/mount.h>
#endif /* HAVE_GETMNTINFO */
#include <string.h>
+#include <sys/stat.h>
#include "ext2_fs.h"
#include "ext2fs.h"
@@ -52,22 +53,43 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file,
while ((mnt = getmntent (f)) != NULL)
if (strcmp(file, mnt->mnt_fsname) == 0)
break;
- endmntent (f);
- if (mnt == 0)
+
+ if (mnt == 0) {
+ struct stat st_root, st_file;
+ /*
+ * Do an extra check to see if this is the root device. We
+ * can't trust /etc/fstab, and /proc/mounts will only list
+ * /dev/root for the root filesystem. Argh. Instead we
+ * check if the given device has the same major/minor number
+ * as the device that the root directory is on.
+ */
+ if (stat("/", &st_root) == 0 && stat(file, &st_file) == 0) {
+ if (st_root.st_dev == st_file.st_rdev) {
+ *mount_flags = EXT2_MF_MOUNTED;
+ if (mtpt)
+ strcpy(mtpt, "/");
+ goto is_root;
+ }
+ }
+ endmntent (f);
return 0;
+ }
*mount_flags = EXT2_MF_MOUNTED;
/* Check to see if the ro option is set */
if (hasmntopt(mnt, MNTOPT_RO))
*mount_flags |= EXT2_MF_READONLY;
+ if (mtpt)
+ strncpy(mtpt, mnt->mnt_dir, mtlen);
/*
* Check to see if we're referring to the root filesystem.
* If so, do a manual check to see if we can open /etc/mtab
- * read/write, since if the root is mounted read/only,
- * /etc/mtab may not be accurate.
+ * read/write, since if the root is mounted read/only, the
+ * contents of /etc/mtab may not be accurate.
*/
if (!strcmp(mnt->mnt_dir, "/")) {
+is_root:
*mount_flags |= EXT2_MF_ISROOT;
fd = open(MOUNTED, O_RDWR);
if (fd < 0) {
@@ -76,8 +98,7 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file,
} else
close(fd);
}
- if (mtpt)
- strncpy(mtpt, mnt->mnt_dir, mtlen);
+ endmntent (f);
return 0;
}
@@ -200,13 +221,13 @@ int main(int argc, char **argv)
}
printf("Device %s reports flags %02x\n", argv[1], mount_flags);
if (mount_flags & EXT2_MF_MOUNTED)
- printf("\t%s is mounted.\n");
+ printf("\t%s is mounted.\n", argv[1]);
if (mount_flags & EXT2_MF_READONLY)
- printf("\t%s is read-only.\n");
+ printf("\t%s is read-only.\n", argv[1]);
if (mount_flags & EXT2_MF_ISROOT)
- printf("\t%s is the root filesystem.\n");
+ printf("\t%s is the root filesystem.\n", argv[1]);
exit(0);
}