From 3c61aab98b22d5224adad020788f8f656f528f66 Mon Sep 17 00:00:00 2001 From: usa Date: Mon, 14 Nov 2016 18:58:23 +0000 Subject: merge revision(s) 56559,56582,56584,56585: [Backport #12903] * test/ruby/test_file.rb (TestFile#test_stat): fix noatime case. [ruby-core:77943] [Bug #12903] * ext/-test/file/fs.c (get_atime_p): Updating of file access times is enabled or not. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@56789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/-test-/file/extconf.rb | 1 + ext/-test-/file/fs.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'ext') diff --git a/ext/-test-/file/extconf.rb b/ext/-test-/file/extconf.rb index 87a2f4a205..44aa828b25 100644 --- a/ext/-test-/file/extconf.rb +++ b/ext/-test-/file/extconf.rb @@ -4,6 +4,7 @@ headers = %w[sys/param.h sys/mount.h sys/vfs.h].select {|h| have_header(h)} if have_type("struct statfs", headers) have_struct_member("struct statfs", "f_fstypename", headers) have_struct_member("struct statfs", "f_type", headers) + have_struct_member("struct statfs", "f_flags", headers) end headers = %w[sys/statvfs.h].select {|h| have_header(h)} diff --git a/ext/-test-/file/fs.c b/ext/-test-/file/fs.c index d93ce27945..657a7d20a5 100644 --- a/ext/-test-/file/fs.c +++ b/ext/-test-/file/fs.c @@ -33,6 +33,12 @@ typedef struct statvfs statfs_t; # if defined HAVE_STRUCT_STATVFS_F_TYPE # define HAVE_STRUCT_STATFS_T_F_TYPE 1 # endif +#elif defined(HAVE_STRUCT_STATFS_F_TYPE) /* Linux */ +typedef struct statfs statfs_t; +# define STATFS(f, s) statfs((f), (s)) +# if defined HAVE_STRUCT_STATFS_F_TYPE +# define HAVE_STRUCT_STATFS_T_F_TYPE 1 +# endif #endif VALUE @@ -69,9 +75,31 @@ get_fsname(VALUE self, VALUE str) return Qnil; } +VALUE +get_noatime_p(VALUE self, VALUE str) +{ +#ifdef STATFS + statfs_t st; + FilePathValue(str); + str = rb_str_encode_ospath(str); + if (STATFS(StringValueCStr(str), &st) == -1) { + rb_sys_fail_str(str); + } +# ifdef HAVE_STRUCT_STATFS_F_FLAGS +# ifdef MNT_NOATIME + return st.f_flags & MNT_NOATIME ? Qtrue : Qfalse; +# elif defined(ST_NOATIME) + return st.f_flags & ST_NOATIME ? Qtrue : Qfalse; +# endif +# endif +#endif + return Qnil; +} + void Init_fs(VALUE module) { VALUE fs = rb_define_module_under(module, "Fs"); rb_define_module_function(fs, "fsname", get_fsname, 1); + rb_define_module_function(fs, "noatime?", get_noatime_p, 1); } -- cgit v1.2.3