+ progress_info->extract.completed_bytes += wim_resource_size(lte);
+ return 0;
+}
+
+static int do_apply_dentry_ntfs(struct wim_dentry *dentry, ntfs_inode *dir_ni,
+ struct apply_args *args);
+
+/*
+ * If @dentry is part of a hard link group, search for hard-linked dentries in
+ * the same directory that have a nonempty DOS (short) filename. There should
+ * be exactly 0 or 1 such dentries. If there is 1, extract that dentry first,
+ * so that the DOS name is correctly associated with the corresponding long name
+ * in the Win32 namespace, and not any of the additional names in the POSIX
+ * namespace created from hard links.
+ */
+static int preapply_dentry_with_dos_name(struct wim_dentry *dentry,
+ ntfs_inode **dir_ni_p,
+ struct apply_args *args)
+{
+ struct wim_dentry *other;
+ struct wim_dentry *dentry_with_dos_name;
+
+ dentry_with_dos_name = NULL;
+ inode_for_each_dentry(other, dentry->d_inode) {
+ if (other != dentry && (dentry->parent == other->parent)
+ && other->short_name_len)
+ {
+ if (dentry_with_dos_name) {
+ ERROR("Found multiple DOS names for file `%s' "
+ "in the same directory",
+ dentry_with_dos_name->full_path_utf8);
+ return WIMLIB_ERR_INVALID_DENTRY;
+ }
+ dentry_with_dos_name = other;
+ }
+ }
+ /* If there's a dentry with a DOS name, extract it first */
+ if (dentry_with_dos_name && !dentry_with_dos_name->is_extracted) {
+ int ret;
+ ntfs_volume *vol = (*dir_ni_p)->vol;
+
+ DEBUG("pre-applying DOS name `%s'",
+ dentry_with_dos_name->full_path_utf8);
+ ret = do_apply_dentry_ntfs(dentry_with_dos_name,
+ *dir_ni_p, args);
+ if (ret != 0)
+ return ret;
+
+ *dir_ni_p = dentry_open_parent_ni(dentry, vol);
+ if (!*dir_ni_p)
+ return WIMLIB_ERR_NTFS_3G;
+ }