summaryrefslogtreecommitdiff
path: root/lib/ext2fs/ismounted.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2001-01-03 14:56:46 +0000
committerTheodore Ts'o <tytso@mit.edu>2001-01-03 14:56:46 +0000
commit43ec8734f2ecd0a345e831f45fd3dfb077426811 (patch)
tree36fa35d5b4a8a2bf7e345e441efcde9bd88cb642 /lib/ext2fs/ismounted.c
parentcc7067b40bbd3e585da3031c1e06794107ff0d0b (diff)
downloade2fsprogs-43ec8734f2ecd0a345e831f45fd3dfb077426811.tar.gz
ChangeLog, ext2fs.h, ismounted.c:
ismounted.c: add ext2fs_check_mount_point() function, which will optionally return the mount point of a device if mounted ChangeLog, closefs.c, ext2fs.h: ext2fs.h, closefs.c (ext2fs_flush): Add new flag, EXT2_FLAG_SUPER_ONLY, which the close routines to only update the superblock, and not the group descriptors.
Diffstat (limited to 'lib/ext2fs/ismounted.c')
-rw-r--r--lib/ext2fs/ismounted.c47
1 files changed, 40 insertions, 7 deletions
diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c
index fc66d482..95bf953e 100644
--- a/lib/ext2fs/ismounted.c
+++ b/lib/ext2fs/ismounted.c
@@ -39,10 +39,12 @@
#ifdef HAVE_MNTENT_H
/*
- * XXX we only check to see if the mount is readonly when it's the
- * root filesystem.
+ * XXX we assume that /etc/mtab is located on the root filesystem, and
+ * we only check to see if the mount is readonly for the root
+ * filesystem.
*/
-static errcode_t check_mntent(const char *file, int *mount_flags)
+static errcode_t check_mntent(const char *file, int *mount_flags,
+ char *mtpt, int mtlen)
{
FILE * f;
struct mntent * mnt;
@@ -68,12 +70,15 @@ static errcode_t check_mntent(const char *file, int *mount_flags)
} else
close(fd);
}
+ if (mtpt)
+ strncpy(mtpt, mnt->mnt_dir, mtlen);
return 0;
}
#endif
#ifdef HAVE_GETMNTINFO
-static errcode_t check_getmntinfo(const char *file, int *mount_flags)
+static errcode_t check_getmntinfo(const char *file, int *mount_flags,
+ char *mtpt, int mtlen)
{
struct statfs *mp;
int len, n;
@@ -102,12 +107,40 @@ static errcode_t check_getmntinfo(const char *file, int *mount_flags)
}
++mp;
}
+ if (mtpt)
+ strncpy(mtpt, mp->f_mntonname, mtlen);
return 0;
}
#endif /* HAVE_GETMNTINFO */
/*
- * Is_mounted is set to 1 if the device is mounted, 0 otherwise
+ * ext2fs_check_mount_point() returns 1 if the device is mounted, 0
+ * otherwise. If mtpt is non-NULL, the directory where the device is
+ * mounted is copied to where mtpt is pointing, up to mtlen
+ * characters.
+ */
+#ifdef __TURBOC__
+#pragma argsused
+#endif
+errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
+ char *mtpt, int mtlen)
+{
+#ifdef HAVE_MNTENT_H
+ return check_mntent(device, mount_flags, mtpt, mtlen);
+#else
+#ifdef HAVE_GETMNTINFO
+ return check_getmntinfo(device, mount_flags, mtpt, mtlen);
+#else
+ *mount_flags = 0;
+ return 0;
+#endif /* HAVE_GETMNTINFO */
+#endif /* HAVE_MNTENT_H */
+}
+
+/*
+ * ext2fs_check_if_mounted() sets the mount_flags EXT2_MF_MOUNTED and
+ * EXT2_MF_READONLY
+ *
*/
#ifdef __TURBOC__
#pragma argsused
@@ -115,10 +148,10 @@ static errcode_t check_getmntinfo(const char *file, int *mount_flags)
errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags)
{
#ifdef HAVE_MNTENT_H
- return check_mntent(file, mount_flags);
+ return check_mntent(file, mount_flags, NULL, 0);
#else
#ifdef HAVE_GETMNTINFO
- return check_getmntinfo(file, mount_flags);
+ return check_getmntinfo(file, mount_flags, NULL, 0);
#else
*mount_flags = 0;
return 0;