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