mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 10:55:06 +00:00
Kernel: Make RAMFS pass along the inode type when traversing as a dir
RAMFS was passing 0, which lead to the userspace seeing all entries as DT_UNKNOWN when iterating over the directory contents. To repro prior to this commit, simply check `echo /tmp/*/`.
This commit is contained in:
parent
24a7df9b09
commit
b545427d53
3 changed files with 63 additions and 4 deletions
|
@ -5,6 +5,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/FileSystem/RAMFS/FileSystem.h>
|
||||
#include <Kernel/FileSystem/RAMFS/Inode.h>
|
||||
#include <Kernel/Tasks/Process.h>
|
||||
|
||||
|
@ -49,6 +50,28 @@ InodeMetadata RAMFSInode::metadata() const
|
|||
return m_metadata;
|
||||
}
|
||||
|
||||
static RAMFS::FileType file_type_from_mode(mode_t mode)
|
||||
{
|
||||
switch (mode & S_IFMT) {
|
||||
case S_IFDIR:
|
||||
return RAMFS::FileType::Directory;
|
||||
case S_IFCHR:
|
||||
return RAMFS::FileType::Character;
|
||||
case S_IFBLK:
|
||||
return RAMFS::FileType::Block;
|
||||
case S_IFREG:
|
||||
return RAMFS::FileType::Regular;
|
||||
case S_IFIFO:
|
||||
return RAMFS::FileType::FIFO;
|
||||
case S_IFLNK:
|
||||
return RAMFS::FileType::Link;
|
||||
case S_IFSOCK:
|
||||
return RAMFS::FileType::Socket;
|
||||
default:
|
||||
return RAMFS::FileType::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
ErrorOr<void> RAMFSInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
|
||||
{
|
||||
MutexLocker locker(m_inode_lock, Mutex::Mode::Shared);
|
||||
|
@ -56,15 +79,15 @@ ErrorOr<void> RAMFSInode::traverse_as_directory(Function<ErrorOr<void>(FileSyste
|
|||
if (!is_directory())
|
||||
return ENOTDIR;
|
||||
|
||||
TRY(callback({ "."sv, identifier(), 0 }));
|
||||
TRY(callback({ "."sv, identifier(), to_underlying(RAMFS::FileType::Directory) }));
|
||||
if (m_root_directory_inode) {
|
||||
TRY(callback({ ".."sv, identifier(), 0 }));
|
||||
TRY(callback({ ".."sv, identifier(), to_underlying(RAMFS::FileType::Directory) }));
|
||||
} else if (auto parent = m_parent.strong_ref()) {
|
||||
TRY(callback({ ".."sv, parent->identifier(), 0 }));
|
||||
TRY(callback({ ".."sv, parent->identifier(), to_underlying(RAMFS::FileType::Directory) }));
|
||||
}
|
||||
|
||||
for (auto& child : m_children) {
|
||||
TRY(callback({ child.name->view(), child.inode->identifier(), 0 }));
|
||||
TRY(callback({ child.name->view(), child.inode->identifier(), to_underlying(file_type_from_mode(child.inode->metadata().mode)) }));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue