From 978d10a42b2cfccf6bfc4df1cfad480ac3bbcb3d Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Tue, 15 Jul 2014 17:41:02 +0200 Subject: [PATCH] libfuse: allow setting ctime in ->setattr() --- ChangeLog | 2 ++ include/fuse_kernel.h | 7 +++++-- include/fuse_lowlevel.h | 1 + lib/fuse_lowlevel.c | 5 ++++- lib/fuse_misc.h | 3 +++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 167ca7e..a5f611d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,8 @@ specify the time granularity it supports when the kernel is responsible for updating times ("writeback_cache" option). + * libfuse: allow setting ctime in ->setattr() + 2014-03-26 Miklos Szeredi * Initilaize stat buffer passed to ->getattr() and ->fgetattr() to diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h index d1b4e2c..e86a21a 100644 --- a/include/fuse_kernel.h +++ b/include/fuse_kernel.h @@ -98,6 +98,8 @@ * - add FUSE_WRITEBACK_CACHE * - add time_gran to fuse_init_out * - add reserved space to fuse_init_out + * - add FATTR_CTIME + * - add ctime and ctimensec to fuse_setattr_in */ #ifndef _LINUX_FUSE_H @@ -193,6 +195,7 @@ struct fuse_file_lock { #define FATTR_ATIME_NOW (1 << 7) #define FATTR_MTIME_NOW (1 << 8) #define FATTR_LOCKOWNER (1 << 9) +#define FATTR_CTIME (1 << 10) /** * Flags returned by the OPEN request @@ -440,10 +443,10 @@ struct fuse_setattr_in { uint64_t lock_owner; uint64_t atime; uint64_t mtime; - uint64_t unused2; + uint64_t ctime; uint32_t atimensec; uint32_t mtimensec; - uint32_t unused3; + uint32_t ctimensec; uint32_t mode; uint32_t unused4; uint32_t uid; diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h index 31ea87f..8eef9b9 100644 --- a/include/fuse_lowlevel.h +++ b/include/fuse_lowlevel.h @@ -135,6 +135,7 @@ struct fuse_forget_data { #define FUSE_SET_ATTR_MTIME (1 << 5) #define FUSE_SET_ATTR_ATIME_NOW (1 << 7) #define FUSE_SET_ATTR_MTIME_NOW (1 << 8) +#define FUSE_SET_ATTR_CTIME (1 << 10) /* ----------------------------------------------------------- * * Request methods and replies * diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c index dc27cb5..9131811 100755 --- a/lib/fuse_lowlevel.c +++ b/lib/fuse_lowlevel.c @@ -79,8 +79,10 @@ static void convert_attr(const struct fuse_setattr_in *attr, struct stat *stbuf) stbuf->st_size = attr->size; stbuf->st_atime = attr->atime; stbuf->st_mtime = attr->mtime; + stbuf->st_ctime = attr->ctime; ST_ATIM_NSEC_SET(stbuf, attr->atimensec); ST_MTIM_NSEC_SET(stbuf, attr->mtimensec); + ST_CTIM_NSEC_SET(stbuf, attr->ctimensec); } static size_t iov_length(const struct iovec *iov, size_t count) @@ -1173,7 +1175,8 @@ static void do_setattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME | FUSE_SET_ATTR_ATIME_NOW | - FUSE_SET_ATTR_MTIME_NOW; + FUSE_SET_ATTR_MTIME_NOW | + FUSE_SET_ATTR_CTIME; req->f->op.setattr(req, nodeid, &stbuf, arg->valid, fi); } else diff --git a/lib/fuse_misc.h b/lib/fuse_misc.h index 8b76775..1839a67 100644 --- a/lib/fuse_misc.h +++ b/lib/fuse_misc.h @@ -28,6 +28,7 @@ static inline void fuse_mutex_init(pthread_mutex_t *mut) #define ST_CTIM_NSEC(stbuf) ((stbuf)->st_ctim.tv_nsec) #define ST_MTIM_NSEC(stbuf) ((stbuf)->st_mtim.tv_nsec) #define ST_ATIM_NSEC_SET(stbuf, val) (stbuf)->st_atim.tv_nsec = (val) +#define ST_CTIM_NSEC_SET(stbuf, val) (stbuf)->st_ctim.tv_nsec = (val) #define ST_MTIM_NSEC_SET(stbuf, val) (stbuf)->st_mtim.tv_nsec = (val) #elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC) /* FreeBSD */ @@ -35,11 +36,13 @@ static inline void fuse_mutex_init(pthread_mutex_t *mut) #define ST_CTIM_NSEC(stbuf) ((stbuf)->st_ctimespec.tv_nsec) #define ST_MTIM_NSEC(stbuf) ((stbuf)->st_mtimespec.tv_nsec) #define ST_ATIM_NSEC_SET(stbuf, val) (stbuf)->st_atimespec.tv_nsec = (val) +#define ST_CTIM_NSEC_SET(stbuf, val) (stbuf)->st_ctimespec.tv_nsec = (val) #define ST_MTIM_NSEC_SET(stbuf, val) (stbuf)->st_mtimespec.tv_nsec = (val) #else #define ST_ATIM_NSEC(stbuf) 0 #define ST_CTIM_NSEC(stbuf) 0 #define ST_MTIM_NSEC(stbuf) 0 #define ST_ATIM_NSEC_SET(stbuf, val) do { } while (0) +#define ST_CTIM_NSEC_SET(stbuf, val) do { } while (0) #define ST_MTIM_NSEC_SET(stbuf, val) do { } while (0) #endif -- 2.30.2