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