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.

358 lines
10 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. --*/
  17. /////////////////////////////////////////////////////////////////////////////
  18. // Needed includes
  19. #include "stdafx.hxx"
  20. #include "vs_inc.hxx"
  21. #include "vs_idl.hxx"
  22. #include "copy.hxx"
  23. #include "pointer.hxx"
  24. ////////////////////////////////////////////////////////////////////////
  25. // Standard foo for file name aliasing. This code block must be after
  26. // all includes of VSS header files.
  27. //
  28. #ifdef VSS_FILE_ALIAS
  29. #undef VSS_FILE_ALIAS
  30. #endif
  31. #define VSS_FILE_ALIAS "PRPPNTRC"
  32. //
  33. ////////////////////////////////////////////////////////////////////////
  34. /////////////////////////////////////////////////////////////////////////////
  35. // VSS_OBJECT_PROP_Ptr class
  36. void VSS_OBJECT_PROP_Ptr::InitializeAsSnapshot(
  37. IN CVssFunctionTracer& ft,
  38. IN VSS_ID SnapshotId,
  39. IN VSS_ID SnapshotSetId,
  40. IN LONG lSnapshotsCount,
  41. IN VSS_PWSZ pwszSnapshotDeviceObject,
  42. IN VSS_PWSZ pwszOriginalVolumeName,
  43. IN VSS_PWSZ pwszOriginatingMachine,
  44. IN VSS_PWSZ pwszServiceMachine,
  45. IN VSS_PWSZ pwszExposedName,
  46. IN VSS_PWSZ pwszExposedPath,
  47. IN VSS_ID ProviderId,
  48. IN LONG lSnapshotAttributes,
  49. IN VSS_TIMESTAMP tsCreationTimestamp,
  50. IN VSS_SNAPSHOT_STATE eStatus
  51. ) throw (HRESULT)
  52. /*++
  53. Routine description:
  54. Initialize a VSS_OBJECT_PROP_Ptr in order to keep a VSS_OBJECT_SNAPSHOT structure.
  55. Throws:
  56. E_OUTOFMEMORY
  57. --*/
  58. {
  59. WCHAR wszFunctionName[] = L"VSS_OBJECT_PROP_Ptr::InitializeAsSnapshot";
  60. VSS_OBJECT_PROP* pProp = NULL;
  61. try
  62. {
  63. // Assert the structure pointer to be set
  64. BS_ASSERT(m_pStruct == NULL);
  65. // Allocate the VSS_OBJECT_UNION structure
  66. pProp = static_cast<VSS_OBJECT_PROP*>(::CoTaskMemAlloc(sizeof(VSS_OBJECT_PROP)));
  67. if (pProp == NULL)
  68. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  69. L"%s: Error on allocating the Properties structure",
  70. wszFunctionName );
  71. // Initialize the structure
  72. VSS_OBJECT_PROP_Copy::init(pProp);
  73. pProp->Type = VSS_OBJECT_SNAPSHOT;
  74. // Getting the equivalent VSS_SNAPSHOT_PROP structure
  75. BS_ASSERT(pProp);
  76. VSS_SNAPSHOT_PROP& SnapshotProp = pProp->Obj.Snap;
  77. // Setting the internal members
  78. SnapshotProp.m_SnapshotId = SnapshotId;
  79. SnapshotProp.m_SnapshotSetId = SnapshotSetId;
  80. SnapshotProp.m_lSnapshotsCount = lSnapshotsCount;
  81. ::VssSafeDuplicateStr(ft, SnapshotProp.m_pwszSnapshotDeviceObject, pwszSnapshotDeviceObject);
  82. ::VssSafeDuplicateStr(ft, SnapshotProp.m_pwszOriginalVolumeName, pwszOriginalVolumeName);
  83. ::VssSafeDuplicateStr(ft, SnapshotProp.m_pwszOriginatingMachine, pwszOriginatingMachine);
  84. ::VssSafeDuplicateStr(ft, SnapshotProp.m_pwszServiceMachine, pwszServiceMachine);
  85. ::VssSafeDuplicateStr(ft, SnapshotProp.m_pwszExposedName, pwszExposedName);
  86. ::VssSafeDuplicateStr(ft, SnapshotProp.m_pwszExposedPath, pwszExposedPath);
  87. SnapshotProp.m_ProviderId = ProviderId;
  88. SnapshotProp.m_lSnapshotAttributes = lSnapshotAttributes;
  89. SnapshotProp.m_tsCreationTimestamp = tsCreationTimestamp;
  90. SnapshotProp.m_eStatus = eStatus;
  91. // Setting the pointer field
  92. m_pStruct = pProp;
  93. }
  94. VSS_STANDARD_CATCH(ft)
  95. if (ft.HrFailed())
  96. {
  97. BS_ASSERT(ft.hr == E_OUTOFMEMORY);
  98. BS_ASSERT(m_pStruct == NULL);
  99. if (pProp)
  100. {
  101. VSS_OBJECT_PROP_Copy::destroy(pProp); // destroy its contents.
  102. ::CoTaskMemFree(static_cast<LPVOID>(pProp));
  103. }
  104. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  105. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  106. }
  107. }
  108. void VSS_OBJECT_PROP_Ptr::InitializeAsProvider(
  109. IN CVssFunctionTracer& ft,
  110. IN VSS_ID ProviderId,
  111. IN VSS_PWSZ pwszProviderName,
  112. IN VSS_PROVIDER_TYPE eProviderType,
  113. IN VSS_PWSZ pwszProviderVersion,
  114. IN VSS_ID ProviderVersionId,
  115. IN CLSID ClassId
  116. ) throw (HRESULT)
  117. /*++
  118. Routine description:
  119. Initialize a VSS_OBJECT_PROP_Ptr in order to keep a VSS_OBJECT_PROVIDER structure.
  120. Throws:
  121. E_OUTOFMEMORY
  122. --*/
  123. {
  124. WCHAR wszFunctionName[] = L"VSS_OBJECT_PROP_Ptr::InitializeAsProvider";
  125. VSS_OBJECT_PROP* pProp = NULL;
  126. // Reset the error code
  127. ft.hr = S_OK;
  128. try
  129. {
  130. // Assert parameters
  131. BS_ASSERT(pwszProviderName == NULL || pwszProviderName[0] != L'\0');
  132. BS_ASSERT(eProviderType == VSS_PROV_SYSTEM ||
  133. eProviderType == VSS_PROV_SOFTWARE ||
  134. eProviderType == VSS_PROV_HARDWARE
  135. );
  136. // Assert the structure pointer to be set
  137. BS_ASSERT(m_pStruct == NULL);
  138. // Allocate the VSS_OBJECT_UNION structure
  139. pProp = static_cast<VSS_OBJECT_PROP*>(::CoTaskMemAlloc(sizeof(VSS_OBJECT_PROP)));
  140. if (pProp == NULL)
  141. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  142. L"%s: Error on allocating the Properties structure",
  143. wszFunctionName );
  144. // Initialize the structure
  145. VSS_OBJECT_PROP_Copy::init(pProp);
  146. pProp->Type = VSS_OBJECT_PROVIDER;
  147. // Getting the equivalent VSS_SNAPSHOT_PROP structure
  148. BS_ASSERT(pProp);
  149. VSS_PROVIDER_PROP& ProviderProp = pProp->Obj.Prov;
  150. // Setting the internal members
  151. ProviderProp.m_ProviderId = ProviderId;
  152. ::VssSafeDuplicateStr(ft, ProviderProp.m_pwszProviderName, pwszProviderName);
  153. ProviderProp.m_eProviderType = eProviderType;
  154. ::VssSafeDuplicateStr(ft, ProviderProp.m_pwszProviderVersion, pwszProviderVersion);
  155. ProviderProp.m_ProviderVersionId = ProviderVersionId;
  156. ProviderProp.m_ClassId = ClassId;
  157. // Setting the pointer field
  158. m_pStruct = pProp;
  159. }
  160. VSS_STANDARD_CATCH(ft)
  161. if (ft.HrFailed())
  162. {
  163. BS_ASSERT(ft.hr == E_OUTOFMEMORY);
  164. BS_ASSERT(m_pStruct == NULL);
  165. if (pProp)
  166. {
  167. VSS_OBJECT_PROP_Copy::destroy(pProp); // destroy its contents.
  168. ::CoTaskMemFree(static_cast<LPVOID>(pProp));
  169. }
  170. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  171. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  172. }
  173. }
  174. void VSS_OBJECT_PROP_Ptr::InitializeAsEmpty(
  175. IN CVssFunctionTracer& ft
  176. )
  177. /*++
  178. Routine description:
  179. Initialize a VSS_OBJECT_PROP_Ptr in order to appear as an empty structure (to be filled later).
  180. Throws:
  181. E_OUTOFMEMORY
  182. --*/
  183. {
  184. WCHAR wszFunctionName[] = L"VSS_OBJECT_PROP_Ptr::InitializeEmpty";
  185. VSS_OBJECT_PROP* pProp = NULL;
  186. // Reset the error code
  187. ft.hr = S_OK;
  188. try
  189. {
  190. // Assert the structure pointer to be set
  191. BS_ASSERT(m_pStruct == NULL);
  192. // Allocate the VSS_OBJECT_UNION structure
  193. pProp = static_cast<VSS_OBJECT_PROP*>(::CoTaskMemAlloc(sizeof(VSS_OBJECT_PROP)));
  194. if (pProp == NULL)
  195. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  196. L"%s: Error on allocating the Properties structure",
  197. wszFunctionName );
  198. // Initialize the structure
  199. VSS_OBJECT_PROP_Copy::init(pProp);
  200. // Setting the pointer field
  201. m_pStruct = pProp;
  202. }
  203. VSS_STANDARD_CATCH(ft)
  204. if (ft.HrFailed())
  205. {
  206. BS_ASSERT(ft.hr == E_OUTOFMEMORY);
  207. BS_ASSERT(m_pStruct == NULL);
  208. BS_ASSERT(pProp == NULL);
  209. ft.Throw( VSSDBG_GEN, E_OUTOFMEMORY,
  210. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  211. }
  212. }
  213. void VSS_OBJECT_PROP_Ptr::Print(
  214. IN CVssFunctionTracer& ft,
  215. IN LPWSTR wszOutputBuffer,
  216. IN LONG lBufferSize
  217. )
  218. {
  219. WCHAR wszFunctionName[] = L"VSS_OBJECT_PROP_Ptr::Print";
  220. // Reset the error code
  221. ft.hr = S_OK;
  222. try
  223. {
  224. if (m_pStruct == NULL)
  225. ::_snwprintf(wszOutputBuffer, lBufferSize, L"NULL object\n\n");
  226. // Effective copy
  227. switch(m_pStruct->Type)
  228. {
  229. case VSS_OBJECT_SNAPSHOT:
  230. ::_snwprintf(wszOutputBuffer, lBufferSize,
  231. L"Id = " WSTR_GUID_FMT L", "
  232. L"SnapshotSetId = " WSTR_GUID_FMT L"\n"
  233. L"SnapCount = %ld "
  234. L"DevObj = %s\n"
  235. L"OriginalVolumeName = %s\n"
  236. L"OriginatingMachine = %s\n"
  237. L"ServiceMachine = %s\n"
  238. L"Exposed name = %s\n"
  239. L"Exposed path = %s\n"
  240. L"ProviderId = " WSTR_GUID_FMT L"\n"
  241. L"Attributes = 0x%08lx\n"
  242. L"Timestamp = " WSTR_LONGLONG_FMT L"\n"
  243. L"Status = %d\n ",
  244. GUID_PRINTF_ARG( m_pStruct->Obj.Snap.m_SnapshotId ),
  245. GUID_PRINTF_ARG( m_pStruct->Obj.Snap.m_SnapshotSetId ),
  246. m_pStruct->Obj.Snap.m_lSnapshotsCount,
  247. m_pStruct->Obj.Snap.m_pwszSnapshotDeviceObject,
  248. m_pStruct->Obj.Snap.m_pwszOriginalVolumeName,
  249. m_pStruct->Obj.Snap.m_pwszOriginatingMachine,
  250. m_pStruct->Obj.Snap.m_pwszServiceMachine,
  251. m_pStruct->Obj.Snap.m_pwszExposedName,
  252. m_pStruct->Obj.Snap.m_pwszExposedPath,
  253. GUID_PRINTF_ARG( m_pStruct->Obj.Snap.m_ProviderId ),
  254. m_pStruct->Obj.Snap.m_lSnapshotAttributes,
  255. LONGLONG_PRINTF_ARG( m_pStruct->Obj.Snap.m_tsCreationTimestamp ),
  256. m_pStruct->Obj.Snap.m_eStatus);
  257. break;
  258. case VSS_OBJECT_PROVIDER:
  259. ::_snwprintf(wszOutputBuffer, lBufferSize,
  260. L"m_ProviderId = " WSTR_GUID_FMT L"\n"
  261. L"m_pwszProviderName = %s\n"
  262. L"m_ProviderType = %d\n"
  263. L"m_pwszProviderVersion = %s\n"
  264. L"m_ProviderVersionId = " WSTR_GUID_FMT L"\n"
  265. L"m_ClassID: " WSTR_GUID_FMT L"\n\n",
  266. GUID_PRINTF_ARG( m_pStruct->Obj.Prov.m_ProviderId ),
  267. m_pStruct->Obj.Prov.m_pwszProviderName? m_pStruct->Obj.Prov.m_pwszProviderName: L"NULL",
  268. m_pStruct->Obj.Prov.m_eProviderType,
  269. m_pStruct->Obj.Prov.m_pwszProviderVersion? m_pStruct->Obj.Prov.m_pwszProviderVersion: L"NULL",
  270. GUID_PRINTF_ARG( m_pStruct->Obj.Prov.m_ProviderVersionId ),
  271. GUID_PRINTF_ARG( m_pStruct->Obj.Prov.m_ClassId )
  272. );
  273. break;
  274. default:
  275. ft.ErrBox( VSSDBG_GEN, E_UNEXPECTED,
  276. L"%s: Wrong object type %d", wszFunctionName, m_pStruct->Type );
  277. break;
  278. }
  279. }
  280. VSS_STANDARD_CATCH(ft)
  281. if (ft.HrFailed())
  282. {
  283. BS_ASSERT(m_pStruct == NULL);
  284. ft.Throw( VSSDBG_GEN, E_UNEXPECTED,
  285. L"%s: Error catched 0x%08lx", wszFunctionName, ft.hr );
  286. }
  287. }