diff --git a/Kernel/FileSystem/BlockBasedFileSystem.cpp b/Kernel/FileSystem/BlockBasedFileSystem.cpp index 6143f3472e..d070df16ea 100644 --- a/Kernel/FileSystem/BlockBasedFileSystem.cpp +++ b/Kernel/FileSystem/BlockBasedFileSystem.cpp @@ -148,7 +148,7 @@ ErrorOr BlockBasedFileSystem::initialize_while_locked() ErrorOr BlockBasedFileSystem::write_block(BlockIndex index, UserOrKernelBuffer const& data, size_t count, u64 offset, bool allow_cache) { - VERIFY(m_logical_block_size); + VERIFY(m_device_block_size); VERIFY(offset + count <= block_size()); dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::write_block {}, size={}", index, count); @@ -183,17 +183,17 @@ ErrorOr BlockBasedFileSystem::write_block(BlockIndex index, UserOrKernelBu ErrorOr BlockBasedFileSystem::raw_read(BlockIndex index, UserOrKernelBuffer& buffer) { - auto base_offset = index.value() * m_logical_block_size; - auto nread = TRY(file_description().read(buffer, base_offset, m_logical_block_size)); - VERIFY(nread == m_logical_block_size); + auto base_offset = index.value() * m_device_block_size; + auto nread = TRY(file_description().read(buffer, base_offset, m_device_block_size)); + VERIFY(nread == m_device_block_size); return {}; } ErrorOr BlockBasedFileSystem::raw_write(BlockIndex index, UserOrKernelBuffer const& buffer) { - auto base_offset = index.value() * m_logical_block_size; - auto nwritten = TRY(file_description().write(base_offset, buffer, m_logical_block_size)); - VERIFY(nwritten == m_logical_block_size); + auto base_offset = index.value() * m_device_block_size; + auto nwritten = TRY(file_description().write(base_offset, buffer, m_device_block_size)); + VERIFY(nwritten == m_device_block_size); return {}; } @@ -202,7 +202,7 @@ ErrorOr BlockBasedFileSystem::raw_read_blocks(BlockIndex index, size_t cou auto current = buffer; for (auto block = index.value(); block < (index.value() + count); block++) { TRY(raw_read(BlockIndex { block }, current)); - current = current.offset(logical_block_size()); + current = current.offset(device_block_size()); } return {}; } @@ -212,14 +212,14 @@ ErrorOr BlockBasedFileSystem::raw_write_blocks(BlockIndex index, size_t co auto current = buffer; for (auto block = index.value(); block < (index.value() + count); block++) { TRY(raw_write(block, current)); - current = current.offset(logical_block_size()); + current = current.offset(device_block_size()); } return {}; } ErrorOr BlockBasedFileSystem::write_blocks(BlockIndex index, unsigned count, UserOrKernelBuffer const& data, bool allow_cache) { - VERIFY(m_logical_block_size); + VERIFY(m_device_block_size); dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::write_blocks {}, count={}", index, count); for (unsigned i = 0; i < count; ++i) { TRY(write_block(BlockIndex { index.value() + i }, data.offset(i * block_size()), block_size(), 0, allow_cache)); @@ -229,7 +229,7 @@ ErrorOr BlockBasedFileSystem::write_blocks(BlockIndex index, unsigned coun ErrorOr BlockBasedFileSystem::read_block(BlockIndex index, UserOrKernelBuffer* buffer, size_t count, u64 offset, bool allow_cache) const { - VERIFY(m_logical_block_size); + VERIFY(m_device_block_size); VERIFY(offset + count <= block_size()); dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::read_block {}", index); @@ -258,7 +258,7 @@ ErrorOr BlockBasedFileSystem::read_block(BlockIndex index, UserOrKernelBuf ErrorOr BlockBasedFileSystem::read_blocks(BlockIndex index, unsigned count, UserOrKernelBuffer& buffer, bool allow_cache) const { - VERIFY(m_logical_block_size); + VERIFY(m_device_block_size); if (!count) return EINVAL; if (count == 1) diff --git a/Kernel/FileSystem/BlockBasedFileSystem.h b/Kernel/FileSystem/BlockBasedFileSystem.h index c14e389231..3fb80e46ff 100644 --- a/Kernel/FileSystem/BlockBasedFileSystem.h +++ b/Kernel/FileSystem/BlockBasedFileSystem.h @@ -17,7 +17,7 @@ public: virtual ~BlockBasedFileSystem() override; - u64 logical_block_size() const { return m_logical_block_size; } + u64 device_block_size() const { return m_device_block_size; } virtual void flush_writes() override; void flush_writes_impl(); @@ -39,7 +39,7 @@ protected: ErrorOr write_block(BlockIndex, UserOrKernelBuffer const&, size_t count, u64 offset = 0, bool allow_cache = true); ErrorOr write_blocks(BlockIndex, unsigned count, UserOrKernelBuffer const&, bool allow_cache = true); - u64 m_logical_block_size { 512 }; + u64 m_device_block_size { 512 }; void remove_disk_cache_before_last_unmount(); diff --git a/Kernel/FileSystem/Ext2FS/FileSystem.cpp b/Kernel/FileSystem/Ext2FS/FileSystem.cpp index b782ac1c5b..489fd56c8e 100644 --- a/Kernel/FileSystem/Ext2FS/FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FS/FileSystem.cpp @@ -30,12 +30,12 @@ ErrorOr Ext2FS::flush_super_block() { MutexLocker locker(m_lock); auto super_block_buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)&m_super_block); - auto const superblock_physical_block_count = (sizeof(ext2_super_block) / logical_block_size()); + auto const superblock_physical_block_count = (sizeof(ext2_super_block) / device_block_size()); // FIXME: We currently have no ability of writing within a device block, but the ability to do so would allow us to use device block sizes larger than 1024. - VERIFY((sizeof(ext2_super_block) % logical_block_size()) == 0); + VERIFY((sizeof(ext2_super_block) % device_block_size()) == 0); // First superblock is always at offset 1024 (physical block index 2). - TRY(raw_write_blocks(1024 / logical_block_size(), superblock_physical_block_count, super_block_buffer)); + TRY(raw_write_blocks(1024 / device_block_size(), superblock_physical_block_count, super_block_buffer)); auto is_sparse = has_flag(get_features_readonly(), FeaturesReadOnly::SparseSuperblock); @@ -70,9 +70,9 @@ ErrorOr Ext2FS::initialize_while_locked() VERIFY(m_lock.is_locked()); VERIFY(!is_initialized_while_locked()); - VERIFY((sizeof(ext2_super_block) % logical_block_size()) == 0); + VERIFY((sizeof(ext2_super_block) % device_block_size()) == 0); auto super_block_buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)&m_super_block); - TRY(raw_read_blocks(1024 / logical_block_size(), (sizeof(ext2_super_block) / logical_block_size()), super_block_buffer)); + TRY(raw_read_blocks(1024 / device_block_size(), (sizeof(ext2_super_block) / device_block_size()), super_block_buffer)); auto const& super_block = this->super_block(); if constexpr (EXT2_DEBUG) { diff --git a/Kernel/FileSystem/FATFS/FileSystem.cpp b/Kernel/FileSystem/FATFS/FileSystem.cpp index 30c143a3de..10172aaa0f 100644 --- a/Kernel/FileSystem/FATFS/FileSystem.cpp +++ b/Kernel/FileSystem/FATFS/FileSystem.cpp @@ -31,7 +31,7 @@ ErrorOr FATFS::initialize_while_locked() VERIFY(m_lock.is_locked()); VERIFY(!is_initialized_while_locked()); - m_boot_record = TRY(KBuffer::try_create_with_size("FATFS: Boot Record"sv, m_logical_block_size)); + m_boot_record = TRY(KBuffer::try_create_with_size("FATFS: Boot Record"sv, m_device_block_size)); auto boot_record_buffer = UserOrKernelBuffer::for_kernel_buffer(m_boot_record->data()); TRY(raw_read(0, boot_record_buffer)); @@ -62,10 +62,10 @@ ErrorOr FATFS::initialize_while_locked() return EINVAL; } - m_logical_block_size = boot_record()->bytes_per_sector; - set_block_size(m_logical_block_size); + m_device_block_size = boot_record()->bytes_per_sector; + set_block_size(m_device_block_size); - u32 root_directory_sectors = ((boot_record()->root_directory_entry_count * sizeof(FATEntry)) + (m_logical_block_size - 1)) / m_logical_block_size; + u32 root_directory_sectors = ((boot_record()->root_directory_entry_count * sizeof(FATEntry)) + (m_device_block_size - 1)) / m_device_block_size; m_first_data_sector = boot_record()->reserved_sector_count + (boot_record()->fat_count * boot_record()->sectors_per_fat) + root_directory_sectors; TRY(BlockBasedFileSystem::initialize_while_locked()); diff --git a/Kernel/FileSystem/FATFS/Inode.cpp b/Kernel/FileSystem/FATFS/Inode.cpp index 33acb1e687..8f345c3869 100644 --- a/Kernel/FileSystem/FATFS/Inode.cpp +++ b/Kernel/FileSystem/FATFS/Inode.cpp @@ -52,7 +52,7 @@ ErrorOr> FATInode::compute_block_list() Vector block_list; - auto fat_sector = TRY(KBuffer::try_create_with_size("FATFS: FAT read buffer"sv, fs().m_logical_block_size)); + auto fat_sector = TRY(KBuffer::try_create_with_size("FATFS: FAT read buffer"sv, fs().m_device_block_size)); auto fat_sector_buffer = UserOrKernelBuffer::for_kernel_buffer(fat_sector->data()); while (cluster < no_more_clusters) { @@ -63,8 +63,8 @@ ErrorOr> FATInode::compute_block_list() block_list.append(BlockBasedFileSystem::BlockIndex { first_block.value() + i }); u32 fat_offset = cluster * sizeof(u32); - u32 fat_sector_index = fs().boot_record()->reserved_sector_count + (fat_offset / fs().m_logical_block_size); - u32 entry_offset = fat_offset % fs().m_logical_block_size; + u32 fat_sector_index = fs().boot_record()->reserved_sector_count + (fat_offset / fs().m_device_block_size); + u32 entry_offset = fat_offset % fs().m_device_block_size; TRY(fs().raw_read(fat_sector_index, fat_sector_buffer)); @@ -87,13 +87,13 @@ ErrorOr> FATInode::read_block_list() auto builder = TRY(KBufferBuilder::try_create()); u8 buffer[512]; - VERIFY(fs().m_logical_block_size <= sizeof(buffer)); + VERIFY(fs().m_device_block_size <= sizeof(buffer)); auto buf = UserOrKernelBuffer::for_kernel_buffer(buffer); for (BlockBasedFileSystem::BlockIndex block : m_block_list) { dbgln_if(FAT_DEBUG, "FATFS: reading block: {}", block); TRY(fs().raw_read(block, buf)); - TRY(builder.append((char const*)buffer, fs().m_logical_block_size)); + TRY(builder.append((char const*)buffer, fs().m_device_block_size)); } auto blocks = builder.build(); @@ -207,9 +207,9 @@ ErrorOr FATInode::read_bytes_locked(off_t offset, size_t size, UserOrKer // FIXME: Read only the needed blocks instead of the whole file auto blocks = TRY(const_cast(*this).read_block_list()); - TRY(buffer.write(blocks->data() + offset, min(size, m_block_list.size() * fs().m_logical_block_size - offset))); + TRY(buffer.write(blocks->data() + offset, min(size, m_block_list.size() * fs().m_device_block_size - offset))); - return min(size, m_block_list.size() * fs().m_logical_block_size - offset); + return min(size, m_block_list.size() * fs().m_device_block_size - offset); } InodeMetadata FATInode::metadata() const diff --git a/Kernel/FileSystem/ISO9660FS/DirectoryIterator.cpp b/Kernel/FileSystem/ISO9660FS/DirectoryIterator.cpp index b127d85c7a..cedd8d0bc8 100644 --- a/Kernel/FileSystem/ISO9660FS/DirectoryIterator.cpp +++ b/Kernel/FileSystem/ISO9660FS/DirectoryIterator.cpp @@ -78,8 +78,8 @@ bool ISO9660DirectoryIterator::skip() // need to snap to the next logical block, because directory records // cannot span multiple logical blocks. u32 remaining_bytes = m_current_directory.entry->length - m_current_directory.offset; - if (remaining_bytes > m_fs.logical_block_size()) { - m_current_directory.offset += remaining_bytes % m_fs.logical_block_size(); + if (remaining_bytes > m_fs.device_block_size()) { + m_current_directory.offset += remaining_bytes % m_fs.device_block_size(); get_header(); dbgln_if(ISO9660_VERY_DEBUG, "skip(): Snapped to next logical block (succeeded)"); diff --git a/Kernel/FileSystem/ISO9660FS/FileSystem.cpp b/Kernel/FileSystem/ISO9660FS/FileSystem.cpp index a6b18fe391..8e231ed732 100644 --- a/Kernel/FileSystem/ISO9660FS/FileSystem.cpp +++ b/Kernel/FileSystem/ISO9660FS/FileSystem.cpp @@ -25,7 +25,7 @@ ISO9660FS::ISO9660FS(OpenFileDescription& description) : BlockBasedFileSystem(description) { set_block_size(logical_sector_size); - m_logical_block_size = logical_sector_size; + m_device_block_size = logical_sector_size; } ISO9660FS::~ISO9660FS() = default; @@ -91,7 +91,7 @@ ErrorOr ISO9660FS::parse_volume_set() { VERIFY(!m_primary_volume); - auto block = TRY(KBuffer::try_create_with_size("ISO9660FS: Temporary volume descriptor storage"sv, m_logical_block_size, Memory::Region::Access::Read | Memory::Region::Access::Write)); + auto block = TRY(KBuffer::try_create_with_size("ISO9660FS: Temporary volume descriptor storage"sv, m_device_block_size, Memory::Region::Access::Read | Memory::Region::Access::Write)); auto block_buffer = UserOrKernelBuffer::for_kernel_buffer(block->data()); auto current_block_index = first_data_area_block; @@ -136,7 +136,7 @@ all_headers_read: return EIO; } - m_logical_block_size = LittleEndian { m_primary_volume->logical_block_size.little }; + m_device_block_size = LittleEndian { m_primary_volume->logical_block_size.little }; return {}; } @@ -242,14 +242,14 @@ ErrorOr> ISO9660FS::directory_entry_f m_directory_entry_cache.remove(m_directory_entry_cache.begin()); } - if (!(data_length % logical_block_size() == 0)) { + if (!(data_length % device_block_size() == 0)) { dbgln_if(ISO9660_DEBUG, "Found a directory with non-logical block size aligned data length!"); return EIO; } auto blocks = TRY(KBuffer::try_create_with_size("ISO9660FS: Directory traversal buffer"sv, data_length, Memory::Region::Access::Read | Memory::Region::Access::Write)); auto blocks_buffer = UserOrKernelBuffer::for_kernel_buffer(blocks->data()); - TRY(raw_read_blocks(BlockBasedFileSystem::BlockIndex { extent_location }, data_length / logical_block_size(), blocks_buffer)); + TRY(raw_read_blocks(BlockBasedFileSystem::BlockIndex { extent_location }, data_length / device_block_size(), blocks_buffer)); auto entry = TRY(ISO9660FSDirectoryEntry::try_create(extent_location, data_length, move(blocks))); m_directory_entry_cache.set(key, entry); diff --git a/Kernel/FileSystem/ISO9660FS/Inode.cpp b/Kernel/FileSystem/ISO9660FS/Inode.cpp index 3f2d4f121b..bd225878cb 100644 --- a/Kernel/FileSystem/ISO9660FS/Inode.cpp +++ b/Kernel/FileSystem/ISO9660FS/Inode.cpp @@ -20,17 +20,17 @@ ErrorOr ISO9660Inode::read_bytes_locked(off_t offset, size_t size, UserO if (static_cast(offset) >= data_length) return 0; - auto block = TRY(KBuffer::try_create_with_size("ISO9660FS: Inode read buffer"sv, fs().m_logical_block_size)); + auto block = TRY(KBuffer::try_create_with_size("ISO9660FS: Inode read buffer"sv, fs().device_block_size())); auto block_buffer = UserOrKernelBuffer::for_kernel_buffer(block->data()); size_t total_bytes = min(size, data_length - offset); size_t nread = 0; - size_t blocks_already_read = offset / fs().m_logical_block_size; - size_t initial_offset = offset % fs().m_logical_block_size; + size_t blocks_already_read = offset / fs().device_block_size(); + size_t initial_offset = offset % fs().device_block_size(); auto current_block_index = BlockBasedFileSystem::BlockIndex { extent_location + blocks_already_read }; while (nread != total_bytes) { - size_t bytes_to_read = min(total_bytes - nread, fs().logical_block_size() - initial_offset); + size_t bytes_to_read = min(total_bytes - nread, fs().device_block_size() - initial_offset); auto buffer_offset = buffer.offset(nread); dbgln_if(ISO9660_VERY_DEBUG, "ISO9660Inode::read_bytes: Reading {} bytes into buffer offset {}/{}, logical block index: {}", bytes_to_read, nread, total_bytes, current_block_index.value());