+static int
+win32_extract_try_rpfix(u8 *rpbuf,
+ const wchar_t *extract_root_realpath,
+ unsigned extract_root_realpath_nchars)
+{
+ struct reparse_data rpdata;
+ wchar_t *target;
+ size_t target_nchars;
+ size_t stripped_nchars;
+ wchar_t *stripped_target;
+ wchar_t stripped_target_nchars;
+ int ret;
+
+ utf16lechar *new_target;
+ utf16lechar *new_print_name;
+ size_t new_target_nchars;
+ size_t new_print_name_nchars;
+ utf16lechar *p;
+
+ ret = parse_reparse_data(rpbuf, 8 + le16_to_cpu(*(u16*)(rpbuf + 4)),
+ &rpdata);
+ if (ret)
+ return ret;
+
+ if (extract_root_realpath[0] == L'\0' ||
+ extract_root_realpath[1] != L':' ||
+ extract_root_realpath[2] != L'\\')
+ {
+ ERROR("Can't understand full path format \"%ls\". "
+ "Try turning reparse point fixups off...",
+ extract_root_realpath);
+ return WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED;
+ }
+
+ ret = parse_substitute_name(rpdata.substitute_name,
+ rpdata.substitute_name_nbytes,
+ rpdata.rptag);
+ if (ret < 0)
+ return 0;
+ stripped_nchars = ret;
+ target = rpdata.substitute_name;
+ target_nchars = rpdata.substitute_name_nbytes / sizeof(utf16lechar);
+ stripped_target = target + 6;
+ stripped_target_nchars = target_nchars - stripped_nchars;
+
+ new_target = alloca((6 + extract_root_realpath_nchars +
+ stripped_target_nchars) * sizeof(utf16lechar));
+
+ p = new_target;
+ if (stripped_nchars == 6) {
+ /* Include \??\ prefix if it was present before */
+ wmemcpy(p, L"\\??\\", 4);
+ p += 4;
+ }
+
+ /* Print name excludes the \??\ if present. */
+ new_print_name = p;
+ if (target_nchars - stripped_target_nchars != 0) {
+ /* Get drive letter from real path to extract root, if a drive
+ * letter was present before. */
+ *p++ = extract_root_realpath[0];
+ *p++ = extract_root_realpath[1];
+ }
+ /* Copy the rest of the extract root */
+ wmemcpy(p, extract_root_realpath + 2, extract_root_realpath_nchars - 2);
+ p += extract_root_realpath_nchars - 2;
+
+ /* Append the stripped target */
+ wmemcpy(p, stripped_target, stripped_target_nchars);
+ p += stripped_target_nchars;
+ new_target_nchars = p - new_target;
+ new_print_name_nchars = p - new_print_name;
+
+ if (new_target_nchars * sizeof(utf16lechar) >= REPARSE_POINT_MAX_SIZE ||
+ new_print_name_nchars * sizeof(utf16lechar) >= REPARSE_POINT_MAX_SIZE)
+ {
+ ERROR("Path names too long to do reparse point fixup!");
+ return WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED;
+ }
+ rpdata.substitute_name = new_target;
+ rpdata.substitute_name_nbytes = new_target_nchars * sizeof(utf16lechar);
+ rpdata.print_name = new_print_name;
+ rpdata.print_name_nbytes = new_print_name_nchars * sizeof(utf16lechar);
+ return make_reparse_buffer(&rpdata, rpbuf);
+}
+