1503{
1507 PCWSTR pwszNtPathToMap = pwszNTPath;
1511 WCHAR wszDrives[512];
1514
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525 for (ListEntry = MappingList->List.Flink;
1526 ListEntry != &MappingList->List;
1527 ListEntry = ListEntry->
Flink)
1528 {
1530
1532
1533
1535 if (FoundDrive)
1536 {
1537
1538
1539
1540 pwszDrive =
Entry->Win32Path;
1541 pwszRemaining = pwszNTPath +
wcslen(
Entry->NtPath);
1542 goto Quit;
1543 }
1544 }
1545
1546
1547
1548
1549
1550
1552 if (cchDrives == 0 || cchDrives >=
_countof(wszDrives))
1553 {
1554
1555 DPRINT1(
"ConvertNtPathToWin32Path: GetLogicalDriveStringsW failed\n");
1557 }
1558
1559
1561
1562
1563 for (pwszDrive = wszDrives; *pwszDrive; pwszDrive +=
wcslen(pwszDrive) + 1)
1564 {
1565
1568 pwszDrive[2] =
L'\\';
1569
1570 DPRINT(
"Testing '%S' --> '%S'\n", pwszDrive, wszNTPath);
1571
1572
1573 FoundDrive = !
_wcsnicmp(pwszNtPathToMap, wszNTPath,
wcslen(wszNTPath));
1574 if (!FoundDrive)
1575 {
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1596 {
1597
1598
1599
1600
1601
1602 if (pwszDrive[0] !=
ptr[1])
1603 {
1604 DPRINT1(
"Peculiar: expected network share drive letter %C different from actual one %C\n",
1605 pwszDrive[0],
ptr[1]);
1606 }
1607
1608
1610
1611 while (*ptr2 ==
L'\\') ++ptr2;
1612
1614
1615
1616 FoundDrive = !
_wcsnicmp(pwszNtPathToMap, wszNTPath,
wcslen(wszNTPath));
1617 }
1618 }
1619 if (FoundDrive)
1620 {
1621
1622
1624
1625 if (pwszNtPathToMap == pwszNTPath)
1626 {
1627 ASSERT(!RetryOnce && pwszNTPath != TargetPath);
1628 pwszRemaining = pwszNTPath +
wcslen(wszNTPath);
1629 }
1630 break;
1631 }
1632 }
1633
1634 if (FoundDrive)
1635 {
1636
1639 {
1640 DPRINT1(
"ConvertNtPathToWin32Path: Cannot allocate memory\n");
1642 }
1644 pwszNTPath, pwszRemaining - pwszNTPath);
1646
1647
1649 MappingList->MappingsCount++;
1650
1651
1652 pwszDrive =
Entry->Win32Path;
1653 goto Quit;
1654 }
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677 if (!RetryOnce && !FoundDrive)
1678 {
1681
1686
1687 if (
swscanf(pwszNTPath,
L"\\Device\\Harddisk%lu\\Partition%lu%n",
1689 {
1690
1692 }
1693
1694
1695 RtlInitEmptyUnicodeString(&SymLink, (
PWCHAR)pwszNTPath,
Length *
sizeof(
WCHAR));
1697
1699 &SymLink,
1707 {
1708
1709 DPRINT1(
"ConvertNtPathToWin32Path: NtOpenSymbolicLinkObject(%wZ) failed, Status 0x%08lx\n",
1712 }
1713
1715 RtlInitEmptyUnicodeString(&
Target, TargetPath,
sizeof(TargetPath));
1716
1717
1720
1721
1723 {
1724
1725 DPRINT1(
"ConvertNtPathToWin32Path: NtQuerySymbolicLinkObject(%wZ) failed, Status 0x%08lx\n",
1728 }
1729
1730
1731 pwszRemaining = pwszNTPath +
Length;
1732 pwszNtPathToMap = TargetPath;
1733
1734
1737 }
1738
1740
1741Quit:
1742 if (FoundDrive)
1743 {
1746 pwszDrive,
1747 pwszRemaining);
1748 DPRINT(
"ConvertNtPathToWin32Path: %S\n", pwszPath);
1750 }
1751
1753}
_In_ PSCSI_REQUEST_BLOCK _Out_ NTSTATUS _Inout_ BOOLEAN * Retry
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define NT_SUCCESS(StatCode)
DWORD WINAPI QueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax)
DWORD WINAPI GetLogicalDriveStringsW(IN DWORD nBufferLength, IN LPWSTR lpBuffer)
#define InsertHeadList(ListHead, Entry)
_Check_return_ _CRTIMP int __cdecl swscanf(_In_z_ const wchar_t *_Src, _In_z_ _Scanf_format_string_ const wchar_t *_Format,...)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define OBJ_CASE_INSENSITIVE
#define memmove(s1, s2, n)
#define InitializeObjectAttributes(p, n, a, r, s)
#define SYMBOLIC_LINK_QUERY
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
_In_ ULONG _In_ ULONG _In_ ULONG Length
NTSTATUS NTAPI NtQuerySymbolicLinkObject(IN HANDLE LinkHandle, OUT PUNICODE_STRING LinkTarget, OUT PULONG ResultLength OPTIONAL)
NTSTATUS NTAPI NtOpenSymbolicLinkObject(OUT PHANDLE LinkHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
STRSAFEAPI StringCchCopyNW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, size_t cchToCopy)
base of all file and directory entries
struct _LIST_ENTRY * Flink
#define CONTAINING_RECORD(address, type, field)
_In_ ULONG _In_ ULONG PartitionNumber