35 #define MIN(x,y) ((x) < (y) ? (x) : (y))
133 (uint8_t *)&arena_hdr,
134 sizeof(arena_hdr)) != 0) {
156 (uint8_t *)&arena_hdr,
157 sizeof(arena_hdr)) != 0) {
171 (uint8_t *)&arena_hdr,
172 sizeof(arena_hdr)) != 0) {
189 for (uint16_t arena = 0; arena < num_arenas; arena++) {
211 (uint8_t *)&arena_hdr,
212 sizeof (arena_hdr)) != 0) {
226 (uint8_t *)&arena_hdr,
227 sizeof(arena_hdr)) != 0) {
252 (uint8_t *)&arena_hdr,
253 sizeof (arena_hdr)) != 0) {
267 (uint8_t *)&arena_hdr,
268 sizeof(arena_hdr)) != 0) {
286 for (uint8_t arena_id = 0;
294 (uint8_t *)&arena_hdr,
295 sizeof (arena_hdr)) != 0) {
340 #define RAW_COPY_BLOCK_SIZE 16
372 src_size -= blk_size;
373 src_addr += blk_size;
374 dst_addr += blk_size;
420 for (uint16_t slot_id = 1;
427 (uint8_t *)&slot_hdr,
428 sizeof (slot_hdr)) != 0) {
439 switch (slot_hdr.
state) {
469 if (!logfs)
return (NULL);
530 for (uint8_t
try = 0; !found &&
try < 2;
try++) {
562 *fs_id = (uintptr_t) logfs;
611 uint16_t dst_slot_id = 1;
612 for (uint16_t src_slot_id = 1;
616 uintptr_t src_addr =
logfs_get_addr (logfs, src_arena_id, src_slot_id);
619 (uint8_t *)&slot_hdr,
620 sizeof (slot_hdr)) != 0) {
625 uintptr_t dst_addr =
logfs_get_addr (logfs, dst_arena_id, dst_slot_id);
628 sizeof(slot_hdr) + slot_hdr.
obj_size,
667 if (*curr_slot == 0) *curr_slot = 1;
669 for (uint16_t slot_id = *curr_slot;
677 sizeof (*slot_hdr)) != 0) {
685 slot_hdr->
obj_id == obj_id &&
688 *curr_slot = slot_id;
704 uint16_t curr_slot_id = 0;
715 (uint8_t *)&slot_hdr,
716 sizeof(slot_hdr)) != 0) {
750 if (obj_size > (logfs->
cfg->
slot_size - sizeof (slot_hdr))) {
763 sizeof (*slot_hdr)) != 0) {
783 sizeof(*slot_hdr)) != 0) {
791 *slot_id = candidate_slot_id;
799 uint16_t free_slot_id;
811 uintptr_t slot_offset =
sizeof(slot_hdr);
814 slot_addr + slot_offset,
826 (uint8_t *)&slot_hdr,
827 sizeof(slot_hdr)) != 0) {
966 uint16_t slot_id = 0;
975 if (slot_hdr.
obj_size != obj_size) {
985 slot_addr +
sizeof(slot_hdr),
int32_t PIOS_FLASH_find_partition_id(enum pios_flash_partition_labels label, uintptr_t *partition_id)
Main PiOS header to include all the compiled in PiOS options.
static int32_t logfs_raw_copy_bytes(const struct logfs_state *logfs, uintptr_t src_addr, uint16_t src_size, uintptr_t dst_addr)
static int32_t logfs_erase_all_arenas(const struct logfs_state *logfs)
Erases all arenas available to this filesystem instance.
int32_t PIOS_FLASH_get_partition_size(uintptr_t partition_id, uint32_t *partition_size)
static int32_t logfs_erase_arena(const struct logfs_state *logfs, uint8_t arena_id)
Erases all sectors within the given arena and sets arena to erased state.
#define RAW_COPY_BLOCK_SIZE
#define PIOS_DEBUG_Assert(test)
static void PIOS_FLASHFS_Logfs_free(struct logfs_state *logfs)
static int8_t logfs_delete_object(struct logfs_state *logfs, uint32_t obj_id, uint16_t obj_inst_id)
int32_t PIOS_FLASHFS_Logfs_Init(uintptr_t *fs_id, const struct flashfs_logfs_cfg *cfg, enum pios_flash_partition_labels partition_label)
Initialize the flash object setting FS.
void * PIOS_malloc_no_dma(size_t size)
int32_t PIOS_FLASHFS_Logfs_Destroy(uintptr_t fs_id)
int32_t PIOS_FLASH_write_data(uintptr_t partition_id, uint32_t offset, const uint8_t *data, uint16_t len)
static struct flyingpicmd_cfg_fa cfg
int32_t PIOS_FLASH_end_transaction(uintptr_t partition_id)
int32_t PIOS_FLASHFS_ObjDelete(uintptr_t fs_id, uint32_t obj_id, uint16_t obj_inst_id)
Delete one instance of an object from the filesystem.
static int32_t logfs_reserve_arena(const struct logfs_state *logfs, uint8_t arena_id)
Marks the given arena as reserved so it can be filled.
static int16_t logfs_object_find_next(const struct logfs_state *logfs, struct slot_header *slot_hdr, uint16_t *curr_slot, uint32_t obj_id, uint16_t obj_inst_id)
static bool PIOS_FLASHFS_Logfs_validate(const struct logfs_state *logfs)
static struct logfs_state * PIOS_FLASHFS_Logfs_alloc(void)
static int8_t logfs_reserve_free_slot(struct logfs_state *logfs, uint16_t *slot_id, struct slot_header *slot_hdr, uint32_t obj_id, uint16_t obj_inst_id, uint16_t obj_size)
static bool logfs_log_is_full(const struct logfs_state *logfs)
static int32_t logfs_find_active_arena(const struct logfs_state *logfs)
Find the first active arena in flash.
static int8_t logfs_append_to_log(struct logfs_state *logfs, uint32_t obj_id, uint16_t obj_inst_id, uint8_t *obj_data, uint16_t obj_size)
pios_flashfs_logfs_dev_magic
static uintptr_t logfs_get_addr(const struct logfs_state *logfs, uint8_t arena_id, uint16_t slot_id)
Return the offset in flash of a particular slot within an arena.
int32_t PIOS_FLASH_erase_range(uintptr_t partition_id, uint32_t start_offset, uint32_t size)
void PIOS_free(void *buf)
static int32_t logfs_garbage_collect(struct logfs_state *logfs)
int32_t PIOS_FLASHFS_ObjSave(uintptr_t fs_id, uint32_t obj_id, uint16_t obj_inst_id, uint8_t *obj_data, uint16_t obj_size)
Saves one object instance to the filesystem.
int32_t PIOS_FLASHFS_ObjLoad(uintptr_t fs_id, uint32_t obj_id, uint16_t obj_inst_id, uint8_t *obj_data, uint16_t obj_size)
Load one object instance from the filesystem.
static int32_t logfs_activate_arena(const struct logfs_state *logfs, uint8_t arena_id)
Marks the given arena as active so it can be mounted.
static bool logfs_fs_is_full(const struct logfs_state *logfs)
enum arena_state __attribute__((packed))
pios_flash_partition_labels
int32_t PIOS_FLASH_read_data(uintptr_t partition_id, uint32_t offset, uint8_t *data, uint16_t len)
enum pios_flashfs_logfs_dev_magic magic
int32_t PIOS_FLASH_start_transaction(uintptr_t partition_id)
static int32_t logfs_obsolete_arena(const struct logfs_state *logfs, uint8_t arena_id)
Marks the given arena as obsolete.
static int32_t logfs_mount_log(struct logfs_state *logfs, uint8_t arena_id)
const struct flashfs_logfs_cfg * cfg
int32_t PIOS_FLASHFS_Format(uintptr_t fs_id)
Erases all filesystem arenas and activate the first arena.
#define PIOS_Assert(test)
static int32_t logfs_unmount_log(struct logfs_state *logfs)
uint16_t num_active_slots