~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to libblkid/src/blkidP.h

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * blkidP.h - Internal interfaces for libblkid
 
3
 *
 
4
 * Copyright (C) 2001 Andreas Dilger
 
5
 * Copyright (C) 2003 Theodore Ts'o
 
6
 *
 
7
 * %Begin-Header%
 
8
 * This file may be redistributed under the terms of the
 
9
 * GNU Lesser General Public License.
 
10
 * %End-Header%
 
11
 */
 
12
 
 
13
#ifndef _BLKID_BLKIDP_H
 
14
#define _BLKID_BLKIDP_H
 
15
 
 
16
 
 
17
#define CONFIG_BLKID_DEBUG 1
 
18
 
 
19
#include <sys/types.h>
 
20
#include <dirent.h>
 
21
#include <sys/stat.h>
 
22
#include <stdio.h>
 
23
#include <stdarg.h>
 
24
#include <stdint.h>
 
25
 
 
26
#include "c.h"
 
27
#include "bitops.h"     /* $(top_srcdir)/include/ */
 
28
#include "blkdev.h"
 
29
 
 
30
#include "blkid.h"
 
31
#include "list.h"
 
32
 
 
33
/*
 
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.
 
38
 */
 
39
struct blkid_struct_dev
 
40
{
 
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 */
 
53
};
 
54
 
 
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() */
 
58
 
 
59
/*
 
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.
 
65
 */
 
66
struct blkid_struct_tag
 
67
{
 
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 */
 
73
};
 
74
typedef struct blkid_struct_tag *blkid_tag;
 
75
 
 
76
/*
 
77
 * Chain IDs
 
78
 */
 
79
enum {
 
80
        BLKID_CHAIN_SUBLKS,     /* FS/RAID superblocks (enabled by default) */
 
81
        BLKID_CHAIN_TOPLGY,     /* Block device topology */
 
82
        BLKID_CHAIN_PARTS,      /* Partition tables */
 
83
 
 
84
        BLKID_NCHAINS           /* number of chains */
 
85
};
 
86
 
 
87
struct blkid_chain {
 
88
        const struct blkid_chaindrv *driver;    /* chain driver */
 
89
 
 
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 */
 
96
};
 
97
 
 
98
/*
 
99
 * Chain driver
 
100
 */
 
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 */
 
107
 
 
108
        const struct blkid_idinfo **idinfos; /* description of probing functions */
 
109
        const size_t    nidinfos;       /* number of idinfos */
 
110
 
 
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 *);
 
115
};
 
116
 
 
117
/*
 
118
 * Low-level probe result
 
119
 */
 
120
#define BLKID_PROBVAL_BUFSIZ    64
 
121
 
 
122
#define BLKID_NVALS_SUBLKS      14
 
123
#define BLKID_NVALS_TOPLGY      5
 
124
#define BLKID_NVALS_PARTS       13
 
125
 
 
126
/* Max number of all values in probing result */
 
127
#define BLKID_NVALS             (BLKID_NVALS_SUBLKS + \
 
128
                                 BLKID_NVALS_TOPLGY + \
 
129
                                 BLKID_NVALS_PARTS)
 
130
 
 
131
struct blkid_prval
 
132
{
 
133
        const char      *name;                  /* value name */
 
134
        unsigned char   data[BLKID_PROBVAL_BUFSIZ]; /* value data */
 
135
        size_t          len;                    /* length of value data */
 
136
 
 
137
        struct blkid_chain      *chain;         /* owner */
 
138
};
 
139
 
 
140
/*
 
141
 * Filesystem / Raid magic strings
 
142
 */
 
143
struct blkid_idmag
 
144
{
 
145
        const char      *magic;         /* magic string */
 
146
        unsigned int    len;            /* length of magic */
 
147
 
 
148
        long            kboff;          /* kilobyte offset of superblock */
 
149
        unsigned int    sboff;          /* byte offset within superblock */
 
150
};
 
151
 
 
152
/*
 
153
 * Filesystem / Raid description
 
154
 */
 
155
struct blkid_idinfo
 
