From f0772e385c2b6c825ac399f3d1917b53297c1183 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 5 Sep 2023 00:58:49 +0300 Subject: [PATCH] Kernel: Implement basic RamSymlinkInode --- kernel/include/kernel/FS/RamFS/Inode.h | 20 ++++++++++++++ kernel/kernel/FS/RamFS/Inode.cpp | 36 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/kernel/include/kernel/FS/RamFS/Inode.h b/kernel/include/kernel/FS/RamFS/Inode.h index 2ff11efe35..2bf858f1b8 100644 --- a/kernel/include/kernel/FS/RamFS/Inode.h +++ b/kernel/include/kernel/FS/RamFS/Inode.h @@ -97,4 +97,24 @@ namespace Kernel friend class RamFileSystem; }; + class RamSymlinkInode final : public RamInode + { + public: + static BAN::ErrorOr> 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 link_target() override; + BAN::ErrorOr set_link_target(BAN::StringView); + + private: + RamSymlinkInode(RamFileSystem&, mode_t, uid_t, gid_t); + + private: + BAN::String m_target; + + friend class RamFileSystem; + }; + } \ No newline at end of file diff --git a/kernel/kernel/FS/RamFS/Inode.cpp b/kernel/kernel/FS/RamFS/Inode.cpp index 4870bdd075..936efb0364 100644 --- a/kernel/kernel/FS/RamFS/Inode.cpp +++ b/kernel/kernel/FS/RamFS/Inode.cpp @@ -214,4 +214,40 @@ namespace Kernel return {}; } + /* + + RAM SYMLINK INODE + + */ + + BAN::ErrorOr> 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::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 RamSymlinkInode::link_target() + { + BAN::String result; + TRY(result.append(m_target)); + return result; + } + + BAN::ErrorOr RamSymlinkInode::set_link_target(BAN::StringView target) + { + BAN::String temp; + TRY(temp.append(target)); + m_target = BAN::move(temp); + return {}; + } + } \ No newline at end of file