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.

385 lines
11 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Abstract:
  4. @doc
  5. @module Copy.cxx | Implementation of VSS_OBJECT_PROP_Copy and VSS_OBJECT_PROP_Ptr classes
  6. @end
  7. Author:
  8. Adi Oltean [aoltean] 09/01/1999
  9. Remarks:
  10. It cannot be put into a library because of ATL code.
  11. Revision History:
  12. Name Date Comments
  13. aoltean 09/01/1999 Created
  14. aoltean 09/09/1999 dss -> vss
  15. aoltean 09/13/1999 Moved to inc. Renamed to copy.inl
  16. aoltean 09/20/1999 Adding methods for creating the snapshot, snapshot set,
  17. provider and volume property structures.
  18. Also VSS_OBJECT_PROP_Manager renamed to VSS_OBJECT_PROP_Manager.
  19. aoltean 09/21/1999 Renaming back VSS_OBJECT_PROP_Manager to VSS_OBJECT_PROP_Copy.
  20. Moving the CreateXXX into VSS_OBJECT_PROP_Ptr::InstantiateAsXXX
  21. aoltean 09/22/1999 Fixing VSSDBG_GEN.
  22. aoltean 09/24/1999 Moving into modules/prop
  23. aoltean 12/16/1999 Adding specialized copyXXX methods
  24. aoltean 03/05/2001 Adding support for management objects
  25. --*/
  26. /////////////////////////////////////////////////////////////////////////////
  27. // Needed includes
  28. #include "stdafx.hxx"
  29. #include "vs_inc.hxx"
  30. #include "vs_idl.hxx"
  31. #include "copy.hxx"
  32. ////////////////////////////////////////////////////////////////////////
  33. // Standard foo for file name aliasing. This code block must be after
  34. // all includes of VSS header files.
  35. //
  36. #ifdef VSS_FILE_ALIAS
  37. #undef VSS_FILE_ALIAS
  38. #endif
  39. #define VSS_FILE_ALIAS "PRPCOPYC"
  40. //
  41. ////////////////////////////////////////////////////////////////////////
  42. /////////////////////////////////////////////////////////////////////////////
  43. // VSS_OBJECT_PROP_Copy class
  44. HRESULT VSS_OBJECT_PROP_Copy::copySnapshot(
  45. IN VSS_SNAPSHOT_PROP* pObj1,
  46. IN VSS_SNAPSHOT_PROP* pObj2
  47. )
  48. {
  49. CVssFunctionTracer ft( VSSDBG_GEN, L"VSS_OBJECT_PROP_Copy::copySnapshot" );
  50. try
  51. {
  52. // Testing arguments
  53. BS_ASSERT(pObj1 != NULL);
  54. BS_ASSERT(pObj2 != NULL);
  55. // Copy the members
  56. pObj1->m_SnapshotId = pObj2->m_SnapshotId;
  57. pObj1->m_SnapshotSetId = pObj2->m_SnapshotSetId;
  58. pObj1->m_lSnapshotsCount = pObj2->m_lSnapshotsCount;
  59. ::VssSafeDuplicateStr( ft, pObj1->m_pwszSnapshotDeviceObject, pObj2->m_pwszSnapshotDeviceObject );
  60. ::VssSafeDuplicateStr( ft, pObj1->m_pwszOriginalVolumeName, pObj2->m_pwszOriginalVolumeName );
  61. ::VssSafeDuplicateStr( ft, pObj1->m_pwszOriginatingMachine, pObj2->m_pwszOriginatingMachine );
  62. ::VssSafeDuplicateStr( ft, pObj1->m_pwszServiceMachine, pObj2->m_pwszServiceMachine );
  63. ::VssSafeDuplicateStr( ft, pObj1->m_pwszExposedName, pObj2->m_pwszExposedName );
  64. ::VssSafeDuplicateStr( ft, pObj1->m_pwszExposedPath, pObj2->m_pwszExposedPath );
  65. pObj1->m_ProviderId = pObj2->m_ProviderId;
  66. pObj1->m_lSnapshotAttributes = pObj2->m_lSnapshotAttributes;
  67. pObj1->m_tsCreationTimestamp = pObj2->m_tsCreationTimestamp;
  68. pObj1->m_eStatus = pObj2->m_eStatus;
  69. }
  70. VSS_STANDARD_CATCH(ft)
  71. return ft.hr;
  72. }
  73. HRESULT VSS_OBJECT_PROP_Copy::copyProvider(
  74. IN VSS_PROVIDER_PROP* pObj1,
  75. IN VSS_PROVIDER_PROP* pObj2
  76. )
  77. {
  78. CVssFunctionTracer ft( VSSDBG_GEN, L"VSS_OBJECT_PROP_Copy::copyProvider" );
  79. try
  80. {
  81. // Testing arguments
  82. BS_ASSERT(pObj1 != NULL);
  83. BS_ASSERT(pObj2 != NULL);
  84. // Copy the members
  85. pObj1->m_ProviderId = pObj2->m_ProviderId;
  86. ::VssSafeDuplicateStr( ft, pObj1->m_pwszProviderName, pObj2->m_pwszProviderName );
  87. pObj1->m_eProviderType = pObj2->m_eProviderType;
  88. ::VssSafeDuplicateStr( ft, pObj1->m_pwszProviderVersion, pObj2->m_pwszProviderVersion );
  89. pObj1->m_ProviderVersionId = pObj2->m_ProviderVersionId;
  90. pObj1->m_ClassId = pObj2->m_ClassId;
  91. }
  92. VSS_STANDARD_CATCH(ft)
  93. return ft.hr;
  94. }
  95. HRESULT VSS_OBJECT_PROP_Copy::copy(
  96. IN VSS_OBJECT_PROP* pObj1,
  97. IN VSS_OBJECT_PROP* pObj2
  98. )
  99. {
  100. HRESULT hr;
  101. // Testing arguments
  102. if ((pObj1 == NULL) || (pObj2 == NULL))
  103. return E_INVALIDARG;
  104. // Zeroing the contents of the destination structure
  105. ::VssZeroOut(pObj1);
  106. // Copy the type
  107. pObj1->Type = pObj2->Type;
  108. // Effective copy
  109. switch(pObj2->Type)
  110. {
  111. case VSS_OBJECT_SNAPSHOT:
  112. hr = copySnapshot( &(pObj1->Obj.Snap), &(pObj2->Obj.Snap) );
  113. break;
  114. case VSS_OBJECT_PROVIDER:
  115. hr = copyProvider( &(pObj1->Obj.Prov), &(pObj2->Obj.Prov) );
  116. break;
  117. default:
  118. BS_ASSERT(false);
  119. hr = E_UNEXPECTED;
  120. break;
  121. }
  122. return hr;
  123. }
  124. void VSS_OBJECT_PROP_Copy::init(
  125. IN VSS_OBJECT_PROP* pObjectProp
  126. )
  127. {
  128. CVssFunctionTracer ft( VSSDBG_GEN, L"VSS_OBJECT_PROP_Copy::init" );
  129. try
  130. {
  131. // Zeroing the contents of the structure
  132. ::VssZeroOut(pObjectProp);
  133. }
  134. VSS_STANDARD_CATCH(ft)
  135. }
  136. void VSS_OBJECT_PROP_Copy::destroy(
  137. IN VSS_OBJECT_PROP* pObjectProp
  138. )
  139. {
  140. CVssFunctionTracer ft( VSSDBG_GEN, L"VSS_OBJECT_PROP_Copy::destroy" );
  141. try
  142. {
  143. if (pObjectProp)
  144. {
  145. switch(pObjectProp->Type)
  146. {
  147. case VSS_OBJECT_SNAPSHOT:
  148. ::VssFreeString(pObjectProp->Obj.Snap.m_pwszOriginalVolumeName);
  149. ::VssFreeString(pObjectProp->Obj.Snap.m_pwszSnapshotDeviceObject);
  150. ::VssFreeString(pObjectProp->Obj.Snap.m_pwszOriginatingMachine);
  151. ::VssFreeString(pObjectProp->Obj.Snap.m_pwszServiceMachine);
  152. ::VssFreeString(pObjectProp->Obj.Snap.m_pwszExposedName);
  153. ::VssFreeString(pObjectProp->Obj.Snap.m_pwszExposedPath);
  154. break;
  155. case VSS_OBJECT_PROVIDER:
  156. ::VssFreeString(pObjectProp->Obj.Prov.m_pwszProviderName);
  157. ::VssFreeString(pObjectProp->Obj.Prov.m_pwszProviderVersion);
  158. break;
  159. default:
  160. break;
  161. }
  162. pObjectProp->Type = VSS_OBJECT_UNKNOWN;
  163. }
  164. }
  165. VSS_STANDARD_CATCH(ft)
  166. }
  167. /////////////////////////////////////////////////////////////////////////////
  168. // VSS_MGMT_OBJECT_PROP_Copy class
  169. HRESULT VSS_MGMT_OBJECT_PROP_Copy::copyVolume(
  170. IN VSS_VOLUME_PROP* pObj1,
  171. IN VSS_VOLUME_PROP* pObj2
  172. )
  173. {
  174. CVssFunctionTracer ft( VSSDBG_GEN, L"VSS_MGMT_OBJECT_PROP_Copy::copyVolume" );
  175. try
  176. {
  177. // Testing arguments
  178. BS_ASSERT(pObj1 != NULL);
  179. BS_ASSERT(pObj2 != NULL);
  180. // Copy the members
  181. ::VssSafeDuplicateStr( ft, pObj1->m_pwszVolumeName, pObj2->m_pwszVolumeName);
  182. ::VssSafeDuplicateStr( ft, pObj1->m_pwszVolumeDisplayName, pObj2->m_pwszVolumeDisplayName);
  183. }
  184. VSS_STANDARD_CATCH(ft)
  185. return ft.hr;
  186. }
  187. HRESULT VSS_MGMT_OBJECT_PROP_Copy::copyDiffVolume(
  188. IN VSS_DIFF_VOLUME_PROP* pObj1,
  189. IN VSS_DIFF_VOLUME_PROP* pObj2
  190. )
  191. {
  192. CVssFunctionTracer ft( VSSDBG_GEN, L"VSS_MGMT_OBJECT_PROP_Copy::copyDiffVolume" );
  193. try
  194. {
  195. // Testing arguments
  196. BS_ASSERT(pObj1 != NULL);
  197. BS_ASSERT(pObj2 != NULL);
  198. // Copy the members
  199. ::VssSafeDuplicateStr( ft, pObj1->m_pwszVolumeName, pObj2->m_pwszVolumeName);
  200. ::VssSafeDuplicateStr( ft, pObj1->m_pwszVolumeDisplayName, pObj2->m_pwszVolumeDisplayName);
  201. pObj1->m_llVolumeFreeSpace = pObj2->m_llVolumeFreeSpace;
  202. pObj1->m_llVolumeTotalSpace = pObj2->m_llVolumeTotalSpace;
  203. }
  204. VSS_STANDARD_CATCH(ft)
  205. return ft.hr;
  206. }
  207. HRESULT VSS_MGMT_OBJECT_PROP_Copy::copyDiffArea(
  208. IN VSS_DIFF_AREA_PROP* pObj1,
  209. IN VSS_DIFF_AREA_PROP* pObj2
  210. )
  211. {
  212. CVssFunctionTracer ft( VSSDBG_GEN, L"VSS_MGMT_OBJECT_PROP_Copy::copyDiffArea" );
  213. try
  214. {
  215. // Testing arguments
  216. BS_ASSERT(pObj1 != NULL);
  217. BS_ASSERT(pObj2 != NULL);
  218. // Copy the members
  219. ::VssSafeDuplicateStr( ft, pObj1->m_pwszVolumeName, pObj2->m_pwszVolumeName);
  220. ::VssSafeDuplicateStr( ft, pObj1->m_pwszDiffAreaVolumeName, pObj2->m_pwszDiffAreaVolumeName);
  221. pObj1->m_llMaximumDiffSpace = pObj2->m_llMaximumDiffSpace;
  222. pObj1->m_llAllocatedDiffSpace = pObj2->m_llAllocatedDiffSpace;
  223. pObj1->m_llUsedDiffSpace = pObj2->m_llUsedDiffSpace;
  224. }
  225. VSS_STANDARD_CATCH(ft)
  226. return ft.hr;
  227. }
  228. HRESULT VSS_MGMT_OBJECT_PROP_Copy::copy(
  229. IN VSS_MGMT_OBJECT_PROP* pObj1,
  230. IN VSS_MGMT_OBJECT_PROP* pObj2
  231. )
  232. {
  233. HRESULT hr;
  234. // Testing arguments
  235. if ((pObj1 == NULL) || (pObj2 == NULL))
  236. return E_INVALIDARG;
  237. // Zeroing the contents of the destination structure
  238. ::VssZeroOut(pObj1);
  239. // Copy the type
  240. pObj1->Type = pObj2->Type;
  241. // Effective copy
  242. switch(pObj2->Type)
  243. {
  244. case VSS_MGMT_OBJECT_VOLUME:
  245. hr = copyVolume( &(pObj1->Obj.Vol), &(pObj2->Obj.Vol) );
  246. break;
  247. case VSS_MGMT_OBJECT_DIFF_VOLUME:
  248. hr = copyDiffVolume( &(pObj1->Obj.DiffVol), &(pObj2->Obj.DiffVol) );
  249. break;
  250. case VSS_MGMT_OBJECT_DIFF_AREA:
  251. hr = copyDiffArea( &(pObj1->Obj.DiffArea), &(pObj2->Obj.DiffArea) );
  252. break;
  253. default:
  254. BS_ASSERT(false);
  255. hr = E_UNEXPECTED;
  256. break;
  257. }
  258. return hr;
  259. }
  260. void VSS_MGMT_OBJECT_PROP_Copy::init(
  261. IN VSS_MGMT_OBJECT_PROP* pObjectProp
  262. )
  263. {
  264. CVssFunctionTracer ft( VSSDBG_GEN, L"VSS_MGMT_OBJECT_PROP_Copy::init" );
  265. try
  266. {
  267. // Zeroing the contents of the structure
  268. ::VssZeroOut(pObjectProp);
  269. }
  270. VSS_STANDARD_CATCH(ft)
  271. }
  272. void VSS_MGMT_OBJECT_PROP_Copy::destroy(
  273. IN VSS_MGMT_OBJECT_PROP* pObjectProp
  274. )
  275. {
  276. CVssFunctionTracer ft( VSSDBG_GEN, L"VSS_MGMT_OBJECT_PROP_Copy::destroy" );
  277. try
  278. {
  279. if (pObjectProp)
  280. {
  281. switch(pObjectProp->Type)
  282. {
  283. case VSS_MGMT_OBJECT_VOLUME:
  284. ::VssFreeString(pObjectProp->Obj.Vol.m_pwszVolumeName);
  285. ::VssFreeString(pObjectProp->Obj.Vol.m_pwszVolumeDisplayName);
  286. break;
  287. case VSS_MGMT_OBJECT_DIFF_VOLUME:
  288. ::VssFreeString(pObjectProp->Obj.DiffVol.m_pwszVolumeName);
  289. ::VssFreeString(pObjectProp->Obj.DiffVol.m_pwszVolumeDisplayName);
  290. break;
  291. case VSS_MGMT_OBJECT_DIFF_AREA:
  292. ::VssFreeString(pObjectProp->Obj.DiffArea.m_pwszVolumeName);
  293. ::VssFreeString(pObjectProp->Obj.DiffArea.m_pwszDiffAreaVolumeName);
  294. break;
  295. default:
  296. break;
  297. }
  298. pObjectProp->Type = VSS_MGMT_OBJECT_UNKNOWN;
  299. }
  300. }
  301. VSS_STANDARD_CATCH(ft)
  302. }