]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: consolidate MNT_FS_* code
authorKarel Zak <kzak@redhat.com>
Mon, 2 Jan 2012 14:00:27 +0000 (15:00 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 2 Jan 2012 14:00:27 +0000 (15:00 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/context_loopdev.c
libmount/src/context_mount.c
libmount/src/context_umount.c
libmount/src/fs.c
libmount/src/libmount.h.in
libmount/src/libmount.sym
libmount/src/mountP.h
libmount/src/tab.c

index 7dc4731847edaab10e332666e31e0029aa869d1b..19954096b508bfb3811ed92d414b62da0a4276a4 100644 (file)
@@ -1085,7 +1085,7 @@ int mnt_context_prepare_srcpath(struct libmnt_context *cxt)
        /* ignore filesystems without source or filesystems
         * where the source is quasi-path (//foo/bar)
         */
-       if (!src || (cxt->fs->flags & MNT_FS_NET))
+       if (!src || mnt_fs_is_netfs(cxt->fs))
                return 0;
 
        DBG(CXT, mnt_debug_h(cxt, "srcpath '%s'", src));
@@ -1101,7 +1101,7 @@ int mnt_context_prepare_srcpath(struct libmnt_context *cxt)
 
                rc = path ? mnt_fs_set_source(cxt->fs, path) : -EINVAL;
 
-       } else if (cache && !(cxt->fs->flags & MNT_FS_PSEUDO)) {
+       } else if (cache && !mnt_fs_is_pseudofs(cxt->fs)) {
                /*
                 * Source is PATH (canonicalize)
                 */
@@ -1119,7 +1119,7 @@ int mnt_context_prepare_srcpath(struct libmnt_context *cxt)
                path = src;
 
        if ((cxt->mountflags & (MS_BIND | MS_MOVE | MS_PROPAGATION)) ||
-           (cxt->fs->flags & MNT_FS_PSEUDO)) {
+           mnt_fs_is_pseudofs(cxt->fs)) {
                DBG(CXT, mnt_debug_h(cxt, "PROPAGATION/pseudo FS source: %s", path));
                return rc;
        }
@@ -1254,7 +1254,7 @@ int mnt_context_prepare_helper(struct libmnt_context *cxt, const char *name,
                type = mnt_fs_get_fstype(cxt->fs);
 
        if ((cxt->flags & MNT_FL_NOHELPERS) || !type ||
-           !strcmp(type, "none") || (cxt->fs->flags & MNT_FS_SWAP))
+           !strcmp(type, "none") || mnt_fs_is_swaparea(cxt->fs))
                return 0;
 
        path = strtok_r(search_path, ":", &p);
index 561ab397dcfa0119099b1ef76c10d47103db5b08..6221166ff7faafe8b8c7506560d8c63f4695bd19 100644 (file)
@@ -20,7 +20,6 @@
 int mnt_context_is_loopdev(struct libmnt_context *cxt)
 {
        const char *type, *src;
-       int fl;
 
        assert(cxt);
        /* The mount flags have to be merged, otherwise we have to use
@@ -50,9 +49,8 @@ int mnt_context_is_loopdev(struct libmnt_context *cxt)
         * regular files could be implemented.
         */
        type = mnt_fs_get_fstype(cxt->fs);
-       fl = __mnt_fs_get_flags(cxt->fs);
 
-       if (!(fl & (MNT_FS_PSEUDO | MNT_FS_NET | MNT_FS_SWAP)) &&
+       if (mnt_fs_is_regular(cxt->fs) &&
            (!type || strcmp(type, "auto") == 0 || blkid_known_fstype(type))) {
                struct stat st;
 
index 8fba9c6be3b87653cfe5ed586a7bc6a081e5acc4..f86b3f761a67f86d4e1fac2d82b96f557f9dc9f6 100644 (file)
@@ -515,7 +515,7 @@ int mnt_context_prepare_mount(struct libmnt_context *cxt)
        assert(cxt->helper_exec_status == 1);
        assert(cxt->syscall_status == 1);
 
-       if (!cxt || !cxt->fs || (cxt->fs->flags & MNT_FS_SWAP))
+       if (!cxt || !cxt->fs || mnt_fs_is_swaparea(cxt->fs))
                return -EINVAL;
        if (!mnt_fs_get_source(cxt->fs) && !mnt_fs_get_target(cxt->fs))
                return -EINVAL;
@@ -726,10 +726,10 @@ int mnt_context_next_mount(struct libmnt_context *cxt,
        DBG(CXT, mnt_debug_h(cxt, "next-mount: trying %s", tgt));
 
        /*  ignore swap */
-       if (((*fs)->flags & MNT_FS_SWAP) ||
+       if (mnt_fs_is_swaparea(*fs) ||
 
        /* ignore root filesystem */
-         (tgt && (strcmp(tgt, "/") == 0 || strcmp(tgt, "root") == 0)) ||
+          (tgt && (strcmp(tgt, "/") == 0 || strcmp(tgt, "root") == 0)) ||
 
        /* ignore noauto filesystems */
           (o && mnt_optstr_get_option(o, "noauto", NULL, NULL) == 0) ||
index 5474da01d8e91829dbf28532582fb35c24ccb1b7..568cf505ba5e86cdbcc42aa456fc1090cab13d7c 100644 (file)
@@ -557,7 +557,7 @@ int mnt_context_prepare_umount(struct libmnt_context *cxt)
        assert(cxt->helper_exec_status == 1);
        assert(cxt->syscall_status == 1);
 
-       if (!cxt || !cxt->fs || (cxt->fs->flags & MNT_FS_SWAP))
+       if (!cxt || !cxt->fs || mnt_fs_is_swaparea(cxt->fs))
                return -EINVAL;
        if (!mnt_context_get_source(cxt) && !mnt_context_get_target(cxt))
                return -EINVAL;
index 90f484beccf2e555b195d16196ae353f1113e94f..43faa0511e43a3ffeb23a52c8ae16425a4c59e74 100644 (file)
@@ -437,20 +437,11 @@ int mnt_fs_set_target(struct libmnt_fs *fs, const char *target)
        return 0;
 }
 
-int __mnt_fs_get_flags(struct libmnt_fs *fs)
+static int mnt_fs_get_flags(struct libmnt_fs *fs)
 {
        return fs ? fs->flags : 0;
 }
 
-int __mnt_fs_set_flags(struct libmnt_fs *fs, int flags)
-{
-       if (fs) {
-               fs->flags = flags;
-               return 0;
-       }
-       return -EINVAL;
-}
-
 /**
  * mnt_fs_is_kernel:
  * @fs: filesystem
@@ -459,7 +450,40 @@ int __mnt_fs_set_flags(struct libmnt_fs *fs, int flags)
  */
 int mnt_fs_is_kernel(struct libmnt_fs *fs)
 {
-       return __mnt_fs_get_flags(fs) & MNT_FS_KERNEL;
+       return mnt_fs_get_flags(fs) & MNT_FS_KERNEL;
+}
+
+/**
+ * mnt_fs_is_swaparea:
+ * @fs: filesystem
+ *
+ * Returns: 1 if the filesystem uses "swap" as a type
+ */
+int mnt_fs_is_swaparea(struct libmnt_fs *fs)
+{
+       return mnt_fs_get_flags(fs) & MNT_FS_SWAP;
+}
+
+/**
+ * mnt_fs_is_pseudofs:
+ * @fs: filesystem
+ *
+ * Returns: 1 if the filesystem is a pseudo fs type (proc, cgroups)
+ */
+int mnt_fs_is_pseudo(struct libmnt_fs *fs)
+{
+       return mnt_fs_get_flags(fs) & MNT_FS_PSEUDO;
+}
+
+/**
+ * mnt_fs_is_netfs:
+ * @fs: filesystem
+ *
+ * Returns: 1 if the filesystem is a network filesystem
+ */
+int mnt_fs_is_netfs(struct libmnt_fs *fs)
+{
+       return mnt_fs_get_flags(fs) & MNT_FS_NET;
 }
 
 /**
index 7cc6cb607ea9201dfa94aab42be5855c8f4fc536..9e1a65fcaaf7bd99138aff2af9daa5833d01e540 100644 (file)
@@ -263,6 +263,9 @@ extern int mnt_fs_match_options(struct libmnt_fs *fs, const char *options);
 extern int mnt_fs_print_debug(struct libmnt_fs *fs, FILE *file);
 
 extern int mnt_fs_is_kernel(struct libmnt_fs *fs);
+extern int mnt_fs_is_swaparea(struct libmnt_fs *fs);
+extern int mnt_fs_is_netfs(struct libmnt_fs *fs);
+extern int mnt_fs_is_pseudofs(struct libmnt_fs *fs);
 
 extern void mnt_free_mntent(struct mntent *mnt);
 extern int mnt_fs_to_mntent(struct libmnt_fs *fs, struct mntent **mnt);
index 6f4d1c02bff97b82a97595dae9ccaa70d205936f..0740db8e123989f8c828def23d107c202099780c 100644 (file)
@@ -214,4 +214,7 @@ global:
        mnt_context_is_parent;
        mnt_context_next_umount;
        mnt_context_wait_for_children;
+       mnt_fs_is_netfs;
+       mnt_fs_is_pseudofs;
+       mnt_fs_is_swaparea;
 } MOUNT_2.20;
index 9be3aabed902ad873ee15df82d8c9f7c8d3e3d50..c82a9799988473b1944694f79ffce25a084fee6d 100644 (file)
@@ -224,9 +224,9 @@ struct libmnt_fs {
 #define MNT_FS_KERNEL  (1 << 4) /* data from /proc/{mounts,self/mountinfo} */
 #define MNT_FS_MERGED  (1 << 5) /* already merged data from /run/mount/utab */
 
-extern int __mnt_fs_get_flags(struct libmnt_fs *fs);
-extern int __mnt_fs_set_flags(struct libmnt_fs *fs, int flags);
-
+#define mnt_fs_is_regular(_f)  (!(mnt_fs_is_pseudofs(_f) \
+                                  || mnt_fs_is_netfs(_f) \
+                                  || mnt_fs_is_swaparea(_f)))
 
 /*
  * mtab/fstab/mountinfo file
index 15e20f8f6cc56c7b41c1eab8b025ff9c6cde7f07..6d2d44e6ff291e12695a8ac567fdd079bed8c8bb 100644 (file)
@@ -456,7 +456,7 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat
        while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
                char *p;
 
-               if (!fs->target || !(fs->flags & MNT_FS_SWAP) ||
+               if (!fs->target || !mnt_fs_is_swaparea(fs) ||
                    (*fs->target == '/' && *(fs->target + 1) == '\0'))
                       continue;
 
@@ -562,7 +562,7 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa
        if (ntags <= mnt_table_get_nents(tb)) {
                mnt_reset_iter(&itr, direction);
                while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
-                       if (fs->flags & (MNT_FS_NET | MNT_FS_PSEUDO))
+                       if (mnt_fs_is_netfs(fs) || mnt_fs_is_pseudofs(fs))
                                continue;
                        p = mnt_fs_get_srcpath(fs);
                        if (p)
@@ -837,7 +837,7 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs)
        assert(tb);
        assert(fstab_fs);
 
-       if (fstab_fs->flags & MNT_FS_SWAP)
+       if (mnt_fs_is_swaparea(fstab_fs))
                return 0;
 
        if (mnt_fs_get_option(fstab_fs, "bind", NULL, NULL) == 0)
@@ -846,7 +846,7 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs)
        src_fs = mnt_table_get_fs_root(tb, fstab_fs, flags, &root);
        if (src_fs)
                src = mnt_fs_get_srcpath(src_fs);
-       else if (fstab_fs->flags & MNT_FS_PSEUDO)
+       else if (mnt_fs_is_pseudofs(fstab_fs))
                src = mnt_fs_get_source(fstab_fs);
        else
                src = xsrc = mnt_resolve_spec(mnt_fs_get_source(fstab_fs),