lib/unix/sys/filesystem.rb in sys-filesystem-1.1.1 vs lib/unix/sys/filesystem.rb in sys-filesystem-1.1.2

- old
+ new

@@ -8,11 +8,11 @@ class Filesystem extend FFI::Library ffi_lib FFI::Library::LIBC # The version of the sys-filesystem library. - VERSION = '1.1.1' + VERSION = '1.1.2' private if RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i attach_function(:statvfs, :statvfs64, [:string, :pointer], :int) @@ -101,13 +101,13 @@ MNT_DEFWRITE => 'defwrite', MNT_NOATIME => 'noatime' } # File used to read mount informtion from. - if File.exists?('/etc/mtab') + if File.exist?('/etc/mtab') MOUNT_FILE = '/etc/mtab' - elsif File.exists?('/etc/mnttab') + elsif File.exist?('/etc/mnttab') MOUNT_FILE = '/etc/mnttab' else MOUNT_FILE = 'getmntinfo' end @@ -324,10 +324,30 @@ @filesystem_id = nil @flags = nil @name_max = nil @base_type = nil end + + # Returns the total space on the partition. + def bytes_total + blocks * block_size + end + + # Returns the total amount of free space on the partition. + def bytes_free + blocks_available * block_size + end + + # Returns the total amount of used space on the partition. + def bytes_used + bytes_total - bytes_free + end + + # Returns the percentage of the partition that has been used. + def percent_used + 100 - (100.0 * bytes_free.to_f / bytes_total.to_f) + end end # Mount objects are returned by the Sys::Filesystem.mounts method. class Mount # The name of the mounted resource. @@ -546,11 +566,11 @@ val end end end -class Fixnum +class Numeric # Converts a number to kilobytes. def to_kb self / 1024 end @@ -560,7 +580,12 @@ end # Converts a number to gigabytes. def to_gb self / 1073741824 + end + + # Converts a number to terabytes. + def to_tb + self / 1099511627776 end end