mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 19:10:26 +00:00
Get rid of Ext2FS::modify_link_count() in favor of Inode accessors.
This commit is contained in:
parent
673870563d
commit
b0db0e5de0
Notes:
sideshowbarker
2024-07-19 16:07:15 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b0db0e5de09
4 changed files with 30 additions and 23 deletions
|
@ -612,20 +612,6 @@ void Ext2FS::traverse_block_bitmap(unsigned groupIndex, F callback) const
|
|||
}
|
||||
}
|
||||
|
||||
bool Ext2FS::modify_link_count(InodeIndex inode, int delta)
|
||||
{
|
||||
ASSERT(inode);
|
||||
auto e2inode = lookup_ext2_inode(inode);
|
||||
if (!e2inode)
|
||||
return false;
|
||||
|
||||
auto newLinkCount = e2inode->i_links_count + delta;
|
||||
dbgprintf("Ext2FS: changing inode %u link count from %u to %u\n", inode, e2inode->i_links_count, newLinkCount);
|
||||
e2inode->i_links_count = newLinkCount;
|
||||
|
||||
return write_ext2_inode(inode, *e2inode);
|
||||
}
|
||||
|
||||
bool Ext2FS::write_ext2_inode(unsigned inode, const ext2_inode& e2inode)
|
||||
{
|
||||
unsigned blockIndex;
|
||||
|
@ -830,9 +816,9 @@ bool Ext2FS::set_block_allocation_state(GroupIndex group, BlockIndex bi, bool ne
|
|||
return true;
|
||||
}
|
||||
|
||||
RetainPtr<Inode> Ext2FS::create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, int& error)
|
||||
RetainPtr<Inode> Ext2FS::create_directory(InodeIdentifier parent_id, const String& name, Unix::mode_t mode, int& error)
|
||||
{
|
||||
ASSERT(parentInode.fsid() == id());
|
||||
ASSERT(parent_id.fsid() == id());
|
||||
|
||||
// Fix up the mode to definitely be a directory.
|
||||
// FIXME: This is a bit on the hackish side.
|
||||
|
@ -841,21 +827,23 @@ RetainPtr<Inode> Ext2FS::create_directory(InodeIdentifier parentInode, const Str
|
|||
|
||||
// NOTE: When creating a new directory, make the size 1 block.
|
||||
// There's probably a better strategy here, but this works for now.
|
||||
auto inode = create_inode(parentInode, name, mode, blockSize(), error);
|
||||
auto inode = create_inode(parent_id, name, mode, blockSize(), error);
|
||||
if (!inode)
|
||||
return { };
|
||||
return nullptr;
|
||||
|
||||
dbgprintf("Ext2FS: create_directory: created new directory named '%s' with inode %u\n", name.characters(), inode->identifier().index());
|
||||
|
||||
Vector<DirectoryEntry> entries;
|
||||
entries.append({ ".", inode->identifier(), EXT2_FT_DIR });
|
||||
entries.append({ "..", parentInode, EXT2_FT_DIR });
|
||||
entries.append({ "..", parent_id, EXT2_FT_DIR });
|
||||
|
||||
bool success = write_directory_inode(inode->identifier().index(), move(entries));
|
||||
ASSERT(success);
|
||||
|
||||
success = modify_link_count(parentInode.index(), 1);
|
||||
ASSERT(success);
|
||||
auto parent_inode = get_inode(parent_id);
|
||||
error = parent_inode->increment_link_count();
|
||||
if (error < 0)
|
||||
return nullptr;
|
||||
|
||||
auto& bgd = const_cast<ext2_group_desc&>(group_descriptor(group_index_from_inode(inode->identifier().index())));
|
||||
++bgd.bg_used_dirs_count;
|
||||
|
|
|
@ -94,8 +94,6 @@ private:
|
|||
bool set_inode_allocation_state(unsigned inode, bool);
|
||||
bool set_block_allocation_state(GroupIndex, BlockIndex, bool);
|
||||
|
||||
bool modify_link_count(InodeIndex, int delta);
|
||||
|
||||
unsigned m_blockGroupCount { 0 };
|
||||
|
||||
mutable ByteBuffer m_cached_super_block;
|
||||
|
|
|
@ -144,6 +144,25 @@ int Inode::set_mtime(Unix::time_t ts)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Inode::increment_link_count()
|
||||
{
|
||||
if (fs().is_readonly())
|
||||
return -EROFS;
|
||||
++m_metadata.linkCount;
|
||||
m_metadata_dirty = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Inode::decrement_link_count()
|
||||
{
|
||||
if (fs().is_readonly())
|
||||
return -EROFS;
|
||||
ASSERT(m_metadata.linkCount);
|
||||
--m_metadata.linkCount;
|
||||
m_metadata_dirty = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FS::sync()
|
||||
{
|
||||
for (auto* inode : all_inodes()) {
|
||||
|
|
|
@ -88,6 +88,8 @@ public:
|
|||
int set_atime(Unix::time_t);
|
||||
int set_ctime(Unix::time_t);
|
||||
int set_mtime(Unix::time_t);
|
||||
int increment_link_count();
|
||||
int decrement_link_count();
|
||||
|
||||
virtual void flush_metadata() = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue