Skip to content

Commit

Permalink
Properly implemented and fixed file truncation.
Browse files Browse the repository at this point in the history
Edits which remove lines should now properly work! :)
Also changed the makefile to work properly with some fussier gcc setups.
  • Loading branch information
ecpre committed Mar 5, 2023
1 parent faa0bb3 commit 06bc670
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
26 changes: 22 additions & 4 deletions FuseRedSea.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,9 @@ void write_file(struct redsea_file* file, const char* buffer, size_t size, off_t
rewind(image);
fseek(image, block*BLOCK_SIZE, SEEK_SET);
fseek(image, offset, SEEK_CUR);
// pad last RS block
fwrite(buffer, size, 1, image);

// is this check unnecessary after properly implementing truncate? I think so? I'll leave it in.
if ((size+offset) > file->size) {
file->size += (size+offset)-file->size; // set file size
}
Expand Down Expand Up @@ -713,10 +714,27 @@ static int fuse_rs_write(const char* path, const char* buffer, size_t size, off_
return size;
}

static int fuse_rs_truncate(const char* path, off_t offset) {
static int fuse_rs_truncate(const char* path, off_t length) {

/* It seems that I forgot the proper reasons for truncate to exist when I
* release this last time. :(
* Corrupted files shouldn't be an issue anymore
*/
unsigned long long int fid = file_position(path);
struct redsea_file* file = file_structs[fid];

file->size = length;

unsigned char size_char[8] = {length & 0xff, (length >> 8) & 0xff, (length >> 16) & 0xff, (length >> 24) & 0xff,
(length >> 32) & 0xff, (length >> 40) & 0xff, (length >> 48) & 0xff, (length >> 56) & 0xff};

// we are just going to ignore truncate ;)
return offset;
rewind(image);
fseek(image, file->parent->block*BLOCK_SIZE, SEEK_SET);
fseek(image, file->seek_to, SEEK_CUR);
fseek(image, 48, SEEK_CUR);
fwrite(size_char, 8, 1, image);

return length;
}

static void fuse_rs_destroy() {
Expand Down
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
redseabuild:
gcc -I/usr/include/fuse -lfuse FuseRedSea.c -o redsea
gcc -I/usr/include/fuse FuseRedSea.c -lfuse -o redsea
debug:
gcc -Wall -g -O0 -I/usr/include/fuse -lfuse FuseRedSea.c -o redsea
gcc -Wall -g -O0 -I/usr/include/fuse FuseRedSea.c -lfuse -o redsea

all: redseabuild

0 comments on commit 06bc670

Please sign in to comment.