tolvmxfs/lib/to_lvm_xfs/structs.rb

50 lines
1.3 KiB
Ruby

require 'to_lvm_xfs/exts'
class Image
attr_reader :base, :dir, :image, :root
def initialize base, dir, image: nil, root: nil
@base = base
@dir =
case dir
when Pathname then dir
when String then Pathname.new dir
else raise ArgumentError, "Pathname for dir expected"
end
@image =
case image
when Pathname then image
when String then Pathname.new image
when nil then @dir+'image'
else raise ArgumentError, "Pathname for image expected"
end
@image = @image.readlink.expand_path @image.expand_path.dirname while @image.symlink?
@root =
case root
when Pathname then root
when String then Pathname.new root
when nil then @dir+'root'
else raise ArgumentError, "Path for root must be Pathname, String or MP, if given"
end
end
def to_s() @dir.to_s end
def kpartx() @base.kpartx @image end
def departx() @base.departx @image end
def lpartx() @base.lpartx @image end
def kpartxed?() @base.kpartxed? @image end
end
class MP
attr_reader :base, :dev, :mp, :opts
def initialize base, dev, mp, *opts
@base, @dev, @mp, opts = base, dev, mp, opts
end
def mount() @base.mount dev, mp, *opts end
def umount() @base.umount mp end
def uuid() @uuid ||= @base.sh.fs_uuid @dev end
def fstype() @fstype ||= @base.sh.fs_type @dev end
def clear_cache() @uuid = @fstype = nil end
end