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.

198 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Abstract:
  4. module common.hxx |
  5. Author:
  6. Michael C. Johnson [mikejohn] 03-Feb-2000
  7. Stefan R. Steiner [SSteiner] 25-Jul-2001
  8. Description:
  9. Contains general code and definitions used by the Shim writer and the various other writers
  10. Revision History:
  11. reuvenl 05/02/2002 Incorporated code from common.h/cpp into this module
  12. --*/
  13. #ifndef __H_COMMON_
  14. #define __H_COMMON_
  15. #pragma once
  16. #include "bsstring.hxx"
  17. typedef PWCHAR *PPWCHAR;
  18. typedef PVOID *PPVOID;
  19. typedef VSS_ID *PVSS_ID, **PPVSS_ID;
  20. #define ROOT_BACKUP_DIR L"%SystemRoot%\\Repair\\Backup"
  21. #define BOOTABLE_STATE_SUBDIR L"\\BootableSystemState"
  22. #define SERVICE_STATE_SUBDIR L"\\ServiceState"
  23. /*
  24. ** In a number of places we need a buffer into which to fetch registry
  25. ** values. Define a common buffer size for the mini writers to use
  26. */
  27. #ifndef REGISTRY_BUFFER_SIZE
  28. #define REGISTRY_BUFFER_SIZE (4096)
  29. #endif
  30. #ifndef MAX_VOLUMENAME_LENGTH
  31. #define MAX_VOLUMENAME_LENGTH (50)
  32. #endif
  33. #ifndef MAX_VOLUMENAME_SIZE
  34. #define MAX_VOLUMENAME_SIZE (MAX_VOLUMENAME_LENGTH * sizeof (WCHAR))
  35. #endif
  36. #ifndef DIR_SEP_STRING
  37. #define DIR_SEP_STRING L"\\"
  38. #endif
  39. #ifndef DIR_SEP_CHAR
  40. #define DIR_SEP_CHAR L'\\'
  41. #endif
  42. #ifndef UMIN
  43. #define UMIN(_P1, _P2) (((_P1) < (_P2)) ? (_P1) : (_P2))
  44. #endif
  45. #ifndef UMAX
  46. #define UMAX(_P1, _P2) (((_P1) > (_P2)) ? (_P1) : (_P2))
  47. #endif
  48. #define HandleInvalid(_Handle) ((NULL == (_Handle)) || (INVALID_HANDLE_VALUE == (_Handle)))
  49. #define GET_STATUS_FROM_BOOL(_bSucceeded) ((_bSucceeded) ? NOERROR : HRESULT_FROM_WIN32 (GetLastError()))
  50. #define GET_STATUS_FROM_HANDLE(_handle) ((!HandleInvalid(_handle)) ? NOERROR : HRESULT_FROM_WIN32 (GetLastError()))
  51. #define GET_STATUS_FROM_POINTER(_ptr) ((NULL != (_ptr)) ? NOERROR : E_OUTOFMEMORY)
  52. #define GET_STATUS_FROM_FILESCAN(_bMoreFiles) ((_bMoreFiles) \
  53. ? NOERROR \
  54. : ((ERROR_NO_MORE_FILES == GetLastError()) \
  55. ? NOERROR \
  56. : HRESULT_FROM_WIN32 (GetLastError())))
  57. #define NameIsDotOrDotDot(_ptszName) ((L'.' == (_ptszName) [0]) && \
  58. ((L'\0' == (_ptszName) [1]) || ((L'.' == (_ptszName) [1]) && \
  59. (L'\0' == (_ptszName) [2]))))
  60. #define DeclareStaticUnicodeString(_StringName, _StringValue) \
  61. static UNICODE_STRING (_StringName) = {sizeof (_StringValue) - sizeof (UNICODE_NULL), \
  62. sizeof (_StringValue), \
  63. _StringValue}
  64. #define RETURN_VALUE_IF_REQUIRED(_Ptr, _Value) {if (NULL != (_Ptr)) *(_Ptr) = (_Value);}
  65. HRESULT StringInitialise (PUNICODE_STRING pucsString);
  66. HRESULT StringInitialise (PUNICODE_STRING pucsString, PWCHAR pwszString);
  67. HRESULT StringInitialise (PUNICODE_STRING pucsString, LPCWSTR pwszString);
  68. HRESULT StringTruncate (PUNICODE_STRING pucsString, USHORT usSizeInChars);
  69. HRESULT StringSetLength (PUNICODE_STRING pucsString);
  70. HRESULT StringAllocate (PUNICODE_STRING pucsString, USHORT usMaximumStringLengthInBytes);
  71. HRESULT StringFree (PUNICODE_STRING pucsString);
  72. HRESULT StringCreateFromString (PUNICODE_STRING pucsNewString, PUNICODE_STRING pucsOriginalString);
  73. HRESULT StringCreateFromString (PUNICODE_STRING pucsNewString, PUNICODE_STRING pucsOriginalString, DWORD dwExtraChars);
  74. HRESULT StringCreateFromString (PUNICODE_STRING pucsNewString, LPCWSTR pwszOriginalString);
  75. HRESULT StringCreateFromString (PUNICODE_STRING pucsNewString, LPCWSTR pwszOriginalString, DWORD dwExtraChars);
  76. HRESULT StringAppendString (PUNICODE_STRING pucsTarget, PUNICODE_STRING pucsSource);
  77. HRESULT StringAppendString (PUNICODE_STRING pucsTarget, PWCHAR pwszSource);
  78. HRESULT StringCreateFromExpandedString (PUNICODE_STRING pucsNewString, PUNICODE_STRING pucsOriginalString);
  79. HRESULT StringCreateFromExpandedString (PUNICODE_STRING pucsNewString, PUNICODE_STRING pucsOriginalString, DWORD dwExtraChars);
  80. HRESULT StringCreateFromExpandedString (PUNICODE_STRING pucsNewString, LPCWSTR pwszOriginalString);
  81. HRESULT StringCreateFromExpandedString (PUNICODE_STRING pucsNewString, LPCWSTR pwszOriginalString, DWORD dwExtraChars);
  82. HRESULT CommonCloseHandle (PHANDLE phHandle);
  83. HRESULT VsServiceChangeState (IN LPCWSTR pwszServiceName,
  84. IN DWORD dwRequestedState,
  85. OUT PDWORD pdwReturnedOldState,
  86. OUT PBOOL pbReturnedStateChanged);
  87. BOOL VsCreateDirectories (
  88. IN LPCWSTR pwszPathName,
  89. IN LPSECURITY_ATTRIBUTES lpSecurityAttribute,
  90. IN DWORD dwExtraAttributes
  91. );
  92. HRESULT RemoveDirectoryTree (
  93. IN LPCWSTR pwcsDirectoryPath
  94. );
  95. HRESULT CreateTargetPath(
  96. IN LPCWSTR pwszTargetPath
  97. );
  98. HRESULT CleanupTargetPath(LPCWSTR pwszTargetPath);
  99. HRESULT MoveFilesInDirectory (
  100. IN CBsString cwsSourceDirectoryPath,
  101. IN CBsString cwsTargetDirectoryPath
  102. );
  103. HRESULT IsPathInVolumeArray (IN LPCWSTR pwszPath,
  104. IN const ULONG ulVolumeCount,
  105. IN LPCWSTR *ppwszVolumeNamesArray,
  106. OUT PBOOL pbReturnedFoundInVolumeArray);
  107. const HRESULT ClassifyShimFailure (HRESULT hrShimFailure);
  108. const HRESULT ClassifyShimFailure (HRESULT hrShimFailure, BOOL &bStatusUpdated);
  109. const HRESULT ClassifyWriterFailure (HRESULT hrWriterFailure);
  110. const HRESULT ClassifyWriterFailure (HRESULT hrWriterFailure, BOOL &bStatusUpdated);
  111. HRESULT LogFailureWorker (CVssFunctionTracer *pft,
  112. LPCWSTR pwszNameWriter,
  113. LPCWSTR pwszNameCalledRoutine);
  114. #define LogFailure(_pft, _hrStatus, _hrStatusRemapped, _pwszNameWriter, _pwszNameCalledRoutine, _pwszNameCallingRoutine) \
  115. { \
  116. if (FAILED (_hrStatus)) \
  117. { \
  118. if (CVssFunctionTracer *_pftLocal = (NULL != (_pft)) ? (_pft) : new CVssFunctionTracer (VSSDBG_SHIM, (_pwszNameCallingRoutine))) \
  119. { \
  120. _pftLocal->hr = (_hrStatus); \
  121. \
  122. (_hrStatusRemapped) = LogFailureWorker (_pftLocal, (_pwszNameWriter), (_pwszNameCalledRoutine)); \
  123. \
  124. if (NULL == (_pft)) delete _pftLocal; \
  125. } \
  126. } \
  127. }
  128. #define LogAndThrowOnFailure(_ft, _pwszNameWriter, _pwszNameFailedRoutine) \
  129. { \
  130. HRESULT _hrStatusRemapped; \
  131. \
  132. if (FAILED ((_ft).hr)) \
  133. { \
  134. LogFailure (&(_ft), (_ft).hr, _hrStatusRemapped, (_pwszNameWriter), (_pwszNameFailedRoutine), L"(UNKNOWN)"); \
  135. \
  136. throw (_hrStatusRemapped); \
  137. } \
  138. }
  139. #endif // __H_COMMON_