Kernel: Implement directory creation for RamFS

This commit is contained in:
Bananymous 2023-10-25 19:41:34 +03:00
parent e85f9ac6a1
commit 1f794e4ac0
2 changed files with 11 additions and 3 deletions

View File

@ -96,6 +96,7 @@ namespace Kernel
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_impl(BAN::StringView) override;
virtual BAN::ErrorOr<void> list_next_inodes_impl(off_t, DirectoryEntryList*, size_t) override;
virtual BAN::ErrorOr<void> create_file_impl(BAN::StringView, mode_t, uid_t, gid_t) override;
virtual BAN::ErrorOr<void> create_directory_impl(BAN::StringView, mode_t, uid_t, gid_t) override;
virtual BAN::ErrorOr<void> delete_inode_impl(BAN::StringView) override;
private:

View File

@ -202,16 +202,23 @@ namespace Kernel
BAN::RefPtr<RamInode> inode;
if (Mode(mode).ifreg())
inode = TRY(RamFileInode::create(m_fs, mode & ~Inode::Mode::TYPE_MASK, uid, gid));
else if (Mode(mode).ifdir())
inode = TRY(RamDirectoryInode::create(m_fs, ino(), mode & ~Inode::Mode::TYPE_MASK, uid, gid));
else
ASSERT_NOT_REACHED();
return BAN::Error::from_errno(ENOTSUP);
TRY(add_inode(name, inode));
return {};
}
BAN::ErrorOr<void> RamDirectoryInode::create_directory_impl(BAN::StringView name, mode_t mode, uid_t uid, gid_t gid)
{
if (!Mode(mode).ifdir())
return BAN::Error::from_errno(EINVAL);
auto inode = TRY(RamDirectoryInode::create(m_fs, ino(), mode & ~Inode::Mode::TYPE_MASK, uid, gid));
TRY(add_inode(name, inode));
return {};
}
static uint8_t get_type(Inode::Mode mode)
{
if (mode.ifreg())