1528{
1532 PCWSTR pwszNtPathToMap = pwszNTPath;
1536 WCHAR wszDrives[512];
1539
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550 for (ListEntry = MappingList->List.Flink;
1551 ListEntry != &MappingList->List;
1552 ListEntry = ListEntry->
Flink)
1553 {
1555
1557
1558
1560 if (FoundDrive)
1561 {
1562
1563
1564
1565 pwszDrive =
Entry->Win32Path;
1566 pwszRemaining = pwszNTPath +
wcslen(
Entry->NtPath);
1567 goto Quit;
1568 }
1569 }
1570
1571
1572
1573
1574
1575
1577 if (cchDrives == 0 || cchDrives >=
_countof(wszDrives))
1578 {
1579
1580 DPRINT1(
"ConvertNtPathToWin32Path: GetLogicalDriveStringsW failed\n");
1582 }
1583
1584
1586
1587
1588 for (pwszDrive = wszDrives; *pwszDrive; pwszDrive +=
wcslen(pwszDrive) + 1)
1589 {
1590
1593 pwszDrive[2] =
L'\\';
1594
1595 DPRINT(
"Testing '%S' --> '%S'\n", pwszDrive, wszNTPath);
1596
1597
1598 FoundDrive = !
_wcsnicmp(pwszNtPathToMap, wszNTPath,
wcslen(wszNTPath));
1599 if (!FoundDrive)
1600 {
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1621 {
1622
1623
1624
1625
1626
1627 if (pwszDrive[0] !=
ptr[1])
1628 {
1629 DPRINT1(
"Peculiar: expected network share drive letter %C different from actual one %C\n",
1630 pwszDrive[0],
ptr[1]);
1631 }
1632
1633
1635
1636 while (*ptr2 ==
L'\\') ++ptr2;
1637
1639
1640
1641 FoundDrive = !
_wcsnicmp(pwszNtPathToMap, wszNTPath,
wcslen(wszNTPath));
1642 }
1643 }
1644 if (FoundDrive)
1645 {
1646
1647
1649
1650 if (pwszNtPathToMap == pwszNTPath)
1651 {
1652 ASSERT(!RetryOnce && pwszNTPath != TargetPath);
1653 pwszRemaining = pwszNTPath +
wcslen(wszNTPath);
1654 }
1655 break;
1656 }
1657 }
1658
1659 if (FoundDrive)
1660 {
1661
1664 {
1665 DPRINT1(
"ConvertNtPathToWin32Path: Cannot allocate memory\n");
1667 }
1669 pwszNTPath, pwszRemaining - pwszNTPath);
1671
1672
1674 MappingList->MappingsCount++;
1675
1676
1677 pwszDrive =
Entry->Win32Path;
1678 goto Quit;
1679 }
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702 if (!RetryOnce && !FoundDrive)
1703 {
1706
1711
1712 if (
swscanf(pwszNTPath,
L"\\Device\\Harddisk%lu\\Partition%lu%n",
1714 {
1715
1717 }
1718
1719
1720 RtlInitEmptyUnicodeString(&SymLink, (
PWCHAR)pwszNTPath,
Length *
sizeof(
WCHAR));
1722
1724 &SymLink,
1732 {
1733
1734 DPRINT1(
"ConvertNtPathToWin32Path: NtOpenSymbolicLinkObject(%wZ) failed, Status 0x%08lx\n",
1737 }
1738
1740 RtlInitEmptyUnicodeString(&
Target, TargetPath,
sizeof(TargetPath));
1741
1742
1745
1746
1748 {
1749
1750 DPRINT1(
"ConvertNtPathToWin32Path: NtQuerySymbolicLinkObject(%wZ) failed, Status 0x%08lx\n",
1753 }
1754
1755
1756 pwszRemaining = pwszNTPath +
Length;
1757 pwszNtPathToMap = TargetPath;
1758
1759
1762 }
1763
1765
1766Quit:
1767 if (FoundDrive)
1768 {
1771 pwszDrive,
1772 pwszRemaining);
1773 DPRINT(
"ConvertNtPathToWin32Path: %S\n", pwszPath);
1775 }
1776
1778}
_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