aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2016-02-21 22:44:47 -0500
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2016-02-21 22:48:53 -0500
commitb5c9c8540a29babf990ff72b1eb5904424f1abb0 (patch)
tree423e7f183a75a453134d302f9a7f0ff1121f5cbb
parent604841c6c81608a7dfcfe05ab75fa0c7ede2a890 (diff)
Implement ftruncate
-rw-r--r--src/operations.cc6
-rw-r--r--src/posix_extras.cc2
-rw-r--r--src/posix_extras.h3
3 files changed, 11 insertions, 0 deletions
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<Directory>(file_info->fh);
}
+int Ftruncate(const char*, const off_t size, fuse_file_info* const file_info) {
+ reinterpret_cast<File*>(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;