aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2016-02-22 22:55:05 -0500
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2016-02-22 22:55:05 -0500
commit69ef8f9008c612656649c93f33d3a5279a6483bb (patch)
tree0e918b230acc9dc581b58297744f220b07044f7c
parent1cdab3af0d1a53f75700ff437a59756052a403d8 (diff)
Implement truncate
-rw-r--r--src/operations.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/operations.cc b/src/operations.cc
index 8e2b008..bff7bce 100644
--- a/src/operations.cc
+++ b/src/operations.cc
@@ -235,6 +235,16 @@ int Releasedir(const char*, fuse_file_info* const file_info) {
return ReleaseResource<Directory>(file_info->fh);
}
+int Truncate(const char* const c_path, const off_t size) {
+ const std::string path(Encode(c_path));
+ if (path == "/") {
+ return -EISDIR;
+ } else {
+ root_->OpenAt(MakeRelative(path).c_str(), O_WRONLY).Truncate(size);
+ return 0;
+ }
+}
+
int Ftruncate(const char*, const off_t size, fuse_file_info* const file_info) {
reinterpret_cast<File*>(file_info->fh)->Truncate(size);
return 0;
@@ -294,6 +304,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.truncate = CATCH_AND_RETURN_EXCEPTIONS(Truncate);
result.ftruncate = CATCH_AND_RETURN_EXCEPTIONS(Ftruncate);
result.unlink = CATCH_AND_RETURN_EXCEPTIONS(Unlink);