- if (!ni) {
- ni = ntfs_pathname_to_inode(dir_ni->vol, NULL,
- dentry->full_path_utf8);
+ if (is_hardlink) {
+ char *p;
+ char orig;
+ const char *dir_name;
+
+ /* ntfs_set_ntfs_dos_name() closes the inodes in the
+ * wrong order if we have applied a hard link. Close
+ * them ourselves, then re-open then. */
+ if (ntfs_inode_close(dir_ni) != 0) {
+ if (ret == 0)
+ ret = WIMLIB_ERR_NTFS_3G;
+ ERROR_WITH_ERRNO("Failed to close directory inode");
+ }
+ if (ntfs_inode_close(ni) != 0) {
+ if (ret == 0)
+ ret = WIMLIB_ERR_NTFS_3G;
+ ERROR_WITH_ERRNO("Failed to close hard link target inode");
+ }
+ p = dentry->full_path_utf8 + dentry->full_path_utf8_len;
+ do {
+ p--;
+ } while (*p != '/');
+
+ orig = *p;
+ *p = '\0';
+ dir_name = dentry->full_path_utf8;
+
+ dir_ni = ntfs_pathname_to_inode(vol, NULL, dir_name);
+ *p = orig;
+ if (!dir_ni) {
+ ERROR_WITH_ERRNO("Could not find NTFS inode for `%s'",
+ dir_name);
+ return WIMLIB_ERR_NTFS_3G;
+ }
+ ni = ntfs_pathname_to_inode(vol, dir_ni,
+ dentry->file_name_utf8);