2014-05-22 14:39:29 +04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/io.h"
|
|
|
|
|
2015-04-12 03:01:11 +03:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
2015-03-24 11:30:15 +03:00
|
|
|
#ifdef HAVE_SYS_MOUNT_H
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_VFS_H
|
|
|
|
#include <sys/vfs.h>
|
2014-05-22 14:39:29 +04:00
|
|
|
#endif
|
2015-05-03 16:54:54 +03:00
|
|
|
#ifdef HAVE_SYS_STATVFS_H
|
|
|
|
#include <sys/statvfs.h>
|
|
|
|
#endif
|
2014-05-22 14:39:29 +04:00
|
|
|
|
2015-03-24 11:30:15 +03:00
|
|
|
#if defined HAVE_STRUCT_STATFS_F_FSTYPENAME
|
|
|
|
typedef struct statfs statfs_t;
|
|
|
|
# define STATFS(f, s) statfs((f), (s))
|
|
|
|
# define HAVE_STRUCT_STATFS_T_F_FSTYPENAME 1
|
2015-03-25 11:03:11 +03:00
|
|
|
# if defined HAVE_STRUCT_STATFS_F_TYPE
|
|
|
|
# define HAVE_STRUCT_STATFS_T_F_TYPE 1
|
|
|
|
# endif
|
2015-03-24 11:30:15 +03:00
|
|
|
#elif defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME) /* NetBSD */
|
|
|
|
typedef struct statvfs statfs_t;
|
|
|
|
# define STATFS(f, s) statvfs((f), (s))
|
|
|
|
# define HAVE_STRUCT_STATFS_T_F_FSTYPENAME 1
|
2015-03-25 11:03:11 +03:00
|
|
|
# if defined HAVE_STRUCT_STATVFS_F_TYPE
|
|
|
|
# define HAVE_STRUCT_STATFS_T_F_TYPE 1
|
|
|
|
# endif
|
2015-03-24 11:30:15 +03:00
|
|
|
#elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE) /* AIX, HP-UX, Solaris */
|
|
|
|
typedef struct statvfs statfs_t;
|
|
|
|
# define STATFS(f, s) statvfs((f), (s))
|
|
|
|
# define HAVE_STRUCT_STATFS_T_F_FSTYPENAME 1
|
|
|
|
# define f_fstypename f_basetype
|
2015-03-25 11:03:11 +03:00
|
|
|
# if defined HAVE_STRUCT_STATVFS_F_TYPE
|
|
|
|
# define HAVE_STRUCT_STATFS_T_F_TYPE 1
|
|
|
|
# endif
|
2016-11-05 11:23:57 +03:00
|
|
|
#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
|
2014-05-22 14:39:29 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
get_fsname(VALUE self, VALUE str)
|
|
|
|
{
|
2015-03-24 11:30:15 +03:00
|
|
|
#ifdef STATFS
|
|
|
|
statfs_t st;
|
|
|
|
# define CSTR(s) rb_str_new_cstr(s)
|
2014-05-22 14:39:29 +04:00
|
|
|
|
|
|
|
FilePathValue(str);
|
2015-03-24 11:30:15 +03:00
|
|
|
str = rb_str_encode_ospath(str);
|
|
|
|
if (STATFS(StringValueCStr(str), &st) == -1) {
|
|
|
|
rb_sys_fail_str(str);
|
|
|
|
}
|
|
|
|
# ifdef HAVE_STRUCT_STATFS_T_F_FSTYPENAME
|
|
|
|
if (st.f_fstypename[0])
|
|
|
|
return CSTR(st.f_fstypename);
|
|
|
|
# endif
|
2015-03-25 11:03:11 +03:00
|
|
|
# ifdef HAVE_STRUCT_STATFS_T_F_TYPE
|
2015-03-24 11:30:15 +03:00
|
|
|
switch (st.f_type) {
|
|
|
|
case 0x9123683E: /* BTRFS_SUPER_MAGIC */
|
|
|
|
return CSTR("btrfs");
|
|
|
|
case 0x7461636f: /* OCFS2_SUPER_MAGIC */
|
|
|
|
return CSTR("ocfs");
|
|
|
|
case 0xEF53: /* EXT2_SUPER_MAGIC EXT3_SUPER_MAGIC EXT4_SUPER_MAGIC */
|
|
|
|
return CSTR("ext4");
|
|
|
|
case 0x58465342: /* XFS_SUPER_MAGIC */
|
|
|
|
return CSTR("xfs");
|
|
|
|
case 0x01021994: /* TMPFS_MAGIC */
|
|
|
|
return CSTR("tmpfs");
|
2014-05-22 14:39:29 +04:00
|
|
|
}
|
2015-03-25 11:03:11 +03:00
|
|
|
# endif
|
2014-05-22 14:39:29 +04:00
|
|
|
#endif
|
2015-03-24 11:30:15 +03:00
|
|
|
return Qnil;
|
2014-05-22 14:39:29 +04:00
|
|
|
}
|
|
|
|
|
2016-11-05 11:23:57 +03:00
|
|
|
VALUE
|
2016-11-05 11:59:42 +03:00
|
|
|
get_noatime_p(VALUE self, VALUE str)
|
2016-11-05 11:23:57 +03:00
|
|
|
{
|
|
|
|
#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
|
2019-10-12 08:55:55 +03:00
|
|
|
# ifdef MNT_STRICTATIME
|
|
|
|
if (!(st.f_flags & MNT_STRICTATIME)) return Qtrue;
|
|
|
|
# endif
|
2016-11-05 11:23:57 +03:00
|
|
|
# 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;
|
|
|
|
}
|
|
|
|
|
2014-05-22 14:39:29 +04:00
|
|
|
void
|
|
|
|
Init_fs(VALUE module)
|
|
|
|
{
|
|
|
|
VALUE fs = rb_define_module_under(module, "Fs");
|
|
|
|
rb_define_module_function(fs, "fsname", get_fsname, 1);
|
2016-11-05 11:59:42 +03:00
|
|
|
rb_define_module_function(fs, "noatime?", get_noatime_p, 1);
|
2014-05-22 14:39:29 +04:00
|
|
|
}
|