Skip to content

Commit

Permalink
[component/fs/romfs] prepare for external APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
versaloon committed Aug 9, 2023
1 parent 3c53b2c commit 8c83be2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 10 additions & 6 deletions source/component/fs/driver/romfs/vsf_romfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,17 @@ const vk_fs_op_t vk_romfs_op = {
/*============================ LOCAL VARIABLES ===============================*/
/*============================ IMPLEMENTATION ================================*/

static bool __vsf_romfs_is_image_valid(vk_romfs_header_t *image)
bool vsf_romfs_is_image_valid(vk_romfs_header_t *image)
{
return (image->nextfh == be32_to_cpu(0x2d726f6d)) && (image->spec == be32_to_cpu(0x3166732d));
}

vk_romfs_header_t * vsf_romfs_chain_get_next(vk_romfs_header_t *image)
{
image = (vk_romfs_header_t *)((uint8_t *)image + be32_to_cpu(image->size));
return vsf_romfs_is_image_valid(image) ? image : NULL;
}

static vk_romfs_header_t * __vsf_romfs_lookup_in_dir(vk_romfs_header_t *image, vk_romfs_header_t *dir, char *name)
{
vk_romfs_header_t *header = dir + 1;
Expand Down Expand Up @@ -171,7 +177,7 @@ __vsf_component_peda_ifs_entry(__vk_romfs_mount, vk_fs_mount)

fsinfo->root.header = fsinfo->root.image = fsinfo->image;
// basic check for romfs
if (!__vsf_romfs_is_image_valid(fsinfo->image)) {
if (!vsf_romfs_is_image_valid(fsinfo->image)) {
vsf_eda_return(VSF_ERR_FAIL);
return;
}
Expand Down Expand Up @@ -263,10 +269,8 @@ __vsf_component_peda_ifs_entry(__vk_romfs_lookup, vk_file_lookup)
}
} else if (fsinfo->is_chained) {
while (true) {
image = (vk_romfs_header_t *)((uint8_t *)image + be32_to_cpu(image->size));

if ( ((uint8_t *)image >= ((uint8_t *)fsinfo->image + fsinfo->image_size))
|| !__vsf_romfs_is_image_valid(image)) {
image = vsf_romfs_chain_get_next(image);
if ((NULL == image) || ((uint8_t *)image >= ((uint8_t *)fsinfo->image + fsinfo->image_size))) {
goto not_found;
}

Expand Down
10 changes: 8 additions & 2 deletions source/component/fs/driver/romfs/vsf_romfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
#if VSF_USE_FS == ENABLED && VSF_FS_USE_ROMFS == ENABLED

#if defined(__VSF_ROMFS_CLASS_IMPLEMENT)
# undef __VSF_ROMFS_CLASS_IMPLEMENT
# define __VSF_CLASS_IMPLEMENT__
#elif defined(__VSF_ROMFS_CLASS_INHERIT__)
# undef __VSF_ROMFS_CLASS_INHERIT__
# define __VSF_CLASS_INHERIT__
#endif

Expand Down Expand Up @@ -85,9 +83,17 @@ extern const vk_fs_op_t vk_romfs_op;

/*============================ PROTOTYPES ====================================*/

#if defined(__VSF_ROMFS_CLASS_INHERIT__) || defined(__VSF_ROMFS_CLASS_IMPLEMENT)
extern bool vsf_romfs_is_image_valid(vk_romfs_header_t *image);
extern vk_romfs_header_t * vsf_romfs_chain_get_next(vk_romfs_header_t *image);
#endif

#ifdef __cplusplus
}
#endif

#undef __VSF_ROMFS_CLASS_IMPLEMENT
#undef __VSF_ROMFS_CLASS_INHERIT__

#endif // VSF_USE_FS && VSF_FS_USE_ROMFS
#endif // __VSF_ROMFS_H__

0 comments on commit 8c83be2

Please sign in to comment.