summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@googlemail.com>2015-11-16 15:48:21 +0100
committerDavid Herrmann <dh.herrmann@googlemail.com>2015-11-16 15:48:21 +0100
commit920a7262211254a6f728af5ed4f6cd7f9a83e9a6 (patch)
tree28e800c3c807976014bb91bccecc23c70571acc2 /src/basic
parent44690833dfadb523c1f9b6a9e6e1dced44f374e1 (diff)
parent2904e949f23aeb17b7e21a2a0f8c43f959a07f98 (diff)
Merge pull request #1915 from poettering/btrfs-root-subvol
tmpfiles: create subvolumes for "v", "q", and "Q" only if / is a subv…
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/btrfs-util.c18
-rw-r--r--src/basic/btrfs-util.h4
2 files changed, 18 insertions, 4 deletions
diff --git a/src/basic/btrfs-util.c b/src/basic/btrfs-util.c
index 8c2d76b8aa..be40dc5702 100644
--- a/src/basic/btrfs-util.c
+++ b/src/basic/btrfs-util.c
@@ -105,7 +105,7 @@ int btrfs_is_filesystem(int fd) {
return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC);
}
-int btrfs_is_subvol(int fd) {
+int btrfs_is_subvol_fd(int fd) {
struct stat st;
assert(fd >= 0);
@@ -121,6 +121,18 @@ int btrfs_is_subvol(int fd) {
return btrfs_is_filesystem(fd);
}
+int btrfs_is_subvol(const char *path) {
+ _cleanup_close_ int fd = -1;
+
+ assert(path);
+
+ fd = open(path, O_RDONLY|O_NOCTTY|O_CLOEXEC|O_DIRECTORY);
+ if (fd < 0)
+ return -errno;
+
+ return btrfs_is_subvol_fd(fd);
+}
+
int btrfs_subvol_make(const char *path) {
struct btrfs_ioctl_vol_args args = {};
_cleanup_close_ int fd = -1;
@@ -1686,7 +1698,7 @@ int btrfs_subvol_snapshot_fd(int old_fd, const char *new_path, BtrfsSnapshotFlag
assert(old_fd >= 0);
assert(new_path);
- r = btrfs_is_subvol(old_fd);
+ r = btrfs_is_subvol_fd(old_fd);
if (r < 0)
return r;
if (r == 0) {
@@ -1872,7 +1884,7 @@ int btrfs_subvol_auto_qgroup_fd(int fd, uint64_t subvol_id, bool insert_intermed
*/
if (subvol_id == 0) {
- r = btrfs_is_subvol(fd);
+ r = btrfs_is_subvol_fd(fd);
if (r < 0)
return r;
if (!r)
diff --git a/src/basic/btrfs-util.h b/src/basic/btrfs-util.h
index fc9efd72d5..8c11ce35d2 100644
--- a/src/basic/btrfs-util.h
+++ b/src/basic/btrfs-util.h
@@ -56,7 +56,9 @@ typedef enum BtrfsRemoveFlags {
} BtrfsRemoveFlags;
int btrfs_is_filesystem(int fd);
-int btrfs_is_subvol(int fd);
+
+int btrfs_is_subvol_fd(int fd);
+int btrfs_is_subvol(const char *path);
int btrfs_reflink(int infd, int outfd);
int btrfs_clone_range(int infd, uint64_t in_offset, int ofd, uint64_t out_offset, uint64_t sz);