mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 11:55:07 +00:00
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:
parent
cafb5b2ad6
commit
8293a0ff36
5 changed files with 47 additions and 10 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue