diff --git a/Kernel/FileSystem/Plan9FileSystem.cpp b/Kernel/FileSystem/Plan9FileSystem.cpp index ed6bbbf40f5..71c334a04d4 100644 --- a/Kernel/FileSystem/Plan9FileSystem.cpp +++ b/Kernel/FileSystem/Plan9FileSystem.cpp @@ -9,9 +9,9 @@ namespace Kernel { -NonnullRefPtr Plan9FS::create(FileDescription& file_description) +KResultOr> Plan9FS::try_create(FileDescription& file_description) { - return adopt_ref(*new Plan9FS(file_description)); + return adopt_nonnull_ref_or_enomem(new (nothrow) Plan9FS(file_description)); } Plan9FS::Plan9FS(FileDescription& file_description) @@ -202,9 +202,7 @@ KResult Plan9FS::initialize() Message version_message { *this, Message::Type::Tversion }; version_message << (u32)m_max_message_size << "9P2000.L"; - auto result = post_message_and_wait_for_a_reply(version_message); - if (result.is_error()) - return result; + TRY(post_message_and_wait_for_a_reply(version_message)); u32 msize; StringView remote_protocol_version; @@ -224,15 +222,8 @@ KResult Plan9FS::initialize() if (m_remote_protocol_version >= ProtocolVersion::v9P2000u) attach_message << (u32)-1; - result = post_message_and_wait_for_a_reply(attach_message); - if (result.is_error()) { - dbgln("Attaching failed"); - return result; - } - - m_root_inode = Plan9FSInode::create(*this, root_fid); - if (!m_root_inode) - return ENOMEM; + TRY(post_message_and_wait_for_a_reply(attach_message)); + m_root_inode = TRY(Plan9FSInode::try_create(*this, root_fid)); return KSuccess; } @@ -685,9 +676,9 @@ Plan9FSInode::Plan9FSInode(Plan9FS& fs, u32 fid) { } -NonnullRefPtr Plan9FSInode::create(Plan9FS& fs, u32 fid) +KResultOr> Plan9FSInode::try_create(Plan9FS& fs, u32 fid) { - return adopt_ref(*new Plan9FSInode(fs, fid)); + return adopt_nonnull_ref_or_enomem(new (nothrow) Plan9FSInode(fs, fid)); } Plan9FSInode::~Plan9FSInode() @@ -927,12 +918,8 @@ KResultOr> Plan9FSInode::lookup(StringView name) u32 newfid = fs().allocate_fid(); Plan9FS::Message message { fs(), Plan9FS::Message::Type::Twalk }; message << fid() << newfid << (u16)1 << name; - auto result = fs().post_message_and_wait_for_a_reply(message); - - if (result.is_error()) - return result; - - return Plan9FSInode::create(fs(), newfid); + TRY(fs().post_message_and_wait_for_a_reply(message)); + return TRY(Plan9FSInode::try_create(fs(), newfid)); } KResultOr> Plan9FSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID) diff --git a/Kernel/FileSystem/Plan9FileSystem.h b/Kernel/FileSystem/Plan9FileSystem.h index b5b3f4ba6bd..7cb964207ba 100644 --- a/Kernel/FileSystem/Plan9FileSystem.h +++ b/Kernel/FileSystem/Plan9FileSystem.h @@ -20,7 +20,7 @@ class Plan9FS final : public FileBackedFileSystem { public: virtual ~Plan9FS() override; - static NonnullRefPtr create(FileDescription&); + static KResultOr> try_create(FileDescription&); virtual KResult initialize() override; @@ -169,7 +169,7 @@ public: private: Plan9FSInode(Plan9FS&, u32 fid); - static NonnullRefPtr create(Plan9FS&, u32 fid); + static KResultOr> try_create(Plan9FS&, u32 fid); enum class GetAttrMask : u64 { Mode = 0x1, diff --git a/Kernel/Syscalls/mount.cpp b/Kernel/Syscalls/mount.cpp index 8844ba62bc5..aa28dfb520c 100644 --- a/Kernel/Syscalls/mount.cpp +++ b/Kernel/Syscalls/mount.cpp @@ -77,7 +77,7 @@ KResultOr Process::sys$mount(Userspace if (description_or_error.is_error()) return EBADF; auto description = description_or_error.release_value(); - fs = Plan9FS::create(*description); + fs = TRY(Plan9FS::try_create(*description)); } else if (fs_type == "proc"sv || fs_type == "ProcFS"sv) { fs = TRY(ProcFS::try_create()); } else if (fs_type == "devpts"sv || fs_type == "DevPtsFS"sv) {