1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "libbb.h"
22#include "volume_id.h"
23
24PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
25
26#define dbg(...) ((void)0)
27
28
29
30
31#define VOLUME_ID_VERSION 48
32
33#define VOLUME_ID_LABEL_SIZE 64
34#define VOLUME_ID_UUID_SIZE 36
35#define VOLUME_ID_FORMAT_SIZE 32
36#define VOLUME_ID_PARTITIONS_MAX 256
37
38enum volume_id_usage {
39 VOLUME_ID_UNUSED,
40 VOLUME_ID_UNPROBED,
41 VOLUME_ID_OTHER,
42 VOLUME_ID_FILESYSTEM,
43 VOLUME_ID_PARTITIONTABLE,
44 VOLUME_ID_RAID,
45 VOLUME_ID_DISKLABEL,
46 VOLUME_ID_CRYPTO,
47};
48
49#ifdef UNUSED_PARTITION_CODE
50struct volume_id_partition {
51
52
53
54
55
56
57};
58#endif
59
60struct volume_id {
61 int fd;
62
63 int error;
64 size_t sbbuf_len;
65 size_t seekbuf_len;
66 uint8_t *sbbuf;
67 uint8_t *seekbuf;
68 uint64_t seekbuf_off;
69#ifdef UNUSED_PARTITION_CODE
70 struct volume_id_partition *partitions;
71 size_t partition_count;
72#endif
73
74
75 char label[VOLUME_ID_LABEL_SIZE+1];
76
77
78
79 char uuid[VOLUME_ID_UUID_SIZE+1];
80
81
82
83
84};
85
86struct volume_id* FAST_FUNC volume_id_open_node(int fd);
87int FAST_FUNC volume_id_probe_all(struct volume_id *id, uint64_t size);
88void FAST_FUNC free_volume_id(struct volume_id *id);
89
90
91
92
93#define SB_BUFFER_SIZE 0x11000
94
95#define SEEK_BUFFER_SIZE 0x10000
96
97#define bswap16(x) (uint16_t) ( \
98 (((uint16_t)(x) & 0x00ffu) << 8) | \
99 (((uint16_t)(x) & 0xff00u) >> 8))
100
101#define bswap32(x) (uint32_t) ( \
102 (((uint32_t)(x) & 0xff000000u) >> 24) | \
103 (((uint32_t)(x) & 0x00ff0000u) >> 8) | \
104 (((uint32_t)(x) & 0x0000ff00u) << 8) | \
105 (((uint32_t)(x) & 0x000000ffu) << 24))
106
107#define bswap64(x) (uint64_t) ( \
108 (((uint64_t)(x) & 0xff00000000000000ull) >> 56) | \
109 (((uint64_t)(x) & 0x00ff000000000000ull) >> 40) | \
110 (((uint64_t)(x) & 0x0000ff0000000000ull) >> 24) | \
111 (((uint64_t)(x) & 0x000000ff00000000ull) >> 8) | \
112 (((uint64_t)(x) & 0x00000000ff000000ull) << 8) | \
113 (((uint64_t)(x) & 0x0000000000ff0000ull) << 24) | \
114 (((uint64_t)(x) & 0x000000000000ff00ull) << 40) | \
115 (((uint64_t)(x) & 0x00000000000000ffull) << 56))
116
117#if BB_LITTLE_ENDIAN
118#define le16_to_cpu(x) (x)
119#define le32_to_cpu(x) (x)
120#define le64_to_cpu(x) (x)
121#define be16_to_cpu(x) bswap16(x)
122#define be32_to_cpu(x) bswap32(x)
123#define cpu_to_le16(x) (x)
124#define cpu_to_le32(x) (x)
125#define cpu_to_be32(x) bswap32(x)
126#else
127#define le16_to_cpu(x) bswap16(x)
128#define le32_to_cpu(x) bswap32(x)
129#define le64_to_cpu(x) bswap64(x)
130#define be16_to_cpu(x) (x)
131#define be32_to_cpu(x) (x)
132#define cpu_to_le16(x) bswap16(x)
133#define cpu_to_le32(x) bswap32(x)
134#define cpu_to_be32(x) (x)
135#endif
136
137enum uuid_format {
138 UUID_DCE_STRING,
139 UUID_DCE,
140 UUID_DOS,
141 UUID_NTFS,
142 UUID_HFS,
143};
144
145enum endian {
146 LE = 0,
147 BE = 1
148};
149
150void volume_id_set_unicode16(char *str, size_t len, const uint8_t *buf, enum endian endianess, size_t count);
151
152
153
154void volume_id_set_label_string(struct volume_id *id, const uint8_t *buf, size_t count);
155void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enum endian endianess, size_t count);
156void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, enum uuid_format format);
157void *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len);
158void volume_id_free_buffer(struct volume_id *id);
159
160
161
162
163
164
165
166
167
168
169
170int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id , uint64_t size);
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187int FAST_FUNC volume_id_probe_btrfs(struct volume_id *id );
188
189int FAST_FUNC volume_id_probe_cramfs(struct volume_id *id );
190
191int FAST_FUNC volume_id_probe_ext(struct volume_id *id );
192
193int FAST_FUNC volume_id_probe_vfat(struct volume_id *id );
194
195int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id );
196
197
198
199int FAST_FUNC volume_id_probe_iso9660(struct volume_id *id );
200
201int FAST_FUNC volume_id_probe_jfs(struct volume_id *id );
202
203int FAST_FUNC volume_id_probe_linux_swap(struct volume_id *id );
204
205int FAST_FUNC volume_id_probe_luks(struct volume_id *id );
206
207
208
209
210
211
212
213int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id );
214
215int FAST_FUNC volume_id_probe_ocfs2(struct volume_id *id );
216
217int FAST_FUNC volume_id_probe_reiserfs(struct volume_id *id );
218
219int FAST_FUNC volume_id_probe_romfs(struct volume_id *id );
220
221int FAST_FUNC volume_id_probe_sysv(struct volume_id *id );
222
223int FAST_FUNC volume_id_probe_udf(struct volume_id *id );
224
225
226
227int FAST_FUNC volume_id_probe_xfs(struct volume_id *id );
228
229POP_SAVED_FUNCTION_VISIBILITY
230