2020-01-05 09:00:43 +01:00
|
|
|
#include <kernel/fs/smemfs.h>
|
|
|
|
|
2020-01-07 10:12:45 +01:00
|
|
|
/* smemfs_walk() - Find inode based on directory ID and flags */
|
2020-01-08 10:14:11 +01:00
|
|
|
/* @note: This function is internal of smemFS, do not call it ! */
|
2020-01-07 10:12:45 +01:00
|
|
|
smemfs_inode_t *smemfs_walk(smemfs_inode_t *current,
|
|
|
|
smemfs_inode_t *entry, uint16_t folder_id, int flags)
|
2020-01-05 09:00:43 +01:00
|
|
|
{
|
2020-01-07 10:12:45 +01:00
|
|
|
smemfs_fragdata_t *fragdata;
|
2020-01-05 09:00:43 +01:00
|
|
|
|
|
|
|
// Check current inode validity.
|
2020-01-07 10:12:45 +01:00
|
|
|
if (entry == NULL)
|
2020-01-05 09:00:43 +01:00
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
// Walk entry
|
2020-01-07 10:12:45 +01:00
|
|
|
while (entry->info == CASIO_SMEM_HEADER_INFO_EXIST ||
|
|
|
|
entry->info == CASIO_SMEM_HEADER_INFO_DELETE)
|
2020-01-05 09:00:43 +01:00
|
|
|
{
|
|
|
|
// New inode validity check.
|
2020-01-07 10:12:45 +01:00
|
|
|
if (entry != current &&
|
|
|
|
entry->info == CASIO_SMEM_HEADER_INFO_EXIST &&
|
|
|
|
(((flags & WALK_FLAG_ID_CHECK_PARENT) != 0 && entry->parent.id == folder_id) ||
|
|
|
|
((flags & WALK_FLAG_ID_CHECK_PARENT) == 0 && entry->id == folder_id)))
|
2020-01-05 09:00:43 +01:00
|
|
|
{
|
2020-01-07 10:12:45 +01:00
|
|
|
return (entry);
|
2020-01-05 09:00:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fast fragmentation skip
|
2020-01-07 10:12:45 +01:00
|
|
|
fragdata = (void *)((uint32_t)(entry) + sizeof(struct casio_smem_header_s));
|
|
|
|
if (fragdata->magic == CASIO_SMEM_FRAGMENT_MAGIC)
|
2020-01-05 09:00:43 +01:00
|
|
|
{
|
2020-01-07 10:12:45 +01:00
|
|
|
fragdata = (void *)((uint32_t)fragdata +
|
|
|
|
(sizeof(struct casio_smem_fragment_s) * fragdata->frag_total));
|
2020-01-05 09:00:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update current inode
|
2020-01-07 10:12:45 +01:00
|
|
|
entry = (void*)fragdata;
|
2020-01-05 09:00:43 +01:00
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|