summaryrefslogtreecommitdiff
path: root/Kernel/DiskDevice.cpp
blob: d7157485addb43ce1c20d7909b9c35578e3a5b8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "DiskDevice.h"

DiskDevice::DiskDevice()
{
}

DiskDevice::~DiskDevice()
{
}

bool DiskDevice::read(DiskOffset offset, unsigned length, byte* out) const
{
    ASSERT((offset % block_size()) == 0);
    ASSERT((length % block_size()) == 0);
    dword first_block = offset / block_size();
    dword end_block = (offset + length) / block_size();
    byte* outptr = out;
    for (unsigned bi = first_block; bi < end_block; ++bi) {
        if (!read_block(bi, outptr))
            return false;
        outptr += block_size();
    }
    return true;
}

bool DiskDevice::write(DiskOffset offset, unsigned length, const byte* in)
{
    ASSERT((offset % block_size()) == 0);
    ASSERT((length % block_size()) == 0);
    dword first_block = offset / block_size();
    dword end_block = (offset + length) / block_size();
    ASSERT(first_block <= 0xffffffff);
    ASSERT(end_block <= 0xffffffff);
    const byte* inptr = in;
    for (unsigned bi = first_block; bi < end_block; ++bi) {
        if (!write_block(bi, inptr))
            return false;
        inptr += block_size();
    }
    return true;
}