Luna/kernel/src/fs/devices/Device.h

56 lines
1.1 KiB
C++

#pragma once
#include "Log.h"
#include <luna/Result.h>
#include <luna/SharedPtr.h>
class Device : public Shareable
{
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> query_shared_memory(off_t, usize)
{
return err(EACCES);
}
virtual Result<u64> ioctl(int, void*)
{
return err(ENOTTY);
}
virtual Result<u64> isatty() const
{
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 will_block_if_read() const = 0;
virtual ~Device() = default;
protected:
Option<u64> m_shmid;
};