summaryrefslogtreecommitdiff
path: root/VirtualFileSystem/DiskBackedFileSystem.h
blob: 0a9f35f51f9fedf2a3e82d8d64f7473f313008b7 (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
#pragma once

#include "FileSystem.h"
#include <AK/ByteBuffer.h>

class DiskBackedFS : public FS {
public:
    virtual ~DiskBackedFS() override;

    DiskDevice& device() { return *m_device; }
    const DiskDevice& device() const { return *m_device; }

    size_t blockSize() const { return m_blockSize; }

protected:
    explicit DiskBackedFS(RetainPtr<DiskDevice>&&);

    void setBlockSize(unsigned);

    ByteBuffer readBlock(unsigned index) const;
    ByteBuffer readBlocks(unsigned index, unsigned count) const;

    bool writeBlock(unsigned index, const ByteBuffer&);
    bool writeBlocks(unsigned index, unsigned count, const ByteBuffer&);

private:
    size_t m_blockSize { 0 };
    RetainPtr<DiskDevice> m_device;
};