156
{
 
157
        const char      *name;          /* fs, raid or partition table name */
 
158
        int             usage;          /* BLKID_USAGE_* flag */
 
159
        int             flags;          /* BLKID_IDINFO_* flags */
 
160
        int             minsz;          /* minimal device size */
 
161
 
 
162
                                        /* probe function */
 
163
        int             (*probefunc)(blkid_probe pr, const struct blkid_idmag *mag);
 
164
 
 
165
        struct blkid_idmag      magics[];       /* NULL or array with magic strings */
 
166
};
 
167
 
 
168
#define BLKID_NONE_MAGIC        {{ NULL }}
 
169
 
 
170
/*
 
171
 * tolerant FS - can share the same device with more filesystems (e.g. typical
 
172
 * on CD-ROMs). We need this flag to detect ambivalent results (e.g. valid fat
 
173
 * and valid linux swap on the same device).
 
174
 */
 
175
#define BLKID_IDINFO_TOLERANT   (1 << 1)
 
176
 
 
177
struct blkid_bufinfo {
 
178
        unsigned char           *data;
 
179
        blkid_loff_t            off;
 
180
        blkid_loff_t            len;
 
181
        struct list_head        bufs;   /* list of buffers */
 
182
};
 
183
 
 
184
/*
 
185
 * Low-level probing control struct
 
186
 */
 
187
struct blkid_struct_probe
 
188
{
 
189
        int                     fd;             /* device file descriptor */
 
190
        blkid_loff_t            off;            /* begin of data on the device */
 
191
        blkid_loff_t            size;           /* end of data on the device */
 
192
 
 
193
        dev_t                   devno;          /* device number (st.st_rdev) */
 
194
        dev_t                   disk_devno;     /* devno of the whole-disk or 0 */
 
195
        unsigned int            blkssz;         /* sector size (BLKSSZGET ioctl) */
 
196
        mode_t                  mode;           /* struct stat.sb_mode */
 
197
 
 
198
        int                     flags;          /* private libray flags */
 
199
        int                     prob_flags;     /* always zeroized by blkid_do_*() */
 
200
 
 
201
        blkid_loff_t            wipe_off;       /* begin of the wiped area */
 
202
        blkid_loff_t            wipe_size;      /* size of the wiped area */
 
203
        struct blkid_chain      *wipe_chain;    /* superblock, partition, ... */
 
204
 
 
205
        struct list_head        buffers;        /* list of buffers */
 
206
 
 
207
        struct blkid_chain      chains[BLKID_NCHAINS];  /* array of chains */
 
208
        struct blkid_chain      *cur_chain;             /* current chain */
 
209
 
 
210
        struct blkid_prval      vals[BLKID_NVALS];      /* results */
 
211
        int                     nvals;          /* number of assigned vals */
 
212
 
 
213
        struct blkid_struct_probe *parent;      /* for clones */
 
214
        struct blkid_struct_probe *disk_probe;  /* whole-disk probing */
 
215
};
 
216
 
 
217
/* private flags library flags */
 
218
#define BLKID_FL_PRIVATE_FD     (1 << 1)        /* see blkid_new_probe_from_filename() */
 
219
#define BLKID_FL_TINY_DEV       (1 << 2)        /* <= 1.47MiB (floppy or so) */
 
220
#define BLKID_FL_CDROM_DEV      (1 << 3)        /* is a CD/DVD drive */
 
221
 
 
222
/* private per-probing flags */
 
223
#define BLKID_PROBE_FL_IGNORE_PT (1 << 1)       /* ignore partition table */
 
224
 
 
225
extern blkid_probe blkid_clone_probe(blkid_probe parent);
 
226
extern blkid_probe blkid_probe_get_wholedisk_probe(blkid_probe pr);
 
227
 
 
228
/*
 
229
 * Evaluation methods (for blkid_eval_* API)
 
230
 */
 
231
enum {
 
232
        BLKID_EVAL_UDEV = 0,
 
233
        BLKID_EVAL_SCAN,
 
234
 
 
235
        __BLKID_EVAL_LAST
 
236
};
 
237
 
 
238
/*
 
239
 * Library config options
 
240
 */
 
