Luna/kernel/src/fs/StorageCache.h
apio abbfd5825f
All checks were successful
Build and test / build (push) Successful in 2m10s
kernel: Make StorageCache have a reference to its parent BlockDevice
This will make it easier to implement sync later on.
2024-08-09 18:52:56 +02:00

42 lines
680 B
C++

#pragma once
#include "lib/Mutex.h"
#include <luna/Buffer.h>
#include <luna/HashMap.h>
#include <luna/LinkedList.h>
class BlockDevice;
class StorageCache : public LinkedListNode<StorageCache>
{
public:
struct CacheEntry
{
Buffer buffer {};
bool dirty;
};
void lock()
{
return m_mutex.lock();
}
void unlock()
{
return m_mutex.unlock();
}
Result<CacheEntry*> fetch_entry(u64 block);
void clear();
static void clear_caches();
StorageCache(BlockDevice* device);
~StorageCache();
private:
HashMap<u64, CacheEntry> m_cache_entries;
BlockDevice* m_device;
Mutex m_mutex;
};