fixed a bug of indirect layers

This commit is contained in:
FactorialN 2023-12-01 19:04:00 -08:00
parent f1cfc5022e
commit de198df6d1
3 changed files with 16 additions and 9 deletions

View File

@ -12,6 +12,7 @@
#include <unistd.h> #include <unistd.h>
#define IO_BLOCK_SIZE 4096 #define IO_BLOCK_SIZE 4096
#define INDIRECT_BLOCKS 512
#define NUM_INODE_BLOCKS 1023 #define NUM_INODE_BLOCKS 1023
#define NUM_BLOCKS 2048 #define NUM_BLOCKS 2048

View File

@ -333,7 +333,7 @@ int FilesOperation::fischl_readdir(const char *path, void *buf, fuse_fill_dir_t
ent.deserialize(buffer+i); ent.deserialize(buffer+i);
if (ent.inode_number) { if (ent.inode_number) {
filler(buf, ent.file_name, NULL, 0, FUSE_FILL_DIR_PLUS); 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);
} }
} }
} }

View File

@ -15,6 +15,8 @@ int Fs::sweep_inode_datablocks(INode_Data *inode_data,
DatablockOperation *op) { DatablockOperation *op) {
int result; 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; u_int64_t start_index = start_block_index;
for (size_t i = start_index; i < NUMBER_OF_DIRECT_BLOCKS; ++i) { for (size_t i = start_index; i < NUMBER_OF_DIRECT_BLOCKS; ++i) {
if ((result = sweep_datablocks(&(inode_data->direct_blocks[i]), 0, 0, 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; 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, if ((result = sweep_datablocks(&(inode_data->single_indirect_block), 1,
start_index, allocate, op)) <= 0) start_index, allocate, op)) <= 0)
return result; 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, if ((result = sweep_datablocks(&(inode_data->double_indirect_block), 2,
start_index, allocate, op)) <= 0) start_index, allocate, op)) <= 0)
return result; 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, if ((result = sweep_datablocks(&(inode_data->triple_indirect_block), 3,
start_index, allocate, op)) <= 0) start_index, allocate, op)) <= 0)
return result; return result;
@ -61,6 +63,8 @@ int Fs::sweep_datablocks(u_int64_t *block_num, int indirect_num,
int err; int err;
int result = -1; 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 (allocate && (*block_num) == 0)
if ((err = datablock_manager->new_datablock(block_num)) < 0) if ((err = datablock_manager->new_datablock(block_num)) < 0)
return err; 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) if ((err = disk->read_block(*block_num, buf)) < 0)
return err; return err;
} }
u_int64_t indirect_block_size = 1; u_int64_t indirect_block_size = 1;
for (int i = 1; i < indirect_num; ++i) 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 this_layer_start_index = start_block_index / indirect_block_size;
u_int64_t next_layer_start_index = 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 temp;
u_int64_t next_block_num; u_int64_t next_block_num;
bool modified = false; 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; for (size_t i = this_layer_start_index * sizeof(u_int64_t); i < IO_BLOCK_SIZE;
i += sizeof(u_int64_t)) { i += sizeof(u_int64_t)) {