Kernel: Add API for RamDirectoryInodes to delete containing inodes

This commit is contained in:
Bananymous 2023-09-30 19:13:11 +03:00
parent e949e8550c
commit 8604c55de8
4 changed files with 25 additions and 0 deletions

View File

@ -89,6 +89,7 @@ namespace Kernel
BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode(BAN::StringView); BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode(BAN::StringView);
BAN::ErrorOr<void> list_next_inodes(off_t, DirectoryEntryList*, size_t); BAN::ErrorOr<void> list_next_inodes(off_t, DirectoryEntryList*, size_t);
BAN::ErrorOr<void> create_file(BAN::StringView, mode_t, uid_t, gid_t); BAN::ErrorOr<void> create_file(BAN::StringView, mode_t, uid_t, gid_t);
BAN::ErrorOr<void> delete_inode(BAN::StringView);
// Link API // Link API
BAN::ErrorOr<BAN::String> link_target(); BAN::ErrorOr<BAN::String> link_target();
@ -104,6 +105,7 @@ namespace Kernel
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_impl(BAN::StringView) { return BAN::Error::from_errno(ENOTSUP); } virtual BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_impl(BAN::StringView) { return BAN::Error::from_errno(ENOTSUP); }
virtual BAN::ErrorOr<void> list_next_inodes_impl(off_t, DirectoryEntryList*, size_t) { return BAN::Error::from_errno(ENOTSUP); } virtual BAN::ErrorOr<void> list_next_inodes_impl(off_t, DirectoryEntryList*, size_t) { return BAN::Error::from_errno(ENOTSUP); }
virtual BAN::ErrorOr<void> create_file_impl(BAN::StringView, mode_t, uid_t, gid_t) { return BAN::Error::from_errno(ENOTSUP); } virtual BAN::ErrorOr<void> create_file_impl(BAN::StringView, mode_t, uid_t, gid_t) { return BAN::Error::from_errno(ENOTSUP); }
virtual BAN::ErrorOr<void> delete_inode_impl(BAN::StringView) { return BAN::Error::from_errno(ENOTSUP); }
// Link API // Link API
virtual BAN::ErrorOr<BAN::String> link_target_impl() { return BAN::Error::from_errno(ENOTSUP); } virtual BAN::ErrorOr<BAN::String> link_target_impl() { return BAN::Error::from_errno(ENOTSUP); }

View File

@ -92,6 +92,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> delete_inode_impl(BAN::StringView) override;
private: private:
static constexpr size_t m_name_max = NAME_MAX; static constexpr size_t m_name_max = NAME_MAX;

View File

@ -84,6 +84,15 @@ namespace Kernel
return create_file_impl(name, mode, uid, gid); return create_file_impl(name, mode, uid, gid);
} }
BAN::ErrorOr<void> Inode::delete_inode(BAN::StringView name)
{
LockGuard _(m_lock);
Thread::TerminateBlocker blocker(Thread::current());
if (!mode().ifdir())
return BAN::Error::from_errno(ENOTDIR);
return delete_inode_impl(name);
}
BAN::ErrorOr<BAN::String> Inode::link_target() BAN::ErrorOr<BAN::String> Inode::link_target()
{ {
LockGuard _(m_lock); LockGuard _(m_lock);

View File

@ -227,6 +227,19 @@ namespace Kernel
return {}; return {};
} }
BAN::ErrorOr<void> RamDirectoryInode::delete_inode_impl(BAN::StringView name)
{
for (size_t i = 0; i < m_entries.size(); i++)
{
if (name == m_entries[i].name)
{
m_entries.remove(i);
return {};
}
}
return BAN::Error::from_errno(ENOENT);
}
/* /*
RAM SYMLINK INODE RAM SYMLINK INODE