From c2f3aa1310f74d6d4b6273405dc0aa01c4a55e99 Mon Sep 17 00:00:00 2001 From: FactorialN <8838579+FactorialN@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:59:06 -0800 Subject: [PATCH] fixed fuse offset issue, but still haven't fixed the problem with written file length --- lib/files.cpp | 7 ++----- lib/fischl.cpp | 4 ++-- lib/fs/fs_read_write.cpp | 5 ----- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/files.cpp b/lib/files.cpp index 032955c..7147b76 100644 --- a/lib/files.cpp +++ b/lib/files.cpp @@ -567,15 +567,13 @@ int FilesOperation::fischl_write(const char *path, const char *buf, size_t size, // return -ENOENT; // Caution! this based on content in file are multiple of IO_BLOCK_SIZE, not the exact write size. // based on current write_datablock API implement, when write_datablock pass with actual size not index this function should be fixed + INode_Data inode; // Assuming inode is correctly initialized here based on 'path' inode.inode_num = fi->fh; fs->inode_manager->load_inode(&inode); //size_t len = (inode.metadata.size/IO_BLOCK_SIZE) * IO_BLOCK_SIZE; // Assuming each block is 4096 bytes - - char buffer[size]; - strcpy(buffer, buf); - printf("received offset %d\n", offset); + char *buffer = strdup(buf); size_t bytes_write = fs->write(&inode, buffer, size, offset); /*size_t block_index = offset / IO_BLOCK_SIZE; // Starting block index size_t block_offset = offset % IO_BLOCK_SIZE; // Offset within the first block @@ -590,7 +588,6 @@ int FilesOperation::fischl_write(const char *path, const char *buf, size_t size, block_offset = 0; // Only the first block might have a non-zero offset }*/ fs->inode_manager->save_inode(&inode); - printf("received offset %llu\n", inode.metadata.size); return bytes_write; // Return the actual number of bytes read } diff --git a/lib/fischl.cpp b/lib/fischl.cpp index 40dc8bc..3bc3b6e 100644 --- a/lib/fischl.cpp +++ b/lib/fischl.cpp @@ -124,7 +124,7 @@ static int fischl_read(const char* path, char *buf, size_t size, off_t offset, s } static int fischl_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { - return options.fsop->fischl_write(path, buf, size, offset, fi); + return options.fsop->fischl_write(path, buf, size, offset, fi); } static int fischl_statfs(const char* path, struct statvfs* stbuf) { @@ -213,7 +213,7 @@ int fischl(int argc, char *argv[]) //const char* d = (argc < 2) ? "/dev/vdc" : argv[1]; //setupTestDirectory(&options.root); - options.H = new FakeRawDisk(21504); + options.H = new FakeRawDisk(23552); options.fs = new Fs(options.H); options.fs->format(); options.fsop = new FilesOperation(*options.H, options.fs); diff --git a/lib/fs/fs_read_write.cpp b/lib/fs/fs_read_write.cpp index 1dda70a..3ffccff 100644 --- a/lib/fs/fs_read_write.cpp +++ b/lib/fs/fs_read_write.cpp @@ -61,16 +61,13 @@ int Fs::sweep_datablocks(u_int64_t *block_num, int indirect_num, int err; int result = -1; - printf("SURVIVED 1\n"); if (allocate && (*block_num) == 0) if ((err = datablock_manager->new_datablock(block_num)) < 0) return err; - printf("SURVIVED 2 %d\n", indirect_num); if (indirect_num == 0) return op->operation(*block_num); - printf("SURVIVED 3\n"); if ((*block_num) == 0) { memset(buf, 0, sizeof(buf)); } else { @@ -104,11 +101,9 @@ int Fs::sweep_datablocks(u_int64_t *block_num, int indirect_num, if (result == 0) break; } - printf("SURVIVED 4 %llu %d %llu\n", *block_num, result, this_layer_start_index); if (modified) if ((err = disk->write_block(*block_num, buf)) < 0) return err; - printf("SURVIVED 5 %d\n", result); return result; }