module Facter::Util::Partitions::Linux

Constants

DEVDISK_BY_UUID_DIRECTORY
SYSFS_BLOCK_DIRECTORY

Only Linux 2.6+ kernels support sysfs which is required to easily get device details

Public Class Methods

filesystem(partition) click to toggle source
# File lib/facter/util/partitions/linux.rb, line 52
def self.filesystem(partition)
  if Facter::Core::Execution.which('blkid')
    Facter::Core::Execution.exec("blkid #{File.join('/dev', partition)}").scan(/TYPE="([^"]*)"/).flatten.first
  end
end
label(partition) click to toggle source
# File lib/facter/util/partitions/linux.rb, line 58
def self.label(partition)
  if Facter::Core::Execution.which('blkid')
    Facter::Core::Execution.exec("blkid #{File.join('/dev', partition)}").scan(/LABEL="([^"]*)"/).flatten.first
  end
end
list() click to toggle source
# File lib/facter/util/partitions/linux.rb, line 7
def self.list
  if File.exist?(SYSFS_BLOCK_DIRECTORY)
    devices = Dir.entries(SYSFS_BLOCK_DIRECTORY).select { |d| File.exist?( SYSFS_BLOCK_DIRECTORY + d + "/device" ) }
  
    if devices.empty?
      []
    else
      devices.collect do |device|
        Dir.glob( SYSFS_BLOCK_DIRECTORY + device + "/#{device}*" ).collect do |d|
          File.basename(d)
        end
      end.flatten
    end
  else
    []
  end
end
mount(partition) click to toggle source
# File lib/facter/util/partitions/linux.rb, line 46
def self.mount(partition)
  if Facter::Core::Execution.which('mount')
    Facter::Core::Execution.exec('mount').scan(/\/dev\/#{partition}\son\s(\S+)/).flatten.first
  end
end
size(partition) click to toggle source
# File lib/facter/util/partitions/linux.rb, line 42
def self.size(partition)
  read_size(partition)
end
uuid(partition) click to toggle source
# File lib/facter/util/partitions/linux.rb, line 25
def self.uuid(partition)
  uuid = nil
  if File.exist?(DEVDISK_BY_UUID_DIRECTORY)
    Dir.entries(DEVDISK_BY_UUID_DIRECTORY).each do |file|
      qualified_file = File.join(DEVDISK_BY_UUID_DIRECTORY, file)

      #A uuid is 16 octets long (RFC4122) which is 32hex chars + 4 '-'s
      next unless file.length == 36
      next unless File.symlink?(qualified_file)
      next unless File.readlink(qualified_file).match(%r[(?:\.\./\.\./|/dev/)#{partition}$])

      uuid = file
    end
  end
  uuid
end

Private Class Methods

read_size(partition) click to toggle source
# File lib/facter/util/partitions/linux.rb, line 65
def self.read_size(partition)
  if device = partition.match(/(\D+)/)[1] and File.readable?(File.join(SYSFS_BLOCK_DIRECTORY, device, partition, 'size'))
    File.read(File.join(SYSFS_BLOCK_DIRECTORY, device, partition, 'size')).chomp
  end
end