summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/BlockBasedFileSystem.h
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2020-12-24 18:18:40 +0200
committerAndreas Kling <kling@serenityos.org>2020-12-27 23:07:44 +0100
commit092a13211a4216c19c08280bd5e5803e1030f087 (patch)
tree1c0f1290f1f21951354cf6cbd83021408ebe9d0a /Kernel/FileSystem/BlockBasedFileSystem.h
parentd1366b660ee27564e423aec71ef4e13da432b40e (diff)
downloadserenity-092a13211a4216c19c08280bd5e5803e1030f087.zip
Kernel: Convert read_block method to get a reference instead of pointer
BlockBasedFileSystem::read_block method should get a reference of a UserOrKernelBuffer. If we need to force caching a block, we will call other method to do so.
Diffstat (limited to 'Kernel/FileSystem/BlockBasedFileSystem.h')
-rw-r--r--Kernel/FileSystem/BlockBasedFileSystem.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/Kernel/FileSystem/BlockBasedFileSystem.h b/Kernel/FileSystem/BlockBasedFileSystem.h
index fcf096aec3..827d7ca927 100644
--- a/Kernel/FileSystem/BlockBasedFileSystem.h
+++ b/Kernel/FileSystem/BlockBasedFileSystem.h
@@ -27,10 +27,22 @@
#pragma once
#include <Kernel/FileSystem/FileBackedFileSystem.h>
+#include <Kernel/KResult.h>
namespace Kernel {
+class DiskCache;
class BlockBasedFS : public FileBackedFS {
+ friend class DiskCache;
+
+private:
+ struct CacheEntry {
+ IntrusiveListNode list_node;
+ u32 block_index { 0 };
+ u8* data { nullptr };
+ bool has_data { false };
+ };
+
public:
virtual ~BlockBasedFS() override;
@@ -42,7 +54,10 @@ public:
protected:
explicit BlockBasedFS(FileDescription&);
- int read_block(unsigned index, UserOrKernelBuffer* buffer, size_t count, size_t offset = 0, bool allow_cache = true) const;
+ int read_block(unsigned index, UserOrKernelBuffer& buffer, size_t count, size_t offset = 0, bool allow_cache = true) const;
+ bool force_cache_block(unsigned index) const;
+ KResultOr<CacheEntry> cache_block(unsigned index) const;
+
int read_blocks(unsigned index, unsigned count, UserOrKernelBuffer& buffer, bool allow_cache = true) const;
bool raw_read(unsigned index, UserOrKernelBuffer& buffer);