Serenity Operating System
at master 52 lines 1.7 kB view raw
1/* 2 * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <Kernel/FileSystem/FileBackedFileSystem.h> 10#include <Kernel/Locking/MutexProtected.h> 11 12namespace Kernel { 13 14class BlockBasedFileSystem : public FileBackedFileSystem { 15public: 16 AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, BlockIndex); 17 18 virtual ~BlockBasedFileSystem() override; 19 20 u64 logical_block_size() const { return m_logical_block_size; }; 21 22 virtual void flush_writes() override; 23 void flush_writes_impl(); 24 25protected: 26 explicit BlockBasedFileSystem(OpenFileDescription&); 27 28 virtual ErrorOr<void> initialize_while_locked() override; 29 30 ErrorOr<void> read_block(BlockIndex, UserOrKernelBuffer*, size_t count, u64 offset = 0, bool allow_cache = true) const; 31 ErrorOr<void> read_blocks(BlockIndex, unsigned count, UserOrKernelBuffer&, bool allow_cache = true) const; 32 33 ErrorOr<void> raw_read(BlockIndex, UserOrKernelBuffer&); 34 ErrorOr<void> raw_write(BlockIndex, UserOrKernelBuffer const&); 35 36 ErrorOr<void> raw_read_blocks(BlockIndex index, size_t count, UserOrKernelBuffer&); 37 ErrorOr<void> raw_write_blocks(BlockIndex index, size_t count, UserOrKernelBuffer const&); 38 39 ErrorOr<void> write_block(BlockIndex, UserOrKernelBuffer const&, size_t count, u64 offset = 0, bool allow_cache = true); 40 ErrorOr<void> write_blocks(BlockIndex, unsigned count, UserOrKernelBuffer const&, bool allow_cache = true); 41 42 u64 m_logical_block_size { 512 }; 43 44 void remove_disk_cache_before_last_unmount(); 45 46private: 47 void flush_specific_block_if_needed(BlockIndex index); 48 49 mutable MutexProtected<OwnPtr<DiskCache>> m_cache; 50}; 51 52}