Module: LinuxStat::Filesystem
- Defined in:
- lib/linux_stat/filesystem.rb
Overview
Shows various Filesystem related information of the current system.
Class Method Summary collapse
-
.available(fs = ?..freeze) ⇒ Object
available(fs = ‘.’).
-
.free(fs = ?..freeze) ⇒ Object
free(fs = ‘.’).
-
.stat(fs = ?..freeze) ⇒ Object
stat(fs = ‘.’).
-
.stat_raw(fs = ?..freeze) ⇒ Object
stat_raw(fs = ‘.’).
-
.total(fs = ?..freeze) ⇒ Object
total(fs = ‘.’).
-
.used(fs = ?..freeze) ⇒ Object
used(fs = ‘.’).
Class Method Details
.available(fs = ?..freeze) ⇒ Object
available(fs = ‘.’)
Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
It returns the total free space in a disk in bytes.
It is to be noted that free is not same as available.
Available returns the size of free blocks for unpriviledged users.
If the stat can’t be acquired, this method will return an empty Hash.
94 95 96 97 98 99 |
# File 'lib/linux_stat/filesystem.rb', line 94 def available(fs = ?..freeze) s = stat_raw(fs) return nil if s.empty? s.default = 0 s[:block_size] * s[:block_avail_unpriv] end |
.free(fs = ?..freeze) ⇒ Object
free(fs = ‘.’)
Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
It returns the total free space in a disk in bytes.
It is to be noted that free is not same as available.
Free returns the size of free blocks.
If the stat can’t be acquired, this method will return an empty Hash.
60 61 62 63 64 65 |
# File 'lib/linux_stat/filesystem.rb', line 60 def free(fs = ?..freeze) s = stat_raw(fs) return nil if s.empty? s.default = 0 s[:block_size] * s[:block_free] end |
.stat(fs = ?..freeze) ⇒ Object
stat(fs = ‘.’)
Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
-
It returns a Hash with the following info:
-
total size of the device (in bytes)
-
free space (in kilobytes)
-
used space (in kilobytes)
-
In a hash format:
{:total=>119981191168, :free=>43155574784, :used=>76825616384, :available=>43155574784}
If the stat can’t be acquired, this method will return an empty Hash.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/linux_stat/filesystem.rb', line 21 def stat(fs = ?..freeze) s = stat_raw(fs) return {} if s.empty? s.default = 0 { total: s[:block_size] * s[:blocks], free: s[:block_size] * s[:block_free], used: s[:blocks].-(s[:block_free]) * s[:block_size] } end |
.stat_raw(fs = ?..freeze) ⇒ Object
stat_raw(fs = ‘.’)
Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
It returns a Hash with the following data (for example):
{:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>10535967, :block_avail_unpriv=>10535967, :inodes=>58612160, :free_inodes=>56718550, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
If the stat can’t be acquired, this method will return an empty Hash.
110 111 112 |
# File 'lib/linux_stat/filesystem.rb', line 110 def stat_raw(fs = ?..freeze) LinuxStat::FS.stat(fs) end |
.total(fs = ?..freeze) ⇒ Object
total(fs = ‘.’)
Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
It returns the total size of a given disk in bytes.
If the stat can’t be acquired, this method will return nil.
41 42 43 44 45 46 |
# File 'lib/linux_stat/filesystem.rb', line 41 def total(fs = ?..freeze) s = stat_raw(fs) return nil if s.empty? s.default = 0 s[:block_size] * s[:blocks] end |
.used(fs = ?..freeze) ⇒ Object
used(fs = ‘.’)
Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
It returns the used space of a given disk in bytes.
If the stat can’t be acquired, this method will return nil.
75 76 77 78 79 80 |
# File 'lib/linux_stat/filesystem.rb', line 75 def used(fs = ?..freeze) s = stat_raw(fs) return nil if s.empty? s.default = 0 s[:blocks].-(s[:block_free]) * s[:block_size] end |