]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: use and add has_listmount()
authorKarel Zak <kzak@redhat.com>
Thu, 24 Apr 2025 16:45:24 +0000 (18:45 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 24 Apr 2025 16:45:24 +0000 (18:45 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/mount-api-utils.h
libmount/src/tab_listmount.c
tests/helpers/test_sysinfo.c

index ea9aeb816b5ca93fe8f462ceec476b8d4a13d6b9..8dbe534672438b9e74069f1505cde739c74111f1 100644 (file)
@@ -437,6 +437,17 @@ static inline ssize_t ul_listmount(uint64_t mnt_id,
 
        return syscall(SYS_listmount, &req, list, num, flags);
 }
+
+static inline int has_listmount(void)
+{
+       uint64_t dummy;
+
+       errno = 0;
+
+       if (ul_listmount(LSMT_ROOT, 0, 0, &dummy, 1, LISTMOUNT_REVERSE) != 1)
+               return 0;
+       return 1;
+}
 #endif
 
 #endif /* HAVE_STATMOUNT_API */
index c9725a23c5ff0484570dd98c5251d0bf443ba886..e4a1c2a529ec86f23e7d91c6dc3504ba621f9659 100644 (file)
@@ -91,18 +91,13 @@ static int table_init_listmount(struct libmnt_table *tb, size_t stepsiz)
        ls = tb->lsmnt;
 
        /* check if supported by current kernel */
-       if (!ls) {
-               uint64_t dummy;
-
-               errno = 0;
-               if (ul_listmount(LSMT_ROOT, 0, 0, &dummy, 1, LISTMOUNT_REVERSE) != 1) {
-                       if (errno == ENOSYS)
-                               DBG(TAB, ul_debugobj(tb, "listmount: unsuppported"));
-                       if (errno == EINVAL)
-                               DBG(TAB, ul_debugobj(tb, "listmount: reverse unsuppported"));
-                       errno = ENOSYS;
-                       return -ENOSYS;
-               }
+       if (!ls && !has_listmount()) {
+               if (errno == ENOSYS)
+                       DBG(TAB, ul_debugobj(tb, "listmount: unsuppported"));
+               if (errno == EINVAL)
+                       DBG(TAB, ul_debugobj(tb, "listmount: reverse unsuppported"));
+               errno = ENOSYS;
+               return -ENOSYS;
        }
 
        /* reset if allocated for a different size */
index 00bf12727dea19a17ab35fd28ece1e275dcc87c4..b4a601e3bc030590eae301b6bbcde21f319ea37d 100644 (file)
@@ -157,14 +157,13 @@ static int hlp_statmount_ok(void)
 
 static int hlp_listmount_ok(void)
 {
+       printf("%d\n",
 #ifdef HAVE_STATMOUNT_API
-       uint64_t dummy;
-       errno = 0;
-       ul_listmount(LSMT_ROOT, 0, 0, &dummy, 1, LISTMOUNT_REVERSE);
+               has_listmount()
 #else
-       errno = ENOSYS;
+               0
 #endif
-       printf("%d\n", !(errno == ENOSYS || errno == EINVAL));
+       );
        return 0;
 }