Class: Mount::Table

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

Constant Summary collapse

DIRECTION =
Hash.new {|*|
  :forward
}.merge({
  forward:      Mount::MNT_ITER_FORWARD,
  'forward' =>  Mount::MNT_ITER_FORWARD,
  backward:     Mount::MNT_ITER_BACKWARD,
  'backward' => Mount::MNT_ITER_BACKWARD,

  Mount::MNT_ITER_FORWARD   => Mount::MNT_ITER_FORWARD,
  Mount::MNT_ITER_BACKWARD  => Mount::MNT_ITER_BACKWARD,
}).freeze

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Table

Returns a new instance of Table.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rbmount/table.rb', line 39

def initialize (path=nil)
  @pointer = Mount::C.mnt_new_table unless path
  if File.directory?(path)
    @pointer = Mount::C.mnt_new_table_from_dir(path)
  elsif File.file?(path)
    @pointer = Mount::C.mnt_new_table_from_file(path)
  else
    raise ArgumentError
  end

  raise if !@pointer or @pointer.null?

  ObjectSpace.define_finalizer(self, method(:finalize))
end

Instance Method Details

#add_fs(fs) ⇒ Object



54
55
56
# File 'lib/rbmount/table.rb', line 54

def add_fs (fs)
  Mount::C.mnt_table_add_fs(@pointer, fs.to_c)
end

#cacheObject



98
99
100
# File 'lib/rbmount/table.rb', line 98

def cache
  Mount::Cache.new(Mount::C.mnt_table_get_cache(@pointer))
end

#cache=(mpc) ⇒ Object



162
163
164
# File 'lib/rbmount/table.rb', line 162

def cache= (mpc)
  Mount::C.mnt_table_set_cache(@pointer, mpc.to_c)
end

#each_child_fs(parent, direction = :forward, &blk) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/rbmount/table.rb', line 132

def each_child_fs (parent, direction=:forward, &blk)
  Enumerator.new {|y|
    loop {
      res = next_child_fs(parent, direction)
      break unless res
      y << res
    }
  }.each(&blk)
end

#each_fs(direction = :forward, &blk) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/rbmount/table.rb', line 68

def each_fs (direction=:forward, &blk)
  Enumerator.new {|y|
    loop {
      res = next_fs(direction)
      break unless res
      y << res
    }
  }.each(&blk)
end

#finalizeObject



184
185
186
# File 'lib/rbmount/table.rb', line 184

def finalize
  Mount::C.mnt_free_table(@pointer)
end

#find_pair(source, target, direction = :forward) ⇒ Object



78
79
80
# File 'lib/rbmount/table.rb', line 78

def find_pair (source, target, direction=:forward)
  Mount::FS.new(Mount::C.mnt_table_find_pair(@pointer, source, target, DIRECTION[direction]))
end

#find_source(source, direction = :forward) ⇒ Object



82
83
84
# File 'lib/rbmount/table.rb', line 82

def find_source (source, direction=:forward)
  Mount::FS.new(Mount::C.mnt_table_find_source(@pointer, source, DIRECTION[direction]))
end

#find_srcpath(path, direction = :forward) ⇒ Object



86
87
88
# File 'lib/rbmount/table.rb', line 86

def find_srcpath (path, direction=:forward)
  Mount::FS.new(Mount::C.mnt_table_find_srcpath(@pointer, source, DIRECTION[direction]))
end

#find_tag(tag, val, direction = :forward) ⇒ Object



90
91
92
# File 'lib/rbmount/table.rb', line 90

def find_tag (tag, val, direction=:forward)
  Mount::FS.new(Mount::C.mnt_table_find_tag(@pointer, tag, val, DIRECTION[direction]))
end

#find_target(path, direction = :forward) ⇒ Object



94
95
96
# File 'lib/rbmount/table.rb', line 94

def find_target (path, direction=:forward)
  Mount::FS.new(Mount::C.mnt_table_find_target(@pointer, path, DIRECTION[direction]))
