1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 23:25:06 +00:00

Kernel: Tidy up Plan9FS construction a bit

This commit is contained in:
Andreas Kling 2021-09-06 11:17:53 +02:00
parent 36725228fa
commit d34f2b643e
3 changed files with 12 additions and 25 deletions

View file

@ -9,9 +9,9 @@
namespace Kernel {
NonnullRefPtr<Plan9FS> Plan9FS::create(FileDescription& file_description)
KResultOr<NonnullRefPtr<Plan9FS>> 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> Plan9FSInode::create(Plan9FS& fs, u32 fid)
KResultOr<NonnullRefPtr<Plan9FSInode>> 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<NonnullRefPtr<Inode>> 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<NonnullRefPtr<Inode>> Plan9FSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID)