From 7a3ab6c517649e9dfdd50085f10492212b0bcb18 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 4 Aug 2020 18:02:23 +0200 Subject: Kernel: Make File::write() and File::read() return KResultOr Instead of returning a ssize_t where negative values mean error, we now return KResultOr and use the error state to report errors exclusively. --- Kernel/FileSystem/InodeFile.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Kernel/FileSystem/InodeFile.cpp') diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index 6bbb9e5873..c2657fe969 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -44,21 +44,25 @@ InodeFile::~InodeFile() { } -ssize_t InodeFile::read(FileDescription& description, size_t offset, u8* buffer, ssize_t count) +KResultOr InodeFile::read(FileDescription& description, size_t offset, u8* buffer, size_t count) { ssize_t nread = m_inode->read_bytes(offset, count, buffer, &description); if (nread > 0) Thread::current()->did_file_read(nread); + if (nread < 0) + return KResult(nread); return nread; } -ssize_t InodeFile::write(FileDescription& description, size_t offset, const u8* data, ssize_t count) +KResultOr InodeFile::write(FileDescription& description, size_t offset, const u8* data, size_t count) { ssize_t nwritten = m_inode->write_bytes(offset, count, data, &description); if (nwritten > 0) { m_inode->set_mtime(kgettimeofday().tv_sec); Thread::current()->did_file_write(nwritten); } + if (nwritten < 0) + return KResult(nwritten); return nwritten; } -- cgit v1.2.3