Class: FFI::Pointer

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_array_of_libmnt_optmap(optmap) ⇒ Object



61
62
63
# File 'lib/rbmount/c.rb', line 61

def self.from_array_of_libmnt_optmap (optmap)
  self.new(:pointer, (optmap.size + 1) * Mount::C::OptMap.size).write_array_of_libmnt_optmap(optmap)
end

Instance Method Details

#get_libmnt_optmap(where) ⇒ Object



24
25
26
27
28
# File 'lib/rbmount/c.rb', line 24

def get_libmnt_optmap (where)
  Mount::C::OptMap.new(self + where).tap {|map|
    break Mount::OptMap.new(*[:name, :id, :mask].map {|a| map[a] })
  }
end

#put_libmnt_optmap(optmap, where) ⇒ Object



33
34
35
36
# File 'lib/rbmount/c.rb', line 33

def put_libmnt_optmap (optmap, where)
  put_string(where, [optmap.name, optmap.id, optmap.mask].pack('Pi!i!'))
  self
end

#read_array_of_libmnt_optmapObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/rbmount/c.rb', line 42

def read_array_of_libmnt_optmap
  map, offset = [], 0

  begin
    map << get_libmnt_optmap(offset)
    offset += Mount::C::OptMap.size
  end until map.last.instance_eval { [name, id, mask] } == [nil, 0, 0]

  map.tap(&:pop)
end

#read_libmnt_optmapObject



29
30
31
# File 'lib/rbmount/c.rb', line 29

def read_libmnt_optmap
  get_libmnt_optmap(0)
end

#write_array_of_libmnt_optmap(optmap) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/rbmount/c.rb', line 53

def write_array_of_libmnt_optmap (optmap)
  optmap.each_with_index {|opt, i|
    put_libmnt_optmap(opt, i * Mount::C::OptMap.size)
  }
  put_libmnt_optmap(Mount::OptMap.new(nil, 0, 0), optmap.size * Mount::C::OptMap.size)
  self
end

#write_libmnt_optmap(optmap) ⇒ Object



37
38
39
40
# File 'lib/rbmount/c.rb', line 37

def write_libmnt_optmap (optmap)
  put_libmnt_optmap(optmap, 0)
  self
end