2 * blkid.h - Interface for libblkid, a library to identify block devices
4 * Copyright (C) 2001 Andreas Dilger
5 * Copyright (C) 2003 Theodore Ts'o
6 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifndef _BLKID_BLKID_H
24 #define _BLKID_BLKID_H
27 #include <sys/types.h>
29 #include "libblkid-tiny.h"
35 #define BLKID_VERSION "2.21.0"
36 #define BLKID_DATE "25-May-2012"
41 * The device object keeps information about one device
43 typedef struct blkid_struct_dev
*blkid_dev
;
48 * information about all system devices
50 typedef struct blkid_struct_cache
*blkid_cache
;
55 * low-level probing setting
57 typedef struct blkid_struct_probe
*blkid_probe
;
62 * device topology information
64 typedef struct blkid_struct_topology
*blkid_topology
;
69 * list of all detected partitions and partitions tables
71 typedef struct blkid_struct_partlist
*blkid_partlist
;
76 * information about a partition
78 typedef struct blkid_struct_partition
*blkid_partition
;
83 * information about a partition table
85 typedef struct blkid_struct_parttable
*blkid_parttable
;
90 * 64-bit signed number for offsets and sizes
92 typedef int64_t blkid_loff_t
;
97 * tags iterator for high-level (blkid_cache) API
99 typedef struct blkid_struct_tag_iterate
*blkid_tag_iterate
;
104 * devices iterator for high-level (blkid_cache) API
106 typedef struct blkid_struct_dev_iterate
*blkid_dev_iterate
;
109 * Flags for blkid_get_dev
111 * BLKID_DEV_CREATE Create an empty device structure if not found
113 * BLKID_DEV_VERIFY Make sure the device structure corresponds
115 * BLKID_DEV_FIND Just look up a device entry, and return NULL
116 * if it is not found.
117 * BLKID_DEV_NORMAL Get a valid device structure, either from the
118 * cache or by probing the device.
120 #define BLKID_DEV_FIND 0x0000
121 #define BLKID_DEV_CREATE 0x0001
122 #define BLKID_DEV_VERIFY 0x0002
123 #define BLKID_DEV_NORMAL (BLKID_DEV_CREATE | BLKID_DEV_VERIFY)
126 extern void blkid_put_cache(blkid_cache cache
);
127 extern int blkid_get_cache(blkid_cache
*cache
, const char *filename
);
128 extern void blkid_gc_cache(blkid_cache cache
);
131 extern const char *blkid_dev_devname(blkid_dev dev
);
133 extern blkid_dev_iterate
blkid_dev_iterate_begin(blkid_cache cache
);
134 extern int blkid_dev_set_search(blkid_dev_iterate iter
,
135 char *search_type
, char *search_value
);
136 extern int blkid_dev_next(blkid_dev_iterate iterate
, blkid_dev
*dev
);
137 extern void blkid_dev_iterate_end(blkid_dev_iterate iterate
);
140 extern char *blkid_devno_to_devname(dev_t devno
);
141 extern int blkid_devno_to_wholedisk(dev_t dev
, char *diskname
,
142 size_t len
, dev_t
*diskdevno
);
145 extern int blkid_probe_all(blkid_cache cache
);
146 extern int blkid_probe_all_new(blkid_cache cache
);
147 extern int blkid_probe_all_removable(blkid_cache cache
);
148 extern blkid_dev
blkid_get_dev(blkid_cache cache
, const char *devname
,
152 extern blkid_loff_t
blkid_get_dev_size(int fd
);
155 extern blkid_dev
blkid_verify(blkid_cache cache
, blkid_dev dev
);
160 extern char *blkid_get_tag_value(blkid_cache cache
, const char *tagname
,
161 const char *devname
);
162 extern char *blkid_get_devname(blkid_cache cache
, const char *token
,
166 extern blkid_tag_iterate
blkid_tag_iterate_begin(blkid_dev dev
);
167 extern int blkid_tag_next(blkid_tag_iterate iterate
,
168 const char **type
, const char **value
);
169 extern void blkid_tag_iterate_end(blkid_tag_iterate iterate
);
170 extern int blkid_dev_has_tag(blkid_dev dev
, const char *type
,
172 extern blkid_dev
blkid_find_dev_with_tag(blkid_cache cache
,
175 extern int blkid_parse_tag_string(const char *token
, char **ret_type
,
179 extern int blkid_parse_version_string(const char *ver_string
);
180 extern int blkid_get_library_version(const char **ver_string
,
181 const char **date_string
);
184 extern int blkid_encode_string(const char *str
, char *str_enc
, size_t len
);
185 extern int blkid_safe_string(const char *str
, char *str_safe
, size_t len
);
188 extern int blkid_send_uevent(const char *devname
, const char *action
);
189 extern char *blkid_evaluate_tag(const char *token
, const char *value
,
191 extern char *blkid_evaluate_spec(const char *spec
, blkid_cache
*cache
);
194 extern blkid_probe
blkid_new_probe(void);
195 extern blkid_probe
blkid_new_probe_from_filename(const char *filename
);
196 extern void blkid_free_probe(blkid_probe pr
);
197 extern void blkid_reset_probe(blkid_probe pr
);
199 extern int blkid_probe_set_device(blkid_probe pr
, int fd
,
200 blkid_loff_t off
, blkid_loff_t size
);
202 extern dev_t
blkid_probe_get_devno(blkid_probe pr
);
203 extern dev_t
blkid_probe_get_wholedisk_devno(blkid_probe pr
);
204 extern int blkid_probe_is_wholedisk(blkid_probe pr
);
206 extern blkid_loff_t
blkid_probe_get_size(blkid_probe pr
);
207 extern blkid_loff_t
blkid_probe_get_offset(blkid_probe pr
);
208 extern unsigned int blkid_probe_get_sectorsize(blkid_probe pr
);
209 extern blkid_loff_t
blkid_probe_get_sectors(blkid_probe pr
);
211 extern int blkid_probe_get_fd(blkid_probe pr
);
214 * superblocks probing
216 extern int blkid_known_fstype(const char *fstype
);
217 extern int blkid_superblocks_get_name(size_t idx
, const char **name
, int *usage
);
219 extern int blkid_probe_enable_superblocks(blkid_probe pr
, int enable
);
221 #define BLKID_SUBLKS_LABEL (1 << 1) /* read LABEL from superblock */
222 #define BLKID_SUBLKS_LABELRAW (1 << 2) /* read and define LABEL_RAW result value*/
223 #define BLKID_SUBLKS_UUID (1 << 3) /* read UUID from superblock */
224 #define BLKID_SUBLKS_UUIDRAW (1 << 4) /* read and define UUID_RAW result value */
225 #define BLKID_SUBLKS_TYPE (1 << 5) /* define TYPE result value */
226 #define BLKID_SUBLKS_SECTYPE (1 << 6) /* define compatible fs type (second type) */
227 #define BLKID_SUBLKS_USAGE (1 << 7) /* define USAGE result value */
228 #define BLKID_SUBLKS_VERSION (1 << 8) /* read FS type from superblock */
229 #define BLKID_SUBLKS_MAGIC (1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
231 #define BLKID_SUBLKS_DEFAULT (BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | \
232 BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE)
234 extern int blkid_probe_set_superblocks_flags(blkid_probe pr
, int flags
);
236 extern int blkid_probe_reset_superblocks_filter(blkid_probe pr
);
237 extern int blkid_probe_invert_superblocks_filter(blkid_probe pr
);
242 #define BLKID_FLTR_NOTIN 1
246 #define BLKID_FLTR_ONLYIN 2
247 extern int blkid_probe_filter_superblocks_type(blkid_probe pr
, int flag
, char *names
[]);
249 #define BLKID_USAGE_FILESYSTEM (1 << 1)
250 #define BLKID_USAGE_RAID (1 << 2)
251 #define BLKID_USAGE_CRYPTO (1 << 3)
252 #define BLKID_USAGE_OTHER (1 << 4)
253 extern int blkid_probe_filter_superblocks_usage(blkid_probe pr
, int flag
, int usage
);
258 extern int blkid_probe_enable_topology(blkid_probe pr
, int enable
);
260 /* binary interface */
261 extern blkid_topology
blkid_probe_get_topology(blkid_probe pr
);
263 extern unsigned long blkid_topology_get_alignment_offset(blkid_topology tp
);
264 extern unsigned long blkid_topology_get_minimum_io_size(blkid_topology tp
);
265 extern unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp
);
266 extern unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp
);
267 extern unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp
);
272 extern int blkid_known_pttype(const char *pttype
);
273 extern int blkid_probe_enable_partitions(blkid_probe pr
, int enable
);
275 extern int blkid_probe_reset_partitions_filter(blkid_probe pr
);
276 extern int blkid_probe_invert_partitions_filter(blkid_probe pr
);
277 extern int blkid_probe_filter_partitions_type(blkid_probe pr
, int flag
, char *names
[]);
280 /* partitions probing flags */
281 #define BLKID_PARTS_FORCE_GPT (1 << 1)
282 #define BLKID_PARTS_ENTRY_DETAILS (1 << 2)
283 #define BLKID_PARTS_MAGIC (1 << 3)
284 extern int blkid_probe_set_partitions_flags(blkid_probe pr
, int flags
);
286 /* binary interface */
287 extern blkid_partlist
blkid_probe_get_partitions(blkid_probe pr
);
289 extern int blkid_partlist_numof_partitions(blkid_partlist ls
);
290 extern blkid_parttable
blkid_partlist_get_table(blkid_partlist ls
);
291 extern blkid_partition
blkid_partlist_get_partition(blkid_partlist ls
, int n
);
292 extern blkid_partition
blkid_partlist_devno_to_partition(blkid_partlist ls
, dev_t devno
);
294 extern blkid_parttable
blkid_partition_get_table(blkid_partition par
);
295 extern const char *blkid_partition_get_name(blkid_partition par
);
296 extern const char *blkid_partition_get_uuid(blkid_partition par
);
297 extern int blkid_partition_get_partno(blkid_partition par
);
298 extern blkid_loff_t
blkid_partition_get_start(blkid_partition par
);
299 extern blkid_loff_t
blkid_partition_get_size(blkid_partition par
);
300 extern int blkid_partition_get_type(blkid_partition par
);
301 extern const char *blkid_partition_get_type_string(blkid_partition par
);
302 extern unsigned long long blkid_partition_get_flags(blkid_partition par
);
303 extern int blkid_partition_is_logical(blkid_partition par
);
304 extern int blkid_partition_is_extended(blkid_partition par
);
305 extern int blkid_partition_is_primary(blkid_partition par
);
307 extern const char *blkid_parttable_get_type(blkid_parttable tab
);
308 extern blkid_loff_t
blkid_parttable_get_offset(blkid_parttable tab
);
309 extern blkid_partition
blkid_parttable_get_parent(blkid_parttable tab
);
312 * NAME=value low-level interface
314 extern int blkid_do_probe(blkid_probe pr
);
315 extern int blkid_do_safeprobe(blkid_probe pr
);
316 extern int blkid_do_fullprobe(blkid_probe pr
);
318 extern int blkid_probe_numof_values(blkid_probe pr
);
319 extern int blkid_probe_get_value(blkid_probe pr
, int num
, const char **name
,
320 const char **data
, size_t *len
);
321 extern int blkid_probe_lookup_value(blkid_probe pr
, const char *name
,
322 const char **data
, size_t *len
);
323 extern int blkid_probe_has_value(blkid_probe pr
, const char *name
);
325 extern int blkid_do_wipe(blkid_probe pr
, int dryrun
);
328 * Deprecated functions/macros
330 #ifndef BLKID_DISABLE_DEPRECATED
332 #define BLKID_PROBREQ_LABEL BLKID_SUBLKS_LABEL
333 #define BLKID_PROBREQ_LABELRAW BLKID_SUBLKS_LABELRAW
334 #define BLKID_PROBREQ_UUID BLKID_SUBLKS_UUID
335 #define BLKID_PROBREQ_UUIDRAW BLKID_SUBLKS_UUIDRAW
336 #define BLKID_PROBREQ_TYPE BLKID_SUBLKS_TYPE
337 #define BLKID_PROBREQ_SECTYPE BLKID_SUBLKS_SECTYPE
338 #define BLKID_PROBREQ_USAGE BLKID_SUBLKS_USAGE
339 #define BLKID_PROBREQ_VERSION BLKID_SUBLKS_VERSION
341 extern int blkid_probe_set_request(blkid_probe pr
, int flags
);
342 extern int blkid_probe_filter_usage(blkid_probe pr
, int flag
, int usage
);
343 extern int blkid_probe_filter_types(blkid_probe pr
, int flag
, char *names
[]);
344 extern int blkid_probe_invert_filter(blkid_probe pr
);
345 extern int blkid_probe_reset_filter(blkid_probe pr
);
347 #endif /* BLKID_DISABLE_DEPRECATED */
353 #endif /* _BLKID_BLKID_H */