diff options
author | Nikolaus Rath <Nikolaus@rath.org> | 2016-10-15 18:46:27 -0700 |
---|---|---|
committer | Nikolaus Rath <Nikolaus@rath.org> | 2016-10-15 18:46:27 -0700 |
commit | 73b6ff4b75cf1228ea61262c293fcb2fda5dfeea (patch) | |
tree | 059d5dbe8d2549f5bf363c6174c5887d44f1ee42 /example | |
parent | d49f2e77b4741706ec125cc62ea913ed5d39bd39 (diff) | |
download | libfuse-73b6ff4b75cf1228ea61262c293fcb2fda5dfeea.tar.gz |
Pass fuse_file_info to getattr, chown, chmod, truncate, utimens handlers
This obsoletes the ftruncate & fgetattr handlers.
Fixes #58.
Diffstat (limited to 'example')
-rw-r--r-- | example/hello.c | 4 | ||||
-rw-r--r-- | example/ioctl.c | 8 | ||||
-rw-r--r-- | example/passthrough.c | 20 | ||||
-rw-r--r-- | example/passthrough_fh.c | 63 | ||||
-rw-r--r-- | example/poll.c | 4 |
5 files changed, 55 insertions, 44 deletions
diff --git a/example/hello.c b/example/hello.c index bf6ccf4..c587d72 100644 --- a/example/hello.c +++ b/example/hello.c @@ -68,8 +68,10 @@ static const struct fuse_opt option_spec[] = { FUSE_OPT_END }; -static int hello_getattr(const char *path, struct stat *stbuf) +static int hello_getattr(const char *path, struct stat *stbuf, + struct fuse_file_info *fi) { + (void) fi; int res = 0; memset(stbuf, 0, sizeof(struct stat)); diff --git a/example/ioctl.c b/example/ioctl.c index ee58f03..0a4c14d 100644 --- a/example/ioctl.c +++ b/example/ioctl.c @@ -83,8 +83,10 @@ static int fioc_file_type(const char *path) return FIOC_NONE; } -static int fioc_getattr(const char *path, struct stat *stbuf) +static int fioc_getattr(const char *path, struct stat *stbuf, + struct fuse_file_info *fi) { + (void) fi; stbuf->st_uid = getuid(); stbuf->st_gid = getgid(); stbuf->st_atime = stbuf->st_mtime = time(NULL); @@ -160,8 +162,10 @@ static int fioc_write(const char *path, const char *buf, size_t size, return fioc_do_write(buf, size, offset); } -static int fioc_truncate(const char *path, off_t size) +static int fioc_truncate(const char *path, off_t size, + struct fuse_file_info *fi) { + (void) fi; if (fioc_file_type(path) != FIOC_FILE) return -EINVAL; diff --git a/example/passthrough.c b/example/passthrough.c index cf72cb2..d3d0fde 100644 --- a/example/passthrough.c +++ b/example/passthrough.c @@ -48,8 +48,10 @@ #include <sys/xattr.h> #endif -static int xmp_getattr(const char *path, struct stat *stbuf) +static int xmp_getattr(const char *path, struct stat *stbuf, + struct fuse_file_info *fi) { + (void) fi; int res; res = lstat(path, stbuf); @@ -200,8 +202,10 @@ static int xmp_link(const char *from, const char *to) return 0; } -static int xmp_chmod(const char *path, mode_t mode) +static int xmp_chmod(const char *path, mode_t mode, + struct fuse_file_info *fi) { + (void) fi; int res; res = chmod(path, mode); @@ -211,8 +215,10 @@ static int xmp_chmod(const char *path, mode_t mode) return 0; } -static int xmp_chown(const char *path, uid_t uid, gid_t gid) +static int xmp_chown(const char *path, uid_t uid, gid_t gid, + struct fuse_file_info *fi) { + (void) fi; int res; res = lchown(path, uid, gid); @@ -222,8 +228,10 @@ static int xmp_chown(const char *path, uid_t uid, gid_t gid) return 0; } -static int xmp_truncate(const char *path, off_t size) +static int xmp_truncate(const char *path, off_t size, + struct fuse_file_info *fi) { + (void) fi; int res; res = truncate(path, size); @@ -234,8 +242,10 @@ static int xmp_truncate(const char *path, off_t size) } #ifdef HAVE_UTIMENSAT -static int xmp_utimens(const char *path, const struct timespec ts[2]) +static int xmp_utimens(const char *path, const struct timespec ts[2], + struct fuse_file_info *fi) { + (void) fi; int res; /* don't use utime/utimes since they follow symlinks */ diff --git a/example/passthrough_fh.c b/example/passthrough_fh.c index a179f65..35d909f 100644 --- a/example/passthrough_fh.c +++ b/example/passthrough_fh.c @@ -52,25 +52,17 @@ #endif #include <sys/file.h> /* flock(2) */ -static int xmp_getattr(const char *path, struct stat *stbuf) -{ - int res; - - res = lstat(path, stbuf); - if (res == -1) - return -errno; - - return 0; -} - -static int xmp_fgetattr(const char *path, struct stat *stbuf, +static int xmp_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi) { int res; (void) path; - res = fstat(fi->fh, stbuf); + if(fi) + res = fstat(fi->fh, stbuf); + else + res = lstat(path, stbuf); if (res == -1) return -errno; @@ -272,47 +264,46 @@ static int xmp_link(const char *from, const char *to) return 0; } -static int xmp_chmod(const char *path, mode_t mode) -{ - int res; - - res = chmod(path, mode); - if (res == -1) - return -errno; - - return 0; -} - -static int xmp_chown(const char *path, uid_t uid, gid_t gid) +static int xmp_chmod(const char *path, mode_t mode, + struct fuse_file_info *fi) { int res; - res = lchown(path, uid, gid); + if(fi) + res = fchmod(fi->fh, mode); + else + res = chmod(path, mode); if (res == -1) return -errno; return 0; } -static int xmp_truncate(const char *path, off_t size) +static int xmp_chown(const char *path, uid_t uid, gid_t gid, + struct fuse_file_info *fi) { int res; - res = truncate(path, size); + if (fi) + res = fchown(fi->fh, uid, gid); + else + res = lchown(path, uid, gid); if (res == -1) return -errno; return 0; } -static int xmp_ftruncate(const char *path, off_t size, +static int xmp_truncate(const char *path, off_t size, struct fuse_file_info *fi) { int res; - (void) path; + if(fi) + res = ftruncate(fi->fh, size); + else + res = truncate(path, size); - res = ftruncate(fi->fh, size); if (res == -1) return -errno; @@ -320,12 +311,16 @@ static int xmp_ftruncate(const char *path, off_t size, } #ifdef HAVE_UTIMENSAT -static int xmp_utimens(const char *path, const struct timespec ts[2]) +static int xmp_utimens(const char *path, const struct timespec ts[2], + struct fuse_file_info *fi) { int res; /* don't use utime/utimes since they follow symlinks */ - res = utimensat(0, path, ts, AT_SYMLINK_NOFOLLOW); + if (fi) + res = futimens(fi->fh, ts); + else + res = utimensat(0, path, ts, AT_SYMLINK_NOFOLLOW); if (res == -1) return -errno; @@ -550,7 +545,6 @@ static int xmp_flock(const char *path, struct fuse_file_info *fi, int op) static struct fuse_operations xmp_oper = { .getattr = xmp_getattr, - .fgetattr = xmp_fgetattr, .access = xmp_access, .readlink = xmp_readlink, .opendir = xmp_opendir, @@ -566,7 +560,6 @@ static struct fuse_operations xmp_oper = { .chmod = xmp_chmod, .chown = xmp_chown, .truncate = xmp_truncate, - .ftruncate = xmp_ftruncate, #ifdef HAVE_UTIMENSAT .utimens = xmp_utimens, #endif diff --git a/example/poll.c b/example/poll.c index 61c5365..10175a3 100644 --- a/example/poll.c +++ b/example/poll.c @@ -64,8 +64,10 @@ static int fsel_path_index(const char *path) return ch <= '9' ? ch - '0' : ch - 'A' + 10; } -static int fsel_getattr(const char *path, struct stat *stbuf) +static int fsel_getattr(const char *path, struct stat *stbuf, + struct fuse_file_info *fi) { + (void) fi; int idx; memset(stbuf, 0, sizeof(struct stat)); |