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