Kernel: Replace is_* with kind field

Replaced the is_* virtual functions with a kind field instead
This commit is contained in:
2026-05-15 21:21:32 +03:00
committed by Bananymous
parent 647d6a273d
commit 16967cd9c0
8 changed files with 20 additions and 14 deletions

View File

@@ -12,7 +12,6 @@ namespace Kernel
virtual ~Device() = default;
virtual void update() {}
virtual bool is_device() const override { return true; }
virtual bool is_partition() const { return false; }
virtual bool is_storage_device() const { return false; }

View File

@@ -35,11 +35,10 @@ namespace Kernel
m_blocks = 0;
m_dev = 0;
m_rdev = 0;
m_kind = InodeKind::EPOLL;
}
public:
bool is_epoll() const override { return true; }
const FileSystem* filesystem() const override { return nullptr; }
bool can_read_impl() const override { return false; }

View File

@@ -61,7 +61,12 @@ namespace Kernel
bool ifsock() const { return (mode & Mask::TYPE_MASK) == Mask::IFSOCK; }
mode_t mode;
};
enum InodeKind : uint8_t {
DEVICE = 0x1,
EPOLL = 0x2,
PIPE = 0x4,
TTY = 0x8,
};
public:
virtual ~Inode() {}
@@ -83,10 +88,10 @@ namespace Kernel
dev_t dev() const { return m_dev; }
dev_t rdev() const { return m_rdev; }
virtual bool is_device() const { return false; }
virtual bool is_epoll() const { return false; }
virtual bool is_pipe() const { return false; }
virtual bool is_tty() const { return false; }
bool is_device() const { return m_kind & InodeKind::DEVICE; }
bool is_epoll() const { return m_kind & InodeKind::EPOLL; }
bool is_pipe() const { return m_kind & InodeKind::PIPE; }
bool is_tty() const { return m_kind & InodeKind::TTY; }
virtual const FileSystem* filesystem() const = 0;
@@ -183,6 +188,10 @@ namespace Kernel
virtual BAN::ErrorOr<long> ioctl_impl(int, void*) { return BAN::Error::from_errno(ENOTSUP); }
protected:
// TODO: this is supposed to be const I guess?
// But the thing is I would have to refactor a big chunk of the codebase
// to add it as a parameter to Inode() soooooo yeah no, not doing that rn.
uint8_t m_kind = 0;
BAN::Atomic<ino_t> m_ino;
BAN::Atomic<mode_t> m_mode;
BAN::Atomic<nlink_t> m_nlink;

View File

@@ -13,8 +13,6 @@ namespace Kernel
public:
static BAN::ErrorOr<BAN::RefPtr<Inode>> create(const Credentials&);
virtual bool is_pipe() const override { return true; }
void on_close(int status_flags) override;
void on_clone(int status_flags) override;

View File

@@ -49,8 +49,6 @@ namespace Kernel
void on_key_event(LibInput::KeyEvent);
void handle_input_byte(uint8_t);
virtual bool is_tty() const override { return true; }
virtual void clear() = 0;
virtual BAN::ErrorOr<void> chmod_impl(mode_t) override;

View File

@@ -11,6 +11,7 @@ namespace Kernel
MUST(DevFileSystem::get().allocate_inode(create_inode_info(mode, uid, gid))),
create_inode_info(mode, uid, gid)
)
{ }
{
m_kind |= InodeKind::DEVICE;
}
}

View File

@@ -39,6 +39,7 @@ namespace Kernel
m_blocks = 0;
m_dev = 0; // FIXME
m_rdev = 0; // FIXME
m_kind = InodeKind::PIPE;
}
void Pipe::on_clone(int status_flags)

View File

@@ -74,6 +74,7 @@ namespace Kernel
: CharacterDevice(mode, uid, gid)
, m_termios(termios)
{
m_kind |= InodeKind::TTY;
m_rdev = next_tty_rdev();
m_output.buffer = MUST(ByteRingBuffer::create(PAGE_SIZE));
}