From 74dbffcb8d7857aac6082763a752812de0e0007f Mon Sep 17 00:00:00 2001 From: Enrico Fraccaroli Date: Thu, 23 Dec 2021 18:33:04 +0100 Subject: [PATCH] [WIP] While writing do not abort if you cannot read a block (it might not exist.. yet). --- mentos/src/fs/ext2.c | 6 +++--- mentos/src/kernel.c | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/mentos/src/fs/ext2.c b/mentos/src/fs/ext2.c index 776cb22..0102d53 100644 --- a/mentos/src/fs/ext2.c +++ b/mentos/src/fs/ext2.c @@ -1458,7 +1458,7 @@ static ssize_t ext2_write_inode_data(ext2_filesystem_t *fs, ext2_inode_t *inode, // Read the real block. if (ext2_read_inode_block(fs, inode, start_block, cache) == -1) { pr_err("Failed to read the inode block `%d`\n", start_block); - goto free_cache_return_error; + //goto free_cache_return_error; } // Copy the content back to the buffer. memcpy((uint8_t *)(((uintptr_t)cache) + ((uintptr_t)offset % fs->block_size)), buffer, size_to_write); @@ -1473,7 +1473,7 @@ static ssize_t ext2_write_inode_data(ext2_filesystem_t *fs, ext2_inode_t *inode, // Read the real block. if (ext2_read_inode_block(fs, inode, block_offset, cache) == -1) { pr_err("Failed to read the inode block `%d`\n", block_offset); - goto free_cache_return_error; + //goto free_cache_return_error; } if (block_offset == start_block) { // Copy the content back to the buffer. @@ -1492,7 +1492,7 @@ static ssize_t ext2_write_inode_data(ext2_filesystem_t *fs, ext2_inode_t *inode, // Read the real block. if (ext2_read_inode_block(fs, inode, end_block, cache) == -1) { pr_err("Failed to read the inode block `%d`\n", block_offset); - goto free_cache_return_error; + //goto free_cache_return_error; } // Copy the content back to the buffer. memcpy(cache, buffer + fs->block_size * blocks_read - (offset % fs->block_size), end_size); diff --git a/mentos/src/kernel.c b/mentos/src/kernel.c index df7a3df..403377b 100644 --- a/mentos/src/kernel.c +++ b/mentos/src/kernel.c @@ -351,8 +351,12 @@ int kmain(boot_info_t *boot_informations) print_ok(); vfs_file_t *file1 = vfs_open("/home/test4.txt", O_CREAT | O_EXCL, 0); - vfs_file_t *file2 = vfs_open("/home/test5.txt", O_CREAT | O_EXCL, 0); - vfs_file_t *file3 = vfs_open("/home/test6.txt", O_CREAT | O_EXCL, 0); + char buffer[512]; + for (int i = 0; i < 512; ++i) { + buffer[i] = '0' + (i % 9); + } + vfs_write(file1, buffer, 0, 512); + vfs_close(file1); while (true) {}