From 4b09ba4b78846054b232af1180111132230e7f2d Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 26 Jul 2019 13:25:53 +0200 Subject: [PATCH] btrfs-progs: restore: fix chown of a symlink User reports: "When I execute btrfs restore -S to restore a symlink, it prints: SYMLINK: 'dest/path/of/symlink' => 'symlink/target' Failed to change owner: Bad file descriptor And at cmds-restore.c#L937: ret = fchownat(-1, file, btrfs_inode_uid(path.nodes[0], inode_item), btrfs_inode_gid(path.nodes[0], inode_item), AT_SYMLINK_NOFOLLOW); " The -1 is indeed a bad descriptor, and should be probably AT_FDCWD as this is documented. The path passed as 'file' is always absolute, so the semantics are unaffected. Issue: #183 Signed-off-by: David Sterba --- cmds/restore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds/restore.c b/cmds/restore.c index 4b4f943c..c104b01a 100644 --- a/cmds/restore.c +++ b/cmds/restore.c @@ -934,7 +934,7 @@ static int copy_symlink(struct btrfs_root *root, struct btrfs_key *key, inode_item = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_inode_item); - ret = fchownat(-1, file, btrfs_inode_uid(path.nodes[0], inode_item), + ret = fchownat(AT_FDCWD, file, btrfs_inode_uid(path.nodes[0], inode_item), btrfs_inode_gid(path.nodes[0], inode_item), AT_SYMLINK_NOFOLLOW); if (ret) { @@ -950,7 +950,7 @@ static int copy_symlink(struct btrfs_root *root, struct btrfs_key *key, times[1].tv_sec = btrfs_timespec_sec(path.nodes[0], bts); times[1].tv_nsec = btrfs_timespec_nsec(path.nodes[0], bts); - ret = utimensat(-1, file, times, AT_SYMLINK_NOFOLLOW); + ret = utimensat(AT_FDCWD, file, times, AT_SYMLINK_NOFOLLOW); if (ret) fprintf(stderr, "Failed to set times: %m\n"); out: