# File lib/virt-p2v/blockdevice.rb, line 29 def self.[](device) raise NoSuchDeviceError unless @@devices.has_key?(device) @@devices[device] end
# File lib/virt-p2v/blockdevice.rb, line 25 def self.all_devices @@devices.values end
# File lib/virt-p2v/blockdevice.rb, line 37 def initialize(device) size = 0 begin # Get the device size, in blocks File.open("/sys/block/#{device}/size") { |size_f| size = Integer(size_f.gets.chomp) } # Get the size in bytes by multiplying by the block size File.open("/sys/block/#{device}/queue/logical_block_size") { |size_f| size *= Integer(size_f.gets.chomp) } rescue Errno::ENOENT # Unlikely, but not fatal end raise InvalidDevice if size == 0 # cciss device /dev/cciss/c0d0 will be cciss!c0d0 under /sys/block @device = device.gsub("!", "/") @size = size @@devices[@device] = self end