2018-10-10 06:53:07 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "FileSystem.h"
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
|
|
2018-11-15 14:13:10 -02:00
|
|
|
class DiskBackedFS : public FS {
|
2018-10-10 06:53:07 -03:00
|
|
|
public:
|
2018-11-15 14:13:10 -02:00
|
|
|
virtual ~DiskBackedFS() override;
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2018-10-16 06:21:49 -03:00
|
|
|
DiskDevice& device() { return *m_device; }
|
|
|
|
|
const DiskDevice& device() const { return *m_device; }
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-02-25 18:06:55 -03:00
|
|
|
int block_size() const { return m_block_size; }
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-04-25 17:05:53 -03:00
|
|
|
virtual void flush_writes() override;
|
|
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
protected:
|
2019-06-21 13:37:47 -03:00
|
|
|
explicit DiskBackedFS(NonnullRefPtr<DiskDevice>&&);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-06-22 11:22:34 -03:00
|
|
|
void set_block_size(int);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-01-31 14:31:23 -02:00
|
|
|
ByteBuffer read_block(unsigned index) const;
|
|
|
|
|
ByteBuffer read_blocks(unsigned index, unsigned count) const;
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-01-31 14:31:23 -02:00
|
|
|
bool write_block(unsigned index, const ByteBuffer&);
|
|
|
|
|
bool write_blocks(unsigned index, unsigned count, const ByteBuffer&);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
|
|
|
|
private:
|
2019-02-25 18:06:55 -03:00
|
|
|
int m_block_size { 0 };
|
2019-06-21 13:37:47 -03:00
|
|
|
NonnullRefPtr<DiskDevice> m_device;
|
2019-04-25 17:05:53 -03:00
|
|
|
|
|
|
|
|
HashMap<unsigned, ByteBuffer> m_write_cache;
|
2018-10-10 06:53:07 -03:00
|
|
|
};
|