From 4a2dd3e609b8c72bfb74fb5b4c12effea9e80504 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 27 Nov 2022 20:26:45 +0100 Subject: [PATCH] added utimens --- src/webfuse/filesystem.cpp | 19 +++++++++++++++++++ src/webfuse/filesystem.hpp | 1 + src/webfuse/filesystem/empty_filesystem.cpp | 5 +++++ src/webfuse/filesystem/empty_filesystem.hpp | 1 + src/webfuse/filesystem/filesystem_i.hpp | 1 + src/webfuse/message_type.hpp | 3 ++- src/webfuse/ws/messagewriter.cpp | 6 ++++++ src/webfuse/ws/messagewriter.hpp | 1 + 8 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/webfuse/filesystem.cpp b/src/webfuse/filesystem.cpp index 574f990..0a14376 100644 --- a/src/webfuse/filesystem.cpp +++ b/src/webfuse/filesystem.cpp @@ -190,6 +190,25 @@ int filesystem::fsync(std::string const & path, bool is_datasync, uint64_t handl } } +int filesystem::utimens(std::string const &path, struct timespec tv[2], uint64_t handle) +{ + try + { + messagewriter req(message_type::utimens_req); + req.write_str(path); + req.write_time(tv[0]); + req.write_time(tv[1]); + req.write_u64(handle); + auto reader = proxy.perform(std::move(req)); + return reader.read_result(); + } + catch(...) + { + return fallback.utimens(path, tv, handle); + } +} + + int filesystem::open(std::string const & path, int flags, uint64_t & handle) { try diff --git a/src/webfuse/filesystem.hpp b/src/webfuse/filesystem.hpp index 8b3c44c..ca1e29e 100644 --- a/src/webfuse/filesystem.hpp +++ b/src/webfuse/filesystem.hpp @@ -30,6 +30,7 @@ public: int chown(std::string const & path, uid_t uid, gid_t gid) override; int truncate(std::string const & path, uint64_t size, uint64_t handle) override; int fsync(std::string const & path, bool is_datasync, uint64_t handle) override; + int utimens(std::string const &path, struct timespec tv[2], uint64_t handle) override; int open(std::string const & path, int flags, uint64_t & handle) override; int mknod(std::string const & path, mode_t mode, dev_t rdev) override; diff --git a/src/webfuse/filesystem/empty_filesystem.cpp b/src/webfuse/filesystem/empty_filesystem.cpp index c9389e2..b0d33b3 100644 --- a/src/webfuse/filesystem/empty_filesystem.cpp +++ b/src/webfuse/filesystem/empty_filesystem.cpp @@ -71,6 +71,11 @@ int empty_filesystem::fsync(std::string const & path, bool is_datasync, uint64_t return 0; } +int empty_filesystem::utimens(std::string const &path, struct timespec tv[2], uint64_t handle) +{ + return -ENOSYS; +} + int empty_filesystem::open(std::string const & path, int flags, uint64_t & handle) { return -ENOENT; diff --git a/src/webfuse/filesystem/empty_filesystem.hpp b/src/webfuse/filesystem/empty_filesystem.hpp index b26477f..c271063 100644 --- a/src/webfuse/filesystem/empty_filesystem.hpp +++ b/src/webfuse/filesystem/empty_filesystem.hpp @@ -23,6 +23,7 @@ public: int chown(std::string const & path, uid_t uid, gid_t gid) override; int truncate(std::string const & path, uint64_t size, uint64_t handle) override; int fsync(std::string const & path, bool is_datasync, uint64_t handle) override; + int utimens(std::string const &path, struct timespec tv[2], uint64_t handle) override; int open(std::string const & path, int flags, uint64_t & handle) override; int mknod(std::string const & path, mode_t mode, dev_t rdev) override; diff --git a/src/webfuse/filesystem/filesystem_i.hpp b/src/webfuse/filesystem/filesystem_i.hpp index d1de857..2d42e52 100644 --- a/src/webfuse/filesystem/filesystem_i.hpp +++ b/src/webfuse/filesystem/filesystem_i.hpp @@ -30,6 +30,7 @@ public: virtual int chown(std::string const & path, uid_t uid, gid_t gid) = 0; virtual int truncate(std::string const & path, uint64_t size, uint64_t handle) = 0; virtual int fsync(std::string const & path, bool is_datasync, uint64_t handle) = 0; + virtual int utimens(std::string const &path, struct timespec tv[2], uint64_t handle) = 0; virtual int open(std::string const & path, int flags, uint64_t & handle) = 0; virtual int mknod(std::string const & path, mode_t mode, dev_t rdev) = 0; diff --git a/src/webfuse/message_type.hpp b/src/webfuse/message_type.hpp index b876b40..871466e 100644 --- a/src/webfuse/message_type.hpp +++ b/src/webfuse/message_type.hpp @@ -28,7 +28,8 @@ enum class message_type: uint8_t mkdir_req = 0x12, readdir_req = 0x13, rmdir_req = 0x14, - statfs_req = 0x15 + statfs_req = 0x15, + utimens_req = 0x16 }; diff --git a/src/webfuse/ws/messagewriter.cpp b/src/webfuse/ws/messagewriter.cpp index 7cdcbd8..3a8d4f6 100644 --- a/src/webfuse/ws/messagewriter.cpp +++ b/src/webfuse/ws/messagewriter.cpp @@ -161,6 +161,12 @@ void messagewriter::write_openflags(int value) write_i32(flags); } +void messagewriter::write_time(timespec const & value) +{ + write_u64(static_cast(value.tv_sec)); + write_u32(static_cast(value.tv_nsec)); +} + unsigned char * messagewriter::get_data(size_t &size) { diff --git a/src/webfuse/ws/messagewriter.hpp b/src/webfuse/ws/messagewriter.hpp index c44ab11..22b58d6 100644 --- a/src/webfuse/ws/messagewriter.hpp +++ b/src/webfuse/ws/messagewriter.hpp @@ -39,6 +39,7 @@ public: void write_uid(uid_t value); void write_gid(gid_t value); void write_openflags(int value); + void write_time(timespec const & value); unsigned char * get_data(size_t &size);