[PATCH 2/2] libmount: check for struct statx

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Let's ensure struct statx exists before we try to use it. Checking for
the existence of linux/stat.h is not sufficient. This is because
[uapi/]linux/stat.h has existed since Linux 3.7, however struct statx
was only introduced with Linux 4.11.

The problem arises if one happens ot be using kernel headers from within
the aforementioned range, such as Linux 4.9.

  CC       libmount/src/la-utils.lo
In file included from libmount/src/utils.c:31:
./include/fileutils.h:100:33: warning: declaration of 'struct statx' will not
be visible outside of this function [-Wvisibility]
                    unsigned int mask, struct statx *stx)
                                              ^
libmount/src/utils.c:117:16: error: variable has incomplete type 'struct statx'
                struct statx stx = { 0 };
                             ^
libmount/src/utils.c:117:10: note: forward declaration of 'struct statx'
                struct statx stx = { 0 };
                       ^
libmount/src/utils.c:125:5: error: use of undeclared identifier 'STATX_TYPE'
                                STATX_TYPE
                                ^
libmount/src/utils.c:126:8: error: use of undeclared identifier 'STATX_MODE'
                                        | STATX_MODE
                                          ^
libmount/src/utils.c:127:8: error: use of undeclared identifier 'STATX_INO'
                                        | STATX_INO,
                                          ^
1 warning and 4 errors generated.
make[4]: *** [Makefile:11269: libmount/src/la-utils.lo] Error 1

Checking for the presence of struct statx explicitly avoids this
problem.

Signed-off-by: Markus Mayer <mmayer@xxxxxxxxxxxx>
---
 configure.ac         | 1 +
 include/fileutils.h  | 2 +-
 libmount/src/utils.c | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index dd582f2a4bd1..a3cf330b5ec3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -518,6 +518,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 ])
 
 AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <linux/mount.h>]])
+AC_CHECK_TYPES([struct statx], [], [], [[#include <linux/stat.h>]])
 AC_CHECK_TYPES([enum fsconfig_command], [], [], [[#include <linux/mount.h>]])
 
 AC_CHECK_MEMBERS([struct termios.c_line],,,
diff --git a/include/fileutils.h b/include/fileutils.h
index 13d2bdf0c6e5..a5fe517266f5 100644
--- a/include/fileutils.h
+++ b/include/fileutils.h
@@ -94,7 +94,7 @@ static inline int close_range(unsigned int first, unsigned int last, int flags)
 #  define HAVE_CLOSE_RANGE 1
 # endif	/* SYS_close_range */
 
-# if !defined(HAVE_STATX) && defined(SYS_statx) && defined(HAVE_LINUX_STAT_H)
+# if !defined(HAVE_STATX) && defined(HAVE_STRUCT_STATX) && defined(SYS_statx) && defined(HAVE_LINUX_STAT_H)
 #  include <linux/stat.h>
 static inline int statx(int fd, const char *restrict path, int flags,
 		    unsigned int mask, struct statx *stx)
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index 50553f1d5a14..e550b2d079e8 100644
--- a/libmount/src/utils.c
+++ b/libmount/src/utils.c
@@ -111,7 +111,7 @@ static int safe_stat(const char *target, struct stat *st, int nofollow)
 
 	memset(st, 0, sizeof(struct stat));
 
-#ifdef AT_STATX_DONT_SYNC
+#if defined(AT_STATX_DONT_SYNC) && defined (HAVE_STRUCT_STATX)
 	{
 		int rc;
 		struct statx stx = { 0 };
-- 
2.40.1




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux