From b78f52f24baf4b73ea16162a466dc06c0ad6d817 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Mon, 9 Jul 2018 20:42:14 +0200 Subject: [PATCH] fuse-overlayfs: on link(2) set the redirect link from the source Signed-off-by: Giuseppe Scrivano --- main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 4ec664f..c2a27e7 100644 --- a/main.c +++ b/main.c @@ -2105,7 +2105,21 @@ ovl_link (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, const char *newn int dfd = TEMP_FAILURE_RETRY (openat (node_dirfd (newparentnode), path, O_WRONLY)); if (dfd >= 0) { - fsetxattr (dfd, REDIRECT_XATTR, node->path, strlen (node->path), 0); + bool set = false; + int sfd = TEMP_FAILURE_RETRY (openat (node_dirfd (node), node->path, O_RDONLY)); + if (sfd >= 0) + { + char redirect_path[PATH_MAX + 10]; + ssize_t s = fgetxattr (sfd, REDIRECT_XATTR, redirect_path, sizeof (redirect_path)); + if (s > 0) + { + set = fsetxattr (dfd, REDIRECT_XATTR, redirect_path, s, 0) == 0; + } + close (sfd); + } + + if (! set) + fsetxattr (dfd, REDIRECT_XATTR, node->path, strlen (node->path), 0); close (dfd); } }