Kernel: Rename BlockBasedFS => BlockBasedFileSystem

This commit is contained in:
Andreas Kling 2021-07-11 00:34:36 +02:00
parent 502bbacea0
commit 79552c91d5
Notes: sideshowbarker 2024-07-18 09:22:07 +09:00
4 changed files with 50 additions and 50 deletions

View file

@ -13,14 +13,14 @@ namespace Kernel {
struct CacheEntry {
IntrusiveListNode<CacheEntry> list_node;
BlockBasedFS::BlockIndex block_index { 0 };
BlockBasedFileSystem::BlockIndex block_index { 0 };
u8* data { nullptr };
bool has_data { false };
};
class DiskCache {
public:
explicit DiskCache(BlockBasedFS& fs)
explicit DiskCache(BlockBasedFileSystem& fs)
: m_fs(fs)
, m_cached_block_data(KBuffer::create_with_size(m_entry_count * m_fs.block_size()))
, m_entries(KBuffer::create_with_size(m_entry_count * sizeof(CacheEntry)))
@ -54,7 +54,7 @@ public:
m_clean_list.prepend(entry);
}
CacheEntry& get(BlockBasedFS::BlockIndex block_index) const
CacheEntry& get(BlockBasedFileSystem::BlockIndex block_index) const
{
if (auto it = m_hash.find(block_index); it != m_hash.end()) {
auto& entry = const_cast<CacheEntry&>(*it->value);
@ -94,9 +94,9 @@ public:
}
private:
BlockBasedFS& m_fs;
BlockBasedFileSystem& m_fs;
size_t m_entry_count { 10000 };
mutable HashMap<BlockBasedFS::BlockIndex, CacheEntry*> m_hash;
mutable HashMap<BlockBasedFileSystem::BlockIndex, CacheEntry*> m_hash;
mutable IntrusiveList<CacheEntry, RawPtr<CacheEntry>, &CacheEntry::list_node> m_clean_list;
mutable IntrusiveList<CacheEntry, RawPtr<CacheEntry>, &CacheEntry::list_node> m_dirty_list;
KBuffer m_cached_block_data;
@ -104,17 +104,17 @@ private:
bool m_dirty { false };
};
BlockBasedFS::BlockBasedFS(FileDescription& file_description)
BlockBasedFileSystem::BlockBasedFileSystem(FileDescription& file_description)
: FileBackedFileSystem(file_description)
{
VERIFY(file_description.file().is_seekable());
}
BlockBasedFS::~BlockBasedFS()
BlockBasedFileSystem::~BlockBasedFileSystem()
{
}
KResult BlockBasedFS::write_block(BlockIndex index, const UserOrKernelBuffer& data, size_t count, size_t offset, bool allow_cache)
KResult BlockBasedFileSystem::write_block(BlockIndex index, const UserOrKernelBuffer& data, size_t count, size_t offset, bool allow_cache)
{
Locker locker(m_lock);
VERIFY(m_logical_block_size);
@ -149,7 +149,7 @@ KResult BlockBasedFS::write_block(BlockIndex index, const UserOrKernelBuffer& da
return KSuccess;
}
bool BlockBasedFS::raw_read(BlockIndex index, UserOrKernelBuffer& buffer)
bool BlockBasedFileSystem::raw_read(BlockIndex index, UserOrKernelBuffer& buffer)
{
Locker locker(m_lock);
auto base_offset = index.value() * m_logical_block_size;
@ -161,7 +161,7 @@ bool BlockBasedFS::raw_read(BlockIndex index, UserOrKernelBuffer& buffer)
return true;
}
bool BlockBasedFS::raw_write(BlockIndex index, const UserOrKernelBuffer& buffer)
bool BlockBasedFileSystem::raw_write(BlockIndex index, const UserOrKernelBuffer& buffer)
{
Locker locker(m_lock);
auto base_offset = index.value() * m_logical_block_size;
@ -173,7 +173,7 @@ bool BlockBasedFS::raw_write(BlockIndex index, const UserOrKernelBuffer& buffer)
return true;
}
bool BlockBasedFS::raw_read_blocks(BlockIndex index, size_t count, UserOrKernelBuffer& buffer)
bool BlockBasedFileSystem::raw_read_blocks(BlockIndex index, size_t count, UserOrKernelBuffer& buffer)
{
Locker locker(m_lock);
auto current = buffer;
@ -185,7 +185,7 @@ bool BlockBasedFS::raw_read_blocks(BlockIndex index, size_t count, UserOrKernelB
return true;
}
bool BlockBasedFS::raw_write_blocks(BlockIndex index, size_t count, const UserOrKernelBuffer& buffer)
bool BlockBasedFileSystem::raw_write_blocks(BlockIndex index, size_t count, const UserOrKernelBuffer& buffer)
{
Locker locker(m_lock);
auto current = buffer;
@ -197,7 +197,7 @@ bool BlockBasedFS::raw_write_blocks(BlockIndex index, size_t count, const UserOr
return true;
}
KResult BlockBasedFS::write_blocks(BlockIndex index, unsigned count, const UserOrKernelBuffer& data, bool allow_cache)
KResult BlockBasedFileSystem::write_blocks(BlockIndex index, unsigned count, const UserOrKernelBuffer& data, bool allow_cache)
{
Locker locker(m_lock);
VERIFY(m_logical_block_size);
@ -210,7 +210,7 @@ KResult BlockBasedFS::write_blocks(BlockIndex index, unsigned count, const UserO
return KSuccess;
}
KResult BlockBasedFS::read_block(BlockIndex index, UserOrKernelBuffer* buffer, size_t count, size_t offset, bool allow_cache) const
KResult BlockBasedFileSystem::read_block(BlockIndex index, UserOrKernelBuffer* buffer, size_t count, size_t offset, bool allow_cache) const
{
Locker locker(m_lock);
VERIFY(m_logical_block_size);
@ -218,7 +218,7 @@ KResult BlockBasedFS::read_block(BlockIndex index, UserOrKernelBuffer* buffer, s
dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::read_block {}", index);
if (!allow_cache) {
const_cast<BlockBasedFS*>(this)->flush_specific_block_if_needed(index);
const_cast<BlockBasedFileSystem*>(this)->flush_specific_block_if_needed(index);
auto base_offset = index.value() * block_size() + offset;
auto seek_result = file_description().seek(base_offset, SEEK_SET);
if (seek_result.is_error())
@ -248,7 +248,7 @@ KResult BlockBasedFS::read_block(BlockIndex index, UserOrKernelBuffer* buffer, s
return KSuccess;
}
KResult BlockBasedFS::read_blocks(BlockIndex index, unsigned count, UserOrKernelBuffer& buffer, bool allow_cache) const
KResult BlockBasedFileSystem::read_blocks(BlockIndex index, unsigned count, UserOrKernelBuffer& buffer, bool allow_cache) const
{
Locker locker(m_lock);
VERIFY(m_logical_block_size);
@ -267,7 +267,7 @@ KResult BlockBasedFS::read_blocks(BlockIndex index, unsigned count, UserOrKernel
return KSuccess;
}
void BlockBasedFS::flush_specific_block_if_needed(BlockIndex index)
void BlockBasedFileSystem::flush_specific_block_if_needed(BlockIndex index)
{
Locker locker(m_lock);
if (!cache().is_dirty())
@ -290,7 +290,7 @@ void BlockBasedFS::flush_specific_block_if_needed(BlockIndex index)
cache().mark_clean(*entry);
}
void BlockBasedFS::flush_writes_impl()
void BlockBasedFileSystem::flush_writes_impl()
{
Locker locker(m_lock);
if (!cache().is_dirty())
@ -309,15 +309,15 @@ void BlockBasedFS::flush_writes_impl()
dbgln("{}: Flushed {} blocks to disk", class_name(), count);
}
void BlockBasedFS::flush_writes()
void BlockBasedFileSystem::flush_writes()
{
flush_writes_impl();
}
DiskCache& BlockBasedFS::cache() const
DiskCache& BlockBasedFileSystem::cache() const
{
if (!m_cache)
m_cache = make<DiskCache>(const_cast<BlockBasedFS&>(*this));
m_cache = make<DiskCache>(const_cast<BlockBasedFileSystem&>(*this));
return *m_cache;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -10,11 +10,11 @@
namespace Kernel {
class BlockBasedFS : public FileBackedFileSystem {
class BlockBasedFileSystem : public FileBackedFileSystem {
public:
TYPEDEF_DISTINCT_ORDERED_ID(u64, BlockIndex);
virtual ~BlockBasedFS() override;
virtual ~BlockBasedFileSystem() override;
u64 logical_block_size() const { return m_logical_block_size; };
@ -22,7 +22,7 @@ public:
void flush_writes_impl();
protected:
explicit BlockBasedFS(FileDescription&);
explicit BlockBasedFileSystem(FileDescription&);
KResult read_block(BlockIndex, UserOrKernelBuffer*, size_t count, size_t offset = 0, bool allow_cache = true) const;
KResult read_blocks(BlockIndex, unsigned count, UserOrKernelBuffer&, bool allow_cache = true) const;
@ -48,8 +48,8 @@ private:
}
template<>
struct AK::Formatter<Kernel::BlockBasedFS::BlockIndex> : AK::Formatter<FormatString> {
void format(FormatBuilder& builder, Kernel::BlockBasedFS::BlockIndex value)
struct AK::Formatter<Kernel::BlockBasedFileSystem::BlockIndex> : AK::Formatter<FormatString> {
void format(FormatBuilder& builder, Kernel::BlockBasedFileSystem::BlockIndex value)
{
return AK::Formatter<FormatString>::format(builder, "{}", value.value());
}

View file

@ -60,7 +60,7 @@ NonnullRefPtr<Ext2FS> Ext2FS::create(FileDescription& file_description)
}
Ext2FS::Ext2FS(FileDescription& file_description)
: BlockBasedFS(file_description)
: BlockBasedFileSystem(file_description)
{
}
@ -210,7 +210,7 @@ Ext2FS::BlockListShape Ext2FS::compute_block_list_shape(unsigned blocks) const
return shape;
}
KResult Ext2FSInode::write_indirect_block(BlockBasedFS::BlockIndex block, Span<BlockBasedFS::BlockIndex> blocks_indices)
KResult Ext2FSInode::write_indirect_block(BlockBasedFileSystem::BlockIndex block, Span<BlockBasedFileSystem::BlockIndex> blocks_indices)
{
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
VERIFY(blocks_indices.size() <= entries_per_block);
@ -227,7 +227,7 @@ KResult Ext2FSInode::write_indirect_block(BlockBasedFS::BlockIndex block, Span<B
return fs().write_block(block, buffer, stream.size());
}
KResult Ext2FSInode::grow_doubly_indirect_block(BlockBasedFS::BlockIndex block, size_t old_blocks_length, Span<BlockBasedFS::BlockIndex> blocks_indices, Vector<Ext2FS::BlockIndex>& new_meta_blocks, unsigned& meta_blocks)
KResult Ext2FSInode::grow_doubly_indirect_block(BlockBasedFileSystem::BlockIndex block, size_t old_blocks_length, Span<BlockBasedFileSystem::BlockIndex> blocks_indices, Vector<Ext2FS::BlockIndex>& new_meta_blocks, unsigned& meta_blocks)
{
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
const auto entries_per_doubly_indirect_block = entries_per_block * entries_per_block;
@ -269,7 +269,7 @@ KResult Ext2FSInode::grow_doubly_indirect_block(BlockBasedFS::BlockIndex block,
return fs().write_block(block, buffer, stream.size());
}
KResult Ext2FSInode::shrink_doubly_indirect_block(BlockBasedFS::BlockIndex block, size_t old_blocks_length, size_t new_blocks_length, unsigned& meta_blocks)
KResult Ext2FSInode::shrink_doubly_indirect_block(BlockBasedFileSystem::BlockIndex block, size_t old_blocks_length, size_t new_blocks_length, unsigned& meta_blocks)
{
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
const auto entries_per_doubly_indirect_block = entries_per_block * entries_per_block;
@ -304,7 +304,7 @@ KResult Ext2FSInode::shrink_doubly_indirect_block(BlockBasedFS::BlockIndex block
return KSuccess;
}
KResult Ext2FSInode::grow_triply_indirect_block(BlockBasedFS::BlockIndex block, size_t old_blocks_length, Span<BlockBasedFS::BlockIndex> blocks_indices, Vector<Ext2FS::BlockIndex>& new_meta_blocks, unsigned& meta_blocks)
KResult Ext2FSInode::grow_triply_indirect_block(BlockBasedFileSystem::BlockIndex block, size_t old_blocks_length, Span<BlockBasedFileSystem::BlockIndex> blocks_indices, Vector<Ext2FS::BlockIndex>& new_meta_blocks, unsigned& meta_blocks)
{
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
const auto entries_per_doubly_indirect_block = entries_per_block * entries_per_block;
@ -349,7 +349,7 @@ KResult Ext2FSInode::grow_triply_indirect_block(BlockBasedFS::BlockIndex block,
return fs().write_block(block, buffer, stream.size());
}
KResult Ext2FSInode::shrink_triply_indirect_block(BlockBasedFS::BlockIndex block, size_t old_blocks_length, size_t new_blocks_length, unsigned& meta_blocks)
KResult Ext2FSInode::shrink_triply_indirect_block(BlockBasedFileSystem::BlockIndex block, size_t old_blocks_length, size_t new_blocks_length, unsigned& meta_blocks)
{
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
const auto entries_per_doubly_indirect_block = entries_per_block * entries_per_block;
@ -422,7 +422,7 @@ KResult Ext2FSInode::flush_block_list()
bool inode_dirty = false;
VERIFY(new_shape.direct_blocks <= EXT2_NDIR_BLOCKS);
for (unsigned i = 0; i < new_shape.direct_blocks; ++i) {
if (BlockBasedFS::BlockIndex(m_raw_inode.i_block[i]) != m_block_list[output_block_index])
if (BlockBasedFileSystem::BlockIndex(m_raw_inode.i_block[i]) != m_block_list[output_block_index])
inode_dirty = true;
m_raw_inode.i_block[i] = m_block_list[output_block_index].value();
++output_block_index;
@ -708,7 +708,7 @@ void Ext2FS::flush_writes()
}
}
BlockBasedFS::flush_writes();
BlockBasedFileSystem::flush_writes();
// Uncache Inodes that are only kept alive by the index-to-inode lookup cache.
// We don't uncache Inodes that are being watched by at least one InodeWatcher.
@ -855,8 +855,8 @@ KResultOr<size_t> Ext2FSInode::read_bytes(off_t offset, size_t count, UserOrKern
const int block_size = fs().block_size();
BlockBasedFS::BlockIndex first_block_logical_index = offset / block_size;
BlockBasedFS::BlockIndex last_block_logical_index = (offset + count) / block_size;
BlockBasedFileSystem::BlockIndex first_block_logical_index = offset / block_size;
BlockBasedFileSystem::BlockIndex last_block_logical_index = (offset + count) / block_size;
if (last_block_logical_index >= m_block_list.size())
last_block_logical_index = m_block_list.size() - 1;
@ -1009,8 +1009,8 @@ KResultOr<size_t> Ext2FSInode::write_bytes(off_t offset, size_t count, const Use
return EIO;
}
BlockBasedFS::BlockIndex first_block_logical_index = offset / block_size;
BlockBasedFS::BlockIndex last_block_logical_index = (offset + count) / block_size;
BlockBasedFileSystem::BlockIndex first_block_logical_index = offset / block_size;
BlockBasedFileSystem::BlockIndex last_block_logical_index = (offset + count) / block_size;
if (last_block_logical_index >= m_block_list.size())
last_block_logical_index = m_block_list.size() - 1;

View file

@ -61,27 +61,27 @@ private:
KResult write_directory(Vector<Ext2FSDirectoryEntry>&);
KResult populate_lookup_cache() const;
KResult resize(u64);
KResult write_indirect_block(BlockBasedFS::BlockIndex, Span<BlockBasedFS::BlockIndex>);
KResult grow_doubly_indirect_block(BlockBasedFS::BlockIndex, size_t, Span<BlockBasedFS::BlockIndex>, Vector<BlockBasedFS::BlockIndex>&, unsigned&);
KResult shrink_doubly_indirect_block(BlockBasedFS::BlockIndex, size_t, size_t, unsigned&);
KResult grow_triply_indirect_block(BlockBasedFS::BlockIndex, size_t, Span<BlockBasedFS::BlockIndex>, Vector<BlockBasedFS::BlockIndex>&, unsigned&);
KResult shrink_triply_indirect_block(BlockBasedFS::BlockIndex, size_t, size_t, unsigned&);
KResult write_indirect_block(BlockBasedFileSystem::BlockIndex, Span<BlockBasedFileSystem::BlockIndex>);
KResult grow_doubly_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, Span<BlockBasedFileSystem::BlockIndex>, Vector<BlockBasedFileSystem::BlockIndex>&, unsigned&);
KResult shrink_doubly_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, size_t, unsigned&);
KResult grow_triply_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, Span<BlockBasedFileSystem::BlockIndex>, Vector<BlockBasedFileSystem::BlockIndex>&, unsigned&);
KResult shrink_triply_indirect_block(BlockBasedFileSystem::BlockIndex, size_t, size_t, unsigned&);
KResult flush_block_list();
Vector<BlockBasedFS::BlockIndex> compute_block_list() const;
Vector<BlockBasedFS::BlockIndex> compute_block_list_with_meta_blocks() const;
Vector<BlockBasedFS::BlockIndex> compute_block_list_impl(bool include_block_list_blocks) const;
Vector<BlockBasedFS::BlockIndex> compute_block_list_impl_internal(const ext2_inode& e2inode, bool include_block_list_blocks) const;
Vector<BlockBasedFileSystem::BlockIndex> compute_block_list() const;
Vector<BlockBasedFileSystem::BlockIndex> compute_block_list_with_meta_blocks() const;
Vector<BlockBasedFileSystem::BlockIndex> compute_block_list_impl(bool include_block_list_blocks) const;
Vector<BlockBasedFileSystem::BlockIndex> compute_block_list_impl_internal(const ext2_inode& e2inode, bool include_block_list_blocks) const;
Ext2FS& fs();
const Ext2FS& fs() const;
Ext2FSInode(Ext2FS&, InodeIndex);
mutable Vector<BlockBasedFS::BlockIndex> m_block_list;
mutable Vector<BlockBasedFileSystem::BlockIndex> m_block_list;
mutable HashMap<String, InodeIndex> m_lookup_cache;
ext2_inode m_raw_inode;
};
class Ext2FS final : public BlockBasedFS {
class Ext2FS final : public BlockBasedFileSystem {
friend class Ext2FSInode;
public: