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