class Filesys::Stat

Objects of class Filesys::Stat encapsulate common status information for Filesys objects. The information is recorded at the moment the Filesys::Stat object is created; changes made to the file after that point will not be reflected.

Many of its attributes contain platform-specific values, and not all values are meaningful on all systems.

Public Class Methods

Filesys::Stat.new( dir_name) → stat click to toggle source

Create a Filesys::Stat object for the given file system.

VALUE
rb_fsstat_init( VALUE obj, VALUE dname)
{
    struct statfs st, *nst;

    SafeStringValue( dname);

    if (statfs( StringValueCStr( dname), &st) == -1)
        rb_sys_fail( RSTRING_PTR(dname));
    if (DATA_PTR(obj)) {
        free( DATA_PTR(obj));
        DATA_PTR(obj) = NULL;
    }
    nst = ALLOC(struct statfs);
    *nst = st;
    DATA_PTR(obj) = nst;

    return Qnil;
}

Public Instance Methods

avail → num click to toggle source

Free bytes avail to non-superuser.

VALUE
rb_fsstat_avail( VALUE self)
{
    struct statfs *s;

    s = get_statfs( self);
    return rb_funcall( INT2NUM(s->f_bavail), id_mul, 1, INT2NUM(s->f_bsize));
}
bavail → fixnum click to toggle source

Free blocks avail to non-superuser.

VALUE
rb_fsstat_bavail( VALUE self)
{
    return INT2NUM(get_statfs(self)->f_bavail);
}
blocks → fixnum click to toggle source

Total data blocks in filesystem.

VALUE
rb_fsstat_blocks( VALUE self)
{
    return INT2NUM(get_statfs(self)->f_blocks);
}
bytes → fixnum click to toggle source

Total data bytes in filesystem.

VALUE
rb_fsstat_bytes( VALUE self)
{
    struct statfs *s;

    s = get_statfs( self);
    return rb_funcall( INT2NUM(s->f_blocks), id_mul, 1, INT2NUM(s->f_bsize));
}
inspect → string click to toggle source

Produce a nicely formatted description of stat with all available information.

VALUE
rb_fsstat_inspect( VALUE self)
{
    VALUE str;
    int i, m;
    static const struct {
        const char  *name;
        VALUE      (*func)(VALUE);
    } member[] = {
        { "type",   &rb_fsstat_type  },
        { "bsize",  &rb_fsstat_bsize },
        { "blocks", &rb_fsstat_blocks},
        { "bfree",  &rb_fsstat_bfree },
        { "bavail", &rb_fsstat_bavail},
        { "files",  &rb_fsstat_files },
        { "ffree",  &rb_fsstat_ffree },
        { "fsid",   &rb_fsstat_fsid  }
    };

    str = rb_str_buf_new2("#<");
    rb_str_buf_cat2(str, rb_obj_classname( self));
    rb_str_buf_cat2(str, " ");

    m = sizeof(member) / sizeof(member[0]);
    for (i = 0; i < m; i++) {
        VALUE v;

        if (i > 0)
            rb_str_buf_cat2( str, ", ");
        rb_str_buf_cat2( str, member[i].name);
        rb_str_buf_cat2( str, "=");
        rb_str_append( str, rb_inspect( (*member[i].func)( self)));
    }
    rb_str_buf_cat2( str, ">");
    OBJ_INFECT( str, self);

    return str;
}
pavail → fixnum click to toggle source

Free percentage avail to non-superuser.

VALUE
rb_fsstat_pavail( VALUE self)
{
    struct statfs *s;

    s = get_statfs( self);
    return rb_float_new( 100.0 * s->f_bavail / s->f_blocks);
}