]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
btrfs-util: rework btrfs_is_nocow_fd() around fd_is_fs_type() + read_attr_fd()
authorLennart Poettering <lennart@poettering.net>
Mon, 12 Feb 2024 11:55:47 +0000 (12:55 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 12 Feb 2024 14:35:03 +0000 (15:35 +0100)
Let's our safer helpers where appropriate.

src/shared/btrfs-util.c

index aa4eb5a8d8dcb592cbb6931a67107c92eb241c2b..57e11dc1a810d8c4f16413f99444d299b55ae1e0 100644 (file)
@@ -2030,19 +2030,20 @@ static BtrfsChunk* btrfs_find_chunk_from_logical_address(const BtrfsChunkTree *t
 }
 
 static int btrfs_is_nocow_fd(int fd) {
-        struct statfs sfs;
         unsigned flags;
+        int r;
 
         assert(fd >= 0);
 
-        if (fstatfs(fd, &sfs) < 0)
-                return -errno;
-
-        if (!is_fs_type(&sfs, BTRFS_SUPER_MAGIC))
+        r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
+        if (r < 0)
+                return r;
+        if (r == 0)
                 return -ENOTTY;
 
-        if (ioctl(fd, FS_IOC_GETFLAGS, &flags) < 0)
-                return -errno;
+        r = read_attr_fd(fd, &flags);
+        if (r < 0)
+                return r;
 
         return FLAGS_SET(flags, FS_NOCOW_FL) && !FLAGS_SET(flags, FS_COMPR_FL);
 }