From 96ac0e5d76db3714b7c8d37956f6e6b1d804a01a Mon Sep 17 00:00:00 2001 From: Anatol Pomozov Date: Sun, 22 Apr 2012 18:49:35 -0700 Subject: Add FALLOCATE operation fallocate filesystem operation preallocates media space for the given file. If fallocate returns success then any subsequent write to the given range never fails with 'not enough space' error. --- example/fusexmp.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'example/fusexmp.c') diff --git a/example/fusexmp.c b/example/fusexmp.c index 20a7116..dca8a46 100644 --- a/example/fusexmp.c +++ b/example/fusexmp.c @@ -310,6 +310,29 @@ static int xmp_fsync(const char *path, int isdatasync, return 0; } +#ifdef HAVE_POSIX_FALLOCATE +static int xmp_fallocate(const char *path, int mode, + off_t offset, off_t length, struct fuse_file_info *fi) +{ + int fd; + int res; + + (void) fi; + + if (mode) + return -EOPNOTSUPP; + + fd = open(path, O_WRONLY); + if (fd == -1) + return -errno; + + res = -posix_fallocate(fd, offset, length); + + close(fd); + return res; +} +#endif + #ifdef HAVE_SETXATTR /* xattr operations are optional and can safely be left unimplemented */ static int xmp_setxattr(const char *path, const char *name, const char *value, @@ -371,6 +394,9 @@ static struct fuse_operations xmp_oper = { .statfs = xmp_statfs, .release = xmp_release, .fsync = xmp_fsync, +#ifdef HAVE_POSIX_FALLOCATE + .fallocate = xmp_fallocate, +#endif #ifdef HAVE_SETXATTR .setxattr = xmp_setxattr, .getxattr = xmp_getxattr, -- cgit v1.2.3