1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker * blkidP.h - Internal interfaces for libblkid
3*6a54128fSAndroid Build Coastguard Worker *
4*6a54128fSAndroid Build Coastguard Worker * Copyright (C) 2001 Andreas Dilger
5*6a54128fSAndroid Build Coastguard Worker * Copyright (C) 2003 Theodore Ts'o
6*6a54128fSAndroid Build Coastguard Worker *
7*6a54128fSAndroid Build Coastguard Worker * %Begin-Header%
8*6a54128fSAndroid Build Coastguard Worker * This file may be redistributed under the terms of the
9*6a54128fSAndroid Build Coastguard Worker * GNU Lesser General Public License.
10*6a54128fSAndroid Build Coastguard Worker * %End-Header%
11*6a54128fSAndroid Build Coastguard Worker */
12*6a54128fSAndroid Build Coastguard Worker
13*6a54128fSAndroid Build Coastguard Worker #ifndef _BLKID_BLKIDP_H
14*6a54128fSAndroid Build Coastguard Worker #define _BLKID_BLKIDP_H
15*6a54128fSAndroid Build Coastguard Worker
16*6a54128fSAndroid Build Coastguard Worker #include <sys/types.h>
17*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
18*6a54128fSAndroid Build Coastguard Worker #if HAVE_SYS_TYPES_H
19*6a54128fSAndroid Build Coastguard Worker #include <sys/types.h>
20*6a54128fSAndroid Build Coastguard Worker #endif
21*6a54128fSAndroid Build Coastguard Worker #if HAVE_SYS_STAT_H
22*6a54128fSAndroid Build Coastguard Worker #include <sys/stat.h>
23*6a54128fSAndroid Build Coastguard Worker #endif
24*6a54128fSAndroid Build Coastguard Worker
25*6a54128fSAndroid Build Coastguard Worker #include <blkid/blkid.h>
26*6a54128fSAndroid Build Coastguard Worker
27*6a54128fSAndroid Build Coastguard Worker #include <blkid/list.h>
28*6a54128fSAndroid Build Coastguard Worker
29*6a54128fSAndroid Build Coastguard Worker #ifdef __GNUC__
30*6a54128fSAndroid Build Coastguard Worker #define __BLKID_ATTR(x) __attribute__(x)
31*6a54128fSAndroid Build Coastguard Worker #else
32*6a54128fSAndroid Build Coastguard Worker #define __BLKID_ATTR(x)
33*6a54128fSAndroid Build Coastguard Worker #endif
34*6a54128fSAndroid Build Coastguard Worker
35*6a54128fSAndroid Build Coastguard Worker
36*6a54128fSAndroid Build Coastguard Worker /*
37*6a54128fSAndroid Build Coastguard Worker * This describes the attributes of a specific device.
38*6a54128fSAndroid Build Coastguard Worker * We can traverse all of the tags by bid_tags (linking to the tag bit_names).
39*6a54128fSAndroid Build Coastguard Worker * The bid_label and bid_uuid fields are shortcuts to the LABEL and UUID tag
40*6a54128fSAndroid Build Coastguard Worker * values, if they exist.
41*6a54128fSAndroid Build Coastguard Worker */
42*6a54128fSAndroid Build Coastguard Worker struct blkid_struct_dev
43*6a54128fSAndroid Build Coastguard Worker {
44*6a54128fSAndroid Build Coastguard Worker struct list_head bid_devs; /* All devices in the cache */
45*6a54128fSAndroid Build Coastguard Worker struct list_head bid_tags; /* All tags for this device */
46*6a54128fSAndroid Build Coastguard Worker blkid_cache bid_cache; /* Dev belongs to this cache */
47*6a54128fSAndroid Build Coastguard Worker char *bid_name; /* Device inode pathname */
48*6a54128fSAndroid Build Coastguard Worker char *bid_type; /* Preferred device TYPE */
49*6a54128fSAndroid Build Coastguard Worker int bid_pri; /* Device priority */
50*6a54128fSAndroid Build Coastguard Worker dev_t bid_devno; /* Device major/minor number */
51*6a54128fSAndroid Build Coastguard Worker time_t bid_time; /* Last update time of device */
52*6a54128fSAndroid Build Coastguard Worker unsigned int bid_flags; /* Device status bitflags */
53*6a54128fSAndroid Build Coastguard Worker char *bid_label; /* Shortcut to device LABEL */
54*6a54128fSAndroid Build Coastguard Worker char *bid_uuid; /* Shortcut to binary UUID */
55*6a54128fSAndroid Build Coastguard Worker };
56*6a54128fSAndroid Build Coastguard Worker
57*6a54128fSAndroid Build Coastguard Worker #define BLKID_BID_FL_VERIFIED 0x0001 /* Device data validated from disk */
58*6a54128fSAndroid Build Coastguard Worker #define BLKID_BID_FL_INVALID 0x0004 /* Device is invalid */
59*6a54128fSAndroid Build Coastguard Worker
60*6a54128fSAndroid Build Coastguard Worker /*
61*6a54128fSAndroid Build Coastguard Worker * Each tag defines a NAME=value pair for a particular device. The tags
62*6a54128fSAndroid Build Coastguard Worker * are linked via bit_names for a single device, so that traversing the
63*6a54128fSAndroid Build Coastguard Worker * names list will get you a list of all tags associated with a device.
64*6a54128fSAndroid Build Coastguard Worker * They are also linked via bit_values for all devices, so one can easily
65*6a54128fSAndroid Build Coastguard Worker * search all tags with a given NAME for a specific value.
66*6a54128fSAndroid Build Coastguard Worker */
67*6a54128fSAndroid Build Coastguard Worker struct blkid_struct_tag
68*6a54128fSAndroid Build Coastguard Worker {
69*6a54128fSAndroid Build Coastguard Worker struct list_head bit_tags; /* All tags for this device */
70*6a54128fSAndroid Build Coastguard Worker struct list_head bit_names; /* All tags with given NAME */
71*6a54128fSAndroid Build Coastguard Worker char *bit_name; /* NAME of tag (shared) */
72*6a54128fSAndroid Build Coastguard Worker char *bit_val; /* value of tag */
73*6a54128fSAndroid Build Coastguard Worker blkid_dev bit_dev; /* pointer to device */
74*6a54128fSAndroid Build Coastguard Worker };
75*6a54128fSAndroid Build Coastguard Worker typedef struct blkid_struct_tag *blkid_tag;
76*6a54128fSAndroid Build Coastguard Worker
77*6a54128fSAndroid Build Coastguard Worker /*
78*6a54128fSAndroid Build Coastguard Worker * Minimum number of seconds between device probes, even when reading
79*6a54128fSAndroid Build Coastguard Worker * from the cache. This is to avoid re-probing all devices which were
80*6a54128fSAndroid Build Coastguard Worker * just probed by another program that does not share the cache.
81*6a54128fSAndroid Build Coastguard Worker */
82*6a54128fSAndroid Build Coastguard Worker #define BLKID_PROBE_MIN 2
83*6a54128fSAndroid Build Coastguard Worker
84*6a54128fSAndroid Build Coastguard Worker /*
85*6a54128fSAndroid Build Coastguard Worker * Time in seconds an entry remains verified in the in-memory cache
86*6a54128fSAndroid Build Coastguard Worker * before being reverified (in case of long-running processes that
87*6a54128fSAndroid Build Coastguard Worker * keep a cache in memory and continue to use it for a long time).
88*6a54128fSAndroid Build Coastguard Worker */
89*6a54128fSAndroid Build Coastguard Worker #define BLKID_PROBE_INTERVAL 200
90*6a54128fSAndroid Build Coastguard Worker
91*6a54128fSAndroid Build Coastguard Worker /* This describes an entire blkid cache file and probed devices.
92*6a54128fSAndroid Build Coastguard Worker * We can traverse all of the found devices via bic_list.
93*6a54128fSAndroid Build Coastguard Worker * We can traverse all of the tag types by bic_tags, which hold empty tags
94*6a54128fSAndroid Build Coastguard Worker * for each tag type. Those tags can be used as list_heads for iterating
95*6a54128fSAndroid Build Coastguard Worker * through all devices with a specific tag type (e.g. LABEL).
96*6a54128fSAndroid Build Coastguard Worker */
97*6a54128fSAndroid Build Coastguard Worker struct blkid_struct_cache
98*6a54128fSAndroid Build Coastguard Worker {
99*6a54128fSAndroid Build Coastguard Worker struct list_head bic_devs; /* List head of all devices */
100*6a54128fSAndroid Build Coastguard Worker struct list_head bic_tags; /* List head of all tag types */
101*6a54128fSAndroid Build Coastguard Worker time_t bic_time; /* Last probe time */
102*6a54128fSAndroid Build Coastguard Worker time_t bic_ftime; /* Mod time of the cachefile */
103*6a54128fSAndroid Build Coastguard Worker unsigned int bic_flags; /* Status flags of the cache */
104*6a54128fSAndroid Build Coastguard Worker char *bic_filename; /* filename of cache */
105*6a54128fSAndroid Build Coastguard Worker };
106*6a54128fSAndroid Build Coastguard Worker
107*6a54128fSAndroid Build Coastguard Worker #define BLKID_BIC_FL_PROBED 0x0002 /* We probed /proc/partition devices */
108*6a54128fSAndroid Build Coastguard Worker #define BLKID_BIC_FL_CHANGED 0x0004 /* Cache has changed from disk */
109*6a54128fSAndroid Build Coastguard Worker
110*6a54128fSAndroid Build Coastguard Worker extern char *blkid_strdup(const char *s);
111*6a54128fSAndroid Build Coastguard Worker extern char *blkid_strndup(const char *s, const int length);
112*6a54128fSAndroid Build Coastguard Worker
113*6a54128fSAndroid Build Coastguard Worker #define BLKID_CACHE_FILE "/etc/blkid.tab"
114*6a54128fSAndroid Build Coastguard Worker
115*6a54128fSAndroid Build Coastguard Worker #define BLKID_ERR_IO 5
116*6a54128fSAndroid Build Coastguard Worker #define BLKID_ERR_PROC 9
117*6a54128fSAndroid Build Coastguard Worker #define BLKID_ERR_MEM 12
118*6a54128fSAndroid Build Coastguard Worker #define BLKID_ERR_CACHE 14
119*6a54128fSAndroid Build Coastguard Worker #define BLKID_ERR_DEV 19
120*6a54128fSAndroid Build Coastguard Worker #define BLKID_ERR_PARAM 22
121*6a54128fSAndroid Build Coastguard Worker #define BLKID_ERR_BIG 27
122*6a54128fSAndroid Build Coastguard Worker
123*6a54128fSAndroid Build Coastguard Worker /*
124*6a54128fSAndroid Build Coastguard Worker * Priority settings for different types of devices
125*6a54128fSAndroid Build Coastguard Worker */
126*6a54128fSAndroid Build Coastguard Worker #define BLKID_PRI_DM 40
127*6a54128fSAndroid Build Coastguard Worker #define BLKID_PRI_EVMS 30
128*6a54128fSAndroid Build Coastguard Worker #define BLKID_PRI_LVM 20
129*6a54128fSAndroid Build Coastguard Worker #define BLKID_PRI_MD 10
130*6a54128fSAndroid Build Coastguard Worker
131*6a54128fSAndroid Build Coastguard Worker #if defined(TEST_PROGRAM) && !defined(CONFIG_BLKID_DEBUG)
132*6a54128fSAndroid Build Coastguard Worker #define CONFIG_BLKID_DEBUG
133*6a54128fSAndroid Build Coastguard Worker #endif
134*6a54128fSAndroid Build Coastguard Worker
135*6a54128fSAndroid Build Coastguard Worker #define DEBUG_CACHE 0x0001
136*6a54128fSAndroid Build Coastguard Worker #define DEBUG_DUMP 0x0002
137*6a54128fSAndroid Build Coastguard Worker #define DEBUG_DEV 0x0004
138*6a54128fSAndroid Build Coastguard Worker #define DEBUG_DEVNAME 0x0008
139*6a54128fSAndroid Build Coastguard Worker #define DEBUG_DEVNO 0x0010
140*6a54128fSAndroid Build Coastguard Worker #define DEBUG_PROBE 0x0020
141*6a54128fSAndroid Build Coastguard Worker #define DEBUG_READ 0x0040
142*6a54128fSAndroid Build Coastguard Worker #define DEBUG_RESOLVE 0x0080
143*6a54128fSAndroid Build Coastguard Worker #define DEBUG_SAVE 0x0100
144*6a54128fSAndroid Build Coastguard Worker #define DEBUG_TAG 0x0200
145*6a54128fSAndroid Build Coastguard Worker #define DEBUG_INIT 0x8000
146*6a54128fSAndroid Build Coastguard Worker #define DEBUG_ALL 0xFFFF
147*6a54128fSAndroid Build Coastguard Worker
148*6a54128fSAndroid Build Coastguard Worker #ifdef CONFIG_BLKID_DEBUG
149*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
150*6a54128fSAndroid Build Coastguard Worker extern int blkid_debug_mask;
151*6a54128fSAndroid Build Coastguard Worker #define DBG(m,x) if ((m) & blkid_debug_mask) x;
152*6a54128fSAndroid Build Coastguard Worker #else
153*6a54128fSAndroid Build Coastguard Worker #define DBG(m,x)
154*6a54128fSAndroid Build Coastguard Worker #endif
155*6a54128fSAndroid Build Coastguard Worker
156*6a54128fSAndroid Build Coastguard Worker #ifdef CONFIG_BLKID_DEBUG
157*6a54128fSAndroid Build Coastguard Worker extern void blkid_debug_dump_dev(blkid_dev dev);
158*6a54128fSAndroid Build Coastguard Worker extern void blkid_debug_dump_tag(blkid_tag tag);
159*6a54128fSAndroid Build Coastguard Worker #endif
160*6a54128fSAndroid Build Coastguard Worker
blkidP_is_disk_device(mode_t mode)161*6a54128fSAndroid Build Coastguard Worker static inline int blkidP_is_disk_device(mode_t mode)
162*6a54128fSAndroid Build Coastguard Worker {
163*6a54128fSAndroid Build Coastguard Worker #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
164*6a54128fSAndroid Build Coastguard Worker return S_ISBLK(mode) || S_ISCHR(mode);
165*6a54128fSAndroid Build Coastguard Worker #else
166*6a54128fSAndroid Build Coastguard Worker return S_ISBLK(mode);
167*6a54128fSAndroid Build Coastguard Worker #endif
168*6a54128fSAndroid Build Coastguard Worker }
169*6a54128fSAndroid Build Coastguard Worker
170*6a54128fSAndroid Build Coastguard Worker /* devno.c */
171*6a54128fSAndroid Build Coastguard Worker struct dir_list {
172*6a54128fSAndroid Build Coastguard Worker char *name;
173*6a54128fSAndroid Build Coastguard Worker struct dir_list *next;
174*6a54128fSAndroid Build Coastguard Worker };
175*6a54128fSAndroid Build Coastguard Worker extern void blkid__scan_dir(const char *, dev_t, struct dir_list **, char **);
176*6a54128fSAndroid Build Coastguard Worker
177*6a54128fSAndroid Build Coastguard Worker /* lseek.c */
178*6a54128fSAndroid Build Coastguard Worker extern blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence);
179*6a54128fSAndroid Build Coastguard Worker
180*6a54128fSAndroid Build Coastguard Worker /* read.c */
181*6a54128fSAndroid Build Coastguard Worker extern void blkid_read_cache(blkid_cache cache);
182*6a54128fSAndroid Build Coastguard Worker
183*6a54128fSAndroid Build Coastguard Worker /* save.c */
184*6a54128fSAndroid Build Coastguard Worker extern int blkid_flush_cache(blkid_cache cache);
185*6a54128fSAndroid Build Coastguard Worker
186*6a54128fSAndroid Build Coastguard Worker /*
187*6a54128fSAndroid Build Coastguard Worker * Functions to create and find a specific tag type: tag.c
188*6a54128fSAndroid Build Coastguard Worker */
189*6a54128fSAndroid Build Coastguard Worker extern void blkid_free_tag(blkid_tag tag);
190*6a54128fSAndroid Build Coastguard Worker extern blkid_tag blkid_find_tag_dev(blkid_dev dev, const char *type);
191*6a54128fSAndroid Build Coastguard Worker extern int blkid_set_tag(blkid_dev dev, const char *name,
192*6a54128fSAndroid Build Coastguard Worker const char *value, const int vlength);
193*6a54128fSAndroid Build Coastguard Worker
194*6a54128fSAndroid Build Coastguard Worker /*
195*6a54128fSAndroid Build Coastguard Worker * Functions to create and find a specific tag type: dev.c
196*6a54128fSAndroid Build Coastguard Worker */
197*6a54128fSAndroid Build Coastguard Worker extern blkid_dev blkid_new_dev(void);
198*6a54128fSAndroid Build Coastguard Worker extern void blkid_free_dev(blkid_dev dev);
199*6a54128fSAndroid Build Coastguard Worker
200*6a54128fSAndroid Build Coastguard Worker #ifdef __cplusplus
201*6a54128fSAndroid Build Coastguard Worker }
202*6a54128fSAndroid Build Coastguard Worker #endif
203*6a54128fSAndroid Build Coastguard Worker
204*6a54128fSAndroid Build Coastguard Worker #endif /* _BLKID_BLKIDP_H */
205