#include "queue.h"
#define EXT4_BLOCK_ZERO() \
- {.uptodate = 0, .dirty = 0, .lb_id = 0, .data = 0}
+ {.lb_id = 0, .data = 0}
/**@brief Single block descriptor*/
struct ext4_block {
- /**@brief Uptodate flag*/
- bool uptodate;
-
- /**@brief Dirty flag*/
- bool dirty;
-
/**@brief Logical block ID*/
uint64_t lb_id;
SLIST_HEAD(ext4_buf_dirty, ext4_buf) dirty_list;
};
+/**@brief buffer state bits
+ *
+ * - BC♡UPTODATE: Buffer contains valid data.
+ * - BC_DIRTY: Buffer is dirty.
+ * - BC_FLUSH: Buffer will be immediately flushed,
+ * when no one references it.
+ */
enum bcache_state_bits {
BC_UPTODATE,
- BC_DIRTY
+ BC_DIRTY,
+ BC_FLUSH
};
#define ext4_bcache_set_flag(buf, b) \
#define ext4_bcache_test_flag(buf, b) \
(((buf)->flags & (1 << (b))) >> (b))
+static inline void ext4_bcache_set_dirty(struct ext4_buf *buf) {
+ ext4_bcache_set_flag(buf, BC_UPTODATE);
+ ext4_bcache_set_flag(buf, BC_DIRTY);
+}
+
+static inline void ext4_bcache_clear_dirty(struct ext4_buf *buf) {
+ ext4_bcache_clear_flag(buf, BC_UPTODATE);
+ ext4_bcache_clear_flag(buf, BC_DIRTY);
+}
+
+/**@brief Increment reference counter of buf by 1.*/
+#define ext4_bcache_inc_ref(buf) ((buf)->refctr++)
+
+/**@brief Decrement reference counter of buf by 1.*/
+#define ext4_bcache_dec_ref(buf) ((buf)->refctr--)
+
/**@brief Static initializer of block cache structure.*/
#define EXT4_BCACHE_STATIC_INSTANCE(__name, __cnt, __itemsize) \
static struct ext4_bcache __name = { \