From: Michihiro NAKAJIMA Date: Wed, 11 Jan 2012 07:14:29 +0000 (-0500) Subject: Be more portable way to test if the current filesytem is mounted with noatime option. X-Git-Tag: v3.0.4~2^2~203 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b83f98a2210ec91f8abd4ec53ec7a31770a7f382;p=thirdparty%2Flibarchive.git Be more portable way to test if the current filesytem is mounted with noatime option. SVN-Revision: 4122 --- diff --git a/libarchive/test/test_read_disk_directory_traversals.c b/libarchive/test/test_read_disk_directory_traversals.c index ebbbdefeb..abb416c06 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 -#endif -#ifdef HAVE_SYS_MOUNT_H -#include -#endif -#ifdef HAVE_SYS_STATFS_H -#include -#endif -#ifdef HAVE_SYS_STATVFS_H -#include -#endif #include #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; }