Skip to content

Commit

Permalink
Added support for truncate on files
Browse files Browse the repository at this point in the history
  • Loading branch information
geky committed Jan 23, 2018
1 parent 3f1ed6e commit ed8713c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lfs_fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,28 @@ int lfs_fuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) {
return lfs_fuse_fsync(path, 0, fi);
}

// unsupported functions
int lfs_fuse_ftruncate(const char *path, off_t size,
struct fuse_file_info *fi) {
lfs_file_t *file = (lfs_file_t*)fi->fh;
return lfs_file_truncate(&lfs, file, size);
}

int lfs_fuse_truncate(const char *path, off_t size) {
// not supported, fail
return -EPERM;
lfs_file_t file;
int err = lfs_file_open(&lfs, &file, path, LFS_O_WRONLY);
if (err) {
return err;
}

err = lfs_file_truncate(&lfs, &file, size);
if (err) {
return err;
}

return lfs_file_close(&lfs, &file);
}

// unsupported functions
int lfs_fuse_link(const char *from, const char *to) {
// not supported, fail
return -EPERM;
Expand Down

0 comments on commit ed8713c

Please # to comment.