2020-01-05 09:00:43 +01:00
|
|
|
#include <kernel/fs/smemfs.h>
|
2020-02-24 00:05:27 +01:00
|
|
|
#include <kernel/util/atomic.h>
|
2020-01-05 09:00:43 +01:00
|
|
|
|
2020-01-08 10:14:11 +01:00
|
|
|
/* smemfs_find_first_child() - Find the fist file in the (folder) inode (sync) */
|
2020-05-03 23:10:49 +02:00
|
|
|
void *smemfs_USB2_find_first_child(void *inode)
|
2020-01-05 09:00:43 +01:00
|
|
|
{
|
2020-05-04 23:47:09 +02:00
|
|
|
extern struct smemfs_USB2_superblock smemfs_USB2_superblock;
|
2020-01-07 10:12:45 +01:00
|
|
|
uint16_t folder_id;
|
2020-01-08 10:14:11 +01:00
|
|
|
void *child_inode;
|
2020-01-05 09:00:43 +01:00
|
|
|
|
|
|
|
// Check error.
|
|
|
|
if (inode == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2020-01-08 10:14:11 +01:00
|
|
|
// Start atomic operation
|
|
|
|
atomic_start();
|
|
|
|
|
2020-01-05 09:00:43 +01:00
|
|
|
// Check root inode
|
2020-05-04 23:47:09 +02:00
|
|
|
if (inode == smemfs_USB2_superblock.sector_table)
|
2020-01-05 09:00:43 +01:00
|
|
|
{
|
2020-01-07 10:12:45 +01:00
|
|
|
folder_id = CASIO_SMEM_ROOT_ID;
|
2020-01-05 09:00:43 +01:00
|
|
|
} else {
|
2020-01-07 10:12:45 +01:00
|
|
|
// Check inode validity
|
2020-01-08 10:14:11 +01:00
|
|
|
if (((struct casio_smem_header_s *)inode)->info != CASIO_SMEM_HEADER_INFO_EXIST ||
|
|
|
|
((struct casio_smem_header_s *)inode)->type != CASIO_SMEM_HEADER_TYPE_DIRECTORY)
|
|
|
|
{
|
|
|
|
atomic_stop();
|
2020-01-05 09:00:43 +01:00
|
|
|
return (NULL);
|
2020-01-08 10:14:11 +01:00
|
|
|
}
|
2020-01-05 09:00:43 +01:00
|
|
|
|
|
|
|
// Get directory ID
|
2020-01-07 10:12:45 +01:00
|
|
|
folder_id = ((struct casio_smem_header_s *)inode)->id;
|
2020-01-05 09:00:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the first child of the file.
|
2020-05-04 23:47:09 +02:00
|
|
|
child_inode = smemfs_USB2_walk(inode, smemfs_USB2_superblock.inode_table,
|
2020-01-08 10:14:11 +01:00
|
|
|
folder_id, WALK_FLAG_ID_CHECK_PARENT);
|
|
|
|
|
|
|
|
// Stop atomic operation
|
|
|
|
atomic_stop();
|
|
|
|
return (child_inode);
|
2020-01-05 09:00:43 +01:00
|
|
|
}
|