forked from Bananymous/banan-os
Kernel: Implement basic RamSymlinkInode
This commit is contained in:
parent
4a0652684c
commit
35fd30ee29
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
|
@ -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 {};
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue