Skip to content
Daniel Berger edited this page Jan 11, 2019 · 12 revisions

Overview

The sys-filesystem gem provides information about your filesystem.

This is a cross-platform library that should work on any Unixy flavors, as well as MS Windows.

It includes three main methods:

Filesystem.stat
Filesystem.mounts
Filesystem.mount_point

The Filesystem.stat method will return a Filesystem::Stat object that also includes two custom methods:

Filesystem::Stat#case_insensitive_filesystem?
Filesystem::Stat#case_sensitive_filesystem?

Filesystem.stat(path)

The Filesystem.stat singleton method takes a path and returns a Filesystem::Stat object which includes information on that path. You will typically want to pass a mount point, but any path on the given mount will work.

Filesystem.mounts

The Filesystem.mounts singleton method returns an array of Filesystem::Mount objects which include information about each mount point, such as type, options, etc.

Filesystem.mount_point(path)

The Filesystem.mount_point method takes a path and returns the corresponding mount point for that path. For example, if you have "/home" mounted and you pass `Filesystem.mount_point('/home/dberger'), it will return "/home".

Example

require 'sys/filesystem'
include Sys
   
# Display information about a particular filesystem.
p Filesystem.stat('/')

# Sample output

#<Sys::Filesystem::Stat:0x517440
  @base_type = "ufs",
  @flags = 4,
  @files_available = 3817457,
  @block_size = 8192,
  @blocks_available = 19957633,
  @blocks = 34349612,
  @name_max = 255,
  @path = "/",
  @filesystem_id = 35651592,
  @files = 4135040,
  @fragment_size = 1024,
  @files_free = 3817457,
  @blocks_free = 20301129
>
   
# Describe all mount points on the system
Filesystem.mounts{ |mount| p mount }
   
# Find the mount point of any particular file
puts Filesystem.mount_point('/home/djberge/some_file.txt') => '/home'

Implementation Details

For both Windows and Unixy operating systems, various C functions are wrapped via FFI to provide you with the appropriate information.

Clone this wiki locally