Class: SystemInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/ramdisk.rb

Class Method Summary collapse

Class Method Details

.deallocate(ramdisk) ⇒ Object



29
30
31
32
33
34
# File 'lib/ramdisk.rb', line 29

def self.deallocate(ramdisk)
  raise "Deallocate called with nil device." if ramdisk.nil?
  `hdiutil detach #{ramdisk}`
  device = ramdisk[/\/*([^\/]*)$/,1]
  return "\"#{device}\" unmounted.\n\"#{device}\" ejected.\n"
end

.hdiutil(sectors) ⇒ Object



5
6
7
# File 'lib/ramdisk.rb', line 5

def self.hdiutil(sectors)
  `hdiutil attach -nomount ram://#{sectors}`
end

.mount(mountpoint, ramdisk) ⇒ Object



13
14
15
# File 'lib/ramdisk.rb', line 13

def self.mount(mountpoint, ramdisk)
  system("mount -o noatime -t hfs #{ramdisk} #{mountpoint}")
end

.newfs_hfs(diskname, ramdisk) ⇒ Object



9
10
11
# File 'lib/ramdisk.rb', line 9

def self.newfs_hfs(diskname, ramdisk)
  `newfs_hfs -v '#{diskname}' #{ramdisk}`
end

.ramdisksObject



55
56
57
58
# File 'lib/ramdisk.rb', line 55

def self.ramdisks
    # cannot be ||= because state may have changed.
  @@ramdisks = read_hdutil
end

.read_hdutilObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ramdisk.rb', line 36

def self.read_hdutil
  plist = Plist::parse_xml(`hdiutil info -plist`)

  diskImages = []
  plist.each do |n|
    diskImages.concat n[1] if n[0] == "images"
  end

  response = []
  diskImages.each do |i|
    if i["image-path"] =~ /^ram\:\/\//
      response.push([i["system-entities"][0]["dev-entry"], i["system-entities"][0]["mount-point"]])
    end
  end

  response
end

.sudomount(mountpoint, ramdisk) ⇒ Object



17
18
19
# File 'lib/ramdisk.rb', line 17

def self.sudomount(mountpoint, ramdisk)
  system("sudo mount -o noatime -t hfs #{ramdisk} #{mountpoint}")
end

.sudounmount(mountpoint, ramdisk) ⇒ Object



25
26
27
# File 'lib/ramdisk.rb', line 25

def self.sudounmount(mountpoint, ramdisk)
  system("sudo hdiutil eject -force #{mountpoint}")
end

.unmount(mountpoint) ⇒ Object



21
22
23
# File 'lib/ramdisk.rb', line 21

def self.unmount(mountpoint)
  system("umount -f #{mountpoint}")
end