Luna/kernel/src/fs/devices/Device.h
apio 738b218a49
All checks were successful
continuous-integration/drone/pr Build is passing
kernel/ATA+MBR: Dynamically generate device names + create devices for MBR partitions
2023-06-16 21:30:50 +02:00

42 lines
863 B
C++

#pragma once
#include "Log.h"
#include <luna/Result.h>
class Device
{
public:
virtual Result<usize> read(u8* buf, usize offset, usize length) const = 0;
virtual Result<usize> write(const u8* buf, usize offset, usize length) = 0;
virtual Result<u64> ioctl(int, void*)
{
return err(ENOTTY);
}
virtual usize size() const
{
return 0;
}
virtual bool is_block_device() const
{
return false;
}
virtual Result<usize> block_size() const
{
// Block devices should override this function.
kwarnln("Device::block_size() was called on a character device or block device without block size");
return err(ENOTSUP);
}
// Path in devfs.
virtual StringView device_path() const = 0;
virtual bool blocking() const = 0;
virtual ~Device() = default;
};