2 * blkidP.h - Internal interfaces for libblkid
4 * Copyright (C) 2001 Andreas Dilger
5 * Copyright (C) 2003 Theodore Ts'o
8 * This file may be redistributed under the terms of the
9 * GNU Lesser General Public License.
13 #ifndef _BLKID_BLKIDP_H
14 #define _BLKID_BLKIDP_H
17 #define CONFIG_BLKID_DEBUG 1
19 #include <sys/types.h>
27 #include "bitops.h" /* $(top_srcdir)/include/ */
31 #include <libubox/list.h>
34 * This describes the attributes of a specific device.
35 * We can traverse all of the tags by bid_tags (linking to the tag bit_names).
36 * The bid_label and bid_uuid fields are shortcuts to the LABEL and UUID tag
37 * values, if they exist.
39 struct blkid_struct_dev
41 struct list_head bid_devs
; /* All devices in the cache */
42 struct list_head bid_tags
; /* All tags for this device */
43 blkid_cache bid_cache
; /* Dev belongs to this cache */
44 char *bid_name
; /* Device inode pathname */
45 char *bid_type
; /* Preferred device TYPE */
46 int bid_pri
; /* Device priority */
47 dev_t bid_devno
; /* Device major/minor number */
48 time_t bid_time
; /* Last update time of device */
49 suseconds_t bid_utime
; /* Last update time (microseconds) */
50 unsigned int bid_flags
; /* Device status bitflags */
51 char *bid_label
; /* Shortcut to device LABEL */
52 char *bid_uuid
; /* Shortcut to binary UUID */
55 #define BLKID_BID_FL_VERIFIED 0x0001 /* Device data validated from disk */
56 #define BLKID_BID_FL_INVALID 0x0004 /* Device is invalid */
57 #define BLKID_BID_FL_REMOVABLE 0x0008 /* Device added by blkid_probe_all_removable() */
60 * Each tag defines a NAME=value pair for a particular device. The tags
61 * are linked via bit_names for a single device, so that traversing the
62 * names list will get you a list of all tags associated with a device.
63 * They are also linked via bit_values for all devices, so one can easily
64 * search all tags with a given NAME for a specific value.
66 struct blkid_struct_tag
68 struct list_head bit_tags
; /* All tags for this device */
69 struct list_head bit_names
; /* All tags with given NAME */
70 char *bit_name
; /* NAME of tag (shared) */
71 char *bit_val
; /* value of tag */
72 blkid_dev bit_dev
; /* pointer to device */
74 typedef struct blkid_struct_tag
*blkid_tag
;
80 BLKID_CHAIN_SUBLKS
, /* FS/RAID superblocks (enabled by default) */
81 BLKID_CHAIN_TOPLGY
, /* Block device topology */
82 BLKID_CHAIN_PARTS
, /* Partition tables */
84 BLKID_NCHAINS
/* number of chains */
88 const struct blkid_chaindrv
*driver
; /* chain driver */
90 int enabled
; /* boolean */
91 int flags
; /* BLKID_<chain>_* */
92 int binary
; /* boolean */
93 int idx
; /* index of the current prober (or -1) */
94 unsigned long *fltr
; /* filter or NULL */
95 void *data
; /* private chain data or NULL */
101 struct blkid_chaindrv
{
102 const size_t id
; /* BLKID_CHAIN_* */
103 const char *name
; /* name of chain (for debug purpose) */
104 const int dflt_flags
; /* default chain flags */
105 const int dflt_enabled
; /* default enabled boolean */
106 int has_fltr
; /* boolean */
108 const struct blkid_idinfo
**idinfos
; /* description of probing functions */
109 const size_t nidinfos
; /* number of idinfos */
111 /* driver operations */
112 int (*probe
)(blkid_probe
, struct blkid_chain
*);
113 int (*safeprobe
)(blkid_probe
, struct blkid_chain
*);
114 void (*free_data
)(blkid_probe
, void *);
118 * Low-level probe result
120 #define BLKID_PROBVAL_BUFSIZ 64
122 #define BLKID_NVALS_SUBLKS 14
123 #define BLKID_NVALS_TOPLGY 5
124 #define BLKID_NVALS_PARTS 13
126 /* Max number of all values in probing result */
127 #define BLKID_NVALS (BLKID_NVALS_SUBLKS + \
128 BLKID_NVALS_TOPLGY + \
133 const char *name
; /* value name */
134 unsigned char data
[BLKID_PROBVAL_BUFSIZ
]; /* value data */
135 size_t len
; /* length of value data */
137 struct blkid_chain
*chain
; /* owner */
141 * Filesystem / Raid magic strings
144 * Filesystem / Raid description
146 #define BLKID_NONE_MAGIC {{ NULL }}
149 * tolerant FS - can share the same device with more filesystems (e.g. typical
150 * on CD-ROMs). We need this flag to detect ambivalent results (e.g. valid fat
151 * and valid linux swap on the same device).
153 #define BLKID_IDINFO_TOLERANT (1 << 1)
155 struct blkid_bufinfo
{
159 struct list_head bufs
; /* list of buffers */
162 /* private flags library flags */
163 #define BLKID_FL_PRIVATE_FD (1 << 1) /* see blkid_new_probe_from_filename() */
164 #define BLKID_FL_TINY_DEV (1 << 2) /* <= 1.47MiB (floppy or so) */
165 #define BLKID_FL_CDROM_DEV (1 << 3) /* is a CD/DVD drive */
167 /* private per-probing flags */
168 #define BLKID_PROBE_FL_IGNORE_PT (1 << 1) /* ignore partition table */
170 extern blkid_probe
blkid_clone_probe(blkid_probe parent
);
171 extern blkid_probe
blkid_probe_get_wholedisk_probe(blkid_probe pr
);
174 * Evaluation methods (for blkid_eval_* API)
184 * Library config options
186 struct blkid_config
{
187 int eval
[__BLKID_EVAL_LAST
]; /* array with EVALUATION=<udev,cache> options */
188 int nevals
; /* number of elems in eval array */
189 int uevent
; /* SEND_UEVENT=<yes|not> option */
190 char *cachefile
; /* CACHE_FILE=<path> option */
193 extern struct blkid_config
*blkid_read_config(const char *filename
);
194 extern void blkid_free_config(struct blkid_config
*conf
);
197 * Minimum number of seconds between device probes, even when reading
198 * from the cache. This is to avoid re-probing all devices which were
199 * just probed by another program that does not share the cache.
201 #define BLKID_PROBE_MIN 2
204 * Time in seconds an entry remains verified in the in-memory cache
205 * before being reverified (in case of long-running processes that
206 * keep a cache in memory and continue to use it for a long time).
208 #define BLKID_PROBE_INTERVAL 200
210 /* This describes an entire blkid cache file and probed devices.
211 * We can traverse all of the found devices via bic_list.
212 * We can traverse all of the tag types by bic_tags, which hold empty tags
213 * for each tag type. Those tags can be used as list_heads for iterating
214 * through all devices with a specific tag type (e.g. LABEL).
216 struct blkid_struct_cache
218 struct list_head bic_devs
; /* List head of all devices */
219 struct list_head bic_tags
; /* List head of all tag types */
220 time_t bic_time
; /* Last probe time */
221 time_t bic_ftime
; /* Mod time of the cachefile */
222 unsigned int bic_flags
; /* Status flags of the cache */
223 char *bic_filename
; /* filename of cache */
224 blkid_probe probe
; /* low-level probing stuff */
227 #define BLKID_BIC_FL_PROBED 0x0002 /* We probed /proc/partition devices */
228 #define BLKID_BIC_FL_CHANGED 0x0004 /* Cache has changed from disk */
230 extern char *blkid_strdup(const char *s
);
231 extern char *blkid_strndup(const char *s
, const int length
);
232 extern char *blkid_strconcat(const char *a
, const char *b
, const char *c
);
235 #define BLKID_CONFIG_FILE "/etc/blkid.conf"
237 /* cache file on systemds with /run */
238 #define BLKID_RUNTIME_TOPDIR "/run"
239 #define BLKID_RUNTIME_DIR BLKID_RUNTIME_TOPDIR "/blkid"
240 #define BLKID_CACHE_FILE BLKID_RUNTIME_DIR "/blkid.tab"
243 #define BLKID_CACHE_FILE_OLD "/etc/blkid.tab"
245 #define BLKID_ERR_IO 5
246 #define BLKID_ERR_PROC 9
247 #define BLKID_ERR_MEM 12
248 #define BLKID_ERR_CACHE 14
249 #define BLKID_ERR_DEV 19
250 #define BLKID_ERR_PARAM 22
251 #define BLKID_ERR_BIG 27
254 * Priority settings for different types of devices
256 #define BLKID_PRI_UBI 50
257 #define BLKID_PRI_DM 40
258 #define BLKID_PRI_EVMS 30
259 #define BLKID_PRI_LVM 20
260 #define BLKID_PRI_MD 10
262 #if defined(TEST_PROGRAM) && !defined(CONFIG_BLKID_DEBUG)
263 #define CONFIG_BLKID_DEBUG
266 #define DEBUG_CACHE 0x0001
267 #define DEBUG_DUMP 0x0002
268 #define DEBUG_DEV 0x0004
269 #define DEBUG_DEVNAME 0x0008
270 #define DEBUG_DEVNO 0x0010
271 #define DEBUG_PROBE 0x0020
272 #define DEBUG_READ 0x0040
273 #define DEBUG_RESOLVE 0x0080
274 #define DEBUG_SAVE 0x0100
275 #define DEBUG_TAG 0x0200
276 #define DEBUG_LOWPROBE 0x0400
277 #define DEBUG_CONFIG 0x0800
278 #define DEBUG_EVALUATE 0x1000
279 #define DEBUG_INIT 0x8000
280 #define DEBUG_ALL 0xFFFF
282 #ifdef CONFIG_BLKID_DEBUG
283 extern int blkid_debug_mask
;
284 extern void blkid_init_debug(int mask
);
285 extern void blkid_debug_dump_dev(blkid_dev dev
);
286 extern void blkid_debug_dump_tag(blkid_tag tag
);
288 #define DBG(m,x) if ((m) & blkid_debug_mask) x;
290 #else /* !CONFIG_BLKID_DEBUG */
292 #define blkid_init_debug(x)
293 #endif /* CONFIG_BLKID_DEBUG */
298 struct dir_list
*next
;
300 extern void blkid__scan_dir(char *, dev_t
, struct dir_list
**, char **);
301 extern int blkid_driver_has_major(const char *drvname
, int major
);
304 extern blkid_loff_t
blkid_llseek(int fd
, blkid_loff_t offset
, int whence
);
307 extern void blkid_read_cache(blkid_cache cache
);
310 extern int blkid_flush_cache(blkid_cache cache
);
313 extern char *blkid_safe_getenv(const char *arg
);
314 extern char *blkid_get_cache_filename(struct blkid_config
*conf
);
317 * Functions to create and find a specific tag type: tag.c
319 extern void blkid_free_tag(blkid_tag tag
);
320 extern blkid_tag
blkid_find_tag_dev(blkid_dev dev
, const char *type
);
321 extern int blkid_set_tag(blkid_dev dev
, const char *name
,
322 const char *value
, const int vlength
);
325 * Functions to create and find a specific tag type: dev.c
327 extern blkid_dev
blkid_new_dev(void);
328 extern void blkid_free_dev(blkid_dev dev
);
331 extern int blkid_probe_is_tiny(blkid_probe pr
);
332 extern int blkid_probe_is_cdrom(blkid_probe pr
);
333 extern unsigned char *blkid_probe_get_buffer(blkid_probe pr
,
334 blkid_loff_t off
, blkid_loff_t len
);
336 extern unsigned char *blkid_probe_get_sector(blkid_probe pr
, unsigned int sector
);
338 extern int blkid_probe_get_dimension(blkid_probe pr
,
339 blkid_loff_t
*off
, blkid_loff_t
*size
);
341 extern int blkid_probe_set_dimension(blkid_probe pr
,
342 blkid_loff_t off
, blkid_loff_t size
);
344 extern int blkid_probe_get_idmag(blkid_probe pr
, const struct blkid_idinfo
*id
,
345 blkid_loff_t
*offset
, const struct blkid_idmag
**res
);
347 /* returns superblok according to 'struct blkid_idmag' */
348 #define blkid_probe_get_sb(_pr, _mag, type) \
349 ((type *) blkid_probe_get_buffer((_pr),\
350 (_mag)->kboff << 10, sizeof(type)))
352 extern blkid_partlist
blkid_probe_get_partlist(blkid_probe pr
);
354 extern int blkid_probe_is_covered_by_pt(blkid_probe pr
,
355 blkid_loff_t offset
, blkid_loff_t size
);
357 extern void blkid_probe_chain_reset_vals(blkid_probe pr
, struct blkid_chain
*chn
);
358 extern int blkid_probe_chain_copy_vals(blkid_probe pr
, struct blkid_chain
*chn
,
359 struct blkid_prval
*vals
, int nvals
);
360 extern struct blkid_prval
*blkid_probe_assign_value(blkid_probe pr
, const char *name
);
361 extern int blkid_probe_reset_last_value(blkid_probe pr
);
362 extern void blkid_probe_append_vals(blkid_probe pr
, struct blkid_prval
*vals
, int nvals
);
364 extern struct blkid_chain
*blkid_probe_get_chain(blkid_probe pr
);
366 extern struct blkid_prval
*__blkid_probe_get_value(blkid_probe pr
, int num
);
367 extern struct blkid_prval
*__blkid_probe_lookup_value(blkid_probe pr
, const char *name
);
369 extern unsigned long *blkid_probe_get_filter(blkid_probe pr
, int chain
, int create
);
370 extern int __blkid_probe_invert_filter(blkid_probe pr
, int chain
);
371 extern int __blkid_probe_reset_filter(blkid_probe pr
, int chain
);
372 extern int __blkid_probe_filter_types(blkid_probe pr
, int chain
, int flag
, char *names
[]);
374 extern void *blkid_probe_get_binary_data(blkid_probe pr
, struct blkid_chain
*chn
);
376 extern int blkid_probe_set_value(blkid_probe pr
, const char *name
,
377 unsigned char *data
, size_t len
);
378 extern int blkid_probe_vsprintf_value(blkid_probe pr
, const char *name
,
379 const char *fmt
, va_list ap
);
380 extern int blkid_probe_sprintf_value(blkid_probe pr
, const char *name
,
381 const char *fmt
, ...);
382 extern int blkid_probe_set_magic(blkid_probe pr
, blkid_loff_t offset
,
383 size_t len
, unsigned char *magic
);
385 extern void blkid_unparse_uuid(const unsigned char *uuid
, char *str
, size_t len
);
386 extern size_t blkid_rtrim_whitespace(unsigned char *str
);
388 extern void blkid_probe_set_wiper(blkid_probe pr
, blkid_loff_t off
,
390 extern int blkid_probe_is_wiped(blkid_probe pr
, struct blkid_chain
**chn
,
391 blkid_loff_t off
, blkid_loff_t size
);
392 extern void blkid_probe_use_wiper(blkid_probe pr
, blkid_loff_t off
, blkid_loff_t size
);
394 /* filter bitmap macros */
395 #define blkid_bmp_wordsize (8 * sizeof(unsigned long))
396 #define blkid_bmp_idx_bit(item) (1UL << ((item) % blkid_bmp_wordsize))
397 #define blkid_bmp_idx_byte(item) ((item) / blkid_bmp_wordsize)
399 #define blkid_bmp_set_item(bmp, item) \
400 ((bmp)[ blkid_bmp_idx_byte(item) ] |= blkid_bmp_idx_bit(item))
402 #define blkid_bmp_unset_item(bmp, item) \
403 ((bmp)[ blkid_bmp_idx_byte(item) ] &= ~blkid_bmp_idx_bit(item))
405 #define blkid_bmp_get_item(bmp, item) \
406 ((bmp)[ blkid_bmp_idx_byte(item) ] & blkid_bmp_idx_bit(item))
408 #define blkid_bmp_nwords(max_items) \
409 (((max_items) + blkid_bmp_wordsize) / blkid_bmp_wordsize)
411 #define blkid_bmp_nbytes(max_items) \
412 (blkid_bmp_nwords(max_items) * sizeof(unsigned long))
415 extern size_t blkid_encode_to_utf8(int enc
, unsigned char *dest
, size_t len
,
416 const unsigned char *src
, size_t count
);
418 #define BLKID_ENC_UTF16BE 0
419 #define BLKID_ENC_UTF16LE 1
421 #endif /* _BLKID_BLKIDP_H */