/* store_v3.c -- the kernel's block subsystem as the chains behind a storage * port. docs/v4.0.0/MESH.md 8.4, docs/v4.0.0/V3-PARITY.md 1d. * * A chain is a blk_chain_t (v3/include/block_subsystem.h). Every block goes * through v3's own calls, so the header, the allocation map, the block * cards and relocation are v3's, as they were. Who may have a block is not * checked here yet (MESH.md 8.5). * * This is the one file of v4's that includes v3's headers. */ #include "v4/storage.h" #include "block_subsystem.h" static int v3_read(void *chain, uint32_t block, unsigned char *bytes) { blk_chain_t *was = blk_chain_select((blk_chain_t *)chain); int status = V4_STORE_RANGE; unsigned i; if (blk_is_valid(block)) { const uint8_t *b = blk_get_buffer(block, 0); status = b ? V4_STORE_OK : V4_STORE_REFUSED; if (b) for (i = 0; i < V4_STORE_BYTES; i++) bytes[i] = b[i]; } blk_chain_select(was); return status; } static int v3_write(void *chain, uint32_t block, const unsigned char *bytes) { blk_chain_t *was = blk_chain_select((blk_chain_t *)chain); int status = V4_STORE_RANGE; unsigned i; if (blk_is_valid(block)) { uint8_t *b = blk_get_buffer(block, 1); status = V4_STORE_REFUSED; if (b) { for (i = 0; i < V4_STORE_BYTES; i++) b[i] = bytes[i]; if (blk_update(block) == BLK_OK && blk_flush(block) == BLK_OK) status = V4_STORE_OK; } } blk_chain_select(was); return status; } static uint32_t v3_blocks(void *chain) { blk_chain_t *was = blk_chain_select((blk_chain_t *)chain); uint32_t n = blk_get_total_blocks(); blk_chain_select(was); return n; } const v4_store_ops v4_store_v3 = { v3_read, v3_write, v3_blocks };