Vhex-kernel/src/kernel/fs/smemfs/inode/walk.c

39 lines
1.1 KiB
C
Raw Normal View History

#include <kernel/fs/smemfs.h>
2020-01-07 10:12:45 +01:00
/* smemfs_walk() - Find inode based on directory ID and flags */
smemfs_inode_t *smemfs_walk(smemfs_inode_t *current,
smemfs_inode_t *entry, uint16_t folder_id, int flags)
{
2020-01-07 10:12:45 +01:00
smemfs_fragdata_t *fragdata;
// Check current inode validity.
2020-01-07 10:12:45 +01:00
if (entry == NULL)
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)
{
// 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-07 10:12:45 +01:00
return (entry);
}
// 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-07 10:12:45 +01:00
fragdata = (void *)((uint32_t)fragdata +
(sizeof(struct casio_smem_fragment_s) * fragdata->frag_total));
}
// Update current inode
2020-01-07 10:12:45 +01:00
entry = (void*)fragdata;
}
return (NULL);
}