1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 13:44:58 +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:
Liav A 2024-01-05 11:18:02 +02:00 committed by Andrew Kaster
parent 75bd1308c5
commit a10e63f08e
16 changed files with 169 additions and 111 deletions

View file

@ -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>
@ -39,25 +40,7 @@ unsigned RAMFS::next_inode_index()
u8 RAMFS::internal_file_type_to_directory_entry_type(DirectoryEntryView const& entry) const
{
switch (static_cast<FileType>(entry.file_type)) {
case FileType::Directory:
return DT_DIR;
case FileType::Character:
return DT_CHR;
case FileType::Block:
return DT_BLK;
case FileType::Regular:
return DT_REG;
case FileType::FIFO:
return DT_FIFO;
case FileType::Link:
return DT_LNK;
case FileType::Socket:
return DT_SOCK;
case FileType::Unknown:
default:
return DT_UNKNOWN;
}
return ram_backed_file_type_to_directory_entry_type(entry);
}
}