end

#fs_mounted?(fstab_fs) ⇒ Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/rbmount/table.rb', line 117

def fs_mounted?(fstab_fs)
  Mount::C.mnt_table_is_fs_mounted(@pointer, fstab_fs.to_c)
end

#nameObject



102
103
104
# File 'lib/rbmount/table.rb', line 102

def name
  Mount::C.mnt_table_get_name(@pointer)
end

#nentsObject



106
107
108
# File 'lib/rbmount/table.rb', line 106

def nents
  Mount::C.mnt_table_get_nents(@pointer)
end

#next_child_fs(parent, direction = :forward) ⇒ Object



121
122
123
124
125
126
127
128
129
130
# File 'lib/rbmount/table.rb', line 121

def next_child_fs (parent, direction=:forward)
  Mount::FS.new.tap {|fs|
    ptr = FFI::MemoryPointer.new(:pointer).write_pointer(fs.to_c)

    res = Mount::C.mnt_table_next_child_fs(@pointer, Mount::Iter.new(DIRECTION[direction]).to_c,
                                          parent.to_c, ptr)
    raise unless res
    break nil if res == 1
  }
end

#next_fs(direction = :forward) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/rbmount/table.rb', line 58

def next_fs (direction=:forward)
  Mount::FS.new.tap {|fs|
    ptr = FFI::MemoryPointer.new(:pointer).write_pointer(fs.to_c)

    res = Mount::C.mnt_table_next_fs(@pointer, Mount::Iter.new(DIRECTION[direction]).to_c, ptr)
    raise unless res
    break nil if res == 1
  }
end

#on_error(&blk) ⇒ Object



170
171
172
173
174
175
176
177
# File 'lib/rbmount/table.rb', line 170

def on_error (&blk)
  if blk.arity == 3
    Mount::C.mnt_table_set_iter(@pointer, blk)
    true
  else
    false
  end
end

#parse_file(path) ⇒ Object



142
143
144
# File 'lib/rbmount/table.rb', line 142

def parse_file (path)
  Mount::C.mnt_table_parse_file(@pointer, path)
end

#parse_fstab(path = nil) ⇒ Object



146
147
148
# File 'lib/rbmount/table.rb', line 146

def parse_fstab (path=nil)
  Mount::C.mnt_table_parse_fstab(@pointer, path)
end

#parse_mtab(path = nil) ⇒ Object



150
151
152
# File 'lib/rbmount/table.rb', line 150

def parse_mtab (path=nil)
  Mount::C.mnt_table_parse_mtab(@pointer, path)
end

#parse_stream(io, filename) ⇒ Object



154
155
156
# File 'lib/rbmount/table.rb', line 154

def parse_stream (io, filename)
  Mount::C.mnt_table_parse_stream(@pointer, io, filename)
end

#remove_fs(fs) ⇒ Object



158
159
160
# File 'lib/rbmount/table.rb', line 158

def remove_fs (fs)
  Mount::C.mnt_table_remove_fs(@pointer, fs.to_c)
end

#reset!Object



179
180
181
182
# File 'lib/rbmount/table.rb', line 179

def reset!
  raise unless Mount::C.mnt_reset_table(@pointer)
  self
end

#root_fsObject



110
111
112
113
114
115
# File 'lib/rbmount/table.rb', line 110

def root_fs
  Mount::FS.new.tap {|fs|
    ptr = FFI::MemoryPointer.new(:pointer).write_pointer(fs.to_c)
    raise unless Mount::C.mnt_table_get_root_fs(@pointer, ptr)
  }
end

#set_iter(fs, direction = :forward) ⇒ Object



166
167
168
# File 'lib/rbmount/table.rb', line 166

def set_iter (fs, direction=:forward)
  Mount::C.mnt_table_set_iter(@pointer, Mount::Iter.new(DIRECTION[direction]).to_c, fs.to_c)
end