1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 17:44:56 +09:00
ladybird/VirtualFileSystem/DiskBackedFileSystem.h
Andreas Kling fdc782c1d1 Add a very naive block cache to the DiskBackedFileSystem.
This would be a lot better as an LRU. Right now it's a 32-slot
hash table with random eviction.
2018-10-25 12:36:50 +02:00

32 lines
872 B
C++

#pragma once
#include "FileSystem.h"
#include <AK/ByteBuffer.h>
#include <AK/HashMap.h>
class DiskBackedFileSystem : public FileSystem {
public:
virtual ~DiskBackedFileSystem() override;
DiskDevice& device() { return *m_device; }
const DiskDevice& device() const { return *m_device; }
unsigned blockSize() const { return m_blockSize; }
protected:
explicit DiskBackedFileSystem(RetainPtr<DiskDevice>&&);
void setBlockSize(unsigned);
void invalidateCaches();
ByteBuffer readBlock(unsigned index) const;
ByteBuffer readBlocks(unsigned index, unsigned count) const;
bool writeBlock(unsigned index, const ByteBuffer&);
bool writeBlocks(unsigned index, unsigned count, const ByteBuffer&);
private:
unsigned m_blockSize { 0 };
RetainPtr<DiskDevice> m_device;
mutable HashMap<unsigned, ByteBuffer> m_blockCache;
};