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

ruby-changes:38789

From: naruse <ko1@a...>
Date: Sat, 13 Jun 2015 20:46:50 +0900 (JST)
Subject: [ruby-changes:38789] naruse:r50870 (trunk): * file.c (rb_stat_ino): get inode from the interval of struct st.

naruse	2015-06-13 20:46:38 +0900 (Sat, 13 Jun 2015)

  New Revision: 50870

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

  Log:
    * file.c (rb_stat_ino): get inode from the interval of struct st.
    
    * win32/win32.c (stati64_set_inode): get nFilIndexHigh/Low, and set it
      to the interval of struct st as inode.
    
    * win32/win32.c (stati64_set_inode_handle): call stati64_set_inode.
    
    * win32/win32.c (rb_w32_fstati64): call stati64_set_inode_handle.
    
    * win32/win32.c (stati64_handle): call stati64_set_inode.

  Modified files:
    trunk/ChangeLog
    trunk/file.c
    trunk/test/ruby/test_file.rb
    trunk/win32/win32.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50869)
+++ ChangeLog	(revision 50870)
@@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun 13 20:28:14 2015  NARUSE, Yui  <naruse@r...>
+
+	* file.c (rb_stat_ino): get inode from the interval of struct st.
+
+	* win32/win32.c (stati64_set_inode): get nFilIndexHigh/Low, and set it
+	  to the interval of struct st as inode.
+
+	* win32/win32.c (stati64_set_inode_handle): call stati64_set_inode.
+
+	* win32/win32.c (rb_w32_fstati64): call stati64_set_inode_handle.
+
+	* win32/win32.c (stati64_handle): call stati64_set_inode.
+
 Sat Jun 13 19:44:53 2015  NAKAMURA Usaku  <usa@r...>
 
 	* ext/io/console/depend (.list.chksum): revert a part of r50859, because
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 50869)
+++ win32/win32.c	(revision 50870)
@@ -4975,6 +4975,48 @@ static time_t filetime_to_unixtime(const https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4975
 static WCHAR *name_for_stat(WCHAR *buf, const WCHAR *path);
 static DWORD stati64_handle(HANDLE h, struct stati64 *st);
 
+/* License: Ruby's */
+static void
+stati64_set_inode(PBY_HANDLE_FILE_INFORMATION pinfo, struct stati64 *st)
+{
+    /* struct stati64 layout
+     *
+     * dev: 0-3
+     * ino: 4-5
+     * mode: 6-7
+     * nlink: 8-9
+     * uid: 10-11
+     * gid: 12-13
+     * _: 14-15
+     * rdev: 16-19
+     * _: 20-23
+     * size: 24-31
+     * atime: 32-39
+     * mtime: 40-47
+     * ctime: 48-55
+     *
+     */
+    unsigned short *p2 = (unsigned short *)st;
+    unsigned int *p4 = (unsigned int *)st;
+    DWORD high = pinfo->nFileIndexHigh;
+    p2[2] = high >> 16;
+    p2[7] = high & 0xFFFF;
+    p4[5] = pinfo->nFileIndexLow;
+}
+
+/* License: Ruby's */
+static DWORD
+stati64_set_inode_handle(HANDLE h, struct stati64 *st)
+{
+    BY_HANDLE_FILE_INFORMATION info;
+    DWORD attr = (DWORD)-1;
+
+    if (GetFileInformationByHandle(h, &info)) {
+	stati64_set_inode(&info, st);
+    }
+    return attr;
+}
+
 #undef fstat
 /* License: Ruby's */
 int
@@ -5000,7 +5042,11 @@ rb_w32_fstati64(int fd, struct stati64 * https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5042
     struct stat tmp;
     int ret;
 
-    if (GetEnvironmentVariableW(L"TZ", NULL, 0) == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND) return _fstati64(fd, st);
+    if (GetEnvironmentVariableW(L"TZ", NULL, 0) == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
+	ret = _fstati64(fd, st);
+	stati64_set_inode_handle((HANDLE)_get_osfhandle(fd), st);
+	return ret;
+    }
     ret = fstat(fd, &tmp);
 
     if (ret) return ret;
@@ -5023,6 +5069,7 @@ stati64_handle(HANDLE h, struct stati64 https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5069
 	st->st_ctime = filetime_to_unixtime(&info.ftCreationTime);
 	st->st_nlink = info.nNumberOfLinks;
 	attr = info.dwFileAttributes;
+	stati64_set_inode(&info, st);
     }
     return attr;
 }
Index: test/ruby/test_file.rb
===================================================================
--- test/ruby/test_file.rb	(revision 50869)
+++ test/ruby/test_file.rb	(revision 50870)
@@ -342,6 +342,10 @@ class TestFile < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file.rb#L342
   rescue NotImplementedError
   end
 
+  def test_stat_inode
+    assert_not_equal 0, File.stat(__FILE__).ino
+  end
+
   def test_chmod_m17n
     bug5671 = '[ruby-dev:44898]'
     Dir.mktmpdir('test-file-chmod-m17n-') do |tmpdir|
Index: file.c
===================================================================
--- file.c	(revision 50869)
+++ file.c	(revision 50870)
@@ -548,7 +548,18 @@ rb_stat_dev_minor(VALUE self) https://github.com/ruby/ruby/blob/trunk/file.c#L548
 static VALUE
 rb_stat_ino(VALUE self)
 {
-#if SIZEOF_STRUCT_STAT_ST_INO > SIZEOF_LONG
+#ifdef _WIN32
+    struct stat *st = get_stat(self);
+    unsigned short *p2 = (unsigned short *)st;
+    unsigned int *p4 = (unsigned int *)st;
+    uint64_t r;
+    r = p2[2];
+    r <<= 16;
+    r |= p2[7];
+    r <<= 32;
+    r |= p4[5];
+    return ULL2NUM(r);
+#elif SIZEOF_STRUCT_STAT_ST_INO > SIZEOF_LONG
     return ULL2NUM(get_stat(self)->st_ino);
 #else
     return ULONG2NUM(get_stat(self)->st_ino);

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

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