-static int
-unix_scan_symlink(struct wim_dentry **root_p, const char *full_path,
- int dirfd, const char *relpath,
- struct wim_inode *inode, struct add_image_params *params)
+/*
+ * Given an absolute symbolic link target (UNIX-style, beginning with '/'),
+ * determine whether it points into the directory identified by @ino and @dev.
+ * If yes, return the suffix of @target which is relative to this directory, but
+ * retaining leading slashes. If no, return @target.
+ *
+ * Here are some examples, assuming that the @ino/@dev directory is "/home/e":
+ *
+ * Original target New target
+ * --------------- ----------
+ * /home/e/test /test
+ * /home/e/test/ /test/
+ * //home//e//test// //test//
+ * /home/e (empty string)
+ * /home/e/ /
+ * /usr/lib /usr/lib (external link)
+ *
+ * Because of the possibility of other links into the @ino/@dev directory and/or
+ * multiple path separators, we can't simply do a string comparison; instead we
+ * need to stat() each ancestor directory.
+ *
+ * If the link points directly to the @ino/@dev directory with no trailing
+ * slashes, then the new target will be an empty string. This is not a valid
+ * UNIX symlink target, but we store this in the archive anyway since the target
+ * is intended to be de-relativized when the link is extracted.
+ */
+static char *
+unix_relativize_link_target(char *target, u64 ino, u64 dev)