Sha256: f507af84d4425a9ad6a9ce9374cb670ee659c056e473398260df3a549b9e772f
Contents?: true
Size: 893 Bytes
Versions: 4
Compression:
Stored size: 893 Bytes
Contents
#include <ruby.h> #include <sys/vfs.h> static VALUE get_disk_usage(VALUE self, VALUE mount_point) { char* mount_point_str = RSTRING(mount_point)->ptr; VALUE out_hash = rb_hash_new(); rb_hash_aset(out_hash, rb_str_new2("free"), Qnil); rb_hash_aset(out_hash, rb_str_new2("total"), Qnil); struct statfs result; if(statfs(mount_point_str, &result) == 0) { rb_hash_aset(out_hash, rb_str_new2("free"), LL2NUM((long long)result.f_bfree * (long long)result.f_bsize)); rb_hash_aset(out_hash, rb_str_new2("total"), LL2NUM((long long)result.f_blocks * (long long)result.f_bsize)); } return out_hash; } void Init_disk_usage() { VALUE mDataProviders = rb_const_get(rb_cObject, rb_intern("DataProviders")); VALUE cDiskUsage = rb_const_get(mDataProviders, rb_intern("DiskUsage")); rb_define_method(cDiskUsage, "get_disk_usage", get_disk_usage, 1); }
Version data entries
4 entries across 4 versions & 1 rubygems