]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: cleanup flags usage
authorKarel Zak <kzak@redhat.com>
Wed, 7 Mar 2012 09:45:48 +0000 (10:45 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 7 Mar 2012 09:45:48 +0000 (10:45 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/docs/libmount-sections.txt
libmount/src/context.c
libmount/src/context_mount.c
libmount/src/context_umount.c
libmount/src/libmount.h.in
libmount/src/libmount.sym

index d99f6dcd26a3b02a878af7f9a318b39f41e8705d..d1318acdeb80e64465c5fdf9071aa9e3803342f6 100644 (file)
@@ -56,6 +56,9 @@ mnt_context_is_force
 mnt_context_is_fork
 mnt_context_is_fs_mounted
 mnt_context_is_lazy
+mnt_context_is_loopdel
+mnt_context_is_nocanonicalize
+mnt_context_is_nohelpers
 mnt_context_is_nomtab
 mnt_context_is_parent
 mnt_context_is_rdonly_umount
index f97dd36a67efdf29dc1ff694903eae1c58184fb7..a9ff910917feab347c7fba4019582ef7d0edde0f 100644 (file)
@@ -286,9 +286,10 @@ int mnt_context_get_optsmode(struct libmnt_context *cxt)
  * canonicalies paths when search in fstab and when prepare source and target paths
  * for mount(2) syscall.
  *
- * This fuction has effect to the private fstab instance only (see
- * mnt_context_set_fstab()). If you want to use an external fstab then you need
- * manage your private struct libmnt_cache (see mnt_table_set_cache(fstab, NULL).
+ * This fuction has effect to the private (within context) fstab instance only
+ * (see mnt_context_set_fstab()). If you want to use an external fstab then you
+ * need manage your private struct libmnt_cache (see mnt_table_set_cache(fstab,
+ * NULL).
  *
  * Returns: 0 on success, negative number in case of error.
  */
@@ -297,6 +298,17 @@ int mnt_context_disable_canonicalize(struct libmnt_context *cxt, int disable)
        return set_flag(cxt, MNT_FL_NOCANONICALIZE, disable);
 }
 
+/**
+ * mnt_context_is_nocanonicalize:
+ * @cxt: mount context
+ *
+ * Returns: 1 if no-canonicalize mode enabled or 0.
+ */
+int mnt_context_is_nocanonicalize(struct libmnt_context *cxt)
+{
+       return cxt && (cxt->flags & MNT_FL_NOCANONICALIZE) ? 1 : 0;
+}
+
 /**
  * mnt_context_enable_lazy:
  * @cxt: mount context
@@ -311,6 +323,17 @@ int mnt_context_enable_lazy(struct libmnt_context *cxt, int enable)
        return set_flag(cxt, MNT_FL_LAZY, enable);
 }
 
+/**
+ * mnt_context_is_lazy:
+ * @cxt: mount context
+ *
+ * Returns: 1 if lazy umount is enabled or 0
+ */
+int mnt_context_is_lazy(struct libmnt_context *cxt)
+{
+       return cxt && (cxt->flags & MNT_FL_LAZY) ? 1 : 0;
+}
+
 /**
  * mnt_context_enable_fork:
  * @cxt: mount context
@@ -327,16 +350,37 @@ int mnt_context_enable_fork(struct libmnt_context *cxt, int enable)
 }
 
 /**
- * mnt_context_is_lazy:
+ * mnt_context_is_fork:
  * @cxt: mount context
  *
- * Returns: 1 if lazy umount is enabled or 0
+ * Returns: 1 if fork (mount -F) is enabled or 0
  */
-int mnt_context_is_lazy(struct libmnt_context *cxt)
+int mnt_context_is_fork(struct libmnt_context *cxt)
 {
-       return cxt && (cxt->flags & MNT_FL_LAZY) ? 1 : 0;
+       return cxt && (cxt->flags & MNT_FL_FORK) ? 1 : 0;
 }
 
+/**
+ * mnt_context_is_parent:
+ * @cxt: mount context
+ *
+ * Return: 1 if mount -F enabled and the current context is parent, or 0
+ */
+int mnt_context_is_parent(struct libmnt_context *cxt)
+{
+       return mnt_context_is_fork(cxt) && cxt->pid == 0;
+}
+
+/**
+ * mnt_context_is_child:
+ * @cxt: mount context
+ *
+ * Return: 1 if mount -F enabled and the current context is child, or 0
+ */
+int mnt_context_is_child(struct libmnt_context *cxt)
+{
+       return !mnt_context_is_fork(cxt) && cxt->pid;
+}
 
 /**
  * mnt_context_enable_rdonly_umount:
@@ -381,6 +425,18 @@ int mnt_context_disable_helpers(struct libmnt_context *cxt, int disable)
        return set_flag(cxt, MNT_FL_NOHELPERS, disable);
 }
 
+/**
+ * mnt_context_is_nohelpers
+ * @cxt: mount context
+ *
+ * Returns: 1 if helpers are disabled (mount -i) or 0
+ */
+int mnt_context_is_nohelpers(struct libmnt_context *cxt)
+{
+       return cxt && (cxt->flags & MNT_FL_NOHELPERS) ? 1 : 0;
+}
+
+
 /**
  * mnt_context_enable_sloppy:
  * @cxt: mount context
@@ -520,6 +576,17 @@ int mnt_context_enable_loopdel(struct libmnt_context *cxt, int enable)
        return set_flag(cxt, MNT_FL_LOOPDEL, enable);
 }
 
+/**
+ * mnt_context_is_loopdel:
+ * @cxt: mount context
+ *
+ * Returns: 1 if loop device should be deleted after umount (umount -d) or 0.
+ */
+int mnt_context_is_loopdel(struct libmnt_context *cxt)
+{
+       return cxt && (cxt->flags & MNT_FL_LOOPDEL) ? 1 : 0;
+}
+
 /**
  * mnt_context_set_fs:
  * @cxt: mount context
@@ -934,7 +1001,7 @@ int mnt_context_set_cache(struct libmnt_context *cxt, struct libmnt_cache *cache
  */
 struct libmnt_cache *mnt_context_get_cache(struct libmnt_context *cxt)
 {
-       if (!cxt || (cxt->flags & MNT_FL_NOCANONICALIZE))
+       if (!cxt || mnt_context_is_nocanonicalize(cxt))
                return NULL;
 
        if (!cxt->cache) {
@@ -995,7 +1062,7 @@ struct libmnt_lock *mnt_context_get_lock(struct libmnt_context *cxt)
         * the lock. The mnt_update_* functions are able to allocate the lock
         * only when mtab/utab update is really necessary.
         */
-       if (!cxt || (cxt->flags & MNT_FL_NOMTAB))
+       if (!cxt || mnt_context_is_nomtab(cxt))
                return NULL;
 
        if (!cxt->lock) {
@@ -1340,8 +1407,10 @@ int mnt_context_prepare_helper(struct libmnt_context *cxt, const char *name,
        if (!type)
                type = mnt_fs_get_fstype(cxt->fs);
 
-       if ((cxt->flags & MNT_FL_NOHELPERS) || !type ||
-           !strcmp(type, "none") || mnt_fs_is_swaparea(cxt->fs))
+       if (mnt_context_is_nohelpers(cxt)
+           || !type
+           || !strcmp(type, "none")
+           || mnt_fs_is_swaparea(cxt->fs))
                return 0;
 
        path = strtok_r(search_path, ":", &p);
@@ -1432,9 +1501,9 @@ int mnt_context_prepare_update(struct libmnt_context *cxt)
 
        if (cxt->action == MNT_ACT_UMOUNT && target && !strcmp(target, "/"))
                /* Don't try to touch mtab if umounting root FS */
-               cxt->flags |= MNT_FL_NOMTAB;
+               mnt_context_disable_mtab(cxt, TRUE);
 
-       if (cxt->flags & MNT_FL_NOMTAB) {
+       if (mnt_context_is_nomtab(cxt)) {
                DBG(CXT, mnt_debug_h(cxt, "skip update: NOMTAB flag"));
                return 0;
        }
@@ -1479,7 +1548,7 @@ int mnt_context_update_tabs(struct libmnt_context *cxt)
 
        assert(cxt);
 
-       if (cxt->flags & MNT_FL_NOMTAB) {
+       if (mnt_context_is_nomtab(cxt)) {
                DBG(CXT, mnt_debug_h(cxt, "don't update: NOMTAB flag"));
                return 0;
        }
@@ -1898,7 +1967,7 @@ int mnt_fork_context(struct libmnt_context *cxt)
 
        case 0: /* child */
                cxt->pid = getpid();
-               cxt->flags &= ~MNT_FL_FORK;
+               mnt_context_enable_fork(cxt, FALSE);
                DBG(CXT, mnt_debug_h(cxt, "child created"));
                break;
 
@@ -1953,22 +2022,8 @@ int mnt_context_wait_for_children(struct libmnt_context *cxt,
        return 0;
 }
 
-int mnt_context_is_fork(struct libmnt_context *cxt)
-{
-       return cxt && (cxt->flags & MNT_FL_FORK);
-}
 
 
-int mnt_context_is_parent(struct libmnt_context *cxt)
-{
-       return mnt_context_is_fork(cxt) && cxt->pid == 0;
-}
-
-int mnt_context_is_child(struct libmnt_context *cxt)
-{
-       return !mnt_context_is_fork(cxt) && cxt->pid;
-}
-
 #ifdef TEST_PROGRAM
 
 struct libmnt_lock *lock;
index c56ffd4c195ae987772f98a769d1d6d799fac3ff..4174f84cbfd338e9eb22e1c89e191e94b7861631 100644 (file)
@@ -467,11 +467,11 @@ static int do_mount(struct libmnt_context *cxt, const char *try_type)
        DBG(CXT, mnt_debug_h(cxt, "%smount(2) "
                        "[source=%s, target=%s, type=%s, "
                        " mountflags=0x%08lx, mountdata=%s]",
-                       (cxt->flags & MNT_FL_FAKE) ? "(FAKE) " : "",
+                       mnt_context_is_fake(cxt) ? "(FAKE) " : "",
                        src, target, type,
                        flags, cxt->mountdata ? "yes" : "<none>"));
 
-       if (cxt->flags & MNT_FL_FAKE)
+       if (mnt_context_is_fake(cxt))
                cxt->syscall_status = 0;
        else {
                if (mount(src, target, type, flags, cxt->mountdata)) {
@@ -607,11 +607,11 @@ int mnt_context_prepare_mount(struct libmnt_context *cxt)
  * another source or target than you have to call mnt_reset_context().
  *
  * If you want to call mount(2) for the same source and target with a diffrent
- * mount flags or fstype then you call mnt_context_reset_status() and then try
+ * mount flags or fstype then call mnt_context_reset_status() and then try
  * again mnt_context_do_mount().
  *
  * WARNING: non-zero return code does not mean that mount(2) syscall or
- *          umount.type helper wasn't sucessfully called.
+ *          mount.type helper wasn't sucessfully called.
  *
  *          Check mnt_context_get_status() after error!
 *
@@ -644,7 +644,7 @@ int mnt_context_do_mount(struct libmnt_context *cxt)
                res = do_mount_by_pattern(cxt, cxt->fstype_pattern);
 
        if (mnt_context_get_status(cxt)
-           && !(cxt->flags & MNT_FL_FAKE)
+           && !mnt_context_is_fake(cxt)
            && !cxt->helper) {
                /*
                 * Mounted by mount(2), do some post-mount checks
index 5a2ad9ec7b4e778fd4e7a97b04db53c475e7d039..7daa913fccaf68711a8fb09f0afb20e393dcba4a 100644 (file)
@@ -178,7 +178,7 @@ static int prepare_helper_from_options(struct libmnt_context *cxt,
        const char *opts;
        size_t valsz;
 
-       if (cxt->flags & MNT_FL_NOHELPERS)
+       if (mnt_context_is_nohelpers(cxt))
                return 0;
 
        opts = mnt_fs_get_user_options(cxt->fs);
@@ -369,15 +369,15 @@ static int exec_helper(struct libmnt_context *cxt)
                args[i++] = cxt->helper;                        /* 1 */
                args[i++] = mnt_fs_get_target(cxt->fs);         /* 2 */
 
-               if (cxt->flags & MNT_FL_NOMTAB)
+               if (mnt_context_is_nomtab(cxt))
                        args[i++] = "-n";                       /* 3 */
-               if (cxt->flags & MNT_FL_LAZY)
+               if (mnt_context_is_lazy(cxt))
                        args[i++] = "-l";                       /* 4 */
-               if (cxt->flags & MNT_FL_FORCE)
+               if (mnt_context_is_force(cxt))
                        args[i++] = "-f";                       /* 5 */
-               if (cxt->flags & MNT_FL_VERBOSE)
+               if (mnt_context_is_verbose(cxt))
                        args[i++] = "-v";                       /* 6 */
-               if (cxt->flags & MNT_FL_RDONLY_UMOUNT)
+               if (mnt_context_is_rdonly_umount(cxt))
                        args[i++] = "-r";                       /* 7 */
                if (type && !endswith(cxt->helper, type)) {
                        args[i++] = "-t";                       /* 8 */
@@ -495,7 +495,7 @@ static int do_umount(struct libmnt_context *cxt)
 
        DBG(CXT, mnt_debug_h(cxt, "do umount"));
 
-       if (cxt->restricted && !(cxt->flags & MNT_FL_FAKE)) {
+       if (cxt->restricted && !mnt_context_is_fake(cxt)) {
                /*
                 * extra paranoa for non-root users
                 * -- chdir to the parent of the mountpoint and use NOFOLLOW
@@ -510,17 +510,17 @@ static int do_umount(struct libmnt_context *cxt)
                target = tgtbuf;
        }
 
-       if (cxt->flags & MNT_FL_LAZY)
+       if (mnt_context_is_lazy(cxt))
                flags |= MNT_DETACH;
 
-       else if (cxt->flags & MNT_FL_FORCE)
+       else if (mnt_context_is_force(cxt))
                flags |= MNT_FORCE;
 
        DBG(CXT, mnt_debug_h(cxt, "umount(2) [target='%s', flags=0x%08x]%s",
                                target, flags,
-                               cxt->flags & MNT_FL_FAKE ? " (FAKE)" : ""));
+                               mnt_context_is_fake(cxt) ? " (FAKE)" : ""));
 
-       if (cxt->flags & MNT_FL_FAKE)
+       if (mnt_context_is_fake(cxt))
                rc = 0;
        else {
                rc = flags ? umount2(target, flags) : umount(target);
@@ -532,12 +532,14 @@ static int do_umount(struct libmnt_context *cxt)
        /*
         * try remount read-only
         */
-       if (rc < 0 && cxt->syscall_status == -EBUSY &&
-           (cxt->flags & MNT_FL_RDONLY_UMOUNT) && src) {
+       if (rc < 0
+           && cxt->syscall_status == -EBUSY
+           && mnt_context_is_rdonly_umount(cxt)
+           && src) {
 
                mnt_context_set_mflags(cxt, (cxt->mountflags |
                                             MS_REMOUNT | MS_RDONLY));
-               cxt->flags &= ~MNT_FL_LOOPDEL;
+               mnt_context_enable_loopdel(cxt, FALSE);
 
                DBG(CXT, mnt_debug_h(cxt,
                        "umount(2) failed [errno=%d] -- trying to remount read-only",
@@ -616,11 +618,11 @@ int mnt_context_prepare_umount(struct libmnt_context *cxt)
                        rc = mnt_context_prepare_helper(cxt, "umount", NULL);
        }
 
-       if (!rc && (cxt->flags & MNT_FL_LOOPDEL) && cxt->fs) {
+       if (!rc && mnt_context_is_loopdel(cxt) && cxt->fs) {
                const char *src = mnt_fs_get_srcpath(cxt->fs);
 
                if (src && (!is_loopdev(src) || loopdev_is_autoclear(src)))
-                       cxt->flags &= ~MNT_FL_LOOPDEL;
+                       mnt_context_enable_loopdel(cxt, FALSE);
        }
 
        if (rc) {
@@ -665,21 +667,21 @@ int mnt_context_do_umount(struct libmnt_context *cxt)
        if (rc)
                return rc;
 
-       if (mnt_context_get_status(cxt) && !(cxt->flags & MNT_FL_FAKE)) {
+       if (mnt_context_get_status(cxt) && !mnt_context_is_fake(cxt)) {
                /*
                 * Umounted, do some post-umount operations
                 *      - remove loopdev
                 *      - refresh in-memory mtab stuff if remount rather than
                 *        umount has been performed
                 */
-               if ((cxt->flags & MNT_FL_LOOPDEL)
+               if (mnt_context_is_loopdel(cxt)
                    && !(cxt->mountflags & MS_REMOUNT))
                        rc = mnt_context_delete_loopdev(cxt);
 
-               if (!(cxt->flags & MNT_FL_NOMTAB)
+               if (!mnt_context_is_nomtab(cxt)
                    && mnt_context_get_status(cxt)
                    && !cxt->helper
-                   && (cxt->flags & MNT_FL_RDONLY_UMOUNT)
+                   && mnt_context_is_rdonly_umount(cxt)
                    && (cxt->mountflags & MS_REMOUNT)) {
 
                        /* use "remount" instead of "umount" in /etc/mtab */
index 771952924e4ddf205241f262150191f60c004394..fbabec5c8fda65f90075da7f8e28ae29807afe91 100644 (file)
@@ -412,6 +412,9 @@ extern int mnt_context_is_fake(struct libmnt_context *cxt);
 extern int mnt_context_is_nomtab(struct libmnt_context *cxt);
 extern int mnt_context_is_force(struct libmnt_context *cxt);
 extern int mnt_context_is_verbose(struct libmnt_context *cxt);
+extern int mnt_context_is_loopdel(struct libmnt_context *cxt);
+extern int mnt_context_is_nohelpers(struct libmnt_context *cxt);
+extern int mnt_context_is_nocanonicalize(struct libmnt_context *cxt);
 
 extern int mnt_context_is_fork(struct libmnt_context *cxt);
 extern int mnt_context_is_parent(struct libmnt_context *cxt);
index 1d174bcb6d8a14578a66babf3ca50cb6828ae026..48860e870cecf58f1752547d3a4c9f2ebaae0356 100644 (file)
@@ -230,4 +230,7 @@ MOUNT_2.22 {
 global:
        mnt_fs_streq_target;
        mnt_fs_streq_srcpath;
+       mnt_context_is_loopdel;
+       mnt_context_is_nocanonicalize;
+       mnt_context_is_nohelpers;
 } MOUNT_2.21;