50 status,
sizeof(*status));
56 &status,
sizeof(status));
90 (sizeof(struct slot_header) + fs->object_size) * loc->slot;
96 status,
sizeof(*status));
102 &status,
sizeof(status));
111 static bool _loc_equal(
struct ringfs_loc *a,
struct ringfs_loc *b)
113 return (a->sector == b->sector) && (a->slot == b->slot);
148 (sizeof(struct slot_header) + fs->object_size);
166 fs->
write.sector = 0;
184 bool free_seen =
false;
186 bool used_seen =
false;
194 fs->
flash->
read(addr, &header,
sizeof(header));
198 printf(
"ringfs_scan: partially formatted partition\r\n");
210 printf(
"ringfs_scan: corrupted sector %d\r\n", sector);
217 printf(
"ringfs_scan: incompatible version 0x%08"PRIx32
"\r\n", header.
version);
227 read_sector = sector;
229 write_sector = sector-1;
231 previous_sector_status = header.
status;
236 printf(
"ringfs_scan: invariant violated: no FREE sector found\r\n");
246 fs->
write.sector = write_sector;
248 while (fs->
write.sector == write_sector) {
261 fs->
read.sector = read_sector;
296 struct ringfs_loc loc = fs->
read;
328 if (fs->
read.sector == next_sector)
330 if (fs->
cursor.sector == next_sector)
343 printf(
"ringfs_append: corrupted filesystem\r\n");
int sector_size
Sector size, in bytes.
int ringfs_format(struct ringfs *fs)
Format the flash memory.
static int _sector_get_status(struct ringfs *fs, int sector, uint32_t *status)
The entire partition is being formatted.
static void _loc_advance_slot(struct ringfs *fs, struct ringfs_loc *loc)
Advance a location to the next slot, advancing the sector too if needed.
int sector_count
Partition size, in sectors.
int ringfs_capacity(struct ringfs *fs)
Calculate maximum RingFS capacity.
Default state after NOR flash erase.
int ringfs_init(struct ringfs *fs, const struct ringfs_flash_partition *flash, uint32_t version, int object_size)
Initialize a RingFS instance.
Flash memory+parition descriptor.
static int _slot_set_status(struct ringfs *fs, struct ringfs_loc *loc, uint32_t status)
Write started but not yet committed.
static int _sector_address(struct ringfs *fs, int sector_offset)
ssize_t(* program)(int address, const void *data, size_t size)
Program flash memory bits by toggling them from 1 to 0.
int ringfs_count_exact(struct ringfs *fs)
Calculate exact object count.
Default state after NOR flash erase.
ssize_t(* read)(int address, void *data, size_t size)
Read flash memory.
int ringfs_count_estimate(struct ringfs *fs)
Calculate approximate object count.
static int _sector_free(struct ringfs *fs, int sector)
static bool _loc_equal(struct ringfs_loc *a, struct ringfs_loc *b)
int ringfs_discard(struct ringfs *fs)
Discard all fetched objects up to the read cursor.
int ringfs_scan(struct ringfs *fs)
Scan the flash memory for a valid filesystem.
int ringfs_fetch(struct ringfs *fs, void *object)
Fetch next object from the ring, oldest-first.
static void _loc_advance_sector(struct ringfs *fs, struct ringfs_loc *loc)
Advance a location to the beginning of the next sector.
int sector_offset
Partition offset, in sectors.
static int _sector_set_status(struct ringfs *fs, int sector, uint32_t status)
static const struct ringfs_flash_partition flash
static int _slot_get_status(struct ringfs *fs, struct ringfs_loc *loc, uint32_t *status)
int ringfs_rewind(struct ringfs *fs)
Rewind the read cursor back to the oldest object.
static int _slot_address(struct ringfs *fs, struct ringfs_loc *loc)
Write committed, slot contains valid data.
Slot contents discarded and no longer valid.
int(* sector_erase)(int address)
Erase a sector.
const struct ringfs_flash_partition * flash
Sector contains valid data.
int ringfs_append(struct ringfs *fs, const void *object)
Append an object at the end of the ring.