diff options
author | Andreas Kling <kling@serenityos.org> | 2021-05-13 09:08:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-13 23:28:40 +0200 |
commit | e46343bf9aadaf8b310821c8a92b131f2b726654 (patch) | |
tree | 4d027e4b413e82b8482865c8a8c3d9b37cdaa0ca /Kernel/FileSystem | |
parent | 25a45e639ac48bc75507f003c692f24310688e9b (diff) | |
download | serenity-e46343bf9aadaf8b310821c8a92b131f2b726654.zip |
Kernel: Make UserOrKernelBuffer R/W helpers return KResultOr<size_t>
This makes error propagation less cumbersome (and also exposed some
places where we were not doing it.)
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r-- | Kernel/FileSystem/InodeWatcher.cpp | 8 | ||||
-rw-r--r-- | Kernel/FileSystem/ProcFS.cpp | 10 |
2 files changed, 8 insertions, 10 deletions
diff --git a/Kernel/FileSystem/InodeWatcher.cpp b/Kernel/FileSystem/InodeWatcher.cpp index fb7c36739a..29be55b502 100644 --- a/Kernel/FileSystem/InodeWatcher.cpp +++ b/Kernel/FileSystem/InodeWatcher.cpp @@ -48,7 +48,7 @@ KResultOr<size_t> InodeWatcher::read(FileDescription&, u64, UserOrKernelBuffer& if (buffer_size < bytes_to_write) return EINVAL; - ssize_t nwritten = buffer.write_buffered<MAXIMUM_EVENT_SIZE>(bytes_to_write, [&](u8* data, size_t data_bytes) { + auto result = buffer.write_buffered<MAXIMUM_EVENT_SIZE>(bytes_to_write, [&](u8* data, size_t data_bytes) { size_t offset = 0; memcpy(data + offset, &event.wd, sizeof(InodeWatcherEvent::watch_descriptor)); @@ -64,12 +64,10 @@ KResultOr<size_t> InodeWatcher::read(FileDescription&, u64, UserOrKernelBuffer& memset(data + offset, 0, sizeof(InodeWatcherEvent::name_length)); } - return (ssize_t)data_bytes; + return data_bytes; }); - if (nwritten < 0) - return KResult((ErrnoCode)-nwritten); evaluate_block_conditions(); - return bytes_to_write; + return result; } KResult InodeWatcher::close() diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 07789b904a..777bb5b936 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -903,17 +903,17 @@ static ssize_t write_sys_bool(InodeIdentifier inode_id, const UserOrKernelBuffer char value = 0; bool did_read = false; - ssize_t nread = buffer.read_buffered<1>(1, [&](const u8* data, size_t) { + auto result = buffer.read_buffered<1>(1, [&](u8 const* data, size_t) { if (did_read) return 0; value = (char)data[0]; did_read = true; return 1; }); - if (nread < 0) - return nread; - VERIFY(nread == 0 || (nread == 1 && did_read)); - if (nread == 0 || !(value == '0' || value == '1')) + if (result.is_error()) + return result.error(); + VERIFY(result.value() == 0 || (result.value() == 1 && did_read)); + if (result.value() == 0 || !(value == '0' || value == '1')) return (ssize_t)size; auto* lockable_bool = reinterpret_cast<Lockable<bool>*>(variable.address); |