+#include <string.h>
+
+INLINE size_t kblock_readDirect(struct KBlock *b, block_idx_t index, void *buf, size_t offset, size_t size)
+{
+ KB_ASSERT_METHOD(b, readDirect);
+ ASSERT(index < b->blk_cnt);
+ return b->priv.vt->readDirect(b, b->priv.blk_start + index, buf, offset, size);
+}
+
+INLINE size_t kblock_writeDirect(struct KBlock *b, block_idx_t index, const void *buf, size_t offset, size_t size)
+{
+ KB_ASSERT_METHOD(b, writeDirect);
+ ASSERT(index < b->blk_cnt);
+ return b->priv.vt->writeDirect(b, b->priv.blk_start + index, buf, offset, size);
+}
+
+INLINE size_t kblock_readBuf(struct KBlock *b, void *buf, size_t offset, size_t size)
+{
+ KB_ASSERT_METHOD(b, readBuf);
+ ASSERT(offset + size <= b->blk_size);
+
+ return b->priv.vt->readBuf(b, buf, offset, size);
+}
+
+INLINE size_t kblock_writeBuf(struct KBlock *b, const void *buf, size_t offset, size_t size)
+{
+ KB_ASSERT_METHOD(b, writeBuf);
+ ASSERT(offset + size <= b->blk_size);
+ return b->priv.vt->writeBuf(b, buf, offset, size);
+}
+
+INLINE int kblock_load(struct KBlock *b, block_idx_t index)
+{
+ KB_ASSERT_METHOD(b, load);
+ ASSERT(index < b->blk_cnt);
+
+ LOG_INFO("index %ld\n", index);
+ return b->priv.vt->load(b, b->priv.blk_start + index);
+}
+
+INLINE int kblock_store(struct KBlock *b, block_idx_t index)
+{
+ KB_ASSERT_METHOD(b, store);
+ ASSERT(index < b->blk_cnt);
+
+ LOG_INFO("index %ld\n", index);
+ return b->priv.vt->store(b, b->priv.blk_start + index);
+}
+
+INLINE void kblock_setDirty(struct KBlock *b, bool dirty)
+{
+ if (dirty)
+ b->priv.flags |= KB_CACHE_DIRTY;
+ else
+ b->priv.flags &= ~KB_CACHE_DIRTY;
+}
+
+
+
+size_t kblock_read(struct KBlock *b, block_idx_t idx, void *buf, size_t offset, size_t size)
+{
+ ASSERT(b);
+ ASSERT(buf);
+ ASSERT(offset + size <= b->blk_size);
+ LOG_INFO("blk_idx %ld, offset %u, size %u\n", idx, offset, size);
+
+ if (kblock_buffered(b) && idx == b->priv.curr_blk)
+ return kblock_readBuf(b, buf, offset, size);
+ else
+ return kblock_readDirect(b, idx, buf, offset, size);
+}