summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-05-11 04:13:04 -0700
committerAndreas Kling <kling@serenityos.org>2021-05-13 08:29:01 +0200
commita643ee5759af8f45d34f332e160c224fca92233e (patch)
tree7becc2dec2cddf06da4f50e8419b097b7bfa9946 /Kernel/FileSystem
parent12ab0dcee01bb3c3ace9924ef6f2c407f46f16b5 (diff)
downloadserenity-a643ee5759af8f45d34f332e160c224fca92233e.zip
Kernel: Move FileDescription::get_dir_entries to KResultOr<ssize_t>
This normalizes the error handling with the rest of the subsystem.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r--Kernel/FileSystem/FileDescription.cpp14
-rw-r--r--Kernel/FileSystem/FileDescription.h2
2 files changed, 8 insertions, 8 deletions
diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp
index 5d14f6f6dc..46ffbca86b 100644
--- a/Kernel/FileSystem/FileDescription.cpp
+++ b/Kernel/FileSystem/FileDescription.cpp
@@ -202,21 +202,21 @@ KResultOr<NonnullOwnPtr<KBuffer>> FileDescription::read_entire_file()
return m_inode->read_entire(this);
}
-ssize_t FileDescription::get_dir_entries(UserOrKernelBuffer& output_buffer, ssize_t size)
+KResultOr<ssize_t> FileDescription::get_dir_entries(UserOrKernelBuffer& output_buffer, ssize_t size)
{
Locker locker(m_lock, Lock::Mode::Shared);
if (!is_directory())
- return -ENOTDIR;
+ return ENOTDIR;
auto metadata = this->metadata();
if (!metadata.is_valid())
- return -EIO;
+ return EIO;
if (size < 0)
- return -EINVAL;
+ return EINVAL;
size_t remaining = size;
- ssize_t error = 0;
+ KResult error = KSuccess;
u8 stack_buffer[PAGE_SIZE];
Bytes temp_buffer(stack_buffer, sizeof(stack_buffer));
OutputMemoryStream stream { temp_buffer };
@@ -227,10 +227,10 @@ ssize_t FileDescription::get_dir_entries(UserOrKernelBuffer& output_buffer, ssiz
if (stream.size() == 0)
return true;
if (remaining < stream.size()) {
- error = -EINVAL;
+ error = EINVAL;
return false;
} else if (!output_buffer.write(stream.bytes())) {
- error = -EFAULT;
+ error = EFAULT;
return false;
}
output_buffer = output_buffer.offset(stream.size());
diff --git a/Kernel/FileSystem/FileDescription.h b/Kernel/FileSystem/FileDescription.h
index 47efdec69c..8be270218d 100644
--- a/Kernel/FileSystem/FileDescription.h
+++ b/Kernel/FileSystem/FileDescription.h
@@ -56,7 +56,7 @@ public:
bool can_read() const;
bool can_write() const;
- ssize_t get_dir_entries(UserOrKernelBuffer& buffer, ssize_t);
+ KResultOr<ssize_t> get_dir_entries(UserOrKernelBuffer& buffer, ssize_t);
KResultOr<NonnullOwnPtr<KBuffer>> read_entire_file();