241
struct blkid_config {
 
242
        int eval[__BLKID_EVAL_LAST];    /* array with EVALUATION=<udev,cache> options */
 
243
        int nevals;                     /* number of elems in eval array */
 
244
        int uevent;                     /* SEND_UEVENT=<yes|not> option */
 
245
        char *cachefile;                /* CACHE_FILE=<path> option */
 
246
};
 
247
 
 
248
extern struct blkid_config *blkid_read_config(const char *filename);
 
249
extern void blkid_free_config(struct blkid_config *conf);
 
250
 
 
251
/*
 
252
 * Minimum number of seconds between device probes, even when reading
 
253
 * from the cache.  This is to avoid re-probing all devices which were
 
254
 * just probed by another program that does not share the cache.
 
255
 */
 
256
#define BLKID_PROBE_MIN         2
 
257
 
 
258
/*
 
259
 * Time in seconds an entry remains verified in the in-memory cache
 
260
 * before being reverified (in case of long-running processes that
 
261
 * keep a cache in memory and continue to use it for a long time).
 
262
 */
 
263
#define BLKID_PROBE_INTERVAL    200
 
264
 
 
265
/* This describes an entire blkid cache file and probed devices.
 
266
 * We can traverse all of the found devices via bic_list.
 
267
 * We can traverse all of the tag types by bic_tags, which hold empty tags
 
268
 * for each tag type.  Those tags can be used as list_heads for iterating
 
269
 * through all devices with a specific tag type (e.g. LABEL).
 
270
 */
 
271
struct blkid_struct_cache
 
272
{
 
273
        struct list_head        bic_devs;       /* List head of all devices */
 
274
        struct list_head        bic_tags;       /* List head of all tag types */
 
275
        time_t                  bic_time;       /* Last probe time */
 
276
        time_t                  bic_ftime;      /* Mod time of the cachefile */
 
277
        unsigned int            bic_flags;      /* Status flags of the cache */
 
278
        char                    *bic_filename;  /* filename of cache */
 
279
        blkid_probe             probe;          /* low-level probing stuff */
 
280
};
 
281
 
 
282
#define BLKID_BIC_FL_PROBED     0x0002  /* We probed /proc/partition devices */
 
283
#define BLKID_BIC_FL_CHANGED    0x0004  /* Cache has changed from disk */
 
284
 
 
285
extern char *blkid_strdup(const char *s);
 
286
extern char *blkid_strndup(const char *s, const int length);
 
287
extern char *blkid_strconcat(const char *a, const char *b, const char *c);
 
288
 
 
289
#define BLKID_CACHE_FILE        "/etc/blkid.tab"
 
290
#define BLKID_CONFIG_FILE       "/etc/blkid.conf"
 
291
 
 
292
#define BLKID_ERR_IO     5
 
293
#define BLKID_ERR_PROC   9
 
294
#define BLKID_ERR_MEM   12
 
295
#define BLKID_ERR_CACHE 14
 
296
#define BLKID_ERR_DEV   19
 
297
#define BLKID_ERR_PARAM 22
 
298
#define BLKID_ERR_BIG   27
 
299
 
 
300
/*
 
301
 * Priority settings for different types of devices
 
302
 */
 
303
#define BLKID_PRI_UBI   50
 
304
#define BLKID_PRI_DM    40
 
305
#define BLKID_PRI_EVMS  30
 
306
#define BLKID_PRI_LVM   20
 
307
#define BLKID_PRI_MD    10
 
308
 
 
309
#if defined(TEST_PROGRAM) && !defined(CONFIG_BLKID_DEBUG)
 
310
#define CONFIG_BLKID_DEBUG
 
311
#endif
 
312
 
 
313
#define DEBUG_CACHE     0x0001
 
314
#define DEBUG_DUMP      0x0002
 
315
#define DEBUG_DEV       0x0004
 
316
#define DEBUG_DEVNAME   0x0008
 
317
#define DEBUG_DEVNO     0x0010
 
318
#define DEBUG_PROBE     0x0020
 
319
#define DEBUG_READ      0x0040
 
