summaryrefslogtreecommitdiff
path: root/Kernel/Devices/DiskPartition.h
blob: 0c2ea477d4c2f7ad85b6348197b829d1644b0f2d (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
#pragma once

#include <AK/RefPtr.h>
#include <Kernel/Devices/DiskDevice.h>

class DiskPartition final : public DiskDevice {
public:
    static NonnullRefPtr<DiskPartition> create(DiskDevice&, unsigned block_offset, unsigned block_limit);
    virtual ~DiskPartition();

    virtual bool read_block(unsigned index, u8* out) const override;
    virtual bool write_block(unsigned index, const u8*) override;
    virtual bool read_blocks(unsigned index, u16 count, u8*) override;
    virtual bool write_blocks(unsigned index, u16 count, const u8*) override;

    // ^BlockDevice
    virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return 0; }
    virtual bool can_read(const FileDescription&) const override { return true; }
    virtual ssize_t write(FileDescription&, const u8*, ssize_t) override { return 0; }
    virtual bool can_write(const FileDescription&) const override { return true; }

private:
    virtual const char* class_name() const override;

    DiskPartition(DiskDevice&, unsigned block_offset, unsigned block_limit);

    NonnullRefPtr<DiskDevice> m_device;
    unsigned m_block_offset;
    unsigned m_block_limit;
};