]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fsck: use libmount to check for mounted filesystems
authorKarel Zak <kzak@redhat.com>
Mon, 20 Feb 2012 16:28:53 +0000 (17:28 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 20 Mar 2012 10:22:09 +0000 (11:22 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
fsck/Makefile.am
fsck/fsck.c
fsck/fsck.h

index 224967147f10fdf880732bc7659a2befb16f6f04..020df83f966fb9944897f6fe6c9f19f6a70dbab3 100644 (file)
@@ -3,6 +3,6 @@ include $(top_srcdir)/config/include-Makefile.am
 sbin_PROGRAMS = fsck
 dist_man_MANS = fsck.8
 
-fsck_SOURCES = fsck.c fsck.h $(top_srcdir)/lib/ismounted.c
+fsck_SOURCES = fsck.c fsck.h
 fsck_LDADD = $(ul_libmount_la) $(ul_libblkid_la)
 fsck_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir) -I$(ul_libblkid_incdir)
index 6786ab485d6ec38d2ad30da1967f611626917d4f..cbf74dcf4a1c0d26fc1bc9e813c4c29a6c0f9bd0 100644 (file)
@@ -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;
 }
 
index bb39dc236d65b5decd94290ad2cb1de61f26b371..ddda58411c9588b9bba2b5919b2c0eaa9c8f9685 100644 (file)
@@ -58,5 +58,3 @@ struct fsck_instance {
 extern char *base_device(const char *device);
 extern const char *identify_fs(const char *fs_name, const char *fs_types);
 
-/* ismounted.h */
-extern int is_mounted(const char *file);