From: Nikolaus Rath Date: Fri, 7 Apr 2017 23:27:59 +0000 (-0700) Subject: passthrough:truncate(): work on file descriptor when possible X-Git-Tag: fuse-3.0.1~9 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=76218eb4614146b52f59563e85e6b5971acbfe92;p=qemu-gpiodev%2Flibfuse.git passthrough:truncate(): work on file descriptor when possible This allows truncating an open file even if write permission was removed after open() (which is the expected behavior). --- diff --git a/example/passthrough.c b/example/passthrough.c index 55f7704..67663ab 100644 --- a/example/passthrough.c +++ b/example/passthrough.c @@ -250,10 +250,12 @@ static int xmp_chown(const char *path, uid_t uid, gid_t gid, static int xmp_truncate(const char *path, off_t size, struct fuse_file_info *fi) { - (void) fi; int res; - res = truncate(path, size); + if (fi != NULL) + res = ftruncate(fi->fh, size); + else + res = truncate(path, size); if (res == -1) return -errno;