- /* Create a WIM dentry with an associated inode, which may be shared */
- ret = inode_table_new_dentry(params->inode_table,
- path_basename_with_len(path, path_num_chars),
- ((u64)file_info.nFileIndexHigh << 32) |
- (u64)file_info.nFileIndexLow,
- file_info.dwVolumeSerialNumber,
- &root);
- if (ret)
- goto out_close_handle;
+ /* Create a WIM dentry with an associated inode, which may be shared.
+ *
+ * However, we need to explicitly check for directories and files with
+ * only 1 link and refuse to hard link them. This is because Windows
+ * has a bug where it can return duplicate File IDs for files and
+ * directories on the FAT filesystem. */
+ basename = path_basename_with_len(path, path_num_chars);
+ if (!(file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ && file_info.nNumberOfLinks > 1)
+ {
+ ret = inode_table_new_dentry(params->inode_table,
+ basename,
+ ((u64)file_info.nFileIndexHigh << 32) |
+ (u64)file_info.nFileIndexLow,
+ file_info.dwVolumeSerialNumber,
+ &root);
+ if (ret)
+ goto out_close_handle;
+ } else {
+ ret = new_dentry_with_inode(basename, &root);
+ if (ret)
+ goto out_close_handle;
+ list_add_tail(&root->d_inode->i_list, ¶ms->inode_table->extra_inodes);
+ }
+