Rework DiskDevice's read() and write() to be non-virtual wrappers.

This way subclasses only have to implement readBlock() and writeBlock().
read() and write() require that the offset and length are both divisible
by the blockSize().
This commit is contained in:
Andreas Kling 2018-10-16 14:11:58 +02:00
commit 8293a0ff36
Notes: sideshowbarker 2024-07-19 18:47:22 +09:00
5 changed files with 47 additions and 10 deletions

View file

@ -7,3 +7,39 @@ DiskDevice::DiskDevice()
DiskDevice::~DiskDevice()
{
}
bool DiskDevice::read(qword offset, unsigned length, byte* out) const
{
ASSERT((offset % blockSize()) == 0);
ASSERT((length % blockSize()) == 0);
qword firstBlock = offset / blockSize();
qword endBlock = (offset + length) / blockSize();
ASSERT(firstBlock <= 0xffffffff);
ASSERT(endBlock <= 0xffffffff);
byte* outptr = out;
unsigned remainingCount = length;
for (unsigned bi = firstBlock; bi < endBlock; ++bi) {
if (!readBlock(bi, outptr))
return false;
outptr += blockSize();
}
return true;
}
bool DiskDevice::write(qword offset, unsigned length, const byte* in)
{
ASSERT((offset % blockSize()) == 0);
ASSERT((length % blockSize()) == 0);
qword firstBlock = offset / blockSize();
qword endBlock = (offset + length) / blockSize();
ASSERT(firstBlock <= 0xffffffff);
ASSERT(endBlock <= 0xffffffff);
const byte* inptr = in;
for (unsigned bi = firstBlock; bi < endBlock; ++bi) {
if (!writeBlock(bi, inptr))
return false;
inptr += blockSize();
}
return true;
}