What is on a storage port (v4/system/storage.c): it takes Block read, Block write and Block data and answers Block data or Block done. It holds a view of a common chain, a private chain, or both; private block k is number 2^32 - 1 - k. Behind it is v3's block subsystem, reached through v4/system/store_v3.c, the one v4 file that includes v3's headers. v3's block code links here with its two device back ends, its log and its clock, and nothing else of v3. v4/tests/test_store.c: 36 checks at 64 bits, 35 at 32, and under the sanitizers. docs/v4.0.0/MESH.md 8.3, 8.4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.7 KiB
C
56 lines
1.7 KiB
C
/* 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 };
|