mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
btrfs-util: Add btrfs_subvol_set_read_only_at()
This commit is contained in:
parent
5124aa8c03
commit
77c66be37b
@ -152,11 +152,16 @@ int btrfs_subvol_make_fallback(const char *path, mode_t mode) {
|
||||
return 0; /* plain directory */
|
||||
}
|
||||
|
||||
int btrfs_subvol_set_read_only_fd(int fd, bool b) {
|
||||
int btrfs_subvol_set_read_only_at(int dir_fd, const char *path, bool b) {
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
uint64_t flags, nflags;
|
||||
struct stat st;
|
||||
|
||||
assert(fd >= 0);
|
||||
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
|
||||
|
||||
fd = xopenat(dir_fd, path, O_RDONLY|O_NOCTTY|O_CLOEXEC|O_DIRECTORY, /* xopen_flags = */ 0, /* mode = */ 0);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
if (fstat(fd, &st) < 0)
|
||||
return -errno;
|
||||
@ -174,16 +179,6 @@ int btrfs_subvol_set_read_only_fd(int fd, bool b) {
|
||||
return RET_NERRNO(ioctl(fd, BTRFS_IOC_SUBVOL_SETFLAGS, &nflags));
|
||||
}
|
||||
|
||||
int btrfs_subvol_set_read_only(const char *path, bool b) {
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
|
||||
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;
|
||||
struct stat st;
|
||||
|
@ -89,8 +89,14 @@ static inline int btrfs_subvol_remove(const char *path, BtrfsRemoveFlags flags)
|
||||
return btrfs_subvol_remove_at(AT_FDCWD, path, flags);
|
||||
}
|
||||
|
||||
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_set_read_only_at(int dir_fd, const char *path, bool b);
|
||||
static inline int btrfs_subvol_set_read_only_fd(int fd, bool b) {
|
||||
return btrfs_subvol_set_read_only_at(fd, NULL, b);
|
||||
}
|
||||
static inline int btrfs_subvol_set_read_only(const char *path, bool b) {
|
||||
return btrfs_subvol_set_read_only_at(AT_FDCWD, path, b);
|
||||
}
|
||||
|
||||
int btrfs_subvol_get_read_only_fd(int fd);
|
||||
|
||||
int btrfs_subvol_get_id(int fd, const char *subvolume, uint64_t *ret);
|
||||
|
Loading…
Reference in New Issue
Block a user