2021-03-13 12:01:44 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Kernel/FileSystem/FileSystem.h>
|
|
|
|
#include <Kernel/FileSystem/Inode.h>
|
2022-04-22 09:44:31 +03:00
|
|
|
#include <Kernel/FileSystem/SysFS/Component.h>
|
2021-08-14 11:40:37 +03:00
|
|
|
#include <Kernel/Locking/MutexProtected.h>
|
2021-03-13 12:01:44 +02:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-07-11 00:20:38 +02:00
|
|
|
class SysFS final : public FileSystem {
|
2021-03-13 12:01:44 +02:00
|
|
|
friend class SysFSInode;
|
|
|
|
friend class SysFSDirectoryInode;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~SysFS() override;
|
2022-08-19 20:53:40 +02:00
|
|
|
static ErrorOr<NonnullLockRefPtr<FileSystem>> try_create();
|
2021-03-13 12:01:44 +02:00
|
|
|
|
2021-11-08 00:51:39 +01:00
|
|
|
virtual ErrorOr<void> initialize() override;
|
2021-07-17 20:59:06 +02:00
|
|
|
virtual StringView class_name() const override { return "SysFS"sv; }
|
2021-03-13 12:01:44 +02:00
|
|
|
|
2021-07-18 01:50:47 +02:00
|
|
|
virtual Inode& root_inode() override;
|
2021-03-13 12:01:44 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
SysFS();
|
|
|
|
|
2022-08-19 20:53:40 +02:00
|
|
|
LockRefPtr<SysFSInode> m_root_inode;
|
2021-03-13 12:01:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class SysFSInode : public Inode {
|
|
|
|
friend class SysFS;
|
|
|
|
friend class SysFSDirectoryInode;
|
|
|
|
|
|
|
|
public:
|
2022-08-19 20:53:40 +02:00
|
|
|
static ErrorOr<NonnullLockRefPtr<SysFSInode>> try_create(SysFS const&, SysFSComponent const&);
|
2021-03-13 12:01:44 +02:00
|
|
|
StringView name() const { return m_associated_component->name(); }
|
|
|
|
|
|
|
|
protected:
|
2021-07-11 01:06:27 +02:00
|
|
|
SysFSInode(SysFS const&, SysFSComponent const&);
|
2022-08-06 04:22:20 +03:00
|
|
|
virtual ErrorOr<size_t> read_bytes_locked(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
|
2021-11-10 15:42:39 +01:00
|
|
|
virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
2022-08-19 20:53:40 +02:00
|
|
|
virtual ErrorOr<NonnullLockRefPtr<Inode>> lookup(StringView name) override;
|
2021-11-08 00:51:39 +01:00
|
|
|
virtual ErrorOr<void> flush_metadata() override;
|
2021-03-13 12:01:44 +02:00
|
|
|
virtual InodeMetadata metadata() const override;
|
2022-08-06 04:22:20 +03:00
|
|
|
virtual ErrorOr<size_t> write_bytes_locked(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) override;
|
2022-08-19 20:53:40 +02:00
|
|
|
virtual ErrorOr<NonnullLockRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
|
2021-11-11 00:55:02 +01:00
|
|
|
virtual ErrorOr<void> add_child(Inode&, StringView name, mode_t) override;
|
|
|
|
virtual ErrorOr<void> remove_child(StringView name) override;
|
2021-11-08 00:51:39 +01:00
|
|
|
virtual ErrorOr<void> chmod(mode_t) override;
|
|
|
|
virtual ErrorOr<void> chown(UserID, GroupID) override;
|
|
|
|
virtual ErrorOr<void> truncate(u64) override;
|
2022-08-23 00:55:26 +02:00
|
|
|
virtual ErrorOr<void> update_timestamps(Optional<time_t> atime, Optional<time_t> ctime, Optional<time_t> mtime) override;
|
2021-11-08 00:51:39 +01:00
|
|
|
|
|
|
|
virtual ErrorOr<void> attach(OpenFileDescription& description) override final;
|
2021-09-07 13:39:11 +02:00
|
|
|
virtual void did_seek(OpenFileDescription&, off_t) override final;
|
2021-09-04 16:23:45 +03:00
|
|
|
|
2022-08-19 20:53:40 +02:00
|
|
|
NonnullLockRefPtr<SysFSComponent> m_associated_component;
|
2021-03-13 12:01:44 +02:00
|
|
|
};
|
|
|
|
|
2022-04-22 20:35:15 +03:00
|
|
|
class SysFSLinkInode : public SysFSInode {
|
|
|
|
friend class SysFS;
|
|
|
|
|
|
|
|
public:
|
2022-08-19 20:53:40 +02:00
|
|
|
static ErrorOr<NonnullLockRefPtr<SysFSLinkInode>> try_create(SysFS const&, SysFSComponent const&);
|
2022-04-22 20:35:15 +03:00
|
|
|
virtual ~SysFSLinkInode() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SysFSLinkInode(SysFS const&, SysFSComponent const&);
|
|
|
|
// ^Inode
|
|
|
|
virtual InodeMetadata metadata() const override;
|
|
|
|
};
|
|
|
|
|
2021-03-13 12:01:44 +02:00
|
|
|
class SysFSDirectoryInode : public SysFSInode {
|
|
|
|
friend class SysFS;
|
|
|
|
|
|
|
|
public:
|
2022-08-19 20:53:40 +02:00
|
|
|
static ErrorOr<NonnullLockRefPtr<SysFSDirectoryInode>> try_create(SysFS const&, SysFSComponent const&);
|
2021-03-13 12:01:44 +02:00
|
|
|
virtual ~SysFSDirectoryInode() override;
|
|
|
|
|
2021-07-18 02:23:22 +02:00
|
|
|
SysFS& fs() { return static_cast<SysFS&>(Inode::fs()); }
|
|
|
|
SysFS const& fs() const { return static_cast<SysFS const&>(Inode::fs()); }
|
|
|
|
|
2021-03-13 12:01:44 +02:00
|
|
|
protected:
|
2021-07-11 01:06:27 +02:00
|
|
|
SysFSDirectoryInode(SysFS const&, SysFSComponent const&);
|
2021-03-13 12:01:44 +02:00
|
|
|
// ^Inode
|
|
|
|
virtual InodeMetadata metadata() const override;
|
2021-11-10 15:42:39 +01:00
|
|
|
virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
2022-08-19 20:53:40 +02:00
|
|
|
virtual ErrorOr<NonnullLockRefPtr<Inode>> lookup(StringView name) override;
|
2021-03-13 12:01:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|