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.

179 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. SxsPath.cpp
  5. Abstract:
  6. Author:
  7. Jay Krell (a-JayK) October 2000
  8. Revision History:
  9. --*/
  10. #include "stdinc.h"
  11. #include "sxspath.h"
  12. #include "fusiontrace.h"
  13. BOOL
  14. SxspIsUncPath(
  15. PCWSTR Path,
  16. BOOL* Result
  17. )
  18. {
  19. BOOL fSuccess = FALSE;
  20. FN_TRACE_WIN32(fSuccess);
  21. BOOL fIsFullWin32OrNtPath = FALSE;
  22. PARAMETER_CHECK(Path != NULL);
  23. PARAMETER_CHECK(Result != NULL);
  24. IFW32FALSE_EXIT(::SxspIsFullWin32OrNtPath(Path, &fIsFullWin32OrNtPath));
  25. PARAMETER_CHECK(fIsFullWin32OrNtPath);
  26. //
  27. // UNC paths take at least two forms.
  28. //
  29. // 1) \\computer\share
  30. // 2) \\?\unc\computer\share
  31. // This is the NT path disguised as a Win32 path form.
  32. //
  33. // Non UNC paths take at least two forms.
  34. //
  35. // 1) c:\blah
  36. // 2) \\?\c:\blah
  37. // This is the NT path disguised as a Win32 path form.
  38. //
  39. if (RTL_IS_PATH_SEPARATOR(Path[0]) &&
  40. RTL_IS_PATH_SEPARATOR(Path[1]))
  41. {
  42. if (Path[2] != '?')
  43. {
  44. *Result = TRUE;
  45. fSuccess = TRUE;
  46. goto Exit;
  47. }
  48. if ((Path[3] == 'U' || Path[3] == 'u') &&
  49. (Path[4] == 'N' || Path[4] == 'n') &&
  50. (Path[5] == 'N' || Path[5] == 'c') &&
  51. RTL_IS_PATH_SEPARATOR(Path[6])
  52. )
  53. {
  54. *Result = TRUE;
  55. fSuccess = TRUE;
  56. goto Exit;
  57. }
  58. }
  59. fSuccess = TRUE;
  60. *Result = FALSE;
  61. Exit:
  62. KdPrint((__FUNCTION__"(%ls):%s\n", Path, *Result ? "true" : "false"));
  63. return fSuccess;
  64. }
  65. BOOL
  66. SxspIsNtPath(
  67. PCWSTR Path,
  68. BOOL* Result
  69. )
  70. {
  71. BOOL fSuccess = FALSE;
  72. FN_TRACE_WIN32(fSuccess);
  73. PARAMETER_CHECK(Path != NULL);
  74. PARAMETER_CHECK(Result != NULL);
  75. //
  76. // Nt paths usually look like \??\c:\blah
  77. // or \??\unc\machine\share
  78. //
  79. // There general form is just a slash delimited path that
  80. // starts with a slash and never contains double slashes (like DOS/Win32 paths can have).
  81. //
  82. // The path \foo\bar is ambiguous between DOS/Win32 and NT.
  83. //
  84. *Result = ((Path[0] != 0) && (Path[1] == '?'));
  85. fSuccess = TRUE;
  86. Exit:
  87. KdPrint((__FUNCTION__"(%ls):%s\n", Path, *Result ? "true" : "false"));
  88. return fSuccess;
  89. }
  90. BOOL
  91. SxspIsFullWin32OrNtPath(
  92. PCWSTR Path,
  93. BOOL* Result
  94. )
  95. {
  96. BOOL fSuccess = FALSE;
  97. FN_TRACE_WIN32(fSuccess);
  98. PARAMETER_CHECK(Path != NULL);
  99. PARAMETER_CHECK(Result != NULL);
  100. //
  101. //
  102. // The acceptable forms are
  103. //
  104. // \\machine\share
  105. // c:\foo
  106. // \??\c:\foo
  107. // \??\unc\machine\share
  108. // \\?\c:\foo
  109. // \\?\unc\machine\share
  110. //
  111. //
  112. if (::FusionpIsDriveLetter(Path[0]) &&
  113. (Path[1] == ':') &&
  114. RTL_IS_PATH_SEPARATOR(Path[2]))
  115. {
  116. *Result = TRUE;
  117. fSuccess = TRUE;
  118. goto Exit;
  119. }
  120. if (RTL_IS_PATH_SEPARATOR(Path[0])
  121. && (Path[1] == '?' || RTL_IS_PATH_SEPARATOR(Path[1]))
  122. && Path[2] == '?'
  123. && RTL_IS_PATH_SEPARATOR(Path[3]))
  124. {
  125. // "\??\" or "\\?\"
  126. if (::FusionpIsDriveLetter(Path[4]) &&
  127. (Path[5] == ':') &&
  128. (RTL_IS_PATH_SEPARATOR(Path[6]) || Path[6] == 0))
  129. {
  130. // "\??\c:\" or "\\?\c:\"
  131. *Result = TRUE;
  132. fSuccess = TRUE;
  133. goto Exit;
  134. }
  135. if ((Path[4] == L'U' || Path[4] == L'u') &&
  136. (Path[5] == L'N' || Path[5] == L'n') &&
  137. (Path[6] == L'C' || Path[6] == L'c') &&
  138. RTL_IS_PATH_SEPARATOR(Path[7]) &&
  139. (Path[8] != L'\0'))
  140. {
  141. // "\??\unc\" for "\\?\unc\"
  142. *Result = TRUE;
  143. fSuccess = TRUE;
  144. goto Exit;
  145. }
  146. }
  147. if (RTL_IS_PATH_SEPARATOR(Path[0]) &&
  148. RTL_IS_PATH_SEPARATOR(Path[1]))
  149. {
  150. // "\\" presumably "\\machine\share"
  151. {
  152. *Result = TRUE;
  153. fSuccess = TRUE;
  154. goto Exit;
  155. }
  156. }
  157. Exit:
  158. KdPrint((__FUNCTION__"(%ls):%s\n", Path, *Result ? "true" : "false"));
  159. return fSuccess;
  160. }