diff options
author | Martin Matuska <martin@matuska.org> | 2017-02-24 01:56:50 +0100 |
---|---|---|
committer | Martin Matuska <martin@matuska.org> | 2017-02-24 02:04:16 +0100 |
commit | a9c5818b92c7800241387c8e5389c66e724b19fa (patch) | |
tree | e83e02722c74a2c3899e8c4dd335ab753c5ee504 /test_utils | |
parent | 525f55c9b8dcfb0cfe1075ba4b1014443c7c3bb6 (diff) | |
download | libarchive-a9c5818b92c7800241387c8e5389c66e724b19fa.tar.gz |
Fix broken Linux fflags code since kernel 3.7 (Dec 2012)
Diffstat (limited to 'test_utils')
-rw-r--r-- | test_utils/test_main.c | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/test_utils/test_main.c b/test_utils/test_main.c index b0b6c2bd..2ae6b38d 100644 --- a/test_utils/test_main.c +++ b/test_utils/test_main.c @@ -45,6 +45,9 @@ #if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) #include <ext2fs/ext2_fs.h> /* Linux file flags, broken on Cygwin */ #endif +#ifdef HAVE_LINUX_FS_H +#include <linux/fs.h> +#endif #include <limits.h> #include <locale.h> #ifdef HAVE_SIGNAL_H @@ -1894,8 +1897,10 @@ assertion_nodump(const char *file, int line, const char *pathname) failure_finish(NULL); return (0); } -#elif defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS)\ - && defined(EXT2_NODUMP_FL) +#elif (defined(FS_IOC_GETFLAGS) && defined(HAVE_WORKING_FS_IOC_GETFLAGS) && \ + defined(FS_NODUMP_FL)) || \ + (defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS) \ + && defined(EXT2_NODUMP_FL)) int fd, r, flags; assertion_count(file, line); @@ -1905,14 +1910,31 @@ assertion_nodump(const char *file, int line, const char *pathname) failure_finish(NULL); return (0); } - r = ioctl(fd, EXT2_IOC_GETFLAGS, &flags); + r = ioctl(fd, +#ifdef FS_IOC_GETFLAGS + FS_IOC_GETFLAGS, +#else + EXT2_IOC_GETFLAGS, +#endif + &flags); if (r < 0) { failure_start(file, line, "Can't get flags %s\n", pathname); failure_finish(NULL); return (0); } +#ifdef FS_NODUMP_FL + flags |= FS_NODUMP_FL; +#else flags |= EXT2_NODUMP_FL; - r = ioctl(fd, EXT2_IOC_SETFLAGS, &flags); +#endif + + r = ioctl(fd, +#ifdef FS_IOC_SETFLAGS + FS_IOC_SETFLAGS, +#else + EXT2_IOC_SETFLAGS, +#endif + &flags); if (r < 0) { failure_start(file, line, "Can't set nodump %s\n", pathname); failure_finish(NULL); @@ -2252,9 +2274,10 @@ canNodump(void) return (0); } -#elif defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS)\ - && defined(EXT2_NODUMP_FL) - +#elif (defined(FS_IOC_GETFLAGS) && defined(HAVE_WORKING_FS_IOC_GETFLAGS) \ + && defined(FS_NODUMP_FL)) || \ + (defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS) \ + && defined(EXT2_NODUMP_FL)) int canNodump(void) { @@ -2265,22 +2288,48 @@ canNodump(void) fd = open(path, O_RDONLY | O_NONBLOCK); if (fd < 0) return (0); - r = ioctl(fd, EXT2_IOC_GETFLAGS, &flags); + r = ioctl(fd, +#ifdef FS_IOC_GETFLAGS + FS_IOC_GETFLAGS, +#else + EXT2_IOC_GETFLAGS, +#endif + &flags); if (r < 0) return (0); +#ifdef FS_NODUMP_FL + flags |= FS_NODUMP_FL; +#else flags |= EXT2_NODUMP_FL; - r = ioctl(fd, EXT2_IOC_SETFLAGS, &flags); +#endif + r = ioctl(fd, +#ifdef FS_IOC_SETFLAGS + FS_IOC_SETFLAGS, +#else + EXT2_IOC_SETFLAGS, +#endif + &flags); if (r < 0) return (0); close(fd); fd = open(path, O_RDONLY | O_NONBLOCK); if (fd < 0) return (0); - r = ioctl(fd, EXT2_IOC_GETFLAGS, &flags); + r = ioctl(fd, +#ifdef FS_IOC_GETFLAGS + FS_IOC_GETFLAGS, +#else + EXT2_IOC_GETFLAGS, +#endif + &flags); if (r < 0) return (0); close(fd); +#ifdef FS_NODUMP_FL + if (flags & FS_NODUMP_FL) +#else if (flags & EXT2_NODUMP_FL) +#endif return (1); return (0); } |