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