diff options
author | Anatol Pomozov <anatol.pomozov@gmail.com> | 2012-04-22 18:49:35 -0700 |
---|---|---|
committer | Miklos Szeredi <mszeredi@suse.cz> | 2012-06-18 13:32:43 +0200 |
commit | 96ac0e5d76db3714b7c8d37956f6e6b1d804a01a (patch) | |
tree | 4cd918bccb54e30edca0dadbe2b44a43b7ef1c91 /example | |
parent | 46b9c3326d50aebe52c33d63885b83a47a2e74ea (diff) | |
download | android_external_fuse-96ac0e5d76db3714b7c8d37956f6e6b1d804a01a.tar.gz android_external_fuse-96ac0e5d76db3714b7c8d37956f6e6b1d804a01a.tar.bz2 android_external_fuse-96ac0e5d76db3714b7c8d37956f6e6b1d804a01a.zip |
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.
Diffstat (limited to 'example')
-rw-r--r-- | example/fusexmp.c | 26 | ||||
-rw-r--r-- | example/fusexmp_fh.c | 16 |
2 files changed, 42 insertions, 0 deletions
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, diff --git a/example/fusexmp_fh.c b/example/fusexmp_fh.c index d79ff37..1ba9dbc 100644 --- a/example/fusexmp_fh.c +++ b/example/fusexmp_fh.c @@ -439,6 +439,19 @@ 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) +{ + (void) path; + + if (mode) + return -EOPNOTSUPP; + + return -posix_fallocate(fi->fh, offset, length); +} +#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, @@ -529,6 +542,9 @@ static struct fuse_operations xmp_oper = { .flush = xmp_flush, .release = xmp_release, .fsync = xmp_fsync, +#ifdef HAVE_POSIX_FALLOCATE + .fallocate = xmp_fallocate, +#endif #ifdef HAVE_SETXATTR .setxattr = xmp_setxattr, .getxattr = xmp_getxattr, |