From 166550fbba87d222f4020961ddf0feefe54732c0 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 7 Oct 2024 18:20:08 +0300 Subject: [PATCH] Kernel: Ext2 check if file exists before creating it --- kernel/kernel/FS/Ext2/Inode.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/kernel/FS/Ext2/Inode.cpp b/kernel/kernel/FS/Ext2/Inode.cpp index 3e9b16cf..909eb7c1 100644 --- a/kernel/kernel/FS/Ext2/Inode.cpp +++ b/kernel/kernel/FS/Ext2/Inode.cpp @@ -424,6 +424,9 @@ done: { ASSERT(this->mode().ifdir()); + if (!find_inode_impl(name).is_error()) + return BAN::Error::from_errno(EEXIST); + if (!(Mode(mode).ifreg())) return BAN::Error::from_errno(ENOTSUP); @@ -448,6 +451,9 @@ done: ASSERT(this->mode().ifdir()); ASSERT(Mode(mode).ifdir()); + if (!find_inode_impl(name).is_error()) + return BAN::Error::from_errno(EEXIST); + const uint32_t new_ino = TRY(m_fs.create_inode(initialize_new_inode_info(mode, uid, gid))); auto inode_or_error = Ext2Inode::create(m_fs, new_ino);