mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-02 12:30:31 +00:00
44673c4f3b
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. :^)
33 lines
821 B
C++
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;
|
|
};
|