]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: ifdef listmount and statmount stuff
authorKarel Zak <kzak@redhat.com>
Mon, 19 Aug 2024 10:59:10 +0000 (12:59 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 8 Jan 2025 12:57:42 +0000 (13:57 +0100)
* introduce mnt_fs_try_statmount() macro to simplify mnt_fs_fetch_statmount() calls

* define dummy API functions when HAVE_STATMOUNT_API undefined

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/fs.c
libmount/src/fs_statmount.c
libmount/src/mountP.h
libmount/src/tab.c
libmount/src/tab_listmount.c

index e466bca134d06d542cab5e011aeed92930a0200d..fdc249ed9824067c946170e0e343c116fbd93fcc 100644 (file)
@@ -617,8 +617,9 @@ const char *mnt_fs_get_target(struct libmnt_fs *fs)
 {
        if (!fs)
                return NULL;
-       if (!fs->target && mnt_fs_want_statmount(fs, STATMOUNT_MNT_POINT))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_MNT_POINT);
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, target, STATMOUNT_MNT_POINT);
+#endif
        return fs->target;;
 }
 
@@ -665,9 +666,9 @@ int mnt_fs_get_propagation(struct libmnt_fs *fs, unsigned long *flags)
 {
        if (!fs || !flags)
                return -EINVAL;
-       if (!fs->propagation && mnt_fs_want_statmount(fs, STATMOUNT_MNT_BASIC))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_MNT_BASIC);
-
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, propagation, STATMOUNT_MNT_BASIC);
+#endif
        if (!fs->propagation && fs->opt_fields) {
                 /*
                 * The optional fields format is incompatible with mount options
@@ -719,9 +720,9 @@ int mnt_fs_is_pseudofs(struct libmnt_fs *fs)
 {
        if (!fs)
                return 0;
-       if (!fs->fstype && mnt_fs_want_statmount(fs, STATMOUNT_FS_TYPE))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_FS_TYPE);
-
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, fstype, STATMOUNT_FS_TYPE);
+#endif
        return mnt_fs_get_flags(fs) & MNT_FS_PSEUDO ? 1 : 0;
 }
 
@@ -735,9 +736,9 @@ int mnt_fs_is_netfs(struct libmnt_fs *fs)
 {
        if (!fs)
                return 0;
-       if (!fs->fstype && mnt_fs_want_statmount(fs, STATMOUNT_FS_TYPE))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_FS_TYPE);
-
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, fstype, STATMOUNT_FS_TYPE);
+#endif
        return mnt_fs_get_flags(fs) & MNT_FS_NET ? 1 : 0;
 }
 
@@ -766,10 +767,9 @@ const char *mnt_fs_get_fstype(struct libmnt_fs *fs)
 {
        if (!fs)
                return NULL;
-
-       if (!fs->fstype && mnt_fs_want_statmount(fs, STATMOUNT_FS_TYPE))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_FS_TYPE);
-
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, fstype, STATMOUNT_FS_TYPE);
+#endif
        return fs->fstype;
 }
 
@@ -892,9 +892,10 @@ char *mnt_fs_strdup_options(struct libmnt_fs *fs)
                return NULL;
        if (fs->optlist)
                sync_opts_from_optlist(fs, fs->optlist);
-       else if (!fs->optstr && mnt_fs_want_statmount(fs, STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC);
-
+#ifdef HAVE_STATMOUNT_API
+       else
+               mnt_fs_try_statmount(fs, optstr, STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC);
+#endif
        errno = 0;
        if (fs->optstr)
                return strdup(fs->optstr);
@@ -922,9 +923,10 @@ const char *mnt_fs_get_options(struct libmnt_fs *fs)
               return NULL;
        if (fs->optlist)
                sync_opts_from_optlist(fs, fs->optlist);
-       else if (!fs->optstr && mnt_fs_want_statmount(fs, STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC);
-
+#ifdef HAVE_STATMOUNT_API
+       else
+               mnt_fs_try_statmount(fs, optstr, STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC);
+#endif
        return fs->optstr;
 }
 
@@ -1094,9 +1096,10 @@ const char *mnt_fs_get_fs_options(struct libmnt_fs *fs)
                return NULL;
        if (fs->optlist)
                sync_opts_from_optlist(fs, fs->optlist);
-       else if (!fs->fs_optstr && mnt_fs_want_statmount(fs, STATMOUNT_SB_BASIC))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_SB_BASIC);
-
+#ifdef HAVE_STATMOUNT_API
+       else
+               mnt_fs_try_statmount(fs, fs_optstr, STATMOUNT_SB_BASIC);
+#endif
        return fs->fs_optstr;
 }
 
@@ -1112,9 +1115,10 @@ const char *mnt_fs_get_vfs_options(struct libmnt_fs *fs)
                return NULL;
        if (fs->optlist)
                sync_opts_from_optlist(fs, fs->optlist);
-       else if (!fs->vfs_optstr && mnt_fs_want_statmount(fs, STATMOUNT_MNT_BASIC))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_MNT_BASIC);
-
+#ifdef HAVE_STATMOUNT_API
+       else
+               mnt_fs_try_statmount(fs, vfs_optstr, STATMOUNT_MNT_BASIC);
+#endif
        return fs->vfs_optstr;
 }
 
@@ -1299,9 +1303,9 @@ const char *mnt_fs_get_root(struct libmnt_fs *fs)
 {
        if (!fs)
                return NULL;
-       if (!fs->root && mnt_fs_want_statmount(fs, STATMOUNT_MNT_ROOT))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_MNT_ROOT);
-
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, root, STATMOUNT_MNT_ROOT);
+#endif
        return fs->root;
 }
 
@@ -1414,9 +1418,9 @@ int mnt_fs_get_id(struct libmnt_fs *fs)
 {
        if (!fs)
                return 0;
-       if (!fs->id && mnt_fs_want_statmount(fs, STATMOUNT_MNT_BASIC))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_MNT_BASIC);
-
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, id, STATMOUNT_MNT_BASIC);
+#endif
        return fs->id;
 }
 
@@ -1435,9 +1439,9 @@ uint64_t mnt_fs_get_uniq_id(struct libmnt_fs *fs)
 {
        if (!fs)
                return 0;
-       if (!fs->uniq_id && mnt_fs_want_statmount(fs, STATMOUNT_MNT_BASIC))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_MNT_BASIC);
-
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, uniq_id, STATMOUNT_MNT_BASIC);
+#endif
        return fs->uniq_id;
 }
 
@@ -1471,9 +1475,9 @@ int mnt_fs_get_parent_id(struct libmnt_fs *fs)
 {
        if (!fs)
                return 0;
-       if (!fs->parent && mnt_fs_want_statmount(fs, STATMOUNT_MNT_BASIC))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_MNT_BASIC);
-
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, parent, STATMOUNT_MNT_BASIC);
+#endif
        return fs->parent;
 }
 
@@ -1489,9 +1493,9 @@ uint64_t mnt_fs_get_parent_uniq_id(struct libmnt_fs *fs)
 {
        if (!fs)
                return 0;
-       if (!fs->uniq_parent && mnt_fs_want_statmount(fs, STATMOUNT_MNT_BASIC))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_MNT_BASIC);
-
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, uniq_parent, STATMOUNT_MNT_BASIC);
+#endif
        return fs->uniq_parent;
 }
 
@@ -1509,8 +1513,9 @@ uint64_t mnt_fs_get_ns(struct libmnt_fs *fs)
 {
        if (!fs)
                return 0;
-       if (!fs->ns_id && mnt_fs_want_statmount(fs, STATMOUNT_MNT_NS_ID))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_MNT_NS_ID);
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, ns_id, STATMOUNT_MNT_NS_ID);
+#endif
        return fs->ns_id;
 }
 
@@ -1542,9 +1547,9 @@ dev_t mnt_fs_get_devno(struct libmnt_fs *fs)
 {
        if (!fs)
                return 0;
-       if (!fs->devno && mnt_fs_want_statmount(fs, STATMOUNT_SB_BASIC))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_SB_BASIC);
-
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, devno, STATMOUNT_SB_BASIC);
+#endif
        return fs->devno;
 }
 
@@ -1578,9 +1583,10 @@ int mnt_fs_get_option(struct libmnt_fs *fs, const char *name,
 
        if (fs->optlist)
                sync_opts_from_optlist(fs, fs->optlist);
-       else if (!fs->vfs_optstr && mnt_fs_want_statmount(fs, STATMOUNT_MNT_BASIC | STATMOUNT_SB_BASIC))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_MNT_BASIC | STATMOUNT_SB_BASIC);
-
+#ifdef HAVE_STATMOUNT_API
+       else
+               mnt_fs_try_statmount(fs, vfs_optstr, STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC);
+#endif
        if (fs->fs_optstr)
                rc = mnt_optstr_get_option(fs->fs_optstr, name, value, valsz);
        if (rc == 1 && fs->vfs_optstr)
@@ -1686,8 +1692,9 @@ int mnt_fs_match_target(struct libmnt_fs *fs, const char *target,
 
        if (!fs || !target)
                return 0;
-       if (!fs->target && mnt_fs_want_statmount(fs, STATMOUNT_MNT_POINT))
-               mnt_fs_fetch_statmount(fs, STATMOUNT_MNT_POINT);
+#ifdef HAVE_STATMOUNT_API
+       mnt_fs_try_statmount(fs, target, STATMOUNT_MNT_BASIC);
+#endif
        if (!fs->target)
                return 0;
 
index 0fad5bd4b1b97a2a42a643495203d749fa4c296d..d331e247606907e5382a838663f5f6aace539f9c 100644 (file)
@@ -29,6 +29,7 @@
  */
 struct libmnt_statmnt *mnt_new_statmnt(void)
 {
+#ifdef HAVE_STATMOUNT_API
        struct libmnt_statmnt *sm;
 
        errno = 0;
@@ -44,6 +45,10 @@ struct libmnt_statmnt *mnt_new_statmnt(void)
        sm->refcount = 1;
        DBG(STATMNT, ul_debugobj(sm, "alloc"));
        return sm;
+#else
+       errno = ENOSYS;
+       return NULL;
+#endif
 }
 
 /**
index ee275f2611b4c3961c6eb6cfab59ed428da0b33c..da4b60f39e3a0efae3e6df0a0f546920e6f71312 100644 (file)
@@ -283,8 +283,15 @@ 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 */
 
-#define mnt_fs_want_statmount(_x, _m) \
-               ((_x)->stmnt && !(_x)->stmnt->disabled && !((_x)->stmnt_done & (_m)))
+#ifdef HAVE_STATMOUNT_API
+# define       mnt_fs_try_statmount(FS, MEMBER, FLAGS) __extension__ ({        \
+                       if (!(FS)->MEMBER                                       \
+                           && (FS)->stmnt                                      \
+                           && !(FS)->stmnt->disabled                           \
+                           && !((FS)->stmnt_done & (FLAGS)))                   \
+                               mnt_fs_fetch_statmount((FS), (FLAGS)); })
+#endif
+
 
 /*
  * fstab/mountinfo file
index 7880d6491cfd588e0243850cfd44eb9ea5d426ed..ba4eef850ad0e14cd8fda70c67dedd46eba63af0 100644 (file)
@@ -855,7 +855,7 @@ int mnt_table_next_fs(struct libmnt_table *tb, struct libmnt_iter *itr, struct l
                return -EINVAL;
        if (fs)
                *fs = NULL;
-
+#ifdef HAVE_STATMOUNT_API
        if (mnt_table_want_listmount(tb) &&
            (list_empty(&tb->ents) || itr->p == itr->head)) {
                struct list_head *prev = NULL;
@@ -871,7 +871,7 @@ int mnt_table_next_fs(struct libmnt_table *tb, struct libmnt_iter *itr, struct l
                        MNT_ITER_ITERATE(itr);
                }
        }
-
+#endif
        if (!itr->head)
                MNT_ITER_INIT(itr, &tb->ents);
        if (itr->p != itr->head) {
index 2d11af6e980aab2dbb20e4c14e1b317891cd656b..4bf86298a4b80ab2982a660b7b22b21d11826210 100644 (file)
  */
 #include "mountP.h"
 
