Kernel: Make ProcFS use the new TmpFS internally

This commit is contained in:
2023-11-07 02:35:44 +02:00
parent b7771e95ac
commit 06e176e6b9
8 changed files with 56 additions and 42 deletions

View File

@@ -1,13 +1,13 @@
#pragma once
#include <kernel/FS/RamFS/FileSystem.h>
#include <kernel/FS/RamFS/Inode.h>
#include <kernel/FS/TmpFS/FileSystem.h>
#include <kernel/FS/TmpFS/Inode.h>
#include <kernel/Process.h>
namespace Kernel
{
class ProcFileSystem final : public RamFileSystem
class ProcFileSystem final : public TmpFileSystem
{
public:
static void initialize();
@@ -17,10 +17,7 @@ namespace Kernel
void on_process_delete(Process&);
private:
ProcFileSystem(size_t size);
private:
BAN::RefPtr<RamDirectoryInode> m_root_inode;
ProcFileSystem();
};
}

View File

@@ -1,41 +1,43 @@
#pragma once
#include <kernel/FS/RamFS/FileSystem.h>
#include <kernel/FS/RamFS/Inode.h>
#include <kernel/FS/TmpFS/FileSystem.h>
#include <kernel/FS/TmpFS/Inode.h>
#include <kernel/Process.h>
namespace Kernel
{
class ProcPidInode final : public RamDirectoryInode
class ProcPidInode final : public TmpDirectoryInode
{
public:
static BAN::ErrorOr<BAN::RefPtr<ProcPidInode>> create(Process&, RamFileSystem&, mode_t, uid_t, gid_t);
static BAN::ErrorOr<BAN::RefPtr<ProcPidInode>> create_new(Process&, TmpFileSystem&, mode_t, uid_t, gid_t);
~ProcPidInode() = default;
void cleanup();
private:
ProcPidInode(Process&, RamFileSystem&, const FullInodeInfo&);
ProcPidInode(Process&, TmpFileSystem&, const TmpInodeInfo&);
private:
Process& m_process;
};
class ProcROInode final : public RamInode
class ProcROInode final : public TmpInode
{
public:
static BAN::ErrorOr<BAN::RefPtr<ProcROInode>> create(Process&, size_t (Process::*callback)(off_t, BAN::ByteSpan) const, RamFileSystem&, mode_t, uid_t, gid_t);
static BAN::ErrorOr<BAN::RefPtr<ProcROInode>> create_new(Process&, size_t (Process::*callback)(off_t, BAN::ByteSpan) const, TmpFileSystem&, mode_t, uid_t, gid_t);
~ProcROInode() = default;
protected:
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
// You may not write here and this is always non blocking
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override { return BAN::Error::from_errno(EINVAL); }
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override { return BAN::Error::from_errno(EINVAL); }
virtual BAN::ErrorOr<void> truncate_impl(size_t) override { return BAN::Error::from_errno(EINVAL); }
virtual bool has_data_impl() const override { return true; }
private:
ProcROInode(Process&, size_t (Process::*)(off_t, BAN::ByteSpan) const, RamFileSystem&, const FullInodeInfo&);
ProcROInode(Process&, size_t (Process::*)(off_t, BAN::ByteSpan) const, TmpFileSystem&, const TmpInodeInfo&);
private:
Process& m_process;

View File

@@ -88,10 +88,11 @@ namespace Kernel
size_t index;
};
private:
protected:
TmpFileSystem(size_t max_pages);
BAN::ErrorOr<void> initialize(mode_t, uid_t, gid_t);
private:
InodeLocation find_inode(ino_t ino);
paddr_t find_block(size_t index);

View File

@@ -97,7 +97,11 @@ namespace Kernel
~TmpDirectoryInode();
BAN::ErrorOr<void> link_inode(TmpInode&, BAN::StringView);
protected:
TmpDirectoryInode(TmpFileSystem&, ino_t, const TmpInodeInfo&);
virtual BAN::ErrorOr<void> prepare_unlink() override;
protected:
@@ -108,14 +112,12 @@ namespace Kernel
virtual BAN::ErrorOr<void> unlink_impl(BAN::StringView) override final;
private:
TmpDirectoryInode(TmpFileSystem&, ino_t, const TmpInodeInfo&);
BAN::ErrorOr<void> link_inode(TmpInode&, BAN::StringView);
template<TmpFuncs::for_each_valid_entry_callback F>
void for_each_valid_entry(F callback);
friend class TmpInode;
};
TmpInodeInfo create_inode_info(mode_t mode, uid_t uid, gid_t gid);
}

View File

@@ -60,6 +60,8 @@ namespace Kernel
bool is_session_leader() const { return pid() == sid(); }
const Credentials& credentials() const { return m_credentials; }
BAN::ErrorOr<long> sys_exit(int status);
BAN::ErrorOr<long> sys_gettermios(::termios*);