ladybird/Kernel/FileSystem/DiskBackedFileSystem.h
Andreas Kling 44673c4f3b Kernel: Add a write cache to DiskBackedFS.
This way you can spam small write()s on a file without the kernel writing
to disk every single time. Flushes are included in the FS::sync() operation
and will get triggered regularly by syncd. :^)
2019-04-25 22:05:53 +02:00

33 lines
821 B
C++

#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;
};