From 97ee370ffe43ae6af41f60324210dc71c95ee6aa Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 17 Sep 2024 15:51:40 +0300 Subject: [PATCH] Kernel: Allow listing files even if one of directories blocks are empty --- kernel/kernel/FS/Ext2/Inode.cpp | 3 +++ kernel/kernel/FS/TmpFS/Inode.cpp | 2 ++ kernel/kernel/OpenFileDescriptorSet.cpp | 8 +++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/kernel/FS/Ext2/Inode.cpp b/kernel/kernel/FS/Ext2/Inode.cpp index efd6d543..d8d49923 100644 --- a/kernel/kernel/FS/Ext2/Inode.cpp +++ b/kernel/kernel/FS/Ext2/Inode.cpp @@ -331,6 +331,9 @@ done: return BAN::Error::from_errno(ENOBUFS); } + if (entry_count == 0) + return BAN::Error::from_errno(ENODATA); + // Second fill the list { dirent* dirp = list; diff --git a/kernel/kernel/FS/TmpFS/Inode.cpp b/kernel/kernel/FS/TmpFS/Inode.cpp index 4fff2bfe..50faabd7 100644 --- a/kernel/kernel/FS/TmpFS/Inode.cpp +++ b/kernel/kernel/FS/TmpFS/Inode.cpp @@ -475,6 +475,8 @@ namespace Kernel } }); + if (entry_count == 0) + return BAN::Error::from_errno(ENODATA); return entry_count; } diff --git a/kernel/kernel/OpenFileDescriptorSet.cpp b/kernel/kernel/OpenFileDescriptorSet.cpp index aff0a38e..43c15846 100644 --- a/kernel/kernel/OpenFileDescriptorSet.cpp +++ b/kernel/kernel/OpenFileDescriptorSet.cpp @@ -327,7 +327,13 @@ namespace Kernel auto& open_file = m_open_files[fd]; if (!(open_file->flags & O_RDONLY)) return BAN::Error::from_errno(EACCES); - return TRY(open_file->inode()->list_next_inodes(open_file->offset++, list, list_len)); + for (;;) + { + auto ret = open_file->inode()->list_next_inodes(open_file->offset++, list, list_len); + if (ret.is_error() && ret.error().get_error_code() == ENODATA) + continue; + return ret; + } } BAN::ErrorOr OpenFileDescriptorSet::file_of(int fd) const