From 6c1745964d5c659da77be0490eec9ac2b75429c4 Mon Sep 17 00:00:00 2001 From: "Enrico Fraccaroli (Galfurian)" Date: Thu, 7 Apr 2022 13:07:37 -0400 Subject: [PATCH] Separate inode creation and inode write operation. --- mentos/src/fs/ext2.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mentos/src/fs/ext2.c b/mentos/src/fs/ext2.c index 4b2b89a..ca673f0 100644 --- a/mentos/src/fs/ext2.c +++ b/mentos/src/fs/ext2.c @@ -2122,8 +2122,6 @@ static int ext2_create_inode( pr_err("Failed to read the newly created inode.\n"); return -1; } - pr_debug("UID = %d\n", task->uid); - pr_debug("GID = %d\n", task->gid); // Set the inode mode. inode->mode = mode; // Set the user identifiers of the owners. @@ -2160,11 +2158,6 @@ static int ext2_create_inode( inode->fragment_addr = 0; // TODO: OS dependant structure. memset(&inode->osd2, 0, sizeof(inode->osd2)); - // Write the inode. - if (ext2_write_inode(fs, inode, inode_index) == -1) { - pr_err("Failed to write the newly created inode.\n"); - return -1; - } return inode_index; } @@ -2232,6 +2225,11 @@ static vfs_file_t *ext2_creat(const char *path, mode_t permission) pr_err("Failed to create a new inode inside `%s` (group index: %d).\n", parent->name, group_index); goto close_parent_return_null; } + // Write the inode. + if (ext2_write_inode(fs, &inode, inode_index) == -1) { + pr_err("Failed to write the newly created inode.\n"); + goto close_parent_return_null; + } // Initialize the file. if (ext2_allocate_direntry(fs, parent, file_name, inode_index, ext2_file_type_regular_file) == -1) { pr_err("Failed to allocate a new direntry for the inode.\n"); @@ -2693,8 +2691,13 @@ static int ext2_mkdir(const char *path, mode_t permission) vfs_close(parent); return -ENOENT; } - // Initialize the file. - if (ext2_allocate_direntry(fs, parent, basename(path), inode_index, ext2_file_type_directory) == -1) { + // Write the inode. + if (ext2_write_inode(fs, &inode, inode_index) == -1) { + pr_err("Failed to write the newly created inode.\n"); + // Close the parent directory. + vfs_close(parent); + return -ENOENT; + } pr_err("Failed to allocate a new direntry for the inode.\n"); // Close the parent directory. vfs_close(parent);