Kernel: Rewrite whole device structure
We now have DevFileSystem which is derived from RamFileSystem. All devices are RamInodes. We don't have separate DeviceManager anymore. To iterate over devices, you can loop througn every inode in devfs.
This commit is contained in:
30
kernel/include/kernel/FS/DevFS/FileSystem.h
Normal file
30
kernel/include/kernel/FS/DevFS/FileSystem.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <kernel/Device.h>
|
||||
#include <kernel/FS/RamFS/FileSystem.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
class DevFileSystem final : public RamFileSystem
|
||||
{
|
||||
public:
|
||||
static void initialize();
|
||||
static DevFileSystem& get();
|
||||
|
||||
void initialize_device_updater();
|
||||
|
||||
void add_device(BAN::StringView path, BAN::RefPtr<Device>);
|
||||
|
||||
dev_t get_next_rdev();
|
||||
|
||||
private:
|
||||
DevFileSystem(size_t size)
|
||||
: RamFileSystem(size)
|
||||
{ }
|
||||
|
||||
private:
|
||||
SpinLock m_device_lock;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -137,8 +137,6 @@ namespace Kernel
|
||||
virtual dev_t dev() const override { return 0; }
|
||||
virtual dev_t rdev() const override { return 0; }
|
||||
|
||||
virtual BAN::StringView name() const override { return m_name; }
|
||||
|
||||
virtual BAN::ErrorOr<BAN::String> link_target() override;
|
||||
|
||||
virtual BAN::ErrorOr<void> directory_read_next_entries(off_t, DirectoryEntryList*, size_t) override;
|
||||
|
||||
@@ -78,8 +78,6 @@ namespace Kernel
|
||||
virtual bool is_device() const { return false; }
|
||||
virtual bool is_pipe() const { return false; }
|
||||
|
||||
virtual BAN::StringView name() const = 0;
|
||||
|
||||
virtual BAN::ErrorOr<BAN::String> link_target() { ASSERT_NOT_REACHED(); }
|
||||
|
||||
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> directory_find_inode(BAN::StringView) { if (!mode().ifdir()) return BAN::Error::from_errno(ENOTDIR); ASSERT_NOT_REACHED(); }
|
||||
|
||||
@@ -30,8 +30,6 @@ namespace Kernel
|
||||
virtual dev_t dev() const override { return 0; } // FIXME
|
||||
virtual dev_t rdev() const override { return 0; } // FIXME
|
||||
|
||||
virtual BAN::StringView name() const override { return ""sv; }
|
||||
|
||||
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
|
||||
virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) override;
|
||||
|
||||
|
||||
@@ -8,13 +8,15 @@ namespace Kernel
|
||||
{
|
||||
|
||||
class RamInode;
|
||||
class RamDirectoryInode;
|
||||
|
||||
class RamFileSystem final : public FileSystem
|
||||
class RamFileSystem : public FileSystem
|
||||
{
|
||||
public:
|
||||
static BAN::ErrorOr<RamFileSystem*> create(size_t size, mode_t, uid_t, gid_t);
|
||||
~RamFileSystem() = default;
|
||||
virtual ~RamFileSystem() = default;
|
||||
|
||||
BAN::ErrorOr<void> set_root_inode(BAN::RefPtr<RamDirectoryInode>);
|
||||
virtual BAN::RefPtr<Inode> root_inode() override { return m_inodes[m_root_inode]; }
|
||||
|
||||
BAN::ErrorOr<void> add_inode(BAN::RefPtr<RamInode>);
|
||||
@@ -23,15 +25,19 @@ namespace Kernel
|
||||
blksize_t blksize() const { return m_blksize; }
|
||||
ino_t next_ino() { return m_next_ino++; }
|
||||
|
||||
private:
|
||||
RamFileSystem() = default;
|
||||
void for_each_inode(void (*callback)(BAN::RefPtr<RamInode>));
|
||||
|
||||
protected:
|
||||
RamFileSystem(size_t size)
|
||||
: m_size(size)
|
||||
{ }
|
||||
|
||||
private:
|
||||
SpinLock m_lock;
|
||||
RecursiveSpinLock m_lock;
|
||||
size_t m_size { 0 };
|
||||
|
||||
BAN::HashMap<ino_t, BAN::RefPtr<RamInode>> m_inodes;
|
||||
ino_t m_root_inode;
|
||||
ino_t m_root_inode { 0 };
|
||||
|
||||
const blksize_t m_blksize = PAGE_SIZE;
|
||||
ino_t m_next_ino { 1 };
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Kernel
|
||||
class RamInode : public Inode
|
||||
{
|
||||
public:
|
||||
static BAN::ErrorOr<BAN::RefPtr<RamInode>> create(RamFileSystem&, mode_t, uid_t, gid_t);
|
||||
virtual ~RamInode() = default;
|
||||
|
||||
virtual ino_t ino() const override { return m_inode_info.ino; }
|
||||
@@ -28,8 +29,6 @@ namespace Kernel
|
||||
virtual dev_t dev() const override { return m_inode_info.dev; }
|
||||
virtual dev_t rdev() const override { return m_inode_info.rdev; }
|
||||
|
||||
virtual BAN::StringView name() const override { ASSERT_NOT_REACHED(); }
|
||||
|
||||
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
|
||||
virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) override;
|
||||
|
||||
@@ -39,7 +38,6 @@ namespace Kernel
|
||||
|
||||
protected:
|
||||
RamInode(RamFileSystem& fs, mode_t, uid_t, gid_t);
|
||||
static BAN::ErrorOr<BAN::RefPtr<RamInode>> create(RamFileSystem&, mode_t, uid_t, gid_t);
|
||||
|
||||
protected:
|
||||
struct FullInodeInfo
|
||||
@@ -71,15 +69,17 @@ namespace Kernel
|
||||
class RamDirectoryInode final : public RamInode
|
||||
{
|
||||
public:
|
||||
static BAN::ErrorOr<BAN::RefPtr<RamDirectoryInode>> create(RamFileSystem&, ino_t parent, mode_t, uid_t, gid_t);
|
||||
~RamDirectoryInode() = default;
|
||||
|
||||
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> directory_find_inode(BAN::StringView) override;
|
||||
virtual BAN::ErrorOr<void> directory_read_next_entries(off_t, DirectoryEntryList*, size_t) override;
|
||||
virtual BAN::ErrorOr<void> create_file(BAN::StringView, mode_t, uid_t, gid_t) override;
|
||||
|
||||
BAN::ErrorOr<void> add_inode(BAN::StringView, BAN::RefPtr<RamInode>);
|
||||
|
||||
private:
|
||||
RamDirectoryInode(RamFileSystem&, ino_t parent, mode_t, uid_t, gid_t);
|
||||
static BAN::ErrorOr<BAN::RefPtr<RamDirectoryInode>> create(RamFileSystem&, ino_t parent, mode_t, uid_t, gid_t);
|
||||
|
||||
private:
|
||||
static constexpr size_t m_name_max = NAME_MAX;
|
||||
|
||||
Reference in New Issue
Block a user