320
#define DEBUG_RESOLVE   0x0080
 
321
#define DEBUG_SAVE      0x0100
 
322
#define DEBUG_TAG       0x0200
 
323
#define DEBUG_LOWPROBE  0x0400
 
324
#define DEBUG_CONFIG    0x0800
 
325
#define DEBUG_EVALUATE  0x1000
 
326
#define DEBUG_INIT      0x8000
 
327
#define DEBUG_ALL       0xFFFF
 
328
 
 
329
#ifdef CONFIG_BLKID_DEBUG
 
330
extern int blkid_debug_mask;
 
331
extern void blkid_init_debug(int mask);
 
332
extern void blkid_debug_dump_dev(blkid_dev dev);
 
333
extern void blkid_debug_dump_tag(blkid_tag tag);
 
334
 
 
335
#define DBG(m,x)        if ((m) & blkid_debug_mask) x;
 
336
 
 
337
#else /* !CONFIG_BLKID_DEBUG */
 
338
#define DBG(m,x)
 
339
#define blkid_init_debug(x)
 
340
#endif /* CONFIG_BLKID_DEBUG */
 
341
 
 
342
/* devno.c */
 
343
struct dir_list {
 
344
        char    *name;
 
345
        struct dir_list *next;
 
346
};
 
347
extern void blkid__scan_dir(char *, dev_t, struct dir_list **, char **);
 
348
extern int blkid_driver_has_major(const char *drvname, int major);
 
349
 
 
350
/* lseek.c */
 
351
extern blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence);
 
352
 
 
353
/* read.c */
 
354
extern void blkid_read_cache(blkid_cache cache);
 
355
 
 
356
/* save.c */
 
357
extern int blkid_flush_cache(blkid_cache cache);
 
358
 
 
359
/* cache */
 
360
extern char *blkid_safe_getenv(const char *arg);
 
361
extern char *blkid_get_cache_filename(struct blkid_config *conf);
 
362
 
 
363
/*
 
364
 * Functions to create and find a specific tag type: tag.c
 
365
 */
 
366
extern void blkid_free_tag(blkid_tag tag);
 
367
extern blkid_tag blkid_find_tag_dev(blkid_dev dev, const char *type);
 
368
extern int blkid_set_tag(blkid_dev dev, const char *name,
 
369
                         const char *value, const int vlength);
 
370
 
 
371
/*
 
372
 * Functions to create and find a specific tag type: dev.c
 
373
 */
 
374
extern blkid_dev blkid_new_dev(void);
 
375
extern void blkid_free_dev(blkid_dev dev);
 
376
 
 
377
/* probe.c */
 
378
extern int blkid_probe_is_tiny(blkid_probe pr);
 
379
extern int blkid_probe_is_cdrom(blkid_probe pr);
 
380
extern unsigned char *blkid_probe_get_buffer(blkid_probe pr,
 
381
                                blkid_loff_t off, blkid_loff_t len);
 
382
 
 
383
extern unsigned char *blkid_probe_get_sector(blkid_probe pr, unsigned int sector);
 
384
 
 
385
extern int blkid_probe_get_dimension(blkid_probe pr,
 
386
                        blkid_loff_t *off, blkid_loff_t *size);
 
387
 
 
388
extern int blkid_probe_set_dimension(blkid_probe pr,
 
389
                        blkid_loff_t off, blkid_loff_t size);
 
390
 
 
391
extern int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id,
 
392
                        blkid_loff_t *offset, const struct blkid_idmag **res);
 
393
 
 
394
/* returns superblok according to 'struct blkid_idmag' */
 
395
#define blkid_probe_get_sb(_pr, _mag, type) \
 
396
                        ((type *) blkid_probe_get_buffer((_pr),\
 
397
                                        (_mag)->kboff << 10, sizeof(type)))
 
398
 
 
399
extern blkid_partlist blkid_probe_get_partlist(blkid_probe pr);
 
400
 
 
401
extern int blkid_probe_is_covered_by_pt(blkid_probe pr,
 
402
                                        blkid_loff_t offset, blkid_loff_t size);
 
