ladybird/Kernel/FileSystem/DevPtsFS/FileSystem.h
Liav A a10e63f08e 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.
2024-01-13 19:01:07 -07:00

40 lines
902 B
C++

/*
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h>
namespace Kernel {
class SlavePTY;
class DevPtsFSInode;
class DevPtsFS final : public FileSystem {
friend class DevPtsFSInode;
public:
virtual ~DevPtsFS() override;
static ErrorOr<NonnullRefPtr<FileSystem>> try_create(ReadonlyBytes);
virtual ErrorOr<void> initialize() override;
virtual StringView class_name() const override { return "DevPtsFS"sv; }
virtual Inode& root_inode() override;
private:
virtual u8 internal_file_type_to_directory_entry_type(DirectoryEntryView const& entry) const override;
DevPtsFS();
ErrorOr<NonnullRefPtr<Inode>> get_inode(InodeIdentifier) const;
RefPtr<DevPtsFSInode> m_root_inode;
};
}