+out_set_dos_name:
+ /* Set DOS (short) name if given */
+ if (dentry->short_name_len != 0) {
+
+ char *short_name_utf8;
+ size_t short_name_utf8_len;
+ short_name_utf8 = utf16_to_utf8(dentry->short_name,
+ dentry->short_name_len,
+ &short_name_utf8_len);
+ if (!short_name_utf8) {
+ ERROR("Out of memory");
+ ret = WIMLIB_ERR_NOMEM;
+ goto out_close_dir_ni;
+ }
+
+ 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);
+ if (!ni) {
+ ERROR_WITH_ERRNO("Could not find NTFS inode for `%s'",
+ dir_name);
+ return WIMLIB_ERR_NTFS_3G;
+ }
+ }
+
+ DEBUG("Setting short (DOS) name of `%s' to %s",
+ dentry->full_path_utf8, short_name_utf8);
+
+ ret = ntfs_set_ntfs_dos_name(ni, dir_ni, short_name_utf8,
+ short_name_utf8_len, 0);
+ FREE(short_name_utf8);
+ if (ret != 0) {
+ ERROR_WITH_ERRNO("Could not set DOS (short) name for `%s'",
+ dentry->full_path_utf8);
+ ret = WIMLIB_ERR_NTFS_3G;
+ }
+ /* inodes have been closed by ntfs_set_ntfs_dos_name(). */
+ return ret;
+ }
+
+out_close_dir_ni:
+ if (ntfs_inode_close(dir_ni) != 0) {
+ if (ret == 0)
+ ret = WIMLIB_ERR_NTFS_3G;
+ ERROR_WITH_ERRNO("Failed to close directory inode");
+ }
+ if (ni && ntfs_inode_close(ni) != 0) {
+ if (ret == 0)
+ ret = WIMLIB_ERR_NTFS_3G;
+ ERROR_WITH_ERRNO("Failed to close inode");