+#ifndef HAVE_STATMOUNT_API
+
+int mnt_table_listmount_set_id(
+               struct libmnt_table *tb __attribute__((__unused__)),
+               uint64_t id __attribute__((__unused__)))
+{
+       return -ENOSYS;
+}
+
+int mnt_table_listmount_set_ns(
+               struct libmnt_table *tb __attribute__((__unused__)),
+               uint64_t ns __attribute__((__unused__)))
+{
+       return -ENOSYS;
+}
+
+int mnt_table_listmount_set_stepsiz(
+               struct libmnt_table *tb __attribute__((__unused__)),
+               size_t sz __attribute__((__unused__)))
+{
+       return -ENOSYS;
+}
+
+int mnt_table_enable_listmount(
+               struct libmnt_table *tb __attribute__((__unused__)),
+               int enable __attribute__((__unused__)))
+{
+       return -ENOSYS;
+}
+
+int mnt_table_fetch_listmount(struct libmnt_table *tb __attribute__((__unused__)))
+{
+       return -ENOSYS;
+}
+
+int mnt_table_reset_listmount(struct libmnt_table *tb __attribute__((__unused__)))
+{
+       return -ENOSYS;
+}
+
+int mnt_table_next_lsmnt(struct libmnt_table *tb __attribute__((__unused__)),
+                       int direction __attribute__((__unused__)))
+{
+       return -ENOSYS;
+}
+
+#else /* HAVE_STATMOUNT_API */
+
 /*
 * This struct is not shared between multiple tables, so reference counting is
 * not used for it.
@@ -371,4 +419,4 @@ int mnt_table_fetch_listmount(struct libmnt_table *tb)
        return rc;
 }
 
-
+#endif /* HAVE_STATMOUNT_API */