Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. map.c
  5. Abstract:
  6. This module implements the drive mapping command.
  7. Author:
  8. Wesley Witt (wesw) 21-Oct-1998
  9. Ted Miller (tedm) 21-Oct-1998
  10. Revision History:
  11. --*/
  12. #include "cmdcons.h"
  13. #pragma hdrstop
  14. LPWSTR FsTypes[] =
  15. {
  16. L" ",
  17. L"NEW ",
  18. L"FAT16",
  19. L"NTFS ",
  20. L"FAT32",
  21. L" ",
  22. L" "
  23. };
  24. BOOL
  25. RcDiskRegionEnum(
  26. IN PPARTITIONED_DISK Disk,
  27. IN PDISK_REGION Region,
  28. IN ULONG_PTR UseArcNames
  29. )
  30. {
  31. ULONGLONG RegionSizeMB;
  32. WCHAR ArcName[256];
  33. if (!SPPT_IS_REGION_PARTITIONED(Region) ||
  34. (Region->ExtendedType == EPTContainerPartition)) {
  35. return TRUE;
  36. }
  37. if (UseArcNames) {
  38. SpArcNameFromRegion(
  39. Region,
  40. ArcName,
  41. sizeof(ArcName),
  42. PartitionOrdinalCurrent,
  43. PrimaryArcPath
  44. );
  45. } else {
  46. SpNtNameFromRegion(
  47. Region,
  48. ArcName,
  49. sizeof(ArcName),
  50. PartitionOrdinalCurrent
  51. );
  52. }
  53. RegionSizeMB = SpPtSectorCountToMB(Disk->HardDisk, Region->SectorCount);
  54. RcMessageOut(
  55. MSG_MAP_ENTRY,
  56. Region->DriveLetter == 0 ? L'?' : Region->DriveLetter,
  57. Region->DriveLetter == 0 ? L' ' : L':',
  58. FsTypes[Region->Filesystem],
  59. (ULONG)RegionSizeMB,
  60. ArcName
  61. );
  62. return TRUE;
  63. }
  64. NTSTATUS
  65. GetDriveLetterLinkTarget(
  66. IN PWSTR SourceNameStr,
  67. OUT PWSTR *LinkTarget
  68. )
  69. {
  70. static WCHAR targetNameBuffer[256];
  71. NTSTATUS status;
  72. UNICODE_STRING sourceName;
  73. UNICODE_STRING targetName;
  74. OBJECT_ATTRIBUTES oa;
  75. HANDLE handle;
  76. RtlInitUnicodeString(&sourceName, SourceNameStr);
  77. InitializeObjectAttributes(&oa, &sourceName, OBJ_CASE_INSENSITIVE, NULL, NULL);
  78. status = ZwOpenSymbolicLinkObject(&handle, READ_CONTROL | SYMBOLIC_LINK_QUERY, &oa);
  79. if (NT_SUCCESS(status))
  80. {
  81. RtlZeroMemory(targetNameBuffer, sizeof(targetNameBuffer));
  82. targetName.Buffer = targetNameBuffer;
  83. targetName.MaximumLength = sizeof(targetNameBuffer);
  84. status = ZwQuerySymbolicLinkObject(handle, &targetName, NULL);
  85. NtClose(handle);
  86. }
  87. if (NT_SUCCESS(status))
  88. {
  89. *LinkTarget = targetName.Buffer;
  90. }
  91. else
  92. {
  93. *LinkTarget = NULL;
  94. }
  95. return status;
  96. }
  97. ULONG
  98. RcCmdDriveMap(
  99. IN PTOKENIZED_LINE TokenizedLine
  100. )
  101. {
  102. ULONG i;
  103. LPWSTR s;
  104. LPWSTR p;
  105. WCHAR buf[128];
  106. if (RcCmdParseHelp( TokenizedLine, MSG_MAP_HELP )) {
  107. return 1;
  108. }
  109. RcTextOut( L"\r\n" );
  110. if (TokenizedLine->TokenCount == 2 && _wcsicmp( TokenizedLine->Tokens->Next->String, L"arc" ) == 0) {
  111. SpEnumerateDiskRegions( (PSPENUMERATEDISKREGIONS)RcDiskRegionEnum, 1 );
  112. } else {
  113. SpEnumerateDiskRegions( (PSPENUMERATEDISKREGIONS)RcDiskRegionEnum, 0 );
  114. }
  115. for (i=0; i<26; i++) {
  116. swprintf( buf, L"\\DosDevices\\%c:",i+L'A');
  117. if (RcIsFileOnCDROM(buf) == STATUS_SUCCESS ||
  118. RcIsFileOnFloppy(buf) == STATUS_SUCCESS
  119. || RcIsNetworkDrive(buf) == STATUS_SUCCESS
  120. )
  121. {
  122. GetDriveLetterLinkTarget( buf, &s );
  123. RcMessageOut( MSG_MAP_ENTRY2, buf[12], s );
  124. }
  125. }
  126. return 1;
  127. }