Kernel: Implement directory creation for RamFS

This commit is contained in:
Bananymous 2023-10-25 19:41:34 +03:00
parent 4ee2f0f789
commit e9b7cf332d
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<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> 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_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; virtual BAN::ErrorOr<void> delete_inode_impl(BAN::StringView) override;
private: private:

View File

@ -202,16 +202,23 @@ namespace Kernel
BAN::RefPtr<RamInode> inode; BAN::RefPtr<RamInode> inode;
if (Mode(mode).ifreg()) if (Mode(mode).ifreg())
inode = TRY(RamFileInode::create(m_fs, mode & ~Inode::Mode::TYPE_MASK, uid, gid)); 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 else
ASSERT_NOT_REACHED(); return BAN::Error::from_errno(ENOTSUP);
TRY(add_inode(name, inode)); TRY(add_inode(name, inode));
return {}; 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) static uint8_t get_type(Inode::Mode mode)
{ {
if (mode.ifreg()) if (mode.ifreg())