]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Introduce canNodump and assertNodump to bsdtar_test and bsdcpio_test.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 31 Dec 2011 21:39:51 +0000 (16:39 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 31 Dec 2011 21:39:51 +0000 (16:39 -0500)
SVN-Revision: 4054

cpio/test/main.c
cpio/test/test.h
tar/test/main.c
tar/test/test.h

index 3ef9f40dfa89df444e7e5b8ca60498b9587d0173..6d0d75899542c570e351d09fb47a45050b97e028 100644 (file)
@@ -24,6 +24,9 @@
  */
 
 #include "test.h"
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
 #ifdef HAVE_ICONV_H
 #include <iconv.h>
 #endif
+/*
+ * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h.
+ * As the include guards don't agree, the order of include is important.
+ */
+#ifdef HAVE_LINUX_EXT2_FS_H
+#include <linux/ext2_fs.h>      /* for Linux file flags */
+#endif
+#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__)
+#include <ext2fs/ext2_fs.h>     /* Linux file flags, broken on Cygwin */
+#endif
 #include <limits.h>
 #include <locale.h>
 #ifdef HAVE_SIGNAL_H
@@ -1716,6 +1729,52 @@ assertion_utimes(const char *file, int line,
 #endif /* defined(_WIN32) && !defined(__CYGWIN__) */
 }
 
+/* Set nodump, report failures. */
+int
+assertion_nodump(const char *file, int line, const char *pathname)
+{
+#if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
+       int r;
+
+       assertion_count(file, line);
+       r = chflags(pathname, UF_NODUMP);
+       if (r < 0) {
+               failure_start(file, line, "Can't set nodump %s\n", pathname);
+               failure_finish(NULL);
+               return (0);
+       }
+#elif defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS)\
+        && defined(EXT2_NODUMP_FL)
+       int fd, r, flags;
+
+       assertion_count(file, line);
+       fd = open(pathname, O_RDONLY | O_NONBLOCK);
+       if (fd < 0) {
+               failure_start(file, line, "Can't open %s\n", pathname);
+               failure_finish(NULL);
+               return (0);
+       }
+       r = ioctl(fd, EXT2_IOC_GETFLAGS, &flags);
+       if (r < 0) {
+               failure_start(file, line, "Can't get flags %s\n", pathname);
+               failure_finish(NULL);
+               return (0);
+       }
+       flags |= EXT2_NODUMP_FL;
+       r = ioctl(fd, EXT2_IOC_SETFLAGS, &flags);
+       if (r < 0) {
+               failure_start(file, line, "Can't set nodump %s\n", pathname);
+               failure_finish(NULL);
+               return (0);
+       }
+       close(fd);
+#else
+       (void)pathname; /* UNUSED */
+       assertion_count(file, line);
+#endif
+       return (1);
+}
+
 /*
  *
  *  UTILITIES for use by tests.
@@ -1793,6 +1852,70 @@ canGunzip(void)
        return (value);
 }
 
+/*
+ * Can this filesystem handle nodump flags.
+ */
+#if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
+
+int
+canNodump(void)
+{
+       const char *path = "cannodumptest";
+       struct stat sb;
+
+       assertion_make_file(__FILE__, __LINE__, path, 0644, NULL);
+       if (chflags(path, UF_NODUMP) < 0)
+               return (0);
+       if (stat(path, &sb) < 0)
+               return (0);
+       if (sb.st_flags & UF_NODUMP)
+               return (1);
+       return (0);
+}
+
+#elif defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS)\
+        && defined(EXT2_NODUMP_FL)
+
+int
+canNodump(void)
+{
+       const char *path = "cannodumptest";
+       int fd, r, flags;
+
+       assertion_make_file(__FILE__, __LINE__, path, 0644, NULL);
+       fd = open(path, O_RDONLY | O_NONBLOCK);
+       if (fd < 0)
+               return (0);
+       r = ioctl(fd, EXT2_IOC_GETFLAGS, &flags);
+       if (r < 0)
+               return (0);
+       flags |= EXT2_NODUMP_FL;
+       r = ioctl(fd, EXT2_IOC_SETFLAGS, &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);
+       if (r < 0)
+               return (0);
+       close(fd);
+       if (flags & EXT2_NODUMP_FL)
+               return (1);
+       return (0);
+}
+
+#else
+
+int
+canNodump()
+{
+       return (0);
+}
+
+#endif
+
 /*
  * Sleep as needed; useful for verifying disk timestamp changes by
  * ensuring that the wall-clock time has actually changed before we
index 46124f84b20e7bf204290bbe1d2f32b386122a3e..601ec938a597b81ffc4d7673e9d5d87fb2b2510c 100644 (file)
   assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile)
 #define assertMakeSymlink(newfile, linkto)     \
   assertion_make_symlink(__FILE__, __LINE__, newfile, linkto)
+#define assertNodump(path)      \
+  assertion_nodump(__FILE__, __LINE__, path)
 #define assertUmask(mask)      \
   assertion_umask(__FILE__, __LINE__, mask)
 #define assertUtimes(pathname, atime, atime_nsec, mtime, mtime_nsec)   \
@@ -244,6 +246,7 @@ int assertion_make_dir(const char *, int, const char *, int);
 int assertion_make_file(const char *, int, const char *, int, const char *);
 int assertion_make_hardlink(const char *, int, const char *newpath, const char *);
 int assertion_make_symlink(const char *, int, const char *newpath, const char *);
+int assertion_nodump(const char *, int, const char *);
 int assertion_non_empty_file(const char *, int, const char *);
 int assertion_text_file_contents(const char *, int, const char *buff, const char *f);
 int assertion_umask(const char *, int, int);
@@ -267,6 +270,9 @@ int canGzip(void);
 /* Return true if this platform can run the "gunzip" program. */
 int canGunzip(void);
 
+/* Return true if this filesystem can handle nodump flags. */
+int canNodump(void);
+
 /* Return true if the file has large i-node number(>0xffffffff). */
 int is_LargeInode(const char *);
 
index 51ae5f2c87d67dd1976764d13b40edf261d6af85..45a5f4875c3d8aaf2d06ec48db1b2f5c173cc28b 100644 (file)
@@ -24,6 +24,9 @@
  */
 
 #include "test.h"
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
 #ifdef HAVE_ICONV_H
 #include <iconv.h>
 #endif
+/*
+ * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h.
+ * As the include guards don't agree, the order of include is important.
+ */
+#ifdef HAVE_LINUX_EXT2_FS_H
+#include <linux/ext2_fs.h>      /* for Linux file flags */
+#endif
+#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__)
+#include <ext2fs/ext2_fs.h>     /* Linux file flags, broken on Cygwin */
+#endif
 #include <limits.h>
 #include <locale.h>
 #ifdef HAVE_SIGNAL_H
@@ -1716,6 +1729,52 @@ assertion_utimes(const char *file, int line,
 #endif /* defined(_WIN32) && !defined(__CYGWIN__) */
 }
 
+/* Set nodump, report failures. */
+int
+assertion_nodump(const char *file, int line, const char *pathname)
+{
+#if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
+       int r;
+
+       assertion_count(file, line);
+       r = chflags(pathname, UF_NODUMP);
+       if (r < 0) {
+               failure_start(file, line, "Can't set nodump %s\n", pathname);
+               failure_finish(NULL);
+               return (0);
+       }
+#elif defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS)\
+        && defined(EXT2_NODUMP_FL)
+       int fd, r, flags;
+
+       assertion_count(file, line);
+       fd = open(pathname, O_RDONLY | O_NONBLOCK);
+       if (fd < 0) {
+               failure_start(file, line, "Can't open %s\n", pathname);
+               failure_finish(NULL);
+               return (0);
+       }
+       r = ioctl(fd, EXT2_IOC_GETFLAGS, &flags);
+       if (r < 0) {
+               failure_start(file, line, "Can't get flags %s\n", pathname);
+               failure_finish(NULL);
+               return (0);
+       }
+       flags |= EXT2_NODUMP_FL;
+       r = ioctl(fd, EXT2_IOC_SETFLAGS, &flags);
+       if (r < 0) {
+               failure_start(file, line, "Can't set nodump %s\n", pathname);
+               failure_finish(NULL);
+               return (0);
+       }
+       close(fd);
+#else
+       (void)pathname; /* UNUSED */
+       assertion_count(file, line);
+#endif
+       return (1);
+}
+
 /*
  *
  *  UTILITIES for use by tests.
@@ -1793,6 +1852,70 @@ canGunzip(void)
        return (value);
 }
 
+/*
+ * Can this filesystem handle nodump flags.
+ */
+#if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
+
+int
+canNodump(void)
+{
+       const char *path = "cannodumptest";
+       struct stat sb;
+
+       assertion_make_file(__FILE__, __LINE__, path, 0644, NULL);
+       if (chflags(path, UF_NODUMP) < 0)
+               return (0);
+       if (stat(path, &sb) < 0)
+               return (0);
+       if (sb.st_flags & UF_NODUMP)
+               return (1);
+       return (0);
+}
+
+#elif defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS)\
+        && defined(EXT2_NODUMP_FL)
+
+int
+canNodump(void)
+{
+       const char *path = "cannodumptest";
+       int fd, r, flags;
+
+       assertion_make_file(__FILE__, __LINE__, path, 0644, NULL);
+       fd = open(path, O_RDONLY | O_NONBLOCK);
+       if (fd < 0)
+               return (0);
+       r = ioctl(fd, EXT2_IOC_GETFLAGS, &flags);
+       if (r < 0)
+               return (0);
+       flags |= EXT2_NODUMP_FL;
+       r = ioctl(fd, EXT2_IOC_SETFLAGS, &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);
+       if (r < 0)
+               return (0);
+       close(fd);
+       if (flags & EXT2_NODUMP_FL)
+               return (1);
+       return (0);
+}
+
+#else
+
+int
+canNodump()
+{
+       return (0);
+}
+
+#endif
+
 /*
  * Sleep as needed; useful for verifying disk timestamp changes by
  * ensuring that the wall-clock time has actually changed before we
index f8682d5a8014790d1bcf836dcd429958504209cb..ccb14db4a43ea841b14e11aa726107fd87963ef9 100644 (file)
   assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile)
 #define assertMakeSymlink(newfile, linkto)     \
   assertion_make_symlink(__FILE__, __LINE__, newfile, linkto)
+#define assertNodump(path)      \
+  assertion_nodump(__FILE__, __LINE__, path)
 #define assertUmask(mask)      \
   assertion_umask(__FILE__, __LINE__, mask)
 #define assertUtimes(pathname, atime, atime_nsec, mtime, mtime_nsec)   \
@@ -246,6 +248,7 @@ int assertion_make_dir(const char *, int, const char *, int);
 int assertion_make_file(const char *, int, const char *, int, const char *);
 int assertion_make_hardlink(const char *, int, const char *newpath, const char *);
 int assertion_make_symlink(const char *, int, const char *newpath, const char *);
+int assertion_nodump(const char *, int, const char *);
 int assertion_non_empty_file(const char *, int, const char *);
 int assertion_text_file_contents(const char *, int, const char *buff, const char *f);
 int assertion_umask(const char *, int, int);
@@ -269,6 +272,9 @@ int canGzip(void);
 /* Return true if this platform can run the "gunzip" program. */
 int canGunzip(void);
 
+/* Return true if this filesystem can handle nodump flags. */
+int canNodump(void);
+
 /* Return true if the file has large i-node number(>0xffffffff). */
 int is_LargeInode(const char *);