Class: Sys::Filesystem::Stat
- Inherits:
-
Object
- Object
- Sys::Filesystem::Stat
- Defined in:
- lib/sys/filesystem.rb,
lib/sys/unix/sys/filesystem.rb,
lib/sys/windows/sys/filesystem.rb
Overview
Stat objects are returned by the Sys::Filesystem.stat method.
Constant Summary collapse
- RDONLY =
Read-only filesystem
1
- NOSUID =
Filesystem does not support suid or sgid semantics.
2
- NOTRUNC =
Filesystem does not truncate file names longer than
name_max
. 3
Instance Attribute Summary collapse
-
#async_reads ⇒ Object
Count of async reads since mount.
-
#async_writes ⇒ Object
Count of async writes since mount.
-
#base_type ⇒ Object
The file system type, e.g.
-
#block_size ⇒ Object
The file system block size.
-
#blocks ⇒ Object
The total number of blocks available (used or unused) on the file system.
-
#blocks_available ⇒ Object
The total number of unused blocks available to unprivileged processes.
-
#blocks_free ⇒ Object
The total number of unused blocks.
-
#bytes_available ⇒ Object
readonly
The amount of free space available to unprivileged processes.
-
#bytes_free ⇒ Object
readonly
The total amount of free space on the partition.
-
#files ⇒ Object
(also: #inodes)
Total number of files/inodes that can be created on the file system.
-
#files_available ⇒ Object
(also: #inodes_available)
Total number of available files/inodes for unprivileged processes that can be created on the file system.
-
#files_free ⇒ Object
(also: #inodes_free)
Total number of free files/inodes that can be created on the file system.
-
#filesystem_id ⇒ Object
The file system volume id.
-
#filesystem_type ⇒ Object
The filesystem type.
-
#flags ⇒ Object
A bit mask of file system flags.
-
#fragment_size ⇒ Object
Fragment size.
-
#name_max ⇒ Object
The maximum length of a file name permitted on the file system.
-
#owner ⇒ Object
The user that mounted the filesystem.
-
#path ⇒ Object
The path of the file system.
-
#sync_reads ⇒ Object
Count of sync reads since mount.
-
#sync_writes ⇒ Object
Count of sync writes since mount.
Instance Method Summary collapse
-
#bytes_total ⇒ Object
Returns the total space on the partition.
-
#bytes_used ⇒ Object
Returns the total amount of used space on the partition.
-
#case_insensitive? ⇒ Boolean
Returns true if the filesystem is case sensitive for the current path.
-
#case_sensitive? ⇒ Boolean
Opposite of case_insensitive?.
-
#initialize ⇒ Stat
constructor
Creates a new Sys::Filesystem::Stat object.
-
#percent_used ⇒ Object
Returns the percentage of the partition that has been used.
Constructor Details
#initialize ⇒ Stat
Creates a new Sys::Filesystem::Stat object. This is meant for internal use only. Do not instantiate directly.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/sys/unix/sys/filesystem.rb', line 133 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 |
Instance Attribute Details
#async_reads ⇒ Object
Count of async reads since mount
121 122 123 |
# File 'lib/sys/unix/sys/filesystem.rb', line 121 def async_reads @async_reads end |
#async_writes ⇒ Object
Count of async writes since mount
124 125 126 |
# File 'lib/sys/unix/sys/filesystem.rb', line 124 def async_writes @async_writes end |
#base_type ⇒ Object
The file system type, e.g. NTFS, FAT, etc.
106 107 108 |
# File 'lib/sys/unix/sys/filesystem.rb', line 106 def base_type @base_type end |
#block_size ⇒ Object
The file system block size. MS Windows typically defaults to 4096.
73 74 75 |
# File 'lib/sys/unix/sys/filesystem.rb', line 73 def block_size @block_size end |
#blocks ⇒ Object
The total number of blocks available (used or unused) on the file system.
79 80 81 |
# File 'lib/sys/unix/sys/filesystem.rb', line 79 def blocks @blocks end |
#blocks_available ⇒ Object
The total number of unused blocks available to unprivileged processes.
85 86 87 |
# File 'lib/sys/unix/sys/filesystem.rb', line 85 def blocks_available @blocks_available end |
#blocks_free ⇒ Object
The total number of unused blocks.
82 83 84 |
# File 'lib/sys/unix/sys/filesystem.rb', line 82 def blocks_free @blocks_free end |
#bytes_available ⇒ Object (readonly)
The amount of free space available to unprivileged processes.
160 161 162 |
# File 'lib/sys/unix/sys/filesystem.rb', line 160 def bytes_available blocks_available * fragment_size end |
#bytes_free ⇒ Object (readonly)
The total amount of free space on the partition.
155 156 157 |
# File 'lib/sys/unix/sys/filesystem.rb', line 155 def bytes_free blocks_free * fragment_size end |
#files ⇒ Object Also known as: inodes
Total number of files/inodes that can be created on the file system. This attribute is always nil on MS Windows.
88 89 90 |
# File 'lib/sys/unix/sys/filesystem.rb', line 88 def files @files end |
#files_available ⇒ Object Also known as: inodes_available
Total number of available files/inodes for unprivileged processes that can be created on the file system. This attribute is always nil on MS Windows.
94 95 96 |
# File 'lib/sys/unix/sys/filesystem.rb', line 94 def files_available @files_available end |
#files_free ⇒ Object Also known as: inodes_free
Total number of free files/inodes that can be created on the file system. This attribute is always nil on MS Windows.
91 92 93 |
# File 'lib/sys/unix/sys/filesystem.rb', line 91 def files_free @files_free end |
#filesystem_id ⇒ Object
The file system volume id.
97 98 99 |
# File 'lib/sys/unix/sys/filesystem.rb', line 97 def filesystem_id @filesystem_id end |
#filesystem_type ⇒ Object
The filesystem type
109 110 111 |
# File 'lib/sys/unix/sys/filesystem.rb', line 109 def filesystem_type @filesystem_type end |
#flags ⇒ Object
A bit mask of file system flags.
100 101 102 |
# File 'lib/sys/unix/sys/filesystem.rb', line 100 def flags @flags end |
#fragment_size ⇒ Object
Fragment size. Meaningless at the moment.
76 77 78 |
# File 'lib/sys/unix/sys/filesystem.rb', line 76 def fragment_size @fragment_size end |
#name_max ⇒ Object
The maximum length of a file name permitted on the file system.
103 104 105 |
# File 'lib/sys/unix/sys/filesystem.rb', line 103 def name_max @name_max end |
#owner ⇒ Object
The user that mounted the filesystem
112 113 114 |
# File 'lib/sys/unix/sys/filesystem.rb', line 112 def owner @owner end |
#path ⇒ Object
The path of the file system.
70 71 72 |
# File 'lib/sys/unix/sys/filesystem.rb', line 70 def path @path end |
#sync_reads ⇒ Object
Count of sync reads since mount
115 116 117 |
# File 'lib/sys/unix/sys/filesystem.rb', line 115 def sync_reads @sync_reads end |
#sync_writes ⇒ Object
Count of sync writes since mount
118 119 120 |
# File 'lib/sys/unix/sys/filesystem.rb', line 118 def sync_writes @sync_writes end |
Instance Method Details
#bytes_total ⇒ Object
Returns the total space on the partition.
150 151 152 |
# File 'lib/sys/unix/sys/filesystem.rb', line 150 def bytes_total blocks * fragment_size end |
#bytes_used ⇒ Object
Returns the total amount of used space on the partition.
165 166 167 |
# File 'lib/sys/unix/sys/filesystem.rb', line 165 def bytes_used bytes_total - bytes_free end |
#case_insensitive? ⇒ Boolean
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.
31 32 33 34 35 36 37 38 39 |
# File 'lib/sys/filesystem.rb', line 31 def case_insensitive? if path =~ /\w+/ File.identical?(path, path.swapcase) elsif RbConfig::CONFIG['host_os'] =~ /darwin|mac|windows|mswin|mingw/i true # Assumes HFS/APFS on Mac else false end end |
#case_sensitive? ⇒ Boolean
Opposite of case_insensitive?
43 44 45 |
# File 'lib/sys/filesystem.rb', line 43 def case_sensitive? !case_insensitive? end |
#percent_used ⇒ Object
Returns the percentage of the partition that has been used.
170 171 172 |
# File 'lib/sys/unix/sys/filesystem.rb', line 170 def percent_used 100 - (100.0 * bytes_free.to_f / bytes_total.to_f) end |