Leaked source code of windows server 2003
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.

97 lines
2.6 KiB

  1. #include "stdinc.h"
  2. #include "debmacro.h"
  3. #include "util.h"
  4. //
  5. // used by tools\copy_bigpath and tools\mkdir_bigpath
  6. //
  7. BOOL
  8. FusionpConvertToBigPath(PCWSTR Path, SIZE_T BufferSize, PWSTR Buffer)
  9. {
  10. FN_PROLOG_WIN32
  11. SIZE_T i = 0;
  12. SIZE_T j = 0;
  13. PWSTR FilePart = NULL;
  14. BOOL Unc = FALSE;
  15. PARAMETER_CHECK(Path != NULL);
  16. PARAMETER_CHECK(Path[0] != 0);
  17. PARAMETER_CHECK(Buffer != NULL);
  18. PARAMETER_CHECK(BufferSize != 0);
  19. if (::FusionpIsPathSeparator(Path[0])
  20. && ::FusionpIsPathSeparator(Path[1])
  21. && Path[2] == '?')
  22. {
  23. i = 1 + ::wcslen(Path);
  24. if (i >= BufferSize)
  25. {
  26. ::FusionpSetLastWin32Error(ERROR_BUFFER_OVERFLOW);
  27. goto Exit;
  28. }
  29. CopyMemory(Buffer, Path, i * sizeof(WCHAR));
  30. FN_SUCCESSFUL_EXIT();
  31. }
  32. else if (::FusionpIsPathSeparator(Path[0])
  33. && FusionpIsPathSeparator(Path[1])
  34. )
  35. {
  36. Unc = TRUE;
  37. if (BufferSize <= NUMBER_OF(L"\\\\?\\UN\\m\\s"))
  38. {
  39. ORIGINATE_WIN32_FAILURE_AND_EXIT(BufferTooSmall, ERROR_BUFFER_OVERFLOW);
  40. }
  41. ::wcscpy(Buffer, L"\\\\?\\UN");
  42. }
  43. else
  44. {
  45. Unc = FALSE;
  46. if (BufferSize <= NUMBER_OF(L"\\\\?\\c:\\"))
  47. {
  48. ORIGINATE_WIN32_FAILURE_AND_EXIT(BufferTooSmall, ERROR_BUFFER_OVERFLOW);
  49. }
  50. ::wcscpy(Buffer, L"\\\\?\\");
  51. }
  52. i = ::wcslen(Buffer);
  53. IFW32FALSE_ORIGINATE_AND_EXIT((j = GetFullPathNameW(Path, static_cast<ULONG>(BufferSize - i), Buffer + i, &FilePart)));
  54. if ((j + i + 1) >= BufferSize)
  55. {
  56. ORIGINATE_WIN32_FAILURE_AND_EXIT(BufferTooSmall, ERROR_BUFFER_OVERFLOW);
  57. }
  58. if (Unc)
  59. Buffer[i] = 'C';
  60. FN_EPILOG
  61. }
  62. BOOL
  63. FusionpSkipBigPathRoot(PCWSTR s, OUT SIZE_T* RootLengthOut)
  64. {
  65. FN_PROLOG_WIN32
  66. SIZE_T i = 0;
  67. PARAMETER_CHECK(s != NULL);
  68. PARAMETER_CHECK(s[0] != 0);
  69. PARAMETER_CHECK(memcmp(s, L"\\\\?\\", sizeof(L"\\\\?\\") - sizeof(WCHAR)) == 0);
  70. PARAMETER_CHECK(RootLengthOut != NULL);
  71. if (s[NUMBER_OF(L"\\\\?\\c:") - 2] == ':')
  72. {
  73. i += NUMBER_OF(L"\\\\?\\c:\\") - 2;
  74. i += wcsspn(s + i, L"\\/");
  75. }
  76. else
  77. {
  78. i += NUMBER_OF(L"\\\\?\\unc\\") - 1;
  79. i += wcsspn(s + i, L"\\/"); // skip "\\"
  80. i += wcscspn(s + i, L"\\/"); // skip "\\computer"
  81. i += wcsspn(s + i, L"\\/"); // skip "\\computer\"
  82. i += wcscspn(s + i, L"\\/"); // skip "\\computer\share"
  83. i += wcsspn(s + i, L"\\/"); // skip "\\computer\share\"
  84. }
  85. *RootLengthOut += i;
  86. FN_EPILOG
  87. }