summaryrefslogtreecommitdiff
path: root/Kernel/Devices/DiskPartition.cpp
blob: 56ebe4c8944099171263d6aa8f54bf805f8e9101 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <Kernel/Devices/DiskPartition.h>

// #define OFFD_DEBUG

NonnullRefPtr<DiskPartition> DiskPartition::create(DiskDevice& device, unsigned block_offset, unsigned block_limit)
{
    return adopt(*new DiskPartition(device, block_offset, block_limit));
}

DiskPartition::DiskPartition(DiskDevice& device, unsigned block_offset, unsigned block_limit)
    : DiskDevice(100, 0, device.block_size())
    , m_device(device)
    , m_block_offset(block_offset)
    , m_block_limit(block_limit)
{
}

DiskPartition::~DiskPartition()
{
}

bool DiskPartition::read_block(unsigned index, u8* out) const
{
#ifdef OFFD_DEBUG
    kprintf("DiskPartition::read_block %u (really: %u)\n", index, m_block_offset + index);
#endif

    return m_device->read_block(m_block_offset + index, out);
}

bool DiskPartition::write_block(unsigned index, const u8* data)
{
#ifdef OFFD_DEBUG
    kprintf("DiskPartition::write_block %u (really: %u)\n", index, m_block_offset + index);
#endif

    return m_device->write_block(m_block_offset + index, data);
}

bool DiskPartition::read_blocks(unsigned index, u16 count, u8* out)
{
#ifdef OFFD_DEBUG
    kprintf("DiskPartition::read_blocks %u (really: %u) count=%u\n", index, m_block_offset + index, count);
#endif

    return m_device->read_blocks(m_block_offset + index, count, out);
}

bool DiskPartition::write_blocks(unsigned index, u16 count, const u8* data)
{
#ifdef OFFD_DEBUG
    kprintf("DiskPartition::write_blocks %u (really: %u) count=%u\n", index, m_block_offset + index, count);
#endif

    return m_device->write_blocks(m_block_offset + index, count, data);
}

const char* DiskPartition::class_name() const
{
    return "DiskPartition";
}