From: Lennart Poettering Date: Mon, 12 Feb 2024 11:55:47 +0000 (+0100) Subject: btrfs-util: rework btrfs_is_nocow_fd() around fd_is_fs_type() + read_attr_fd() X-Git-Tag: v256-rc1~891^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05f38c897fa9ac32d627395e4c7a7c7d7e5a1b23;p=thirdparty%2Fsystemd.git btrfs-util: rework btrfs_is_nocow_fd() around fd_is_fs_type() + read_attr_fd() Let's our safer helpers where appropriate. --- diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index aa4eb5a8d8d..57e11dc1a81 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -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); }