1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 18:15:09 +00:00
serenity/VirtualFileSystem/DiskDevice.cpp
Andreas Kling 8293a0ff36 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().
2018-10-16 14:13:32 +02:00

45 lines
1.2 KiB
C++

#include "DiskDevice.h"
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;
}