[前][次][番号順一覧][スレッド一覧]

ruby-changes:38540

From: nagachika <ko1@a...>
Date: Sun, 24 May 2015 02:15:32 +0900 (JST)
Subject: [ruby-changes:38540] nagachika:r50621 (ruby_2_2): merge revision(s) 50071, 50088: [Backport #10998] [Backport #11000]

nagachika	2015-05-24 02:15:12 +0900 (Sun, 24 May 2015)

  New Revision: 50621

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50621

  Log:
    merge revision(s) 50071,50088: [Backport #10998] [Backport #11000]
    
    * ext/-test-/file/fs.c (get_fsname): return filesystem name by
      statfs/statvfs.  [ruby-core:68624] [Bug #10998]
    
    * ext/-test-/file/fs.c (get_fsname): try magic number only if
      f_type is included.  [ruby-dev:48913] [Bug #11000]

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ChangeLog
    branches/ruby_2_2/ext/-test-/file/extconf.rb
    branches/ruby_2_2/ext/-test-/file/fs.c
    branches/ruby_2_2/version.h
Index: ruby_2_2/ChangeLog
===================================================================
--- ruby_2_2/ChangeLog	(revision 50620)
+++ ruby_2_2/ChangeLog	(revision 50621)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1
+Sun May 24 02:06:34 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/-test-/file/fs.c (get_fsname): try magic number only if
+	  f_type is included.  [ruby-dev:48913] [Bug #11000]
+
+Sun May 24 02:06:34 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/-test-/file/fs.c (get_fsname): return filesystem name by
+	  statfs/statvfs.  [ruby-core:68624] [Bug #10998]
+
 Sun May 24 02:02:00 2015  Koichi Sasada  <ko1@a...>
 
 	* test/ruby/test_symbol.rb: fix syntax error.
Index: ruby_2_2/ext/-test-/file/extconf.rb
===================================================================
--- ruby_2_2/ext/-test-/file/extconf.rb	(revision 50620)
+++ ruby_2_2/ext/-test-/file/extconf.rb	(revision 50621)
@@ -1,4 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ext/-test-/file/extconf.rb#L1
 $INCFLAGS << " -I$(topdir) -I$(top_srcdir)"
+
+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)
+end
+
+headers = %w[sys/statvfs.h]
+if have_type("struct statvfs", headers)
+  have_struct_member("struct statvfs", "f_fstypename", headers)
+  have_struct_member("struct statvfs", "f_basetype", headers)
+  have_struct_member("struct statvfs", "f_type", headers)
+end
+
 $srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
 inits = $srcs.map {|s| File.basename(s, ".*")}
 inits.delete("init")
Index: ruby_2_2/ext/-test-/file/fs.c
===================================================================
--- ruby_2_2/ext/-test-/file/fs.c	(revision 50620)
+++ ruby_2_2/ext/-test-/file/fs.c	(revision 50621)
@@ -1,55 +1,69 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ext/-test-/file/fs.c#L1
 #include "ruby/ruby.h"
 #include "ruby/io.h"
 
-#ifdef __linux__
-# define HAVE_GETMNTENT
+#ifdef HAVE_SYS_MOUNT_H
+#include <sys/mount.h>
+#endif
+#ifdef HAVE_SYS_VFS_H
+#include <sys/vfs.h>
 #endif
 
-#ifdef HAVE_GETMNTENT
-# include <stdio.h>
-# include <mntent.h>
+#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
+# if defined HAVE_STRUCT_STATFS_F_TYPE
+#   define HAVE_STRUCT_STATFS_T_F_TYPE 1
+# endif
+#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
+# if defined HAVE_STRUCT_STATVFS_F_TYPE
+#   define HAVE_STRUCT_STATFS_T_F_TYPE 1
+# endif
+#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
+# if defined HAVE_STRUCT_STATVFS_F_TYPE
+#   define HAVE_STRUCT_STATFS_T_F_TYPE 1
+# endif
 #endif
 
 VALUE
 get_fsname(VALUE self, VALUE str)
 {
-#ifdef HAVE_GETMNTENT
-    const char *path;
-    struct mntent mntbuf;
-    static const int buflen = 4096;
-    char *buf = alloca(buflen);
-    int len = 0;
-    FILE *fp;
-#define FSNAME_LEN 100
-    char name[FSNAME_LEN] = "";
+#ifdef STATFS
+    statfs_t st;
+# define CSTR(s) rb_str_new_cstr(s)
 
     FilePathValue(str);
-    path = RSTRING_PTR(str);
-    fp = setmntent("/etc/mtab", "r");
-    if (!fp) rb_sys_fail("setmntent(/etb/mtab)");;
-
-    while (getmntent_r(fp, &mntbuf, buf, buflen)) {
-	int i;
-	char *mnt_dir = mntbuf.mnt_dir;
-	for (i=0; mnt_dir[i]; i++) {
-	    if (mnt_dir[i] != path[i]) {
-		goto next_entry;
-	    }
-	}
-	if (i >= len) {
-	    len = i;
-	    strlcpy(name, mntbuf.mnt_type, FSNAME_LEN);
-	}
-next_entry:
-	;
+    str = rb_str_encode_ospath(str);
+    if (STATFS(StringValueCStr(str), &st) == -1) {
+	rb_sys_fail_str(str);
     }
-    endmntent(fp);
-
-    if (!len) rb_sys_fail("no matching entry");;
-    return rb_str_new_cstr(name);
-#else
-    return Qnil;
+# ifdef HAVE_STRUCT_STATFS_T_F_FSTYPENAME
+    if (st.f_fstypename[0])
+	return CSTR(st.f_fstypename);
+# endif
+# ifdef HAVE_STRUCT_STATFS_T_F_TYPE
+    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");
+    }
+# endif
 #endif
+    return Qnil;
 }
 
 void
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 50620)
+++ ruby_2_2/version.h	(revision 50621)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #define RUBY_VERSION "2.2.3"
 #define RUBY_RELEASE_DATE "2015-05-24"
-#define RUBY_PATCHLEVEL 117
+#define RUBY_PATCHLEVEL 118
 
 #define RUBY_RELEASE_YEAR 2015
 #define RUBY_RELEASE_MONTH 5

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r50071,50088


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]