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#if ENABLE_FEATURE_BLKID_TYPE
70 const char *type;
71#endif
72#ifdef UNUSED_PARTITION_CODE
73 struct volume_id_partition *partitions;
74 size_t partition_count;
75#endif
76
77
78 char label[VOLUME_ID_LABEL_SIZE+1];
79
80
81
82 char uuid[VOLUME_ID_UUID_SIZE+1];
83
84
85
86};
87
88struct volume_id* FAST_FUNC volume_id_open_node(int fd);
89int FAST_FUNC volume_id_probe_all(struct volume_id *id, uint64_t size);
90void FAST_FUNC free_volume_id(struct volume_id *id);
91
92
93
94
95#define SB_BUFFER_SIZE 0x11000
96
97#define SEEK_BUFFER_SIZE 0x10000
98
99#if BB_LITTLE_ENDIAN
100# define le16_to_cpu(x) (uint16_t)(x)
101# define le32_to_cpu(x) (uint32_t)(x)
102# define le64_to_cpu(x) (uint64_t)(x)
103# define be16_to_cpu(x) (uint16_t)(bswap_16(x))
104# define be32_to_cpu(x) (uint32_t)(bswap_32(x))
105# define cpu_to_le16(x) (uint16_t)(x)
106# define cpu_to_le32(x) (uint32_t)(x)
107# define cpu_to_be32(x) (uint32_t)(bswap_32(x))
108#else
109# define le16_to_cpu(x) (uint16_t)(bswap_16(x))
110# define le32_to_cpu(x) (uint32_t)(bswap_32(x))
111# define le64_to_cpu(x) (uint64_t)(bb_bswap_64(x))
112# define be16_to_cpu(x) (uint16_t)(x)
113# define be32_to_cpu(x) (uint32_t)(x)
114# define cpu_to_le16(x) (uint16_t)(bswap_16(x))
115# define cpu_to_le32(x) (uint32_t)(bswap_32(x))
116# define cpu_to_be32(x) (uint32_t)(x)
117#endif
118
119
120
121
122
123enum uuid_format {
124 UUID_DOS = 0,
125 UUID_NTFS = 1,
126 UUID_DCE = 2,
127 UUID_DCE_STRING = 3,
128};
129
130enum endian {
131 LE = 0,
132 BE = 1
133};
134
135void volume_id_set_unicode16(char *str, size_t len, const uint8_t *buf, enum endian endianess, size_t count);
136
137
138
139void volume_id_set_label_string(struct volume_id *id, const uint8_t *buf, size_t count);
140void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enum endian endianess, size_t count);
141void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, enum uuid_format format);
142void *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len);
143void volume_id_free_buffer(struct volume_id *id);
144
145
146
147
148
149
150
151
152
153
154
155int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id , uint64_t size);
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172int FAST_FUNC volume_id_probe_bcache(struct volume_id *id );
173
174int FAST_FUNC volume_id_probe_btrfs(struct volume_id *id );
175
176int FAST_FUNC volume_id_probe_cramfs(struct volume_id *id );
177
178int FAST_FUNC volume_id_probe_ext(struct volume_id *id );
179
180int FAST_FUNC volume_id_probe_vfat(struct volume_id *id );
181
182int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id );
183
184
185
186int FAST_FUNC volume_id_probe_iso9660(struct volume_id *id );
187
188int FAST_FUNC volume_id_probe_jfs(struct volume_id *id );
189
190int FAST_FUNC volume_id_probe_lfs(struct volume_id *id );
191
192int FAST_FUNC volume_id_probe_linux_swap(struct volume_id *id );
193
194int FAST_FUNC volume_id_probe_luks(struct volume_id *id );
195
196
197
198int FAST_FUNC volume_id_probe_minix(struct volume_id *id );
199
200
201
202int FAST_FUNC volume_id_probe_f2fs(struct volume_id *id );
203
204int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id );
205
206int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id );
207
208int FAST_FUNC volume_id_probe_exfat(struct volume_id *id );
209
210int FAST_FUNC volume_id_probe_ocfs2(struct volume_id *id );
211
212int FAST_FUNC volume_id_probe_reiserfs(struct volume_id *id );
213
214int FAST_FUNC volume_id_probe_romfs(struct volume_id *id );
215
216int FAST_FUNC volume_id_probe_squashfs(struct volume_id *id );
217
218int FAST_FUNC volume_id_probe_erofs(struct volume_id *id );
219
220int FAST_FUNC volume_id_probe_sysv(struct volume_id *id );
221
222int FAST_FUNC volume_id_probe_udf(struct volume_id *id );
223
224
225
226int FAST_FUNC volume_id_probe_xfs(struct volume_id *id );
227
228int FAST_FUNC volume_id_probe_ubifs(struct volume_id *id );
229
230POP_SAVED_FUNCTION_VISIBILITY
231