Class: Sys::Filesystem::Stat

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeStat

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_readsObject

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_writesObject

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_typeObject

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_sizeObject

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

#blocksObject

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_availableObject

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_freeObject

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_availableObject (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_freeObject (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

#filesObject 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_availableObject 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_freeObject 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_idObject

The file system volume id.



97
98
99
# File 'lib/sys/unix/sys/filesystem.rb', line 97

def filesystem_id
  @filesystem_id
end

#filesystem_typeObject

The filesystem type



109
110
111
# File 'lib/sys/unix/sys/filesystem.rb', line 109

def filesystem_type
  @filesystem_type
end

#flagsObject

A bit mask of file system flags.



100
101
102
# File 'lib/sys/unix/sys/filesystem.rb', line 100

def flags
  @flags
end

#fragment_sizeObject

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_maxObject

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

#ownerObject

The user that mounted the filesystem



112
113
114
# File 'lib/sys/unix/sys/filesystem.rb', line 112

def owner
  @owner
end

#pathObject

The path of the file system.



70
71
72
# File 'lib/sys/unix/sys/filesystem.rb', line 70

def path
  @path
end

#sync_readsObject

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_writesObject

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_totalObject

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_usedObject

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.

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


43
44
45
# File 'lib/sys/filesystem.rb', line 43

def case_sensitive?
  !case_insensitive?
end

#percent_usedObject

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