From 607e0858232c0bb8aefc31cba426d4ff56dd10d7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 18 Aug 2020 21:53:58 +0200 Subject: [PATCH] Ext2FS: Fix inode link leak on all new inodes The initial inode link count was wrong in Ext2FS, as the act of adding new inodes to their new parent bumps the count. This regressed in df66c28479e9206adeef1f40f8c0e448c8aea77e. --- Kernel/FileSystem/Ext2FileSystem.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index ce9dd8e58e..deee0cca05 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -1428,12 +1428,6 @@ KResultOr> Ext2FS::create_inode(InodeIdentifier parent_id, bool success = set_inode_allocation_state(inode_id, true); ASSERT(success); - unsigned initial_links_count; - if (is_directory(mode)) - initial_links_count = 2; // (parent directory + "." entry in self) - else - initial_links_count = 1; - struct timeval now; kgettimeofday(now); ext2_inode e2inode; @@ -1446,7 +1440,9 @@ KResultOr> Ext2FS::create_inode(InodeIdentifier parent_id, e2inode.i_ctime = now.tv_sec; e2inode.i_mtime = now.tv_sec; e2inode.i_dtime = 0; - e2inode.i_links_count = initial_links_count; + + // For directories, add +1 link count for the "." entry in self. + e2inode.i_links_count = is_directory(mode); if (is_character_device(mode)) e2inode.i_block[0] = dev;