From bfce80fef8e571aeaf58cccfcd57cc3dc02964e4 Mon Sep 17 00:00:00 2001 From: "Enrico Fraccaroli (Galfurian)" Date: Thu, 7 Apr 2022 13:11:00 -0400 Subject: [PATCH] Create . and .. directories in each newly created directory. --- mentos/src/fs/ext2.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mentos/src/fs/ext2.c b/mentos/src/fs/ext2.c index 9b1688f..21ec32f 100644 --- a/mentos/src/fs/ext2.c +++ b/mentos/src/fs/ext2.c @@ -2658,7 +2658,7 @@ static int ext2_getdents(vfs_file_t *file, dirent_t *dirp, off_t doff, size_t co static int ext2_mkdir(const char *path, mode_t permission) { - pr_debug("ext2_mkdir(%s, %d)\n", path, permission); + pr_debug("\next2_mkdir(%s, %d)\n", path, permission); // Get the absolute path. char absolute_path[PATH_MAX]; // If the first character is not the '/' then get the absolute path. @@ -2725,6 +2725,15 @@ static int ext2_mkdir(const char *path, mode_t permission) vfs_close(parent); return -ENOENT; } + // Create a directory entry, inside the new directory, pointing to itself. + if (ext2_allocate_direntry(fs, inode_index, inode_index, ".", ext2_file_type_directory) == -1) { + pr_err("Failed to allocate a new direntry for the inode.\n"); + // Close the parent directory. + vfs_close(parent); + return -ENOENT; + } + // Create a directory entry, inside the new directory, pointing to its parent. + if (ext2_allocate_direntry(fs, inode_index, parent->ino, "..", ext2_file_type_directory) == -1) { pr_err("Failed to allocate a new direntry for the inode.\n"); // Close the parent directory. vfs_close(parent);