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