diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/btrfs-util.c | 22 | ||||
-rw-r--r-- | src/shared/btrfs-util.h | 1 |
2 files changed, 19 insertions, 4 deletions
diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index 254483c31a..b34ac8b15a 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -228,14 +228,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 +257,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; diff --git a/src/shared/btrfs-util.h b/src/shared/btrfs-util.h index 28946c60c9..d5249d1bf1 100644 --- a/src/shared/btrfs-util.h +++ b/src/shared/btrfs-util.h @@ -48,6 +48,7 @@ int btrfs_subvol_make_label(const char *path); int btrfs_subvol_remove(const char *path); int btrfs_subvol_snapshot(const char *old_path, const char *new_path, bool read_only, bool fallback_copy); +int btrfs_subvol_set_read_only_fd(int fd, bool b); int btrfs_subvol_set_read_only(const char *path, bool b); int btrfs_subvol_get_read_only_fd(int fd); int btrfs_subvol_get_id_fd(int fd, uint64_t *ret); |