summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/DiskBackedFileSystem.h
blob: b115eb6d123510310ca05a5e76f29dfb3f99b4f6 (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
#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; }

    int block_size() const { return m_block_size; }

    virtual void flush_writes() override;

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

    void set_block_size(unsigned);

    ByteBuffer read_block(unsigned index) const;
    ByteBuffer read_blocks(unsigned index, unsigned count) const;

    bool write_block(unsigned index, const ByteBuffer&);
    bool write_blocks(unsigned index, unsigned count, const ByteBuffer&);

private:
    int m_block_size { 0 };
    Retained<DiskDevice> m_device;

    HashMap<unsigned, ByteBuffer> m_write_cache;
};