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