summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>2012-01-11 02:14:29 -0500
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>2012-01-11 02:14:29 -0500
commitb83f98a2210ec91f8abd4ec53ec7a31770a7f382 (patch)
tree2c262fb544e8c219768069449b70763d4568e619
parentc2a2e5f990a53ea4573cfc0f09dd42e9fff179fb (diff)
downloadlibarchive-b83f98a2210ec91f8abd4ec53ec7a31770a7f382.tar.gz
Be more portable way to test if the current filesytem is mounted with noatime option.
SVN-Revision: 4122
-rw-r--r--libarchive/test/test_read_disk_directory_traversals.c57
1 files changed, 17 insertions, 40 deletions
diff --git a/libarchive/test/test_read_disk_directory_traversals.c b/libarchive/test/test_read_disk_directory_traversals.c
index ebbbdefe..abb416c0 100644
--- a/libarchive/test/test_read_disk_directory_traversals.c
+++ b/libarchive/test/test_read_disk_directory_traversals.c
@@ -25,18 +25,6 @@
#include "test.h"
__FBSDID("$FreeBSD$");
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-#ifdef HAVE_SYS_MOUNT_H
-#include <sys/mount.h>
-#endif
-#ifdef HAVE_SYS_STATFS_H
-#include <sys/statfs.h>
-#endif
-#ifdef HAVE_SYS_STATVFS_H
-#include <sys/statvfs.h>
-#endif
#include <limits.h>
#if defined(_WIN32) && !defined(__CYGWIN__)
# if !defined(__BORLANDC__)
@@ -45,39 +33,28 @@ __FBSDID("$FreeBSD$");
#endif
/*
- * Test if the current filesytem can restore atime.
+ * Test if the current filesytem is mounted with noatime option.
*/
-#if defined(HAVE_STATVFS) && defined(ST_NOATIME)
-static int
-canRestoreAtime(void)
-{
- struct statvfs sfs;
- int r;
-
- r = statvfs(".", &sfs);
- if (r != 0)
- return (1);
- return (sfs.f_flag & ST_NOATIME)?0:1;
-}
-#elif defined(HAVE_STATFS) && defined(MNT_NOATIME)
static int
-canRestoreAtime(void)
+atimeIsUpdated(void)
{
- struct statfs sfs;
- int r;
+ const char *fn = "fs_noatime";
+ struct stat st;
- r = statfs(".", &sfs);
- if (r != 0)
+ if (!assertMakeFile(fn, 0666, "a"))
+ return (0);
+ if (!assertUtimes(fn, 1, 0, 1, 0))
+ return (0);
+ /* Test the file contents in order to update its atime. */
+ if (!assertTextFileContents("a", fn))
+ return (0);
+ if (stat(fn, &st) != 0)
+ return (0);
+ /* Is atime updated? */
+ if (st.st_atime > 1)
return (1);
- return (sfs.f_flags & MNT_NOATIME)?0:1;
+ return (0);
}
-#else
-static int
-canRestoreAtime(void)
-{
- return (1);
-}
-#endif
static void
test_basic(void)
@@ -1048,7 +1025,7 @@ test_restore_atime(void)
int64_t offset;
int file_count;
- if (!canRestoreAtime()) {
+ if (!atimeIsUpdated()) {
skipping("Can't test restoring atime on this filesystem");
return;
}