summaryrefslogtreecommitdiff
path: root/src/shared/btrfs-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-22 13:08:19 +0200
committerLennart Poettering <lennart@poettering.net>2015-04-22 13:27:53 +0200
commit21222ea5cdec65fa30a75bd5a78475459075b946 (patch)
treebd043503be06aa6a0c10ed097eece733a4466f47 /src/shared/btrfs-util.c
parent03091baac3c37094af6a30be31e4962dd26f8404 (diff)
btrfs-util: introduce btrfs_is_filesystem() and make use of it where appropriate
Let's unify the code that checks whether an fd is on btrfs a bit. (Also, rename btrfs_is_snapshot() to btrfs_is_subvol(), since that's usually how this is referred to in our code)
Diffstat (limited to 'src/shared/btrfs-util.c')
-rw-r--r--src/shared/btrfs-util.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c
index 5bf87a389e..5a1ed60558 100644
--- a/src/shared/btrfs-util.c
+++ b/src/shared/btrfs-util.c
@@ -83,10 +83,22 @@ static int extract_subvolume_name(const char *path, const char **subvolume) {
return 0;
}
-int btrfs_is_snapshot(int fd) {
- struct stat st;
+int btrfs_is_filesystem(int fd) {
struct statfs sfs;
+ assert(fd >= 0);
+
+ if (fstatfs(fd, &sfs) < 0)
+ return -errno;
+
+ return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC);
+}
+
+int btrfs_is_subvol(int fd) {
+ struct stat st;
+
+ assert(fd >= 0);
+
/* On btrfs subvolumes always have the inode 256 */
if (fstat(fd, &st) < 0)
@@ -95,10 +107,7 @@ int btrfs_is_snapshot(int fd) {
if (!S_ISDIR(st.st_mode) || st.st_ino != 256)
return 0;
- if (fstatfs(fd, &sfs) < 0)
- return -errno;
-
- return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC);
+ return btrfs_is_filesystem(fd);
}
int btrfs_subvol_make(const char *path) {
@@ -970,7 +979,7 @@ int btrfs_subvol_snapshot_fd(int old_fd, const char *new_path, BtrfsSnapshotFlag
assert(old_fd >= 0);
assert(new_path);
- r = btrfs_is_snapshot(old_fd);
+ r = btrfs_is_subvol(old_fd);
if (r < 0)
return r;
if (r == 0) {