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.

706 lines
20 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Abstract:
  4. @doc
  5. @module Pointer.cxx | Implementation of VSS_OBJECT_PROP_Ptr class
  6. @end
  7. Author:
  8. Adi Oltean [aoltean] 09/21/1999
  9. Revision History:
  10. Name Date Comments
  11. aoltean 09/21/1999 VSS_OBJECT_PROP_Ptr as a pointer to the properties structure.
  12. This pointer will serve as element in CSimpleArray constructs.
  13. aoltean 09/22/1999 Adding InitializeAsEmpty and Print
  14. aoltean 09/24/1999 Moving into modules/prop
  15. aoltean 03/27/2000 Adding Writers
  16. aoltean 03/01/2001 Adding mgmt objects
  17. --*/
  18. /////////////////////////////////////////////////////////////////////////////
  19. // Needed includes
  20. #include "stdafx.hxx"
  21. #include "vs_idl.hxx"
  22. #include "vs_inc.hxx"
  23. #include "copy.hxx"
  24. #include "pointer.hxx"
  25. ////////////////////////////////////////////////////////////////////////
  26. // Standard foo for file name aliasing. This code block must be after
  27. // all includes of VSS header files.
  28. //
  29. #ifdef VSS_FILE_ALIAS
  30. #undef VSS_FILE_ALIAS
  31. #endif
  32. #define VSS_FILE_ALIAS "PRPPNTRC"
  33. //
  34. ////////////////////////////////////////////////////////////////////////
  35. /////////////////////////////////////////////////////////////////////////////
  36. // VSS_OBJECT_PROP_Ptr class
  37. void VSS_OBJECT_PROP_Ptr::InitializeAsSnapshot(
  38. IN CVssFunctionTracer& ft,
  39. IN VSS_ID SnapshotId,
  40. IN VSS_ID SnapshotSetId,
  41. IN LONG lSnapshotsCount,
  42. IN VSS_PWSZ pwszSnapshotDeviceObject,
  43. IN VSS_PWSZ pwszOriginalVolumeName,
  44. IN VSS_PWSZ pwszOriginatingMachine,
  45. IN VSS_PWSZ pwszServiceMachine,
  46. IN VSS_PWSZ pwszExposedName,
  47. IN VSS_PWSZ pwszExposedPath,
  48. IN VSS_ID ProviderId,
  49. IN LONG lSnapshotAttributes,
  50. IN VSS_TIMESTAMP tsCreationTimestamp,
  51. IN VSS_SNAPSHOT_STATE eStatus
  52. ) throw (HRESULT)
  53. /*++
  54. Routine description:
  55. Initialize a VSS_OBJECT_PROP_Ptr in order to keep a VSS_OBJECT_SNAPSHOT structure.
  56. Throws:
  57. E_OUTOFMEMORY
  58. --*/
  59. {
  60. WCHAR wszFunctionName[] = L"VSS_OBJECT_PROP_Ptr::InitializeAsSnapshot";
  61. VSS_OBJECT_PROP* pProp = NULL;
  62. try
  63. {
  64. // Assert the structure pointer to be set
  65. BS_ASSERT(m_pStruct == NULL);
  66. // Allocate the VSS_OBJECT_UNION structure
  67. pProp = static_cast<VSS_OBJECT_PROP*>(::CoTaskMemAlloc(sizeof(VSS_OBJECT_PROP)));
  68. if (pProp == NULL)
  69. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  70. L"%s: Error on allocating the Properties structure",
  71. wszFunctionName );
  72. // Initialize the structure
  73. VSS_OBJECT_PROP_Copy::init(pProp);
  74. pProp->Type = VSS_OBJECT_SNAPSHOT;
  75. // Getting the equivalent VSS_SNAPSHOT_PROP structure
  76. BS_ASSERT(pProp);
  77. VSS_SNAPSHOT_PROP& SnapshotProp = pProp->Obj.Snap;
  78. // Setting the internal members
  79. SnapshotProp.m_SnapshotId = SnapshotId;
  80. SnapshotProp.m_SnapshotSetId = SnapshotSetId;
  81. SnapshotProp.m_lSnapshotsCount = lSnapshotsCount;
  82. ::VssSafeDuplicateStr(ft, SnapshotProp.m_pwszSnapshotDeviceObject, pwszSnapshotDeviceObject);
  83. ::VssSafeDuplicateStr(ft, SnapshotProp.m_pwszOriginalVolumeName, pwszOriginalVolumeName);
  84. ::VssSafeDuplicateStr(ft, SnapshotProp.m_pwszOriginatingMachine, pwszOriginatingMachine);
  85. ::VssSafeDuplicateStr(ft, SnapshotProp.m_pwszServiceMachine, pwszServiceMachine);
  86. ::VssSafeDuplicateStr(ft, SnapshotProp.m_pwszExposedName, pwszExposedName);
  87. ::VssSafeDuplicateStr(ft, SnapshotProp.m_pwszExposedPath, pwszExposedPath);
  88. SnapshotProp.m_ProviderId = ProviderId;
  89. SnapshotProp.m_lSnapshotAttributes = lSnapshotAttributes;
  90. SnapshotProp.m_tsCreationTimestamp = tsCreationTimestamp;
  91. SnapshotProp.m_eStatus = eStatus;
  92. // Setting the pointer field
  93. m_pStruct = pProp;
  94. }
  95. VSS_STANDARD_CATCH(ft)
  96. if (ft.HrFailed())
  97. {
  98. BS_ASSERT(ft.hr == E_OUTOFMEMORY);
  99. BS_ASSERT(m_pStruct == NULL);
  100. if (pProp)
  101. {
  102. VSS_OBJECT_PROP_Copy::destroy(pProp); // destroy its contents.
  103. ::CoTaskMemFree(static_cast<LPVOID>(pProp));
  104. }
  105. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  106. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  107. }
  108. }
  109. void VSS_OBJECT_PROP_Ptr::InitializeAsProvider(
  110. IN CVssFunctionTracer& ft,
  111. IN VSS_ID ProviderId,
  112. IN VSS_PWSZ pwszProviderName,
  113. IN VSS_PROVIDER_TYPE eProviderType,
  114. IN VSS_PWSZ pwszProviderVersion,
  115. IN VSS_ID ProviderVersionId,
  116. IN CLSID ClassId
  117. ) throw (HRESULT)
  118. /*++
  119. Routine description:
  120. Initialize a VSS_OBJECT_PROP_Ptr in order to keep a VSS_OBJECT_PROVIDER structure.
  121. Throws:
  122. E_OUTOFMEMORY
  123. --*/
  124. {
  125. WCHAR wszFunctionName[] = L"VSS_OBJECT_PROP_Ptr::InitializeAsProvider";
  126. VSS_OBJECT_PROP* pProp = NULL;
  127. // Reset the error code
  128. ft.hr = S_OK;
  129. try
  130. {
  131. // Assert parameters
  132. BS_ASSERT(pwszProviderName == NULL || pwszProviderName[0] != L'\0');
  133. BS_ASSERT(eProviderType == VSS_PROV_SYSTEM ||
  134. eProviderType == VSS_PROV_SOFTWARE ||
  135. eProviderType == VSS_PROV_HARDWARE
  136. );
  137. // Assert the structure pointer to be set
  138. BS_ASSERT(m_pStruct == NULL);
  139. // Allocate the VSS_OBJECT_UNION structure
  140. pProp = static_cast<VSS_OBJECT_PROP*>(::CoTaskMemAlloc(sizeof(VSS_OBJECT_PROP)));
  141. if (pProp == NULL)
  142. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  143. L"%s: Error on allocating the Properties structure",
  144. wszFunctionName );
  145. // Initialize the structure
  146. VSS_OBJECT_PROP_Copy::init(pProp);
  147. pProp->Type = VSS_OBJECT_PROVIDER;
  148. // Getting the equivalent VSS_SNAPSHOT_PROP structure
  149. BS_ASSERT(pProp);
  150. VSS_PROVIDER_PROP& ProviderProp = pProp->Obj.Prov;
  151. // Setting the internal members
  152. ProviderProp.m_ProviderId = ProviderId;
  153. ::VssSafeDuplicateStr(ft, ProviderProp.m_pwszProviderName, pwszProviderName);
  154. ProviderProp.m_eProviderType = eProviderType;
  155. ::VssSafeDuplicateStr(ft, ProviderProp.m_pwszProviderVersion, pwszProviderVersion);
  156. ProviderProp.m_ProviderVersionId = ProviderVersionId;
  157. ProviderProp.m_ClassId = ClassId;
  158. // Setting the pointer field
  159. m_pStruct = pProp;
  160. }
  161. VSS_STANDARD_CATCH(ft)
  162. if (ft.HrFailed())
  163. {
  164. BS_ASSERT(ft.hr == E_OUTOFMEMORY);
  165. BS_ASSERT(m_pStruct == NULL);
  166. if (pProp)
  167. {
  168. VSS_OBJECT_PROP_Copy::destroy(pProp); // destroy its contents.
  169. ::CoTaskMemFree(static_cast<LPVOID>(pProp));
  170. }
  171. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  172. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  173. }
  174. }
  175. void VSS_OBJECT_PROP_Ptr::InitializeAsEmpty(
  176. IN CVssFunctionTracer& ft
  177. )
  178. /*++
  179. Routine description:
  180. Initialize a VSS_OBJECT_PROP_Ptr in order to appear as an empty structure (to be filled later).
  181. Throws:
  182. E_OUTOFMEMORY
  183. --*/
  184. {
  185. WCHAR wszFunctionName[] = L"VSS_OBJECT_PROP_Ptr::InitializeEmpty";
  186. VSS_OBJECT_PROP* pProp = NULL;
  187. // Reset the error code
  188. ft.hr = S_OK;
  189. try
  190. {
  191. // Assert the structure pointer to be set
  192. BS_ASSERT(m_pStruct == NULL);
  193. // Allocate the VSS_OBJECT_UNION structure
  194. pProp = static_cast<VSS_OBJECT_PROP*>(::CoTaskMemAlloc(sizeof(VSS_OBJECT_PROP)));
  195. if (pProp == NULL)
  196. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  197. L"%s: Error on allocating the Properties structure",
  198. wszFunctionName );
  199. // Initialize the structure
  200. VSS_OBJECT_PROP_Copy::init(pProp);
  201. // Setting the pointer field
  202. m_pStruct = pProp;
  203. }
  204. VSS_STANDARD_CATCH(ft)
  205. if (ft.HrFailed())
  206. {
  207. BS_ASSERT(ft.hr == E_OUTOFMEMORY);
  208. BS_ASSERT(m_pStruct == NULL);
  209. BS_ASSERT(pProp == NULL);
  210. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  211. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  212. }
  213. }
  214. void VSS_OBJECT_PROP_Ptr::Print(
  215. IN CVssFunctionTracer& ft,
  216. IN LPWSTR wszOutputBuffer,
  217. IN LONG lBufferSize
  218. )
  219. {
  220. WCHAR wszFunctionName[] = L"VSS_OBJECT_PROP_Ptr::Print";
  221. // Reset the error code
  222. ft.hr = S_OK;
  223. try
  224. {
  225. if (m_pStruct == NULL)
  226. ::StringCchPrintfW(wszOutputBuffer, lBufferSize, L"NULL object\n\n");
  227. // Effective copy
  228. switch(m_pStruct->Type)
  229. {
  230. case VSS_OBJECT_SNAPSHOT:
  231. ::StringCchPrintfW(wszOutputBuffer, lBufferSize,
  232. L"Id = " WSTR_GUID_FMT L", "
  233. L"SnapshotSetId = " WSTR_GUID_FMT L"\n"
  234. L"SnapCount = %ld "
  235. L"DevObj = %s\n"
  236. L"OriginalVolumeName = %s\n"
  237. L"OriginatingMachine = %s\n"
  238. L"ServiceMachine = %s\n"
  239. L"Exposed name = %s\n"
  240. L"Exposed path = %s\n"
  241. L"ProviderId = " WSTR_GUID_FMT L"\n"
  242. L"Attributes = 0x%08lx\n"
  243. L"Timestamp = " WSTR_LONGLONG_FMT L"\n"
  244. L"Status = %d\n ",
  245. GUID_PRINTF_ARG( m_pStruct->Obj.Snap.m_SnapshotId ),
  246. GUID_PRINTF_ARG( m_pStruct->Obj.Snap.m_SnapshotSetId ),
  247. m_pStruct->Obj.Snap.m_lSnapshotsCount,
  248. m_pStruct->Obj.Snap.m_pwszSnapshotDeviceObject,
  249. m_pStruct->Obj.Snap.m_pwszOriginalVolumeName,
  250. m_pStruct->Obj.Snap.m_pwszOriginatingMachine,
  251. m_pStruct->Obj.Snap.m_pwszServiceMachine,
  252. m_pStruct->Obj.Snap.m_pwszExposedName,
  253. m_pStruct->Obj.Snap.m_pwszExposedPath,
  254. GUID_PRINTF_ARG( m_pStruct->Obj.Snap.m_ProviderId ),
  255. m_pStruct->Obj.Snap.m_lSnapshotAttributes,
  256. LONGLONG_PRINTF_ARG( m_pStruct->Obj.Snap.m_tsCreationTimestamp ),
  257. m_pStruct->Obj.Snap.m_eStatus);
  258. break;
  259. case VSS_OBJECT_PROVIDER:
  260. ::StringCchPrintfW(wszOutputBuffer, lBufferSize,
  261. L"m_ProviderId = " WSTR_GUID_FMT L"\n"
  262. L"m_pwszProviderName = %s\n"
  263. L"m_ProviderType = %d\n"
  264. L"m_pwszProviderVersion = %s\n"
  265. L"m_ProviderVersionId = " WSTR_GUID_FMT L"\n"
  266. L"m_ClassID: " WSTR_GUID_FMT L"\n\n",
  267. GUID_PRINTF_ARG( m_pStruct->Obj.Prov.m_ProviderId ),
  268. m_pStruct->Obj.Prov.m_pwszProviderName? m_pStruct->Obj.Prov.m_pwszProviderName: L"NULL",
  269. m_pStruct->Obj.Prov.m_eProviderType,
  270. m_pStruct->Obj.Prov.m_pwszProviderVersion? m_pStruct->Obj.Prov.m_pwszProviderVersion: L"NULL",
  271. GUID_PRINTF_ARG( m_pStruct->Obj.Prov.m_ProviderVersionId ),
  272. GUID_PRINTF_ARG( m_pStruct->Obj.Prov.m_ClassId )
  273. );
  274. break;
  275. default:
  276. ft.ErrBox( VSSDBG_GEN, E_UNEXPECTED,
  277. L"%s: Wrong object type %d", wszFunctionName, m_pStruct->Type );
  278. break;
  279. }
  280. }
  281. VSS_STANDARD_CATCH(ft)
  282. if (ft.HrFailed())
  283. {
  284. BS_ASSERT(m_pStruct == NULL);
  285. ft.Throw( VSSDBG_GEN, E_UNEXPECTED,
  286. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  287. }
  288. }
  289. /////////////////////////////////////////////////////////////////////////////
  290. // VSS_MGMT_OBJECT_PROP_Ptr class
  291. void VSS_MGMT_OBJECT_PROP_Ptr::InitializeAsVolume(
  292. IN CVssFunctionTracer& ft,
  293. IN VSS_PWSZ pwszVolumeName,
  294. IN VSS_PWSZ pwszVolumeDisplayName
  295. ) throw (HRESULT)
  296. /*++
  297. Routine description:
  298. Initialize a VSS_MGMT_OBJECT_PROP_Ptr in order to keep a VSS_MGMT_OBJECT_SNAPSHOT structure.
  299. Throws:
  300. E_OUTOFMEMORY
  301. --*/
  302. {
  303. WCHAR wszFunctionName[] = L"VSS_MGMT_OBJECT_PROP_Ptr::InitializeAsVolume";
  304. VSS_MGMT_OBJECT_PROP* pProp = NULL;
  305. try
  306. {
  307. // Assert the structure pointer to be set
  308. BS_ASSERT(m_pStruct == NULL);
  309. // Allocate the VSS_MGMT_OBJECT_UNION structure
  310. pProp = static_cast<VSS_MGMT_OBJECT_PROP*>(::CoTaskMemAlloc(sizeof(VSS_MGMT_OBJECT_PROP)));
  311. if (pProp == NULL)
  312. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  313. L"%s: Error on allocating the Properties structure",
  314. wszFunctionName );
  315. // Initialize the structure
  316. VSS_MGMT_OBJECT_PROP_Copy::init(pProp);
  317. pProp->Type = VSS_MGMT_OBJECT_VOLUME;
  318. // Getting the equivalent VSS_SNAPSHOT_PROP structure
  319. BS_ASSERT(pProp);
  320. VSS_VOLUME_PROP& VolumeProp = pProp->Obj.Vol;
  321. // Setting the internal members
  322. ::VssSafeDuplicateStr(ft, VolumeProp.m_pwszVolumeName, pwszVolumeName);
  323. ::VssSafeDuplicateStr(ft, VolumeProp.m_pwszVolumeDisplayName, pwszVolumeDisplayName);
  324. // Setting the pointer field
  325. m_pStruct = pProp;
  326. }
  327. VSS_STANDARD_CATCH(ft)
  328. if (ft.HrFailed())
  329. {
  330. BS_ASSERT(ft.hr == E_OUTOFMEMORY);
  331. BS_ASSERT(m_pStruct == NULL);
  332. if (pProp)
  333. {
  334. VSS_MGMT_OBJECT_PROP_Copy::destroy(pProp); // destroy its contents.
  335. ::CoTaskMemFree(static_cast<LPVOID>(pProp));
  336. }
  337. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  338. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  339. }
  340. }
  341. void VSS_MGMT_OBJECT_PROP_Ptr::InitializeAsDiffVolume(
  342. IN CVssFunctionTracer& ft,
  343. IN VSS_PWSZ pwszVolumeName,
  344. IN VSS_PWSZ pwszVolumeDisplayName,
  345. IN LONGLONG llVolumeFreeSpace,
  346. IN LONGLONG llVolumeTotalSpace
  347. ) throw (HRESULT)
  348. /*++
  349. Routine description:
  350. Initialize a VSS_MGMT_OBJECT_PROP_Ptr in order to keep a VSS_MGMT_OBJECT_PROVIDER structure.
  351. Throws:
  352. E_OUTOFMEMORY
  353. --*/
  354. {
  355. WCHAR wszFunctionName[] = L"VSS_MGMT_OBJECT_PROP_Ptr::InitializeAsDiffVolume";
  356. VSS_MGMT_OBJECT_PROP* pProp = NULL;
  357. // Reset the error code
  358. ft.hr = S_OK;
  359. try
  360. {
  361. // Assert parameters
  362. BS_ASSERT(llVolumeFreeSpace >= 0);
  363. BS_ASSERT(llVolumeTotalSpace >= 0);
  364. // Assert the structure pointer to be set
  365. BS_ASSERT(m_pStruct == NULL);
  366. // Allocate the VSS_MGMT_OBJECT_UNION structure
  367. pProp = static_cast<VSS_MGMT_OBJECT_PROP*>(::CoTaskMemAlloc(sizeof(VSS_MGMT_OBJECT_PROP)));
  368. if (pProp == NULL)
  369. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  370. L"%s: Error on allocating the Properties structure",
  371. wszFunctionName );
  372. // Initialize the structure
  373. VSS_MGMT_OBJECT_PROP_Copy::init(pProp);
  374. pProp->Type = VSS_MGMT_OBJECT_DIFF_VOLUME;
  375. // Getting the equivalent VSS_SNAPSHOT_PROP structure
  376. BS_ASSERT(pProp);
  377. VSS_DIFF_VOLUME_PROP& DiffVolumeProp = pProp->Obj.DiffVol;
  378. // Setting the internal members
  379. ::VssSafeDuplicateStr(ft, DiffVolumeProp.m_pwszVolumeName, pwszVolumeName);
  380. ::VssSafeDuplicateStr(ft, DiffVolumeProp.m_pwszVolumeDisplayName, pwszVolumeDisplayName);
  381. DiffVolumeProp.m_llVolumeFreeSpace = llVolumeFreeSpace;
  382. DiffVolumeProp.m_llVolumeTotalSpace = llVolumeTotalSpace;
  383. // Setting the pointer field
  384. m_pStruct = pProp;
  385. }
  386. VSS_STANDARD_CATCH(ft)
  387. if (ft.HrFailed())
  388. {
  389. BS_ASSERT(ft.hr == E_OUTOFMEMORY);
  390. BS_ASSERT(m_pStruct == NULL);
  391. if (pProp)
  392. {
  393. VSS_MGMT_OBJECT_PROP_Copy::destroy(pProp); // destroy its contents.
  394. ::CoTaskMemFree(static_cast<LPVOID>(pProp));
  395. }
  396. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  397. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  398. }
  399. }
  400. void VSS_MGMT_OBJECT_PROP_Ptr::InitializeAsDiffArea(
  401. IN CVssFunctionTracer& ft,
  402. IN VSS_PWSZ pwszVolumeName,
  403. IN VSS_PWSZ pwszDiffAreaVolumeName,
  404. IN LONGLONG llUsedDiffSpace,
  405. IN LONGLONG llAllocatedDiffSpace,
  406. IN LONGLONG llMaximumDiffSpace
  407. ) throw (HRESULT)
  408. /*++
  409. Routine description:
  410. Initialize a VSS_MGMT_OBJECT_PROP_Ptr in order to keep a VSS_MGMT_OBJECT_PROVIDER structure.
  411. Throws:
  412. E_OUTOFMEMORY
  413. --*/
  414. {
  415. WCHAR wszFunctionName[] = L"VSS_MGMT_OBJECT_PROP_Ptr::InitializeAsProvider";
  416. VSS_MGMT_OBJECT_PROP* pProp = NULL;
  417. // Reset the error code
  418. ft.hr = S_OK;
  419. try
  420. {
  421. // Assert parameters
  422. BS_ASSERT(llUsedDiffSpace >= 0);
  423. BS_ASSERT(llAllocatedDiffSpace >= 0);
  424. BS_ASSERT((llMaximumDiffSpace >= 0) || (llMaximumDiffSpace == -1));
  425. // Assert the structure pointer to be set
  426. BS_ASSERT(m_pStruct == NULL);
  427. // Allocate the VSS_MGMT_OBJECT_UNION structure
  428. pProp = static_cast<VSS_MGMT_OBJECT_PROP*>(::CoTaskMemAlloc(sizeof(VSS_MGMT_OBJECT_PROP)));
  429. if (pProp == NULL)
  430. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  431. L"%s: Error on allocating the Properties structure",
  432. wszFunctionName );
  433. // Initialize the structure
  434. VSS_MGMT_OBJECT_PROP_Copy::init(pProp);
  435. pProp->Type = VSS_MGMT_OBJECT_DIFF_AREA;
  436. // Getting the equivalent VSS_SNAPSHOT_PROP structure
  437. BS_ASSERT(pProp);
  438. VSS_DIFF_AREA_PROP& DiffAreaProp = pProp->Obj.DiffArea;
  439. // Setting the internal members
  440. ::VssSafeDuplicateStr(ft, DiffAreaProp.m_pwszVolumeName, pwszVolumeName);
  441. ::VssSafeDuplicateStr(ft, DiffAreaProp.m_pwszDiffAreaVolumeName, pwszDiffAreaVolumeName);
  442. DiffAreaProp.m_llMaximumDiffSpace = llMaximumDiffSpace;
  443. DiffAreaProp.m_llAllocatedDiffSpace = llAllocatedDiffSpace;
  444. DiffAreaProp.m_llUsedDiffSpace = llUsedDiffSpace;
  445. // Setting the pointer field
  446. m_pStruct = pProp;
  447. }
  448. VSS_STANDARD_CATCH(ft)
  449. if (ft.HrFailed())
  450. {
  451. BS_ASSERT(ft.hr == E_OUTOFMEMORY);
  452. BS_ASSERT(m_pStruct == NULL);
  453. if (pProp)
  454. {
  455. VSS_MGMT_OBJECT_PROP_Copy::destroy(pProp); // destroy its contents.
  456. ::CoTaskMemFree(static_cast<LPVOID>(pProp));
  457. }
  458. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  459. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  460. }
  461. }
  462. void VSS_MGMT_OBJECT_PROP_Ptr::InitializeAsEmpty(
  463. IN CVssFunctionTracer& ft
  464. )
  465. /*++
  466. Routine description:
  467. Initialize a VSS_MGMT_OBJECT_PROP_Ptr in order to appear as an empty structure (to be filled later).
  468. Throws:
  469. E_OUTOFMEMORY
  470. --*/
  471. {
  472. WCHAR wszFunctionName[] = L"VSS_MGMT_OBJECT_PROP_Ptr::InitializeEmpty";
  473. VSS_MGMT_OBJECT_PROP* pProp = NULL;
  474. // Reset the error code
  475. ft.hr = S_OK;
  476. try
  477. {
  478. // Assert the structure pointer to be set
  479. BS_ASSERT(m_pStruct == NULL);
  480. // Allocate the VSS_MGMT_OBJECT_UNION structure
  481. pProp = static_cast<VSS_MGMT_OBJECT_PROP*>(::CoTaskMemAlloc(sizeof(VSS_MGMT_OBJECT_PROP)));
  482. if (pProp == NULL)
  483. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  484. L"%s: Error on allocating the Properties structure",
  485. wszFunctionName );
  486. // Initialize the structure
  487. VSS_MGMT_OBJECT_PROP_Copy::init(pProp);
  488. // Setting the pointer field
  489. m_pStruct = pProp;
  490. }
  491. VSS_STANDARD_CATCH(ft)
  492. if (ft.HrFailed())
  493. {
  494. BS_ASSERT(ft.hr == E_OUTOFMEMORY);
  495. BS_ASSERT(m_pStruct == NULL);
  496. BS_ASSERT(pProp == NULL);
  497. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  498. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  499. }
  500. }
  501. void VSS_MGMT_OBJECT_PROP_Ptr::Print(
  502. IN CVssFunctionTracer& ft,
  503. IN LPWSTR wszOutputBuffer,
  504. IN LONG lBufferSize
  505. )
  506. {
  507. WCHAR wszFunctionName[] = L"VSS_MGMT_OBJECT_PROP_Ptr::Print";
  508. // Reset the error code
  509. ft.hr = S_OK;
  510. try
  511. {
  512. if (m_pStruct == NULL)
  513. ::StringCchPrintfW(wszOutputBuffer, lBufferSize, L"NULL object\n\n");
  514. switch(m_pStruct->Type)
  515. {
  516. case VSS_MGMT_OBJECT_VOLUME:
  517. ::StringCchPrintfW(wszOutputBuffer, lBufferSize,
  518. L"VolumeName = %s\n"
  519. L"VolumeDisplayName = %s\n"
  520. L"lCurrentSnapshotCount = %ld \n",
  521. m_pStruct->Obj.Vol.m_pwszVolumeName,
  522. m_pStruct->Obj.Vol.m_pwszVolumeDisplayName);
  523. break;
  524. case VSS_MGMT_OBJECT_DIFF_VOLUME:
  525. ::StringCchPrintfW(wszOutputBuffer, lBufferSize,
  526. L"VolumeName = %s\n"
  527. L"VolumeDisplayName = %s\n"
  528. L"llFreeSpace = " WSTR_LONGLONG_FMT L"\n"
  529. L"llTotalSpace = " WSTR_LONGLONG_FMT L"\n",
  530. m_pStruct->Obj.DiffVol.m_pwszVolumeName,
  531. m_pStruct->Obj.DiffVol.m_pwszVolumeDisplayName,
  532. m_pStruct->Obj.DiffVol.m_llVolumeFreeSpace,
  533. m_pStruct->Obj.DiffVol.m_llVolumeTotalSpace);
  534. break;
  535. case VSS_MGMT_OBJECT_DIFF_AREA:
  536. ::StringCchPrintfW(wszOutputBuffer, lBufferSize,
  537. L"VolumeName = %s\n"
  538. L"VolumeDiffAreaName = %s\n"
  539. L"MaxSpace = " WSTR_LONGLONG_FMT L"\n"
  540. L"AllocatedSpace = " WSTR_LONGLONG_FMT L"\n"
  541. L"UsedSpace = " WSTR_LONGLONG_FMT L"\n",
  542. m_pStruct->Obj.DiffArea.m_pwszVolumeName,
  543. m_pStruct->Obj.DiffArea.m_pwszDiffAreaVolumeName,
  544. m_pStruct->Obj.DiffArea.m_llMaximumDiffSpace,
  545. m_pStruct->Obj.DiffArea.m_llAllocatedDiffSpace,
  546. m_pStruct->Obj.DiffArea.m_llUsedDiffSpace);
  547. break;
  548. default:
  549. ft.ErrBox( VSSDBG_GEN, E_UNEXPECTED,
  550. L"%s: Wrong object type %d", wszFunctionName, m_pStruct->Type );
  551. break;
  552. }
  553. }
  554. VSS_STANDARD_CATCH(ft)
  555. if (ft.HrFailed())
  556. {
  557. BS_ASSERT(m_pStruct == NULL);
  558. ft.Throw( VSSDBG_GEN, E_UNEXPECTED,
  559. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  560. }
  561. }