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

ruby-changes:33591

From: usa <ko1@a...>
Date: Wed, 23 Apr 2014 00:45:10 +0900 (JST)
Subject: [ruby-changes:33591] usa:r45672 (trunk): * win32/win32.c, include/ruby/win32.h (ustatfs): implementation of

usa	2014-04-23 00:45:00 +0900 (Wed, 23 Apr 2014)

  New Revision: 45672

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

  Log:
    * win32/win32.c, include/ruby/win32.h (ustatfs): implementation of
      statfs(2) clone. [EXPERIMENTAL]
    
    * file.c (rb_io_statfs): use above function.
    
    * configure.in, win32/Makefile.sub (struct statfs): available.

  Modified files:
    trunk/ChangeLog
    trunk/configure.in
    trunk/file.c
    trunk/include/ruby/win32.h
    trunk/win32/Makefile.sub
    trunk/win32/win32.c
Index: include/ruby/win32.h
===================================================================
--- include/ruby/win32.h	(revision 45671)
+++ include/ruby/win32.h	(revision 45672)
@@ -262,6 +262,20 @@ struct ifaddrs { https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L262
 #define IFF_POINTOPOINT IFF_POINTTOPOINT
 #endif
 
+/* for ustatfs() */
+typedef uint32_t fsid_t;
+struct statfs {
+    uint32_t f_type;
+    uint64_t f_bsize;
+    uint64_t f_blocks;
+    uint64_t f_bfree;
+    int64_t f_bavail;
+    uint64_t f_files;
+    uint64_t f_ffree;
+    fsid_t f_fsid;
+    char f_fstypename[MAX_PATH];
+};
+
 extern DWORD  rb_w32_osid(void);
 extern rb_pid_t  rb_w32_pipe_exec(const char *, const char *, int, int *, int *);
 extern int    flock(int fd, int oper);
@@ -347,6 +361,7 @@ extern int rb_w32_uaccess(const char *, https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L361
 extern char rb_w32_fd_is_text(int);
 extern int rb_w32_fstati64(int, struct stati64 *);
 extern int rb_w32_dup2(int, int);
+extern int ustatfs(const char *, struct statfs *);
 
 #ifdef __BORLANDC__
 extern off_t _lseeki64(int, off_t, int);
Index: configure.in
===================================================================
--- configure.in	(revision 45671)
+++ configure.in	(revision 45672)
@@ -1059,6 +1059,8 @@ main() https://github.com/ruby/ruby/blob/trunk/configure.in#L1059
                 ac_cv_func_clock_gettime=yes
                 ac_cv_func_clock_getres=yes
 		ac_cv_func_malloc_usable_size=no
+		ac_cv_struct_statfs=yes
+		ac_cv_member_struct_statfs_f_fstypename=yes
 		{ test "$target_cpu" = x64 && ac_cv_func___builtin_setjmp=no; }
 		AC_CHECK_TYPE([NET_LUID], [], [],
 			      [@%:@include <windows.h>
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45671)
+++ ChangeLog	(revision 45672)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Apr 23 00:43:00 2014  NAKAMURA Usaku  <usa@r...>
+
+	* win32/win32.c, include/ruby/win32.h (ustatfs): implementation of
+	  statfs(2) clone. [EXPERIMENTAL]
+
+	* file.c (rb_io_statfs): use above function.
+
+	* configure.in, win32/Makefile.sub (struct statfs): available.
+
 Tue Apr 22 23:56:24 2014  NAKAMURA Usaku  <usa@r...>
 
 	* file.c (rb_io_stafs): use statfs(2) if fstatfs(2) is unavailable.
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 45671)
+++ win32/win32.c	(revision 45672)
@@ -5865,6 +5865,54 @@ rb_w32_pipe(int fds[2]) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5865
 }
 
 /* License: Ruby's */
+int
+ustatfs(const char *path, struct statfs *buf)
+{
+    WCHAR *wpath = utf8_to_wstr(path, NULL);
+    WCHAR root[MAX_PATH], system[8];
+    DWORD serial, spc, bps, unused, total;
+    char *tmp;
+
+    if (!wpath) {
+	return -1;
+    }
+
+    if (!GetVolumePathNameW(wpath, root, sizeof(root) / sizeof(WCHAR))) {
+	free(wpath);
+	errno = map_errno(GetLastError());
+	return -1;
+    }
+    free(wpath);
+
+    if (!GetVolumeInformationW(root, NULL, 0, &serial, NULL, NULL,
+			       system, sizeof(system) / sizeof(WCHAR))) {
+	errno = map_errno(GetLastError());
+	return -1;
+    }
+
+    if (!GetDiskFreeSpaceW(root, &spc, &bps, &unused, &total)) {
+	errno = map_errno(GetLastError());
+	return -1;
+    }
+
+    tmp = wstr_to_filecp(system, NULL);
+    if (!tmp) {
+	return -1;
+    }
+    strlcpy(buf->f_fstypename, tmp, sizeof(buf->f_fstypename));
+    free(tmp);
+
+    buf->f_type = 0;
+    buf->f_bsize = (uint64_t)spc * bps;
+    buf->f_blocks = total;
+    buf->f_bfree = buf->f_bavail = unused;
+    buf->f_files = buf->f_ffree = 0;
+    buf->f_fsid = serial;
+
+    return 0;
+}
+
+/* License: Ruby's */
 static int
 console_emulator_p(void)
 {
Index: win32/Makefile.sub
===================================================================
--- win32/Makefile.sub	(revision 45671)
+++ win32/Makefile.sub	(revision 45672)
@@ -699,6 +699,8 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/ https://github.com/ruby/ruby/blob/trunk/win32/Makefile.sub#L699
 #define SETPGRP_VOID 1
 #define RSHIFT(x,y) ((x)>>(int)y)
 #define HAVE_RB_FD_INIT 1
+#define HAVE_STRUCT_STATFS 1
+#define HAVE_STRUCT_STATFS_F_FSTYPENAME 1
 #define RUBY_SETJMP(env) _setjmp(env)
 #define RUBY_LONGJMP(env,val) longjmp(env,val)
 #define RUBY_JMP_BUF jmp_buf
Index: file.c
===================================================================
--- file.c	(revision 45671)
+++ file.c	(revision 45672)
@@ -115,6 +115,8 @@ static VALUE rb_statfs_new(const struct https://github.com/ruby/ruby/blob/trunk/file.c#L115
 #define unlink(p)	rb_w32_uunlink(p)
 #undef rename
 #define rename(f, t)	rb_w32_urename((f), (t))
+#undef statfs
+#define statfs(f, s)	ustatfs((f), (s))
 #else
 #define STAT(p, s)	stat((p), (s))
 #endif
@@ -1118,12 +1120,16 @@ rb_io_statfs(VALUE obj) https://github.com/ruby/ruby/blob/trunk/file.c#L1120
 {
     rb_io_t *fptr;
     struct statfs st;
+#ifndef HAVE_FSTATFS
+    VALUE path;
+#endif
 
     GetOpenFile(obj, fptr);
 #ifdef HAVE_FSTATFS
     if (fstatfs(fptr->fd, &st) == -1)
 #else
-    if (statfs(RSTRING_PTR(fptr->pathv), &st) == -1)
+    path = rb_str_encode_ospath(fptr->pathv);
+    if (statfs(StringValueCStr(path), &st) == -1)
 #endif
     {
 	rb_sys_fail_path(fptr->pathv);

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

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