From 51cd951b4ca3854c2b944ba7dc77a19ced756c32 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 27 Aug 2025 00:46:24 +0300 Subject: [PATCH] Kernel: Add hardlink support to tmpfs --- kernel/include/kernel/FS/TmpFS/Inode.h | 1 + kernel/kernel/FS/TmpFS/Inode.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/kernel/include/kernel/FS/TmpFS/Inode.h b/kernel/include/kernel/FS/TmpFS/Inode.h index 5c4bb69f..606da429 100644 --- a/kernel/include/kernel/FS/TmpFS/Inode.h +++ b/kernel/include/kernel/FS/TmpFS/Inode.h @@ -156,6 +156,7 @@ namespace Kernel virtual BAN::ErrorOr list_next_inodes_impl(off_t, struct dirent*, size_t) override final; virtual BAN::ErrorOr create_file_impl(BAN::StringView, mode_t, uid_t, gid_t) override final; virtual BAN::ErrorOr create_directory_impl(BAN::StringView, mode_t, uid_t, gid_t) override final; + virtual BAN::ErrorOr link_inode_impl(BAN::StringView, BAN::RefPtr) override final; virtual BAN::ErrorOr unlink_impl(BAN::StringView) override; virtual bool can_read_impl() const override { return false; } diff --git a/kernel/kernel/FS/TmpFS/Inode.cpp b/kernel/kernel/FS/TmpFS/Inode.cpp index b8b3f44f..579426cd 100644 --- a/kernel/kernel/FS/TmpFS/Inode.cpp +++ b/kernel/kernel/FS/TmpFS/Inode.cpp @@ -655,6 +655,20 @@ namespace Kernel return {}; } + BAN::ErrorOr TmpDirectoryInode::link_inode_impl(BAN::StringView name, BAN::RefPtr inode) + { + ASSERT(this->mode().ifdir()); + ASSERT(!inode->mode().ifdir()); + ASSERT(&m_fs == inode->filesystem()); + + if (!find_inode_impl(name).is_error()) + return BAN::Error::from_errno(EEXIST); + + auto* tmp_inode = static_cast(inode.ptr()); + TRY(link_inode(*tmp_inode, name)); + return {}; + } + BAN::ErrorOr TmpDirectoryInode::unlink_impl(BAN::StringView name) { ino_t entry_ino = 0;