diff options
Diffstat (limited to 'src/shared/btrfs-util.c')
-rw-r--r-- | src/shared/btrfs-util.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index 164ac9f337..e648121b47 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -531,3 +531,22 @@ finish: return 0; } + +int btrfs_defrag_fd(int fd) { + assert(fd >= 0); + + if (ioctl(fd, BTRFS_IOC_DEFRAG, NULL) < 0) + return -errno; + + return 0; +} + +int btrfs_defrag(const char *p) { + _cleanup_close_ int fd = -1; + + fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); + if (fd < 0) + return -errno; + + return btrfs_defrag_fd(fd); +} |