blob: b283009f6e925790156415d21ef8769af8675253 [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
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 <kzak@redhat.com>
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 Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef _BLKID_BLKID_H
24#define _BLKID_BLKID_H
25
26#include <stdint.h>
27#include <sys/types.h>
28
29#define _SC_HOST_NAME_MAX 255
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#define BLKID_VERSION "2.22.0"
35#define BLKID_DATE "04-Sep-2012"
36
37/**
38 * blkid_dev:
39 *
40 * The device object keeps information about one device
41 */
42typedef struct blkid_struct_dev *blkid_dev;
43
44/**
45 * blkid_cache:
46 *
47 * information about all system devices
48 */
49typedef struct blkid_struct_cache *blkid_cache;
50
51/**
52 * blkid_probe:
53 *
54 * low-level probing setting
55 */
56typedef struct blkid_struct_probe *blkid_probe;
57
58/**
59 * blkid_topology:
60 *
61 * device topology information
62 */
63typedef struct blkid_struct_topology *blkid_topology;
64
65/**
66 * blkid_partlist
67 *
68 * list of all detected partitions and partitions tables
69 */
70typedef struct blkid_struct_partlist *blkid_partlist;
71
72/**
73 * blkid_partition:
74 *
75 * information about a partition
76 */
77typedef struct blkid_struct_partition *blkid_partition;
78
79/**
80 * blkid_parttable:
81 *
82 * information about a partition table
83 */
84typedef struct blkid_struct_parttable *blkid_parttable;
85
86/**
87 * blkid_loff_t:
88 *
89 * 64-bit signed number for offsets and sizes
90 */
91typedef int64_t blkid_loff_t;
92
93/**
94 * blkid_tag_iterate:
95 *
96 * tags iterator for high-level (blkid_cache) API
97 */
98typedef struct blkid_struct_tag_iterate *blkid_tag_iterate;
99
100/**
101 * blkid_dev_iterate:
102 *
103 * devices iterator for high-level (blkid_cache) API
104 */
105typedef struct blkid_struct_dev_iterate *blkid_dev_iterate;
106
107/*
108 * Flags for blkid_get_dev
109 *
110 * BLKID_DEV_CREATE Create an empty device structure if not found
111 * in the cache.
112 * BLKID_DEV_VERIFY Make sure the device structure corresponds
113 * with reality.
114 * BLKID_DEV_FIND Just look up a device entry, and return NULL
115 * if it is not found.
116 * BLKID_DEV_NORMAL Get a valid device structure, either from the
117 * cache or by probing the device.
118 */
119#define BLKID_DEV_FIND 0x0000
120#define BLKID_DEV_CREATE 0x0001
121#define BLKID_DEV_VERIFY 0x0002
122#define BLKID_DEV_NORMAL (BLKID_DEV_CREATE | BLKID_DEV_VERIFY)
123
124
125#ifndef __GNUC_PREREQ
126# if defined __GNUC__ && defined __GNUC_MINOR__
127# define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
128# else
129# define __GNUC_PREREQ(maj, min) 0
130# endif
131#endif
132
133#ifndef __ul_attribute__
134# if __GNUC_PREREQ (3, 4)
135# define __ul_attribute__(_a_) __attribute__(_a_)
136# else
137# define __ul_attribute__(_a_)
138# endif
139#endif
140
141/* cache.c */
142extern void blkid_put_cache(blkid_cache cache);
143extern int blkid_get_cache(blkid_cache *cache, const char *filename);
144extern void blkid_gc_cache(blkid_cache cache);
145
146/* dev.c */
147extern const char *blkid_dev_devname(blkid_dev dev)
148 __ul_attribute__((warn_unused_result));
149
150extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache)
151 __ul_attribute__((nonnull));
152extern int blkid_dev_set_search(blkid_dev_iterate iter,
153 char *search_type, char *search_value);
154extern int blkid_dev_next(blkid_dev_iterate iterate, blkid_dev *dev);
155extern void blkid_dev_iterate_end(blkid_dev_iterate iterate);
156
157/* devno.c */
158extern char *blkid_devno_to_devname(dev_t devno)
159 __ul_attribute__((warn_unused_result));
160extern int blkid_devno_to_wholedisk(dev_t dev, char *diskname,
161 size_t len, dev_t *diskdevno)
162 __ul_attribute__((warn_unused_result));
163
164/* devname.c */
165extern int blkid_probe_all(blkid_cache cache);
166extern int blkid_probe_all_new(blkid_cache cache);
167extern int blkid_probe_all_removable(blkid_cache cache);
168
169extern blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags);
170
171/* getsize.c */
172extern blkid_loff_t blkid_get_dev_size(int fd)
173 __ul_attribute__((warn_unused_result));
174
175/* verify.c */
176extern blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev);
177
178/* read.c */
179
180/* resolve.c */
181extern char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
182 const char *devname)
183 __ul_attribute__((warn_unused_result));
184extern char *blkid_get_devname(blkid_cache cache, const char *token,
185 const char *value)
186 __ul_attribute__((warn_unused_result));
187
188/* tag.c */
189extern blkid_tag_iterate blkid_tag_iterate_begin(blkid_dev dev)
190 __ul_attribute__((warn_unused_result));
191extern int blkid_tag_next(blkid_tag_iterate iterate,
192 const char **type, const char **value);
193extern void blkid_tag_iterate_end(blkid_tag_iterate iterate);
194extern int blkid_dev_has_tag(blkid_dev dev, const char *type, const char *value)
195 __ul_attribute__((nonnull(1,2)));
196
197extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
198 const char *type,
199 const char *value)
200 __ul_attribute__((warn_unused_result));
201
202extern int blkid_parse_tag_string(const char *token, char **ret_type, char **ret_val);
203
204/* version.c */
205extern int blkid_parse_version_string(const char *ver_string)
206 __ul_attribute__((nonnull))
207 __ul_attribute__((warn_unused_result));
208extern int blkid_get_library_version(const char **ver_string,
209 const char **date_string);
210
211/* encode.c */
212extern int blkid_encode_string(const char *str, char *str_enc, size_t len);
213extern int blkid_safe_string(const char *str, char *str_safe, size_t len);
214
215/* evaluate.c */
216extern int blkid_send_uevent(const char *devname, const char *action);
217extern char *blkid_evaluate_tag(const char *token, const char *value,
218 blkid_cache *cache)
219 __ul_attribute__((warn_unused_result));
220extern char *blkid_evaluate_spec(const char *spec, blkid_cache *cache)
221 __ul_attribute__((warn_unused_result));
222
223/* probe.c */
224extern blkid_probe blkid_new_probe(void)
225 __ul_attribute__((warn_unused_result));
226extern blkid_probe blkid_new_probe_from_filename(const char *filename)
227 __ul_attribute__((warn_unused_result));
228extern void blkid_free_probe(blkid_probe pr);
229
230extern void blkid_reset_probe(blkid_probe pr);
231
232extern int blkid_probe_set_device(blkid_probe pr, int fd,
233 blkid_loff_t off, blkid_loff_t size);
234
235extern dev_t blkid_probe_get_devno(blkid_probe pr)
236 __ul_attribute__((nonnull))
237 __ul_attribute__((warn_unused_result));
238
239extern dev_t blkid_probe_get_wholedisk_devno(blkid_probe pr)
240 __ul_attribute__((nonnull))
241 __ul_attribute__((warn_unused_result));
242
243extern int blkid_probe_is_wholedisk(blkid_probe pr)
244 __ul_attribute__((nonnull))
245 __ul_attribute__((warn_unused_result));
246
247extern blkid_loff_t blkid_probe_get_size(blkid_probe pr)
248 __ul_attribute__((warn_unused_result));
249extern blkid_loff_t blkid_probe_get_offset(blkid_probe pr)
250 __ul_attribute__((warn_unused_result));
251extern unsigned int blkid_probe_get_sectorsize(blkid_probe pr)
252 __ul_attribute__((warn_unused_result));
253extern blkid_loff_t blkid_probe_get_sectors(blkid_probe pr)
254 __ul_attribute__((warn_unused_result));
255
256extern int blkid_probe_get_fd(blkid_probe pr)
257 __ul_attribute__((warn_unused_result));
258
259/*
260 * superblocks probing
261 */
262extern int blkid_known_fstype(const char *fstype)
263 __ul_attribute__((warn_unused_result));
264
265extern int blkid_superblocks_get_name(size_t idx, const char **name, int *usage);
266
267extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable);
268
269#define BLKID_SUBLKS_LABEL (1 << 1) /* read LABEL from superblock */
270#define BLKID_SUBLKS_LABELRAW (1 << 2) /* read and define LABEL_RAW result value*/
271#define BLKID_SUBLKS_UUID (1 << 3) /* read UUID from superblock */
272#define BLKID_SUBLKS_UUIDRAW (1 << 4) /* read and define UUID_RAW result value */
273#define BLKID_SUBLKS_TYPE (1 << 5) /* define TYPE result value */
274#define BLKID_SUBLKS_SECTYPE (1 << 6) /* define compatible fs type (second type) */
275#define BLKID_SUBLKS_USAGE (1 << 7) /* define USAGE result value */
276#define BLKID_SUBLKS_VERSION (1 << 8) /* read FS type from superblock */
277#define BLKID_SUBLKS_MAGIC (1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
278
279#define BLKID_SUBLKS_DEFAULT (BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | \
280 BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE)
281
282extern int blkid_probe_set_superblocks_flags(blkid_probe pr, int flags);
283extern int blkid_probe_reset_superblocks_filter(blkid_probe pr);
284extern int blkid_probe_invert_superblocks_filter(blkid_probe pr);
285
286/**
287 * BLKID_FLTR_NOTIN
288 */
289#define BLKID_FLTR_NOTIN 1
290/**
291 * BLKID_FLTR_ONLYIN
292 */
293#define BLKID_FLTR_ONLYIN 2
294extern int blkid_probe_filter_superblocks_type(blkid_probe pr, int flag, char *names[]);
295
296#define BLKID_USAGE_FILESYSTEM (1 << 1)
297#define BLKID_USAGE_RAID (1 << 2)
298#define BLKID_USAGE_CRYPTO (1 << 3)
299#define BLKID_USAGE_OTHER (1 << 4)
300extern int blkid_probe_filter_superblocks_usage(blkid_probe pr, int flag, int usage);
301
302/*
303 * topology probing
304 */
305extern int blkid_probe_enable_topology(blkid_probe pr, int enable);
306
307/* binary interface */
308extern blkid_topology blkid_probe_get_topology(blkid_probe pr)
309 __ul_attribute__((warn_unused_result));
310
311extern unsigned long blkid_topology_get_alignment_offset(blkid_topology tp)
312 __ul_attribute__((nonnull))
313 __ul_attribute__((warn_unused_result));
314extern unsigned long blkid_topology_get_minimum_io_size(blkid_topology tp)
315 __ul_attribute__((nonnull))
316 __ul_attribute__((warn_unused_result));
317extern unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp)
318 __ul_attribute__((nonnull))
319 __ul_attribute__((warn_unused_result));
320extern unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp)
321 __ul_attribute__((nonnull))
322 __ul_attribute__((warn_unused_result));
323extern unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp)
324 __ul_attribute__((nonnull))
325 __ul_attribute__((warn_unused_result));
326
327/*
328 * partitions probing
329 */
330extern int blkid_known_pttype(const char *pttype)
331 __ul_attribute__((warn_unused_result));
332
333extern int blkid_probe_enable_partitions(blkid_probe pr, int enable);
334
335extern int blkid_probe_reset_partitions_filter(blkid_probe pr);
336extern int blkid_probe_invert_partitions_filter(blkid_probe pr);
337extern int blkid_probe_filter_partitions_type(blkid_probe pr, int flag, char *names[]);
338
339/* partitions probing flags */
340#define BLKID_PARTS_FORCE_GPT (1 << 1)
341#define BLKID_PARTS_ENTRY_DETAILS (1 << 2)
342#define BLKID_PARTS_MAGIC (1 << 3)
343extern int blkid_probe_set_partitions_flags(blkid_probe pr, int flags);
344
345/* binary interface */
346extern blkid_partlist blkid_probe_get_partitions(blkid_probe pr)
347 __ul_attribute__((warn_unused_result));
348
349extern int blkid_partlist_numof_partitions(blkid_partlist ls)
350 __ul_attribute__((warn_unused_result));
351extern blkid_parttable blkid_partlist_get_table(blkid_partlist ls)
352 __ul_attribute__((warn_unused_result));
353extern blkid_partition blkid_partlist_get_partition(blkid_partlist ls, int n)
354 __ul_attribute__((warn_unused_result));
355extern blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno)
356 __ul_attribute__((warn_unused_result));
357extern blkid_parttable blkid_partition_get_table(blkid_partition par)
358 __ul_attribute__((warn_unused_result));
359
360extern const char *blkid_partition_get_name(blkid_partition par)
361 __ul_attribute__((warn_unused_result));
362extern const char *blkid_partition_get_uuid(blkid_partition par)
363 __ul_attribute__((warn_unused_result));
364extern int blkid_partition_get_partno(blkid_partition par)
365 __ul_attribute__((warn_unused_result));
366extern blkid_loff_t blkid_partition_get_start(blkid_partition par)
367 __ul_attribute__((warn_unused_result));
368extern blkid_loff_t blkid_partition_get_size(blkid_partition par)
369 __ul_attribute__((warn_unused_result));
370
371extern int blkid_partition_get_type(blkid_partition par)
372 __ul_attribute__((nonnull))
373 __ul_attribute__((warn_unused_result));
374
375extern const char *blkid_partition_get_type_string(blkid_partition par)
376 __ul_attribute__((warn_unused_result));
377
378extern unsigned long long blkid_partition_get_flags(blkid_partition par)
379 __ul_attribute__((nonnull))
380 __ul_attribute__((warn_unused_result));
381
382extern int blkid_partition_is_logical(blkid_partition par)
383 __ul_attribute__((nonnull))
384 __ul_attribute__((warn_unused_result));
385extern int blkid_partition_is_extended(blkid_partition par)
386 __ul_attribute__((nonnull))
387 __ul_attribute__((warn_unused_result));
388extern int blkid_partition_is_primary(blkid_partition par)
389 __ul_attribute__((nonnull))
390 __ul_attribute__((warn_unused_result));
391
392extern const char *blkid_parttable_get_type(blkid_parttable tab)
393 __ul_attribute__((warn_unused_result));
394
395extern const char *blkid_parttable_get_id(blkid_parttable tab)
396 __ul_attribute__((warn_unused_result));
397
398extern blkid_loff_t blkid_parttable_get_offset(blkid_parttable tab)
399 __ul_attribute__((warn_unused_result));
400extern blkid_partition blkid_parttable_get_parent(blkid_parttable tab)
401 __ul_attribute__((warn_unused_result));
402
403/*
404 * NAME=value low-level interface
405 */
406extern int blkid_do_probe(blkid_probe pr);
407extern int blkid_do_safeprobe(blkid_probe pr);
408extern int blkid_do_fullprobe(blkid_probe pr);
409
410extern int blkid_probe_numof_values(blkid_probe pr)
411 __ul_attribute__((warn_unused_result));
412extern int blkid_probe_get_value(blkid_probe pr, int num, const char **name,
413 const char **data, size_t *len);
414extern int blkid_probe_lookup_value(blkid_probe pr, const char *name,
415 const char **data, size_t *len);
416extern int blkid_probe_has_value(blkid_probe pr, const char *name)
417 __ul_attribute__((nonnull))
418 __ul_attribute__((warn_unused_result));
419
420extern int blkid_do_wipe(blkid_probe pr, int dryrun);
421extern int blkid_probe_step_back(blkid_probe pr);
422
423/*
424 * Deprecated functions/macros
425 */
426#ifndef BLKID_DISABLE_DEPRECATED
427
428#define BLKID_PROBREQ_LABEL BLKID_SUBLKS_LABEL
429#define BLKID_PROBREQ_LABELRAW BLKID_SUBLKS_LABELRAW
430#define BLKID_PROBREQ_UUID BLKID_SUBLKS_UUID
431#define BLKID_PROBREQ_UUIDRAW BLKID_SUBLKS_UUIDRAW
432#define BLKID_PROBREQ_TYPE BLKID_SUBLKS_TYPE
433#define BLKID_PROBREQ_SECTYPE BLKID_SUBLKS_SECTYPE
434#define BLKID_PROBREQ_USAGE BLKID_SUBLKS_USAGE
435#define BLKID_PROBREQ_VERSION BLKID_SUBLKS_VERSION
436
437extern int blkid_probe_set_request(blkid_probe pr, int flags)
438 __ul_attribute__((deprecated));
439
440extern int blkid_probe_filter_usage(blkid_probe pr, int flag, int usage)
441 __ul_attribute__((deprecated));
442
443extern int blkid_probe_filter_types(blkid_probe pr, int flag, char *names[])
444 __ul_attribute__((deprecated));
445
446extern int blkid_probe_invert_filter(blkid_probe pr)
447 __ul_attribute__((deprecated));
448
449extern int blkid_probe_reset_filter(blkid_probe pr)
450 __ul_attribute__((deprecated));
451
452#endif /* BLKID_DISABLE_DEPRECATED */
453
454#ifdef __cplusplus
455}
456#endif
457
458#endif /* _BLKID_BLKID_H */