]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
btrfs-util: make sure btrfs_subvol_get_info_fd() works on O_PATH fds
authorLennart Poettering <lennart@poettering.net>
Mon, 9 Dec 2024 12:51:28 +0000 (13:51 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 17 Dec 2024 10:21:57 +0000 (11:21 +0100)
src/shared/btrfs-util.c

index e9a96cb3a211df27482e031526d29e19c92b7d26..9ae22d8aa561d2788cccfa5097af88565027cb95 100644 (file)
@@ -329,6 +329,12 @@ int btrfs_subvol_get_info_fd(int fd, uint64_t subvol_id, BtrfsSubvolInfo *ret) {
         assert(fd >= 0);
         assert(ret);
 
+        /* Make sure this works on O_PATH fds */
+        _cleanup_close_ int fd_close = -EBADF;
+        fd = fd_reopen_condition(fd, O_CLOEXEC|O_RDONLY|O_DIRECTORY, O_PATH, &fd_close);
+        if (fd < 0)
+                return fd;
+
         if (subvol_id == 0) {
                 r = btrfs_subvol_get_id_fd(fd, &subvol_id);
                 if (r < 0)