403
 
 
404
extern void blkid_probe_chain_reset_vals(blkid_probe pr, struct blkid_chain *chn);
 
405
extern int blkid_probe_chain_copy_vals(blkid_probe pr, struct blkid_chain *chn,
 
406
                                        struct blkid_prval *vals, int nvals);
 
407
extern struct blkid_prval *blkid_probe_assign_value(blkid_probe pr, const char *name);
 
408
extern int blkid_probe_reset_last_value(blkid_probe pr);
 
409
extern void blkid_probe_append_vals(blkid_probe pr, struct blkid_prval *vals, int nvals);
 
410
 
 
411
extern struct blkid_chain *blkid_probe_get_chain(blkid_probe pr);
 
412
 
 
413
extern struct blkid_prval *__blkid_probe_get_value(blkid_probe pr, int num);
 
414
extern struct blkid_prval *__blkid_probe_lookup_value(blkid_probe pr, const char *name);
 
415
 
 
416
extern unsigned long *blkid_probe_get_filter(blkid_probe pr, int chain, int create);
 
417
extern int __blkid_probe_invert_filter(blkid_probe pr, int chain);
 
418
extern int __blkid_probe_reset_filter(blkid_probe pr, int chain);
 
419
extern int __blkid_probe_filter_types(blkid_probe pr, int chain, int flag, char *names[]);
 
420
 
 
421
extern void *blkid_probe_get_binary_data(blkid_probe pr, struct blkid_chain *chn);
 
422
 
 
423
extern int blkid_probe_set_value(blkid_probe pr, const char *name,
 
424
                unsigned char *data, size_t len);
 
425
extern int blkid_probe_vsprintf_value(blkid_probe pr, const char *name,
 
426
                const char *fmt, va_list ap);
 
427
extern int blkid_probe_sprintf_value(blkid_probe pr, const char *name,
 
428
                const char *fmt, ...);
 
429
 
 
430
extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len);
 
431
extern size_t blkid_rtrim_whitespace(unsigned char *str);
 
432
 
 
433
extern void blkid_probe_set_wiper(blkid_probe pr, blkid_loff_t off,
 
434
                                  blkid_loff_t size);
 
435
extern int blkid_probe_is_wiped(blkid_probe pr, struct blkid_chain **chn,
 
436
                                blkid_loff_t off, blkid_loff_t size);
 
437
extern void blkid_probe_use_wiper(blkid_probe pr, blkid_loff_t off, blkid_loff_t size);
 
438
 
 
439
/* filter bitmap macros */
 
440
#define blkid_bmp_wordsize              (8 * sizeof(unsigned long))
 
441
#define blkid_bmp_idx_bit(item)         (1UL << ((item) % blkid_bmp_wordsize))
 
442
#define blkid_bmp_idx_byte(item)        ((item) / blkid_bmp_wordsize)
 
443
 
 
444
#define blkid_bmp_set_item(bmp, item)   \
 
445
                ((bmp)[ blkid_bmp_idx_byte(item) ] |= blkid_bmp_idx_bit(item))
 
446
 
 
447
#define blkid_bmp_unset_item(bmp, item) \
 
448
                ((bmp)[ blkid_bmp_idx_byte(item) ] &= ~blkid_bmp_idx_bit(item))
 
449
 
 
450
#define blkid_bmp_get_item(bmp, item)   \
 
451
                ((bmp)[ blkid_bmp_idx_byte(item) ] & blkid_bmp_idx_bit(item))
 
452
 
 
453
#define blkid_bmp_nwords(max_items) \
 
454
                (((max_items) + blkid_bmp_wordsize) / blkid_bmp_wordsize)
 
455
 
 
456
#define blkid_bmp_nbytes(max_items) \
 
457
                (blkid_bmp_nwords(max_items) * sizeof(unsigned long))
 
458
 
 
459
/* encode.c */
 
460
extern size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len,
 
461
                        const unsigned char *src, size_t count);
 
462
 
 
463
#define BLKID_ENC_UTF16BE       0
 
464
#define BLKID_ENC_UTF16LE       1
 
465
 
 
466
#endif /* _BLKID_BLKIDP_H */