rbmount 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ #--
2
+ # Copyleft shura. [ shura1991@gmail.com ]
3
+ #
4
+ # This file is part of rbmount.
5
+ #
6
+ # rbmount is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # rbmount is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with rbmount. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'rbmount/mount'
21
+ require 'rbmount/context'
22
+ require 'rbmount/cache'
23
+ require 'rbmount/fs'
24
+ require 'rbmount/iterator'
25
+ require 'rbmount/lock'
26
+ require 'rbmount/string'
27
+ require 'rbmount/table'
28
+ require 'rbmount/update'
@@ -0,0 +1,399 @@
1
+ #--
2
+ # Copyleft shura. [ shura1991@gmail.com ]
3
+ #
4
+ # This file is part of rbmount.
5
+ #
6
+ # rbmount is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # rbmount is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with rbmount. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'ffi'
21
+
22
+ module FFI
23
+ class Pointer
24
+ def get_libmnt_optmap (where)
25
+ Mount::C::OptMap.new(self + where).tap {|map|
26
+ break Mount::OptMap.new(*[:name, :id, :mask].map {|a| map[a] })
27
+ }
28
+ end
29
+ def read_libmnt_optmap
30
+ get_libmnt_optmap(0)
31
+ end
32
+
33
+ def put_libmnt_optmap (optmap, where)
34
+ put_string(where, [optmap.name, optmap.id, optmap.mask].pack('Pi!i!'))
35
+ self
36
+ end
37
+ def write_libmnt_optmap (optmap)
38
+ put_libmnt_optmap(optmap, 0)
39
+ self
40
+ end
41
+
42
+ def read_array_of_libmnt_optmap
43
+ map, offset = [], 0
44
+
45
+ begin
46
+ map << get_libmnt_optmap(offset)
47
+ offset += Mount::C::OptMap.size
48
+ end until map.last.instance_eval { [name, id, mask] } == [nil, 0, 0]
49
+
50
+ map.tap(&:pop)
51
+ end
52
+
53
+ def write_array_of_libmnt_optmap (optmap)
54
+ optmap.each_with_index {|opt, i|
55
+ put_libmnt_optmap(opt, i * Mount::C::OptMap.size)
56
+ }
57
+ put_libmnt_optmap(Mount::OptMap.new(nil, 0, 0), optmap.size * Mount::C::OptMap.size)
58
+ self
59
+ end
60
+
61
+ def self.from_array_of_libmnt_optmap (optmap)
62
+ self.new(:pointer, (optmap.size + 1) * Mount::C::OptMap.size).write_array_of_libmnt_optmap(optmap)
63
+ end
64
+ end
65
+ end
66
+
67
+ module Mount
68
+ module C
69
+ module Bool
70
+ extend FFI::DataConverter
71
+ native_type FFI::Type::UCHAR
72
+
73
+ def self.to_native(value, ctx)
74
+ [0, false, nil].include?(value) ? 0 : 1
75
+ end
76
+
77
+ def self.from_native(value, ctx)
78
+ !value.zero?
79
+ end
80
+ end
81
+
82
+ module MntBool
83
+ extend FFI::DataConverter
84
+ native_type FFI::Type::UCHAR
85
+
86
+ def self.to_native (value, ctx)
87
+ [0, false, nil].include?(value) ? 1 : 0
88
+ end
89
+
90
+ def self.from_native (value, ctx)
91
+ value.zero?
92
+ end
93
+ end
94
+
95
+ module MntCC
96
+ extend FFI::DataConverter
97
+ native_type FFI::Type::UCHAR
98
+
99
+ def self.to_native (value, ctx)
100
+ return 1 if value == nil
101
+ [0, false].include?(value) ? 1 : 0
102
+ end
103
+
104
+ def self.from_native (value, ctx)
105
+ return 1 if value == 1
106
+ value.zero?
107
+ end
108
+ end
109
+
110
+ module IO
111
+ extend FFI::DataConverter
112
+ native_type FFI::Type::POINTER
113
+
114
+ module CFunc
115
+ extend FFI::Library
116
+ ffi_lib FFI::Library::LIBC
117
+
118
+ attach_function :fdopen, [:int, :string], :pointer
119
+ attach_function :fileno, [:pointer], :int
120
+ end
121
+
122
+ def self.to_native (value, ctx)
123
+ Mount::C::IO::CFunc.fdopen(value.fileno, 'r+')
124
+ end
125
+
126
+ def self.from_native (value, ctx)
127
+ ::IO.for_fd(Mount::C::IO::CFunc.fileno(value), 'r+')
128
+ end
129
+ end
130
+
131
+ extend FFI::Library
132
+ FFI.typedef(Bool, :bool)
133
+ FFI.typedef(MntBool, :mnt_bool)
134
+ FFI.typedef(MntCC, :mntcc)
135
+ FFI.typedef(Mount::C::IO, :io)
136
+
137
+ callback :errcb, [:pointer, :string, :int], :int
138
+ callback :match_func, [:pointer, :pointer, :pointer], :int
139
+
140
+ class OptMap < FFI::Struct
141
+ layout \
142
+ :name, :string,
143
+ :id, :int,
144
+ :mask, :int
145
+ end
146
+
147
+ class MntEnt < FFI::Struct
148
+ layout \
149
+ :fsname, :string,
150
+ :dir, :string,
151
+ :type, :string,
152
+ :opts, :string,
153
+ :freq, :int,
154
+ :passno, :int
155
+ end
156
+
157
+ ffi_lib 'mount'
158
+
159
+ # context {{{
160
+ attach_function :mnt_free_context, [:pointer], :void
161
+ attach_function :mnt_new_context, [], :pointer
162
+ attach_function :mnt_reset_context, [:pointer], :mnt_bool
163
+ attach_function :mnt_context_append_options, [:pointer, :string], :mnt_bool
164
+ attach_function :mnt_context_apply_fstab, [:pointer], :mnt_bool
165
+ attach_function :mnt_context_disable_canonicalize, [:pointer, :bool], :mnt_bool
166
+ attach_function :mnt_context_disable_helpers, [:pointer, :bool], :mnt_bool
167
+ attach_function :mnt_context_disable_mtab, [:pointer, :bool], :mnt_bool
168
+ attach_function :mnt_context_enable_fake, [:pointer, :bool], :mnt_bool
169
+ attach_function :mnt_context_enable_force, [:pointer, :bool], :mnt_bool
170
+ attach_function :mnt_context_enable_lazy, [:pointer, :bool], :mnt_bool
171
+ attach_function :mnt_context_enable_loopdel, [:pointer, :bool], :mnt_bool
172
+ attach_function :mnt_context_enable_rdonly_umount, [:pointer, :bool], :mnt_bool
173
+ attach_function :mnt_context_enable_sloppy, [:pointer, :bool], :mnt_bool
174
+ attach_function :mnt_context_enable_verbose, [:pointer, :bool], :mnt_bool
175
+ attach_function :mnt_context_get_cache, [:pointer], :pointer
176
+ attach_function :mnt_context_get_fs, [:pointer], :pointer
177
+ attach_function :mnt_context_get_fstab, [:pointer, :pointer], :mnt_bool
178
+ attach_function :mnt_context_get_fstype, [:pointer], :string
179
+ attach_function :mnt_context_get_lock, [:pointer], :pointer
180
+ attach_function :mnt_context_get_mflags, [:pointer, :pointer], :mnt_bool
181
+ attach_function :mnt_context_get_mtab, [:pointer, :pointer], :mnt_bool
182
+ attach_function :mnt_context_get_optsmode, [:pointer], :int
183
+ attach_function :mnt_context_get_source, [:pointer], :string
184
+ attach_function :mnt_context_get_status, [:pointer], :int
185
+ #attach_function :mnt_context_get_table, [:pointer, :string, :pointer], :mnt_bool
186
+ attach_function :mnt_context_get_target, [:pointer], :string
187
+ attach_function :mnt_context_get_user_mflags, [:pointer, :pointer], :mnt_bool
188
+ attach_function :mnt_context_helper_setopt, [:pointer, :int, :string], :mnt_bool
189
+ attach_function :mnt_context_init_helper, [:pointer, :int, :int], :mnt_bool
190
+ attach_function :mnt_context_is_fake, [:pointer], :bool
191
+ attach_function :mnt_context_is_force, [:pointer], :bool
192
+ #attach_function :mnt_context_is_fs_mounted, [:pointer, :pointer, :pointer], :mnt_bool
193
+ attach_function :mnt_context_is_lazy, [:pointer], :bool
194
+ attach_function :mnt_context_is_nomtab, [:pointer], :bool
195
+ attach_function :mnt_context_is_rdonly_umount, [:pointer], :bool
196
+ attach_function :mnt_context_is_restricted, [:pointer], :bool
197
+ attach_function :mnt_context_is_sloppy, [:pointer], :bool
198
+ attach_function :mnt_context_is_verbose, [:pointer], :bool
199
+ attach_function :mnt_context_set_cache, [:pointer, :pointer], :mnt_bool
200
+ attach_function :mnt_context_set_fs, [:pointer, :pointer], :mnt_bool
201
+ attach_function :mnt_context_set_fstab, [:pointer, :pointer], :mnt_bool
202
+ attach_function :mnt_context_set_fstype, [:pointer, :string], :mnt_bool
203
+ attach_function :mnt_context_set_fstype_pattern, [:pointer, :string], :mnt_bool
204
+ attach_function :mnt_context_set_mflags, [:pointer, :ulong], :mnt_bool
205
+ attach_function :mnt_context_set_mountdata, [:pointer, :pointer], :mnt_bool
206
+ attach_function :mnt_context_set_options, [:pointer, :string], :mnt_bool
207
+ attach_function :mnt_context_set_options_pattern, [:pointer, :string], :mnt_bool
208
+ attach_function :mnt_context_set_optsmode, [:pointer, :int], :mnt_bool
209
+ attach_function :mnt_context_set_source, [:pointer, :string], :mnt_bool
210
+ attach_function :mnt_context_set_syscall_status, [:pointer, :int], :mnt_bool
211
+ #attach_function :mnt_context_set_tables_errcb, [:pointer, :errcb], :mnt_bool
212
+ attach_function :mnt_context_set_target, [:pointer, :string], :mnt_bool
213
+ attach_function :mnt_context_set_user_mflags, [:pointer, :ulong], :mnt_bool
214
+ attach_function :mnt_context_strerror, [:pointer, :pointer, :int], :mnt_bool
215
+
216
+ # mount context {{{
217
+ attach_function :mnt_context_do_mount, [:pointer], :mnt_bool
218
+ attach_function :mnt_context_finalize_mount, [:pointer], :mnt_bool
219
+ attach_function :mnt_context_mount, [:pointer], :mnt_bool
220
+ #attach_function :mnt_context_next_mount, [:pointer, :pointer, :pointer, :pointer, :pointer], :mntcc
221
+ attach_function :mnt_context_prepare_mount, [:pointer], :mnt_bool
222
+ # }}}
223
+
224
+ # umount context {{{
225
+ attach_function :mnt_context_do_umount, [:pointer], :mnt_bool
226
+ attach_function :mnt_context_finalize_umount, [:pointer], :mnt_bool
227
+ attach_function :mnt_context_prepare_umount, [:pointer], :mnt_bool
228
+ attach_function :mnt_context_umount, [:pointer], :mnt_bool
229
+ # }}}
230
+ # }}}
231
+
232
+ # table {{{
233
+ attach_function :mnt_free_table, [:pointer], :void
234
+ attach_function :mnt_new_table, [], :pointer
235
+ #attach_function :mnt_reset_table, [:pointer], :mnt_bool
236
+ attach_function :mnt_new_table_from_dir, [:string], :pointer
237
+ attach_function :mnt_new_table_from_file, [:string], :pointer
238
+ attach_function :mnt_table_add_fs, [:pointer, :pointer], :mnt_bool
239
+ attach_function :mnt_table_find_next_fs, [:pointer, :pointer, :match_func, :pointer, :pointer], :mnt_bool
240
+ attach_function :mnt_table_find_pair, [:pointer, :string, :string, :int], :pointer
241
+ attach_function :mnt_table_find_source, [:pointer, :string, :int], :pointer
242
+ attach_function :mnt_table_find_srcpath, [:pointer, :string, :int], :pointer
243
+ attach_function :mnt_table_find_tag, [:pointer, :string, :string, :int], :pointer
244
+ attach_function :mnt_table_find_target, [:pointer, :string, :int], :pointer
245
+ attach_function :mnt_table_get_cache, [:pointer], :pointer
246
+ #attach_function :mnt_table_get_name, [:pointer], :string
247
+ attach_function :mnt_table_get_nents, [:pointer], :int
248
+ attach_function :mnt_table_get_root_fs, [:pointer, :pointer], :mnt_bool
249
+ #attach_function :mnt_table_is_fs_mounted, [:pointer, :pointer], :bool
250
+ attach_function :mnt_table_next_child_fs, [:pointer, :pointer, :pointer, :pointer], :mnt_bool
251
+ attach_function :mnt_table_next_fs, [:pointer, :pointer, :pointer], :mnt_bool
252
+ attach_function :mnt_table_parse_file, [:pointer, :string], :mnt_bool
253
+ attach_function :mnt_table_parse_fstab, [:pointer, :string], :mnt_bool
254
+ attach_function :mnt_table_parse_mtab, [:pointer, :string], :mnt_bool
255
+ attach_function :mnt_table_parse_stream, [:pointer, :io, :string], :mnt_bool
256
+ attach_function :mnt_table_remove_fs, [:pointer, :pointer], :mnt_bool
257
+ attach_function :mnt_table_set_cache, [:pointer, :pointer], :mnt_bool
258
+ attach_function :mnt_table_set_iter, [:pointer, :pointer, :pointer], :mnt_bool
259
+ attach_function :mnt_table_set_parser_errcb, [:pointer, :errcb], :mnt_bool
260
+ # }}}
261
+
262
+ # filesystem {{{
263
+ attach_function :mnt_copy_fs, [:pointer, :pointer], :pointer
264
+ attach_function :mnt_free_fs, [:pointer], :void
265
+ attach_function :mnt_free_mntent, [:pointer], :void
266
+ attach_function :mnt_fs_append_attributes, [:pointer, :string], :mnt_bool
267
+ attach_function :mnt_fs_append_options, [:pointer, :string], :mnt_bool
268
+ attach_function :mnt_fs_get_attribute, [:pointer, :string, :pointer, :pointer], :mnt_bool
269
+ attach_function :mnt_fs_get_attributes, [:pointer], :string
270
+ attach_function :mnt_fs_get_bindsrc, [:pointer], :string
271
+ attach_function :mnt_fs_get_devno, [:pointer], :dev_t
272
+ attach_function :mnt_fs_get_freq, [:pointer], :int
273
+ attach_function :mnt_fs_get_fs_options, [:pointer], :string
274
+ attach_function :mnt_fs_get_fstype, [:pointer], :string
275
+ attach_function :mnt_fs_get_id, [:pointer], :int
276
+ attach_function :mnt_fs_get_option, [:pointer, :pointer, :pointer, :pointer], :mnt_bool
277
+ #attach_function :mnt_fs_get_options, [:pointer], :string
278
+ attach_function :mnt_fs_get_parent_id, [:pointer], :int
279
+ attach_function :mnt_fs_get_passno, [:pointer], :int
280
+ attach_function :mnt_fs_get_root, [:pointer], :string
281
+ attach_function :mnt_fs_get_source, [:pointer], :string
282
+ attach_function :mnt_fs_get_srcpath, [:pointer], :string
283
+ attach_function :mnt_fs_get_tag, [:pointer, :pointer, :pointer], :mnt_bool
284
+ attach_function :mnt_fs_get_target, [:pointer], :string
285
+ attach_function :mnt_fs_get_userdata, [:pointer], :pointer
286
+ attach_function :mnt_fs_get_user_options, [:pointer], :string
287
+ attach_function :mnt_fs_get_vfs_options, [:pointer], :string
288
+ attach_function :mnt_fs_is_kernel, [:pointer], :mnt_bool
289
+ attach_function :mnt_fs_match_fstype, [:pointer, :string], :bool
290
+ attach_function :mnt_fs_match_options, [:pointer, :string], :bool
291
+ attach_function :mnt_fs_match_source, [:pointer, :string, :pointer], :bool
292
+ attach_function :mnt_fs_match_target, [:pointer, :string, :pointer], :bool
293
+ attach_function :mnt_fs_prepend_attributes, [:pointer, :string], :mnt_bool
294
+ attach_function :mnt_fs_prepend_options, [:pointer, :string], :mnt_bool
295
+ attach_function :mnt_fs_print_debug, [:pointer, :io], :mnt_bool
296
+ attach_function :mnt_fs_set_attributes, [:pointer, :string], :mnt_bool
297
+ attach_function :mnt_fs_set_bindsrc, [:pointer, :string], :mnt_bool
298
+ attach_function :mnt_fs_set_freq, [:pointer, :int], :mnt_bool
299
+ attach_function :mnt_fs_set_fstype, [:pointer, :string], :mnt_bool
300
+ attach_function :mnt_fs_set_options, [:pointer, :string], :mnt_bool
301
+ attach_function :mnt_fs_set_passno, [:pointer, :int], :mnt_bool
302
+ attach_function :mnt_fs_set_root, [:pointer, :string], :mnt_bool
303
+ attach_function :mnt_fs_set_source, [:pointer, :string], :mnt_bool
304
+ attach_function :mnt_fs_set_target, [:pointer, :string], :mnt_bool
305
+ attach_function :mnt_fs_set_userdata, [:pointer, :pointer], :mnt_bool
306
+ attach_function :mnt_fs_strdup_options, [:pointer], :string
307
+ attach_function :mnt_fs_to_mntent, [:pointer, :pointer], :mnt_bool
308
+ attach_function :mnt_new_fs, [], :pointer
309
+ attach_function :mnt_reset_fs, [:pointer], :void
310
+ # }}}
311
+
312
+ # locking {{{
313
+ attach_function :mnt_free_lock, [:pointer], :void
314
+ attach_function :mnt_lock_file, [:pointer], :mnt_bool
315
+ attach_function :mnt_new_lock, [:string, :pid_t], :pointer
316
+ attach_function :mnt_unlock_file, [:pointer], :void
317
+ attach_function :mnt_lock_block_signals, [:pointer, :bool], :mnt_bool
318
+ # }}}
319
+
320
+ # tables update {{{
321
+ attach_function :mnt_free_update, [:pointer], :void
322
+ attach_function :mnt_new_update, [], :pointer
323
+ attach_function :mnt_update_force_rdonly, [:pointer, :bool], :mnt_bool
324
+ attach_function :mnt_update_get_filename, [:pointer], :string
325
+ attach_function :mnt_update_get_fs, [:pointer], :pointer
326
+ attach_function :mnt_update_get_mflags, [:pointer], :ulong
327
+ attach_function :mnt_update_is_ready, [:pointer], :bool
328
+ attach_function :mnt_update_set_fs, [:pointer, :ulong, :string, :pointer], :mnt_bool
329
+ attach_function :mnt_update_table, [:pointer, :pointer], :mnt_bool
330
+ # }}}
331
+
332
+ # monitor mountinfo changes {{{
333
+ #attach_function :mnt_new_tabdiff, [], :pointer
334
+ #attach_function :mnt_free_tabdiff, [:pointer], :void
335
+ #attach_function :mnt_tabdiff_next_change, [:pointer, :pointer, :pointer, :pointer, :pointer], :mnt_bool
336
+ #attach_function :mnt_diff_tables, [:pointer, :pointer, :pointer], :int
337
+ # }}}
338
+
339
+ # option string {{{
340
+ attach_function :mnt_optstr_append_option, [:pointer, :string, :string], :mnt_bool
341
+ attach_function :mnt_optstr_apply_flags, [:pointer, :ulong, :pointer], :mnt_bool
342
+ attach_function :mnt_optstr_get_flags, [:string, :pointer, :pointer], :mnt_bool
343
+ attach_function :mnt_optstr_get_option, [:string, :string, :pointer, :pointer], :mnt_bool
344
+ attach_function :mnt_optstr_get_options, [:string, :pointer, :pointer, :int], :mnt_bool
345
+ attach_function :mnt_optstr_next_option, [:pointer, :pointer, :pointer, :pointer, :pointer], :mntcc
346
+ attach_function :mnt_optstr_prepend_option, [:pointer, :string, :string], :mnt_bool
347
+ attach_function :mnt_optstr_remove_option, [:pointer, :string], :mnt_bool
348
+ attach_function :mnt_optstr_set_option, [:pointer, :string, :string], :mnt_bool
349
+ attach_function :mnt_split_optstr, [:string, :pointer, :pointer, :pointer, :int, :int], :mnt_bool
350
+ # }}}
351
+
352
+ # option maps {{{
353
+ attach_function :mnt_get_builtin_optmap, [:int], :pointer
354
+ # }}}
355
+
356
+ # initialization {{{
357
+ attach_function :mnt_init_debug, [:int], :void
358
+ # }}}
359
+
360
+ # cache {{{
361
+ attach_function :mnt_new_cache, [], :pointer
362
+ attach_function :mnt_free_cache, [:pointer], :void
363
+ attach_function :mnt_cache_device_has_tag, [:pointer, :string, :string, :string], :bool
364
+ attach_function :mnt_cache_find_tag_value, [:pointer, :string, :string], :string
365
+ attach_function :mnt_cache_read_tags, [:pointer, :string], :mnt_bool
366
+ attach_function :mnt_get_fstype, [:string, :pointer, :pointer], :string
367
+ #attach_function :mnt_pretty_path, [:string, :pointer], :string
368
+ attach_function :mnt_resolve_path, [:string, :pointer], :string
369
+ attach_function :mnt_resolve_spec, [:string, :pointer], :string
370
+ attach_function :mnt_resolve_tag, [:string, :string, :pointer], :string
371
+ # }}}
372
+
373
+ # iterator {{{
374
+ attach_function :mnt_free_iter, [:pointer], :void
375
+ attach_function :mnt_iter_get_direction, [:pointer], :int
376
+ attach_function :mnt_new_iter, [:int], :pointer
377
+ attach_function :mnt_reset_iter, [:pointer, :int], :void
378
+ # }}}
379
+
380
+ # utils {{{
381
+ attach_function :mnt_fstype_is_netfs, [:string], :bool
382
+ attach_function :mnt_fstype_is_pseudofs, [:string], :bool
383
+ attach_function :mnt_get_fstab_path, [], :string
384
+ attach_function :mnt_get_fstype, [:string, :pointer, :pointer], :string
385
+ attach_function :mnt_get_library_version, [:pointer], :int
386
+ attach_function :mnt_get_mtab_path, [], :string
387
+ attach_function :mnt_has_regular_mtab, [:pointer, :pointer], :bool
388
+ attach_function :mnt_mangle, [:string], :string
389
+ attach_function :mnt_match_fstype, [:string, :string], :bool
390
+ attach_function :mnt_match_options, [:string, :string], :bool
391
+ attach_function :mnt_unmangle, [:string], :string
392
+ # }}}
393
+
394
+ # version {{{
395
+ attach_function :mnt_parse_version_string, [:string], :int
396
+ attach_function :mnt_get_library_version, [:pointer], :int
397
+ # }}}
398
+ end
399
+ end
@@ -0,0 +1,76 @@
1
+ #--
2
+ # Copyleft shura. [ shura1991@gmail.com ]
3
+ #
4
+ # This file is part of rbmount.
5
+ #
6
+ # rbmount is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # rbmount is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with rbmount. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'rbmount/c'
21
+
22
+ module Mount
23
+ class Cache
24
+ def initialize (ptr=nil)
25
+ @pointer= ptr
26
+ @pointer = Mount::C.mnt_new_fs unless @pointer
27
+ raise if @pointer.null?
28
+
29
+ ObjectSpace.define_finalizer(self, method(:finalize))
30
+ end
31
+
32
+ def has_tag? (devname, token, value)
33
+ Mount::C.mnt_cache_device_has_tag(@pointer, devname, token, value)
34
+ end
35
+ alias tag? has_tag?
36
+
37
+ def tag (devname, token)
38
+ Mount::C.mnt_cache_find_tag_value(@pointer, devname, token)
39
+ end
40
+
41
+ def read_tags (devname)
42
+ Mount::C.mnt_cache_read_tags(@pointer, devname)
43
+ end
44
+
45
+ def fs_type (devname, amb=false)
46
+ ambi = amb ? FFI::MemoryPointer.new(:int) : nil
47
+ fs = Mount::C.mnt_get_fstype(devname, ambi, @pointer)
48
+
49
+ amb ? [fs, ambi.read_int] : fs
50
+ end
51
+
52
+ def pretty_path (devname)
53
+ Mount::C.mnt_pretty_path(devname, @pointer)
54
+ end
55
+
56
+ def resolve_path (path)
57
+ Mount::C.mnt_resolve_path(path, @pointer)
58
+ end
59
+
60
+ def resolve_spec (spec)
61
+ Mount::C.mnt_resolve_spec(spec, @pointer)
62
+ end
63
+
64
+ def resolve_tag (token, value)
65
+ Mount::C.mnt_resolve_tag(token, value, @pointer)
66
+ end
67
+
68
+ def finalize (id=nil)
69
+ Mount::C.mnt_free_cache(@pointer)
70
+ end
71
+
72
+ def to_c
73
+ @pointer
74
+ end
75
+ end
76
+ end