Whamcloud - gitweb
423e7dea0c99386e061aa3c44035d7167f2137cb
[tools/e2fsprogs.git] / lib / blkid / blkidP.h
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 #include <sys/types.h>
17 #include <stdio.h>
18
19 #include <blkid/blkid.h>
20
21 #include <blkid/list.h>
22
23 /*
24  * This describes the attributes of a specific device.
25  * We can traverse all of the tags by bid_tags (linking to the tag bit_names).
26  * The bid_label and bid_uuid fields are shortcuts to the LABEL and UUID tag
27  * values, if they exist.
28  */
29 struct blkid_struct_dev
30 {
31         struct list_head        bid_devs;       /* All devices in the cache */
32         struct list_head        bid_tags;       /* All tags for this device */
33         blkid_cache             bid_cache;      /* Dev belongs to this cache */
34         char                    *bid_name;      /* Device inode pathname */
35         char                    *bid_type;      /* Preferred device TYPE */
36         int                     bid_pri;        /* Device priority */
37         dev_t                   bid_devno;      /* Device major/minor number */
38         time_t                  bid_time;       /* Last update time of device */
39         unsigned int            bid_id;         /* Unique cache id for device */
40         unsigned int            bid_flags;      /* Device status bitflags */
41         char                    *bid_label;     /* Shortcut to device LABEL */
42         char                    *bid_uuid;      /* Shortcut to binary UUID */
43 };
44
45 #define BLKID_BID_FL_VERIFIED   0x0001  /* Device data validated from disk */
46 #define BLKID_BID_FL_MTYPE      0x0002  /* Device has multiple type matches */
47 #define BLKID_BID_FL_INVALID    0x0004  /* Device is invalid */
48
49 /*
50  * Each tag defines a NAME=value pair for a particular device.  The tags
51  * are linked via bit_names for a single device, so that traversing the
52  * names list will get you a list of all tags associated with a device.
53  * They are also linked via bit_values for all devices, so one can easily
54  * search all tags with a given NAME for a specific value.
55  */
56 struct blkid_struct_tag
57 {
58         struct list_head        bit_tags;       /* All tags for this device */
59         struct list_head        bit_names;      /* All tags with given NAME */
60         char                    *bit_name;      /* NAME of tag (shared) */
61         char                    *bit_val;       /* value of tag */
62         blkid_dev               bit_dev;        /* pointer to device */
63 };
64 typedef struct blkid_struct_tag *blkid_tag;
65
66 /*
67  * Minimum number of seconds between device probes, even when reading
68  * from the cache.  This is to avoid re-probing all devices which were
69  * just probed by another program that does not share the cache.
70  */
71 #define BLKID_PROBE_MIN         2
72
73 /*
74  * Time in seconds an entry remains verified in the in-memory cache
75  * before being reverified (in case of long-running processes that
76  * keep a cache in memory and continue to use it for a long time).
77  */
78 #define BLKID_PROBE_INTERVAL    200
79
80 /* This describes an entire blkid cache file and probed devices.
81  * We can traverse all of the found devices via bic_list.
82  * We can traverse all of the tag types by bic_tags, which hold empty tags
83  * for each tag type.  Those tags can be used as list_heads for iterating
84  * through all devices with a specific tag type (e.g. LABEL).
85  */
86 struct blkid_struct_cache
87 {
88         struct list_head        bic_devs;       /* List head of all devices */
89         struct list_head        bic_tags;       /* List head of all tag types */
90         time_t                  bic_time;       /* Last probe time */
91 p       unsigned int            bic_idmax;      /* Highest ID assigned */
92         unsigned int            bic_flags;      /* Status flags of the cache */
93         char                    *bic_filename;  /* filename of cache */
94 };
95
96 #define BLKID_BIC_FL_PROBED     0x0002  /* We probed /proc/partition devices */
97 #define BLKID_BIC_FL_CHANGED    0x0004  /* Cache has changed from disk */
98
99 extern char *blkid_strdup(const char *s);
100 extern char *blkid_strndup(const char *s, const int length);
101 extern blkid_cache blkid_new_cache(void);
102
103 #define BLKID_CACHE_FILE "/etc/blkid.tab"
104 extern const char *blkid_devdirs[];
105
106 #define BLKID_ERR_IO     5
107 #define BLKID_ERR_PROC   9
108 #define BLKID_ERR_MEM   12
109 #define BLKID_ERR_CACHE 14
110 #define BLKID_ERR_DEV   19
111 #define BLKID_ERR_PARAM 22
112 #define BLKID_ERR_BIG   27
113
114 /*
115  * Priority settings for different types of devices
116  */
117 #define BLKID_PRI_EVMS  30
118 #define BLKID_PRI_LVM   20
119 #define BLKID_PRI_MD    10
120
121 #if defined(TEST_PROGRAM)
122 #define DEBUG
123 #endif
124
125 #ifdef DEBUG
126 #define DEBUG_CACHE
127 #define DEBUG_DUMP
128 #define DEBUG_DEV
129 #define DEBUG_DEVNAME
130 #define DEBUG_DEVNO
131 #define DEBUG_PROBE
132 #define DEBUG_READ
133 #define DEBUG_RESOLVE
134 #define DEBUG_SAVE
135 #define DEBUG_TAG
136 #define CHECK_TAG
137 #endif
138
139 #if defined(TEST_PROGRAM) && !defined(DEBUG_DUMP)
140 #define DEBUG_DUMP
141 #endif
142
143 #ifdef DEBUG_DUMP
144 static inline void DEB_DUMP_TAG(blkid_tag tag)
145 {
146         if (!tag) {
147                 printf("    tag: NULL\n");
148                 return;
149         }
150
151         printf("    tag: %s=\"%s\"\n", tag->bit_name, tag->bit_val);
152 }
153
154 static inline void DEB_DUMP_DEV(blkid_dev dev)
155 {
156         struct list_head *p;
157
158         if (!dev) {
159                 printf("  dev: NULL\n");
160                 return;
161         }
162
163         printf("  dev: name = %s\n", dev->bid_name);
164         printf("  dev: DEVNO=\"0x%0Lx\"\n", dev->bid_devno);
165         printf("  dev: ID=\"%u\"\n", dev->bid_id);
166         printf("  dev: TIME=\"%lu\"\n", dev->bid_time);
167         printf("  dev: PRI=\"%d\"\n", dev->bid_pri);
168         printf("  dev: flags = 0x%08X\n", dev->bid_flags);
169
170         list_for_each(p, &dev->bid_tags) {
171                 blkid_tag tag = list_entry(p, struct blkid_struct_tag, bit_tags);
172                 DEB_DUMP_TAG(tag);
173         }
174         printf("\n");
175 }
176
177 static inline void DEB_DUMP_CACHE(blkid_cache cache)
178 {
179         struct list_head *p;
180
181         if (!cache) {
182                 printf("cache: NULL\n");
183                 return;
184         }
185
186         printf("cache: time = %lu\n", cache->bic_time);
187         printf("cache: idmax = %u\n", cache->bic_idmax);
188         printf("cache: flags = 0x%08X\n", cache->bic_flags);
189
190         list_for_each(p, &cache->bic_devs) {
191                 blkid_dev dev = list_entry(p, struct blkid_struct_dev, bid_devs);
192                 DEB_DUMP_DEV(dev);
193         }
194 }
195 #else
196 #define DEB_DUMP_TAG(tag) do {} while (0)
197 #define DEB_DUMP_DEV(dev) do {} while (0)
198 #define DEB_DUMP_CACHE(cache) do {} while (0)
199 #endif
200
201 /* lseek.c */
202 extern blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence);
203
204 /* probe.c */
205 extern blkid_dev blkid_verify_devname(blkid_cache cache, blkid_dev dev);
206
207 /* save.c */
208 extern int blkid_flush_cache(blkid_cache cache);
209
210 /*
211  * Functions to create and find a specific tag type: tag.c
212  */
213 extern void blkid_free_tag(blkid_tag tag);
214 extern blkid_tag blkid_find_tag_dev(blkid_dev dev, const char *type);
215 extern int blkid_set_tag(blkid_dev dev, const char *name,
216                          const char *value, const int vlength, int replace);
217
218 /*
219  * Functions to create and find a specific tag type: dev.c
220  */
221 extern blkid_dev blkid_new_dev(void);
222 extern void blkid_free_dev(blkid_dev dev);
223
224 #ifdef __cplusplus
225 }
226 #endif
227
228 #endif /* _BLKID_BLKIDP_H */