mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 17:25:07 +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,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
||||
* Copyright (c) 2021-2024, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -15,6 +15,7 @@
|
|||
#include <Kernel/FileSystem/File.h>
|
||||
#include <Kernel/FileSystem/FileSystem.h>
|
||||
#include <Kernel/FileSystem/OpenFileDescription.h>
|
||||
#include <Kernel/FileSystem/RAMBackedFileType.h>
|
||||
#include <Kernel/Forward.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
@ -28,6 +29,10 @@ class SysFSComponent : public AtomicRefCounted<SysFSComponent> {
|
|||
friend class SysFSDirectory;
|
||||
|
||||
public:
|
||||
// NOTE: It is safe to assume that the regular file type is largely
|
||||
// the most used file type in the SysFS filesystem.
|
||||
virtual RAMBackedFileType type() const { return RAMBackedFileType::Regular; }
|
||||
|
||||
virtual StringView name() const = 0;
|
||||
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { return Error::from_errno(ENOTIMPL); }
|
||||
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); }
|
||||
|
@ -61,6 +66,7 @@ private:
|
|||
|
||||
class SysFSSymbolicLink : public SysFSComponent {
|
||||
public:
|
||||
virtual RAMBackedFileType type() const override final { return RAMBackedFileType::Link; }
|
||||
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override final;
|
||||
virtual ErrorOr<NonnullRefPtr<SysFSInode>> to_inode(SysFS const& sysfs_instance) const override final;
|
||||
|
||||
|
@ -75,6 +81,7 @@ protected:
|
|||
|
||||
class SysFSDirectory : public SysFSComponent {
|
||||
public:
|
||||
virtual RAMBackedFileType type() const override final { return RAMBackedFileType::Directory; }
|
||||
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override final;
|
||||
virtual RefPtr<SysFSComponent> lookup(StringView name) override final;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue