summaryrefslogtreecommitdiffstats
path: root/fsck/fsck.c
diff options
context:
space:
mode:
authorKarel Zak2012-02-20 17:28:53 +0100
committerKarel Zak2012-03-20 11:22:09 +0100
commit67f09eae5be7f8fb084925bed69fcb2fd0b37130 (patch)
tree6d643ea54d1f352809e833f6c2b0412c2a139d8a /fsck/fsck.c
parentlibmount: improve mnt_tables_is_mounted (diff)
downloadkernel-qcow2-util-linux-67f09eae5be7f8fb084925bed69fcb2fd0b37130.tar.gz
kernel-qcow2-util-linux-67f09eae5be7f8fb084925bed69fcb2fd0b37130.tar.xz
kernel-qcow2-util-linux-67f09eae5be7f8fb084925bed69fcb2fd0b37130.zip
fsck: use libmount to check for mounted filesystems
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fsck/fsck.c')
-rw-r--r--fsck/fsck.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 6786ab485..cbf74dcf4 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -48,7 +48,6 @@
#include "nls.h"
#include "pathnames.h"
-#include "ismounted.h"
#include "exitcodes.h"
#include "c.h"
#include "fsck.h"
@@ -107,7 +106,7 @@ const char fsck_prefix_path[] = FS_SEARCH_PATH;
char *fsck_path = 0;
/* parsed fstab */
-static struct libmnt_table *fstab;
+static struct libmnt_table *fstab, *mtab;
static struct libmnt_cache *mntcache;
static int count_slaves(dev_t disk);
@@ -124,6 +123,30 @@ static int string_to_int(const char *s)
return (int) l;
}
+static int is_mounted(struct libmnt_fs *fs)
+{
+ int rc;
+
+ if (!mtab) {
+ mtab = mnt_new_table();
+ if (!mtab)
+ err(FSCK_EX_ERROR, ("failed to initialize libmount table"));
+ if (!mntcache)
+ mntcache = mnt_new_cache();
+ mnt_table_set_cache(mtab, mntcache);
+ mnt_table_parse_mtab(mtab, NULL);
+ }
+
+ rc = mnt_table_is_fs_mounted(mtab, fs);
+ if (verbose) {
+ if (rc)
+ printf(_("%s is mounted\n"), mnt_fs_get_target(fs));
+ else
+ printf(_("%s is not mounted\n"), mnt_fs_get_target(fs));
+ }
+ return rc;
+}
+
static int ignore(struct libmnt_fs *);
static struct fsck_fs_data *fs_create_data(struct libmnt_fs *fs)
@@ -1071,7 +1094,7 @@ static int check_all(void)
if (fs) {
if (!skip_root &&
!fs_is_done(fs) &&
- !(ignore_mounted && is_mounted(fs_get_device(fs)))) {
+ !(ignore_mounted && is_mounted(fs))) {
status |= fsck_device(fs, 1);
status |= wait_many(FLAG_WAIT_ALL);
if (status > FSCK_EX_NONDESTRUCT) {
@@ -1119,7 +1142,7 @@ static int check_all(void)
not_done_yet++;
continue;
}
- if (ignore_mounted && is_mounted(fs_get_device(fs))) {
+ if (ignore_mounted && is_mounted(fs)) {
fs_set_done(fs);
continue;
}
@@ -1427,7 +1450,7 @@ int main(int argc, char *argv[])
else if (fs_ignored_type(fs))
continue;
- if (ignore_mounted && is_mounted(fs_get_device(fs)))
+ if (ignore_mounted && is_mounted(fs))
continue;
status |= fsck_device(fs, interactive);
if (serialize ||
@@ -1447,6 +1470,7 @@ int main(int argc, char *argv[])
free(fsck_path);
mnt_free_cache(mntcache);
mnt_free_table(fstab);
+ mnt_free_table(mtab);
return status;
}