Kernel: Expose block size in AsyncBlockDeviceRequest struct

Expose the block size variable via a member function in the
AsyncBlockDeviceRequest so that the driver doesn't need to assume any
value such as 512 bytes.
This commit is contained in:
Pankaj Raghav 2022-03-26 18:32:44 +01:00 committed by Brian Gianforcaro
parent 4b2094506b
commit 2786a71bc0
Notes: sideshowbarker 2024-07-17 16:41:29 +09:00

View file

@ -12,45 +12,7 @@
namespace Kernel {
class BlockDevice;
class AsyncBlockDeviceRequest final : public AsyncDeviceRequest {
public:
enum RequestType {
Read,
Write
};
AsyncBlockDeviceRequest(Device& block_device, RequestType request_type,
u64 block_index, u32 block_count, const UserOrKernelBuffer& buffer, size_t buffer_size);
RequestType request_type() const { return m_request_type; }
u64 block_index() const { return m_block_index; }
u32 block_count() const { return m_block_count; }
UserOrKernelBuffer& buffer() { return m_buffer; }
const UserOrKernelBuffer& buffer() const { return m_buffer; }
size_t buffer_size() const { return m_buffer_size; }
virtual void start() override;
virtual StringView name() const override
{
switch (m_request_type) {
case Read:
return "BlockDeviceRequest (read)"sv;
case Write:
return "BlockDeviceRequest (write)"sv;
default:
VERIFY_NOT_REACHED();
}
}
private:
BlockDevice& m_block_device;
const RequestType m_request_type;
const u64 m_block_index;
const u32 m_block_count;
UserOrKernelBuffer m_buffer;
const size_t m_buffer_size;
};
class AsyncBlockDeviceRequest;
class BlockDevice : public Device {
public:
@ -83,4 +45,43 @@ private:
u8 m_block_size_log { 0 };
};
class AsyncBlockDeviceRequest final : public AsyncDeviceRequest {
public:
enum RequestType {
Read,
Write
};
AsyncBlockDeviceRequest(Device& block_device, RequestType request_type,
u64 block_index, u32 block_count, const UserOrKernelBuffer& buffer, size_t buffer_size);
RequestType request_type() const { return m_request_type; }
u64 block_index() const { return m_block_index; }
u32 block_count() const { return m_block_count; }
size_t block_size() const { return m_block_device.block_size(); }
UserOrKernelBuffer& buffer() { return m_buffer; }
const UserOrKernelBuffer& buffer() const { return m_buffer; }
size_t buffer_size() const { return m_buffer_size; }
virtual void start() override;
virtual StringView name() const override
{
switch (m_request_type) {
case Read:
return "BlockDeviceRequest (read)"sv;
case Write:
return "BlockDeviceRequest (write)"sv;
default:
VERIFY_NOT_REACHED();
}
}
private:
BlockDevice& m_block_device;
const RequestType m_request_type;
const u64 m_block_index;
const u32 m_block_count;
UserOrKernelBuffer m_buffer;
const size_t m_buffer_size;
};
}