Kernel: Writes to disk are not synchronous anymore

Implement "proper" DiskCache syncing
This commit is contained in:
Bananymous
2023-09-11 01:25:16 +03:00
parent 7ec860a3d4
commit eee0537053
4 changed files with 72 additions and 24 deletions

View File

@@ -7,16 +7,18 @@
namespace Kernel
{
class StorageDevice;
class DiskCache
{
public:
DiskCache(size_t sector_size);
DiskCache(size_t sector_size, StorageDevice&);
~DiskCache();
bool read_from_cache(uint64_t sector, uint8_t* buffer);
BAN::ErrorOr<void> write_to_cache(uint64_t sector, const uint8_t* buffer, bool dirty);
void sync();
BAN::ErrorOr<void> sync();
size_t release_clean_pages(size_t);
size_t release_pages(size_t);
void release_all_pages();
@@ -32,6 +34,7 @@ namespace Kernel
private:
const size_t m_sector_size;
StorageDevice& m_device;
BAN::Vector<PageCache> m_cache;
};

View File

@@ -76,12 +76,15 @@ namespace Kernel
BAN::Vector<Partition*>& partitions() { return m_partitions; }
const BAN::Vector<Partition*>& partitions() const { return m_partitions; }
BAN::ErrorOr<void> sync_disk_cache();
protected:
virtual BAN::ErrorOr<void> read_sectors_impl(uint64_t lba, uint8_t sector_count, uint8_t* buffer) = 0;
virtual BAN::ErrorOr<void> write_sectors_impl(uint64_t lba, uint8_t sector_count, const uint8_t* buffer) = 0;
void add_disk_cache();
private:
SpinLock m_lock;
BAN::Optional<DiskCache> m_disk_cache;
BAN::Vector<Partition*> m_partitions;