return (fwrite(f->b.priv.buf, 1, b->blk_size, f->fp) == b->blk_size) ? 0 : EOF;
}
-static int kblockfile_readBlock(struct KBlock *b, block_idx_t index, void *buf)
-{
- KBlockFile *f = KBLOCKFILE_CAST(b);
- ASSERT(buf);
- ASSERT(index < b->blk_cnt);
- fseek(f->fp, index * b->blk_size, SEEK_SET);
- return (fread(f->b.priv.buf, 1, b->blk_size, f->fp) == b->blk_size) ? 0 : EOF;
-}
-
static int kblockfile_error(struct KBlock *b)
{
KBlockFile *f = KBLOCKFILE_CAST(b);
static const KBlockVTable kblockfile_hwbuffered_vt =
{
.readDirect = kblockfile_readDirect,
+
.readBuf = kblockfile_readBuf,
.writeBuf = kblockfile_writeBuf,
.load = kblockfile_load,
.store = kblockfile_store,
- .readBlock = kblock_swReadBlock,
- .writeBlock = kblock_swWriteBlock,
-
.error = kblockfile_error,
.clearerr = kblockfile_claererr,
.close = kblockfile_close,
static const KBlockVTable kblockfile_swbuffered_vt =
{
- .readDirect = kblock_swReadDirect,
+ .readDirect = kblockfile_readDirect,
+ .writeBlock =kblockfile_writeBlock,
+
.readBuf = kblock_swReadBuf,
.writeBuf = kblock_swWriteBuf,
.load = kblock_swLoad,
.store = kblock_swStore,
- .readBlock = kblockfile_readBlock,
- .writeBlock =kblockfile_writeBlock,
-
.error = kblockfile_error,
.clearerr = kblockfile_claererr,
.close = kblockfile_close,
static const KBlockVTable kblockfile_unbuffered_vt =
{
- .readBlock = kblockfile_readBlock,
+ .readDirect = kblockfile_readDirect,
.writeBlock =kblockfile_writeBlock,
.error = kblockfile_error,
return 0;
}
-static int kblockram_readBlock(struct KBlock *b, block_idx_t index, void *buf)
-{
- KBlockRam *r = KBLOCKRAM_CAST(b);
- ASSERT(buf);
- ASSERT(index < b->blk_cnt);
-
- memcpy(buf, r->membuf + index * r->b.blk_size, r->b.blk_size);
- return 0;
-}
-
static int kblockram_dummy(UNUSED_ARG(struct KBlock *,b))
{
return 0;
static const KBlockVTable kblockram_hwbuffered_vt =
{
.readDirect = kblockram_readDirect,
+
.readBuf = kblockram_readBuf,
.writeBuf = kblockram_writeBuf,
.load = kblockram_load,
.store = kblockram_store,
- .readBlock = kblock_swReadBlock,
- .writeBlock = kblock_swWriteBlock,
-
.error = kblockram_dummy,
.clearerr = kblockram_dummy,
.close = kblockram_dummy,
static const KBlockVTable kblockram_swbuffered_vt =
{
- .readDirect = kblock_swReadDirect,
+ .readDirect = kblockram_readDirect,
+ .writeBlock = kblockram_writeBlock,
+
.readBuf = kblock_swReadBuf,
.writeBuf = kblock_swWriteBuf,
.load = kblock_swLoad,
.store = kblock_swStore,
-
- .readBlock = kblockram_readBlock,
- .writeBlock = kblockram_writeBlock,
-
+
.error = kblockram_dummy,
.clearerr = kblockram_dummy,
.close = kblockram_dummy,
static const KBlockVTable kblockram_unbuffered_vt =
{
- .readBlock = kblockram_readBlock,
+ .readDirect = kblockram_readDirect,
.writeBlock = kblockram_writeBlock,
.error = kblockram_dummy,