From 3c35ea30cc9861bca3825a71706333d88916ec15 Mon Sep 17 00:00:00 2001 From: Liav A Date: Sun, 14 Mar 2021 23:26:33 +0200 Subject: [PATCH] Kernel: Return 0 to indicate EOF when reading from end-of-file of device If we happen to read with offset that is after the end of file of a device, return 0 to indicate EOF. If we return a negative value, userspace will think that something bad happened when it's really not the case. --- Kernel/FileSystem/DevFS.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel/FileSystem/DevFS.cpp b/Kernel/FileSystem/DevFS.cpp index b5be7f822d..f08587236a 100644 --- a/Kernel/FileSystem/DevFS.cpp +++ b/Kernel/FileSystem/DevFS.cpp @@ -362,7 +362,7 @@ ssize_t DevFSDeviceInode::read_bytes(off_t offset, ssize_t count, UserOrKernelBu LOCKER(m_lock); VERIFY(!!description); if (!m_attached_device->can_read(*description, offset)) - return -EIO; + return 0; auto nread = const_cast(*m_attached_device).read(*description, offset, buffer, count); if (nread.is_error()) return -EIO; @@ -388,7 +388,7 @@ ssize_t DevFSDeviceInode::write_bytes(off_t offset, ssize_t count, const UserOrK LOCKER(m_lock); VERIFY(!!description); if (!m_attached_device->can_write(*description, offset)) - return -EIO; + return 0; auto nread = const_cast(*m_attached_device).write(*description, offset, buffer, count); if (nread.is_error()) return -EIO;