X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fbtrfs-util.c;h=6761501da2589166a108be55d0ff9ae39386b4d0;hb=d6ce17c7f02ed3facdb45f65f546e587c2f00950;hp=254483c31a3ce5649fc0d722456c448a5461d450;hpb=1c7dd82563ff2e71a067aea20d2acb2d0553644b;p=elogind.git diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index 254483c31..6761501da 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -31,7 +31,6 @@ #include "util.h" #include "path-util.h" #include "macro.h" -#include "strv.h" #include "copy.h" #include "selinux-util.h" #include "smack-util.h" @@ -228,14 +227,18 @@ int btrfs_subvol_remove(const char *path) { return 0; } -int btrfs_subvol_set_read_only(const char *path, bool b) { - _cleanup_close_ int fd = -1; +int btrfs_subvol_set_read_only_fd(int fd, bool b) { uint64_t flags, nflags; + struct stat st; - fd = open(path, O_RDONLY|O_NOCTTY|O_CLOEXEC); - if (fd < 0) + assert(fd >= 0); + + if (fstat(fd, &st) < 0) return -errno; + if (!S_ISDIR(st.st_mode) || st.st_ino != 256) + return -EINVAL; + if (ioctl(fd, BTRFS_IOC_SUBVOL_GETFLAGS, &flags) < 0) return -errno; @@ -253,6 +256,16 @@ int btrfs_subvol_set_read_only(const char *path, bool b) { return 0; } +int btrfs_subvol_set_read_only(const char *path, bool b) { + _cleanup_close_ int fd = -1; + + fd = open(path, O_RDONLY|O_NOCTTY|O_CLOEXEC|O_DIRECTORY); + if (fd < 0) + return -errno; + + return btrfs_subvol_set_read_only_fd(fd, b); +} + int btrfs_subvol_get_read_only_fd(int fd) { uint64_t flags; @@ -633,3 +646,52 @@ int btrfs_defrag(const char *p) { return btrfs_defrag_fd(fd); } + +int btrfs_quota_enable_fd(int fd, bool b) { + struct btrfs_ioctl_quota_ctl_args args = { + .cmd = b ? BTRFS_QUOTA_CTL_ENABLE : BTRFS_QUOTA_CTL_DISABLE, + }; + + assert(fd >= 0); + + if (ioctl(fd, BTRFS_IOC_QUOTA_CTL, &args) < 0) + return -errno; + + return 0; +} + +int btrfs_quota_enable(const char *path, bool b) { + _cleanup_close_ int fd = -1; + + fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); + if (fd < 0) + return -errno; + + return btrfs_quota_enable_fd(fd, b); +} + +int btrfs_quota_limit_fd(int fd, uint64_t referred_max) { + struct btrfs_ioctl_qgroup_limit_args args = { + .lim.max_rfer = + referred_max == (uint64_t) -1 ? 0 : + referred_max == 0 ? 1 : referred_max, + .lim.flags = BTRFS_QGROUP_LIMIT_MAX_RFER, + }; + + assert(fd >= 0); + + if (ioctl(fd, BTRFS_IOC_QGROUP_LIMIT, &args) < 0) + return -errno; + + return 0; +} + +int btrfs_quota_limit(const char *path, uint64_t referred_max) { + _cleanup_close_ int fd = -1; + + fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); + if (fd < 0) + return -errno; + + return btrfs_quota_limit_fd(fd, referred_max); +}