2018-10-16 05:21:49 -04:00
|
|
|
#include "DiskDevice.h"
|
|
|
|
|
|
|
|
DiskDevice::DiskDevice()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DiskDevice::~DiskDevice()
|
|
|
|
{
|
|
|
|
}
|
2018-10-16 08:11:58 -04:00
|
|
|
|
2018-10-17 04:55:43 -04:00
|
|
|
bool DiskDevice::read(DiskOffset offset, unsigned length, byte* out) const
|
2018-10-16 08:11:58 -04:00
|
|
|
{
|
|
|
|
ASSERT((offset % blockSize()) == 0);
|
|
|
|
ASSERT((length % blockSize()) == 0);
|
2018-10-17 04:55:43 -04:00
|
|
|
dword firstBlock = offset / blockSize();
|
|
|
|
dword endBlock = (offset + length) / blockSize();
|
2018-10-16 08:11:58 -04:00
|
|
|
byte* outptr = out;
|
|
|
|
for (unsigned bi = firstBlock; bi < endBlock; ++bi) {
|
|
|
|
if (!readBlock(bi, outptr))
|
|
|
|
return false;
|
|
|
|
outptr += blockSize();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-17 04:55:43 -04:00
|
|
|
bool DiskDevice::write(DiskOffset offset, unsigned length, const byte* in)
|
2018-10-16 08:11:58 -04:00
|
|
|
{
|
|
|
|
ASSERT((offset % blockSize()) == 0);
|
|
|
|
ASSERT((length % blockSize()) == 0);
|
2018-10-17 04:55:43 -04:00
|
|
|
dword firstBlock = offset / blockSize();
|
|
|
|
dword endBlock = (offset + length) / blockSize();
|
2018-10-16 08:11:58 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|