diff --git a/src/simple-mtpfs-fuse.cpp b/src/simple-mtpfs-fuse.cpp index ffc8b79..772bb42 100644 --- a/src/simple-mtpfs-fuse.cpp +++ b/src/simple-mtpfs-fuse.cpp @@ -167,6 +167,11 @@ int wrap_create(const char *path, mode_t mode, fuse_file_info *file_info) return SMTPFileSystem::instance()->create(path, mode, file_info); } +int wrap_ftruncate(const char *path, off_t offset, struct fuse_file_info *file_info) +{ + return SMTPFileSystem::instance()->ftruncate(path, offset, file_info); +} + // ----------------------------------------------------------------------------- std::unique_ptr SMTPFileSystem::s_instance; @@ -217,6 +222,7 @@ SMTPFileSystem::SMTPFileSystem(): m_fuse_operations.destroy = nullptr; m_fuse_operations.access = nullptr; m_fuse_operations.create = wrap_create; + m_fuse_operations.ftruncate = wrap_ftruncate; } SMTPFileSystem::~SMTPFileSystem() @@ -621,6 +627,10 @@ int SMTPFileSystem::fsyncdir(const char *path, int datasync, int SMTPFileSystem::ftruncate(const char *path, off_t offset, struct fuse_file_info *file_info) { + const TypeTmpFile *tmp_file = m_tmp_files_pool.getFile(file_info->fh); + if (::ftruncate(file_info->fh, offset) != 0) + return -errno; + const_cast(tmp_file)->setModified(); return 0; } diff --git a/src/simple-mtpfs-fuse.h b/src/simple-mtpfs-fuse.h index b2d076d..975ba20 100644 --- a/src/simple-mtpfs-fuse.h +++ b/src/simple-mtpfs-fuse.h @@ -101,7 +101,7 @@ public: int readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *file_info); int releasedir(const char *path, struct fuse_file_info *file_info); int fsyncdir(const char *path, int datasync, struct fuse_file_info *file_info); - int truncate(const char *path, off_t offset, struct fuse_file_info *file_info); + int ftruncate(const char *path, off_t offset, struct fuse_file_info *file_info); void* init(struct fuse_conn_info *conn); int create(const char *path, mode_t mode, fuse_file_info *file_info);