summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r--Kernel/FileSystem/Custody.cpp25
-rw-r--r--Kernel/FileSystem/DevFS.cpp13
-rw-r--r--Kernel/FileSystem/SysFSComponent.cpp2
-rw-r--r--Kernel/FileSystem/TmpFS.cpp7
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.cpp4
5 files changed, 16 insertions, 35 deletions
diff --git a/Kernel/FileSystem/Custody.cpp b/Kernel/FileSystem/Custody.cpp
index 0875f9c828..7e77e514cb 100644
--- a/Kernel/FileSystem/Custody.cpp
+++ b/Kernel/FileSystem/Custody.cpp
@@ -33,15 +33,10 @@ KResultOr<NonnullRefPtr<Custody>> Custody::try_create(Custody* parent, StringVie
}
}
- auto name_kstring = KString::try_create(name);
- if (!name_kstring)
- return ENOMEM;
- auto custody = adopt_ref_if_nonnull(new (nothrow) Custody(parent, name_kstring.release_nonnull(), inode, mount_flags));
- if (!custody)
- return ENOMEM;
-
+ auto name_kstring = TRY(KString::try_create(name));
+ auto custody = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Custody(parent, move(name_kstring), inode, mount_flags)));
all_custodies.prepend(*custody);
- return custody.release_nonnull();
+ return custody;
});
}
@@ -73,12 +68,8 @@ Custody::~Custody()
KResultOr<NonnullOwnPtr<KString>> Custody::try_serialize_absolute_path() const
{
- if (!parent()) {
- auto string = KString::try_create("/"sv);
- if (!string)
- return ENOMEM;
- return string.release_nonnull();
- }
+ if (!parent())
+ return KString::try_create("/"sv);
Vector<Custody const*, 32> custody_chain;
size_t path_length = 0;
@@ -89,9 +80,7 @@ KResultOr<NonnullOwnPtr<KString>> Custody::try_serialize_absolute_path() const
VERIFY(path_length > 0);
char* buffer;
- auto string = KString::try_create_uninitialized(path_length - 1, buffer);
- if (!string)
- return ENOMEM;
+ auto string = TRY(KString::try_create_uninitialized(path_length - 1, buffer));
size_t string_index = 0;
for (size_t custody_index = custody_chain.size() - 1; custody_index > 0; --custody_index) {
buffer[string_index] = '/';
@@ -102,7 +91,7 @@ KResultOr<NonnullOwnPtr<KString>> Custody::try_serialize_absolute_path() const
}
VERIFY(string->length() == string_index);
buffer[string_index] = 0;
- return string.release_nonnull();
+ return string;
}
String Custody::absolute_path() const
diff --git a/Kernel/FileSystem/DevFS.cpp b/Kernel/FileSystem/DevFS.cpp
index d3cba22692..841197c216 100644
--- a/Kernel/FileSystem/DevFS.cpp
+++ b/Kernel/FileSystem/DevFS.cpp
@@ -21,11 +21,10 @@ DevFS::DevFS()
void DevFS::notify_new_device(Device& device)
{
- auto name = KString::try_create(device.device_name());
- VERIFY(name);
-
+ // FIXME: Handle KString allocation failure.
+ auto name = KString::try_create(device.device_name()).release_value();
MutexLocker locker(m_lock);
- auto new_device_inode = adopt_ref(*new DevFSDeviceInode(*this, device, name.release_nonnull()));
+ auto new_device_inode = adopt_ref(*new DevFSDeviceInode(*this, device, move(name)));
m_nodes.append(new_device_inode);
m_root_inode->m_devices.append(new_device_inode);
}
@@ -276,10 +275,8 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(StringView
if (link.name() == name)
return EEXIST;
}
- auto name_kstring = KString::try_create(name);
- if (!name_kstring)
- return ENOMEM;
- auto new_link_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevFSLinkInode(fs(), name_kstring.release_nonnull())));
+ auto name_kstring = TRY(KString::try_create(name));
+ auto new_link_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevFSLinkInode(fs(), move(name_kstring))));
if (!m_links.try_ensure_capacity(m_links.size() + 1))
return ENOMEM;
if (!fs().m_nodes.try_ensure_capacity(fs().m_nodes.size() + 1))
diff --git a/Kernel/FileSystem/SysFSComponent.cpp b/Kernel/FileSystem/SysFSComponent.cpp
index 7bf0278619..1df44166b3 100644
--- a/Kernel/FileSystem/SysFSComponent.cpp
+++ b/Kernel/FileSystem/SysFSComponent.cpp
@@ -21,7 +21,7 @@ static size_t allocate_inode_index()
}
SysFSComponent::SysFSComponent(StringView name)
- : m_name(KString::try_create(name).release_nonnull())
+ : m_name(KString::try_create(name).release_value()) // FIXME: Handle KString allocation failure.
, m_component_index(allocate_inode_index())
{
}
diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp
index 6c6339a99b..d752d6c1e0 100644
--- a/Kernel/FileSystem/TmpFS.cpp
+++ b/Kernel/FileSystem/TmpFS.cpp
@@ -282,11 +282,8 @@ KResult TmpFSInode::add_child(Inode& child, StringView const& name, mode_t)
if (name.length() > NAME_MAX)
return ENAMETOOLONG;
- auto name_kstring = KString::try_create(name);
- if (!name_kstring)
- return ENOMEM;
-
- auto* child_entry = new (nothrow) Child { name_kstring.release_nonnull(), static_cast<TmpFSInode&>(child) };
+ auto name_kstring = TRY(KString::try_create(name));
+ auto* child_entry = new (nothrow) Child { move(name_kstring), static_cast<TmpFSInode&>(child) };
if (!child_entry)
return ENOMEM;
diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp
index 3b456f8075..a0a9756633 100644
--- a/Kernel/FileSystem/VirtualFileSystem.cpp
+++ b/Kernel/FileSystem/VirtualFileSystem.cpp
@@ -323,9 +323,7 @@ KResultOr<NonnullRefPtr<FileDescription>> VirtualFileSystem::create(StringView p
{
auto basename = KLexicalPath::basename(path);
auto parent_path = TRY(parent_custody.try_serialize_absolute_path());
- auto full_path = KLexicalPath::try_join(parent_path->view(), basename);
- if (!full_path)
- return ENOMEM;
+ auto full_path = TRY(KLexicalPath::try_join(parent_path->view(), basename));
TRY(validate_path_against_process_veil(full_path->view(), options));
if (!is_socket(mode) && !is_fifo(mode) && !is_block_device(mode) && !is_character_device(mode)) {