Kernel: Implement basic RamSymlinkInode

This commit is contained in:
Bananymous 2023-09-05 00:58:49 +03:00
parent 4a0652684c
commit 35fd30ee29
2 changed files with 56 additions and 0 deletions

View File

@ -97,4 +97,24 @@ namespace Kernel
friend class RamFileSystem;
};
class RamSymlinkInode final : public RamInode
{
public:
static BAN::ErrorOr<BAN::RefPtr<RamSymlinkInode>> create(RamFileSystem&, BAN::StringView target, mode_t, uid_t, gid_t);
~RamSymlinkInode() = default;
virtual off_t size() const override { return m_target.size(); }
virtual BAN::ErrorOr<BAN::String> link_target() override;
BAN::ErrorOr<void> set_link_target(BAN::StringView);
private:
RamSymlinkInode(RamFileSystem&, mode_t, uid_t, gid_t);
private:
BAN::String m_target;
friend class RamFileSystem;
};
}

View File

@ -214,4 +214,40 @@ namespace Kernel
return {};
}
/*
RAM SYMLINK INODE
*/
BAN::ErrorOr<BAN::RefPtr<RamSymlinkInode>> RamSymlinkInode::create(RamFileSystem& fs, BAN::StringView target, mode_t mode, uid_t uid, gid_t gid)
{
ASSERT(Mode{ mode }.iflnk());
auto* ram_inode = new RamSymlinkInode(fs, mode, uid, gid);
if (ram_inode == nullptr)
return BAN::Error::from_errno(ENOMEM);
auto ref_ptr = BAN::RefPtr<RamSymlinkInode>::adopt(ram_inode);
TRY(ref_ptr->set_link_target(target));
return ref_ptr;
}
RamSymlinkInode::RamSymlinkInode(RamFileSystem& fs, mode_t mode, uid_t uid, gid_t gid)
: RamInode(fs, mode, uid, gid)
{ }
BAN::ErrorOr<BAN::String> RamSymlinkInode::link_target()
{
BAN::String result;
TRY(result.append(m_target));
return result;
}
BAN::ErrorOr<void> RamSymlinkInode::set_link_target(BAN::StringView target)
{
BAN::String temp;
TRY(temp.append(target));
m_target = BAN::move(temp);
return {};
}
}