~pr0gg3d/ubuntu/oneiric/util-linux/bug-805886

« back to all changes in this revision

Viewing changes to libs/blkid/src/blkidP.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2009-07-16 15:48:23 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20090716154823-i26fshvs4v8h90qh
Tags: 2.16-1ubuntu1
* Merge from Debian, remaining changes:
  - Since udev is required in Ubuntu, the hwclock.sh init script is
    not called on startup and the hwclockfirst.sh init script is
    removed.
  - Remove /etc/adjtime on upgrade if it was not used.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - No lsb_release call in mount.preinst since we'd need Pre-Depends
    (LP: #383697).

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 <stdio.h>
21
 
 
22
 
#include "bitops.h"     /* $(top_srcdir)/include/ */
23
 
#include "blkid.h"
24
 
#include "list.h"
25
 
 
26
 
#ifdef __GNUC__
27
 
#define __BLKID_ATTR(x) __attribute__(x)
28
 
#else
29
 
#define __BLKID_ATTR(x)
30
 
#endif
31
 
 
32
 
#ifndef TRUE
33
 
#define TRUE 1
34
 
#define FALSE 1
35
 
#endif
36
 
 
37
 
#include <limits.h>
38
 
#ifndef PATH_MAX
39
 
# define PATH_MAX 4096
40
 
#endif
41
 
 
42
 
/* TODO: move to some top-level util-linux include file */
43
 
#ifndef ARRAY_SIZE
44
 
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
45
 
#endif
46
 
 
47
 
/*
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.
52
 
 */
53
 
struct blkid_struct_dev
54
 
{
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 */
66
 
};
67
 
 
68
 
#define BLKID_BID_FL_VERIFIED   0x0001  /* Device data validated from disk */
69
 
#define BLKID_BID_FL_INVALID    0x0004  /* Device is invalid */
70
 
 
71
 
/*
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.
77
 
 */
78
 
struct blkid_struct_tag
79
 
{
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 */
85
 
};
86
 
typedef struct blkid_struct_tag *blkid_tag;
87
 
 
88
 
/*
89
 
 * Low-level probe result
90
 
 */
91
 
#define BLKID_PROBVAL_BUFSIZ    64
92
 
#define BLKID_PROBVAL_NVALS     8       /* see blkid.h BLKID_PROBREQ_* */
93
 
 
94
 
struct blkid_prval
95
 
{
96
 
        const char      *name;                  /* value name */
97
 
        unsigned char   data[BLKID_PROBVAL_BUFSIZ]; /* value data */
98
 
        size_t          len;                    /* length of value data */
99
 
};
100
 
 
101
 
/*
102
 
 * Low-level probing control struct
103
 
 */
104
 
struct blkid_struct_probe
105
 
{
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 */
109
 
 
110
 
        unsigned char           *sbbuf;         /* superblok buffer */
111
 
        size_t                  sbbuf_len;      /* size of data in superblock buffer */
112
 
 
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 */
117
 
 
118
 
        struct blkid_prval      vals[BLKID_PROBVAL_NVALS];
119
 
        int                     nvals;
120
 
 
121
 
        int                     probreq;        /* BLKID_PROBREQ_* flags */
122
 
        int                     idx;            /* index of the last prober */
123
 
 
124
 
        unsigned long           *fltr;          /* filter */
125
 
};
126
 
 
127
 
#define BLKID_SB_BUFSIZ         0x11000
128
 
 
129
 
/*
130
 
 * Filesystem / Raid magic strings
131
 
 */
132
 
struct blkid_idmag
133
 
{
134
 
        const char      *magic;         /* magic string */
135
 
        unsigned        len;            /* length of magic */
136
 
 
137
 
        long            kboff;          /* kilobyte offset of superblock */
138
 
        unsigned        sboff;          /* byte offset within superblock */
139
 
};
140
 
 
141
 
/*
142
 
 * Filesystem / Raid description
143
 
 */
144
 
struct blkid_idinfo
145
 
{
146
 
        const char      *name;          /* FS/RAID name */
147
 
        int             usage;          /* BLKID_USAGE_* flag */
148
 
        int             flags;          /* BLKID_IDINFO_* flags */
149
 
 
150
 
                                        /* probe function */
151
 
        int             (*probefunc)(blkid_probe pr, const struct blkid_idmag *mag);
152
 
 
153
 
        struct blkid_idmag      magics[];       /* NULL or array with magic strings */
154
 
};
155
 
 
156
 
#define BLKID_NONE_MAGIC        {{ NULL }}
157
 
 
158
 
/*
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).
162
 
 */
163
 
#define BLKID_IDINFO_TOLERANT   (1 << 1)
164
 
 
165
 
/*
166
 
 * Evaluation methods (for blkid_eval_* API)
167
 
 */
168
 
enum {
169
 
        BLKID_EVAL_UDEV = 0,
170
 
        BLKID_EVAL_SCAN,
171
 
 
172
 
        __BLKID_EVAL_LAST
173
 
};
174
 
 
175
 
/*
176
 
 * Library config options
177
 
 */
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 */
183
 
};
184
 
 
185
 
