From: Karel Zak Date: Thu, 24 Apr 2025 16:45:24 +0000 (+0200) Subject: libmount: use and add has_listmount() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=78ade43875b09436616421a6dd10d53673fde415;p=thirdparty%2Futil-linux.git libmount: use and add has_listmount() Signed-off-by: Karel Zak --- diff --git a/include/mount-api-utils.h b/include/mount-api-utils.h index ea9aeb816..8dbe53467 100644 --- a/include/mount-api-utils.h +++ b/include/mount-api-utils.h @@ -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 */ diff --git a/libmount/src/tab_listmount.c b/libmount/src/tab_listmount.c index c9725a23c..e4a1c2a52 100644 --- a/libmount/src/tab_listmount.c +++ b/libmount/src/tab_listmount.c @@ -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 */ diff --git a/tests/helpers/test_sysinfo.c b/tests/helpers/test_sysinfo.c index 00bf12727..b4a601e3b 100644 --- a/tests/helpers/test_sysinfo.c +++ b/tests/helpers/test_sysinfo.c @@ -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; }