1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

revert File::Statfs [Feature #9772]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2014-05-22 10:39:48 +00:00
parent fa244db49b
commit 210f863906
9 changed files with 20 additions and 544 deletions

View file

@ -1,3 +1,7 @@
Thu May 22 19:38:14 2014 NARUSE, Yui <naruse@ruby-lang.org>
* file.c: remove IO::Statfs because of reject. [Feature #9772]
Thu May 22 14:02:13 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* enc/jis/props.kwd: constify character property tables of JIS

7
NEWS
View file

@ -22,18 +22,11 @@ with all sufficient information, see the ChangeLog file.
* min, min_by, max and max_by supports optional argument to return
multiple elements.
* File
* new class File::Statfs to hold filesystem information. (experimental)
* Float
* New methods:
* Float#next_float
* Float#prev_float
* IO
* New methods
* IO#statfs returns filesystem information as File::Statfs. (experimental)
* Process
* Extended method:
* Process execution methods such as Process.spawn opens the file in write

View file

@ -1068,8 +1068,6 @@ main()
ac_cv_func_clock_gettime=yes
ac_cv_func_clock_getres=yes
ac_cv_func_malloc_usable_size=no
ac_cv_type_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>
@ -1093,7 +1091,6 @@ main()
ac_cv_func_close=no
],
[netbsd*], [ LIBS="-lm $LIBS"
ac_cv_func_fstatfs=no
],
[dragonfly*], [ LIBS="-lm $LIBS"
# isinf() and isnan() are macros on DragonFly.
@ -1133,8 +1130,6 @@ AC_CHECK_HEADERS( \
sys/select.h \
sys/time.h \
sys/times.h \
sys/param.h \
sys/vfs.h \
syscall.h \
pwd.h \
grp.h \
@ -1163,9 +1158,6 @@ AC_CHECK_HEADERS( \
malloc/malloc.h \
setjmpex.h
)
AC_CHECK_HEADERS(sys/mount.h, [], [], [@%:@ifdef HAVE_SYS_PARAM_H
@%:@ include <sys/param.h>
@%:@endif])
AC_ARG_WITH([gmp],
[AS_HELP_STRING([--without-gmp],
@ -1743,33 +1735,6 @@ AC_CHECK_TYPES([struct timezone], [], [], [@%:@ifdef HAVE_TIME_H
@%:@ include <sys/time.h>
@%:@endif])
AC_CHECK_TYPES([struct statfs], [], [], [@%:@ifdef HAVE_SYS_PARAM_H
@%:@ include <sys/param.h>
@%:@endif
@%:@ifdef HAVE_SYS_MOUNT_H
@%:@ include <sys/mount.h>
@%:@endif
@%:@ifdef HAVE_SYS_VFS_H
@%:@ include <sys/vfs.h>
@%:@endif])
AS_IF([test "$ac_cv_type_struct_statfs" = yes], [
AC_CHECK_MEMBERS([struct statfs.f_type, struct statfs.f_fstypename], [], [], [@%:@ifdef HAVE_SYS_PARAM_H
@%:@ include <sys/param.h>
@%:@endif
@%:@ifdef HAVE_SYS_MOUNT_H
@%:@ include <sys/mount.h>
@%:@endif
@%:@ifdef HAVE_SYS_VFS_H
@%:@ include <sys/vfs.h>
@%:@endif])
])
# AIX, HP-UX, NetBSD, Solaris
AC_CHECK_TYPES([struct statvfs], [], [], [@%:@ include <sys/statvfs.h>])
# NetBSD
AC_CHECK_MEMBERS([struct statvfs.f_fstypename], [], [], [@%:@ include <sys/statvfs.h>])
# AIX, HP-UX, Solaris
AC_CHECK_MEMBERS([struct statvfs.f_basetype], [], [], [@%:@ include <sys/statvfs.h>])
AC_CHECK_TYPES([clockid_t], [], [], [@%:@ifdef HAVE_TIME_H
@%:@ include <time.h>
@%:@endif
@ -1995,8 +1960,6 @@ AC_CHECK_FUNCS(fcntl)
AC_CHECK_FUNCS(fdatasync)
AC_CHECK_FUNCS(fmod)
AC_CHECK_FUNCS(fork)
AC_CHECK_FUNCS(fstatfs)
AC_CHECK_FUNCS(fstatvfs)
AC_CHECK_FUNCS(fsync)
AC_CHECK_FUNCS(ftruncate)
AC_CHECK_FUNCS(ftruncate64) # used for Win32 platform

385
file.c
View file

@ -63,46 +63,6 @@ int flock(int, int);
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h>
#endif
#ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h>
#endif
#ifdef HAVE_STRUCT_STATFS
typedef struct statfs statfs_t;
# define STATFS(f, s) statfs((f), (s))
# ifdef HAVE_FSTATFS
# define FSTATFS(f, s) fstatfs((f), (s))
# endif
# ifdef HAVE_STRUCT_STATFS_F_FSTYPENAME
# define HAVE_STRUCT_STATFS_T_F_FSTYPENAME 1
# endif
# ifdef HAVE_STRUCT_STATFS_F_TYPE
# define HAVE_STRUCT_STATFS_T_F_TYPE 1
# endif
#elif defined(HAVE_STRUCT_STATVFS)
typedef struct statvfs statfs_t;
# define STATFS(f, s) statvfs((f), (s))
# ifdef HAVE_FSTATVFS
# define FSTATFS(f, s) fstatvfs((f), (s))
# endif
# if defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME) /* NetBSD */
# define HAVE_STRUCT_STATFS_T_F_FSTYPENAME 1
# elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE) /* AIX, HP-UX, Solaris */
# define HAVE_STRUCT_STATFS_T_F_FSTYPENAME 1
# define f_fstypename f_basetype
# endif
# ifdef HAVE_STRUCT_STATVFS_F_TYPE
# define HAVE_STRUCT_STATFS_T_F_TYPE 1
# endif
#else
# define WITHOUT_STATFS
#endif
#ifndef WITHOUT_STATFS
static VALUE rb_statfs_new(const statfs_t *st);
#endif
#if defined(__native_client__) && defined(NACL_NEWLIB)
# include "nacl/utime.h"
# include "nacl/stat.h"
@ -145,9 +105,6 @@ static VALUE rb_statfs_new(const statfs_t *st);
#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))
#define HAVE_STATFS 1
#else
#define STAT(p, s) stat((p), (s))
#endif
@ -182,7 +139,6 @@ be_fchown(int fd, uid_t owner, gid_t group)
VALUE rb_cFile;
VALUE rb_mFileTest;
VALUE rb_cStat;
VALUE rb_cStatfs;
#define insecure_obj_p(obj, level) ((level) >= 4 || ((level) > 0 && OBJ_TAINTED(obj)))
@ -1130,48 +1086,6 @@ rb_file_lstat(VALUE obj)
#endif
}
#ifndef WITHOUT_STATFS
/*
* call-seq:
* ios.statfs -> statfs
*
* Returns filesystem status information for <em>ios</em> as an object of type
* <code>File::Statfs</code>.
*
* f = File.new("testfile")
* s = f.statfs
* s.mode #=> "100644"
* s.bsize #=> 512
* s.fstypename #=> "zfs"
*
*/
static VALUE
rb_io_statfs(VALUE obj)
{
rb_io_t *fptr;
statfs_t st;
#ifndef FSTATFS
VALUE path;
#endif
int ret;
GetOpenFile(obj, fptr);
#ifdef FSTATFS
ret = FSTATFS(fptr->fd, &st);
#else
path = rb_str_encode_ospath(fptr->pathv);
ret = STATFS(StringValueCStr(path), &st);
#endif
if (ret == -1) {
rb_sys_fail_path(fptr->pathv);
}
return rb_statfs_new(&st);
}
#else
#define rb_io_statfs rb_f_notimplement
#endif
static int
rb_group_member(GETGROUPS_T gid)
{
@ -5348,288 +5262,6 @@ rb_stat_sticky(VALUE obj)
return Qfalse;
}
#ifndef WITHOUT_STATFS
/* File::Statfs */
static size_t
statfs_memsize(const void *p)
{
return p ? sizeof(statfs_t) : 0;
}
static const rb_data_type_t statfs_data_type = {
"statfs",
{NULL, RUBY_TYPED_DEFAULT_FREE, statfs_memsize,},
NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
};
static VALUE
statfs_new_0(VALUE klass, const statfs_t *st)
{
statfs_t *nst = 0;
if (st) {
nst = ALLOC(statfs_t);
*nst = *st;
}
return TypedData_Wrap_Struct(klass, &statfs_data_type, nst);
}
static VALUE
rb_statfs_new(const statfs_t *st)
{
return statfs_new_0(rb_cStatfs, st);
}
static statfs_t*
get_statfs(VALUE self)
{
statfs_t* st;
TypedData_Get_Struct(self, statfs_t, &statfs_data_type, st);
if (!st) rb_raise(rb_eTypeError, "uninitialized File::Statfs");
return st;
}
/*
* Document-class: File::Statfs
*
* Objects of class <code>File::Statfs</code> encapsulate common status
* information for filesystem. The information is
* recorded at the moment the <code>File::Statfs</code> object is
* created; changes made to the filesystem after that point will not be
* reflected. <code>File::Statfs</code> objects are returned by
* <code>IO#statfs</code>.
*/
static VALUE
rb_statfs_s_alloc(VALUE klass)
{
return statfs_new_0(klass, 0);
}
/*
* call-seq:
*
* File::Statfs.new(file_name) -> statfs
*
* Create a File::Statfs object for the given file name (raising an
* exception if the file doesn't exist).
*/
static VALUE
rb_statfs_init(VALUE obj, VALUE fname)
{
statfs_t st, *nst;
rb_secure(2);
FilePathValue(fname);
fname = rb_str_encode_ospath(fname);
if (STATFS(StringValueCStr(fname), &st) == -1) {
rb_sys_fail_path(fname);
}
if (DATA_PTR(obj)) {
xfree(DATA_PTR(obj));
DATA_PTR(obj) = NULL;
}
nst = ALLOC(statfs_t);
*nst = st;
DATA_PTR(obj) = nst;
return Qnil;
}
/* :nodoc: */
static VALUE
rb_statfs_init_copy(VALUE copy, VALUE orig)
{
statfs_t *nst;
if (!OBJ_INIT_COPY(copy, orig)) return copy;
if (DATA_PTR(copy)) {
xfree(DATA_PTR(copy));
DATA_PTR(copy) = 0;
}
if (DATA_PTR(orig)) {
nst = ALLOC(statfs_t);
*nst = *(statfs_t*)DATA_PTR(orig);
DATA_PTR(copy) = nst;
}
return copy;
}
#ifdef HAVE_STRUCT_STATFS_T_F_TYPE
/*
* call-seq:
* st.type -> fixnum
*
* Returns type of filesystem.
*
* f = File.new("testfile")
* s = f.statfs
* "%d" % s.type #=> 17
*
*/
static VALUE
statfs_type(VALUE self)
{
return LL2NUM(get_statfs(self)->f_type);
}
#else
#define statfs_type rb_f_notimplement
#endif
/*
* call-seq:
* st.bsize -> integer
*
* Returns block size in filesystem.
*
*/
static VALUE
statfs_bsize(VALUE self)
{
return LL2NUM(get_statfs(self)->f_bsize);
}
/*
* call-seq:
* st.blocks -> integer
*
* Returns total data bocks of filesystem.
*
*/
static VALUE
statfs_blocks(VALUE self)
{
return LL2NUM(get_statfs(self)->f_blocks);
}
/*
* call-seq:
* st.bfree -> integer
*
* Returns free blocks in filesystem.
*
*/
static VALUE
statfs_bfree(VALUE self)
{
return LL2NUM(get_statfs(self)->f_bfree);
}
/*
* call-seq:
* st.bavail -> integer
*
* Returns available blocks to non-super user in filesystem.
*
*/
static VALUE
statfs_bavail(VALUE self)
{
return LL2NUM(get_statfs(self)->f_bavail);
}
/*
* call-seq:
* st.files -> integer
*
* Returns total file nodes in filesystem.
*
*/
static VALUE
statfs_files(VALUE self)
{
return LL2NUM(get_statfs(self)->f_files);
}
/*
* call-seq:
* st.ffree -> integer
*
* Returns free nodes in filesystem.
*
*/
static VALUE
statfs_ffree(VALUE self)
{
return LL2NUM(get_statfs(self)->f_ffree);
}
#ifdef HAVE_STRUCT_STATFS_T_F_FSTYPENAME
/*
* call-seq:
* st.fstypename -> string
*
* Returns name of filesystem.
*
* f = File.new("testfile")
* s = f.statfs
* s.fstypename #=> "zfs"
*
*/
static VALUE
statfs_fstypename(VALUE self)
{
return rb_str_new_cstr(get_statfs(self)->f_fstypename);
}
#else
#define statfs_fstypename rb_f_notimplement
#endif
/*
* call-seq:
* st.inspect -> string
*
* Returns total file nodes in filesystem.
*
* f = File.new("testfile")
* s = f.statfs
* s.inspect #=> ""
* #=> "#<File::Statfs type=zfs, bsize=4096, blocks=900000/1000000/2000000, files=100000/200000>
*
* +blocks+ are numbers of available/free/total blocks.
* +files+ are numbers of free/total files.
*/
static VALUE
statfs_inspect(VALUE self)
{
statfs_t *st = get_statfs(self);
return rb_sprintf("#<%"PRIsVALUE" "
#ifdef HAVE_STRUCT_STATFS_T_F_TYPE
"type=%ld"
#endif
#ifdef HAVE_STRUCT_STATFS_T_F_FSTYPENAME
"(%s)"
#endif
", bsize=%ld"
", blocks=%"PRI_LL_PREFIX"d/%"PRI_LL_PREFIX"d/%"PRI_LL_PREFIX"d"
", files=%"PRI_LL_PREFIX"d/%"PRI_LL_PREFIX"d"
">",
rb_obj_class(self),
#ifdef HAVE_STRUCT_STATFS_T_F_TYPE
(long)st->f_type,
#endif
#ifdef HAVE_STRUCT_STATFS_T_F_FSTYPENAME
st->f_fstypename,
#endif
(long)st->f_bsize,
(LONG_LONG)st->f_bavail, (LONG_LONG)st->f_bfree, (LONG_LONG)st->f_blocks,
(LONG_LONG)st->f_ffree, (LONG_LONG)st->f_files);
}
#endif
VALUE rb_mFConst;
void
@ -6056,7 +5688,6 @@ Init_File(void)
rb_define_const(rb_cFile, "PATH_SEPARATOR", rb_obj_freeze(rb_str_new2(PATH_SEP)));
rb_define_method(rb_cIO, "stat", rb_io_stat, 0); /* this is IO's method */
rb_define_method(rb_cIO, "statfs", rb_io_statfs, 0); /* this is IO's method */
rb_define_method(rb_cFile, "lstat", rb_file_lstat, 0);
rb_define_method(rb_cFile, "atime", rb_file_atime, 0);
@ -6213,20 +5844,4 @@ Init_File(void)
rb_define_method(rb_cStat, "setuid?", rb_stat_suid, 0);
rb_define_method(rb_cStat, "setgid?", rb_stat_sgid, 0);
rb_define_method(rb_cStat, "sticky?", rb_stat_sticky, 0);
#ifndef WITHOUT_STATFS
rb_cStatfs = rb_define_class_under(rb_cFile, "Statfs", rb_cObject);
rb_define_alloc_func(rb_cStatfs, rb_statfs_s_alloc);
rb_define_method(rb_cStatfs, "initialize", rb_statfs_init, 1);
rb_define_method(rb_cStatfs, "initialize_copy", rb_statfs_init_copy, 1);
rb_define_method(rb_cStatfs, "type", statfs_type, 0);
rb_define_method(rb_cStatfs, "bsize", statfs_bsize, 0);
rb_define_method(rb_cStatfs, "blocks", statfs_blocks, 0);
rb_define_method(rb_cStatfs, "bfree", statfs_bfree, 0);
rb_define_method(rb_cStatfs, "bavail", statfs_bavail, 0);
rb_define_method(rb_cStatfs, "files", statfs_files, 0);
rb_define_method(rb_cStatfs, "ffree", statfs_ffree, 0);
rb_define_method(rb_cStatfs, "fstypename", statfs_fstypename, 0);
rb_define_method(rb_cStatfs, "inspect", statfs_inspect, 0);
#endif
}

View file

@ -262,20 +262,6 @@ struct ifaddrs {
#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);
@ -361,7 +347,6 @@ extern int rb_w32_uaccess(const char *, int);
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);

View file

@ -383,31 +383,4 @@ class TestFile < Test::Unit::TestCase
assert_file.not_exist?(path)
end
end
def test_statfs
skip "not implemented" unless $stdout.respond_to?(:statfs)
open(__FILE__) do |f|
st = f.statfs
assert_kind_of File::Statfs, st
begin
assert_kind_of Integer, st.type
rescue NotImplementedError
end
assert_kind_of Integer, st.bsize
assert_kind_of Integer, st.blocks
assert_kind_of Integer, st.bfree
assert_kind_of Integer, st.bavail
assert_kind_of Integer, st.files
assert_kind_of Integer, st.ffree
begin
assert_kind_of String, st.fstypename
rescue NotImplementedError
end
s = st.inspect
assert_match(/\A\#<File::Statfs\b.*>\z/, s)
assert_match(/\bbsize=\d+\b/, s)
assert_match(/\bblocks=(?:\d+[,>\/])+\b/, s)
assert_match(/\bfiles=(?:\d+[,>\/])+\b/, s)
end
end
end

View file

@ -1668,24 +1668,22 @@ class TestIO < Test::Unit::TestCase
def can_seek_data(f)
if /linux/ =~ RUBY_PLATFORM
# include/uapi/linux/magic.h
case f.statfs.type
when 0x9123683E # BTRFS_SUPER_MAGIC
when 0x7461636f # OCFS2_SUPER_MAGIC
when 0xEF53 # EXT2_SUPER_MAGIC EXT3_SUPER_MAGIC EXT4_SUPER_MAGIC
return false if (Etc.uname[:release].split('.').map(&:to_i) <=> [3,8]) < 0
# ext3's timestamp resolution is seconds
s = f.stat
s.mtime.nsec != 0 || s.atime.nsec != 0 || s.ctime.nsec != 0
when 0x58465342 # XFS_SUPER_MAGIC
return false if (Etc.uname[:release].split('.').map(&:to_i) <=> [3,5]) < 0
when 0x01021994 # TMPFS_MAGIC
return false if (Etc.uname[:release].split('.').map(&:to_i) <=> [3,8]) < 0
else
return false
require "-test-/file"
# lseek(2)
case Bug::File::Fs.fsname(f.path)
when "btrfs"
return true if (Etc.uname[:release].split('.').map(&:to_i) <=> [3,1]) >= 0
when "ocfs"
return true if (Etc.uname[:release].split('.').map(&:to_i) <=> [3,2]) >= 0
when "xfs"
return true if (Etc.uname[:release].split('.').map(&:to_i) <=> [3,5]) >= 0
when "ext4"
return true if (Etc.uname[:release].split('.').map(&:to_i) <=> [3,8]) >= 0
when "tmpfs"
return true if (Etc.uname[:release].split('.').map(&:to_i) <=> [3,8]) >= 0
end
end
true
false
end
def test_seek
@ -1715,9 +1713,7 @@ class TestIO < Test::Unit::TestCase
open(t.path) { |f|
break unless can_seek_data(f)
assert_equal("foo\n", f.gets)
assert_nothing_raised(proc {"cannot SEEK_DATA on FS(0x%X)" % f.statfs.type}) do
f.seek(0, IO::SEEK_DATA)
end
f.seek(0, IO::SEEK_DATA)
assert_equal("foo\nbar\nbaz\n", f.read)
}
open(t.path, 'r+') { |f|
@ -1765,9 +1761,7 @@ class TestIO < Test::Unit::TestCase
open(t.path) { |f|
break unless can_seek_data(f)
assert_equal("foo\n", f.gets)
assert_nothing_raised(proc {"cannot SEEK_DATA on FS(0x%X)" % f.statfs.type}) do
f.seek(0, :DATA)
end
f.seek(0, :DATA)
assert_equal("foo\nbar\nbaz\n", f.read)
}
open(t.path, 'r+') { |f|

View file

@ -700,8 +700,6 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#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

View file

@ -5864,55 +5864,6 @@ rb_w32_pipe(int fds[2])
return 0;
}
/* 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;
WINBASEAPI BOOL WINAPI GetVolumePathNameW(LPCWSTR, LPWSTR, DWORD);
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)