2 * Author: Kent Overstreet <kmo@daterainc.com>
10 #define BITMASK(name, type, field, offset, size) \
11 static inline uint64_t name(const type *k) \
12 { return (k->field >> offset) & ~(((uint64_t) ~0) << size); } \
14 static inline void SET_##name(type *k, uint64_t v) \
16 k->field &= ~(~((uint64_t) ~0 << size) << offset); \
17 k->field |= v << offset; \
20 static const char bcache_magic[] = {
21 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca,
22 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 };
25 * Version 0: Cache device
26 * Version 1: Backing device
27 * Version 2: Seed pointer into btree node checksum
28 * Version 3: Cache device with new UUID format
29 * Version 4: Backing device with data offset
31 #define BCACHE_SB_VERSION_CDEV 0
32 #define BCACHE_SB_VERSION_BDEV 1
33 #define BCACHE_SB_VERSION_CDEV_WITH_UUID 3
34 #define BCACHE_SB_VERSION_BDEV_WITH_OFFSET 4
35 #define BCACHE_SB_MAX_VERSION 4
38 #define SB_LABEL_SIZE 32
39 #define SB_JOURNAL_BUCKETS 256U
40 #define BDEV_DATA_START_DEFAULT 16 /* sectors */
41 #define SB_START (SB_SECTOR * 512)
45 uint64_t offset; /* sector where this sb was written */
55 uint8_t label[SB_LABEL_SIZE];
64 uint64_t nbuckets; /* device size */
66 uint16_t block_size; /* sectors */
67 uint16_t bucket_size; /* sectors */
77 * block_size from the cache device section is still used by
78 * backing devices, so don't add anything here until we fix
79 * things to not need it for backing devices anymore
84 uint32_t last_mount; /* time_t */
86 uint16_t first_bucket;
88 uint16_t njournal_buckets;
91 uint64_t d[SB_JOURNAL_BUCKETS]; /* journal buckets */
94 static inline bool SB_IS_BDEV(const struct cache_sb *sb)
96 return sb->version == BCACHE_SB_VERSION_BDEV
97 || sb->version == BCACHE_SB_VERSION_BDEV_WITH_OFFSET;
100 BITMASK(CACHE_SYNC, struct cache_sb, flags, 0, 1);
101 BITMASK(CACHE_DISCARD, struct cache_sb, flags, 1, 1);
102 BITMASK(CACHE_REPLACEMENT, struct cache_sb, flags, 2, 3);
103 #define CACHE_REPLACEMENT_LRU 0U
104 #define CACHE_REPLACEMENT_FIFO 1U
105 #define CACHE_REPLACEMENT_RANDOM 2U
107 BITMASK(BDEV_CACHE_MODE, struct cache_sb, flags, 0, 4);
108 #define CACHE_MODE_WRITETHROUGH 0U
109 #define CACHE_MODE_WRITEBACK 1U
110 #define CACHE_MODE_WRITEAROUND 2U
111 #define CACHE_MODE_NONE 3U
112 BITMASK(BDEV_STATE, struct cache_sb, flags, 61, 2);
113 #define BDEV_STATE_NONE 0U
114 #define BDEV_STATE_CLEAN 1U
115 #define BDEV_STATE_DIRTY 2U
116 #define BDEV_STATE_STALE 3U
118 inline uint64_t crc64(const void *_data, size_t len);
120 #define node(i, j) ((void *) ((i)->d + (j)))
121 #define end(i) node(i, (i)->keys)
123 #define csum_set(i) \
124 crc64(((void *) (i)) + 8, ((void *) end(i)) - (((void *) (i)) + 8))