mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 13:35:00 +00:00
Kernel/FileSystem: Send proper filetypes when traversing RAM-backed FSes
SysFS, ProcFS and DevPtsFS were all sending filetype 0 when traversing their directories, but it is actually very easy to send proper filetypes in these filesystems. This patch binds all RAM backed filesystems to use only one enum for their internal filetype, to simplify the implementation and allow sharing of code. Please note that the Plan9FS case is currently not solved as I am not familiar with this filesystem and its constructs. The ProcFS mostly keeps track of the filetype, and a fix was needed for the /proc root directory - all processes exhibit a directory inside it which makes it very easy to hardcode the directory filetype for them. There's also the `self` symlink inode which is now exposed as DT_LNK. As for SysFS, we could leverage the fact everything inherits from the SysFSComponent class, so we could have a virtual const method to return the proper filetype. Most of the files in SysFS are "regular" files though, so the base class has a non-pure virtual method. Lastly, the DevPtsFS simply hardcodes '.' and '..' as directory file type, and everything else is hardcoded to send the character device file type, as this filesystem is only exposing character pts device files.
This commit is contained in:
parent
75bd1308c5
commit
a10e63f08e
16 changed files with 169 additions and 111 deletions
|
@ -1,10 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
|
||||
* Copyright (c) 2022-2024, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/FileSystem/RAMBackedFileType.h>
|
||||
#include <Kernel/FileSystem/RAMFS/FileSystem.h>
|
||||
#include <Kernel/FileSystem/RAMFS/Inode.h>
|
||||
#include <Kernel/Tasks/Process.h>
|
||||
|
@ -50,28 +51,6 @@ 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);
|
||||
|
@ -79,15 +58,15 @@ ErrorOr<void> RAMFSInode::traverse_as_directory(Function<ErrorOr<void>(FileSyste
|
|||
if (!is_directory())
|
||||
return ENOTDIR;
|
||||
|
||||
TRY(callback({ "."sv, identifier(), to_underlying(RAMFS::FileType::Directory) }));
|
||||
TRY(callback({ "."sv, identifier(), to_underlying(RAMBackedFileType::Directory) }));
|
||||
if (m_root_directory_inode) {
|
||||
TRY(callback({ ".."sv, identifier(), to_underlying(RAMFS::FileType::Directory) }));
|
||||
TRY(callback({ ".."sv, identifier(), to_underlying(RAMBackedFileType::Directory) }));
|
||||
} else if (auto parent = m_parent.strong_ref()) {
|
||||
TRY(callback({ ".."sv, parent->identifier(), to_underlying(RAMFS::FileType::Directory) }));
|
||||
TRY(callback({ ".."sv, parent->identifier(), to_underlying(RAMBackedFileType::Directory) }));
|
||||
}
|
||||
|
||||
for (auto& child : m_children) {
|
||||
TRY(callback({ child.name->view(), child.inode->identifier(), to_underlying(file_type_from_mode(child.inode->metadata().mode)) }));
|
||||
TRY(callback({ child.name->view(), child.inode->identifier(), to_underlying(ram_backed_file_type_from_mode(child.inode->metadata().mode)) }));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue