1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 09:24:57 +00:00

Kernel: Add link() syscall to create hard links.

This accidentally grew into a little bit of VFS cleanup as well.

Also add a simple /bin/ln implementation to exercise it.
This commit is contained in:
Andreas Kling 2019-02-21 13:26:40 +01:00
parent b6115ee5b7
commit 7d288aafb2
13 changed files with 138 additions and 93 deletions

View file

@ -637,12 +637,14 @@ bool Ext2FSInode::add_child(InodeIdentifier child_id, const String& name, byte f
return false;
}
auto child_inode = fs().get_inode(child_id);
if (child_inode)
child_inode->increment_link_count();
entries.append({ name.characters(), name.length(), child_id, file_type });
bool success = fs().write_directory_inode(index(), move(entries));
if (success) {
LOCKER(m_lock);
if (success)
m_lookup_cache.set(name, child_id.index());
}
return success;
}
@ -672,8 +674,8 @@ bool Ext2FSInode::remove_child(const String& name, int& error)
Vector<FS::DirectoryEntry> entries;
traverse_as_directory([&] (auto& entry) {
if (entry.inode != child_id)
entries.append(entry);
if (strcmp(entry.name, name.characters()) != 0)
entries.append(entry);
return true;
});
@ -1336,6 +1338,7 @@ int Ext2FSInode::decrement_link_count()
void Ext2FS::uncache_inode(InodeIndex index)
{
LOCKER(m_lock);
m_inode_cache.remove(index);
}
size_t Ext2FSInode::directory_entry_count() const