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
- ZFS_PROPERTIES =
{ zfs_atime: 'atime', zfs_casesensitivity: 'casesensitivity', zfs_compression: 'compression', zfs_compressratio: 'compressratio', zfs_devices: 'devices', zfs_exec: 'exec', zfs_quota: 'quota', zfs_readonly: 'readonly', zfs_recordsize: 'recordsize', zfs_reservation: 'reservation', zfs_setuid: 'setuid' }.freeze
- 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.
-
#mount_options ⇒ Object
A list of comma separated options for the mount, e.g.
-
#mount_point ⇒ Object
The mount point/directory.
-
#mount_source ⇒ Object
The name of the mounted resource.
-
#mount_type ⇒ Object
The type of filesystem mount, e.g.
-
#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.
-
#zfs_property(property) ⇒ Object
Returns a native ZFS property value for this path’s dataset.
Constructor Details
#initialize ⇒ Stat
Creates a new Sys::Filesystem::Stat object. This is meant for internal use only. Do not instantiate directly.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/sys/unix/sys/filesystem.rb', line 120 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 @mount_source = nil @mount_point = nil @mount_type = nil @mount_options = nil @filesystem_type = nil @owner = nil @sync_reads = nil @sync_writes = nil @async_reads = nil @async_writes = nil end |
Instance Attribute Details
#async_reads ⇒ Object
Count of async reads since mount
108 109 110 |
# File 'lib/sys/unix/sys/filesystem.rb', line 108 def async_reads @async_reads end |
#async_writes ⇒ Object
Count of async writes since mount
111 112 113 |
# File 'lib/sys/unix/sys/filesystem.rb', line 111 def async_writes @async_writes end |
#base_type ⇒ Object
The file system type, e.g. NTFS, FAT, etc.
81 82 83 |
# File 'lib/sys/unix/sys/filesystem.rb', line 81 def base_type @base_type end |
#block_size ⇒ Object
The file system block size. MS Windows typically defaults to 4096.
48 49 50 |
# File 'lib/sys/unix/sys/filesystem.rb', line 48 def block_size @block_size end |
#blocks ⇒ Object
The total number of blocks available (used or unused) on the file system.
54 55 56 |
# File 'lib/sys/unix/sys/filesystem.rb', line 54 def blocks @blocks end |
#blocks_available ⇒ Object
The total number of unused blocks available to unprivileged processes.
60 61 62 |
# File 'lib/sys/unix/sys/filesystem.rb', line 60 def blocks_available @blocks_available end |
#blocks_free ⇒ Object
The total number of unused blocks.
57 58 59 |
# File 'lib/sys/unix/sys/filesystem.rb', line 57 def blocks_free @blocks_free end |
#bytes_available ⇒ Object (readonly)
The amount of free space available to unprivileged processes.
157 158 159 |
# File 'lib/sys/unix/sys/filesystem.rb', line 157 def bytes_available blocks_available * fragment_size end |
#bytes_free ⇒ Object (readonly)
The total amount of free space on the partition.
152 153 154 |
# File 'lib/sys/unix/sys/filesystem.rb', line 152 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.
63 64 65 |
# File 'lib/sys/unix/sys/filesystem.rb', line 63 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.
69 70 71 |
# File 'lib/sys/unix/sys/filesystem.rb', line 69 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.
66 67 68 |
# File 'lib/sys/unix/sys/filesystem.rb', line 66 def files_free @files_free end |
#filesystem_id ⇒ Object
The file system volume id.
72 73 74 |
# File 'lib/sys/unix/sys/filesystem.rb', line 72 def filesystem_id @filesystem_id end |
#filesystem_type ⇒ Object
The filesystem type
96 97 98 |
# File 'lib/sys/unix/sys/filesystem.rb', line 96 def filesystem_type @filesystem_type end |
#flags ⇒ Object
A bit mask of file system flags.
75 76 77 |
# File 'lib/sys/unix/sys/filesystem.rb', line 75 def flags @flags end |
#fragment_size ⇒ Object
Fragment size. Meaningless at the moment.
51 52 53 |
# File 'lib/sys/unix/sys/filesystem.rb', line 51 def fragment_size @fragment_size end |
#mount_options ⇒ Object
A list of comma separated options for the mount, e.g. nosuid, etc.
93 94 95 |
# File 'lib/sys/unix/sys/filesystem.rb', line 93 def @mount_options end |
#mount_point ⇒ Object
The mount point/directory.
87 88 89 |
# File 'lib/sys/unix/sys/filesystem.rb', line 87 def mount_point @mount_point end |
#mount_source ⇒ Object
The name of the mounted resource.
84 85 86 |
# File 'lib/sys/unix/sys/filesystem.rb', line 84 def mount_source @mount_source end |
#mount_type ⇒ Object
The type of filesystem mount, e.g. ufs, zfs, nfs, etc.
90 91 92 |
# File 'lib/sys/unix/sys/filesystem.rb', line 90 def mount_type @mount_type end |
#name_max ⇒ Object
The maximum length of a file name permitted on the file system.
78 79 80 |
# File 'lib/sys/unix/sys/filesystem.rb', line 78 def name_max @name_max end |
#owner ⇒ Object
The user that mounted the filesystem
99 100 101 |
# File 'lib/sys/unix/sys/filesystem.rb', line 99 def owner @owner end |
#path ⇒ Object
The path of the file system.
45 46 47 |
# File 'lib/sys/unix/sys/filesystem.rb', line 45 def path @path end |
#sync_reads ⇒ Object
Count of sync reads since mount
102 103 104 |
# File 'lib/sys/unix/sys/filesystem.rb', line 102 def sync_reads @sync_reads end |
#sync_writes ⇒ Object
Count of sync writes since mount
105 106 107 |
# File 'lib/sys/unix/sys/filesystem.rb', line 105 def sync_writes @sync_writes end |
Instance Method Details
#bytes_total ⇒ Object
Returns the total space on the partition.
147 148 149 |
# File 'lib/sys/unix/sys/filesystem.rb', line 147 def bytes_total blocks * fragment_size end |
#bytes_used ⇒ Object
Returns the total amount of used space on the partition.
162 163 164 |
# File 'lib/sys/unix/sys/filesystem.rb', line 162 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.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sys/filesystem.rb', line 45 def case_insensitive? if path =~ /\w+/ File.identical?(path, path.swapcase) else zfs_case = zfs_case_insensitive? return zfs_case unless zfs_case.nil? if RbConfig::CONFIG['host_os'] =~ /darwin|mac|windows|mswin|mingw/i true # Assumes HFS/APFS on Mac else false end end end |
#case_sensitive? ⇒ Boolean
Opposite of case_insensitive?
62 63 64 |
# File 'lib/sys/filesystem.rb', line 62 def case_sensitive? !case_insensitive? end |
#percent_used ⇒ Object
Returns the percentage of the partition that has been used.
167 168 169 |
# File 'lib/sys/unix/sys/filesystem.rb', line 167 def percent_used 100 - (100.0 * bytes_free.to_f / bytes_total.to_f) end |
#zfs_property(property) ⇒ Object
Returns a native ZFS property value for this path’s dataset. Returns nil if the path is not on ZFS or libzfs is unavailable.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sys/filesystem.rb', line 68 def zfs_property(property) return nil unless base_type == 'zfs' return nil unless Sys::Filesystem.respond_to?(:zfs_property, true) dataset = zfs_dataset return nil unless dataset Sys::Filesystem.send(:zfs_property, dataset, property.to_s) rescue SystemCallError nil end |