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.

131 lines
3.5 KiB

  1. //
  2. // Simple wrapper around GetFullPathname and FindFirstFile/FindNextFile
  3. // that converts to \\? form.
  4. //
  5. #include "nt.h"
  6. #include "ntrtl.h"
  7. #include "nturtl.h"
  8. #include "windows.h"
  9. #include <stddef.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <stdarg.h>
  13. #pragma warning(push)
  14. #pragma warning(disable: 4511)
  15. #pragma warning(disable: 4512)
  16. #include "yvals.h"
  17. #pragma warning(disable: 4663)
  18. #include <vector>
  19. #pragma warning(pop)
  20. #include <string.h>
  21. #include <stdarg.h>
  22. #define NUMBER_OF(x) (sizeof(x)/sizeof((x)[0]))
  23. #define FusionpGetLastWin32Error GetLastError
  24. #define FusionpSetLastWin32Error SetLastError
  25. #include <string.h>
  26. #include <stdarg.h>
  27. #include "fusionhandle.h"
  28. BOOL FusionpConvertToBigPath(PCWSTR Path, SIZE_T BufferSize, PWSTR Buffer);
  29. BOOL FusionpAreWeInOSSetupMode(BOOL* pfIsInSetup) { *pfIsInSetup = FALSE; return TRUE; }
  30. extern "C"
  31. {
  32. BOOL WINAPI SxsDllMain(HINSTANCE hInst, DWORD dwReason, PVOID pvReserved);
  33. void __cdecl wmainCRTStartup();
  34. BOOL FusionpInitializeHeap(HINSTANCE hInstance);
  35. VOID FusionpUninitializeHeap();
  36. };
  37. void ExeEntry()
  38. {
  39. if (!::FusionpInitializeHeap(GetModuleHandleW(NULL)))
  40. goto Exit;
  41. ::wmainCRTStartup();
  42. Exit:
  43. FusionpUninitializeHeap();
  44. }
  45. FILE* g_pLogFile;
  46. const static WCHAR g_pszImage[] = L"mkdir_bigpath";
  47. void
  48. ReportFailure(
  49. const char* szFormat,
  50. ...
  51. )
  52. {
  53. const DWORD dwLastError = ::GetLastError();
  54. va_list ap;
  55. char rgchBuffer[4096] = { 0 };
  56. WCHAR rgchWin32Error[4096] = { 0 };
  57. va_start(ap, szFormat);
  58. _vsnprintf(rgchBuffer, NUMBER_OF(rgchBuffer) - 1, szFormat, ap);
  59. va_end(ap);
  60. if (!::FormatMessageW(
  61. FORMAT_MESSAGE_FROM_SYSTEM,
  62. NULL,
  63. dwLastError,
  64. 0,
  65. rgchWin32Error,
  66. NUMBER_OF(rgchWin32Error) - 1,
  67. &ap))
  68. {
  69. const DWORD dwLastError2 = ::GetLastError();
  70. _snwprintf(rgchWin32Error, NUMBER_OF(rgchWin32Error) - 1, L"Error formatting Win32 error %lu\nError from FormatMessage is %lu", dwLastError, dwLastError2);
  71. }
  72. fprintf(stderr, "%ls: %s\n%ls\n", g_pszImage, rgchBuffer, rgchWin32Error);
  73. if (g_pLogFile != NULL)
  74. fprintf(g_pLogFile, "%ls: %s\n%ls\n", g_pszImage, rgchBuffer, rgchWin32Error);
  75. }
  76. extern "C" int __cdecl wmain(int argc, wchar_t** argv)
  77. {
  78. int iReturnStatus = EXIT_FAILURE;
  79. std::vector<WCHAR> arg1;
  80. PWSTR p = NULL;
  81. ULONG i = 0;
  82. WIN32_FIND_DATAW wfd;
  83. CFindFile FindFileHandle;
  84. if (argc != 2)
  85. {
  86. fprintf(stderr,
  87. "%ls: Usage:\n"
  88. " %ls <directory-to-list>\n",
  89. argv[0], argv[0]);
  90. goto Exit;
  91. }
  92. arg1.resize(1 + (1UL << 15));
  93. arg1[0] = 0;
  94. if (!::FusionpConvertToBigPath(argv[1], arg1.size(), &arg1[0]))
  95. {
  96. ::ReportFailure("FusionpConvertToBigPath\n");
  97. goto Exit;
  98. }
  99. arg1.resize(1 + ::wcslen(&arg1[0]));
  100. arg1.insert(arg1.end() - 1, '\\');
  101. arg1.insert(arg1.end() - 1, '*');
  102. if (!FindFileHandle.Win32FindFirstFile(&arg1[0], &wfd))
  103. {
  104. ::ReportFailure("FindFirstFile\n");
  105. goto Exit;
  106. }
  107. do
  108. {
  109. LARGE_INTEGER Size;
  110. Size.HighPart = wfd.nFileSizeHigh;
  111. Size.LowPart = wfd.nFileSizeLow;
  112. printf("%I64u, %ls%ls\n", Size.QuadPart, wfd.cFileName, (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? L"/" : L"");
  113. } while(::FindNextFileW(FindFileHandle, &wfd));
  114. //Success:
  115. iReturnStatus = EXIT_SUCCESS;
  116. Exit:
  117. return iReturnStatus;
  118. }