In Files

  • file.c

Class/Module Index [+]

Quicksearch
toggle debugging

File::Statfs

Objects of class File::Statfs encapsulate common status information for filesystem. The information is recorded at the moment the File::Statfs object is created; changes made to the filesystem after that point will not be reflected. File::Statfs objects are returned by IO#statfs.

Public Class Methods

File::Statfs.new(file_name) → statfs click to toggle source

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;
}
            

Public Instance Methods

bavail → integer click to toggle source

Returns available blocks to non-super user in filesystem.

 
               static VALUE
statfs_bavail(VALUE self)
{
    return LL2NUM(get_statfs(self)->f_bavail);
}
            
bfree → integer click to toggle source

Returns free blocks in filesystem.

 
               static VALUE
statfs_bfree(VALUE self)
{
    return LL2NUM(get_statfs(self)->f_bfree);
}
            
blocks → integer click to toggle source

Returns total data bocks of filesystem.

 
               static VALUE
statfs_blocks(VALUE self)
{
    return LL2NUM(get_statfs(self)->f_blocks);
}
            
bsize → integer click to toggle source

Returns block size in filesystem.

 
               static VALUE
statfs_bsize(VALUE self)
{
    return LL2NUM(get_statfs(self)->f_bsize);
}
            
ffree → integer click to toggle source

Returns free nodes in filesystem.

 
               static VALUE
statfs_ffree(VALUE self)
{
    return LL2NUM(get_statfs(self)->f_ffree);
}
            
files → integer click to toggle source

Returns total file nodes in filesystem.

 
               static VALUE
statfs_files(VALUE self)
{
    return LL2NUM(get_statfs(self)->f_files);
}
            
fstypename → string click to toggle source

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);
}
            
inspect → string click to toggle source

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);
}
            
type → fixnum click to toggle source

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);
}
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus