2018-10-10 06:53:07 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "FileSystem.h"
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
|
|
2019-09-30 05:31:06 -03:00
|
|
|
class DiskCache;
|
|
|
|
|
|
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
|
|
|
|
2019-08-17 06:17:36 -03:00
|
|
|
virtual bool is_disk_backed() const override { return true; }
|
|
|
|
|
|
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-04-25 17:05:53 -03:00
|
|
|
virtual void flush_writes() override;
|
|
|
|
|
|
2019-11-02 20:21:17 -03:00
|
|
|
void flush_writes_impl();
|
|
|
|
|
|
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-11-05 15:35:12 -03:00
|
|
|
bool read_block(unsigned index, u8* buffer, FileDescription* = nullptr) const;
|
|
|
|
|
bool read_blocks(unsigned index, unsigned count, u8* buffer, FileDescription* = nullptr) const;
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-11-05 15:35:12 -03:00
|
|
|
bool write_block(unsigned index, const u8*, FileDescription* = nullptr);
|
|
|
|
|
bool write_blocks(unsigned index, unsigned count, const u8*, FileDescription* = nullptr);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
|
|
|
|
private:
|
2019-09-30 05:31:06 -03:00
|
|
|
DiskCache& cache() const;
|
2019-11-05 15:35:12 -03:00
|
|
|
void flush_specific_block_if_needed(unsigned index);
|
2019-09-30 05:31:06 -03:00
|
|
|
|
2019-06-21 13:37:47 -03:00
|
|
|
NonnullRefPtr<DiskDevice> m_device;
|
2019-09-30 05:31:06 -03:00
|
|
|
mutable OwnPtr<DiskCache> m_cache;
|
2018-10-10 06:53:07 -03:00
|
|
|
};
|