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

« back to all changes in this revision

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