mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:22:45 +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:
		
							parent
							
								
									d1e6e6110d
								
							
						
					
					
						commit
						c8d7bcede6
					
				
					 8 changed files with 56 additions and 56 deletions
				
			
		|  | @ -27,7 +27,7 @@ public: | ||||||
|         , m_entries(move(entries_buffer)) |         , m_entries(move(entries_buffer)) | ||||||
|     { |     { | ||||||
|         for (size_t i = 0; i < EntryCount; ++i) { |         for (size_t i = 0; i < EntryCount; ++i) { | ||||||
|             entries()[i].data = m_cached_block_data->data() + i * m_fs->block_size(); |             entries()[i].data = m_cached_block_data->data() + i * m_fs->logical_block_size(); | ||||||
|             m_clean_list.append(entries()[i]); |             m_clean_list.append(entries()[i]); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | @ -135,8 +135,8 @@ ErrorOr<void> BlockBasedFileSystem::initialize_while_locked() | ||||||
| { | { | ||||||
|     VERIFY(m_lock.is_locked()); |     VERIFY(m_lock.is_locked()); | ||||||
|     VERIFY(!is_initialized_while_locked()); |     VERIFY(!is_initialized_while_locked()); | ||||||
|     VERIFY(block_size() != 0); |     VERIFY(logical_block_size() != 0); | ||||||
|     auto cached_block_data = TRY(KBuffer::try_create_with_size("BlockBasedFS: Cache blocks"sv, DiskCache::EntryCount * block_size())); |     auto cached_block_data = TRY(KBuffer::try_create_with_size("BlockBasedFS: Cache blocks"sv, DiskCache::EntryCount * logical_block_size())); | ||||||
|     auto entries_data = TRY(KBuffer::try_create_with_size("BlockBasedFS: Cache entries"sv, DiskCache::EntryCount * sizeof(CacheEntry))); |     auto entries_data = TRY(KBuffer::try_create_with_size("BlockBasedFS: Cache entries"sv, DiskCache::EntryCount * sizeof(CacheEntry))); | ||||||
|     auto disk_cache = TRY(adopt_nonnull_own_or_enomem(new (nothrow) DiskCache(*this, move(cached_block_data), move(entries_data)))); |     auto disk_cache = TRY(adopt_nonnull_own_or_enomem(new (nothrow) DiskCache(*this, move(cached_block_data), move(entries_data)))); | ||||||
| 
 | 
 | ||||||
|  | @ -149,7 +149,7 @@ ErrorOr<void> BlockBasedFileSystem::initialize_while_locked() | ||||||
| ErrorOr<void> BlockBasedFileSystem::write_block(BlockIndex index, UserOrKernelBuffer const& data, size_t count, u64 offset, bool allow_cache) | ErrorOr<void> BlockBasedFileSystem::write_block(BlockIndex index, UserOrKernelBuffer const& data, size_t count, u64 offset, bool allow_cache) | ||||||
| { | { | ||||||
|     VERIFY(m_device_block_size); |     VERIFY(m_device_block_size); | ||||||
|     VERIFY(offset + count <= block_size()); |     VERIFY(offset + count <= logical_block_size()); | ||||||
|     dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::write_block {}, size={}", index, count); |     dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::write_block {}, size={}", index, count); | ||||||
| 
 | 
 | ||||||
|     // NOTE: We copy the `data` to write into a local buffer before taking the cache lock.
 |     // NOTE: We copy the `data` to write into a local buffer before taking the cache lock.
 | ||||||
|  | @ -162,16 +162,16 @@ ErrorOr<void> BlockBasedFileSystem::write_block(BlockIndex index, UserOrKernelBu | ||||||
|     return m_cache.with_exclusive([&](auto& cache) -> ErrorOr<void> { |     return m_cache.with_exclusive([&](auto& cache) -> ErrorOr<void> { | ||||||
|         if (!allow_cache) { |         if (!allow_cache) { | ||||||
|             flush_specific_block_if_needed(index); |             flush_specific_block_if_needed(index); | ||||||
|             u64 base_offset = index.value() * block_size() + offset; |             u64 base_offset = index.value() * logical_block_size() + offset; | ||||||
|             auto nwritten = TRY(file_description().write(base_offset, data, count)); |             auto nwritten = TRY(file_description().write(base_offset, data, count)); | ||||||
|             VERIFY(nwritten == count); |             VERIFY(nwritten == count); | ||||||
|             return {}; |             return {}; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         auto entry = TRY(cache->ensure(index)); |         auto entry = TRY(cache->ensure(index)); | ||||||
|         if (count < block_size()) { |         if (count < logical_block_size()) { | ||||||
|             // Fill the cache first.
 |             // Fill the cache first.
 | ||||||
|             TRY(read_block(index, nullptr, block_size())); |             TRY(read_block(index, nullptr, logical_block_size())); | ||||||
|         } |         } | ||||||
|         memcpy(entry->data + offset, buffered_data.data(), count); |         memcpy(entry->data + offset, buffered_data.data(), count); | ||||||
| 
 | 
 | ||||||
|  | @ -222,7 +222,7 @@ ErrorOr<void> BlockBasedFileSystem::write_blocks(BlockIndex index, unsigned coun | ||||||
|     VERIFY(m_device_block_size); |     VERIFY(m_device_block_size); | ||||||
|     dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::write_blocks {}, count={}", index, count); |     dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::write_blocks {}, count={}", index, count); | ||||||
|     for (unsigned i = 0; i < count; ++i) { |     for (unsigned i = 0; i < count; ++i) { | ||||||
|         TRY(write_block(BlockIndex { index.value() + i }, data.offset(i * block_size()), block_size(), 0, allow_cache)); |         TRY(write_block(BlockIndex { index.value() + i }, data.offset(i * logical_block_size()), logical_block_size(), 0, allow_cache)); | ||||||
|     } |     } | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
|  | @ -230,13 +230,13 @@ ErrorOr<void> BlockBasedFileSystem::write_blocks(BlockIndex index, unsigned coun | ||||||
| ErrorOr<void> BlockBasedFileSystem::read_block(BlockIndex index, UserOrKernelBuffer* buffer, size_t count, u64 offset, bool allow_cache) const | ErrorOr<void> BlockBasedFileSystem::read_block(BlockIndex index, UserOrKernelBuffer* buffer, size_t count, u64 offset, bool allow_cache) const | ||||||
| { | { | ||||||
|     VERIFY(m_device_block_size); |     VERIFY(m_device_block_size); | ||||||
|     VERIFY(offset + count <= block_size()); |     VERIFY(offset + count <= logical_block_size()); | ||||||
|     dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::read_block {}", index); |     dbgln_if(BBFS_DEBUG, "BlockBasedFileSystem::read_block {}", index); | ||||||
| 
 | 
 | ||||||
|     return m_cache.with_exclusive([&](auto& cache) -> ErrorOr<void> { |     return m_cache.with_exclusive([&](auto& cache) -> ErrorOr<void> { | ||||||
|         if (!allow_cache) { |         if (!allow_cache) { | ||||||
|             const_cast<BlockBasedFileSystem*>(this)->flush_specific_block_if_needed(index); |             const_cast<BlockBasedFileSystem*>(this)->flush_specific_block_if_needed(index); | ||||||
|             u64 base_offset = index.value() * block_size() + offset; |             u64 base_offset = index.value() * logical_block_size() + offset; | ||||||
|             auto nread = TRY(file_description().read(*buffer, base_offset, count)); |             auto nread = TRY(file_description().read(*buffer, base_offset, count)); | ||||||
|             VERIFY(nread == count); |             VERIFY(nread == count); | ||||||
|             return {}; |             return {}; | ||||||
|  | @ -244,10 +244,10 @@ ErrorOr<void> BlockBasedFileSystem::read_block(BlockIndex index, UserOrKernelBuf | ||||||
| 
 | 
 | ||||||
|         auto* entry = TRY(cache->ensure(index)); |         auto* entry = TRY(cache->ensure(index)); | ||||||
|         if (!entry->has_data) { |         if (!entry->has_data) { | ||||||
|             auto base_offset = index.value() * block_size(); |             auto base_offset = index.value() * logical_block_size(); | ||||||
|             auto entry_data_buffer = UserOrKernelBuffer::for_kernel_buffer(entry->data); |             auto entry_data_buffer = UserOrKernelBuffer::for_kernel_buffer(entry->data); | ||||||
|             auto nread = TRY(file_description().read(entry_data_buffer, base_offset, block_size())); |             auto nread = TRY(file_description().read(entry_data_buffer, base_offset, logical_block_size())); | ||||||
|             VERIFY(nread == block_size()); |             VERIFY(nread == logical_block_size()); | ||||||
|             entry->has_data = true; |             entry->has_data = true; | ||||||
|         } |         } | ||||||
|         if (buffer) |         if (buffer) | ||||||
|  | @ -262,11 +262,11 @@ ErrorOr<void> BlockBasedFileSystem::read_blocks(BlockIndex index, unsigned count | ||||||
|     if (!count) |     if (!count) | ||||||
|         return EINVAL; |         return EINVAL; | ||||||
|     if (count == 1) |     if (count == 1) | ||||||
|         return read_block(index, &buffer, block_size(), 0, allow_cache); |         return read_block(index, &buffer, logical_block_size(), 0, allow_cache); | ||||||
|     auto out = buffer; |     auto out = buffer; | ||||||
|     for (unsigned i = 0; i < count; ++i) { |     for (unsigned i = 0; i < count; ++i) { | ||||||
|         TRY(read_block(BlockIndex { index.value() + i }, &out, block_size(), 0, allow_cache)); |         TRY(read_block(BlockIndex { index.value() + i }, &out, logical_block_size(), 0, allow_cache)); | ||||||
|         out = out.offset(block_size()); |         out = out.offset(logical_block_size()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return {}; |     return {}; | ||||||
|  | @ -282,9 +282,9 @@ void BlockBasedFileSystem::flush_specific_block_if_needed(BlockIndex index) | ||||||
|             return; |             return; | ||||||
|         if (!cache->entry_is_dirty(*entry)) |         if (!cache->entry_is_dirty(*entry)) | ||||||
|             return; |             return; | ||||||
|         size_t base_offset = entry->block_index.value() * block_size(); |         size_t base_offset = entry->block_index.value() * logical_block_size(); | ||||||
|         auto entry_data_buffer = UserOrKernelBuffer::for_kernel_buffer(entry->data); |         auto entry_data_buffer = UserOrKernelBuffer::for_kernel_buffer(entry->data); | ||||||
|         (void)file_description().write(base_offset, entry_data_buffer, block_size()); |         (void)file_description().write(base_offset, entry_data_buffer, logical_block_size()); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -295,9 +295,9 @@ void BlockBasedFileSystem::flush_writes_impl() | ||||||
|         if (!cache->is_dirty()) |         if (!cache->is_dirty()) | ||||||
|             return; |             return; | ||||||
|         cache->for_each_dirty_entry([&](CacheEntry& entry) { |         cache->for_each_dirty_entry([&](CacheEntry& entry) { | ||||||
|             auto base_offset = entry.block_index.value() * block_size(); |             auto base_offset = entry.block_index.value() * logical_block_size(); | ||||||
|             auto entry_data_buffer = UserOrKernelBuffer::for_kernel_buffer(entry.data); |             auto entry_data_buffer = UserOrKernelBuffer::for_kernel_buffer(entry.data); | ||||||
|             [[maybe_unused]] auto rc = file_description().write(base_offset, entry_data_buffer, block_size()); |             [[maybe_unused]] auto rc = file_description().write(base_offset, entry_data_buffer, logical_block_size()); | ||||||
|             ++count; |             ++count; | ||||||
|         }); |         }); | ||||||
|         cache->mark_all_clean(); |         cache->mark_all_clean(); | ||||||
|  |  | ||||||
|  | @ -97,13 +97,13 @@ ErrorOr<void> Ext2FS::initialize_while_locked() | ||||||
|         dmesgln("Ext2FS: Descriptor size: {}", EXT2_DESC_SIZE(&super_block)); |         dmesgln("Ext2FS: Descriptor size: {}", EXT2_DESC_SIZE(&super_block)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     set_block_size(EXT2_BLOCK_SIZE(&super_block)); |     set_logical_block_size(EXT2_BLOCK_SIZE(&super_block)); | ||||||
|     set_fragment_size(EXT2_FRAG_SIZE(&super_block)); |     set_fragment_size(EXT2_FRAG_SIZE(&super_block)); | ||||||
| 
 | 
 | ||||||
|     // Note: This depends on the block size being available.
 |     // Note: This depends on the block size being available.
 | ||||||
|     TRY(BlockBasedFileSystem::initialize_while_locked()); |     TRY(BlockBasedFileSystem::initialize_while_locked()); | ||||||
| 
 | 
 | ||||||
|     VERIFY(block_size() <= (int)max_block_size); |     VERIFY(logical_block_size() <= (int)max_block_size); | ||||||
| 
 | 
 | ||||||
|     m_block_group_count = ceil_div(super_block.s_blocks_count, super_block.s_blocks_per_group); |     m_block_group_count = ceil_div(super_block.s_blocks_count, super_block.s_blocks_per_group); | ||||||
| 
 | 
 | ||||||
|  | @ -112,9 +112,9 @@ ErrorOr<void> Ext2FS::initialize_while_locked() | ||||||
|         return EINVAL; |         return EINVAL; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     auto blocks_to_read = ceil_div(m_block_group_count * sizeof(ext2_group_desc), block_size()); |     auto blocks_to_read = ceil_div(m_block_group_count * sizeof(ext2_group_desc), logical_block_size()); | ||||||
|     BlockIndex first_block_of_bgdt = first_block_of_block_group_descriptors(); |     BlockIndex first_block_of_bgdt = first_block_of_block_group_descriptors(); | ||||||
|     m_cached_group_descriptor_table = TRY(KBuffer::try_create_with_size("Ext2FS: Block group descriptors"sv, block_size() * blocks_to_read, Memory::Region::Access::ReadWrite)); |     m_cached_group_descriptor_table = TRY(KBuffer::try_create_with_size("Ext2FS: Block group descriptors"sv, logical_block_size() * blocks_to_read, Memory::Region::Access::ReadWrite)); | ||||||
|     auto buffer = UserOrKernelBuffer::for_kernel_buffer(m_cached_group_descriptor_table->data()); |     auto buffer = UserOrKernelBuffer::for_kernel_buffer(m_cached_group_descriptor_table->data()); | ||||||
|     TRY(read_blocks(first_block_of_bgdt, blocks_to_read, buffer)); |     TRY(read_blocks(first_block_of_bgdt, blocks_to_read, buffer)); | ||||||
| 
 | 
 | ||||||
|  | @ -154,7 +154,7 @@ bool Ext2FS::find_block_containing_inode(InodeIndex inode, BlockIndex& block_ind | ||||||
| 
 | 
 | ||||||
|     u64 full_offset = ((inode.value() - 1) % inodes_per_group()) * inode_size(); |     u64 full_offset = ((inode.value() - 1) % inodes_per_group()) * inode_size(); | ||||||
|     block_index = bgd.bg_inode_table + (full_offset >> EXT2_BLOCK_SIZE_BITS(&super_block)); |     block_index = bgd.bg_inode_table + (full_offset >> EXT2_BLOCK_SIZE_BITS(&super_block)); | ||||||
|     offset = full_offset & (block_size() - 1); |     offset = full_offset & (logical_block_size() - 1); | ||||||
| 
 | 
 | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
|  | @ -380,7 +380,7 @@ Ext2FS::BlockIndex Ext2FS::first_block_of_group(GroupIndex group_index) const | ||||||
| 
 | 
 | ||||||
| Ext2FS::BlockIndex Ext2FS::first_block_of_block_group_descriptors() const | Ext2FS::BlockIndex Ext2FS::first_block_of_block_group_descriptors() const | ||||||
| { | { | ||||||
|     return block_size() == 1024 ? 2 : 1; |     return logical_block_size() == 1024 ? 2 : 1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| auto Ext2FS::group_index_from_inode(InodeIndex inode) const -> GroupIndex | auto Ext2FS::group_index_from_inode(InodeIndex inode) const -> GroupIndex | ||||||
|  | @ -442,7 +442,7 @@ ErrorOr<void> Ext2FS::set_inode_allocation_state(InodeIndex inode_index, bool ne | ||||||
| 
 | 
 | ||||||
| Ext2FS::BlockIndex Ext2FS::first_block_index() const | Ext2FS::BlockIndex Ext2FS::first_block_index() const | ||||||
| { | { | ||||||
|     return block_size() == 1024 ? 1 : 0; |     return logical_block_size() == 1024 ? 1 : 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<Ext2FS::CachedBitmap*> Ext2FS::get_bitmap_block(BlockIndex bitmap_block_index) | ErrorOr<Ext2FS::CachedBitmap*> Ext2FS::get_bitmap_block(BlockIndex bitmap_block_index) | ||||||
|  | @ -452,9 +452,9 @@ ErrorOr<Ext2FS::CachedBitmap*> Ext2FS::get_bitmap_block(BlockIndex bitmap_block_ | ||||||
|             return cached_bitmap.ptr(); |             return cached_bitmap.ptr(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     auto block = TRY(KBuffer::try_create_with_size("Ext2FS: Cached bitmap block"sv, block_size(), Memory::Region::Access::ReadWrite)); |     auto block = TRY(KBuffer::try_create_with_size("Ext2FS: Cached bitmap block"sv, logical_block_size(), Memory::Region::Access::ReadWrite)); | ||||||
|     auto buffer = UserOrKernelBuffer::for_kernel_buffer(block->data()); |     auto buffer = UserOrKernelBuffer::for_kernel_buffer(block->data()); | ||||||
|     TRY(read_block(bitmap_block_index, &buffer, block_size())); |     TRY(read_block(bitmap_block_index, &buffer, logical_block_size())); | ||||||
|     auto new_bitmap = TRY(adopt_nonnull_own_or_enomem(new (nothrow) CachedBitmap(bitmap_block_index, move(block)))); |     auto new_bitmap = TRY(adopt_nonnull_own_or_enomem(new (nothrow) CachedBitmap(bitmap_block_index, move(block)))); | ||||||
|     TRY(m_cached_bitmaps.try_append(move(new_bitmap))); |     TRY(m_cached_bitmaps.try_append(move(new_bitmap))); | ||||||
|     return m_cached_bitmaps.last().ptr(); |     return m_cached_bitmaps.last().ptr(); | ||||||
|  | @ -639,7 +639,7 @@ ErrorOr<void> Ext2FS::free_inode(Ext2FSInode& inode) | ||||||
| void Ext2FS::flush_block_group_descriptor_table() | void Ext2FS::flush_block_group_descriptor_table() | ||||||
| { | { | ||||||
|     MutexLocker locker(m_lock); |     MutexLocker locker(m_lock); | ||||||
|     auto blocks_to_write = ceil_div(m_block_group_count * sizeof(ext2_group_desc), block_size()); |     auto blocks_to_write = ceil_div(m_block_group_count * sizeof(ext2_group_desc), logical_block_size()); | ||||||
|     auto first_block_of_bgdt = first_block_of_block_group_descriptors(); |     auto first_block_of_bgdt = first_block_of_block_group_descriptors(); | ||||||
|     auto buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)block_group_descriptors()); |     auto buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)block_group_descriptors()); | ||||||
|     auto write_bgdt_to_block = [&](BlockIndex index) { |     auto write_bgdt_to_block = [&](BlockIndex index) { | ||||||
|  | @ -682,7 +682,7 @@ void Ext2FS::flush_writes() | ||||||
|         for (auto& cached_bitmap : m_cached_bitmaps) { |         for (auto& cached_bitmap : m_cached_bitmaps) { | ||||||
|             if (cached_bitmap->dirty) { |             if (cached_bitmap->dirty) { | ||||||
|                 auto buffer = UserOrKernelBuffer::for_kernel_buffer(cached_bitmap->buffer->data()); |                 auto buffer = UserOrKernelBuffer::for_kernel_buffer(cached_bitmap->buffer->data()); | ||||||
|                 if (auto result = write_block(cached_bitmap->bitmap_block_index, buffer, block_size()); result.is_error()) { |                 if (auto result = write_block(cached_bitmap->bitmap_block_index, buffer, logical_block_size()); result.is_error()) { | ||||||
|                     dbgln("Ext2FS[{}]::flush_writes(): Failed to write blocks: {}", fsid(), result.error()); |                     dbgln("Ext2FS[{}]::flush_writes(): Failed to write blocks: {}", fsid(), result.error()); | ||||||
|                 } |                 } | ||||||
|                 cached_bitmap->dirty = false; |                 cached_bitmap->dirty = false; | ||||||
|  |  | ||||||
|  | @ -40,7 +40,7 @@ ErrorOr<void> Ext2FSInode::write_indirect_block(BlockBasedFileSystem::BlockIndex | ||||||
|     auto const entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block()); |     auto const entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block()); | ||||||
|     VERIFY(blocks_indices.size() <= entries_per_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() }; |     FixedMemoryStream stream { block_contents.bytes() }; | ||||||
|     auto buffer = UserOrKernelBuffer::for_kernel_buffer(block_contents.data()); |     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() > old_blocks_length); | ||||||
|     VERIFY(blocks_indices.size() <= entries_per_doubly_indirect_block); |     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(); |     auto* block_as_pointers = (unsigned*)block_contents.data(); | ||||||
|     FixedMemoryStream stream { block_contents.bytes() }; |     FixedMemoryStream stream { block_contents.bytes() }; | ||||||
|     auto buffer = UserOrKernelBuffer::for_kernel_buffer(block_contents.data()); |     auto buffer = UserOrKernelBuffer::for_kernel_buffer(block_contents.data()); | ||||||
| 
 | 
 | ||||||
|     if (old_blocks_length > 0) { |     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.
 |     // 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(old_blocks_length >= new_blocks_length); | ||||||
|     VERIFY(new_blocks_length <= entries_per_doubly_indirect_block); |     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* block_as_pointers = (unsigned*)block_contents.data(); | ||||||
|     auto buffer = UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<u8*>(block_as_pointers)); |     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.
 |     // Free the unused indirect blocks.
 | ||||||
|     for (unsigned i = new_indirect_blocks_length; i < old_indirect_blocks_length; i++) { |     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() > old_blocks_length); | ||||||
|     VERIFY(blocks_indices.size() <= entries_per_triply_indirect_block); |     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(); |     auto* block_as_pointers = (unsigned*)block_contents.data(); | ||||||
|     FixedMemoryStream stream { block_contents.bytes() }; |     FixedMemoryStream stream { block_contents.bytes() }; | ||||||
|     auto buffer = UserOrKernelBuffer::for_kernel_buffer(block_contents.data()); |     auto buffer = UserOrKernelBuffer::for_kernel_buffer(block_contents.data()); | ||||||
| 
 | 
 | ||||||
|     if (old_blocks_length > 0) { |     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.
 |     // 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(old_blocks_length >= new_blocks_length); | ||||||
|     VERIFY(new_blocks_length <= entries_per_triply_indirect_block); |     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* block_as_pointers = (unsigned*)block_contents.data(); | ||||||
|     auto buffer = UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<u8*>(block_as_pointers)); |     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.
 |     // Shrink the doubly indirect blocks.
 | ||||||
|     for (unsigned i = new_triply_indirect_blocks_length; i < old_triply_indirect_blocks_length; i++) { |     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.
 |     // 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 old_shape = fs().compute_block_list_shape(old_block_count); | ||||||
|     auto const new_shape = fs().compute_block_list_shape(m_block_list.size()); |     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)); |         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); |     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; |     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 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
 |     // 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,
 |     // 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.ctime = UnixDateTime::from_seconds_since_epoch(m_raw_inode.i_ctime); | ||||||
|     metadata.mtime = UnixDateTime::from_seconds_since_epoch(m_raw_inode.i_mtime); |     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.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; |     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)) { |     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(); |     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 first_block_logical_index = offset / block_size; | ||||||
|     BlockBasedFileSystem::BlockIndex last_block_logical_index = (offset + count) / 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))) |     if (!((u32)fs().get_features_readonly() & (u32)Ext2FS::FeaturesReadOnly::FileSize64bits) && (new_size >= static_cast<u32>(-1))) | ||||||
|         return ENOSPC; |         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_before = ceil_div(old_size, block_size); | ||||||
|     auto blocks_needed_after = ceil_div(new_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(); |     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()); |     auto new_size = max(static_cast<u64>(offset) + count, size()); | ||||||
| 
 | 
 | ||||||
|     TRY(resize(new_size)); |     TRY(resize(new_size)); | ||||||
|  | @ -734,7 +734,7 @@ ErrorOr<void> Ext2FSInode::traverse_as_directory(Function<ErrorOr<void>(FileSyst | ||||||
|     u8 buffer[max_block_size]; |     u8 buffer[max_block_size]; | ||||||
|     auto buf = UserOrKernelBuffer::for_kernel_buffer(buffer); |     auto buf = UserOrKernelBuffer::for_kernel_buffer(buffer); | ||||||
| 
 | 
 | ||||||
|     auto block_size = fs().block_size(); |     auto block_size = fs().logical_block_size(); | ||||||
|     auto file_size = size(); |     auto file_size = size(); | ||||||
| 
 | 
 | ||||||
|     // Directory entries are guaranteed not to span multiple blocks,
 |     // 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) | ErrorOr<void> Ext2FSInode::write_directory(Vector<Ext2FSDirectoryEntry>& entries) | ||||||
| { | { | ||||||
|     MutexLocker locker(m_inode_lock); |     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
 |     // Calculate directory size and record length of entries so that
 | ||||||
|     // the following constraints are met:
 |     // the following constraints are met:
 | ||||||
|  |  | ||||||
|  | @ -63,7 +63,7 @@ ErrorOr<void> FATFS::initialize_while_locked() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     m_device_block_size = boot_record()->bytes_per_sector; |     m_device_block_size = boot_record()->bytes_per_sector; | ||||||
|     set_block_size(m_device_block_size); |     set_logical_block_size(m_device_block_size); | ||||||
| 
 | 
 | ||||||
|     u32 root_directory_sectors = ((boot_record()->root_directory_entry_count * sizeof(FATEntry)) + (m_device_block_size - 1)) / m_device_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; |     m_first_data_sector = boot_record()->reserved_sector_count + (boot_record()->fat_count * boot_record()->sectors_per_fat) + root_directory_sectors; | ||||||
|  |  | ||||||
|  | @ -53,7 +53,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     virtual void flush_writes() { } |     virtual void flush_writes() { } | ||||||
| 
 | 
 | ||||||
|     u64 block_size() const { return m_block_size; } |     u64 logical_block_size() const { return m_logical_block_size; } | ||||||
|     size_t fragment_size() const { return m_fragment_size; } |     size_t fragment_size() const { return m_fragment_size; } | ||||||
| 
 | 
 | ||||||
|     virtual bool is_file_backed() const { return false; } |     virtual bool is_file_backed() const { return false; } | ||||||
|  | @ -66,7 +66,7 @@ public: | ||||||
| protected: | protected: | ||||||
|     FileSystem(); |     FileSystem(); | ||||||
| 
 | 
 | ||||||
|     void set_block_size(u64 size) { m_block_size = size; } |     void set_logical_block_size(u64 size) { m_logical_block_size = size; } | ||||||
|     void set_fragment_size(size_t size) { m_fragment_size = size; } |     void set_fragment_size(size_t size) { m_fragment_size = size; } | ||||||
| 
 | 
 | ||||||
|     virtual ErrorOr<void> prepare_to_clear_last_mount([[maybe_unused]] Inode& mount_guest_inode) { return {}; } |     virtual ErrorOr<void> prepare_to_clear_last_mount([[maybe_unused]] Inode& mount_guest_inode) { return {}; } | ||||||
|  | @ -75,7 +75,7 @@ protected: | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     FileSystemID m_fsid; |     FileSystemID m_fsid; | ||||||
|     u64 m_block_size { 0 }; |     u64 m_logical_block_size { 0 }; | ||||||
|     size_t m_fragment_size { 0 }; |     size_t m_fragment_size { 0 }; | ||||||
|     bool m_readonly { false }; |     bool m_readonly { false }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -24,7 +24,7 @@ ErrorOr<NonnullRefPtr<FileSystem>> ISO9660FS::try_create(OpenFileDescription& de | ||||||
| ISO9660FS::ISO9660FS(OpenFileDescription& description) | ISO9660FS::ISO9660FS(OpenFileDescription& description) | ||||||
|     : BlockBasedFileSystem(description) |     : BlockBasedFileSystem(description) | ||||||
| { | { | ||||||
|     set_block_size(logical_sector_size); |     set_logical_block_size(logical_sector_size); | ||||||
|     m_device_block_size = logical_sector_size; |     m_device_block_size = logical_sector_size; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -35,7 +35,7 @@ ErrorOr<void> SysFSDiskUsage::try_generate(KBufferBuilder& builder) | ||||||
|         TRY(fs_object.add("free_inode_count"sv, fs.free_inode_count())); |         TRY(fs_object.add("free_inode_count"sv, fs.free_inode_count())); | ||||||
|         auto mount_point = TRY(mount.absolute_path()); |         auto mount_point = TRY(mount.absolute_path()); | ||||||
|         TRY(fs_object.add("mount_point"sv, mount_point->view())); |         TRY(fs_object.add("mount_point"sv, mount_point->view())); | ||||||
|         TRY(fs_object.add("block_size"sv, static_cast<u64>(fs.block_size()))); |         TRY(fs_object.add("block_size"sv, static_cast<u64>(fs.logical_block_size()))); | ||||||
|         TRY(fs_object.add("readonly"sv, fs.is_readonly())); |         TRY(fs_object.add("readonly"sv, fs.is_readonly())); | ||||||
|         TRY(fs_object.add("mount_flags"sv, mount.flags())); |         TRY(fs_object.add("mount_flags"sv, mount.flags())); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ ErrorOr<FlatPtr> Process::do_statvfs(FileSystem const& fs, Custody const* custod | ||||||
| { | { | ||||||
|     statvfs kernelbuf = {}; |     statvfs kernelbuf = {}; | ||||||
| 
 | 
 | ||||||
|     kernelbuf.f_bsize = static_cast<u64>(fs.block_size()); |     kernelbuf.f_bsize = static_cast<u64>(fs.logical_block_size()); | ||||||
|     kernelbuf.f_frsize = fs.fragment_size(); |     kernelbuf.f_frsize = fs.fragment_size(); | ||||||
|     kernelbuf.f_blocks = fs.total_block_count(); |     kernelbuf.f_blocks = fs.total_block_count(); | ||||||
|     kernelbuf.f_bfree = fs.free_block_count(); |     kernelbuf.f_bfree = fs.free_block_count(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 kleines Filmröllchen
						kleines Filmröllchen