Debian Codegraph @

libblkid/src/blkid.h.in

raw
1 /*
2 * blkid.h - Interface for libblkid, a library to identify block devices
3 *
4 * Copyright (C) 2001 Andreas Dilger
5 * Copyright (C) 2003 Theodore Ts'o
6 * Copyright (C) 2008 Karel Zak <[email protected]>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://gnu.org/licenses/>.
20 */
21
22 #ifndef _BLKID_BLKID_H
23 #define _BLKID_BLKID_H
24
25 #include <stdint.h>
26 #include <sys/types.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #define LIBBLKID_VERSION "@LIBBLKID_VERSION@"
33 #define LIBBLKID_MAJOR_VERSION @LIBBLKID_MAJOR_VERSION@
34 #define LIBBLKID_MINOR_VERSION @LIBBLKID_MINOR_VERSION@
35 #define LIBBLKID_PATCH_VERSION @LIBBLKID_PATCH_VERSION@
36 #define LIBBLKID_DATE "@LIBBLKID_DATE@"
37
38 /* backward compatibility */
39 #define BLKID_VERSION LIBBLKID_VERSION
40 #define BLKID_DATE LIBBLKID_DATE
41
42 /**
43 * blkid_dev:
44 *
45 * The device object keeps information about one device
46 */
47 typedef struct blkid_struct_dev *blkid_dev;
48
49 /**
50 * blkid_cache:
51 *
52 * information about all system devices
53 */
54 typedef struct blkid_struct_cache *blkid_cache;
55
56 /**
57 * blkid_probe:
58 *
59 * low-level probing setting
60 */
61 typedef struct blkid_struct_probe *blkid_probe;
62
63 /**
64 * blkid_topology:
65 *
66 * device topology information
67 */
68 typedef struct blkid_struct_topology *blkid_topology;
69
70 /**
71 * blkid_partlist
72 *
73 * list of all detected partitions and partitions tables
74 */
75 typedef struct blkid_struct_partlist *blkid_partlist;
76
77 /**
78 * blkid_partition:
79 *
80 * information about a partition
81 */
82 typedef struct blkid_struct_partition *blkid_partition;
83
84 /**
85 * blkid_parttable:
86 *
87 * information about a partition table
88 */
89 typedef struct blkid_struct_parttable *blkid_parttable;
90
91 /**
92 * blkid_loff_t:
93 *
94 * 64-bit signed number for offsets and sizes
95 */
96 typedef int64_t blkid_loff_t;
97
98 /**
99 * blkid_tag_iterate:
100 *
101 * tags iterator for high-level (blkid_cache) API
102 */
103 typedef struct blkid_struct_tag_iterate *blkid_tag_iterate;
104
105 /**
106 * blkid_dev_iterate:
107 *
108 * devices iterator for high-level (blkid_cache) API
109 */
110 typedef struct blkid_struct_dev_iterate *blkid_dev_iterate;
111
112 /*
113 * Flags for blkid_get_dev
114 *
115 * BLKID_DEV_CREATE Create an empty device structure if not found
116 * in the cache.
117 * BLKID_DEV_VERIFY Make sure the device structure corresponds
118 * with reality.
119 * BLKID_DEV_FIND Just look up a device entry, and return NULL
120 * if it is not found.
121 * BLKID_DEV_NORMAL Get a valid device structure, either from the
122 * cache or by probing the device.
123 */
124 #define BLKID_DEV_FIND 0x0000
125 #define BLKID_DEV_CREATE 0x0001
126 #define BLKID_DEV_VERIFY 0x0002
127 #define BLKID_DEV_NORMAL (BLKID_DEV_CREATE | BLKID_DEV_VERIFY)
128
129
130 #ifndef __GNUC_PREREQ
131 # if defined __GNUC__ && defined __GNUC_MINOR__
132 # define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
133 # else
134 # define __GNUC_PREREQ(maj, min) 0
135 # endif
136 #endif
137
138 #ifndef __ul_attribute__
139 # if __GNUC_PREREQ (3, 4)
140 # define __ul_attribute__(_a_) __attribute__(_a_)
141 # else
142 # define __ul_attribute__(_a_)
143 # endif
144 #endif
145
146 /* init.c */
147 extern void blkid_init_debug(int mask);
148
149 /* cache.c */
150 extern void blkid_put_cache(blkid_cache cache);
151 extern int blkid_get_cache(blkid_cache *cache, const char *filename);
152 extern void blkid_gc_cache(blkid_cache cache);
153
154 /* dev.c */
155 extern const char *blkid_dev_devname(blkid_dev dev)
156 __ul_attribute__((warn_unused_result));
157
158 extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache);
159 extern int blkid_dev_set_search(blkid_dev_iterate iter,
160 const char *search_type, const char *search_value);
161 extern int blkid_dev_next(blkid_dev_iterate iterate, blkid_dev *dev);
162 extern void blkid_dev_iterate_end(blkid_dev_iterate iterate);
163
164 /* devno.c */
165 extern char *blkid_devno_to_devname(dev_t devno)
166 __ul_attribute__((warn_unused_result));
167 extern int blkid_devno_to_wholedisk(dev_t dev, char *diskname,
168 size_t len, dev_t *diskdevno)
169 __ul_attribute__((warn_unused_result));
170
171 /* devname.c */
172 extern int blkid_probe_all(blkid_cache cache);
173 extern int blkid_probe_all_new(blkid_cache cache);
174 extern int blkid_probe_all_removable(blkid_cache cache);
175
176 extern blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags);
177
178 /* getsize.c */
179 extern blkid_loff_t blkid_get_dev_size(int fd);
180
181 /* verify.c */
182 extern blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev);
183
184 /* read.c */
185
186 /* resolve.c */
187 extern char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
188 const char *devname)
189 __ul_attribute__((warn_unused_result));
190 extern char *blkid_get_devname(blkid_cache cache, const char *token,
191 const char *value)
192 __ul_attribute__((warn_unused_result));
193
194 /* tag.c */
195 extern blkid_tag_iterate blkid_tag_iterate_begin(blkid_dev dev);
196 extern int blkid_tag_next(blkid_tag_iterate iterate,
197 const char **type, const char **value);
198 extern void blkid_tag_iterate_end(blkid_tag_iterate iterate);
199 extern int blkid_dev_has_tag(blkid_dev dev, const char *type, const char *value);
200
201 extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
202 const char *type,
203 const char *value);
204
205 extern int blkid_parse_tag_string(const char *token, char **ret_type, char **ret_val);
206
207 /* version.c */
208 extern int blkid_parse_version_string(const char *ver_string)
209 __ul_attribute__((nonnull));
210 extern int blkid_get_library_version(const char **ver_string,
211 const char **date_string);
212
213 /* encode.c */
214 extern int blkid_encode_string(const char *str, char *str_enc, size_t len);
215 extern int blkid_safe_string(const char *str, char *str_safe, size_t len);
216
217 /* evaluate.c */
218 extern int blkid_send_uevent(const char *devname, const char *action);
219 extern char *blkid_evaluate_tag(const char *token, const char *value,
220 blkid_cache *cache)
221 __ul_attribute__((warn_unused_result));
222 extern char *blkid_evaluate_spec(const char *spec, blkid_cache *cache)
223 __ul_attribute__((warn_unused_result));
224
225 /* probe.c */
226 extern blkid_probe blkid_new_probe(void)
227 __ul_attribute__((warn_unused_result));
228 extern blkid_probe blkid_new_probe_from_filename(const char *filename)
229 __ul_attribute__((warn_unused_result))
230 __ul_attribute__((nonnull));
231 extern void blkid_free_probe(blkid_probe pr);
232
233 extern void blkid_reset_probe(blkid_probe pr);
234 extern int blkid_probe_reset_buffers(blkid_probe pr);
235 extern int blkid_probe_hide_range(blkid_probe pr, uint64_t off, uint64_t len);
236
237 extern int blkid_probe_set_device(blkid_probe pr, int fd,
238 blkid_loff_t off, blkid_loff_t size)
239 __ul_attribute__((nonnull));
240
241 extern dev_t blkid_probe_get_devno(blkid_probe pr)
242 __ul_attribute__((nonnull));
243
244 extern dev_t blkid_probe_get_wholedisk_devno(blkid_probe pr)
245 __ul_attribute__((nonnull));
246
247 extern int blkid_probe_is_wholedisk(blkid_probe pr)
248 __ul_attribute__((nonnull));
249
250 extern blkid_loff_t blkid_probe_get_size(blkid_probe pr)
251 __ul_attribute__((nonnull));
252 extern blkid_loff_t blkid_probe_get_offset(blkid_probe pr)
253 __ul_attribute__((nonnull));
254 extern unsigned int blkid_probe_get_sectorsize(blkid_probe pr)
255 __ul_attribute__((nonnull));
256 extern int blkid_probe_set_sectorsize(blkid_probe pr, unsigned int sz)
257 __ul_attribute__((nonnull));
258 extern blkid_loff_t blkid_probe_get_sectors(blkid_probe pr)
259 __ul_attribute__((nonnull));
260
261 extern int blkid_probe_get_fd(blkid_probe pr)
262 __ul_attribute__((nonnull));
263
264 extern int blkid_probe_set_hint(blkid_probe pr, const char *name, uint64_t value)
265 __ul_attribute__((nonnull));
266 extern void blkid_probe_reset_hints(blkid_probe pr)
267 __ul_attribute__((nonnull));
268
269 /*
270 * superblocks probing
271 */
272 extern int blkid_known_fstype(const char *fstype)
273 __ul_attribute__((nonnull));
274
275 extern int blkid_superblocks_get_name(size_t idx, const char **name, int *usage);
276
277 extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable)
278 __ul_attribute__((nonnull));
279
280 #define BLKID_SUBLKS_LABEL (1 << 1) /* read LABEL from superblock */
281 #define BLKID_SUBLKS_LABELRAW (1 << 2) /* read and define LABEL_RAW result value*/
282 #define BLKID_SUBLKS_UUID (1 << 3) /* read UUID from superblock */
283 #define BLKID_SUBLKS_UUIDRAW (1 << 4) /* read and define UUID_RAW result value */
284 #define BLKID_SUBLKS_TYPE (1 << 5) /* define TYPE result value */
285 #define BLKID_SUBLKS_SECTYPE (1 << 6) /* define compatible fs type (second type) */
286 #define BLKID_SUBLKS_USAGE (1 << 7) /* define USAGE result value */
287 #define BLKID_SUBLKS_VERSION (1 << 8) /* read FS type from superblock */
288 #define BLKID_SUBLKS_MAGIC (1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
289 #define BLKID_SUBLKS_BADCSUM (1 << 10) /* allow a bad checksum */
290 #define BLKID_SUBLKS_FSINFO (1 << 11) /* read and define fs properties from superblock */
291
292 #define BLKID_SUBLKS_DEFAULT (BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | \
293 BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE)
294
295 extern int blkid_probe_set_superblocks_flags(blkid_probe pr, int flags)
296 __ul_attribute__((nonnull));
297 extern int blkid_probe_reset_superblocks_filter(blkid_probe pr)
298 __ul_attribute__((nonnull));
299 extern int blkid_probe_invert_superblocks_filter(blkid_probe pr)
300 __ul_attribute__((nonnull));
301
302 /**
303 * BLKID_FLTR_NOTIN
304 */
305 #define BLKID_FLTR_NOTIN 1
306 /**
307 * BLKID_FLTR_ONLYIN
308 */
309 #define BLKID_FLTR_ONLYIN 2
310 extern int blkid_probe_filter_superblocks_type(blkid_probe pr, int flag, char *names[])
311 __ul_attribute__((nonnull));
312
313 #define BLKID_USAGE_FILESYSTEM (1 << 1)
314 #define BLKID_USAGE_RAID (1 << 2)
315 #define BLKID_USAGE_CRYPTO (1 << 3)
316 #define BLKID_USAGE_OTHER (1 << 4)
317 extern int blkid_probe_filter_superblocks_usage(blkid_probe pr, int flag, int usage)
318 __ul_attribute__((nonnull));
319
320 /*
321 * topology probing
322 */
323 extern int blkid_probe_enable_topology(blkid_probe pr, int enable)
324 __ul_attribute__((nonnull));
325
326 /* binary interface */
327 extern blkid_topology blkid_probe_get_topology(blkid_probe pr)
328 __ul_attribute__((nonnull));
329
330 extern unsigned long blkid_topology_get_alignment_offset(blkid_topology tp)
331 __ul_attribute__((nonnull));
332 extern unsigned long blkid_topology_get_minimum_io_size(blkid_topology tp)
333 __ul_attribute__((nonnull));
334 extern unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp)
335 __ul_attribute__((nonnull));
336 extern unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp)
337 __ul_attribute__((nonnull));
338 extern unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp)
339 __ul_attribute__((nonnull));
340 extern unsigned long blkid_topology_get_dax(blkid_topology tp)
341 __ul_attribute__((nonnull));
342 extern uint64_t blkid_topology_get_diskseq(blkid_topology tp)
343 __ul_attribute__((nonnull));
344
345 /*
346 * partitions probing
347 */
348 extern int blkid_known_pttype(const char *pttype);
349 extern int blkid_partitions_get_name(size_t idx, const char **name);
350
351 extern int blkid_probe_enable_partitions(blkid_probe pr, int enable)
352 __ul_attribute__((nonnull));
353
354 extern int blkid_probe_reset_partitions_filter(blkid_probe pr)
355 __ul_attribute__((nonnull));
356 extern int blkid_probe_invert_partitions_filter(blkid_probe pr)
357 __ul_attribute__((nonnull));
358 extern int blkid_probe_filter_partitions_type(blkid_probe pr, int flag, char *names[])
359 __ul_attribute__((nonnull));
360
361 /* partitions probing flags */
362 #define BLKID_PARTS_FORCE_GPT (1 << 1)
363 #define BLKID_PARTS_ENTRY_DETAILS (1 << 2)
364 #define BLKID_PARTS_MAGIC (1 << 3)
365 extern int blkid_probe_set_partitions_flags(blkid_probe pr, int flags)
366 __ul_attribute__((nonnull));
367
368 /* binary interface */
369 extern blkid_partlist blkid_probe_get_partitions(blkid_probe pr)
370 __ul_attribute__((nonnull));
371
372 extern int blkid_partlist_numof_partitions(blkid_partlist ls)
373 __ul_attribute__((nonnull));
374 extern blkid_parttable blkid_partlist_get_table(blkid_partlist ls)
375 __ul_attribute__((nonnull));
376 extern blkid_partition blkid_partlist_get_partition(blkid_partlist ls, int n)
377 __ul_attribute__((nonnull));
378 extern blkid_partition blkid_partlist_get_partition_by_partno(blkid_partlist ls, int n)
379 __ul_attribute__((nonnull));
380 extern blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno)
381 __ul_attribute__((nonnull));
382 extern blkid_parttable blkid_partition_get_table(blkid_partition par)
383 __ul_attribute__((nonnull));
384
385 extern const char *blkid_partition_get_name(blkid_partition par)
386 __ul_attribute__((nonnull));
387 extern const char *blkid_partition_get_uuid(blkid_partition par)
388 __ul_attribute__((nonnull));
389 extern int blkid_partition_get_partno(blkid_partition par)
390 __ul_attribute__((nonnull));
391 extern blkid_loff_t blkid_partition_get_start(blkid_partition par)
392 __ul_attribute__((nonnull));
393 extern blkid_loff_t blkid_partition_get_size(blkid_partition par)
394 __ul_attribute__((nonnull));
395
396 extern int blkid_partition_get_type(blkid_partition par)
397 __ul_attribute__((nonnull));
398 extern const char *blkid_partition_get_type_string(blkid_partition par)
399 __ul_attribute__((nonnull));
400 extern unsigned long long blkid_partition_get_flags(blkid_partition par)
401 __ul_attribute__((nonnull));
402
403 extern int blkid_partition_is_logical(blkid_partition par)
404 __ul_attribute__((nonnull));
405 extern int blkid_partition_is_extended(blkid_partition par)
406 __ul_attribute__((nonnull));
407 extern int blkid_partition_is_primary(blkid_partition par)
408 __ul_attribute__((nonnull));
409
410 extern const char *blkid_parttable_get_type(blkid_parttable tab)
411 __ul_attribute__((nonnull));
412 extern const char *blkid_parttable_get_id(blkid_parttable tab)
413 __ul_attribute__((nonnull));
414 extern blkid_loff_t blkid_parttable_get_offset(blkid_parttable tab)
415 __ul_attribute__((nonnull));
416 extern blkid_partition blkid_parttable_get_parent(blkid_parttable tab)
417 __ul_attribute__((nonnull));
418
419 /*
420 * NAME=value low-level interface
421 */
422 extern int blkid_do_probe(blkid_probe pr)
423 __ul_attribute__((nonnull));
424 extern int blkid_do_safeprobe(blkid_probe pr)
425 __ul_attribute__((nonnull));
426 extern int blkid_do_fullprobe(blkid_probe pr)
427 __ul_attribute__((nonnull));
428
429 /**
430 * BLKID_PROBE_OK:
431 *
432 * probing return value; superblock (RAID, partition table, ...) successfully detected
433 */
434 #define BLKID_PROBE_OK 0
435 /**
436 * BLKID_PROBE_NONE:
437 *
438 * probing return value; found nothing
439 */
440 #define BLKID_PROBE_NONE 1
441 /**
442 * BLKID_PROBE_ERROR:
443 *
444 * probing return value; probing ends with en error (see errno for more details)
445 */
446 #define BLKID_PROBE_ERROR -1
447 /**
448 * BLKID_PROBE_AMBIGUOUS:
449 *
450 * probing return value; more than one probing result, in this case, it's not
451 * safe to use the device automatically and user intervention is recommended
452 */
453 #define BLKID_PROBE_AMBIGUOUS -2
454
455 extern int blkid_probe_numof_values(blkid_probe pr)
456 __ul_attribute__((nonnull));
457 extern int blkid_probe_get_value(blkid_probe pr, int num, const char **name,
458 const char **data, size_t *len)
459 __ul_attribute__((nonnull(1)));
460 extern int blkid_probe_lookup_value(blkid_probe pr, const char *name,
461 const char **data, size_t *len)
462 __ul_attribute__((nonnull(1, 2)));
463 extern int blkid_probe_has_value(blkid_probe pr, const char *name)
464 __ul_attribute__((nonnull));
465 extern int blkid_do_wipe(blkid_probe pr, int dryrun)
466 __ul_attribute__((nonnull));
467 extern int blkid_wipe_all(blkid_probe pr)
468 __ul_attribute__((nonnull));
469 extern int blkid_probe_step_back(blkid_probe pr)
470 __ul_attribute__((nonnull));
471
472 /*
473 * Deprecated functions/macros
474 */
475 #ifndef BLKID_DISABLE_DEPRECATED
476
477 #define BLKID_PROBREQ_LABEL BLKID_SUBLKS_LABEL
478 #define BLKID_PROBREQ_LABELRAW BLKID_SUBLKS_LABELRAW
479 #define BLKID_PROBREQ_UUID BLKID_SUBLKS_UUID
480 #define BLKID_PROBREQ_UUIDRAW BLKID_SUBLKS_UUIDRAW
481 #define BLKID_PROBREQ_TYPE BLKID_SUBLKS_TYPE
482 #define BLKID_PROBREQ_SECTYPE BLKID_SUBLKS_SECTYPE
483 #define BLKID_PROBREQ_USAGE BLKID_SUBLKS_USAGE
484 #define BLKID_PROBREQ_VERSION BLKID_SUBLKS_VERSION
485
486 extern int blkid_probe_set_request(blkid_probe pr, int flags)
487 __ul_attribute__((deprecated));
488
489 extern int blkid_probe_filter_usage(blkid_probe pr, int flag, int usage)
490 __ul_attribute__((deprecated));
491
492 extern int blkid_probe_filter_types(blkid_probe pr, int flag, char *names[])
493 __ul_attribute__((deprecated));
494
495 extern int blkid_probe_invert_filter(blkid_probe pr)
496 __ul_attribute__((deprecated));
497
498 extern int blkid_probe_reset_filter(blkid_probe pr)
499 __ul_attribute__((deprecated));
500
501 #endif /* BLKID_DISABLE_DEPRECATED */
502
503 #ifdef __cplusplus
504 }
505 #endif
506
507 #endif /* _BLKID_BLKID_H */