From 09862556887caf32b37aa0caa412c467f7f5a40e Mon Sep 17 00:00:00 2001 From: Nikolaus Rath Date: Fri, 7 Apr 2017 16:31:07 -0700 Subject: [PATCH] example/passthrough: use fi->fh for read, write, fallocate No reason not to use it. May even be a little faster and will consume less resources :-). --- example/passthrough.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/example/passthrough.c b/example/passthrough.c index 67663ab..d5edc04 100644 --- a/example/passthrough.c +++ b/example/passthrough.c @@ -296,8 +296,11 @@ static int xmp_read(const char *path, char *buf, size_t size, off_t offset, int fd; int res; - (void) fi; - fd = open(path, O_RDONLY); + if(fi == NULL) + fd = open(path, O_RDONLY); + else + fd = fi->fh; + if (fd == -1) return -errno; @@ -305,7 +308,8 @@ static int xmp_read(const char *path, char *buf, size_t size, off_t offset, if (res == -1) res = -errno; - close(fd); + if(fi == NULL) + close(fd); return res; } @@ -316,7 +320,11 @@ static int xmp_write(const char *path, const char *buf, size_t size, int res; (void) fi; - fd = open(path, O_WRONLY); + if(fi == NULL) + fd = open(path, O_WRONLY); + else + fd = fi->fh; + if (fd == -1) return -errno; @@ -324,7 +332,8 @@ static int xmp_write(const char *path, const char *buf, size_t size, if (res == -1) res = -errno; - close(fd); + if(fi == NULL) + close(fd); return res; } @@ -370,13 +379,18 @@ static int xmp_fallocate(const char *path, int mode, if (mode) return -EOPNOTSUPP; - fd = open(path, O_WRONLY); + if(fi == NULL) + fd = open(path, O_WRONLY); + else + fd = fi->fh; + if (fd == -1) return -errno; res = -posix_fallocate(fd, offset, length); - close(fd); + if(fi == NULL) + close(fd); return res; } #endif -- 2.30.2