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.

1164 lines
28 KiB

  1. /*
  2. **++
  3. **
  4. ** Copyright (c) 2000-2001 Microsoft Corporation
  5. **
  6. **
  7. ** Module Name:
  8. **
  9. ** simsnap.cpp
  10. **
  11. **
  12. ** Abstract:
  13. **
  14. ** Test program to drive the VSS Writer Shim contained in VssAPI.DLL
  15. **
  16. **
  17. ** Author:
  18. **
  19. ** Michael C. Johnson [mikejohn] 24-May-2000
  20. **
  21. **
  22. ** Revision History:
  23. **
  24. ** X-5 MCJ Michael C. Johnson 15-Sep-2000
  25. ** Add test for invalid volume array pointer, interleaved calls
  26. ** and so on.
  27. **
  28. ** X-4 MCJ Michael C. Johnson 15-Sep-2000
  29. ** Add test for invalid bits in options parameter of call to
  30. ** SimulateSnapshotFreeze()
  31. **
  32. ** X-3 MCJ Michael C. Johnson 30-Jun-2000
  33. ** Remove calls to RegisterSnapshotSubscriptions() and
  34. ** UnregisterSnapshotSubscriptions() as these are no longer
  35. ** required.
  36. **
  37. ** X-2 MCJ Michael C. Johnson 26-May-2000
  38. ** Add some extra tests to validate shim is properly sensitive
  39. ** to volume name array contents.
  40. **--
  41. */
  42. /*
  43. ** Defines
  44. **
  45. **
  46. ** C4290: C++ Exception Specification ignored
  47. ** warning C4511: 'CVssCOMApplication' : copy constructor could not be generated
  48. ** warning C4127: conditional expression is constant
  49. */
  50. #pragma warning(disable:4290)
  51. #pragma warning(disable:4511)
  52. #pragma warning(disable:4127)
  53. /*
  54. ** Includes
  55. */
  56. #include <windows.h>
  57. #include <wtypes.h>
  58. #include <stddef.h>
  59. #include <stdio.h>
  60. #include <objbase.h>
  61. #include <guiddef.h>
  62. #include "vs_idl.hxx"
  63. #include <vswriter.h>
  64. #include <vsbackup.h>
  65. static BOOL AssertPrivilege (LPCWSTR privName);
  66. static HRESULT DoTest01 (VOID);
  67. static HRESULT DoTest02 (VOID);
  68. static HRESULT DoTest03 (VOID);
  69. static HRESULT DoTest05 (VOID);
  70. static HRESULT DoTest06 (VOID);
  71. static HRESULT DoTest07 (VOID);
  72. static HRESULT DoTest08 (VOID);
  73. static HRESULT DoTest09 (VOID);
  74. static HRESULT DoTest10 (VOID);
  75. static HRESULT DoTest11 (VOID);
  76. static HRESULT DoTest12 (VOID);
  77. static HRESULT DoTest13 (VOID);
  78. static HRESULT DoTest14 (VOID);
  79. extern "C" int __cdecl wmain (int argc, char *argv[])
  80. {
  81. HRESULT hrStatus;
  82. UNREFERENCED_PARAMETER (argv);
  83. UNREFERENCED_PARAMETER (argc);
  84. wprintf (L"Test for SimulateSnapshotXxxx calls (ProcessId 0x%04x)\nChecking privileges\n",
  85. GetCurrentProcessId ());
  86. if (!AssertPrivilege (SE_BACKUP_NAME))
  87. {
  88. wprintf (L"AssertPrivilege returned error 0x%08X\n", GetLastError ());
  89. return 2;
  90. }
  91. wprintf (L"Initializing COM\n");
  92. hrStatus = CoInitializeEx (NULL, COINIT_MULTITHREADED);
  93. if (FAILED (hrStatus))
  94. {
  95. wprintf (L"CoInitialize() returned 0x%08X\n", GetLastError ());
  96. return 1;
  97. }
  98. if ( argc == 1 )
  99. {
  100. hrStatus = DoTest01 ();
  101. hrStatus = DoTest02 ();
  102. hrStatus = DoTest05 ();
  103. hrStatus = DoTest06 ();
  104. hrStatus = DoTest02 ();
  105. hrStatus = DoTest07 ();
  106. hrStatus = DoTest08 ();
  107. hrStatus = DoTest09 ();
  108. hrStatus = DoTest10 ();
  109. hrStatus = DoTest11 ();
  110. hrStatus = DoTest12 ();
  111. hrStatus = DoTest13 ();
  112. hrStatus = DoTest14 ();
  113. }
  114. else
  115. {
  116. hrStatus = DoTest03();
  117. }
  118. CoUninitialize();
  119. return 0;
  120. }
  121. static BOOL AssertPrivilege (LPCWSTR privName)
  122. {
  123. HANDLE tokenHandle;
  124. BOOL stat = FALSE;
  125. if (OpenProcessToken (GetCurrentProcess (), TOKEN_ADJUST_PRIVILEGES, &tokenHandle))
  126. {
  127. LUID value;
  128. if (LookupPrivilegeValue (NULL, privName, &value))
  129. {
  130. TOKEN_PRIVILEGES newState;
  131. DWORD error;
  132. newState.PrivilegeCount = 1;
  133. newState.Privileges[0].Luid = value;
  134. newState.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  135. /*
  136. ** We will always call GetLastError below, so clear
  137. ** any prior error values on this thread.
  138. */
  139. SetLastError (ERROR_SUCCESS);
  140. stat = AdjustTokenPrivileges (tokenHandle,
  141. FALSE,
  142. &newState,
  143. (DWORD)0,
  144. NULL,
  145. NULL);
  146. /*
  147. ** Supposedly, AdjustTokenPriveleges always returns TRUE
  148. ** (even when it fails). So, call GetLastError to be
  149. ** extra sure everything's cool.
  150. */
  151. if ((error = GetLastError()) != ERROR_SUCCESS)
  152. {
  153. stat = FALSE;
  154. }
  155. if (!stat)
  156. {
  157. wprintf (L"AdjustTokenPrivileges for %s failed with 0x%08X",
  158. privName,
  159. error);
  160. }
  161. }
  162. CloseHandle (tokenHandle);
  163. }
  164. return stat;
  165. }
  166. static HRESULT DoTest01 ()
  167. {
  168. HRESULT hrStatus;
  169. LPWSTR pwszVolumeArray [3] = {L"C:\\", L"V:\\", L"E:\\"};
  170. ULONG ulOptionFlags = VSS_SW_BOOTABLE_STATE;
  171. GUID guidSnapshotSetId;
  172. ::CoCreateGuid( &guidSnapshotSetId );
  173. IVssAsync *pIAsync = NULL;
  174. wprintf (L"\n\nTest 1 - Bootable State, Synchronous\n\n");
  175. wprintf (L"Simulating snapshot freeze - should work\n");
  176. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId,
  177. ulOptionFlags,
  178. sizeof (pwszVolumeArray) / sizeof (pwszVolumeArray [0]),
  179. pwszVolumeArray,
  180. &pIAsync);
  181. if (FAILED (hrStatus))
  182. {
  183. wprintf (L"SimulateSnapshotFreeze() returned 0x%08X\n", hrStatus);
  184. }
  185. if ( pIAsync != NULL )
  186. {
  187. HRESULT hrStatusAsync;
  188. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  189. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  190. pIAsync->Wait();
  191. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  192. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  193. pIAsync->Release();
  194. }
  195. wprintf (L"Simulating snapshot thaw\n");
  196. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId);
  197. if (FAILED (hrStatus))
  198. {
  199. wprintf (L"SimulateSnapshotThaw() returned 0x%08X\n", hrStatus);
  200. }
  201. return (hrStatus);
  202. }
  203. static HRESULT DoTest02 ()
  204. {
  205. HRESULT hrStatus;
  206. LPWSTR pwszVolumeArray [3] = {L"C:\\", L"V:\\", L"E:\\"};
  207. ULONG ulOptionFlags = 0;
  208. GUID guidSnapshotSetId;
  209. ::CoCreateGuid( &guidSnapshotSetId );
  210. IVssAsync *pIAsync = NULL;
  211. wprintf (L"\n\nTest 2 - Service State, Synchronous\n\n");
  212. wprintf (L"Simulating snapshot freeze - should work\n");
  213. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId,
  214. ulOptionFlags,
  215. sizeof (pwszVolumeArray) / sizeof (pwszVolumeArray [0]),
  216. pwszVolumeArray,
  217. &pIAsync);
  218. if (FAILED (hrStatus))
  219. {
  220. wprintf (L"SimulateSnapshotFreeze() returned 0x%08X\n", hrStatus);
  221. }
  222. if ( pIAsync != NULL )
  223. {
  224. HRESULT hrStatusAsync;
  225. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  226. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  227. pIAsync->Wait();
  228. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  229. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  230. pIAsync->Release();
  231. }
  232. wprintf (L"Simulating snapshot thaw\n");
  233. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId);
  234. if (FAILED (hrStatus))
  235. {
  236. wprintf (L"SimulateSnapshotThaw() returned 0x%08X\n", hrStatus);
  237. }
  238. return (hrStatus);
  239. }
  240. static HRESULT DoTest03()
  241. {
  242. HRESULT hrStatus;
  243. LPWSTR pwszVolumeArray [3] = {L"C:\\", L"V:\\", L"E:\\"};
  244. ULONG ulOptionFlags = VSS_SW_BOOTABLE_STATE;
  245. GUID guidSnapshotSetId;
  246. ::CoCreateGuid( &guidSnapshotSetId );
  247. IVssAsync *pIAsync = NULL;
  248. wprintf (L"\n\nTest 3 - Bootable State, Asynchronous\n\n");
  249. wprintf (L"Simulating snapshot freeze with Cancel - should work\n");
  250. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId,
  251. ulOptionFlags,
  252. sizeof (pwszVolumeArray) / sizeof (pwszVolumeArray [0]),
  253. pwszVolumeArray,
  254. &pIAsync);
  255. if (FAILED (hrStatus))
  256. {
  257. wprintf (L"SimulateSnapshotFreeze() returned 0x%08X\n", hrStatus);
  258. }
  259. if ( pIAsync != NULL )
  260. {
  261. HRESULT hrStatusAsync;
  262. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  263. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  264. wprintf (L"Waiting 5 seconds and then calling Cancel\n" );
  265. Sleep( 5000 );
  266. wprintf (L"Cancelling\n" );
  267. pIAsync->Cancel();
  268. do {
  269. Sleep( 1000 );
  270. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  271. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  272. } while ( !FAILED( hrStatus ) && hrStatusAsync == VSS_S_ASYNC_PENDING );
  273. pIAsync->Release();
  274. }
  275. #if 0
  276. wprintf (L"Simulating snapshot thaw\n");
  277. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId);
  278. if (FAILED (hrStatus))
  279. {
  280. wprintf (L"SimulateSnapshotThaw() returned 0x%08X\n", hrStatus);
  281. }
  282. #endif
  283. return (hrStatus);
  284. }
  285. static HRESULT DoTest05 ()
  286. {
  287. HRESULT hrStatus;
  288. ULONG ulOptionFlags = VSS_SW_BOOTABLE_STATE;
  289. GUID guidSnapshotSetId;
  290. ::CoCreateGuid( &guidSnapshotSetId );
  291. IVssAsync *pIAsync = NULL;
  292. wprintf (L"\n\nTest 5 - Bootable State, Synchronous, no volumes\n\n");
  293. wprintf (L"Simulating snapshot freeze - should work\n");
  294. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId,
  295. ulOptionFlags,
  296. 0,
  297. NULL,
  298. &pIAsync);
  299. if (FAILED (hrStatus))
  300. {
  301. wprintf (L"SimulateSnapshotFreeze() returned 0x%08X\n", hrStatus);
  302. }
  303. if ( pIAsync != NULL )
  304. {
  305. HRESULT hrStatusAsync;
  306. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  307. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  308. pIAsync->Wait();
  309. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  310. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  311. pIAsync->Release();
  312. }
  313. wprintf (L"Simulating snapshot thaw\n");
  314. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId);
  315. if (FAILED (hrStatus))
  316. {
  317. wprintf (L"SimulateSnapshotThaw() returned 0x%08X\n", hrStatus);
  318. }
  319. return (hrStatus);
  320. }
  321. static HRESULT DoTest06 ()
  322. {
  323. HRESULT hrStatus;
  324. ULONG ulOptionFlags = 0;
  325. GUID guidSnapshotSetId;
  326. IVssAsync *pIAsync = NULL;
  327. ::CoCreateGuid( &guidSnapshotSetId );
  328. wprintf (L"\n\nTest 6 - Service State, Synchronous, no volumes\n\n");
  329. wprintf (L"Simulating snapshot freeze - should NOT work\n");
  330. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId,
  331. ulOptionFlags,
  332. 0,
  333. NULL,
  334. &pIAsync);
  335. if (FAILED (hrStatus))
  336. {
  337. wprintf (L"SimulateSnapshotFreeze() returned 0x%08X\n", hrStatus);
  338. }
  339. if ( pIAsync != NULL )
  340. {
  341. HRESULT hrStatusAsync;
  342. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  343. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  344. pIAsync->Wait();
  345. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  346. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  347. pIAsync->Release();
  348. }
  349. wprintf (L"Simulating snapshot thaw\n");
  350. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId);
  351. if (FAILED (hrStatus))
  352. {
  353. wprintf (L"SimulateSnapshotThaw() returned 0x%08X\n", hrStatus);
  354. }
  355. return (hrStatus);
  356. }
  357. static HRESULT DoTest07 ()
  358. {
  359. HRESULT hrStatus;
  360. LPWSTR pwszVolumeArray [3] = {L"C:\\", L"V:\\", L"E:\\"};
  361. ULONG ulOptionFlags = 0x40 | VSS_SW_BOOTABLE_STATE;
  362. GUID guidSnapshotSetId;
  363. IVssAsync *pIAsync = NULL;
  364. ::CoCreateGuid( &guidSnapshotSetId );
  365. wprintf (L"\n\nTest 7 - Bootable State, Synchronous, Extra Options set\n\n");
  366. wprintf (L"Simulating snapshot freeze - should NOT work\n");
  367. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId,
  368. ulOptionFlags,
  369. sizeof (pwszVolumeArray) / sizeof (pwszVolumeArray [0]),
  370. pwszVolumeArray,
  371. &pIAsync);
  372. if (FAILED (hrStatus))
  373. {
  374. wprintf (L"SimulateSnapshotFreeze() returned 0x%08X\n", hrStatus);
  375. }
  376. if ( pIAsync != NULL )
  377. {
  378. HRESULT hrStatusAsync;
  379. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  380. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  381. pIAsync->Wait();
  382. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  383. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  384. pIAsync->Release();
  385. }
  386. wprintf (L"Simulating snapshot thaw\n");
  387. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId);
  388. if (FAILED (hrStatus))
  389. {
  390. wprintf (L"SimulateSnapshotThaw() returned 0x%08X\n", hrStatus);
  391. }
  392. return (hrStatus);
  393. }
  394. static HRESULT DoTest08 ()
  395. {
  396. HRESULT hrStatus;
  397. LPWSTR pwszVolumeArray [3] = {L"C:\\", L"V:\\", L"E:\\"};
  398. ULONG ulOptionFlags = 0x40;
  399. GUID guidSnapshotSetId;
  400. IVssAsync *pIAsync = NULL;
  401. ::CoCreateGuid( &guidSnapshotSetId );
  402. wprintf (L"\n\nTest 8 - Service State, Synchronous, Extra Options set\n\n");
  403. wprintf (L"Simulating snapshot freeze - should NOT work\n");
  404. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId,
  405. ulOptionFlags,
  406. sizeof (pwszVolumeArray) / sizeof (pwszVolumeArray [0]),
  407. pwszVolumeArray,
  408. &pIAsync);
  409. if (FAILED (hrStatus))
  410. {
  411. wprintf (L"SimulateSnapshotFreeze() returned 0x%08X\n", hrStatus);
  412. }
  413. if ( pIAsync != NULL )
  414. {
  415. HRESULT hrStatusAsync;
  416. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  417. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  418. pIAsync->Wait();
  419. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  420. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  421. pIAsync->Release();
  422. }
  423. wprintf (L"Simulating snapshot thaw\n");
  424. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId);
  425. if (FAILED (hrStatus))
  426. {
  427. wprintf (L"SimulateSnapshotThaw() returned 0x%08X\n", hrStatus);
  428. }
  429. return (hrStatus);
  430. }
  431. static HRESULT DoTest09 ()
  432. {
  433. HRESULT hrStatus;
  434. ULONG ulOptionFlags = 0x0 | VSS_SW_BOOTABLE_STATE;
  435. GUID guidSnapshotSetId;
  436. IVssAsync *pIAsync = NULL;
  437. ::CoCreateGuid( &guidSnapshotSetId );
  438. wprintf (L"\n\nTest 9 - Bootable State, Synchronous, No volume list\n\n");
  439. wprintf (L"Simulating snapshot freeze - should work\n");
  440. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId,
  441. ulOptionFlags,
  442. 0,
  443. NULL,
  444. &pIAsync);
  445. if (FAILED (hrStatus))
  446. {
  447. wprintf (L"SimulateSnapshotFreeze() returned 0x%08X\n", hrStatus);
  448. }
  449. if ( pIAsync != NULL )
  450. {
  451. HRESULT hrStatusAsync;
  452. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  453. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  454. pIAsync->Wait();
  455. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  456. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  457. pIAsync->Release();
  458. }
  459. wprintf (L"Simulating snapshot thaw\n");
  460. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId);
  461. if (FAILED (hrStatus))
  462. {
  463. wprintf (L"SimulateSnapshotThaw() returned 0x%08X\n", hrStatus);
  464. }
  465. return (hrStatus);
  466. }
  467. static HRESULT DoTest10 ()
  468. {
  469. HRESULT hrStatus;
  470. ULONG ulOptionFlags = 0x0;
  471. GUID guidSnapshotSetId;
  472. IVssAsync *pIAsync = NULL;
  473. ::CoCreateGuid( &guidSnapshotSetId );
  474. wprintf (L"\n\nTest 10 - Service State, Synchronous, No volume list\n\n");
  475. wprintf (L"Simulating snapshot freeze - should NOT work\n");
  476. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId,
  477. ulOptionFlags,
  478. 0,
  479. NULL,
  480. &pIAsync);
  481. if (FAILED (hrStatus))
  482. {
  483. wprintf (L"SimulateSnapshotFreeze() returned 0x%08X\n", hrStatus);
  484. }
  485. if ( pIAsync != NULL )
  486. {
  487. HRESULT hrStatusAsync;
  488. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  489. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  490. pIAsync->Wait();
  491. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  492. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  493. pIAsync->Release();
  494. }
  495. wprintf (L"Simulating snapshot thaw\n");
  496. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId);
  497. if (FAILED (hrStatus))
  498. {
  499. wprintf (L"SimulateSnapshotThaw() returned 0x%08X\n", hrStatus);
  500. }
  501. return (hrStatus);
  502. }
  503. static HRESULT DoTest11 ()
  504. {
  505. HRESULT hrStatus;
  506. ULONG ulOptionFlags = 0x0;
  507. GUID guidSnapshotSetId;
  508. IVssAsync *pIAsync = NULL;
  509. ::CoCreateGuid( &guidSnapshotSetId );
  510. wprintf (L"\n\nTest 11 - Service State, Synchronous, One volume with bad volume list pointer\n\n");
  511. wprintf (L"Simulating snapshot freeze - should NOT work\n");
  512. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId,
  513. ulOptionFlags,
  514. 01,
  515. NULL,
  516. &pIAsync);
  517. if (FAILED (hrStatus))
  518. {
  519. wprintf (L"SimulateSnapshotFreeze() returned 0x%08X\n", hrStatus);
  520. }
  521. if ( pIAsync != NULL )
  522. {
  523. HRESULT hrStatusAsync;
  524. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  525. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  526. pIAsync->Wait();
  527. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  528. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  529. pIAsync->Release();
  530. }
  531. wprintf (L"Simulating snapshot thaw\n");
  532. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId);
  533. if (FAILED (hrStatus))
  534. {
  535. wprintf (L"SimulateSnapshotThaw() returned 0x%08X\n", hrStatus);
  536. }
  537. return (hrStatus);
  538. }
  539. static HRESULT DoTest12 ()
  540. {
  541. HRESULT hrStatus;
  542. LPWSTR pwszVolumeArray [3] = {L"C:\\", L"V:\\", L"E:\\"};
  543. ULONG ulOptionFlags = 0x0;
  544. GUID guidSnapshotSetId1;
  545. GUID guidSnapshotSetId2;
  546. IVssAsync *pIAsync = NULL;
  547. ::CoCreateGuid( &guidSnapshotSetId1 );
  548. ::CoCreateGuid( &guidSnapshotSetId2 );
  549. wprintf (L"\n\nTest 12 - Service State, Synchronous, nested call\n\n");
  550. wprintf (L"Simulating snapshot freeze (GUID1)\n");
  551. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId1,
  552. ulOptionFlags,
  553. sizeof (pwszVolumeArray) / sizeof (pwszVolumeArray [0]),
  554. pwszVolumeArray,
  555. &pIAsync);
  556. if (FAILED (hrStatus))
  557. {
  558. wprintf (L"SimulateSnapshotFreeze(GUID1) returned 0x%08X\n", hrStatus);
  559. }
  560. if ( pIAsync != NULL )
  561. {
  562. HRESULT hrStatusAsync;
  563. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  564. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  565. pIAsync->Wait();
  566. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  567. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  568. pIAsync->Release();
  569. }
  570. IVssAsync *pIAsync2 = NULL;
  571. wprintf (L"Simulating snapshot freeze (GUID2) - should NOT work\n");
  572. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId2,
  573. ulOptionFlags,
  574. sizeof (pwszVolumeArray) / sizeof (pwszVolumeArray [0]),
  575. pwszVolumeArray,
  576. &pIAsync2);
  577. if (FAILED (hrStatus))
  578. {
  579. wprintf (L"SimulateSnapshotFreeze(GUID2) returned 0x%08X\n", hrStatus);
  580. }
  581. if ( pIAsync2 != NULL )
  582. {
  583. HRESULT hrStatusAsync;
  584. hrStatus = pIAsync2->QueryStatus( &hrStatusAsync, 0 );
  585. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  586. pIAsync2->Wait();
  587. hrStatus = pIAsync2->QueryStatus( &hrStatusAsync, 0 );
  588. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  589. pIAsync2->Release();
  590. }
  591. wprintf (L"Simulating snapshot thaw (GUID2)\n");
  592. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId2);
  593. if (FAILED (hrStatus))
  594. {
  595. wprintf (L"SimulateSnapshotThaw(GUID2) returned 0x%08X\n", hrStatus);
  596. }
  597. wprintf (L"Simulating snapshot thaw (GUID1)\n");
  598. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId1);
  599. if (FAILED (hrStatus))
  600. {
  601. wprintf (L"SimulateSnapshotThaw(GUID1) returned 0x%08X\n", hrStatus);
  602. }
  603. return (hrStatus);
  604. }
  605. static HRESULT DoTest13 ()
  606. {
  607. HRESULT hrStatus;
  608. LPWSTR pwszVolumeArray [3] = {L"C:\\", L"V:\\", L"E:\\"};
  609. ULONG ulOptionFlags = 0x0;
  610. GUID guidSnapshotSetId1;
  611. GUID guidSnapshotSetId2;
  612. IVssAsync *pIAsync = NULL;
  613. ::CoCreateGuid( &guidSnapshotSetId1 );
  614. ::CoCreateGuid( &guidSnapshotSetId2 );
  615. wprintf (L"\n\nTest 13 - Service State, Synchronous, nested call (reverse thaw)\n\n");
  616. wprintf (L"Simulating snapshot freeze (GUID1)\n");
  617. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId1,
  618. ulOptionFlags,
  619. sizeof (pwszVolumeArray) / sizeof (pwszVolumeArray [0]),
  620. pwszVolumeArray,
  621. &pIAsync);
  622. if (FAILED (hrStatus))
  623. {
  624. wprintf (L"SimulateSnapshotFreeze(GUID1) returned 0x%08X\n", hrStatus);
  625. }
  626. if ( pIAsync != NULL )
  627. {
  628. HRESULT hrStatusAsync;
  629. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  630. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  631. pIAsync->Wait();
  632. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  633. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  634. pIAsync->Release();
  635. }
  636. IVssAsync *pIAsync2 = NULL;
  637. wprintf (L"Simulating snapshot freeze (GUID2)\n");
  638. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId2,
  639. ulOptionFlags,
  640. sizeof (pwszVolumeArray) / sizeof (pwszVolumeArray [0]),
  641. pwszVolumeArray,
  642. &pIAsync2);
  643. if (FAILED (hrStatus))
  644. {
  645. wprintf (L"SimulateSnapshotFreeze(GUID2) returned 0x%08X\n", hrStatus);
  646. }
  647. if ( pIAsync2 != NULL )
  648. {
  649. HRESULT hrStatusAsync;
  650. hrStatus = pIAsync2->QueryStatus( &hrStatusAsync, 0 );
  651. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  652. pIAsync2->Wait();
  653. hrStatus = pIAsync2->QueryStatus( &hrStatusAsync, 0 );
  654. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  655. pIAsync2->Release();
  656. }
  657. wprintf (L"Simulating snapshot thaw (GUID1)\n");
  658. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId1);
  659. if (FAILED (hrStatus))
  660. {
  661. wprintf (L"SimulateSnapshotThaw(GUID1) returned 0x%08X\n", hrStatus);
  662. }
  663. wprintf (L"Simulating snapshot thaw (GUID2)\n");
  664. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId2);
  665. if (FAILED (hrStatus))
  666. {
  667. wprintf (L"SimulateSnapshotThaw(GUID2) returned 0x%08X\n", hrStatus);
  668. }
  669. return (hrStatus);
  670. }
  671. static HRESULT DoTest14 ()
  672. {
  673. HRESULT hrStatus = NOERROR;
  674. HRESULT hrStatusAsync = NOERROR;
  675. IVssBackupComponents *pIVssBackupComponents = NULL;
  676. VSS_ID SnapshotId = GUID_NULL;
  677. IVssAsync *pIVssAsync = NULL;
  678. GUID guidSnapshotSetId = GUID_NULL;
  679. GUID guidSnapshotSetId2;
  680. ::CoCreateGuid( &guidSnapshotSetId2 );
  681. wprintf (L"\n\nTest 14 - Bootable State, Synchronous, during DoSnapshot\n\n");
  682. wprintf (L"Calling CreateVssBackupComponents ()\n");
  683. hrStatus = CreateVssBackupComponents (&pIVssBackupComponents);
  684. if (FAILED (hrStatus))
  685. {
  686. wprintf (L"CreateVssBackupComponents () returned 0x%08X\n", hrStatus);
  687. }
  688. wprintf (L"Calling InitializeForBackup ()\n");
  689. hrStatus = pIVssBackupComponents->InitializeForBackup ();
  690. if (FAILED (hrStatus))
  691. {
  692. wprintf (L"InitializeForBackup () returned 0x%08X\n", hrStatus);
  693. }
  694. wprintf (L"Calling SetBackupState ()\n");
  695. hrStatus = pIVssBackupComponents->SetBackupState (true, true, VSS_BT_FULL);
  696. if (FAILED (hrStatus))
  697. {
  698. wprintf (L"SetBackupState () returned 0x%08X\n", hrStatus);
  699. }
  700. wprintf (L"Calling GatherWriterMetadata ()\n");
  701. hrStatus = pIVssBackupComponents->GatherWriterMetadata (&pIVssAsync);
  702. if (FAILED (hrStatus))
  703. {
  704. wprintf (L"GatherWriterMetadata () returned 0x%08X\n", hrStatus);
  705. }
  706. wprintf (L"Calling Wait () (for GatherWriterMetadata() to complete)\n");
  707. hrStatus = pIVssAsync->Wait ();
  708. if (FAILED (hrStatus))
  709. {
  710. wprintf (L"Wait () returned 0x%08X\n", hrStatus);
  711. }
  712. wprintf (L"Calling StartSnapshotSet ()\n");
  713. hrStatus = pIVssBackupComponents->StartSnapshotSet (&guidSnapshotSetId);
  714. if (FAILED (hrStatus))
  715. {
  716. wprintf (L"StartSnapshotSet () returned 0x%08X\n", hrStatus);
  717. }
  718. wprintf (L"Calling AddToSnapshotSet ()\n");
  719. hrStatus = pIVssBackupComponents->AddToSnapshotSet (L"E:\\",
  720. GUID_NULL,
  721. &SnapshotId);
  722. if (FAILED (hrStatus))
  723. {
  724. wprintf (L"AddToSnapshotSet () returned 0x%08X\n", hrStatus);
  725. }
  726. wprintf (L"Calling PrepareForBackup ()\n");
  727. hrStatus = pIVssBackupComponents->PrepareForBackup (&pIVssAsync);
  728. if (FAILED (hrStatus))
  729. {
  730. wprintf (L"PrepareForBackup () returned 0x%08X\n", hrStatus);
  731. }
  732. wprintf (L"Calling Wait () (for PrepareForBackup() to complete)\n");
  733. hrStatus = pIVssAsync->Wait ();
  734. if (FAILED (hrStatus))
  735. {
  736. wprintf (L"Wait () returned 0x%08X\n", hrStatus);
  737. }
  738. wprintf (L"Calling QueryStatus ()\n");
  739. hrStatus = pIVssAsync->QueryStatus (&hrStatusAsync, 0);
  740. if (FAILED (hrStatus))
  741. {
  742. wprintf (L"QueryStatus () returned 0x%08X\n", hrStatus);
  743. }
  744. wprintf (L"Calling DoSnapshotSet ()\n");
  745. hrStatus = pIVssBackupComponents->DoSnapshotSet (&pIVssAsync);
  746. if (FAILED (hrStatus))
  747. {
  748. wprintf (L"DoSnapshotSet () returned 0x%08X\n", hrStatus);
  749. }
  750. wprintf (L"Calling SimulateSnapshotFreeze () - should NOT work\n");
  751. IVssAsync *pIAsync = NULL;
  752. hrStatus = SimulateSnapshotFreeze (guidSnapshotSetId2,
  753. VSS_SW_BOOTABLE_STATE,
  754. 0,
  755. NULL,
  756. &pIAsync);
  757. if (FAILED (hrStatus))
  758. {
  759. wprintf (L"SimulateSnapshotFreeze () returned 0x%08X\n", hrStatus);
  760. }
  761. if ( pIAsync != NULL )
  762. {
  763. HRESULT hrStatusAsync;
  764. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  765. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  766. pIAsync->Wait();
  767. hrStatus = pIAsync->QueryStatus( &hrStatusAsync, 0 );
  768. wprintf (L"QueryStatus () returned: 0x%08X, hrStatusAsync: 0x%08x\n", hrStatus, hrStatusAsync);
  769. pIAsync->Release();
  770. }
  771. wprintf (L"Calling SimulateSnapshotThaw ()\n");
  772. hrStatus = SimulateSnapshotThaw (guidSnapshotSetId2);
  773. if (FAILED (hrStatus))
  774. {
  775. wprintf (L"SimulateSnapshotThaw () returned 0x%08X\n", hrStatus);
  776. }
  777. wprintf (L"Calling Wait () (for DoSnapshotSet () to complete) ()\n");
  778. hrStatus = pIVssAsync->Wait();
  779. if (FAILED (hrStatus))
  780. {
  781. wprintf (L"Wait () returned 0x%08X\n", hrStatus);
  782. }
  783. pIVssAsync->Release();
  784. pIVssBackupComponents->Release();
  785. return (hrStatus);
  786. }