rblkid 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rblkid.rb +134 -0
- data/lib/rblkid/c.rb +31 -0
- data/lib/rblkid/c/functions.rb +146 -0
- data/lib/rblkid/c/types.rb +231 -0
- data/lib/rblkid/cache.rb +72 -0
- data/lib/rblkid/constants.rb +52 -0
- data/lib/rblkid/dev.rb +46 -0
- data/lib/rblkid/dev_iterate.rb +63 -0
- data/lib/rblkid/partition.rb +81 -0
- data/lib/rblkid/partlist.rb +53 -0
- data/lib/rblkid/parttable.rb +45 -0
- data/lib/rblkid/probe.rb +145 -0
- data/lib/rblkid/tag_iterate.rb +59 -0
- data/lib/rblkid/topology.rb +52 -0
- metadata +89 -0
data/lib/rblkid.rb
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'rblkid/constants'
|
|
21
|
+
require 'rblkid/c'
|
|
22
|
+
|
|
23
|
+
require 'rblkid/dev'
|
|
24
|
+
require 'rblkid/cache'
|
|
25
|
+
require 'rblkid/dev_iterate'
|
|
26
|
+
require 'rblkid/partition'
|
|
27
|
+
require 'rblkid/partlist'
|
|
28
|
+
require 'rblkid/parttable'
|
|
29
|
+
require 'rblkid/probe'
|
|
30
|
+
require 'rblkid/tag_iterate'
|
|
31
|
+
require 'rblkid/topology'
|
|
32
|
+
|
|
33
|
+
module BlkID
|
|
34
|
+
class << self
|
|
35
|
+
def evaluate_tag (token, value, cache=nil)
|
|
36
|
+
cache = cache.ptr if cache.is_a?(BlkID::Cache)
|
|
37
|
+
|
|
38
|
+
BlkID::C.blkid_evaluate_tag(token, value, cache)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def evaluate_spec(spec, cache=nil)
|
|
42
|
+
cache = cache.ptr if cache.is_a?(BlkID::Cache)
|
|
43
|
+
|
|
44
|
+
BlkID::C.evaluate_spec(spec, cache)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def known_fstype? (fstype)
|
|
48
|
+
BlkID::C.blkid_known_fstype(fstype)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def name (idx)
|
|
52
|
+
name = FFI::MemoryPointer.new(:string)
|
|
53
|
+
usage = FFI::MemoryPointer.new(:int)
|
|
54
|
+
|
|
55
|
+
BlkID::C.blkid_superblocks_get_name(idx, FFI::MemoryPointer.new(:pointer).write_pointer(name), usage).tap {|res|
|
|
56
|
+
break [name.read_string, usage.read_int] if res
|
|
57
|
+
}
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def filter_superblocks_type (flag, names)
|
|
61
|
+
n = FFI::MemoryPointer.new(:pointer, names.size + 1)
|
|
62
|
+
names.each_with_index {|s, i|
|
|
63
|
+
n[i].put_pointer(0, FFI::MemoryPointer.from_string(s))
|
|
64
|
+
}
|
|
65
|
+
n[names.size].put_pointer(0, nil)
|
|
66
|
+
|
|
67
|
+
BlkID::C.blkid_probe_filter_superblocks_type(@struct, flag, n)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def filter_superblocks_usage (flag, usage)
|
|
71
|
+
BlkID::C.blkid_probe_filter_superblocks_usage(@struct, flag, usage)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def invert_superblocks_filter
|
|
75
|
+
BlkID::C.blkid_probe_invert_superblocks_filter(@struct)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def reset_superblocks_filter
|
|
79
|
+
BlkID::C.blkid_probe_reset_superblocks_filter(@struct)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def superblocks_flags= (flags)
|
|
83
|
+
BlkID::C.blkid_probe_set_superblocks_flags(@struct, flags)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def partitions= (bool)
|
|
87
|
+
BlkID::C.blkid_probe_enable_partitions(@struct, bool)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def partitions_flags= (flags)
|
|
91
|
+
BlkID::C.blkid_probe_set_partitions_flags(@struct, flags)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def filter_partitions_type (flag, names)
|
|
95
|
+
n = FFI::MemoryPointer.new(:pointer, names.size + 1)
|
|
96
|
+
names.each_with_index {|s, i|
|
|
97
|
+
n[i].put_pointer(0, FFI::MemoryPointer.from_string(s))
|
|
98
|
+
}
|
|
99
|
+
n[names.size].put_pointer(0, nil)
|
|
100
|
+
|
|
101
|
+
BlkID::C.blkid_probe_filter_partitions_type(@struct, flag, n)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def invert_partitions_filter
|
|
105
|
+
BlkID::C.blkid_probe_invert_partitions_filter(@struct)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def reset_partitions_filter
|
|
109
|
+
BlkID::C.blkid_probe_reset_partitions_filter(@struct)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def known_pttype? (pttype)
|
|
113
|
+
BlkID::C.blkid_known_pttype(pttype)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def devno_to_devname (devno)
|
|
117
|
+
BlkID::C.blkid_devno_to_devname(devno)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def devno_to_wholedisk (dev)
|
|
121
|
+
diskdevno = FFI::MemoryPointer.new(:ulong, 1)
|
|
122
|
+
BlkID::C.blkid_devno_to_wholedisk(dev, nil, 0, diskdevno)
|
|
123
|
+
diskdevno.read_ulong
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def dev_size (fd)
|
|
127
|
+
BlkID::C.blkid_get_dev_size(fd)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def send_uevent (devname, action)
|
|
131
|
+
BlkID::C.blkid_send_uevent(devname, action)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
data/lib/rblkid/c.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'ffi'
|
|
21
|
+
require 'rblkid/constants'
|
|
22
|
+
|
|
23
|
+
module BlkID
|
|
24
|
+
module C
|
|
25
|
+
extend FFI::Library
|
|
26
|
+
ffi_lib ['blkid', 'libblkid.so.1']
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
require 'rblkid/c/types'
|
|
31
|
+
require 'rblkid/c/functions'
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'rblkid/c/types'
|
|
21
|
+
|
|
22
|
+
module BlkID
|
|
23
|
+
module C
|
|
24
|
+
# evaluate {{{
|
|
25
|
+
attach_function :blkid_evaluate_tag, [:string, :string, :pointer], :string
|
|
26
|
+
attach_function :blkid_send_uevent, [:string, :string], :blkid_bool
|
|
27
|
+
#attach_function :blkid_evaluate_spec, [:string, :pointer], :string
|
|
28
|
+
# }}}
|
|
29
|
+
|
|
30
|
+
# cache {{{
|
|
31
|
+
attach_function :blkid_gc_cache, [BlkIDCache], :void
|
|
32
|
+
attach_function :blkid_get_cache, [:pointer, :string], :blkid_bool
|
|
33
|
+
attach_function :blkid_put_cache, [BlkIDCache], :void
|
|
34
|
+
attach_function :blkid_probe_all, [BlkIDCache], :blkid_bool
|
|
35
|
+
attach_function :blkid_probe_all_removable, [BlkIDCache], :blkid_bool
|
|
36
|
+
attach_function :blkid_probe_all_new, [BlkIDCache], :blkid_bool
|
|
37
|
+
attach_function :blkid_verify, [BlkIDCache, BlkIDDev], BlkIDDev
|
|
38
|
+
# }}}
|
|
39
|
+
|
|
40
|
+
# search and iterate {{{
|
|
41
|
+
attach_function :blkid_dev_devname, [BlkIDDev], :string
|
|
42
|
+
attach_function :blkid_dev_has_tag, [BlkIDDev, :string, :string], :bool
|
|
43
|
+
attach_function :blkid_dev_iterate_begin, [BlkIDCache], BlkIDDevIterate
|
|
44
|
+
attach_function :blkid_dev_iterate_end, [BlkIDDevIterate], :void
|
|
45
|
+
attach_function :blkid_dev_next, [BlkIDDevIterate, :pointer], :blkid_bool
|
|
46
|
+
attach_function :blkid_dev_set_search, [BlkIDDevIterate, :string, :string], :blkid_bool
|
|
47
|
+
attach_function :blkid_find_dev_with_tag, [BlkIDCache, :string, :string], BlkIDDev
|
|
48
|
+
attach_function :blkid_get_dev, [BlkIDCache, :string, :int], BlkIDDev
|
|
49
|
+
attach_function :blkid_get_devname, [BlkIDCache, :string, :string], :string
|
|
50
|
+
attach_function :blkid_tag_iterate_begin, [BlkIDDev], BlkIDTagIterate
|
|
51
|
+
attach_function :blkid_tag_iterate_end, [BlkIDTagIterate], :void
|
|
52
|
+
attach_function :blkid_tag_next, [BlkIDTagIterate, :pointer, :pointer], :blkid_bool
|
|
53
|
+
# }}}
|
|
54
|
+
|
|
55
|
+
# low-level probing {{{
|
|
56
|
+
attach_function :blkid_free_probe, [BlkIDProbe], :void
|
|
57
|
+
attach_function :blkid_new_probe, [], BlkIDProbe
|
|
58
|
+
attach_function :blkid_new_probe_from_filename, [:string], BlkIDProbe
|
|
59
|
+
attach_function :blkid_probe_get_devno, [BlkIDProbe], :dev_t
|
|
60
|
+
attach_function :blkid_probe_get_fd, [BlkIDProbe], :int
|
|
61
|
+
attach_function :blkid_probe_get_sectorsize, [BlkIDProbe], :uint
|
|
62
|
+
attach_function :blkid_probe_get_sectors, [BlkIDProbe], :blkid_loff_t
|
|
63
|
+
attach_function :blkid_probe_get_size, [BlkIDProbe], :blkid_loff_t
|
|
64
|
+
attach_function :blkid_probe_get_offset, [BlkIDProbe], :blkid_loff_t
|
|
65
|
+
attach_function :blkid_probe_get_wholedisk_devno, [BlkIDProbe], :dev_t
|
|
66
|
+
attach_function :blkid_probe_set_device, [BlkIDProbe, :int, :blkid_loff_t, :blkid_loff_t], :int
|
|
67
|
+
attach_function :blkid_probe_is_wholedisk, [BlkIDProbe], :bool
|
|
68
|
+
attach_function :blkid_reset_probe, [BlkIDProbe], :void
|
|
69
|
+
# }}}
|
|
70
|
+
|
|
71
|
+
# low-level tags {{{
|
|
72
|
+
attach_function :blkid_do_fullprobe, [BlkIDProbe], :blkid_bool
|
|
73
|
+
attach_function :blkid_do_probe, [BlkIDProbe], :blkid_bool
|
|
74
|
+
attach_function :blkid_do_safeprobe, [BlkIDProbe], :blkid_bool
|
|
75
|
+
attach_function :blkid_probe_get_value, [BlkIDProbe, :int, :pointer, :pointer, :pointer], :int
|
|
76
|
+
attach_function :blkid_probe_has_value, [BlkIDProbe, :string], :bool
|
|
77
|
+
attach_function :blkid_probe_lookup_value, [BlkIDProbe, :string, :pointer, :pointer], :blkid_bool
|
|
78
|
+
attach_function :blkid_probe_numof_values, [BlkIDProbe], :int
|
|
79
|
+
# }}}
|
|
80
|
+
|
|
81
|
+
# superblocks probing {{{
|
|
82
|
+
attach_function :blkid_probe_enable_superblocks, [BlkIDProbe, :bool], :blkid_bool
|
|
83
|
+
attach_function :blkid_known_fstype, [:string], :bool
|
|
84
|
+
attach_function :blkid_superblocks_get_name, [:uint, :pointer, :pointer], :blkid_bool
|
|
85
|
+
attach_function :blkid_probe_filter_superblocks_type, [BlkIDProbe, :int, :pointer], :blkid_bool
|
|
86
|
+
attach_function :blkid_probe_filter_superblocks_usage, [BlkIDProbe, :int, :int], :blkid_bool
|
|
87
|
+
attach_function :blkid_probe_invert_superblocks_filter, [BlkIDProbe], :blkid_bool
|
|
88
|
+
attach_function :blkid_probe_reset_superblocks_filter, [BlkIDProbe], :blkid_bool
|
|
89
|
+
attach_function :blkid_probe_set_superblocks_flags, [BlkIDProbe, :int], :blkid_bool
|
|
90
|
+
attach_function :blkid_probe_reset_filter, [BlkIDProbe], :blkid_bool
|
|
91
|
+
attach_function :blkid_probe_filter_types, [BlkIDProbe, :int, :pointer], :blkid_bool
|
|
92
|
+
attach_function :blkid_probe_filter_usage, [BlkIDProbe, :int, :int], :blkid_bool
|
|
93
|
+
attach_function :blkid_probe_invert_filter, [BlkIDProbe], :blkid_bool
|
|
94
|
+
attach_function :blkid_probe_set_request, [BlkIDProbe, :int], :blkid_bool
|
|
95
|
+
# }}}
|
|
96
|
+
|
|
97
|
+
# partitions probing {{{
|
|
98
|
+
attach_function :blkid_probe_enable_partitions, [BlkIDProbe, :bool], :blkid_bool
|
|
99
|
+
attach_function :blkid_probe_set_partitions_flags, [BlkIDProbe, :int], :blkid_bool
|
|
100
|
+
attach_function :blkid_probe_filter_partitions_type, [BlkIDProbe, :int, :pointer], :blkid_bool
|
|
101
|
+
attach_function :blkid_probe_invert_partitions_filter, [BlkIDProbe], :blkid_bool
|
|
102
|
+
attach_function :blkid_probe_reset_partitions_filter, [BlkIDProbe], :blkid_bool
|
|
103
|
+
attach_function :blkid_known_pttype, [:string], :bool
|
|
104
|
+
attach_function :blkid_partition_get_name, [BlkIDPartition], :string
|
|
105
|
+
attach_function :blkid_partition_get_flags, [BlkIDPartition], :ulong_long
|
|
106
|
+
attach_function :blkid_partition_get_partno, [BlkIDPartition], :int
|
|
107
|
+
attach_function :blkid_partition_get_size, [BlkIDPartition], :blkid_loff_t
|
|
108
|
+
attach_function :blkid_partition_get_start, [BlkIDPartition], :blkid_loff_t
|
|
109
|
+
attach_function :blkid_partition_get_table, [BlkIDPartition], BlkIDPartTable
|
|
110
|
+
attach_function :blkid_partition_get_type, [BlkIDPartition], :int
|
|
111
|
+
attach_function :blkid_partition_get_type_string, [BlkIDPartition], :string
|
|
112
|
+
attach_function :blkid_partition_get_uuid, [BlkIDPartition], :string
|
|
113
|
+
attach_function :blkid_partition_is_extended, [BlkIDPartition], :bool
|
|
114
|
+
attach_function :blkid_partition_is_logical, [BlkIDPartition], :bool
|
|
115
|
+
attach_function :blkid_partition_is_primary, [BlkIDPartition], :bool
|
|
116
|
+
attach_function :blkid_partlist_get_partition, [BlkIDPartList, :int], BlkIDPartition
|
|
117
|
+
attach_function :blkid_partlist_numof_partitions, [BlkIDPartList], :int
|
|
118
|
+
attach_function :blkid_partlist_devno_to_partition, [BlkIDPartList, :dev_t], BlkIDPartition
|
|
119
|
+
attach_function :blkid_partlist_get_table, [BlkIDPartList], BlkIDPartTable
|
|
120
|
+
attach_function :blkid_parttable_get_offset, [BlkIDPartTable], :blkid_loff_t
|
|
121
|
+
attach_function :blkid_parttable_get_parent, [BlkIDPartTable], BlkIDPartition
|
|
122
|
+
attach_function :blkid_parttable_get_type, [BlkIDPartTable], :string
|
|
123
|
+
attach_function :blkid_probe_get_partitions, [BlkIDProbe], BlkIDPartList
|
|
124
|
+
# }}}
|
|
125
|
+
|
|
126
|
+
# Topology information {{{
|
|
127
|
+
attach_function :blkid_probe_enable_topology, [BlkIDProbe, :bool], :blkid_bool
|
|
128
|
+
attach_function :blkid_probe_get_topology, [BlkIDProbe], BlkIDTopology
|
|
129
|
+
attach_function :blkid_topology_get_alignment_offset, [BlkIDTopology], :ulong
|
|
130
|
+
attach_function :blkid_topology_get_logical_sector_size, [BlkIDTopology], :ulong
|
|
131
|
+
attach_function :blkid_topology_get_minimum_io_size, [BlkIDTopology], :ulong
|
|
132
|
+
attach_function :blkid_topology_get_optimal_io_size, [BlkIDTopology], :ulong
|
|
133
|
+
attach_function :blkid_topology_get_physical_sector_size, [BlkIDTopology], :ulong
|
|
134
|
+
# }}}
|
|
135
|
+
|
|
136
|
+
# Miscellaneous utils {{{
|
|
137
|
+
attach_function :blkid_devno_to_devname, [:dev_t], :string
|
|
138
|
+
attach_function :blkid_devno_to_wholedisk, [:dev_t, :string, :size_t, :pointer], :blkid_bool
|
|
139
|
+
attach_function :blkid_get_dev_size, [:int], :blkid_loff_t
|
|
140
|
+
attach_function :blkid_get_library_version, [:pointer, :pointer], :int
|
|
141
|
+
attach_function :blkid_parse_tag_string, [:string, :pointer, :pointer], :int
|
|
142
|
+
attach_function :blkid_parse_version_string, [:string], :int
|
|
143
|
+
attach_function :blkid_send_uevent, [:string, :string], :blkid_bool
|
|
144
|
+
# }}}
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'rblkid/c'
|
|
21
|
+
|
|
22
|
+
module BlkID
|
|
23
|
+
module C
|
|
24
|
+
module Bool
|
|
25
|
+
extend FFI::DataConverter
|
|
26
|
+
native_type FFI::Type::INT
|
|
27
|
+
|
|
28
|
+
def self.to_native(value, ctx)
|
|
29
|
+
[0, false, nil].include?(value) ? 0 : 1
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.from_native(value, ctx)
|
|
33
|
+
!value.zero?
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
module BlkIDBool
|
|
38
|
+
extend FFI::DataConverter
|
|
39
|
+
native_type FFI::Type::INT
|
|
40
|
+
|
|
41
|
+
def self.to_native (value, ctx)
|
|
42
|
+
[0, false, nil].include?(value) ? 1 : 0
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.from_native (value, ctx)
|
|
46
|
+
value.zero?
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
FFI.typedef(Bool, :bool)
|
|
51
|
+
FFI.typedef(BlkIDBool, :blkid_bool)
|
|
52
|
+
FFI.typedef(:int64, :blkid_loff_t)
|
|
53
|
+
|
|
54
|
+
class ListHead < FFI::Struct
|
|
55
|
+
layout \
|
|
56
|
+
:next, :pointer,
|
|
57
|
+
:prev, :pointer
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
class BlkIDCache < FFI::Struct
|
|
61
|
+
layout \
|
|
62
|
+
:bic_devs, ListHead,
|
|
63
|
+
:bic_tags, ListHead,
|
|
64
|
+
:bic_time, :time_t,
|
|
65
|
+
:bic_ftime, :time_t,
|
|
66
|
+
:bic_flags, :uint,
|
|
67
|
+
:bic_filename, :pointer
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class BlkIDDev < FFI::Struct
|
|
71
|
+
layout \
|
|
72
|
+
:bid_devs, ListHead,
|
|
73
|
+
:bid_tags, ListHead,
|
|
74
|
+
:bid_cache, BlkIDCache,
|
|
75
|
+
:bid_name, :pointer,
|
|
76
|
+
:bid_type, :pointer,
|
|
77
|
+
:bid_pri, :int,
|
|
78
|
+
:bid_devno, :dev_t,
|
|
79
|
+
:bid_time, :time_t,
|
|
80
|
+
:bid_flags, :uint,
|
|
81
|
+
:bid_label, :pointer,
|
|
82
|
+
:bid_uuid, :pointer
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
class BlkIDTag < FFI::Struct
|
|
86
|
+
layout \
|
|
87
|
+
:bit_tags, ListHead,
|
|
88
|
+
:bit_names, ListHead,
|
|
89
|
+
:bit_name, :pointer,
|
|
90
|
+
:bit_val, :pointer,
|
|
91
|
+
:bit_dev, BlkIDDev
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
class BlkIDDevIterate < FFI::Struct
|
|
95
|
+
layout \
|
|
96
|
+
:magic, :int,
|
|
97
|
+
:cache, BlkIDCache,
|
|
98
|
+
:search_type, :pointer,
|
|
99
|
+
:search_value, :pointer,
|
|
100
|
+
:p, :pointer
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
class BlkIDTagIterate < FFI::Struct
|
|
104
|
+
layout \
|
|
105
|
+
:magic, :int,
|
|
106
|
+
:dev, BlkIDDev,
|
|
107
|
+
:p, :pointer
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
class BlkIDIdMag < FFI::Struct
|
|
111
|
+
layout \
|
|
112
|
+
:magic, :pointer,
|
|
113
|
+
:len, :uint,
|
|
114
|
+
:kboff, :long,
|
|
115
|
+
:sboff, :uint
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
class BlkIDPrVal < FFI::Struct
|
|
119
|
+
layout \
|
|
120
|
+
:name, :pointer,
|
|
121
|
+
:data, :pointer,
|
|
122
|
+
:len, :uint,
|
|
123
|
+
:chain, :pointer
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
class BlkIDProbe < FFI::Struct
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
callback :probefunccb, [BlkIDProbe, BlkIDIdMag], :int
|
|
130
|
+
|
|
131
|
+
class BlkIDIdInfo < FFI::Struct
|
|
132
|
+
layout \
|
|
133
|
+
:name, :pointer,
|
|
134
|
+
:usage, :int,
|
|
135
|
+
:flags, :int,
|
|
136
|
+
:minsz, :int,
|
|
137
|
+
:probefunc, :probefunccb,
|
|
138
|
+
:magics, :pointer
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
callback :probecb, [BlkIDProbe, :pointer], :int
|
|
142
|
+
callback :safeprobecb, [BlkIDProbe, :pointer], :int
|
|
143
|
+
callback :free_datacb, [BlkIDProbe, :pointer], :void
|
|
144
|
+
|
|
145
|
+
class BlkIDChainDrv < FFI::Struct
|
|
146
|
+
layout \
|
|
147
|
+
:id, :int,
|
|
148
|
+
:name, :string,
|
|
149
|
+
:dflt_flags, :int,
|
|
150
|
+
:dflt_enabled, :int,
|
|
151
|
+
:has_fltr, :int,
|
|
152
|
+
:idinfos, :pointer,
|
|
153
|
+
:nidinfos, :uint,
|
|
154
|
+
:probe, :probecb,
|
|
155
|
+
:safeprobe, :safeprobecb,
|
|
156
|
+
:free_data, :free_datacb
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
class BlkIDChain < FFI::Struct
|
|
160
|
+
layout \
|
|
161
|
+
:driver, :pointer,
|
|
162
|
+
:enabled, :int,
|
|
163
|
+
:flags, :int,
|
|
164
|
+
:binary, :int,
|
|
165
|
+
:idx, :int,
|
|
166
|
+
:fltr, :ulong,
|
|
167
|
+
:data, :pointer
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
class BlkIDProbe
|
|
171
|
+
layout \
|
|
172
|
+
:fd, :int,
|
|
173
|
+
:off, :blkid_loff_t,
|
|
174
|
+
:size, :blkid_loff_t,
|
|
175
|
+
:devno, :dev_t,
|
|
176
|
+
:disk_devno, :dev_t,
|
|
177
|
+
:blkssz, :uint,
|
|
178
|
+
:mode, :mode_t,
|
|
179
|
+
:flags, :int,
|
|
180
|
+
:prob_flags, :int,
|
|
181
|
+
:wipe_off, :blkid_loff_t,
|
|
182
|
+
:wipe_size, :blkid_loff_t,
|
|
183
|
+
:wipe_chain, :pointer,
|
|
184
|
+
:buffers, ListHead,
|
|
185
|
+
:chains, [BlkIDChain, BlkID::BLKID_NCHAINS],
|
|
186
|
+
:cur_chain, :pointer,
|
|
187
|
+
:vals, [BlkIDPrVal, BlkID::BLKID_NVALS],
|
|
188
|
+
:nvals, :int
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
class BlkIDPartition < FFI::Struct
|
|
192
|
+
layout \
|
|
193
|
+
:start, :blkid_loff_t,
|
|
194
|
+
:size, :blkid_loff_t,
|
|
195
|
+
:type, :int,
|
|
196
|
+
:typestr, [:char, 37],
|
|
197
|
+
:flags, :ulong_long,
|
|
198
|
+
:partno, :int,
|
|
199
|
+
:uuid, [:char, 37],
|
|
200
|
+
:name, [:uchar, 128]
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
class BlkIDPartTable < FFI::Struct
|
|
204
|
+
layout \
|
|
205
|
+
:type, :pointer,
|
|
206
|
+
:offset, :blkid_loff_t,
|
|
207
|
+
:nparts, :int,
|
|
208
|
+
:parent, BlkIDPartition,
|
|
209
|
+
:t_tabs, ListHead
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
class BlkIDPartList < FFI::Struct
|
|
213
|
+
layout \
|
|
214
|
+
:next_partno, :int,
|
|
215
|
+
:next_parent, BlkIDPartition,
|
|
216
|
+
:nparts, :int,
|
|
217
|
+
:nparts_max, :int,
|
|
218
|
+
:parts, BlkIDPartition,
|
|
219
|
+
:l_tabs, ListHead
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
class BlkIDTopology < FFI::Struct
|
|
223
|
+
layout \
|
|
224
|
+
:alignment_offset, :ulong,
|
|
225
|
+
:minimum_io_size, :ulong,
|
|
226
|
+
:optimal_io_size, :ulong,
|
|
227
|
+
:logical_sector_size, :ulong,
|
|
228
|
+
:physical_sector_size, :ulong
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
end
|
data/lib/rblkid/cache.rb
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'rblkid/c'
|
|
21
|
+
require 'rblkid/dev'
|
|
22
|
+
|
|
23
|
+
module BlkID
|
|
24
|
+
class Cache
|
|
25
|
+
def initialize (filename=nil)
|
|
26
|
+
@struct = BlkID::C::BlkIDCache.new
|
|
27
|
+
|
|
28
|
+
raise "Error while getting cache" unless BlkID::C.blkid_get_cache(@struct.pointer, filename)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def save
|
|
32
|
+
BlkID::C.blkid_put_cache(@struct)
|
|
33
|
+
self
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def probe_all
|
|
37
|
+
BlkID::C.blkid_probe_all(@struct)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def probe_all_removable
|
|
41
|
+
BlkID::C.blkid_probe_all_removable(@struct)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def probe_all_new
|
|
45
|
+
BlkID::C.blkid_probe_all_new(@struct)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def verify (dev)
|
|
49
|
+
BlkID::C.blkid_verify(@struct, dev.to_ffi)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def find_dev_with_tag (type, value)
|
|
53
|
+
Dev.new(BlkID::C.blkid_find_dev_with_tag(@struct, type, value))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def dev (devname, flags)
|
|
57
|
+
Dev.new(BlkID::C.blkid_get_dev(@struct, devname, flags))
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def devname (token, value)
|
|
61
|
+
BlkID::C.blkid_get_tag_value(@struct, tagname, devname)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def to_ffi
|
|
65
|
+
@struct
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def ptr
|
|
69
|
+
to_ffi.ptr
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
module BlkID
|
|
21
|
+
BLKID_PROBVAL_BUFSIZ = 64
|
|
22
|
+
BLKID_NVALS_SUBLKS = 14
|
|
23
|
+
BLKID_NVALS_TOPLGY = 5
|
|
24
|
+
BLKID_NVALS_PARTS = 10
|
|
25
|
+
BLKID_NVALS = BLKID_NVALS_SUBLKS + BLKID_NVALS_TOPLGY + BLKID_NVALS_PARTS
|
|
26
|
+
BLKID_CHAIN_SUBLKS = 0
|
|
27
|
+
BLKID_CHAIN_TOPLGY = 1
|
|
28
|
+
BLKID_CHAIN_PARTS = 2
|
|
29
|
+
BLKID_NCHAINS = 3
|
|
30
|
+
BLKID_FLTR_NOTIN = 1
|
|
31
|
+
BLKID_FLTR_ONLYIN = 2
|
|
32
|
+
BLKID_DEV_CREATE = 0x0001
|
|
33
|
+
BLKID_DEV_FIND = 0x0000
|
|
34
|
+
BLKID_DEV_VERIFY = 0x0002
|
|
35
|
+
BLKID_DEV_NORMAL = BLKID_DEV_CREATE | BLKID_DEV_VERIFY
|
|
36
|
+
BLKID_PARTS_ENTRY_DETAILS = 1 << 2
|
|
37
|
+
BLKID_PARTS_FORCE_GPT = (1 << 1)
|
|
38
|
+
BLKID_SUBLKS_DEFAULT = 0
|
|
39
|
+
BLKID_SUBLKS_LABEL = (1 << 1)
|
|
40
|
+
BLKID_SUBLKS_LABELRAW = (1 << 2)
|
|
41
|
+
BLKID_SUBLKS_MAGIC = (1 << 9)
|
|
42
|
+
BLKID_SUBLKS_SECTYPE = (1 << 6)
|
|
43
|
+
BLKID_SUBLKS_TYPE = (1 << 5)
|
|
44
|
+
BLKID_SUBLKS_USAGE = (1 << 7)
|
|
45
|
+
BLKID_SUBLKS_UUID = (1 << 3)
|
|
46
|
+
BLKID_SUBLKS_UUIDRAW = (1 << 4)
|
|
47
|
+
BLKID_SUBLKS_VERSION = (1 << 8)
|
|
48
|
+
BLKID_USAGE_CRYPTO = (1 << 3)
|
|
49
|
+
BLKID_USAGE_FILESYSTEM = (1 << 1)
|
|
50
|
+
BLKID_USAGE_OTHER = (1 << 4)
|
|
51
|
+
BLKID_USAGE_RAID = (1 << 2)
|
|
52
|
+
end
|
data/lib/rblkid/dev.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'rblkid/c'
|
|
21
|
+
require 'rblkid/tag_iterate'
|
|
22
|
+
|
|
23
|
+
module BlkID
|
|
24
|
+
class Dev
|
|
25
|
+
def initialize (struct)
|
|
26
|
+
@struct = struct
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def devname
|
|
30
|
+
BlkID::C.blkid_dev_devname(@struct)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def tag? (type, value)
|
|
34
|
+
BlkID::C.blkid_dev_has_tag(@struct, type, value)
|
|
35
|
+
end
|
|
36
|
+
alias has_tag? tag?
|
|
37
|
+
|
|
38
|
+
def tags
|
|
39
|
+
TagIterate.new(self)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def to_ffi
|
|
43
|
+
@struct
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'rblkid/c'
|
|
21
|
+
require 'rblkid/dev'
|
|
22
|
+
|
|
23
|
+
module BlkID
|
|
24
|
+
class DevIterate
|
|
25
|
+
include Enumerable
|
|
26
|
+
|
|
27
|
+
def initialize (cache)
|
|
28
|
+
@struct = BlkID::C.blkid_dev_iterate_begin(cache.to_ffi)
|
|
29
|
+
|
|
30
|
+
ObjectSpace.define_finalizer(self, method(:finalize))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def search (type, value)
|
|
34
|
+
BlkID::C.blkid_dev_set_search(@struct, type, value)
|
|
35
|
+
self
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def next
|
|
39
|
+
Dev.new(BlkID::C::BlkIDDev.new.tap {|res|
|
|
40
|
+
break nil unless BlkID::C.blkid_dev_next(@struct, res.pointer)
|
|
41
|
+
})
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def each
|
|
45
|
+
[].tap {|a|
|
|
46
|
+
while (dev = self.next)
|
|
47
|
+
a << dev
|
|
48
|
+
yield dev if block_given?
|
|
49
|
+
end
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def finalize
|
|
54
|
+
BlkID::C.blkid_dev_iterate_end(@struct)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def to_ffi
|
|
58
|
+
@struct
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private :next
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'rblkid/c'
|
|
21
|
+
require 'rblkid/parttable'
|
|
22
|
+
|
|
23
|
+
module BlkID
|
|
24
|
+
class Partition
|
|
25
|
+
def initialize (struct)
|
|
26
|
+
@struct = struct
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def name
|
|
30
|
+
BlkID::C.blkid_partition_get_name(@struct)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def flags
|
|
34
|
+
BlkID::C.blkid_partition_get_flags(@struct)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def partno
|
|
38
|
+
BlkID::C.blkid_partition_get_partno(@struct)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def size
|
|
42
|
+
BlkID::C.blkid_partition_get_size(@struct)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def start
|
|
46
|
+
BlkID::C.blkid_partition_get_start(@struct)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def table
|
|
50
|
+
PartTable.new(BlkID::C.blkid_partition_get_table(@struct))
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def type
|
|
54
|
+
BlkID::C.blkid_partition_get_type(@struct)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def type_string
|
|
58
|
+
BlkID::C.blkid_partition_get_type_string(@struct)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def uuid
|
|
62
|
+
BlkID::C.blkid_partition_get_uuid(@struct)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def extended?
|
|
66
|
+
BlkID::C.blkid_partition_is_extended(@struct)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def logical?
|
|
70
|
+
BlkID::C.blkid_partition_is_logical(@struct)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def primary?
|
|
74
|
+
BlkID::C.blkid_partition_is_primary(@struct)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def to_ffi
|
|
78
|
+
@struct
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'rblkid/c'
|
|
21
|
+
require 'rblkid/partition'
|
|
22
|
+
require 'rblkid/parttable'
|
|
23
|
+
|
|
24
|
+
module BlkID
|
|
25
|
+
class PartList
|
|
26
|
+
def initialize (struct)
|
|
27
|
+
@struct = struct
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def partition (n)
|
|
31
|
+
BlkID::C.blkid_partlist_get_partition(@struct, n)
|
|
32
|
+
end
|
|
33
|
+
alias [] partition
|
|
34
|
+
|
|
35
|
+
def numof_partitions
|
|
36
|
+
BlkID::C.blkid_partlist_numof_partitions(@struct)
|
|
37
|
+
end
|
|
38
|
+
alias size numof_partitions
|
|
39
|
+
|
|
40
|
+
def devno_to_partition (devno)
|
|
41
|
+
Partition.new(BlkID::C.blkid_partlist_devno_to_partition(@struct, devno))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def table
|
|
45
|
+
PartTable.new(BlkID::C.blkid_partlist_get_table(@struct))
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def to_ffi
|
|
49
|
+
@struct
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'rblkid/c'
|
|
21
|
+
require 'rblkid/partition'
|
|
22
|
+
|
|
23
|
+
module BlkID
|
|
24
|
+
class PartTable
|
|
25
|
+
def initialize (struct)
|
|
26
|
+
@struct = struct
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def offset
|
|
30
|
+
BlkID::C.blkid_parttable_get_offset(@struct)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def parent
|
|
34
|
+
Partition.new(BlkID::C.blkid_parttable_get_parent(@struct))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def type
|
|
38
|
+
BlkID::C.blkid_parttable_get_type(@struct)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_ffi
|
|
42
|
+
@struct
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/rblkid/probe.rb
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'rblkid/c'
|
|
21
|
+
require 'rblkid/partlist'
|
|
22
|
+
require 'rblkid/topology'
|
|
23
|
+
|
|
24
|
+
module BlkID
|
|
25
|
+
class Probe
|
|
26
|
+
def self.from_filename (filename)
|
|
27
|
+
allocate.tap {|o| o.instance_eval {
|
|
28
|
+
@struct = BlkID::C.blkid_new_probe_from_filename(filename)
|
|
29
|
+
ObjectSpace.define_finalizer(self, method(:finalize))
|
|
30
|
+
}}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def initialize
|
|
34
|
+
@struct = BlkID::C.blkid_new_probe
|
|
35
|
+
|
|
36
|
+
ObjectSpace.define_finalizer(self, method(:finalize))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def finalize
|
|
40
|
+
BlkID::C.blkid_free_probe(@struct)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def devno
|
|
44
|
+
BlkID::C.blkid_probe_get_devno(@struct)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def fd
|
|
48
|
+
BlkID::C.blkid_probe_get_fd(@struct)
|
|
49
|
+
end
|
|
50
|
+
alias to_i fd
|
|
51
|
+
|
|
52
|
+
def sector_size
|
|
53
|
+
BlkID::C.blkid_probe_get_sectorsize(@struct)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def sectors
|
|
57
|
+
BlkID::C.blkid_probe_get_sectors(@struct)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def size
|
|
61
|
+
BlkID::C.blkid_probe_get_size(@struct)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def offset
|
|
65
|
+
BlkID::C.blkid_probe_get_offset(@struct)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def wholedisk_devno
|
|
69
|
+
BlkID::C.blkid_probe_get_wholedisk_devno(@struct)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def set_device (fd, off, size)
|
|
73
|
+
BlkID::C.blkid_probe_set_device(@struct, fd, off, size)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def wholedisk?
|
|
77
|
+
BlkID::C.blkid_probe_is_wholedisk(@struct)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def reset
|
|
81
|
+
BlkID::C.blkid_reset_probe(@struct)
|
|
82
|
+
self
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def fullprobe
|
|
86
|
+
BlkID::C.blkid_do_fullprobe(@struct)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def probe
|
|
90
|
+
BlkID::C.blkid_do_probe(@struct)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def safeprobe
|
|
94
|
+
BlkID::C.blkid_do_safeprobe(@struct)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def value (num)
|
|
98
|
+
name = FFI::MemoryPointer.new(:string)
|
|
99
|
+
data = FFI::MemoryPointer.new(:string)
|
|
100
|
+
|
|
101
|
+
BlkID::C.blkid_probe_get_value(@struct, num,
|
|
102
|
+
FFI::MemoryPointer.new(:pointer).write_pointer(name),
|
|
103
|
+
FFI::MemoryPointer.new(:pointer).write_pointer(data),
|
|
104
|
+
nil)
|
|
105
|
+
[name.read_string, data.read_string]
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def has_value? (name)
|
|
109
|
+
BlkID::C.blkid_probe_has_value(@struct, name)
|
|
110
|
+
end
|
|
111
|
+
alias value? has_value?
|
|
112
|
+
|
|
113
|
+
def lookup_value (name)
|
|
114
|
+
data = FFI::MemoryPointer.new(:string)
|
|
115
|
+
BlkID::C.blkid_probe_lookup_value(@struct, name,
|
|
116
|
+
FFI::MemoryPointer.new(:pointer).write_pointer(data),
|
|
117
|
+
nil)
|
|
118
|
+
data.read_string
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def numof_values
|
|
122
|
+
BlkID::C.blkid_probe_numof_values(@struct)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def superblocks= (bool)
|
|
126
|
+
BlkID::C.blkid_probe_enable_superblocks(@struct, bool)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def partitions
|
|
130
|
+
PartList.new(BlkID::C.blkid_probe_get_partitions(@struct))
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def topology= (bool)
|
|
134
|
+
BlkID::C.blkid_probe_enable_topology(@struct, bool)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def topology
|
|
138
|
+
Topology.new(BlkID::C.blkid_probe_get_topology(@struct))
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def to_ffi
|
|
142
|
+
@struct
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'rblkid/c'
|
|
21
|
+
|
|
22
|
+
module BlkID
|
|
23
|
+
class TagIterate
|
|
24
|
+
include Enumerable
|
|
25
|
+
|
|
26
|
+
def initialize (dev)
|
|
27
|
+
@struct = BlkID::C.blkid_tag_iterate_begin(dev.to_ffi)
|
|
28
|
+
|
|
29
|
+
ObjectSpace.define_finalizer(self, method(:finalize))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def next
|
|
33
|
+
type = FFI::MemoryPointer.new(:string)
|
|
34
|
+
value = FFI::MemoryPointer.new(:string)
|
|
35
|
+
BlkID::C.blkid_tag_next(@struct, type, value)
|
|
36
|
+
|
|
37
|
+
[type, value]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def each
|
|
41
|
+
Hash[[].tap {|a|
|
|
42
|
+
while (tag = self.next)
|
|
43
|
+
a << tag
|
|
44
|
+
yield *tag if block_given?
|
|
45
|
+
end
|
|
46
|
+
}]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def finalize
|
|
50
|
+
BlkID::C.blkid_tag_iterate_end(@struct)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def to_ffi
|
|
54
|
+
@struct
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private :next
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
|
3
|
+
#
|
|
4
|
+
# This file is part of rblkid.
|
|
5
|
+
#
|
|
6
|
+
# rblkid 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
|
+
# rblkid 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 rblkid. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#++
|
|
19
|
+
|
|
20
|
+
require 'rblkid/c'
|
|
21
|
+
|
|
22
|
+
module BlkID
|
|
23
|
+
class Topology
|
|
24
|
+
def initialize (struct)
|
|
25
|
+
@struct = struct
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def alignment_offset
|
|
29
|
+
BlkID::C.blkid_topology_get_alignment_offset(@struct)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def logical_sector_size
|
|
33
|
+
BlkID::C.blkid_topology_get_logical_sector_size(@struct)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def minimum_io_size
|
|
37
|
+
BlkID::C.blkid_topology_get_minimum_io_size(@struct)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def optimal_io_size
|
|
41
|
+
BlkID::C.blkid_topology_get_optimal_io_size(@struct)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def physical_sector_size
|
|
45
|
+
BlkID::C.blkid_topology_get_physical_sector_size(@struct)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def to_ffi
|
|
49
|
+
@struct
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rblkid
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 0
|
|
8
|
+
- 1
|
|
9
|
+
version: 0.0.1
|
|
10
|
+
platform: ruby
|
|
11
|
+
authors:
|
|
12
|
+
- shura
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2011-09-06 00:00:00 +02:00
|
|
18
|
+
default_executable:
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: ffi
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
none: false
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
segments:
|
|
29
|
+
- 0
|
|
30
|
+
version: "0"
|
|
31
|
+
type: :runtime
|
|
32
|
+
version_requirements: *id001
|
|
33
|
+
description: libblkid ruby bindings
|
|
34
|
+
email: shura1991@gmail.com
|
|
35
|
+
executables: []
|
|
36
|
+
|
|
37
|
+
extensions: []
|
|
38
|
+
|
|
39
|
+
extra_rdoc_files: []
|
|
40
|
+
|
|
41
|
+
files:
|
|
42
|
+
- lib/rblkid/c.rb
|
|
43
|
+
- lib/rblkid/cache.rb
|
|
44
|
+
- lib/rblkid/partlist.rb
|
|
45
|
+
- lib/rblkid/dev_iterate.rb
|
|
46
|
+
- lib/rblkid/probe.rb
|
|
47
|
+
- lib/rblkid/partition.rb
|
|
48
|
+
- lib/rblkid/c/types.rb
|
|
49
|
+
- lib/rblkid/c/functions.rb
|
|
50
|
+
- lib/rblkid/topology.rb
|
|
51
|
+
- lib/rblkid/tag_iterate.rb
|
|
52
|
+
- lib/rblkid/constants.rb
|
|
53
|
+
- lib/rblkid/parttable.rb
|
|
54
|
+
- lib/rblkid/dev.rb
|
|
55
|
+
- lib/rblkid.rb
|
|
56
|
+
has_rdoc: true
|
|
57
|
+
homepage: http://github.com/shurizzle/rblkid
|
|
58
|
+
licenses: []
|
|
59
|
+
|
|
60
|
+
post_install_message:
|
|
61
|
+
rdoc_options: []
|
|
62
|
+
|
|
63
|
+
require_paths:
|
|
64
|
+
- lib
|
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
|
+
none: false
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
segments:
|
|
71
|
+
- 0
|
|
72
|
+
version: "0"
|
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
|
+
none: false
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
segments:
|
|
79
|
+
- 0
|
|
80
|
+
version: "0"
|
|
81
|
+
requirements: []
|
|
82
|
+
|
|
83
|
+
rubyforge_project:
|
|
84
|
+
rubygems_version: 1.3.7
|
|
85
|
+
signing_key:
|
|
86
|
+
specification_version: 3
|
|
87
|
+
summary: libblkid ruby bindings
|
|
88
|
+
test_files: []
|
|
89
|
+
|