Author: Dharanendiran <dharanendiran@timesys.com>
Date: Wed, 7 Oct 2026 21:03:44 +0530

Error log:
In file included from ./include/mountutils.h:9,
                 from sys-utils/mountpoint.c:34:
/home/timesys/ubuntu-20.04-64/ubuntu-20_04-64/build/build_aarch64-timesys-linux-gnu/toolchain/include/linux/mount.h:96:6: error: nested redefinition of 'enum fsconfig_command'
   96 | enum fsconfig_command {
      |      ^~~~~~~~~~~~~~~~
/home/timesys/ubuntu-20.04-64/ubuntu-20_04-64/build/build_aarch64-timesys-linux-gnu/toolchain/include/linux/mount.h:96:6: error: redeclaration of 'enum fsconfig_command'
In file included from ./libmount/src/libmount.h:40,
                 from sys-utils/mountpoint.c:27:
/home/timesys/ubuntu-20.04-64/ubuntu-20_04-64/build/build_aarch64-timesys-linux-gnu/toolchain/lib/gcc/aarch64-timesys-linux-gnu/9.5.0/include-fixed/sys/mount.h:250:6: note: originally defined here
  250 | enum fsconfig_command
      |      ^~~~~~~~~~~~~~~~
/home/timesys/ubuntu-20.04-64/ubuntu-20_04-64/build/build_aarch64-timesys-linux-gnu/toolchain/include/linux/mount.h:97:2: error: redeclaration of enumerator 'FSCONFIG_SET_FLAG'
   97 |  FSCONFIG_SET_FLAG = 0, /* Set parameter, supplying no value */
      |  ^~~~~~~~~~~~~~~~~
/home/timesys/ubuntu-20.04-64/ubuntu-20_04-64/build/build_aarch64-timesys-linux-gnu/toolchain/lib/gcc/aarch64-timesys-linux-gnu/9.5.0/include-fixed/sys/mount.h:252:3: note: previous definition of 'FSCONFIG_SET_FLAG' was here
  252 |   FSCONFIG_SET_FLAG       = 0,    /* Set parameter, supplying no value */
      |   ^~~~~~~~~~~~~~~~~
/home/timesys/ubuntu-20.04-64/ubuntu-20_04-64/build/build_aarch64-timesys-linux-gnu/toolchain/include/linux/mount.h:98:2: error: redeclaration of enumerator 'FSCONFIG_SET_STRING'
   98 |  FSCONFIG_SET_STRING = 1, /* Set parameter, supplying a string value */
      |  ^~~~~~~~~~~~~~~~~~~
/home/timesys/ubuntu-20.04-64/ubuntu-20_04-64/build/build_aarch64-timesys-linux-gnu/toolchain/lib/gcc/aarch64-timesys-linux-gnu/9.5.0/include-fixed/sys/mount.h:254:3: note: previous definition of 'FSCONFIG_SET_STRING' was here
  254 |   FSCONFIG_SET_STRING     = 1,    /* Set parameter, supplying a string value */
      |   ^~~~~~~~~~~~~~~~~~~
/home/timesys/ubuntu-20.04-64/ubuntu-20_04-64/build/build_aarch64-timesys-linux-gnu/toolchain/include/linux/mount.h:99:2: error: redeclaration of enumerator 'FSCONFIG_SET_BINARY'
   99 |  FSCONFIG_SET_BINARY = 2, /* Set parameter, supplying a binary blob value */
      |  ^~~~~~~~~~~~~~~~~~~
/home/timesys/ubuntu-20.04-64/ubuntu-20_04-64/build/build_aarch64-timesys-linux-gnu/toolchain/lib/gcc/aarch64-timesys-linux-gnu/9.5.0/include-fixed/sys/mount.h:256:3: note: previous definition of 'FSCONFIG_SET_BINARY' was here
  256 |   FSCONFIG_SET_BINARY     = 2,    /* Set parameter, supplying a binary blob value */
      |   ^~~~~~~~~~~~~~~~~~~
/home/timesys/ubuntu-20.04-64/ubuntu-20_04-64/build/build_aarch64-timesys-linux-gnu/toolchain/include/linux/mount.h:100:2: error: redeclaration of enumerator 'FSCONFIG_SET_PATH'
  100 |  FSCONFIG_SET_PATH = 3, /* Set parameter, supplying an object by path */
      |  ^~~~~~~~~~~~~~~~~
/home/timesys/ubuntu-20.04-64/ubuntu-20_04-64/build/build_aarch64-timesys-linux-gnu/toolchain/lib/gcc/aarch64-timesys-linux-gnu/9.5.0/include-fixed/sys/mount.h:258:3: note: previous definition of 'FSCONFIG_SET_PATH' was here
  258 |   FSCONFIG_SET_PATH       = 3,    /* Set parameter, supplying an object by path */
      |   ^~~~~~~~~~~~~~~~~

---
 config.h.in          |  3 +++
 configure            | 36 ++++++++++++++++++++++++++++++++++++
 include/mountutils.h | 13 ++++++++++++-
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/config.h.in b/config.h.in
index cbdbd39..801692c 100644
--- a/config.h.in
+++ b/config.h.in
@@ -760,6 +760,9 @@
 /* Define to 1 if you have the <sys/mman.h> header file. */
 #undef HAVE_SYS_MMAN_H
 
+/* Define to 1 if sys/mount.h provides the mount API */
+#undef HAVE_SYS_MOUNT_API
+
 /* Define to 1 if you have the <sys/mount.h> header file. */
 #undef HAVE_SYS_MOUNT_H
 
diff --git a/configure b/configure
index 1ac22a9..e798170 100755
--- a/configure
+++ b/configure
@@ -27955,6 +27955,42 @@ printf "%s\n" "#define HAVE_ENUM_FSCONFIG_COMMAND 1" >>confdefs.h
 fi
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether sys/mount.h provides the mount API" >&5
+$as_echo_n "checking whether sys/mount.h provides the mount API... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <sys/mount.h>
+
+int
+main ()
+{
+
+struct mount_attr attr;
+enum fsconfig_command cmd = FSCONFIG_SET_FLAG;
+(void) attr;
+return cmd;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+$as_echo "#define HAVE_SYS_MOUNT_API 1" >>confdefs.h
+
+
+else
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
 ac_fn_c_check_member "$LINENO" "struct termios" "c_line" "ac_cv_member_struct_termios_c_line" "#include <termios.h>
 "
 if test "x$ac_cv_member_struct_termios_c_line" = xyes
diff --git a/include/mountutils.h b/include/mountutils.h
index 057a29d..827449b 100644
--- a/include/mountutils.h
+++ b/include/mountutils.h
@@ -6,7 +6,18 @@
 #define UTIL_LINUX_MOUNTUTILS_H
 
 #ifdef HAVE_LINUX_MOUNT_H
-#include <linux/mount.h>
+/* glibc >= 2.36 defines struct mount_attr / enum fsconfig_command in its
+ * own <sys/mount.h>, which conflicts with <linux/mount.h> if both are
+ * included in the same translation unit. Prefer whichever one already
+ * supplied these types (detected by configure/meson), and only fall
+ * back to <linux/mount.h> if neither has provided them yet.
+ * See: https://sourceware.org/glibc/wiki/Synchronizing_Headers
+ */
+#ifdef HAVE_SYS_MOUNT_API
+# include <sys/mount.h>
+#else
+# include <linux/mount.h>
+#endif
 #include <linux/unistd.h>
 #include <sys/syscall.h>
 #include <inttypes.h>
-- 
2.25.1

