1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 19:05:08 +00:00

Kernel/FileSystem: Rename block_size -> logical_block_size

Since this is the block size that file system drivers *should* set,
let's name it the logical block size, just like most file systems such
as ext2 already do anyways.
This commit is contained in:
kleines Filmröllchen 2023-07-24 22:17:19 +02:00 committed by Jelle Raaijmakers
parent d1e6e6110d
commit c8d7bcede6
8 changed files with 56 additions and 56 deletions

View file

@ -40,7 +40,7 @@ ErrorOr<void> Ext2FSInode::write_indirect_block(BlockBasedFileSystem::BlockIndex
auto const entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
VERIFY(blocks_indices.size() <= entries_per_block);
auto block_contents = TRY(ByteBuffer::create_zeroed(fs().block_size()));
auto block_contents = TRY(ByteBuffer::create_zeroed(fs().logical_block_size()));
FixedMemoryStream stream { block_contents.bytes() };
auto buffer = UserOrKernelBuffer::for_kernel_buffer(block_contents.data());
@ -61,13 +61,13 @@ ErrorOr<void> Ext2FSInode::grow_doubly_indirect_block(BlockBasedFileSystem::Bloc
VERIFY(blocks_indices.size() > old_blocks_length);
VERIFY(blocks_indices.size() <= entries_per_doubly_indirect_block);
auto block_contents = TRY(ByteBuffer::create_zeroed(fs().block_size()));
auto block_contents = TRY(ByteBuffer::create_zeroed(fs().logical_block_size()));
auto* block_as_pointers = (unsigned*)block_contents.data();
FixedMemoryStream stream { block_contents.bytes() };
auto buffer = UserOrKernelBuffer::for_kernel_buffer(block_contents.data());
if (old_blocks_length > 0) {
TRY(fs().read_block(block, &buffer, fs().block_size()));
TRY(fs().read_block(block, &buffer, fs().logical_block_size()));
}
// Grow the doubly indirect block.
@ -100,10 +100,10 @@ ErrorOr<void> Ext2FSInode::shrink_doubly_indirect_block(BlockBasedFileSystem::Bl
VERIFY(old_blocks_length >= new_blocks_length);
VERIFY(new_blocks_length <= entries_per_doubly_indirect_block);
auto block_contents = TRY(ByteBuffer::create_uninitialized(fs().block_size()));
auto block_contents = TRY(ByteBuffer::create_uninitialized(fs().logical_block_size()));
auto* block_as_pointers = (unsigned*)block_contents.data();
auto buffer = UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<u8*>(block_as_pointers));
TRY(fs().read_block(block, &buffer, fs().block_size()));
TRY(fs().read_block(block, &buffer, fs().logical_block_size()));
// Free the unused indirect blocks.
for (unsigned i = new_indirect_blocks_length; i < old_indirect_blocks_length; i++) {
@ -133,13 +133,13 @@ ErrorOr<void> Ext2FSInode::grow_triply_indirect_block(BlockBasedFileSystem::Bloc
VERIFY(blocks_indices.size() > old_blocks_length);
VERIFY(blocks_indices.size() <= entries_per_triply_indirect_block);
auto block_contents = TRY(ByteBuffer::create_zeroed(fs().block_size()));
auto block_contents = TRY(ByteBuffer::create_zeroed(fs().logical_block_size()));
auto* block_as_pointers = (unsigned*)block_contents.data();
FixedMemoryStream stream { block_contents.bytes() };
auto buffer = UserOrKernelBuffer::for_kernel_buffer(block_contents.data());
if (old_blocks_length > 0) {
TRY(fs().read_block(block, &buffer, fs().block_size()));
TRY(fs().read_block(block, &buffer, fs().logical_block_size()));
}
// Grow the triply indirect block.
@ -175,10 +175,10 @@ ErrorOr<void> Ext2FSInode::shrink_triply_indirect_block(BlockBasedFileSystem::Bl
VERIFY(old_blocks_length >= new_blocks_length);
VERIFY(new_blocks_length <= entries_per_triply_indirect_block);
auto block_contents = TRY(ByteBuffer::create_uninitialized(fs().block_size()));
auto block_contents = TRY(ByteBuffer::create_uninitialized(fs().logical_block_size()));
auto* block_as_pointers = (unsigned*)block_contents.data();
auto buffer = UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<u8*>(block_as_pointers));
TRY(fs().read_block(block, &buffer, fs().block_size()));
TRY(fs().read_block(block, &buffer, fs().logical_block_size()));
// Shrink the doubly indirect blocks.
for (unsigned i = new_triply_indirect_blocks_length; i < old_triply_indirect_blocks_length; i++) {
@ -211,7 +211,7 @@ ErrorOr<void> Ext2FSInode::flush_block_list()
}
// NOTE: There is a mismatch between i_blocks and blocks.size() since i_blocks includes meta blocks and blocks.size() does not.
auto const old_block_count = ceil_div(size(), static_cast<u64>(fs().block_size()));
auto const old_block_count = ceil_div(size(), static_cast<u64>(fs().logical_block_size()));
auto old_shape = fs().compute_block_list_shape(old_block_count);
auto const new_shape = fs().compute_block_list_shape(m_block_list.size());
@ -221,7 +221,7 @@ ErrorOr<void> Ext2FSInode::flush_block_list()
new_meta_blocks = TRY(fs().allocate_blocks(fs().group_index_from_inode(index()), new_shape.meta_blocks - old_shape.meta_blocks));
}
m_raw_inode.i_blocks = (m_block_list.size() + new_shape.meta_blocks) * (fs().block_size() / 512);
m_raw_inode.i_blocks = (m_block_list.size() + new_shape.meta_blocks) * (fs().logical_block_size() / 512);
dbgln_if(EXT2_BLOCKLIST_DEBUG, "Ext2FSInode[{}]::flush_block_list(): Old shape=({};{};{};{}:{}), new shape=({};{};{};{}:{})", identifier(), old_shape.direct_blocks, old_shape.indirect_blocks, old_shape.doubly_indirect_blocks, old_shape.triply_indirect_blocks, old_shape.meta_blocks, new_shape.direct_blocks, new_shape.indirect_blocks, new_shape.doubly_indirect_blocks, new_shape.triply_indirect_blocks, new_shape.meta_blocks);
unsigned output_block_index = 0;
@ -354,7 +354,7 @@ ErrorOr<Vector<Ext2FS::BlockIndex>> Ext2FSInode::compute_block_list_impl_interna
{
unsigned entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
unsigned block_count = ceil_div(size(), static_cast<u64>(fs().block_size()));
unsigned block_count = ceil_div(size(), static_cast<u64>(fs().logical_block_size()));
// If we are handling a symbolic link, the path is stored in the 60 bytes in
// the inode that are used for the 12 direct and 3 indirect block pointers,
@ -478,7 +478,7 @@ InodeMetadata Ext2FSInode::metadata() const
metadata.ctime = UnixDateTime::from_seconds_since_epoch(m_raw_inode.i_ctime);
metadata.mtime = UnixDateTime::from_seconds_since_epoch(m_raw_inode.i_mtime);
metadata.dtime = UnixDateTime::from_seconds_since_epoch(m_raw_inode.i_dtime);
metadata.block_size = fs().block_size();
metadata.block_size = fs().logical_block_size();
metadata.block_count = m_raw_inode.i_blocks;
if (Kernel::is_character_device(m_raw_inode.i_mode) || Kernel::is_block_device(m_raw_inode.i_mode)) {
@ -553,7 +553,7 @@ ErrorOr<size_t> Ext2FSInode::read_bytes_locked(off_t offset, size_t count, UserO
bool allow_cache = !description || !description->is_direct();
int const block_size = fs().block_size();
int const block_size = fs().logical_block_size();
BlockBasedFileSystem::BlockIndex first_block_logical_index = offset / block_size;
BlockBasedFileSystem::BlockIndex last_block_logical_index = (offset + count) / block_size;
@ -597,7 +597,7 @@ ErrorOr<void> Ext2FSInode::resize(u64 new_size)
if (!((u32)fs().get_features_readonly() & (u32)Ext2FS::FeaturesReadOnly::FileSize64bits) && (new_size >= static_cast<u32>(-1)))
return ENOSPC;
u64 block_size = fs().block_size();
u64 block_size = fs().logical_block_size();
auto blocks_needed_before = ceil_div(old_size, block_size);
auto blocks_needed_after = ceil_div(new_size, block_size);
@ -683,7 +683,7 @@ ErrorOr<size_t> Ext2FSInode::write_bytes_locked(off_t offset, size_t count, User
bool allow_cache = !description || !description->is_direct();
auto const block_size = fs().block_size();
auto const block_size = fs().logical_block_size();
auto new_size = max(static_cast<u64>(offset) + count, size());
TRY(resize(new_size));
@ -734,7 +734,7 @@ ErrorOr<void> Ext2FSInode::traverse_as_directory(Function<ErrorOr<void>(FileSyst
u8 buffer[max_block_size];
auto buf = UserOrKernelBuffer::for_kernel_buffer(buffer);
auto block_size = fs().block_size();
auto block_size = fs().logical_block_size();
auto file_size = size();
// Directory entries are guaranteed not to span multiple blocks,
@ -761,7 +761,7 @@ ErrorOr<void> Ext2FSInode::traverse_as_directory(Function<ErrorOr<void>(FileSyst
ErrorOr<void> Ext2FSInode::write_directory(Vector<Ext2FSDirectoryEntry>& entries)
{
MutexLocker locker(m_inode_lock);
auto block_size = fs().block_size();
auto block_size = fs().logical_block_size();
// Calculate directory size and record length of entries so that
// the following constraints are met: