class Sys::Filesystem::Stat

Stat objects are returned by the Sys::Filesystem.stat method.

Constants

NOSUID

Filesystem does not support suid or sgid semantics.

NOTRUNC

Filesystem does not truncate file names longer than name_max.

RDONLY

Read-only filesystem

Attributes

base_type[RW]

The filesystem type, e.g. UFS.

block_size[RW]

The preferred system block size.

blocks[RW]

The total number of fragment_size blocks in the filesystem.

blocks_available[RW]

The number of free blocks available to unprivileged processes.

blocks_free[RW]

The total number of free blocks in the filesystem.

files[RW]

The total number of files/inodes that can be created.

files_available[RW]

The number of free files/inodes available to unprivileged processes.

files_free[RW]

The total number of files/inodes on the filesystem.

filesystem_id[RW]

The filesystem identifier.

flags[RW]

A bit mask of flags.

fragment_size[RW]

The fragment size, i.e. fundamental filesystem block size.

inodes[RW]

The total number of files/inodes that can be created.

inodes_available[RW]

The number of free files/inodes available to unprivileged processes.

inodes_free[RW]

The total number of files/inodes on the filesystem.

name_max[RW]

The maximum length of a file name permitted on the filesystem.

path[RW]

The path of the filesystem.

Public Class Methods

new() click to toggle source

Creates a new Sys::Filesystem::Stat object. This is meant for internal use only. Do not instantiate directly.

# File lib/sys/unix/sys/filesystem.rb, line 113
def initialize
  @path             = nil
  @block_size       = nil
  @fragment_size    = nil
  @blocks           = nil
  @blocks_free      = nil
  @blocks_available = nil
  @files            = nil
  @files_free       = nil
  @files_available  = nil
  @filesystem_id    = nil
  @flags            = nil
  @name_max         = nil
  @base_type        = nil
end

Public Instance Methods

bytes_available() click to toggle source

Returns the amount of free space available to unprivileged processes.

# File lib/sys/unix/sys/filesystem.rb, line 140
def bytes_available
  blocks_available * fragment_size
end
bytes_free() click to toggle source

Returns the total amount of free space on the partition.

# File lib/sys/unix/sys/filesystem.rb, line 135
def bytes_free
  blocks_free * fragment_size
end
bytes_total() click to toggle source

Returns the total space on the partition.

# File lib/sys/unix/sys/filesystem.rb, line 130
def bytes_total
  blocks * fragment_size
end
bytes_used() click to toggle source

Returns the total amount of used space on the partition.

# File lib/sys/unix/sys/filesystem.rb, line 145
def bytes_used
  bytes_total - bytes_free
end
case_insensitive?() click to toggle source

Returns true if the filesystem is case sensitive for the current path. Typically this will be any path on MS Windows or Macs using HFS.

For a root path (really any path without actual a-z characters) we take a best guess based on the host operating system. However, as a general rule, I do not recommend using this method for a root path.

# File lib/sys/filesystem.rb, line 28
def case_insensitive?
  if path !~ /\w+/
    if RbConfig::CONFIG['host_os'] =~ /darwin|mac|windows|mswin|mingw/i
      true # Assumes HFS
    else
      false
    end
  else
    File.identical?(path, path.swapcase)
  end
end
case_sensitive?() click to toggle source

Opposite of case_insensitive?

# File lib/sys/filesystem.rb, line 42
def case_sensitive?
  !case_insensitive?
end
percent_used() click to toggle source

Returns the percentage of the partition that has been used.

# File lib/sys/unix/sys/filesystem.rb, line 150
def percent_used
  100 - (100.0 * bytes_free.to_f / bytes_total.to_f)
end