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.

475 lines
13 KiB

  1. /*
  2. **++
  3. **
  4. ** Copyright (c) 2000-2001 Microsoft Corporation
  5. **
  6. **
  7. ** Module Name:
  8. **
  9. ** ml.h
  10. **
  11. **
  12. ** Abstract:
  13. **
  14. ** Test program to exercise backup and multilayer snapshots
  15. **
  16. ** Author:
  17. **
  18. ** Adi Oltean [aoltean] 02/22/2001
  19. **
  20. ** Revision History:
  21. **
  22. **--
  23. */
  24. #ifndef __ML_HEADER_H__
  25. #define __ML_HEADER_H__
  26. #if _MSC_VER > 1000
  27. #pragma once
  28. #endif
  29. /*
  30. ** Defines
  31. **
  32. **
  33. ** C4290: C++ Exception Specification ignored
  34. ** warning C4511: 'CVssCOMApplication' : copy constructor could not be generated
  35. ** warning C4127: conditional expression is constant
  36. */
  37. #pragma warning(disable:4290)
  38. #pragma warning(disable:4511)
  39. #pragma warning(disable:4127)
  40. /*
  41. ** Includes
  42. */
  43. // Disable warning: 'identifier' : identifier was truncated to 'number' characters in the debug information
  44. //#pragma warning(disable:4786)
  45. //
  46. // C4290: C++ Exception Specification ignored
  47. //
  48. #pragma warning(disable:4290)
  49. //
  50. // C4511: copy constructor could not be generated
  51. //
  52. #pragma warning(disable:4511)
  53. //
  54. // Warning: ATL debugging turned off (BUG 250939)
  55. //
  56. // #ifdef _DEBUG
  57. // #define _ATL_DEBUG_INTERFACES
  58. // #define _ATL_DEBUG_QI
  59. // #define _ATL_DEBUG_REFCOUNT
  60. // #endif // _DEBUG
  61. #include <windows.h>
  62. #include <wtypes.h>
  63. #pragma warning( disable: 4201 ) // C4201: nonstandard extension used : nameless struct/union
  64. #include <winioctl.h>
  65. #pragma warning( default: 4201 ) // C4201: nonstandard extension used : nameless struct/union
  66. #include <winbase.h>
  67. #include <wchar.h>
  68. #include <string.h>
  69. #include <iostream.h>
  70. #include <fstream.h>
  71. #include <stdio.h>
  72. #include <process.h>
  73. #include <stddef.h>
  74. #include <stdlib.h>
  75. #include <stdlib.h>
  76. #include <errno.h>
  77. #include <time.h>
  78. #include <string.h>
  79. // Enabling asserts in ATL and VSS
  80. #include "vs_assert.hxx"
  81. #include <oleauto.h>
  82. #include <stddef.h>
  83. #pragma warning( disable: 4127 ) // warning C4127: conditional expression is constant
  84. #include <atlconv.h>
  85. #include <atlbase.h>
  86. // VSS standard headers
  87. #include <vss.h>
  88. #include <vscoordint.h>
  89. #include <vsswprv.h>
  90. #include <vsmgmt.h>
  91. #include <vswriter.h>
  92. #include <vsbackup.h>
  93. #include <vs_inc.hxx>
  94. #include "objects.h"
  95. #include "cmdparse.h"
  96. #include "macros.h"
  97. extern CComModule _Module;
  98. #include <atlcom.h>
  99. ///////////////////////////////////////////////////////////////////////////////
  100. // Useful macros
  101. inline void VsmlCopy(
  102. IN WCHAR* wszDestBuffer,
  103. IN WCHAR* wszSourceBuffer,
  104. IN DWORD dwBufferLen
  105. )
  106. {
  107. ::ZeroMemory(wszDestBuffer, dwBufferLen * sizeof(WCHAR));
  108. ::wcsncpy(wszDestBuffer, wszSourceBuffer, dwBufferLen - 1);
  109. }
  110. #define VSS_ERROR_CASE(wszBuffer, dwBufferLen, X) \
  111. case X: ::VsmlCopy(wszBuffer, VSS_MAKE_W(VSS_EVAL(#X)), dwBufferLen); break;
  112. #define WSTR_GUID_FMT L"{%.8x-%.4x-%.4x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x}"
  113. #define GUID_PRINTF_ARG( X ) \
  114. (X).Data1, \
  115. (X).Data2, \
  116. (X).Data3, \
  117. (X).Data4[0], (X).Data4[1], (X).Data4[2], (X).Data4[3], \
  118. (X).Data4[4], (X).Data4[5], (X).Data4[6], (X).Data4[7]
  119. // Execute the given call and check that the return code must be S_OK
  120. #define CHECK_SUCCESS( Call ) \
  121. { \
  122. ft.hr = Call; \
  123. if (ft.hr != S_OK) \
  124. ft.Err(VSSDBG_VSSTEST, ft.hr, L"\nError: \n\t- Call %S not succeeded. \n" \
  125. L"\t Error code = 0x%08lx. Error description = %s\n", \
  126. #Call, ft.hr, GetStringFromFailureType(ft.hr)); \
  127. }
  128. #define CHECK_NOFAIL( Call ) \
  129. { \
  130. ft.hr = Call; \
  131. if (ft.HrFailed()) \
  132. ft.Err(VSSDBG_VSSTEST, ft.hr, L"\nError: \n\t- Call %S not succeeded. \n" \
  133. L"\t Error code = 0x%08lx. Error description = %s\n", \
  134. #Call, ft.hr, GetStringFromFailureType(ft.hr)); \
  135. }
  136. ///////////////////////////////////////////////////////////////////////////////
  137. // Constants
  138. const MAX_TEXT_BUFFER = 512;
  139. const MAX_VOL_ITERATIONS = 10;
  140. const VSS_SEED = 1234;
  141. // The GUID that corresponds to the format used to store the
  142. // Backup Snapshot Application Info in Client SKU
  143. // {BCF5D39C-27A2-4b4c-B9AE-51B111DC9409}
  144. const GUID VOLSNAP_APPINFO_GUID_BACKUP_CLIENT_SKU =
  145. { 0xbcf5d39c, 0x27a2, 0x4b4c, { 0xb9, 0xae, 0x51, 0xb1, 0x11, 0xdc, 0x94, 0x9 } };
  146. // The GUID that corresponds to the format used to store the
  147. // Backup Snapshot Application Info in Server SKU
  148. // {BAE53126-BC65-41d6-86CC-3D56A5CEE693}
  149. const GUID VOLSNAP_APPINFO_GUID_BACKUP_SERVER_SKU =
  150. { 0xbae53126, 0xbc65, 0x41d6, { 0x86, 0xcc, 0x3d, 0x56, 0xa5, 0xce, 0xe6, 0x93 } };
  151. // The GUID that corresponds to the format used to store the
  152. // Hidden (Inaccessible) Snapshot Application Info
  153. // {F12142B4-9A4B-49af-A851-700C42FDC2BE}
  154. const GUID VOLSNAP_APPINFO_GUID_SYSTEM_HIDDEN =
  155. { 0xf12142b4, 0x9a4b, 0x49af, { 0xa8, 0x51, 0x70, 0xc, 0x42, 0xfd, 0xc2, 0xbe } };
  156. // The GUID that corresponds to the format used to store the
  157. // NAS Rollback Snapshot Application Info
  158. // {D591D4F0-B920-459d-9FFF-09E032ECBB57}
  159. const GUID VOLSNAP_APPINFO_GUID_NAS_ROLLBACK =
  160. { 0xd591d4f0, 0xb920, 0x459d, { 0x9f, 0xff, 0x9, 0xe0, 0x32, 0xec, 0xbb, 0x57 } };
  161. // The GUID that corresponds to the format used to store the
  162. // APP Rollback Snapshot Application Info
  163. // {AE9A9337-0048-4ed6-9874-71500654B7B3}
  164. const GUID VOLSNAP_APPINFO_GUID_APP_ROLLBACK =
  165. { 0xae9a9337, 0x48, 0x4ed6, { 0x98, 0x74, 0x71, 0x50, 0x6, 0x54, 0xb7, 0xb3 } };
  166. // The GUID that corresponds to the format used to store the
  167. // File Share Backup Snapshot Application Info
  168. // {8F8F4EDD-E056-4690-BB9E-E35D4D41A4C0}
  169. const GUID VOLSNAP_APPINFO_GUID_FILE_SHARE_BACKUP =
  170. { 0x8f8f4edd, 0xe056, 0x4690, { 0xbb, 0x9e, 0xe3, 0x5d, 0x4d, 0x41, 0xa4, 0xc0 } };
  171. // Internal flags
  172. const LONG x_nInternalFlagHidden = 0x00000001;
  173. typedef enum _EVssTestType
  174. {
  175. VSS_TEST_UNKNOWN = 0,
  176. VSS_TEST_NONE,
  177. VSS_TEST_QUERY_SNAPSHOTS,
  178. VSS_TEST_QUERY_SNAPSHOTS_ON_VOLUME,
  179. VSS_TEST_QUERY_VOLUMES,
  180. VSS_TEST_VOLSNAP_QUERY,
  181. VSS_TEST_DELETE_BY_SNAPSHOT_ID,
  182. VSS_TEST_DELETE_BY_SNAPSHOT_SET_ID,
  183. VSS_TEST_CREATE,
  184. VSS_TEST_ADD_DIFF_AREA,
  185. VSS_TEST_REMOVE_DIFF_AREA,
  186. VSS_TEST_CHANGE_DIFF_AREA_MAX_SIZE,
  187. VSS_TEST_QUERY_SUPPORTED_VOLUMES_FOR_DIFF_AREA,
  188. VSS_TEST_QUERY_DIFF_AREAS_FOR_VOLUME,
  189. VSS_TEST_QUERY_DIFF_AREAS_ON_VOLUME,
  190. VSS_TEST_QUERY_DIFF_AREAS_FOR_SNAPSHOT,
  191. VSS_TEST_IS_VOLUME_SNAPSHOTTED_C,
  192. VSS_TEST_SET_SNAPSHOT_PROPERTIES,
  193. VSS_TEST_ACCESS_CONTROL_SD,
  194. VSS_TEST_DIAG_WRITERS,
  195. VSS_TEST_DIAG_WRITERS_LOG,
  196. VSS_TEST_DIAG_WRITERS_CSV,
  197. VSS_TEST_DIAG_WRITERS_ON,
  198. VSS_TEST_DIAG_WRITERS_OFF,
  199. VSS_TEST_LIST_WRITERS,
  200. } EVssTestType;
  201. typedef enum _EVssQWSFlags
  202. {
  203. VSS_QWS_THROW_ON_WRITER_FAILURE = 1,
  204. VSS_QWS_DISPLAY_WRITER_STATUS = 2,
  205. };
  206. ///////////////////////////////////////////////////////////////////////////////
  207. // Main class
  208. class CVssMultilayerTest
  209. {
  210. // Constructors& destructors
  211. private:
  212. CVssMultilayerTest();
  213. CVssMultilayerTest(const CVssMultilayerTest&);
  214. public:
  215. CVssMultilayerTest(
  216. IN INT nArgsCount,
  217. IN WCHAR ** ppwszArgsArray
  218. );
  219. ~CVssMultilayerTest();
  220. // Main routines
  221. public:
  222. // Initialize internal members
  223. void Initialize();
  224. // Run the test
  225. void Run();
  226. // Internal tests
  227. public:
  228. // Queries the snapshots
  229. void QuerySnapshots();
  230. // Queries the snapshots on volume
  231. void QuerySnapshotsByVolume();
  232. // Creates a backup snapshot set
  233. void QuerySupportedVolumes();
  234. // Query using hte IOCTL
  235. void QueryVolsnap();
  236. // Delete by snapshot Id
  237. void DeleteBySnapshotId();
  238. // Delete by snapshot set Id
  239. void DeleteBySnapshotSetId();
  240. // Creates a backup snapshot set
  241. void PreloadExistingSnapshots();
  242. // Creates a timewarp snapshot set
  243. void CreateTimewarpSnapshotSet();
  244. // Creates a backup snapshot set
  245. void CreateBackupSnapshotSet();
  246. // Completes the backup
  247. void BackupComplete();
  248. void GatherWriterMetadata();
  249. void GatherWriterStatus(
  250. IN LPCWSTR wszWhen,
  251. DWORD dwFlags = VSS_QWS_THROW_ON_WRITER_FAILURE
  252. );
  253. // Adds a diff area
  254. void AddDiffArea();
  255. // Removes a diff area
  256. void RemoveDiffArea();
  257. // Change diff area maximum size
  258. void ChangeDiffAreaMaximumSize();
  259. // Query volumes for diff area
  260. void QueryVolumesSupportedForDiffAreas();
  261. // Query volumes for diff area
  262. void QueryDiffAreasForVolume();
  263. // Query volumes on diff area
  264. void QueryDiffAreasOnVolume();
  265. // Query volumes on diff area
  266. void QueryDiffAreasForSnapshot();
  267. // Test if the volume is snapshotted using the "C" API
  268. void IsVolumeSnapshotted_C();
  269. // Test if the volume is snapshotted using the "C" API
  270. void SetSnapshotProperties();
  271. // Test the CVssSidCollection class
  272. void TestAccessControlSD();
  273. // Diagnose writers
  274. void DiagnoseWriters(
  275. IN EVssTestType eType
  276. );
  277. // List writers
  278. void TestListWriters();
  279. // Command line processing
  280. public:
  281. // Parse command line arguments
  282. bool ParseCommandLine();
  283. // Print the usage
  284. bool PrintUsage(bool bThrow = true);
  285. // Returns true if there are tokens left
  286. bool TokensLeft();
  287. // Returns the current token
  288. VSS_PWSZ GetCurrentToken();
  289. // Go to next token
  290. void Shift();
  291. // Check if the current token matches the given argument
  292. bool Peek(
  293. IN VSS_PWSZ pwszPattern
  294. ) throw(HRESULT);
  295. // Match a pattern. If succeeds, shift to the next token.
  296. bool Match(
  297. IN VSS_PWSZ pwszPattern
  298. ) throw(HRESULT);
  299. // Extract a GUID. If succeeds, shift to the next token.
  300. bool Extract(
  301. IN OUT VSS_ID& Guid
  302. ) throw(HRESULT);
  303. // Extract a string. If succeeds, shift to the next token.
  304. bool Extract(
  305. IN OUT VSS_PWSZ& pwsz
  306. ) throw(HRESULT);
  307. // Extract an UINT. If succeeds, shift to the next token.
  308. bool Extract(
  309. IN OUT UINT& uint
  310. ) throw(HRESULT);
  311. // Extract an UINT. If succeeds, shift to the next token.
  312. bool Extract(
  313. IN OUT LONGLONG& llValue
  314. ) throw(HRESULT);
  315. // Private methods:
  316. private:
  317. LPCWSTR GetStringFromFailureType (HRESULT hrStatus);
  318. LPCWSTR GetStringFromWriterState(VSS_WRITER_STATE state);
  319. bool IsVolume( IN VSS_PWSZ pwszVolume );
  320. bool AddVolume( IN VSS_PWSZ pwszVolume, OUT bool & bAdded );
  321. INT RndDecision(IN INT nVariants = 2);
  322. LPWSTR DateTimeToString(
  323. IN LONGLONG llTimestamp
  324. );
  325. void DisplayCurrentTime();
  326. // Implementation
  327. private:
  328. // Global state
  329. bool m_bCoInitializeSucceeded;
  330. bool m_bAttachYourDebuggerNow;
  331. // Command line options
  332. unsigned int m_uSeed;
  333. LONG m_lContext;
  334. EVssTestType m_eTest;
  335. VSS_PWSZ m_pwszVolume;
  336. VSS_PWSZ m_pwszDiffAreaVolume;
  337. VSS_ID m_ProviderId;
  338. LONGLONG m_llMaxDiffArea;
  339. VSS_ID m_SnapshotId;
  340. VSS_ID m_SnapshotSetId;
  341. CComVariant m_value;
  342. UINT m_uPropertyId;
  343. // test-related members
  344. CVssSnapshotSetCollection m_pSnapshotSetCollection;
  345. CVssVolumeMap m_mapVolumes;
  346. CComPtr<IVssCoordinator> m_pTimewarpCoord;
  347. CComPtr<IVssCoordinator> m_pAllCoord;
  348. CComPtr<IVssBackupComponents> m_pBackupComponents;
  349. // Command line
  350. INT m_nCurrentArgsCount;
  351. WCHAR ** m_ppwszCurrentArgsArray;
  352. };
  353. #endif // __ML_HEADER_H__