summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-18 21:53:58 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-19 21:17:02 +0200
commit607e0858232c0bb8aefc31cba426d4ff56dd10d7 (patch)
treed7d0e51fa8f0623e58f26453197c691d93adb9f3 /Kernel
parent0f6de0c45ab458b5bb0df500e3174af31960f5f3 (diff)
downloadserenity-607e0858232c0bb8aefc31cba426d4ff56dd10d7.zip
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.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp10
1 files 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<NonnullRefPtr<Inode>> 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<NonnullRefPtr<Inode>> 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;