From de198df6d1f1fab56ff4e1ef45991fe7f625a1c5 Mon Sep 17 00:00:00 2001 From: FactorialN <8838579+FactorialN@users.noreply.github.com> Date: Fri, 1 Dec 2023 19:04:00 -0800 Subject: [PATCH] fixed a bug of indirect layers --- include/fs_constants.hpp | 1 + lib/files.cpp | 2 +- lib/fs/fs_read_write.cpp | 22 ++++++++++++++-------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/fs_constants.hpp b/include/fs_constants.hpp index 8353020..19b9857 100644 --- a/include/fs_constants.hpp +++ b/include/fs_constants.hpp @@ -12,6 +12,7 @@ #include #define IO_BLOCK_SIZE 4096 +#define INDIRECT_BLOCKS 512 #define NUM_INODE_BLOCKS 1023 #define NUM_BLOCKS 2048 diff --git a/lib/files.cpp b/lib/files.cpp index 05a9f0b..2ba6ee5 100644 --- a/lib/files.cpp +++ b/lib/files.cpp @@ -333,7 +333,7 @@ int FilesOperation::fischl_readdir(const char *path, void *buf, fuse_fill_dir_t ent.deserialize(buffer+i); if (ent.inode_number) { filler(buf, ent.file_name, NULL, 0, FUSE_FILL_DIR_PLUS); - printf("%s\t%llu;\t", ent.file_name, ent.inode_number); + //printf("%s\t%llu;\t", ent.file_name, ent.inode_number); } } } diff --git a/lib/fs/fs_read_write.cpp b/lib/fs/fs_read_write.cpp index 4fc1d16..f8a874f 100644 --- a/lib/fs/fs_read_write.cpp +++ b/lib/fs/fs_read_write.cpp @@ -15,6 +15,8 @@ int Fs::sweep_inode_datablocks(INode_Data *inode_data, DatablockOperation *op) { int result; + printf("%llu %llu %llu\n", NUMBER_OF_DIRECT_BLOCKS, INDIRECT_BLOCKS, INDIRECT_BLOCKS * INDIRECT_BLOCKS); + u_int64_t start_index = start_block_index; for (size_t i = start_index; i < NUMBER_OF_DIRECT_BLOCKS; ++i) { if ((result = sweep_datablocks(&(inode_data->direct_blocks[i]), 0, 0, @@ -25,25 +27,25 @@ int Fs::sweep_inode_datablocks(INode_Data *inode_data, start_index -= NUMBER_OF_DIRECT_BLOCKS; - if (start_index < IO_BLOCK_SIZE) { + if (start_index < INDIRECT_BLOCKS) { if ((result = sweep_datablocks(&(inode_data->single_indirect_block), 1, start_index, allocate, op)) <= 0) return result; - start_index = IO_BLOCK_SIZE; + start_index = INDIRECT_BLOCKS; } - start_index -= IO_BLOCK_SIZE; + start_index -= INDIRECT_BLOCKS; - if (start_index < IO_BLOCK_SIZE * IO_BLOCK_SIZE) { + if (start_index < INDIRECT_BLOCKS * INDIRECT_BLOCKS) { if ((result = sweep_datablocks(&(inode_data->double_indirect_block), 2, start_index, allocate, op)) <= 0) return result; - start_index = IO_BLOCK_SIZE * IO_BLOCK_SIZE; + start_index = INDIRECT_BLOCKS * INDIRECT_BLOCKS; } - start_index -= IO_BLOCK_SIZE * IO_BLOCK_SIZE; + start_index -= INDIRECT_BLOCKS * INDIRECT_BLOCKS; - if (start_index < (u_int64_t)IO_BLOCK_SIZE * IO_BLOCK_SIZE * IO_BLOCK_SIZE) { + if (start_index < (u_int64_t)INDIRECT_BLOCKS * INDIRECT_BLOCKS * INDIRECT_BLOCKS) { if ((result = sweep_datablocks(&(inode_data->triple_indirect_block), 3, start_index, allocate, op)) <= 0) return result; @@ -61,6 +63,8 @@ int Fs::sweep_datablocks(u_int64_t *block_num, int indirect_num, int err; int result = -1; + //printf("SWEEP %llu %d %llu %d\n", *block_num, indirect_num, start_block_index, int(allocate)); + if (allocate && (*block_num) == 0) if ((err = datablock_manager->new_datablock(block_num)) < 0) return err; @@ -74,10 +78,11 @@ int Fs::sweep_datablocks(u_int64_t *block_num, int indirect_num, if ((err = disk->read_block(*block_num, buf)) < 0) return err; } + u_int64_t indirect_block_size = 1; for (int i = 1; i < indirect_num; ++i) - indirect_block_size *= IO_BLOCK_SIZE; + indirect_block_size *= INDIRECT_BLOCKS; u_int64_t this_layer_start_index = start_block_index / indirect_block_size; u_int64_t next_layer_start_index = @@ -86,6 +91,7 @@ int Fs::sweep_datablocks(u_int64_t *block_num, int indirect_num, u_int64_t temp; u_int64_t next_block_num; bool modified = false; + //printf("SWEEP TO LOWER LEVEL %llu %llu %llu\n", this_layer_start_index, next_layer_start_index, indirect_block_size); for (size_t i = this_layer_start_index * sizeof(u_int64_t); i < IO_BLOCK_SIZE; i += sizeof(u_int64_t)) {