Kernel: Inode/Device detection is done with overridden bool functions

This commit is contained in:
Bananymous 2023-06-03 13:28:15 +03:00
parent da7f09cf82
commit a4cb5d8360
6 changed files with 7 additions and 26 deletions

View File

@ -8,20 +8,13 @@ namespace Kernel
class Device : public Inode
{
public:
enum class DeviceType
{
BlockDevice,
CharacterDevice,
DeviceController,
Partition,
};
Device();
virtual ~Device() {}
virtual DeviceType device_type() const = 0;
virtual void update() {}
virtual InodeType inode_type() const override { return InodeType::Device; }
virtual bool is_device() const override { return true; }
virtual bool is_partition() const { return false; }
virtual ino_t ino() const override { return m_ino_t; }
virtual nlink_t nlink() const override { return 1; }
@ -50,13 +43,11 @@ namespace Kernel
class BlockDevice : public Device
{
public:
virtual DeviceType device_type() const override { return DeviceType::BlockDevice; }
};
class CharacterDevice : public Device
{
public:
virtual DeviceType device_type() const override { return DeviceType::CharacterDevice; }
};
}

View File

@ -31,8 +31,6 @@ namespace Kernel
virtual BAN::RefPtr<Inode> root_inode() override { return this; }
virtual InodeType inode_type() const override { return InodeType::Device; }
virtual BAN::StringView name() const override { return "device-manager"; }
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> read_directory_inode(BAN::StringView) override;

View File

@ -137,8 +137,6 @@ namespace Kernel
virtual dev_t dev() const override { return 0; }
virtual dev_t rdev() const override { return 0; }
virtual InodeType inode_type() const override { return InodeType::Ext2; }
virtual BAN::StringView name() const override { return m_name; }
virtual BAN::ErrorOr<BAN::String> link_target() override;

View File

@ -49,12 +49,6 @@ namespace Kernel
mode_t mode;
};
enum class InodeType
{
Device,
Ext2,
};
public:
virtual ~Inode() {}
@ -74,7 +68,7 @@ namespace Kernel
virtual dev_t dev() const = 0;
virtual dev_t rdev() const = 0;
virtual InodeType inode_type() const = 0;
virtual bool is_device() const { return false; }
virtual BAN::StringView name() const = 0;

View File

@ -43,7 +43,7 @@ namespace Kernel
char m_label[36 * 4 + 1];
public:
virtual DeviceType device_type() const override { return DeviceType::Partition; }
virtual bool is_partition() const override { return true; }
virtual Mode mode() const override { return { Mode::IFBLK | Mode::IRUSR | Mode::IRGRP }; }
virtual uid_t uid() const override { return 0; }

View File

@ -41,11 +41,11 @@ namespace Kernel
BAN::ErrorOr<void> VirtualFileSystem::mount(BAN::StringView partition, BAN::StringView target)
{
auto partition_file = TRY(file_from_absolute_path(partition, true));
if (partition_file.inode->inode_type() != Inode::InodeType::Device)
if (!partition_file.inode->is_device())
return BAN::Error::from_errno(ENOTBLK);
Device* device = (Device*)partition_file.inode.ptr();
if (device->device_type() != Device::DeviceType::BlockDevice)
if (!device->is_partition())
return BAN::Error::from_errno(ENOTBLK);
auto* file_system = TRY(Ext2FS::create(*(Partition*)device));