From 8edeaa3f29b418f621542c72d77ba0c639e6d457 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Wed, 6 Jul 2011 12:12:01 +0200 Subject: 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. --- example/fusexmp_fh.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'example') 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 #endif +#include /* 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, }; -- cgit v1.2.3