extern struct blkid_config *blkid_read_config(const char *filename);
186
 
extern void blkid_free_config(struct blkid_config *conf);
187
 
 
188
 
/*
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.
192
 
 */
193
 
#define BLKID_PROBE_MIN         2
194
 
 
195
 
/*
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).
199
 
 */
200
 
#define BLKID_PROBE_INTERVAL    200
201
 
 
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).
207
 
 */
208
 
struct blkid_struct_cache
209
 
{
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 */
217
 
};
218
 
 
219
 
#define BLKID_BIC_FL_PROBED     0x0002  /* We probed /proc/partition devices */
220
 
#define BLKID_BIC_FL_CHANGED    0x0004  /* Cache has changed from disk */
221
 
 
222
 
extern char *blkid_strdup(const char *s);
223
 
extern char *blkid_strndup(const char *s, const int length);
224
 
 
225
 
#define BLKID_CACHE_FILE        "/etc/blkid.tab"
226
 
#define BLKID_CONFIG_FILE       "/etc/blkid.conf"
227
 
 
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
235
 
 
236
 
/*
237
 
 * Priority settings for different types of devices
238
 
 */
239
 
#define BLKID_PRI_DM    40
240
 
#define BLKID_PRI_EVMS  30
241
 
#define BLKID_PRI_LVM   20
242
 
#define BLKID_PRI_MD    10
243
 
 
244
 
#if defined(TEST_PROGRAM) && !defined(CONFIG_BLKID_DEBUG)
245
 
#define CONFIG_BLKID_DEBUG
246
 
#endif
247
 
 
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
263
 
 
264
 
#ifdef CONFIG_BLKID_DEBUG
265
 
#include <stdio.h>
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);
270
 
 
271
 
#define DBG(m,x)        if ((m) & blkid_debug_mask) x;
272
 
 
273
 
#else /* !CONFIG_BLKID_DEBUG */
274
 
#define DBG(m,x)
275
 
#define blkid_init_debug(x)
276
 
#endif /* CONFIG_BLKID_DEBUG */
277
 
 
278
 
/* devno.c */
279
 
struct dir_list {
280
 
        char    *name;
281
 
        struct dir_list *next;
282
 
};
283
 
extern void blkid__scan_dir(char *, dev_t, struct dir_list **, char **);
284
 
 
285
 
/* lseek.c */
286
 
extern blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence);
287
 
 
288
 
/* read.c */
289
 
extern void blkid_read_cache(blkid_cache cache);
290
 
 
291
 
/* save.c */
292
 
extern int blkid_flush_cache(blkid_cache cache);
293
 
 
294
 
/* cache */
295
 
extern char *blkid_safe_getenv(const char *arg);
296
 
extern char *blkid_get_cache_filename(struct blkid_config *conf);
297
 
 
298
 
/*
299
 
 * Functions to create and find a specific tag type: tag.c
300
 
 */
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);
305
 
 
306
 
/*
307
 
 * Functions to create and find a specific tag type: dev.c
308
 
 */
309
 
extern blkid_dev blkid_new_dev(void);
310
 
extern void blkid_free_dev(blkid_dev dev);
311
 
 
312
 
/* probe.c */
313
 
unsigned char *blkid_probe_get_buffer(blkid_probe pr,
314
 
                                blkid_loff_t off, blkid_loff_t len);
315
 
 
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)))
320
 
 
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)));
328
 
 
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);
336
 
 
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);
339
 
 
340
 
#define BLKID_ENC_UTF16BE       0
341
 
#define BLKID_ENC_UTF16LE       1
342
 
 
343
 
#endif /* _BLKID_BLKIDP_H */