42 lines
863 B
C++
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;
|
|
};
|