2019-06-02 12:38:37 +03:00
|
|
|
#include <Kernel/Devices/DiskPartition.h>
|
|
|
|
|
|
|
|
// #define OFFD_DEBUG
|
|
|
|
|
2019-08-21 17:45:52 +03:00
|
|
|
NonnullRefPtr<DiskPartition> DiskPartition::create(DiskDevice& device, unsigned block_offset)
|
2019-06-02 12:38:37 +03:00
|
|
|
{
|
2019-08-21 17:45:52 +03:00
|
|
|
return adopt(*new DiskPartition(device, block_offset));
|
2019-06-02 12:38:37 +03:00
|
|
|
}
|
|
|
|
|
2019-08-21 17:45:52 +03:00
|
|
|
DiskPartition::DiskPartition(DiskDevice& device, unsigned block_offset)
|
|
|
|
: DiskDevice(100, 0, device.block_size())
|
|
|
|
, m_device(device)
|
2019-06-07 12:43:58 +03:00
|
|
|
, m_block_offset(block_offset)
|
2019-06-02 12:38:37 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DiskPartition::~DiskPartition()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-07-03 22:17:35 +03:00
|
|
|
bool DiskPartition::read_block(unsigned index, u8* out) const
|
2019-06-02 12:38:37 +03:00
|
|
|
{
|
|
|
|
#ifdef OFFD_DEBUG
|
|
|
|
kprintf("DiskPartition::read_block %u (really: %u)\n", index, m_block_offset + index);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return m_device->read_block(m_block_offset + index, out);
|
|
|
|
}
|
|
|
|
|
2019-07-03 22:17:35 +03:00
|
|
|
bool DiskPartition::write_block(unsigned index, const u8* data)
|
2019-06-02 12:38:37 +03:00
|
|
|
{
|
|
|
|
#ifdef OFFD_DEBUG
|
|
|
|
kprintf("DiskPartition::write_block %u (really: %u)\n", index, m_block_offset + index);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return m_device->write_block(m_block_offset + index, data);
|
|
|
|
}
|
|
|
|
|
2019-07-03 22:17:35 +03:00
|
|
|
bool DiskPartition::read_blocks(unsigned index, u16 count, u8* out)
|
2019-06-02 12:38:37 +03:00
|
|
|
{
|
|
|
|
#ifdef OFFD_DEBUG
|
|
|
|
kprintf("DiskPartition::read_blocks %u (really: %u) count=%u\n", index, m_block_offset + index, count);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return m_device->read_blocks(m_block_offset + index, count, out);
|
|
|
|
}
|
|
|
|
|
2019-07-03 22:17:35 +03:00
|
|
|
bool DiskPartition::write_blocks(unsigned index, u16 count, const u8* data)
|
2019-06-02 12:38:37 +03:00
|
|
|
{
|
|
|
|
#ifdef OFFD_DEBUG
|
|
|
|
kprintf("DiskPartition::write_blocks %u (really: %u) count=%u\n", index, m_block_offset + index, count);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return m_device->write_blocks(m_block_offset + index, count, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* DiskPartition::class_name() const
|
|
|
|
{
|
|
|
|
return "DiskPartition";
|
|
|
|
}
|