]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Enable canNodump and assertNodump on linux and move them into test/main.c
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 31 Dec 2011 21:37:38 +0000 (16:37 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 31 Dec 2011 21:37:38 +0000 (16:37 -0500)
SVN-Revision: 4053

libarchive/test/main.c
libarchive/test/test.h
libarchive/test/test_read_disk_directory_traversals.c

index 4be38d6394c1c6cd22c8ac325ebca5066b708357..4b11454e56efbc50211909475cac1cbf9e74832a 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
@@ -1714,6 +1727,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.
@@ -1791,6 +1850,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 4c82ece92d452527269262e8f38d4f9d020dbcbb..e4591942174ed473498da312a8c18e73b449cb41 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 32fc2470d2d2c5a5624d1f0eaa0591955712c948..569d4745f090bda7819ca635455172d186d16bb8 100644 (file)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2010-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2010-2012 Michihiro NAKAJIMA
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include "test.h"
 __FBSDID("$FreeBSD$");
 
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
 #include <limits.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
 #if defined(_WIN32) && !defined(__CYGWIN__)
 # if !defined(__BORLANDC__)
 #  define getcwd _getcwd
@@ -1238,46 +1232,6 @@ test_callbacks(void)
        archive_entry_free(ae);
 }
 
-#if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
-static int
-canNodump()
-{
-       const char *path = "cannodumptest";
-       struct stat sb;
-
-       assertMakeFile(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);
-}
-
-static int
-assertNodump(const char *path)
-{
-       return (assertEqualInt(0, chflags(path, UF_NODUMP)));
-}
-
-#else
-
-static int
-canNodump()
-{
-       return (0);
-}
-
-static int
-assertNodump(const char *path)
-{
-       (void)path; /* UNUSED */
-       return (0);
-}
-
-#endif
-
 static void
 test_nodump(void)
 {