Class: Sys::Filesystem::Stat

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



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/sys/unix/sys/filesystem.rb', line 111

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

#base_typeObject

The file system type, e.g. NTFS, FAT, etc.



102
103
104
# File 'lib/sys/unix/sys/filesystem.rb', line 102

def base_type
  @base_type
end

#block_sizeObject

The file system block size. MS Windows typically defaults to 4096.



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

def block_size
  @block_size
end

#blocksObject

The total number of blocks available (used or unused) on the file system.



75
76
77
# File 'lib/sys/unix/sys/filesystem.rb', line 75

def blocks
  @blocks
end

#blocks_availableObject

The total number of unused blocks available to unprivileged processes. Identical to blocks at the moment.



81
82
83
# File 'lib/sys/unix/sys/filesystem.rb', line 81

def blocks_available
  @blocks_available
end

#blocks_freeObject

The total number of unused blocks.



78
79
80
# File 'lib/sys/unix/sys/filesystem.rb', line 78

def blocks_free
  @blocks_free
end

#bytes_freeObject (readonly)

Returns the total amount of free space on the partition.



133
134
135
# File 'lib/sys/unix/sys/filesystem.rb', line 133

def bytes_free
  blocks_available * block_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.



84
85
86
# File 'lib/sys/unix/sys/filesystem.rb', line 84

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.



90
91
92
# File 'lib/sys/unix/sys/filesystem.rb', line 90

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.



87
88
89
# File 'lib/sys/unix/sys/filesystem.rb', line 87

def files_free
  @files_free
end

#filesystem_idObject

The file system volume id.



93
94
95
# File 'lib/sys/unix/sys/filesystem.rb', line 93

def filesystem_id
  @filesystem_id
end

#flagsObject

A bit mask of file system flags.



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

def flags
  @flags
end

#fragment_sizeObject

Fragment size. Meaningless at the moment.



72
73
74
# File 'lib/sys/unix/sys/filesystem.rb', line 72

def fragment_size
  @fragment_size
end

#name_maxObject

The maximum length of a file name permitted on the file system.



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

def name_max
  @name_max
end

#pathObject

The path of the file system.



66
67
68
# File 'lib/sys/unix/sys/filesystem.rb', line 66

def path
  @path
end

Instance Method Details

#bytes_totalObject

Returns the total space on the partition.



128
129
130
# File 'lib/sys/unix/sys/filesystem.rb', line 128

def bytes_total
  blocks * block_size
end

#bytes_usedObject

Returns the total amount of used space on the partition.



138
139
140
# File 'lib/sys/unix/sys/filesystem.rb', line 138

def bytes_used
  bytes_total - bytes_free
end

#percent_usedObject

Returns the percentage of the partition that has been used.



143
144
145
# File 'lib/sys/unix/sys/filesystem.rb', line 143

def percent_used
  100 - (100.0 * bytes_free.to_f / bytes_total.to_f)
end