blob: 4d43130217f80e37e83bc7e6689688c6e4dcc660 [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
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050029#ifdef __cplusplus
30extern "C" {
31#endif
32
bigbiff7b4c7a62015-01-01 19:44:14 -050033#define LIBBLKID_VERSION "2.25.0"
34#define LIBBLKID_DATE "22-Jul-2014"
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050035
36/**
37 * blkid_dev:
38 *
39 * The device object keeps information about one device
40 */
41typedef struct blkid_struct_dev *blkid_dev;
42
43/**
44 * blkid_cache:
45 *
46 * information about all system devices
47 */
48typedef struct blkid_struct_cache *blkid_cache;
49
50/**
51 * blkid_probe:
52 *
53 * low-level probing setting
54 */
55typedef struct blkid_struct_probe *blkid_probe;
56
57/**
58 * blkid_topology:
59 *
60 * device topology information
61 */
62typedef struct blkid_struct_topology *blkid_topology;
63
64/**
65 * blkid_partlist
66 *
67 * list of all detected partitions and partitions tables
68 */
69typedef struct blkid_struct_partlist *blkid_partlist;
70
71/**
72 * blkid_partition:
73 *
74 * information about a partition
75 */
76typedef struct blkid_struct_partition *blkid_partition;
77
78/**
79 * blkid_parttable:
80 *
81 * information about a partition table
82 */
83typedef struct blkid_struct_parttable *blkid_parttable;
84
85/**
86 * blkid_loff_t:
87 *
88 * 64-bit signed number for offsets and sizes
89 */
90typedef int64_t blkid_loff_t;
91
92/**
93 * blkid_tag_iterate:
94 *
95 * tags iterator for high-level (blkid_cache) API
96 */
97typedef struct blkid_struct_tag_iterate *blkid_tag_iterate;
98
99/**
100 * blkid_dev_iterate:
101 *
102 * devices iterator for high-level (blkid_cache) API
103 */
104typedef struct blkid_struct_dev_iterate *blkid_dev_iterate;
105
106/*
107 * Flags for blkid_get_dev
108 *
109 * BLKID_DEV_CREATE Create an empty device structure if not found
110 * in the cache.
111 * BLKID_DEV_VERIFY Make sure the device structure corresponds
112 * with reality.
113 * BLKID_DEV_FIND Just look up a device entry, and return NULL
114 * if it is not found.
115 * BLKID_DEV_NORMAL Get a valid device structure, either from the
116 * cache or by probing the device.
117 */
118#define BLKID_DEV_FIND 0x0000
119#define BLKID_DEV_CREATE 0x0001
120#define BLKID_DEV_VERIFY 0x0002
121#define BLKID_DEV_NORMAL (BLKID_DEV_CREATE | BLKID_DEV_VERIFY)
122
123
124#ifndef __GNUC_PREREQ
125# if defined __GNUC__ && defined __GNUC_MINOR__
126# define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
127# else
128# define __GNUC_PREREQ(maj, min) 0
129# endif
130#endif
131
132#ifndef __ul_attribute__
133# if __GNUC_PREREQ (3, 4)
134# define __ul_attribute__(_a_) __attribute__(_a_)
135# else
136# define __ul_attribute__(_a_)
137# endif
138#endif
139
140/* cache.c */
bigbiff7b4c7a62015-01-01 19:44:14 -0500141extern void blkid_init_debug(int mask);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500142extern 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
bigbiff7b4c7a62015-01-01 19:44:14 -0500150extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500151extern int blkid_dev_set_search(blkid_dev_iterate iter,
152 char *search_type, char *search_value);
153extern int blkid_dev_next(blkid_dev_iterate iterate, blkid_dev *dev);
154extern void blkid_dev_iterate_end(blkid_dev_iterate iterate);
155
156/* devno.c */
157extern char *blkid_devno_to_devname(dev_t devno)
158 __ul_attribute__((warn_unused_result));
159extern int blkid_devno_to_wholedisk(dev_t dev, char *diskname,
160 size_t len, dev_t *diskdevno)
161 __ul_attribute__((warn_unused_result));
162
163/* devname.c */
164extern int blkid_probe_all(blkid_cache cache);
165extern int blkid_probe_all_new(blkid_cache cache);
166extern int blkid_probe_all_removable(blkid_cache cache);
167
168extern blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags);
169
170/* getsize.c */
bigbiff7b4c7a62015-01-01 19:44:14 -0500171extern blkid_loff_t blkid_get_dev_size(int fd);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500172
173/* verify.c */
174extern blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev);
175
176/* read.c */
177
178/* resolve.c */
179extern char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
180 const char *devname)
181 __ul_attribute__((warn_unused_result));
182extern char *blkid_get_devname(blkid_cache cache, const char *token,
183 const char *value)
184 __ul_attribute__((warn_unused_result));
185
186/* tag.c */
bigbiff7b4c7a62015-01-01 19:44:14 -0500187extern blkid_tag_iterate blkid_tag_iterate_begin(blkid_dev dev);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500188extern int blkid_tag_next(blkid_tag_iterate iterate,
189 const char **type, const char **value);
190extern void blkid_tag_iterate_end(blkid_tag_iterate iterate);
bigbiff7b4c7a62015-01-01 19:44:14 -0500191extern int blkid_dev_has_tag(blkid_dev dev, const char *type, const char *value);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500192
193extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
194 const char *type,
bigbiff7b4c7a62015-01-01 19:44:14 -0500195 const char *value);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500196
197extern int blkid_parse_tag_string(const char *token, char **ret_type, char **ret_val);
198
199/* version.c */
200extern int blkid_parse_version_string(const char *ver_string)
bigbiff7b4c7a62015-01-01 19:44:14 -0500201 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500202extern int blkid_get_library_version(const char **ver_string,
203 const char **date_string);
204
205/* encode.c */
206extern int blkid_encode_string(const char *str, char *str_enc, size_t len);
207extern int blkid_safe_string(const char *str, char *str_safe, size_t len);
208
209/* evaluate.c */
210extern int blkid_send_uevent(const char *devname, const char *action);
211extern char *blkid_evaluate_tag(const char *token, const char *value,
212 blkid_cache *cache)
213 __ul_attribute__((warn_unused_result));
214extern char *blkid_evaluate_spec(const char *spec, blkid_cache *cache)
215 __ul_attribute__((warn_unused_result));
216
217/* probe.c */
218extern blkid_probe blkid_new_probe(void)
219 __ul_attribute__((warn_unused_result));
220extern blkid_probe blkid_new_probe_from_filename(const char *filename)
221 __ul_attribute__((warn_unused_result));
222extern void blkid_free_probe(blkid_probe pr);
223
224extern void blkid_reset_probe(blkid_probe pr);
225
226extern int blkid_probe_set_device(blkid_probe pr, int fd,
227 blkid_loff_t off, blkid_loff_t size);
228
229extern dev_t blkid_probe_get_devno(blkid_probe pr)
bigbiff7b4c7a62015-01-01 19:44:14 -0500230 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500231
232extern dev_t blkid_probe_get_wholedisk_devno(blkid_probe pr)
bigbiff7b4c7a62015-01-01 19:44:14 -0500233 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500234
235extern int blkid_probe_is_wholedisk(blkid_probe pr)
bigbiff7b4c7a62015-01-01 19:44:14 -0500236 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500237
bigbiff7b4c7a62015-01-01 19:44:14 -0500238extern blkid_loff_t blkid_probe_get_size(blkid_probe pr);
239extern blkid_loff_t blkid_probe_get_offset(blkid_probe pr);
240extern unsigned int blkid_probe_get_sectorsize(blkid_probe pr);
241extern blkid_loff_t blkid_probe_get_sectors(blkid_probe pr);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500242
bigbiff7b4c7a62015-01-01 19:44:14 -0500243extern int blkid_probe_get_fd(blkid_probe pr);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500244
245/*
246 * superblocks probing
247 */
bigbiff7b4c7a62015-01-01 19:44:14 -0500248extern int blkid_known_fstype(const char *fstype);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500249
250extern int blkid_superblocks_get_name(size_t idx, const char **name, int *usage);
251
252extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable);
253
254#define BLKID_SUBLKS_LABEL (1 << 1) /* read LABEL from superblock */
255#define BLKID_SUBLKS_LABELRAW (1 << 2) /* read and define LABEL_RAW result value*/
256#define BLKID_SUBLKS_UUID (1 << 3) /* read UUID from superblock */
257#define BLKID_SUBLKS_UUIDRAW (1 << 4) /* read and define UUID_RAW result value */
258#define BLKID_SUBLKS_TYPE (1 << 5) /* define TYPE result value */
259#define BLKID_SUBLKS_SECTYPE (1 << 6) /* define compatible fs type (second type) */
260#define BLKID_SUBLKS_USAGE (1 << 7) /* define USAGE result value */
261#define BLKID_SUBLKS_VERSION (1 << 8) /* read FS type from superblock */
262#define BLKID_SUBLKS_MAGIC (1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
bigbiff7b4c7a62015-01-01 19:44:14 -0500263#define BLKID_SUBLKS_BADCSUM (1 << 10) /* allow a bad checksum */
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500264
265#define BLKID_SUBLKS_DEFAULT (BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | \
266 BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE)
267
268extern int blkid_probe_set_superblocks_flags(blkid_probe pr, int flags);
269extern int blkid_probe_reset_superblocks_filter(blkid_probe pr);
270extern int blkid_probe_invert_superblocks_filter(blkid_probe pr);
271
272/**
273 * BLKID_FLTR_NOTIN
274 */
275#define BLKID_FLTR_NOTIN 1
276/**
277 * BLKID_FLTR_ONLYIN
278 */
279#define BLKID_FLTR_ONLYIN 2
280extern int blkid_probe_filter_superblocks_type(blkid_probe pr, int flag, char *names[]);
281
282#define BLKID_USAGE_FILESYSTEM (1 << 1)
283#define BLKID_USAGE_RAID (1 << 2)
284#define BLKID_USAGE_CRYPTO (1 << 3)
285#define BLKID_USAGE_OTHER (1 << 4)
286extern int blkid_probe_filter_superblocks_usage(blkid_probe pr, int flag, int usage);
287
288/*
289 * topology probing
290 */
291extern int blkid_probe_enable_topology(blkid_probe pr, int enable);
292
293/* binary interface */
bigbiff7b4c7a62015-01-01 19:44:14 -0500294extern blkid_topology blkid_probe_get_topology(blkid_probe pr);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500295
296extern unsigned long blkid_topology_get_alignment_offset(blkid_topology tp)
bigbiff7b4c7a62015-01-01 19:44:14 -0500297 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500298extern unsigned long blkid_topology_get_minimum_io_size(blkid_topology tp)
bigbiff7b4c7a62015-01-01 19:44:14 -0500299 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500300extern unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp)
bigbiff7b4c7a62015-01-01 19:44:14 -0500301 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500302extern unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp)
bigbiff7b4c7a62015-01-01 19:44:14 -0500303 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500304extern unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp)
bigbiff7b4c7a62015-01-01 19:44:14 -0500305 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500306
307/*
308 * partitions probing
309 */
bigbiff7b4c7a62015-01-01 19:44:14 -0500310extern int blkid_known_pttype(const char *pttype);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500311
312extern int blkid_probe_enable_partitions(blkid_probe pr, int enable);
313
314extern int blkid_probe_reset_partitions_filter(blkid_probe pr);
315extern int blkid_probe_invert_partitions_filter(blkid_probe pr);
316extern int blkid_probe_filter_partitions_type(blkid_probe pr, int flag, char *names[]);
317
318/* partitions probing flags */
319#define BLKID_PARTS_FORCE_GPT (1 << 1)
320#define BLKID_PARTS_ENTRY_DETAILS (1 << 2)
321#define BLKID_PARTS_MAGIC (1 << 3)
322extern int blkid_probe_set_partitions_flags(blkid_probe pr, int flags);
323
324/* binary interface */
bigbiff7b4c7a62015-01-01 19:44:14 -0500325extern blkid_partlist blkid_probe_get_partitions(blkid_probe pr);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500326
bigbiff7b4c7a62015-01-01 19:44:14 -0500327extern int blkid_partlist_numof_partitions(blkid_partlist ls);
328extern blkid_parttable blkid_partlist_get_table(blkid_partlist ls);
329extern blkid_partition blkid_partlist_get_partition(blkid_partlist ls, int n);
330extern blkid_partition blkid_partlist_get_partition_by_partno(blkid_partlist ls, int n);
331extern blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno);
332extern blkid_parttable blkid_partition_get_table(blkid_partition par);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500333
bigbiff7b4c7a62015-01-01 19:44:14 -0500334extern const char *blkid_partition_get_name(blkid_partition par);
335extern const char *blkid_partition_get_uuid(blkid_partition par);
336extern int blkid_partition_get_partno(blkid_partition par);
337extern blkid_loff_t blkid_partition_get_start(blkid_partition par);
338extern blkid_loff_t blkid_partition_get_size(blkid_partition par);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500339
340extern int blkid_partition_get_type(blkid_partition par)
bigbiff7b4c7a62015-01-01 19:44:14 -0500341 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500342
bigbiff7b4c7a62015-01-01 19:44:14 -0500343extern const char *blkid_partition_get_type_string(blkid_partition par);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500344
345extern unsigned long long blkid_partition_get_flags(blkid_partition par)
bigbiff7b4c7a62015-01-01 19:44:14 -0500346 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500347
348extern int blkid_partition_is_logical(blkid_partition par)
bigbiff7b4c7a62015-01-01 19:44:14 -0500349 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500350extern int blkid_partition_is_extended(blkid_partition par)
bigbiff7b4c7a62015-01-01 19:44:14 -0500351 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500352extern int blkid_partition_is_primary(blkid_partition par)
bigbiff7b4c7a62015-01-01 19:44:14 -0500353 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500354
bigbiff7b4c7a62015-01-01 19:44:14 -0500355extern const char *blkid_parttable_get_type(blkid_parttable tab);
356extern const char *blkid_parttable_get_id(blkid_parttable tab);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500357
bigbiff7b4c7a62015-01-01 19:44:14 -0500358extern blkid_loff_t blkid_parttable_get_offset(blkid_parttable tab);
359extern blkid_partition blkid_parttable_get_parent(blkid_parttable tab);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500360
361/*
362 * NAME=value low-level interface
363 */
364extern int blkid_do_probe(blkid_probe pr);
365extern int blkid_do_safeprobe(blkid_probe pr);
366extern int blkid_do_fullprobe(blkid_probe pr);
367
bigbiff7b4c7a62015-01-01 19:44:14 -0500368extern int blkid_probe_numof_values(blkid_probe pr);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500369extern int blkid_probe_get_value(blkid_probe pr, int num, const char **name,
370 const char **data, size_t *len);
371extern int blkid_probe_lookup_value(blkid_probe pr, const char *name,
372 const char **data, size_t *len);
373extern int blkid_probe_has_value(blkid_probe pr, const char *name)
bigbiff7b4c7a62015-01-01 19:44:14 -0500374 __ul_attribute__((nonnull));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500375
376extern int blkid_do_wipe(blkid_probe pr, int dryrun);
377extern int blkid_probe_step_back(blkid_probe pr);
378
379/*
380 * Deprecated functions/macros
381 */
382#ifndef BLKID_DISABLE_DEPRECATED
383
384#define BLKID_PROBREQ_LABEL BLKID_SUBLKS_LABEL
385#define BLKID_PROBREQ_LABELRAW BLKID_SUBLKS_LABELRAW
386#define BLKID_PROBREQ_UUID BLKID_SUBLKS_UUID
387#define BLKID_PROBREQ_UUIDRAW BLKID_SUBLKS_UUIDRAW
388#define BLKID_PROBREQ_TYPE BLKID_SUBLKS_TYPE
389#define BLKID_PROBREQ_SECTYPE BLKID_SUBLKS_SECTYPE
390#define BLKID_PROBREQ_USAGE BLKID_SUBLKS_USAGE
391#define BLKID_PROBREQ_VERSION BLKID_SUBLKS_VERSION
392
393extern int blkid_probe_set_request(blkid_probe pr, int flags)
394 __ul_attribute__((deprecated));
395
396extern int blkid_probe_filter_usage(blkid_probe pr, int flag, int usage)
397 __ul_attribute__((deprecated));
398
399extern int blkid_probe_filter_types(blkid_probe pr, int flag, char *names[])
400 __ul_attribute__((deprecated));
401
402extern int blkid_probe_invert_filter(blkid_probe pr)
403 __ul_attribute__((deprecated));
404
405extern int blkid_probe_reset_filter(blkid_probe pr)
406 __ul_attribute__((deprecated));
407
408#endif /* BLKID_DISABLE_DEPRECATED */
409
410#ifdef __cplusplus
411}
412#endif
413
414#endif /* _BLKID_BLKID_H */