summaryrefslogtreecommitdiff
path: root/src/shared/btrfs-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-19 18:42:50 +0100
committerLennart Poettering <lennart@poettering.net>2014-12-19 19:19:29 +0100
commitcd61c3bfd718fb398cc53ced906266a9297782c9 (patch)
treed727549baccec28d473212b85c55f2e24af25678 /src/shared/btrfs-util.c
parent8eebf6ad553adb22d7ea5d291de0b0da38606f4d (diff)
machined/machinectl: add logic to show list of available images
This adds a new bus call to machined that enumerates /var/lib/container and returns all trees stored in it, distuingishing three types: - GPT disk images, which are files suffixed with ".gpt" - directory trees - btrfs subvolumes
Diffstat (limited to 'src/shared/btrfs-util.c')
-rw-r--r--src/shared/btrfs-util.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c
index 492d7fc777..d685b3ecbd 100644
--- a/src/shared/btrfs-util.c
+++ b/src/shared/btrfs-util.c
@@ -84,18 +84,18 @@ int btrfs_is_snapshot(int fd) {
struct stat st;
struct statfs sfs;
- if (fstatfs(fd, &sfs) < 0)
+ /* On btrfs subvolumes always have the inode 256 */
+
+ if (fstat(fd, &st) < 0)
return -errno;
- if (!F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC))
+ if (!S_ISDIR(st.st_mode) || st.st_ino != 256)
return 0;
- if (fstat(fd, &st) < 0)
+ if (fstatfs(fd, &sfs) < 0)
return -errno;
- /* On btrfs subvolumes always have the inode 256 */
-
- return S_ISDIR(st.st_mode) && st.st_ino == 256;
+ return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC);
}
int btrfs_subvol_snapshot(const char *old_path, const char *new_path, bool read_only, bool fallback_copy) {
@@ -232,6 +232,15 @@ int btrfs_subvol_read_only(const char *path, bool b) {
return 0;
}
+int btrfs_subvol_is_read_only_fd(int fd) {
+ uint64_t flags;
+
+ if (ioctl(fd, BTRFS_IOC_SUBVOL_GETFLAGS, &flags) < 0)
+ return -errno;
+
+ return !!(flags & BTRFS_SUBVOL_RDONLY);
+}
+
int btrfs_reflink(int infd, int outfd) {
int r;