mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
Ext2FS: Convert #if EXT2_DEBUG => dbgln_if() and constexpr-if
This commit is contained in:
parent
abe4463b1c
commit
95064f8b58
1 changed files with 64 additions and 123 deletions
|
@ -109,22 +109,22 @@ bool Ext2FS::initialize()
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
|
|
||||||
auto& super_block = this->super_block();
|
auto& super_block = this->super_block();
|
||||||
#if EXT2_DEBUG
|
if constexpr (EXT2_DEBUG) {
|
||||||
klog() << "ext2fs: super block magic: " << String::format("%x", super_block.s_magic) << " (super block size: " << sizeof(ext2_super_block) << ")";
|
klog() << "ext2fs: super block magic: " << String::format("%x", super_block.s_magic) << " (super block size: " << sizeof(ext2_super_block) << ")";
|
||||||
#endif
|
}
|
||||||
if (super_block.s_magic != EXT2_SUPER_MAGIC)
|
if (super_block.s_magic != EXT2_SUPER_MAGIC)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#if EXT2_DEBUG
|
if constexpr (EXT2_DEBUG) {
|
||||||
klog() << "ext2fs: " << super_block.s_inodes_count << " inodes, " << super_block.s_blocks_count << " blocks";
|
klog() << "ext2fs: " << super_block.s_inodes_count << " inodes, " << super_block.s_blocks_count << " blocks";
|
||||||
klog() << "ext2fs: block size = " << EXT2_BLOCK_SIZE(&super_block);
|
klog() << "ext2fs: block size = " << EXT2_BLOCK_SIZE(&super_block);
|
||||||
klog() << "ext2fs: first data block = " << super_block.s_first_data_block;
|
klog() << "ext2fs: first data block = " << super_block.s_first_data_block;
|
||||||
klog() << "ext2fs: inodes per block = " << inodes_per_block();
|
klog() << "ext2fs: inodes per block = " << inodes_per_block();
|
||||||
klog() << "ext2fs: inodes per group = " << inodes_per_group();
|
klog() << "ext2fs: inodes per group = " << inodes_per_group();
|
||||||
klog() << "ext2fs: free inodes = " << super_block.s_free_inodes_count;
|
klog() << "ext2fs: free inodes = " << super_block.s_free_inodes_count;
|
||||||
klog() << "ext2fs: desc per block = " << EXT2_DESC_PER_BLOCK(&super_block);
|
klog() << "ext2fs: desc per block = " << EXT2_DESC_PER_BLOCK(&super_block);
|
||||||
klog() << "ext2fs: desc size = " << EXT2_DESC_SIZE(&super_block);
|
klog() << "ext2fs: desc size = " << EXT2_DESC_SIZE(&super_block);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
set_block_size(EXT2_BLOCK_SIZE(&super_block));
|
set_block_size(EXT2_BLOCK_SIZE(&super_block));
|
||||||
|
|
||||||
|
@ -152,12 +152,12 @@ bool Ext2FS::initialize()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if EXT2_DEBUG
|
if constexpr (EXT2_DEBUG) {
|
||||||
for (unsigned i = 1; i <= m_block_group_count; ++i) {
|
for (unsigned i = 1; i <= m_block_group_count; ++i) {
|
||||||
auto& group = group_descriptor(i);
|
auto& group = group_descriptor(i);
|
||||||
klog() << "ext2fs: group[" << i << "] { block_bitmap: " << group.bg_block_bitmap << ", inode_bitmap: " << group.bg_inode_bitmap << ", inode_table: " << group.bg_inode_table << " }";
|
klog() << "ext2fs: group[" << i << "] { block_bitmap: " << group.bg_block_bitmap << ", inode_bitmap: " << group.bg_inode_bitmap << ", inode_table: " << group.bg_inode_table << " }";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -267,11 +267,11 @@ KResult Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e
|
||||||
--remaining_blocks;
|
--remaining_blocks;
|
||||||
}
|
}
|
||||||
if (inode_dirty) {
|
if (inode_dirty) {
|
||||||
#if EXT2_DEBUG
|
if constexpr (EXT2_DEBUG) {
|
||||||
dbgln("Ext2FS: Writing {} direct block(s) to i_block array of inode {}", min((size_t)EXT2_NDIR_BLOCKS, blocks.size()), inode_index);
|
dbgln("Ext2FS: Writing {} direct block(s) to i_block array of inode {}", min((size_t)EXT2_NDIR_BLOCKS, blocks.size()), inode_index);
|
||||||
for (size_t i = 0; i < min((size_t)EXT2_NDIR_BLOCKS, blocks.size()); ++i)
|
for (size_t i = 0; i < min((size_t)EXT2_NDIR_BLOCKS, blocks.size()); ++i)
|
||||||
dbgln(" + {}", blocks[i]);
|
dbgln(" + {}", blocks[i]);
|
||||||
#endif
|
}
|
||||||
write_ext2_inode(inode_index, e2inode);
|
write_ext2_inode(inode_index, e2inode);
|
||||||
inode_dirty = false;
|
inode_dirty = false;
|
||||||
}
|
}
|
||||||
|
@ -288,9 +288,7 @@ KResult Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e
|
||||||
inode_dirty = true;
|
inode_dirty = true;
|
||||||
e2inode.i_block[EXT2_IND_BLOCK] = new_indirect_block;
|
e2inode.i_block[EXT2_IND_BLOCK] = new_indirect_block;
|
||||||
if (inode_dirty) {
|
if (inode_dirty) {
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: Adding the indirect block to i_block array of inode {}", inode_index);
|
||||||
dbgln("Ext2FS: Adding the indirect block to i_block array of inode {}", inode_index);
|
|
||||||
#endif
|
|
||||||
write_ext2_inode(inode_index, e2inode);
|
write_ext2_inode(inode_index, e2inode);
|
||||||
inode_dirty = false;
|
inode_dirty = false;
|
||||||
}
|
}
|
||||||
|
@ -330,9 +328,7 @@ KResult Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e
|
||||||
inode_dirty = true;
|
inode_dirty = true;
|
||||||
e2inode.i_block[EXT2_DIND_BLOCK] = new_dindirect_block;
|
e2inode.i_block[EXT2_DIND_BLOCK] = new_dindirect_block;
|
||||||
if (inode_dirty) {
|
if (inode_dirty) {
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: Adding the doubly-indirect block to i_block array of inode {}", inode_index);
|
||||||
dbgln("Ext2FS: Adding the doubly-indirect block to i_block array of inode {}", inode_index);
|
|
||||||
#endif
|
|
||||||
write_ext2_inode(inode_index, e2inode);
|
write_ext2_inode(inode_index, e2inode);
|
||||||
inode_dirty = false;
|
inode_dirty = false;
|
||||||
}
|
}
|
||||||
|
@ -459,9 +455,7 @@ Vector<Ext2FS::BlockIndex> Ext2FS::block_list_for_inode_impl(const ext2_inode& e
|
||||||
if (is_symlink(e2inode.i_mode) && e2inode.i_blocks == 0)
|
if (is_symlink(e2inode.i_mode) && e2inode.i_blocks == 0)
|
||||||
block_count = 0;
|
block_count = 0;
|
||||||
|
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS::block_list_for_inode(): i_size={}, i_blocks={}, block_count={}", e2inode.i_size, e2inode.i_blocks, block_count);
|
||||||
dbgln("Ext2FS::block_list_for_inode(): i_size={}, i_blocks={}, block_count={}", e2inode.i_size, e2inode.i_blocks, block_count);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
unsigned blocks_remaining = block_count;
|
unsigned blocks_remaining = block_count;
|
||||||
|
|
||||||
|
@ -545,9 +539,7 @@ void Ext2FS::free_inode(Ext2FSInode& inode)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
ASSERT(inode.m_raw_inode.i_links_count == 0);
|
ASSERT(inode.m_raw_inode.i_links_count == 0);
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: Inode {} has no more links, time to delete!", inode.index());
|
||||||
dbgln("Ext2FS: Inode {} has no more links, time to delete!", inode.index());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Mark all blocks used by this inode as free.
|
// Mark all blocks used by this inode as free.
|
||||||
auto block_list = block_list_for_inode(inode.m_raw_inode, true);
|
auto block_list = block_list_for_inode(inode.m_raw_inode, true);
|
||||||
|
@ -604,9 +596,7 @@ void Ext2FS::flush_writes()
|
||||||
dbgln("Ext2FS: flush_writes() had error {}", result.error());
|
dbgln("Ext2FS: flush_writes() had error {}", result.error());
|
||||||
}
|
}
|
||||||
cached_bitmap->dirty = false;
|
cached_bitmap->dirty = false;
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Flushed bitmap block {}", cached_bitmap->bitmap_block_index);
|
||||||
dbgln("Flushed bitmap block {}", cached_bitmap->bitmap_block_index);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -671,9 +661,7 @@ InodeMetadata Ext2FSInode::metadata() const
|
||||||
void Ext2FSInode::flush_metadata()
|
void Ext2FSInode::flush_metadata()
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: flush_metadata for inode {}", index());
|
||||||
dbgln("Ext2FS: flush_metadata for inode {}", index());
|
|
||||||
#endif
|
|
||||||
fs().write_ext2_inode(index(), m_raw_inode);
|
fs().write_ext2_inode(index(), m_raw_inode);
|
||||||
if (is_directory()) {
|
if (is_directory()) {
|
||||||
// Unless we're about to go away permanently, invalidate the lookup cache.
|
// Unless we're about to go away permanently, invalidate the lookup cache.
|
||||||
|
@ -758,9 +746,7 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, UserOrKernelBuffer&
|
||||||
ssize_t nread = 0;
|
ssize_t nread = 0;
|
||||||
size_t remaining_count = min((off_t)count, (off_t)size() - offset);
|
size_t remaining_count = min((off_t)count, (off_t)size() - offset);
|
||||||
|
|
||||||
#if EXT2_VERY_DEBUG
|
dbgln_if(EXT2_VERY_DEBUG, "Ext2FS: Reading up to {} bytes, {} bytes into inode {} to {}", count, offset, index(), buffer.user_or_kernel_ptr());
|
||||||
dbgln("Ext2FS: Reading up to {} bytes, {} bytes into inode {} to {}", count, offset, index(), buffer.user_or_kernel_ptr());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (size_t bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
for (size_t bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
||||||
auto block_index = m_block_list[bi];
|
auto block_index = m_block_list[bi];
|
||||||
|
@ -790,10 +776,10 @@ KResult Ext2FSInode::resize(u64 new_size)
|
||||||
size_t blocks_needed_before = ceil_div(old_size, block_size);
|
size_t blocks_needed_before = ceil_div(old_size, block_size);
|
||||||
size_t blocks_needed_after = ceil_div(new_size, block_size);
|
size_t blocks_needed_after = ceil_div(new_size, block_size);
|
||||||
|
|
||||||
#if EXT2_DEBUG
|
if constexpr (EXT2_DEBUG) {
|
||||||
dbgln("Ext2FSInode::resize(): blocks needed before (size was {}): {}", old_size, blocks_needed_before);
|
dbgln("Ext2FSInode::resize(): blocks needed before (size was {}): {}", old_size, blocks_needed_before);
|
||||||
dbgln("Ext2FSInode::resize(): blocks needed after (size is {}): {}", new_size, blocks_needed_after);
|
dbgln("Ext2FSInode::resize(): blocks needed after (size is {}): {}", new_size, blocks_needed_after);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
if (blocks_needed_after > blocks_needed_before) {
|
if (blocks_needed_after > blocks_needed_before) {
|
||||||
u32 additional_blocks_needed = blocks_needed_after - blocks_needed_before;
|
u32 additional_blocks_needed = blocks_needed_after - blocks_needed_before;
|
||||||
|
@ -811,12 +797,12 @@ KResult Ext2FSInode::resize(u64 new_size)
|
||||||
auto new_blocks = fs().allocate_blocks(fs().group_index_from_inode(index()), blocks_needed_after - blocks_needed_before);
|
auto new_blocks = fs().allocate_blocks(fs().group_index_from_inode(index()), blocks_needed_after - blocks_needed_before);
|
||||||
block_list.append(move(new_blocks));
|
block_list.append(move(new_blocks));
|
||||||
} else if (blocks_needed_after < blocks_needed_before) {
|
} else if (blocks_needed_after < blocks_needed_before) {
|
||||||
#if EXT2_DEBUG
|
if constexpr (EXT2_DEBUG) {
|
||||||
dbgln("Ext2FS: Shrinking inode {}. Old block list is {} entries:", index(), block_list.size());
|
dbgln("Ext2FS: Shrinking inode {}. Old block list is {} entries:", index(), block_list.size());
|
||||||
for (auto block_index : block_list) {
|
for (auto block_index : block_list) {
|
||||||
dbgln(" # {}", block_index);
|
dbgln(" # {}", block_index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
while (block_list.size() != blocks_needed_after) {
|
while (block_list.size() != blocks_needed_after) {
|
||||||
auto block_index = block_list.take_last();
|
auto block_index = block_list.take_last();
|
||||||
if (block_index)
|
if (block_index)
|
||||||
|
@ -868,9 +854,7 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const UserOrKernel
|
||||||
if (is_symlink()) {
|
if (is_symlink()) {
|
||||||
ASSERT(offset == 0);
|
ASSERT(offset == 0);
|
||||||
if (max((size_t)(offset + count), (size_t)m_raw_inode.i_size) < max_inline_symlink_length) {
|
if (max((size_t)(offset + count), (size_t)m_raw_inode.i_size) < max_inline_symlink_length) {
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: write_bytes poking into i_block array for inline symlink '{}' ({} bytes)", data.copy_into_string(count), count);
|
||||||
dbgln("Ext2FS: write_bytes poking into i_block array for inline symlink '{}' ({} bytes)", data.copy_into_string(count), count);
|
|
||||||
#endif
|
|
||||||
if (!data.read(((u8*)m_raw_inode.i_block) + offset, (size_t)count))
|
if (!data.read(((u8*)m_raw_inode.i_block) + offset, (size_t)count))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if ((size_t)(offset + count) > (size_t)m_raw_inode.i_size)
|
if ((size_t)(offset + count) > (size_t)m_raw_inode.i_size)
|
||||||
|
@ -908,17 +892,13 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const UserOrKernel
|
||||||
ssize_t nwritten = 0;
|
ssize_t nwritten = 0;
|
||||||
size_t remaining_count = min((off_t)count, (off_t)new_size - offset);
|
size_t remaining_count = min((off_t)count, (off_t)new_size - offset);
|
||||||
|
|
||||||
#if EXT2_VERY_DEBUG
|
dbgln_if(EXT2_VERY_DEBUG, "Ext2FS: Writing {} bytes, {} bytes into inode {} from {}", count, offset, index(), data.user_or_kernel_ptr());
|
||||||
dbgln("Ext2FS: Writing {} bytes, {} bytes into inode {} from {}", count, offset, index(), data.user_or_kernel_ptr());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (size_t bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
for (size_t bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
||||||
size_t offset_into_block = (bi == first_block_logical_index) ? offset_into_first_block : 0;
|
size_t offset_into_block = (bi == first_block_logical_index) ? offset_into_first_block : 0;
|
||||||
size_t num_bytes_to_copy = min(block_size - offset_into_block, remaining_count);
|
size_t num_bytes_to_copy = min(block_size - offset_into_block, remaining_count);
|
||||||
#if EXT2_VERY_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: Writing block {} (offset_into_block: {})", m_block_list[bi], offset_into_block);
|
||||||
dbgln("Ext2FS: Writing block {} (offset_into_block: {})", m_block_list[bi], offset_into_block);
|
result = fs().write_block(m_block_list[bi], data.offset(nwritten), num_bytes_to_copy, offset_into_block, allow_cache);
|
||||||
#endif
|
|
||||||
auto result = fs().write_block(m_block_list[bi], data.offset(nwritten), num_bytes_to_copy, offset_into_block, allow_cache);
|
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
dbgln("Ext2FS: write_block({}) failed (bi: {})", m_block_list[bi], bi);
|
dbgln("Ext2FS: write_block({}) failed (bi: {})", m_block_list[bi], bi);
|
||||||
return result;
|
return result;
|
||||||
|
@ -927,9 +907,7 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const UserOrKernel
|
||||||
nwritten += num_bytes_to_copy;
|
nwritten += num_bytes_to_copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if EXT2_VERY_DEBUG
|
dbgln_if(EXT2_VERY_DEBUG, "Ext2FS: After write, i_size={}, i_blocks={} ({} blocks in list)", m_raw_inode.i_size, m_raw_inode.i_blocks, m_block_list.size());
|
||||||
dbgln("Ext2FS: After write, i_size={}, i_blocks={} ({} blocks in list)", m_raw_inode.i_size, m_raw_inode.i_blocks, m_block_list.size());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (old_size != new_size)
|
if (old_size != new_size)
|
||||||
inode_size_changed(old_size, new_size);
|
inode_size_changed(old_size, new_size);
|
||||||
|
@ -964,9 +942,7 @@ KResult Ext2FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntr
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
ASSERT(is_directory());
|
ASSERT(is_directory());
|
||||||
|
|
||||||
#if EXT2_VERY_DEBUG
|
dbgln_if(EXT2_VERY_DEBUG, "Ext2FS: Traversing as directory: {}", index());
|
||||||
dbgln("Ext2FS: Traversing as directory: {}", index());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
auto buffer_or = read_entire();
|
auto buffer_or = read_entire();
|
||||||
if (buffer_or.is_error())
|
if (buffer_or.is_error())
|
||||||
|
@ -977,9 +953,7 @@ KResult Ext2FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntr
|
||||||
|
|
||||||
while (entry < buffer.end_pointer()) {
|
while (entry < buffer.end_pointer()) {
|
||||||
if (entry->inode != 0) {
|
if (entry->inode != 0) {
|
||||||
#if EXT2_VERY_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2Inode::traverse_as_directory: {}, name_len: {}, rec_len: {}, file_type: {}, name: {}", entry->inode, entry->name_len, entry->rec_len, entry->file_type, StringView(entry->name, entry->name_len));
|
||||||
dbgln("Ext2Inode::traverse_as_directory: {}, name_len: {}, rec_len: {}, file_type: {}, name: {}", entry->inode, entry->name_len, entry->rec_len, entry->file_type, StringView(entry->name, entry->name_len));
|
|
||||||
#endif
|
|
||||||
if (!callback({ { entry->name, entry->name_len }, { fsid(), entry->inode }, entry->file_type }))
|
if (!callback({ { entry->name, entry->name_len }, { fsid(), entry->inode }, entry->file_type }))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1002,9 +976,7 @@ KResult Ext2FSInode::write_directory(const Vector<Ext2FSDirectoryEntry>& entries
|
||||||
int blocks_needed = ceil_div(static_cast<size_t>(directory_size), block_size);
|
int blocks_needed = ceil_div(static_cast<size_t>(directory_size), block_size);
|
||||||
int occupied_size = blocks_needed * block_size;
|
int occupied_size = blocks_needed * block_size;
|
||||||
|
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: New directory inode {} contents to write (size {}, occupied {}):", index(), directory_size, occupied_size);
|
||||||
dbgln("Ext2FS: New directory inode {} contents to write (size {}, occupied {}):", index(), directory_size, occupied_size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
auto directory_data = ByteBuffer::create_uninitialized(occupied_size);
|
auto directory_data = ByteBuffer::create_uninitialized(occupied_size);
|
||||||
OutputMemoryStream stream { directory_data };
|
OutputMemoryStream stream { directory_data };
|
||||||
|
@ -1016,9 +988,7 @@ KResult Ext2FSInode::write_directory(const Vector<Ext2FSDirectoryEntry>& entries
|
||||||
if (i == entries.size() - 1)
|
if (i == entries.size() - 1)
|
||||||
record_length += occupied_size - directory_size;
|
record_length += occupied_size - directory_size;
|
||||||
|
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "* Inode: {}, name_len: {}, rec_len: {}, file_type: {}, name: {}", entry.inode_index, u16(entry.name.length()), u16(record_length), u8(entry.file_type), entry.name);
|
||||||
dbgln("* Inode: {}, name_len: {}, rec_len: {}, file_type: {}, name: {}", entry.inode.index(), u16(entry.name.length()), u16(record_length), u8(entry.file_type), entry.name);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
stream << u32(entry.inode_index);
|
stream << u32(entry.inode_index);
|
||||||
stream << u16(record_length);
|
stream << u16(record_length);
|
||||||
|
@ -1058,9 +1028,7 @@ KResult Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode
|
||||||
if (name.length() > EXT2_NAME_LEN)
|
if (name.length() > EXT2_NAME_LEN)
|
||||||
return ENAMETOOLONG;
|
return ENAMETOOLONG;
|
||||||
|
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FSInode::add_child: Adding inode {} with name '{}' and mode {:o} to directory {}", child.index(), name, mode, index());
|
||||||
dbgln("Ext2FSInode::add_child: Adding inode {} with name '{}' and mode {:o} to directory {}", child.index(), name, mode, index());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Vector<Ext2FSDirectoryEntry> entries;
|
Vector<Ext2FSDirectoryEntry> entries;
|
||||||
bool name_already_exists = false;
|
bool name_already_exists = false;
|
||||||
|
@ -1098,9 +1066,7 @@ KResult Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode
|
||||||
KResult Ext2FSInode::remove_child(const StringView& name)
|
KResult Ext2FSInode::remove_child(const StringView& name)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FSInode::remove_child('{}') in inode {}", name, index());
|
||||||
dbgln("Ext2FSInode::remove_child('{}') in inode {}", name, index());
|
|
||||||
#endif
|
|
||||||
ASSERT(is_directory());
|
ASSERT(is_directory());
|
||||||
|
|
||||||
auto it = m_lookup_cache.find(name);
|
auto it = m_lookup_cache.find(name);
|
||||||
|
@ -1110,9 +1076,7 @@ KResult Ext2FSInode::remove_child(const StringView& name)
|
||||||
|
|
||||||
InodeIdentifier child_id { fsid(), child_inode_index };
|
InodeIdentifier child_id { fsid(), child_inode_index };
|
||||||
|
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FSInode::remove_child(): Removing '{}' in directory {}", name, index());
|
||||||
dbgln("Ext2FSInode::remove_child(): Removing '{}' in directory {}", name, index());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Vector<Ext2FSDirectoryEntry> entries;
|
Vector<Ext2FSDirectoryEntry> entries;
|
||||||
KResult result = traverse_as_directory([&](auto& entry) {
|
KResult result = traverse_as_directory([&](auto& entry) {
|
||||||
|
@ -1171,16 +1135,12 @@ bool Ext2FS::write_ext2_inode(unsigned inode, const ext2_inode& e2inode)
|
||||||
Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count)
|
Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: allocate_blocks(preferred group: {}, count {})", preferred_group_index, count);
|
||||||
dbgln("Ext2FS: allocate_blocks(preferred group: {}, count {})", preferred_group_index, count);
|
|
||||||
#endif
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
Vector<BlockIndex> blocks;
|
Vector<BlockIndex> blocks;
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: allocate_blocks:");
|
||||||
dbgln("Ext2FS: allocate_blocks:");
|
|
||||||
#endif
|
|
||||||
blocks.ensure_capacity(count);
|
blocks.ensure_capacity(count);
|
||||||
|
|
||||||
GroupIndex group_index = preferred_group_index;
|
GroupIndex group_index = preferred_group_index;
|
||||||
|
@ -1216,16 +1176,12 @@ Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(GroupIndex preferred_group_in
|
||||||
size_t free_region_size = 0;
|
size_t free_region_size = 0;
|
||||||
auto first_unset_bit_index = block_bitmap.find_longest_range_of_unset_bits(count - blocks.size(), free_region_size);
|
auto first_unset_bit_index = block_bitmap.find_longest_range_of_unset_bits(count - blocks.size(), free_region_size);
|
||||||
ASSERT(first_unset_bit_index.has_value());
|
ASSERT(first_unset_bit_index.has_value());
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: allocating free region of size: {} [{}]", free_region_size, group_index);
|
||||||
dbgln("Ext2FS: allocating free region of size: {} [{}]", free_region_size, group_index);
|
|
||||||
#endif
|
|
||||||
for (size_t i = 0; i < free_region_size; ++i) {
|
for (size_t i = 0; i < free_region_size; ++i) {
|
||||||
BlockIndex block_index = (first_unset_bit_index.value() + i) + first_block_in_group;
|
BlockIndex block_index = (first_unset_bit_index.value() + i) + first_block_in_group;
|
||||||
set_block_allocation_state(block_index, true);
|
set_block_allocation_state(block_index, true);
|
||||||
blocks.unchecked_append(block_index);
|
blocks.unchecked_append(block_index);
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, " allocated > {}", block_index);
|
||||||
dbgln(" allocated > {}", block_index);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1236,9 +1192,7 @@ Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(GroupIndex preferred_group_in
|
||||||
unsigned Ext2FS::find_a_free_inode(GroupIndex preferred_group)
|
unsigned Ext2FS::find_a_free_inode(GroupIndex preferred_group)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: find_a_free_inode(preferred_group: {})", preferred_group);
|
||||||
dbgln("Ext2FS: find_a_free_inode(preferred_group: {})", preferred_group);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
unsigned group_index = 0;
|
unsigned group_index = 0;
|
||||||
|
|
||||||
|
@ -1263,9 +1217,7 @@ unsigned Ext2FS::find_a_free_inode(GroupIndex preferred_group)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: find_a_free_inode: found suitable group [{}] for new inode :^)", group_index);
|
||||||
dbgln("Ext2FS: find_a_free_inode: found suitable group [{}] for new inode :^)", group_index);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
auto& bgd = group_descriptor(group_index);
|
auto& bgd = group_descriptor(group_index);
|
||||||
unsigned inodes_in_group = min(inodes_per_group(), super_block().s_inodes_count);
|
unsigned inodes_in_group = min(inodes_per_group(), super_block().s_inodes_count);
|
||||||
|
@ -1288,9 +1240,7 @@ unsigned Ext2FS::find_a_free_inode(GroupIndex preferred_group)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned inode = first_free_inode_in_group;
|
unsigned inode = first_free_inode_in_group;
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: found suitable inode {}", inode);
|
||||||
dbgln("Ext2FS: found suitable inode {}", inode);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ASSERT(get_inode_allocation_state(inode) == false);
|
ASSERT(get_inode_allocation_state(inode) == false);
|
||||||
return inode;
|
return inode;
|
||||||
|
@ -1335,9 +1285,7 @@ bool Ext2FS::set_inode_allocation_state(InodeIndex inode_index, bool new_state)
|
||||||
auto& cached_bitmap = get_bitmap_block(bgd.bg_inode_bitmap);
|
auto& cached_bitmap = get_bitmap_block(bgd.bg_inode_bitmap);
|
||||||
|
|
||||||
bool current_state = cached_bitmap.bitmap(inodes_per_group()).get(bit_index);
|
bool current_state = cached_bitmap.bitmap(inodes_per_group()).get(bit_index);
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: set_inode_allocation_state({}) {} -> {}", inode_index, current_state, new_state);
|
||||||
dbgln("Ext2FS: set_inode_allocation_state({}) {} -> {}", inode_index, current_state, new_state);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (current_state == new_state) {
|
if (current_state == new_state) {
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
|
@ -1398,9 +1346,7 @@ bool Ext2FS::set_block_allocation_state(BlockIndex block_index, bool new_state)
|
||||||
auto& cached_bitmap = get_bitmap_block(bgd.bg_block_bitmap);
|
auto& cached_bitmap = get_bitmap_block(bgd.bg_block_bitmap);
|
||||||
|
|
||||||
bool current_state = cached_bitmap.bitmap(blocks_per_group()).get(bit_index);
|
bool current_state = cached_bitmap.bitmap(blocks_per_group()).get(bit_index);
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: block {} state: {} -> {} (in bitmap block {})", block_index, current_state, new_state, bgd.bg_block_bitmap);
|
||||||
dbgln("Ext2FS: block {} state: {} -> {} (in bitmap block {})", block_index, current_state, new_state, bgd.bg_block_bitmap);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (current_state == new_state) {
|
if (current_state == new_state) {
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
|
@ -1439,9 +1385,7 @@ KResult Ext2FS::create_directory(Ext2FSInode& parent_inode, const String& name,
|
||||||
|
|
||||||
auto& inode = inode_or_error.value();
|
auto& inode = inode_or_error.value();
|
||||||
|
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: create_directory: created new directory named '{} with inode {}", name, inode->index());
|
||||||
dbgln("Ext2FS: create_directory: created new directory named '{} with inode {}", name, inode->index());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Vector<Ext2FSDirectoryEntry> entries;
|
Vector<Ext2FSDirectoryEntry> entries;
|
||||||
entries.empend(".", inode->index(), static_cast<u8>(EXT2_FT_DIR));
|
entries.empend(".", inode->index(), static_cast<u8>(EXT2_FT_DIR));
|
||||||
|
@ -1472,9 +1416,7 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(Ext2FSInode& parent_inode,
|
||||||
if (name.length() > EXT2_NAME_LEN)
|
if (name.length() > EXT2_NAME_LEN)
|
||||||
return ENAMETOOLONG;
|
return ENAMETOOLONG;
|
||||||
|
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: Adding inode '{}' (mode {:o}) to parent directory {}", name, mode, parent_inode.index());
|
||||||
dbgln("Ext2FS: Adding inode '{}' (mode {:o}) to parent directory {}", name, mode, parent_inode.index());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// NOTE: This doesn't commit the inode allocation just yet!
|
// NOTE: This doesn't commit the inode allocation just yet!
|
||||||
auto inode_id = find_a_free_inode();
|
auto inode_id = find_a_free_inode();
|
||||||
|
@ -1508,9 +1450,8 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(Ext2FSInode& parent_inode,
|
||||||
else if (is_block_device(mode))
|
else if (is_block_device(mode))
|
||||||
e2inode.i_block[1] = dev;
|
e2inode.i_block[1] = dev;
|
||||||
|
|
||||||
#if EXT2_DEBUG
|
dbgln_if(EXT2_DEBUG, "Ext2FS: writing initial metadata for inode {}", inode_id);
|
||||||
dbgln("Ext2FS: writing initial metadata for inode {}", inode_id);
|
|
||||||
#endif
|
|
||||||
e2inode.i_flags = 0;
|
e2inode.i_flags = 0;
|
||||||
success = write_ext2_inode(inode_id, e2inode);
|
success = write_ext2_inode(inode_id, e2inode);
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue