Class: Sys::Filesystem::Stat

Inherits:
Object
  • Object
show all
Defined in:
lib/unix/sys/filesystem.rb,
lib/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.



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

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.



105
106
107
# File 'lib/unix/sys/filesystem.rb', line 105

def base_type
  @base_type
end

#block_sizeObject

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



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

def block_size
  @block_size
end

#blocksObject

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



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

def blocks
  @blocks
end

#blocks_availableObject

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



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

def blocks_available
  @blocks_available
end

#blocks_freeObject

The total number of unused blocks.



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

def blocks_free
  @blocks_free
end

#bytes_freeObject (readonly)

Returns the total amount of free space on the partition.



136
137
138
# File 'lib/unix/sys/filesystem.rb', line 136

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.



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

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.



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

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.



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

def files_free
  @files_free
end

#filesystem_idObject

The file system volume id.



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

def filesystem_id
  @filesystem_id
end

#flagsObject

A bit mask of file system flags.



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

def flags
  @flags
end

#fragment_sizeObject

Fragment size. Meaningless at the moment.



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

def fragment_size
  @fragment_size
end

#name_maxObject

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



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

def name_max
  @name_max
end

#pathObject

The path of the file system.



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

def path
  @path
end

Instance Method Details

#bytes_totalObject

Returns the total space on the partition.



131
132
133
# File 'lib/unix/sys/filesystem.rb', line 131

def bytes_total
  blocks * block_size
end

#bytes_usedObject

Returns the total amount of used space on the partition.



141
142
143
# File 'lib/unix/sys/filesystem.rb', line 141

def bytes_used
  bytes_total - bytes_free
end

#percent_usedObject

Returns the percentage of the partition that has been used.



146
147
148
# File 'lib/unix/sys/filesystem.rb', line 146

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