aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Pärtel <martin.partel@gmail.com>2014-05-10 12:37:38 +0100
committerMartin Pärtel <martin.partel@gmail.com>2014-05-10 12:37:38 +0100
commitdc0cf937e50ea1abb7ce439a011531ddb3bbda02 (patch)
tree222fbf368ca78c6ef67787c0790280ae3614b385 /src
parent60fc1f3f085983aa3fbb74102c270be8de15f9e5 (diff)
downloadbindfs-dc0cf937e50ea1abb7ce439a011531ddb3bbda02.tar.gz
Use lutimes() when utimensat() unavailable (#6).
Diffstat (limited to 'src')
-rw-r--r--src/bindfs.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/bindfs.c b/src/bindfs.c
index c2fd76f..1138592 100644
--- a/src/bindfs.c
+++ b/src/bindfs.c
@@ -34,6 +34,10 @@
/* For >= 500 for pread/pwrite and readdir_r; >= 700 for utimensat */
#define _XOPEN_SOURCE 700
+#if !HAVE_UTIMENSAT && HAVE_LUTIMES
+#define _BSD_SOURCE
+#endif
+
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
@@ -45,6 +49,7 @@
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
+#include <sys/time.h>
#include <sys/statvfs.h>
#include <unistd.h>
#include <fcntl.h>
@@ -177,11 +182,7 @@ static int bindfs_chown(const char *path, uid_t uid, gid_t gid);
static int bindfs_truncate(const char *path, off_t size);
static int bindfs_ftruncate(const char *path, off_t size,
struct fuse_file_info *fi);
-#ifdef __APPLE__
-static int bindfs_utime(const char *path, struct utimbuf *buf);
-#else
static int bindfs_utimens(const char *path, const struct timespec tv[2]);
-#endif
static int bindfs_create(const char *path, mode_t mode, struct fuse_file_info *fi);
static int bindfs_open(const char *path, struct fuse_file_info *fi);
static int bindfs_read(const char *path, char *buf, size_t size, off_t offset,
@@ -694,21 +695,25 @@ static int bindfs_ftruncate(const char *path, off_t size,
return 0;
}
-#ifdef __APPLE__
-static int bindfs_utime(const char *path, struct utimbuf *buf)
-#else
-static int bindfs_utimens(const char *path, const struct timespec tv[2])
-#endif
+static int bindfs_utimens(const char *path, const struct timespec ts[2])
{
int res;
path = process_path(path);
- #ifdef __APPLE__
- res = utime(path, buf);
- #else
- res = utimensat(settings.mntsrc_fd, path, tv, AT_SYMLINK_NOFOLLOW);
- #endif
+#ifdef HAVE_UTIMENSAT
+ res = utimensat(settings.mntsrc_fd, path, ts, AT_SYMLINK_NOFOLLOW);
+#elif HAVE_LUTIMES
+ struct timeval tv[2];
+ tv[0].tv_sec = ts[0].tv_sec;
+ tv[0].tv_usec = ts[0].tv_nsec / 1000;
+ tv[1].tv_sec = ts[1].tv_sec;
+ tv[1].tv_usec = ts[1].tv_nsec / 1000;
+ res = lutimes(path, tv);
+#else
+#error "No symlink-compatible utime* function available."
+#endif
+
if (res == -1)
return -errno;
@@ -918,11 +923,7 @@ static struct fuse_operations bindfs_oper = {
.chown = bindfs_chown,
.truncate = bindfs_truncate,
.ftruncate = bindfs_ftruncate,
- #ifdef __APPLE__
- .utime = bindfs_utime,
- #else
.utimens = bindfs_utimens,
- #endif
.create = bindfs_create,
.open = bindfs_open,
.read = bindfs_read,