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.



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/unix/sys/filesystem.rb', line 314

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.



305
306
307
# File 'lib/unix/sys/filesystem.rb', line 305

def base_type
  @base_type
end

#block_sizeObject

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



272
273
274
# File 'lib/unix/sys/filesystem.rb', line 272

def block_size
  @block_size
end

#blocksObject

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



278
279
280
# File 'lib/unix/sys/filesystem.rb', line 278

def blocks
  @blocks
end

#blocks_availableObject

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



284
285
286
# File 'lib/unix/sys/filesystem.rb', line 284

def blocks_available
  @blocks_available
end

#blocks_freeObject

The total number of unused blocks.



281
282
283
# File 'lib/unix/sys/filesystem.rb', line 281

def blocks_free
  @blocks_free
end

#bytes_freeObject (readonly)

Returns the total amount of free space on the partition.



336
337
338
# File 'lib/unix/sys/filesystem.rb', line 336

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.



287
288
289
# File 'lib/unix/sys/filesystem.rb', line 287

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.



293
294
295
# File 'lib/unix/sys/filesystem.rb', line 293

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.



290
291
292
# File 'lib/unix/sys/filesystem.rb', line 290

def files_free
  @files_free
end

#filesystem_idObject

The file system volume id.



296
297
298
# File 'lib/unix/sys/filesystem.rb', line 296

def filesystem_id
  @filesystem_id
end

#flagsObject

A bit mask of file system flags.



299
300
301
# File 'lib/unix/sys/filesystem.rb', line 299

def flags
  @flags
end

#fragment_sizeObject

Fragment size. Meaningless at the moment.



275
276
277
# File 'lib/unix/sys/filesystem.rb', line 275

def fragment_size
  @fragment_size
end

#name_maxObject

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



302
303
304
# File 'lib/unix/sys/filesystem.rb', line 302

def name_max
  @name_max
end

#pathObject

The path of the file system.



269
270
271
# File 'lib/unix/sys/filesystem.rb', line 269

def path
  @path
end

Instance Method Details

#bytes_totalObject

Returns the total space on the partition.



331
332
333
# File 'lib/unix/sys/filesystem.rb', line 331

def bytes_total
  blocks * block_size
end

#bytes_usedObject

Returns the total amount of used space on the partition.



341
342
343
# File 'lib/unix/sys/filesystem.rb', line 341

def bytes_used
  bytes_total - bytes_free
end

#percent_usedObject

Returns the percentage of the partition that has been used.



346
347
348
# File 'lib/unix/sys/filesystem.rb', line 346

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