18 #define ITS_FLASH_FS_INTERNAL_FLAGS_MASK (UINT32_MAX - ((1U << 24) - 1))
20 #define ITS_FLASH_FS_FLAG_DELETE (1U << 24)
23 uint32_t del_file_idx);
25 static psa_status_t its_flash_fs_file_write_aligned_data(
33 #if (ITS_FLASH_MAX_ALIGNMENT != 1)
84 return its_flash_fs_delete_idx(fs_ctx, idx);
154 uint32_t cur_phys_block;
166 #if (ITS_FLASH_MAX_ALIGNMENT != 1)
181 if (file_meta.
max_size == max_size) {
227 max_size, flags, &new_idx,
228 &file_meta, &block_meta);
241 if (data_size != 0) {
243 err = its_flash_fs_file_write_aligned_data(fs_ctx, &block_meta,
251 if (offset + data_size > file_meta.
cur_size) {
253 file_meta.
cur_size = offset + data_size;
256 cur_phys_block = block_meta.
phy_id;
336 err = its_flash_fs_delete_idx(fs_ctx, old_idx);
343 uint32_t del_file_idx)
345 size_t del_file_data_idx;
346 uint32_t del_file_lblock;
347 size_t del_file_max_size;
350 size_t nbr_bytes_to_move = 0;
364 del_file_lblock = file_meta.
lblock;
365 del_file_data_idx = file_meta.
data_idx;
366 del_file_max_size = file_meta.
max_size;
380 if (idx == del_file_idx) {
394 if ((file_meta.
lblock == del_file_lblock) &&
399 if (file_meta.
data_idx > del_file_data_idx) {
403 if (src_offset > file_meta.
data_idx) {
410 file_meta.
data_idx -= del_file_max_size;
413 nbr_bytes_to_move += file_meta.
max_size;
427 src_offset, del_file_data_idx,
458 uint32_t del_file_idx;
466 return its_flash_fs_delete_idx(fs_ctx, del_file_idx);
513 static uint32_t its_flash_fs_num_active_dblocks(
const struct its_flash_info_t *info)
533 static size_t its_flash_fs_all_metadata_size(
const struct its_flash_info_t *info)
536 + (its_flash_fs_num_active_dblocks(info)
559 - its_flash_fs_all_metadata_size(info)) {
574 if (its_flash_fs_all_metadata_size(info) > info->
block_size) {
psa_status_t its_flash_fs_mblock_update_scratch_block_meta(struct its_flash_fs_ctx_t *fs_ctx, uint32_t lblock, struct its_block_meta_t *block_meta)
Puts logical block's metadata in scratch metadata block.
const struct its_flash_info_t * flash_info
#define ITS_LOGICAL_DBLOCK0
Defines logical data block 0 ID.
psa_status_t its_flash_fs_file_get_info(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid, struct its_file_info_t *info)
Gets the file information referenced by the file ID.
psa_status_t its_flash_fs_mblock_get_file_idx(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid, uint32_t *idx)
Gets file metadata entry index.
#define ITS_UTILS_IS_ALIGNED(x, a)
Checks that a value is aligned to the provided alignment.
psa_status_t its_flash_fs_prepare(struct its_flash_fs_ctx_t *fs_ctx, const struct its_flash_info_t *flash_info)
Prepares the filesystem to accept operations on the files.
#define PSA_ERROR_STORAGE_FAILURE
Internal Trusted Storage service filesystem abstraction APIs. The purpose of this abstraction is to h...
psa_status_t its_flash_fs_validate_params(const struct its_flash_info_t *info)
Validates the configuration of the flash filesystem.
psa_status_t its_flash_fs_dblock_write_file(struct its_flash_fs_ctx_t *fs_ctx, const struct its_block_meta_t *block_meta, const struct its_file_meta_t *file_meta, size_t offset, size_t size, const uint8_t *data)
Writes scratch data block content with requested data and the rest of the data from the given logical...
psa_status_t its_utils_validate_fid(const uint8_t *fid)
Validates file ID.
#define ITS_FLASH_FS_FLAG_DELETE
#define ITS_FLASH_FS_USER_FLAGS_MASK
psa_status_t its_flash_fs_file_exist(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid)
Checks if a file exists in the filesystem.
#define ITS_UTILS_MAX(x, y)
Evaluates to the maximum of the two parameters.
psa_status_t its_flash_fs_file_write(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid, uint32_t flags, size_t max_size, size_t data_size, size_t offset, const uint8_t *data)
Writes data to a file.
psa_status_t its_flash_fs_mblock_read_block_metadata(struct its_flash_fs_ctx_t *fs_ctx, uint32_t lblock, struct its_block_meta_t *block_meta)
Reads specified logical block metadata.
uint32_t its_flash_fs_mblock_cur_data_scratch_id(struct its_flash_fs_ctx_t *fs_ctx, uint32_t lblock)
Gets current scratch datablock physical ID.
psa_status_t its_flash_fs_mblock_reserve_file(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid, bool use_spare, size_t size, uint32_t flags, uint32_t *idx, struct its_file_meta_t *file_meta, struct its_block_meta_t *block_meta)
Reserves space for a file.
void its_flash_fs_mblock_set_data_scratch(struct its_flash_fs_ctx_t *fs_ctx, uint32_t phy_id, uint32_t lblock)
Sets current data scratch block.
#define PSA_ERROR_GENERIC_ERROR
#define PSA_ERROR_INVALID_ARGUMENT
psa_status_t its_flash_fs_mblock_reset_metablock(struct its_flash_fs_ctx_t *fs_ctx)
Resets metablock by cleaning and initializing the metadatablock.
psa_status_t its_utils_check_contained_in(size_t superset_size, size_t subset_offset, size_t subset_size)
Checks if a subset region is fully contained within a superset region.
psa_status_t its_flash_fs_file_read(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid, size_t size, size_t offset, uint8_t *data)
Reads data from an existing file.
#define ITS_METADATA_INVALID_INDEX
Defines the invalid index value when the metadata table is full.
psa_status_t its_flash_fs_file_delete(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid)
Deletes file referenced by the file ID.
psa_status_t its_flash_fs_mblock_meta_update_finalize(struct its_flash_fs_ctx_t *fs_ctx)
Finalizes an update operation. Last step when a create/write/delete is performed. ...
#define ITS_FLASH_FS_INTERNAL_FLAGS_MASK
psa_status_t its_flash_fs_mblock_read_file_meta(struct its_flash_fs_ctx_t *fs_ctx, uint32_t idx, struct its_file_meta_t *file_meta)
Reads specified file metadata.
psa_status_t its_flash_fs_dblock_read_file(struct its_flash_fs_ctx_t *fs_ctx, const struct its_file_meta_t *file_meta, size_t offset, size_t size, uint8_t *buf)
Reads the file content.
psa_status_t its_flash_fs_mblock_get_file_idx_flag(struct its_flash_fs_ctx_t *fs_ctx, uint32_t flags, uint32_t *idx)
Gets file metadata entry index of the first file with one of the provided flags set.
__STATIC_INLINE int tfm_memcmp(const void *ptr1, const void *ptr2, size_t num)
psa_status_t its_flash_fs_mblock_cp_file_meta(struct its_flash_fs_ctx_t *fs_ctx, uint32_t idx_start, uint32_t idx_end)
Copies the file metadata entries between two indexes from the active metadata block to the scratch me...
psa_status_t its_flash_fs_dblock_compact_block(struct its_flash_fs_ctx_t *fs_ctx, uint32_t lblock, size_t free_size, size_t src_offset, size_t dst_offset, size_t size)
Compacts block data for the given logical block.
#define ITS_FLASH_FS_FLAG_CREATE
psa_status_t its_flash_fs_wipe_all(struct its_flash_fs_ctx_t *fs_ctx)
Wipes all files from the filesystem.
Structure to store the file information.
Structure containing the required information about a flash device to be used by the ITS Flash FS...
Structure to store the ITS flash file system context.
#define PSA_ERROR_DOES_NOT_EXIST
psa_status_t its_flash_fs_mblock_update_scratch_file_meta(struct its_flash_fs_ctx_t *fs_ctx, uint32_t idx, const struct its_file_meta_t *file_meta)
Writes a file metadata entry into scratch metadata block.
int32_t psa_status_t
Function return status.
#define ITS_UTILS_ALIGN(x, a)
Aligns a value up to the provided alignment.
psa_status_t its_flash_fs_mblock_init(struct its_flash_fs_ctx_t *fs_ctx)
Initializes metadata block with the valid/active metablock.
#define ITS_UTILS_MIN(x, y)
Evaluates to the minimum of the two parameters.
#define ITS_FLASH_FS_FLAG_TRUNCATE
psa_status_t its_flash_fs_mblock_migrate_lb0_data_to_scratch(struct its_flash_fs_ctx_t *fs_ctx)
Writes the files data area of logical block 0 into the scratch block.