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>
22
#include "bitops.h" /* $(top_srcdir)/include/ */
27
#define __BLKID_ATTR(x) __attribute__(x)
29
#define __BLKID_ATTR(x)
39
# define PATH_MAX 4096
42
/* TODO: move to some top-level util-linux include file */
44
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
48
* This describes the attributes of a specific device.
49
* We can traverse all of the tags by bid_tags (linking to the tag bit_names).
50
* The bid_label and bid_uuid fields are shortcuts to the LABEL and UUID tag
51
* values, if they exist.
53
struct blkid_struct_dev
55
struct list_head bid_devs; /* All devices in the cache */
56
struct list_head bid_tags; /* All tags for this device */
57
blkid_cache bid_cache; /* Dev belongs to this cache */
58
char *bid_name; /* Device inode pathname */
59
char *bid_type; /* Preferred device TYPE */
60
int bid_pri; /* Device priority */
61
dev_t bid_devno; /* Device major/minor number */
62
time_t bid_time; /* Last update time of device */
63
unsigned int bid_flags; /* Device status bitflags */
64
char *bid_label; /* Shortcut to device LABEL */
65
char *bid_uuid; /* Shortcut to binary UUID */
68
#define BLKID_BID_FL_VERIFIED 0x0001 /* Device data validated from disk */
69
#define BLKID_BID_FL_INVALID 0x0004 /* Device is invalid */
72
* Each tag defines a NAME=value pair for a particular device. The tags
73
* are linked via bit_names for a single device, so that traversing the
74
* names list will get you a list of all tags associated with a device.
75
* They are also linked via bit_values for all devices, so one can easily
76
* search all tags with a given NAME for a specific value.
78
struct blkid_struct_tag
80
struct list_head bit_tags; /* All tags for this device */
81
struct list_head bit_names; /* All tags with given NAME */
82
char *bit_name; /* NAME of tag (shared) */
83
char *bit_val; /* value of tag */
84
blkid_dev bit_dev; /* pointer to device */
86
typedef struct blkid_struct_tag *blkid_tag;
89
* Low-level probe result
91
#define BLKID_PROBVAL_BUFSIZ 64
92
#define BLKID_PROBVAL_NVALS 8 /* see blkid.h BLKID_PROBREQ_* */
96
const char *name; /* value name */
97
unsigned char data[BLKID_PROBVAL_BUFSIZ]; /* value data */
98
size_t len; /* length of value data */
102
* Low-level probing control struct
104
struct blkid_struct_probe
106
int fd; /* device file descriptor */
107
blkid_loff_t off; /* begin of data on the device */
108
blkid_loff_t size; /* end of data on the device */
110
unsigned char *sbbuf; /* superblok buffer */
111
size_t sbbuf_len; /* size of data in superblock buffer */
113
unsigned char *buf; /* seek buffer */
114
blkid_loff_t buf_off; /* offset of seek buffer */
115
size_t buf_len; /* size of data in seek buffer */
116
size_t buf_max; /* allocated size of seek buffer */
118
struct blkid_prval vals[BLKID_PROBVAL_NVALS];
121
int probreq; /* BLKID_PROBREQ_* flags */
122
int idx; /* index of the last prober */
124
unsigned long *fltr; /* filter */
127
#define BLKID_SB_BUFSIZ 0x11000
130
* Filesystem / Raid magic strings
134
const char *magic; /* magic string */
135
unsigned len; /* length of magic */
137
long kboff; /* kilobyte offset of superblock */
138
unsigned sboff; /* byte offset within superblock */
142
* Filesystem / Raid description
146
const char *name; /* FS/RAID name */
147
int usage; /* BLKID_USAGE_* flag */
148
int flags; /* BLKID_IDINFO_* flags */
151
int (*probefunc)(blkid_probe pr, const struct blkid_idmag *mag);
153
struct blkid_idmag magics[]; /* NULL or array with magic strings */
156
#define BLKID_NONE_MAGIC {{ NULL }}
159
* tolerant FS - can share the same device with more filesystems (e.g. typical
160
* on CD-ROMs). We need this flag to detect ambivalent results (e.g. valid fat
161
* and valid linux swap on the same device).
163
#define BLKID_IDINFO_TOLERANT (1 << 1)
166
* Evaluation methods (for blkid_eval_* API)
176
* Library config options
178
struct blkid_config {
179
int eval[__BLKID_EVAL_LAST]; /* array with EVALUATION=<udev,cache> options */
180
int nevals; /* number of elems in eval array */
181
int uevent; /* SEND_UEVENT=<yes|not> option */
182
char *cachefile; /* CACHE_FILE=<path> option */
185
extern struct blkid_config *blkid_read_config(const char *filename);
186
extern void blkid_free_config(struct blkid_config *conf);
189
* Minimum number of seconds between device probes, even when reading
190
* from the cache. This is to avoid re-probing all devices which were
191
* just probed by another program that does not share the cache.
193
#define BLKID_PROBE_MIN 2
196
* Time in seconds an entry remains verified in the in-memory cache
197
* before being reverified (in case of long-running processes that
198
* keep a cache in memory and continue to use it for a long time).
200
#define BLKID_PROBE_INTERVAL 200
202
/* This describes an entire blkid cache file and probed devices.
203
* We can traverse all of the found devices via bic_list.
204
* We can traverse all of the tag types by bic_tags, which hold empty tags
205
* for each tag type. Those tags can be used as list_heads for iterating
206
* through all devices with a specific tag type (e.g. LABEL).
208
struct blkid_struct_cache
210
struct list_head bic_devs; /* List head of all devices */
211
struct list_head bic_tags; /* List head of all tag types */
212
time_t bic_time; /* Last probe time */
213
time_t bic_ftime; /* Mod time of the cachefile */
214
unsigned int bic_flags; /* Status flags of the cache */
215
char *bic_filename; /* filename of cache */
216
blkid_probe probe; /* low-level probing stuff */
219
#define BLKID_BIC_FL_PROBED 0x0002 /* We probed /proc/partition devices */
220
#define BLKID_BIC_FL_CHANGED 0x0004 /* Cache has changed from disk */
222
extern char *blkid_strdup(const char *s);
223
extern char *blkid_strndup(const char *s, const int length);
225
#define BLKID_CACHE_FILE "/etc/blkid.tab"
226
#define BLKID_CONFIG_FILE "/etc/blkid.conf"
228
#define BLKID_ERR_IO 5
229
#define BLKID_ERR_PROC 9
230
#define BLKID_ERR_MEM 12
231
#define BLKID_ERR_CACHE 14
232
#define BLKID_ERR_DEV 19
233
#define BLKID_ERR_PARAM 22
234
#define BLKID_ERR_BIG 27
237
* Priority settings for different types of devices
239
#define BLKID_PRI_DM 40
240
#define BLKID_PRI_EVMS 30
241
#define BLKID_PRI_LVM 20
242
#define BLKID_PRI_MD 10
244
#if defined(TEST_PROGRAM) && !defined(CONFIG_BLKID_DEBUG)
245
#define CONFIG_BLKID_DEBUG
248
#define DEBUG_CACHE 0x0001
249
#define DEBUG_DUMP 0x0002
250
#define DEBUG_DEV 0x0004
251
#define DEBUG_DEVNAME 0x0008
252
#define DEBUG_DEVNO 0x0010
253
#define DEBUG_PROBE 0x0020
254
#define DEBUG_READ 0x0040
255
#define DEBUG_RESOLVE 0x0080
256
#define DEBUG_SAVE 0x0100
257
#define DEBUG_TAG 0x0200
258
#define DEBUG_LOWPROBE 0x0400
259
#define DEBUG_CONFIG 0x0800
260
#define DEBUG_EVALUATE 0x1000
261
#define DEBUG_INIT 0x8000
262
#define DEBUG_ALL 0xFFFF
264
#ifdef CONFIG_BLKID_DEBUG
266
extern int blkid_debug_mask;
267
extern void blkid_init_debug(int mask);
268
extern void blkid_debug_dump_dev(blkid_dev dev);
269
extern void blkid_debug_dump_tag(blkid_tag tag);
271
#define DBG(m,x) if ((m) & blkid_debug_mask) x;
273
#else /* !CONFIG_BLKID_DEBUG */
275
#define blkid_init_debug(x)
276
#endif /* CONFIG_BLKID_DEBUG */
281
struct dir_list *next;
283
extern void blkid__scan_dir(char *, dev_t, struct dir_list **, char **);
286
extern blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence);
289
extern void blkid_read_cache(blkid_cache cache);
292
extern int blkid_flush_cache(blkid_cache cache);
295
extern char *blkid_safe_getenv(const char *arg);
296
extern char *blkid_get_cache_filename(struct blkid_config *conf);
299
* Functions to create and find a specific tag type: tag.c
301
extern void blkid_free_tag(blkid_tag tag);
302
extern blkid_tag blkid_find_tag_dev(blkid_dev dev, const char *type);
303
extern int blkid_set_tag(blkid_dev dev, const char *name,
304
const char *value, const int vlength);
307
* Functions to create and find a specific tag type: dev.c
309
extern blkid_dev blkid_new_dev(void);
310
extern void blkid_free_dev(blkid_dev dev);
313
unsigned char *blkid_probe_get_buffer(blkid_probe pr,
314
blkid_loff_t off, blkid_loff_t len);
316
/* returns superblok according to 'struct blkid_idmag' */
317
#define blkid_probe_get_sb(_pr, _mag, type) \
318
((type *) blkid_probe_get_buffer((_pr),\
319
(_mag)->kboff << 10, sizeof(type)))
321
extern int blkid_probe_set_value(blkid_probe pr, const char *name,
322
unsigned char *data, size_t len);
323
extern int blkid_probe_vsprintf_value(blkid_probe pr, const char *name,
324
const char *fmt, va_list ap);
325
extern int blkid_probe_set_version(blkid_probe pr, const char *version);
326
extern int blkid_probe_sprintf_version(blkid_probe pr, const char *fmt, ...)
327
__attribute__ ((format (printf, 2, 3)));
329
extern int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len);
330
extern int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
331
size_t len, int enc);
332
extern int blkid_probe_sprintf_uuid(blkid_probe pr, unsigned char *uuid,
333
size_t len, const char *fmt, ...)
334
__attribute__ ((format (printf, 4, 5)));
335
extern int blkid_probe_strncpy_uuid(blkid_probe pr, unsigned char *str, size_t len);
337
extern int blkid_probe_set_uuid(blkid_probe pr, unsigned char *uuid);
338
extern int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *name);
340
#define BLKID_ENC_UTF16BE 0
341
#define BLKID_ENC_UTF16LE 1
343
#endif /* _BLKID_BLKIDP_H */