class Ramdisk
class that represents all information associated with a ram disk
Attributes
mountpoint[RW]
name[RW]
ramdisk[RW]
size[RW]
system_interface[RW]
Public Class Methods
new(mountpoint, system_interface = SystemInfo)
click to toggle source
# File lib/ramdisk.rb, line 68 def initialize(mountpoint, system_interface = SystemInfo) self.mountpoint = mountpoint self.system_interface = system_interface end
Public Instance Methods
allocate(size)
click to toggle source
# File lib/ramdisk.rb, line 108 def allocate(size) sectors = size / 512 self.ramdisk = system_interface.hdiutil(sectors).strip end
deallocate()
click to toggle source
# File lib/ramdisk.rb, line 113 def deallocate unmounted.each do |u| msg = system_interface.deallocate(u) if !msg =~ /.*unmounted\./ raise "ramdisk: #{u} failed to deallocate ramdisk with this message: #{msg}" end end unmounted = [] return true end
format(drivename = "ramdev", fileSystemFormat = :hfs)
click to toggle source
# File lib/ramdisk.rb, line 124 def format(drivename = "ramdev", fileSystemFormat = :hfs) self.name = drivename case fileSystemFormat when :hfs msg = system_interface.newfs_hfs(name,ramdisk) if msg =~ /Initialized .*#{ramdisk[/\/*([^\/]*)$/,1]} as a/ return true else raise "ramdisk failed to format HFS volume #{ramdisk}" end else raise "ramdisk doesn't understand how to build #{fileSystemFormat} file system" end return flase end
list()
click to toggle source
# File lib/ramdisk.rb, line 88 def list # cannot be ||= because state may have changed. @list = system_interface.ramdisks end
mount()
click to toggle source
# File lib/ramdisk.rb, line 140 def mount if system_interface.mount(mountpoint, ramdisk) return true else puts "Unable to mount, trying again with 'sudo'" if system_interface.sudomount(mountpoint, ramdisk) return true else puts "ramdisk failed to mount" return false end end end
mounted?()
click to toggle source
# File lib/ramdisk.rb, line 81 def mounted? list.each do |i| return true if i[1] =~ /#{mountpoint}$/ end return false end
ramdisk=(device)
click to toggle source
# File lib/ramdisk.rb, line 93 def ramdisk=(device) @ramdisk = device end
unmount()
click to toggle source
# File lib/ramdisk.rb, line 154 def unmount unmounted_device = ramdisk if system_interface.unmount(mountpoint) unmounted.push(unmounted_device) return true else puts "Unable to unmount, trying again with 'sudo'." if system_interface.sudounmount(mountpoint, unmounted_device) return true else puts "ramdisk failed to un-mount." return false end end end
unmounted()
click to toggle source
# File lib/ramdisk.rb, line 77 def unmounted @unmounted ||= [] end
unmounted=(m)
click to toggle source
# File lib/ramdisk.rb, line 73 def unmounted=(m) @unmounted = m end