aboutsummaryrefslogtreecommitdiffstats
path: root/example/fusexmp_fh.c
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@suse.cz>2011-07-06 12:12:01 +0200
committerMiklos Szeredi <mszeredi@suse.cz>2011-07-06 12:12:01 +0200
commit8edeaa3f29b418f621542c72d77ba0c639e6d457 (patch)
tree2ed1297e688d1f37c7b92ce09dfb38025066900c /example/fusexmp_fh.c
parentc605b5f73c458eeacdb6653e6899b5ebe7f1fc1a (diff)
downloadlibfuse-8edeaa3f29b418f621542c72d77ba0c639e6d457.tar.gz
Add ->flock() operation to low and high level interfaces
This fixes problems with emulating flock() with POSIX locking. Reported by Sebastian Pipping. As with lock/setlk/getlk most filesystems don't need to implement this, as the kernel takes care of file locking. The only reason to implement locking operations is for network filesystems which want file locking to work between clients.
Diffstat (limited to 'example/fusexmp_fh.c')
-rw-r--r--example/fusexmp_fh.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/example/fusexmp_fh.c b/example/fusexmp_fh.c
index 96427b3..046185c 100644
--- a/example/fusexmp_fh.c
+++ b/example/fusexmp_fh.c
@@ -31,6 +31,7 @@
#ifdef HAVE_SETXATTR
#include <sys/xattr.h>
#endif
+#include <sys/file.h> /* flock(2) */
static int xmp_getattr(const char *path, struct stat *stbuf)
{
@@ -481,6 +482,18 @@ static int xmp_lock(const char *path, struct fuse_file_info *fi, int cmd,
sizeof(fi->lock_owner));
}
+static int xmp_flock(const char *path, struct fuse_file_info *fi, int op)
+{
+ int res;
+ (void) path;
+
+ res = flock(fi->fh, op);
+ if (res == -1)
+ return -errno;
+
+ return 0;
+}
+
static struct fuse_operations xmp_oper = {
.getattr = xmp_getattr,
.fgetattr = xmp_fgetattr,
@@ -518,6 +531,7 @@ static struct fuse_operations xmp_oper = {
.removexattr = xmp_removexattr,
#endif
.lock = xmp_lock,
+ .flock = xmp_flock,
.flag_nullpath_ok = 1,
};