Skip to content

Commit b8d95a1

Browse files
author
Vincent Landgraf
committed
#10 use statvfs for solaris/smartos/illumos...
1 parent 04d1580 commit b8d95a1

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

ext/vmstat/extconf.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
have_header 'sys/param.h'
3131
have_header 'sys/mount.h'
3232
have_header 'sys/statfs.h'
33-
have_func 'statfs'
34-
have_struct_member('struct statfs', 'f_type', ['sys/param.h', 'sys/mount.h', 'sys/statfs.h'])
35-
have_struct_member('struct statfs', 'f_fstypename', ['sys/param.h', 'sys/mount.h'])
33+
if have_func 'statfs'
34+
have_struct_member('struct statfs', 'f_type', ['sys/param.h', 'sys/mount.h', 'sys/statfs.h'])
35+
have_struct_member('struct statfs', 'f_fstypename', ['sys/param.h', 'sys/mount.h'])
36+
elsif have_func 'statvfs'
37+
have_struct_member('struct statvfs', 'f_basetype', ['sys/types.h', 'sys/statvfs.h'])
38+
end
3639

3740
# sysctl.h
3841
sys_headers = ['unistd.h', 'sys/sysctl.h', 'sys/types.h', 'sys/socket.h',

ext/vmstat/hw/statfs.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,29 @@ VALUE vmstat_disk(VALUE self, VALUE path) {
3939
}
4040
#endif
4141
#endif
42+
43+
#if defined(HAVE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
44+
#include <vmstat.h>
45+
#include <sys/types.h>
46+
#include <sys/statvfs.h>
47+
48+
#ifndef VMSTAT_DISK
49+
#define VMSTAT_DISK
50+
VALUE vmstat_disk(VALUE self, VALUE path) {
51+
VALUE disk = Qnil;
52+
struct statvfs stat;
53+
54+
if (statvfs(StringValueCStr(path), &stat) == 0) {
55+
disk = rb_funcall(rb_path2class("Vmstat::LinuxDisk"),
56+
rb_intern("new"), 6, ID2SYM(rb_intern(stat.f_basetype)),
57+
path,
58+
ULL2NUM(stat.f_bsize),
59+
ULL2NUM(stat.f_bfree),
60+
ULL2NUM(stat.f_bavail),
61+
ULL2NUM(stat.f_blocks));
62+
}
63+
64+
return disk;
65+
}
66+
#endif
67+
#endif

0 commit comments

Comments
 (0)