From b5c9c8540a29babf990ff72b1eb5904424f1abb0 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sun, 21 Feb 2016 22:44:47 -0500 Subject: Implement ftruncate --- src/operations.cc | 6 ++++++ src/posix_extras.cc | 2 ++ src/posix_extras.h | 3 +++ 3 files changed, 11 insertions(+) diff --git a/src/operations.cc b/src/operations.cc index b1c568a..a82ad99 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -224,6 +224,11 @@ int Releasedir(const char*, fuse_file_info* const file_info) { return ReleaseResource(file_info->fh); } +int Ftruncate(const char*, const off_t size, fuse_file_info* const file_info) { + reinterpret_cast(file_info->fh)->Truncate(size); + return 0; +} + int Rmdir(const char* c_path) { const std::string path(c_path); if (path == "/") { @@ -275,6 +280,7 @@ fuse_operations FuseOperations(File* const root) { result.write = CATCH_AND_RETURN_EXCEPTIONS(Write); result.utimens = CATCH_AND_RETURN_EXCEPTIONS(Utimens); result.release = CATCH_AND_RETURN_EXCEPTIONS(Release); + result.ftruncate = CATCH_AND_RETURN_EXCEPTIONS(Ftruncate); result.unlink = CATCH_AND_RETURN_EXCEPTIONS(Unlink); result.symlink = CATCH_AND_RETURN_EXCEPTIONS(Symlink); diff --git a/src/posix_extras.cc b/src/posix_extras.cc index 11db247..c0a5234 100644 --- a/src/posix_extras.cc +++ b/src/posix_extras.cc @@ -154,6 +154,8 @@ void File::SymLinkAt(const char* const target, const char* const source) const { CheckSyscall(symlinkat(target, fd_, source)); } +void File::Truncate(const off_t size) { CheckSyscall(ftruncate(fd_, size)); } + void File::UnlinkAt(const char* const path) const { ValidatePath(path); CheckSyscall(unlinkat(fd_, path, 0)); diff --git a/src/posix_extras.h b/src/posix_extras.h index 889175e..b67e2b4 100644 --- a/src/posix_extras.h +++ b/src/posix_extras.h @@ -112,6 +112,9 @@ class File { // indeed be relative (i.e., it must not start with '/'). void SymLinkAt(const char* target, const char* source) const; + // Truncates the file to the specified size. + void Truncate(off_t); + // Removes the file at the path relative to the file descriptor. The path // must indeed be relative (i.e., it must not start with '/'). void UnlinkAt(const char* path) const; -- cgit v1.2.3