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.

918 lines
20 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. HsmStgPl.cpp
  5. Abstract:
  6. This component is an object representation of the HSM Storage Pool. It
  7. is both a persistable and collectable.
  8. Author:
  9. Cat Brant [cbrant] 09-Feb-1997
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "Wsb.h"
  14. #include "HsmEng.h"
  15. #include "HsmServ.h"
  16. #include "HsmConn.h"
  17. #include "HsmStgPl.h"
  18. #include "Fsa.h"
  19. #include "Rms.h"
  20. #define WSB_TRACE_IS WSB_TRACE_BIT_HSMENG
  21. HRESULT
  22. CHsmStoragePool::FinalConstruct(
  23. void
  24. )
  25. /*++
  26. Routine Description:
  27. This method does some initialization of the object that is necessary
  28. after construction.
  29. Arguments:
  30. None.
  31. Return Value:
  32. S_OK
  33. Anything returned by CWsbObject::FinalConstruct().
  34. --*/
  35. {
  36. HRESULT hr = S_OK;
  37. try {
  38. WsbAffirmHr(CWsbObject::FinalConstruct());
  39. m_MediaSetId = GUID_NULL;
  40. m_PolicyId = GUID_NULL;
  41. m_NumOnlineMedia = 0;
  42. m_NumMediaCopies = 0;
  43. m_MediaSetName = " ";
  44. WsbAffirmHr(CoCreateGuid( &m_Id ));
  45. } WsbCatch(hr);
  46. return(hr);
  47. }
  48. HRESULT
  49. CHsmStoragePool::GetId(
  50. OUT GUID *pId
  51. )
  52. /*++
  53. Routine Description:
  54. See IHsmStoragePool::GetId
  55. Arguments:
  56. See IHsmStoragePool::GetId
  57. Return Value:
  58. See IHsmStoragePool::GetId
  59. --*/
  60. {
  61. HRESULT hr = S_OK;
  62. WsbTraceIn(OLESTR("CHsmStoragePool::GetId"),OLESTR(""));
  63. try {
  64. //Make sure we can provide data memebers
  65. WsbAssert(0 != pId, E_POINTER);
  66. //Provide the data members
  67. *pId = m_Id;
  68. } WsbCatch(hr);
  69. WsbTraceOut(OLESTR("CHsmStoragePool::GetId"),
  70. OLESTR("hr = <%ls>, Id = <%ls>>"),WsbHrAsString(hr), WsbPtrToGuidAsString(pId));
  71. return(hr);
  72. }
  73. HRESULT
  74. CHsmStoragePool::SetId(
  75. GUID Id
  76. )
  77. /*++
  78. Routine Description:
  79. See IHsmStoragePool::SetId
  80. Arguments:
  81. See IHsmStoragePool::SetId
  82. Return Value:
  83. See IHsmStoragePool::SetId
  84. --*/
  85. {
  86. HRESULT hr = S_OK;
  87. WsbTraceIn(OLESTR("CHsmStoragePool::SetId"),OLESTR("Id = <%ls>>"), WsbGuidAsString(Id));
  88. try {
  89. //Provide the data members
  90. m_Id = Id;
  91. } WsbCatch(hr);
  92. WsbTraceOut(OLESTR("CHsmStoragePool::SetId"),OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  93. return(hr);
  94. }
  95. HRESULT
  96. CHsmStoragePool::GetClassID (
  97. OUT LPCLSID pClsId
  98. )
  99. /*++
  100. Routine Description:
  101. See IPerist::GetClassID()
  102. Arguments:
  103. See IPerist::GetClassID()
  104. Return Value:
  105. See IPerist::GetClassID()
  106. --*/
  107. {
  108. HRESULT hr = S_OK;
  109. WsbTraceIn(OLESTR("CHsmStoragePool::GetClassID"), OLESTR(""));
  110. try {
  111. WsbAssert(0 != pClsId, E_POINTER);
  112. *pClsId = CLSID_CHsmStoragePool;
  113. } WsbCatch(hr);
  114. WsbTraceOut(OLESTR("CHsmStoragePool::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsId));
  115. return(hr);
  116. }
  117. HRESULT
  118. CHsmStoragePool::GetSizeMax (
  119. OUT ULARGE_INTEGER* pcbSize
  120. )
  121. /*++
  122. Routine Description:
  123. See IPersistStream::GetSizeMax().
  124. Arguments:
  125. See IPersistStream::GetSizeMax().
  126. Return Value:
  127. See IPersistStream::GetSizeMax().
  128. --*/
  129. {
  130. HRESULT hr = S_OK;
  131. WsbTraceIn(OLESTR("CHsmStoragePool::GetSizeMax"), OLESTR(""));
  132. try {
  133. ULONG nameLen;
  134. WsbAssert(0 != pcbSize, E_POINTER);
  135. nameLen = SysStringByteLen(m_MediaSetName);
  136. pcbSize->QuadPart = ((3 * WsbPersistSizeOf(GUID)) + // m_id + m_MediaSetID + m_PolicyId
  137. WsbPersistSizeOf(ULONG) + // m_NumOnlineMedia
  138. WsbPersistSizeOf(USHORT) + // m_NumMediaCopies
  139. nameLen); // m_MediaSetName
  140. } WsbCatch(hr);
  141. WsbTraceOut(OLESTR("CHsmStoragePool::GetSizeMax"),
  142. OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr),
  143. WsbPtrToUliAsString(pcbSize));
  144. return(hr);
  145. }
  146. HRESULT
  147. CHsmStoragePool::Load (
  148. IN IStream* pStream
  149. )
  150. /*++
  151. Routine Description:
  152. See IPersistStream::Load().
  153. Arguments:
  154. See IPersistStream::Load().
  155. Return Value:
  156. See IPersistStream::Load().
  157. --*/
  158. {
  159. HRESULT hr = S_OK;
  160. WsbTraceIn(OLESTR("CHsmStoragePool::Load"), OLESTR(""));
  161. try {
  162. WsbAssert(0 != pStream, E_POINTER);
  163. WsbAffirmHr(WsbLoadFromStream(pStream, &m_Id));
  164. WsbAffirmHr(WsbLoadFromStream(pStream, &m_MediaSetId));
  165. WsbAffirmHr(WsbLoadFromStream(pStream, &m_PolicyId));
  166. WsbAffirmHr(WsbLoadFromStream(pStream, &m_NumOnlineMedia));
  167. WsbAffirmHr(WsbLoadFromStream(pStream, &m_NumMediaCopies));
  168. m_MediaSetName.Free();
  169. WsbAffirmHr(WsbBstrFromStream(pStream, &m_MediaSetName));
  170. } WsbCatch(hr);
  171. WsbTraceOut(OLESTR("CHsmStoragePool::Load"),
  172. OLESTR("hr = <%ls>, GUID = <%ls>"),
  173. WsbHrAsString(hr),
  174. WsbGuidAsString(m_Id));
  175. return(hr);
  176. }
  177. HRESULT
  178. CHsmStoragePool::Save (
  179. IN IStream* pStream,
  180. IN BOOL clearDirty
  181. )
  182. /*++
  183. Routine Description:
  184. See IPersistStream::Save().
  185. Arguments:
  186. See IPersistStream::Save().
  187. Return Value:
  188. See IPersistStream::Save().
  189. --*/
  190. {
  191. HRESULT hr = S_OK;
  192. WsbTraceIn(OLESTR("CHsmStoragePool::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  193. try {
  194. WsbAssert(0 != pStream, E_POINTER);
  195. WsbAffirmHr(WsbSaveToStream(pStream, m_Id));
  196. WsbAffirmHr(WsbSaveToStream(pStream, m_MediaSetId));
  197. WsbAffirmHr(WsbSaveToStream(pStream, m_PolicyId));
  198. WsbAffirmHr(WsbSaveToStream(pStream, m_NumOnlineMedia));
  199. WsbAffirmHr(WsbSaveToStream(pStream, m_NumMediaCopies));
  200. WsbAffirmHr(WsbBstrToStream(pStream, m_MediaSetName));
  201. if (clearDirty) {
  202. m_isDirty = FALSE;
  203. }
  204. } WsbCatch(hr);
  205. WsbTraceOut(OLESTR("CHsmStoragePool::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  206. return(hr);
  207. }
  208. HRESULT
  209. CHsmStoragePool::Test (
  210. OUT USHORT *pTestsPassed,
  211. OUT USHORT *pTestsFailed
  212. )
  213. /*++
  214. Routine Description:
  215. See IWsbTestable::Test().
  216. Arguments:
  217. See IWsbTestable::Test().
  218. Return Value:
  219. See IWsbTestable::Test().
  220. --*/
  221. {
  222. HRESULT hr = S_OK;
  223. CComPtr<IHsmStoragePool> pHsmStoragePool1;
  224. CComPtr<IHsmStoragePool> pHsmStoragePool2;
  225. GUID l_Id;
  226. WsbTraceIn(OLESTR("CHsmStoragePool::Test"), OLESTR(""));
  227. *pTestsPassed = *pTestsFailed = 0;
  228. try {
  229. // Get the pHsmStoragePool interface.
  230. WsbAffirmHr(((IUnknown*)(IHsmStoragePool*) this)->QueryInterface(IID_IHsmStoragePool,
  231. (void**) &pHsmStoragePool1));
  232. hr = S_OK;
  233. try {
  234. //Create another instance and test the comparisson methods:
  235. WsbAffirmHr(CoCreateInstance(CLSID_CHsmStoragePool, NULL, CLSCTX_ALL, IID_IHsmStoragePool, (void**) &pHsmStoragePool2));
  236. // Check the default values.
  237. WsbAffirmHr(pHsmStoragePool2->GetId(&l_Id));
  238. WsbAffirm((l_Id == GUID_NULL), E_FAIL);
  239. } WsbCatch(hr);
  240. if (hr == S_OK) {
  241. (*pTestsPassed)++;
  242. } else {
  243. (*pTestsFailed)++;
  244. }
  245. } WsbCatch(hr);
  246. WsbTraceOut(OLESTR("CHsmStoragePool::Test"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  247. return(S_OK);
  248. }
  249. HRESULT
  250. CHsmStoragePool::CompareTo (
  251. IN IUnknown* pCollectable,
  252. OUT short* pResult
  253. )
  254. /*++
  255. Routine Description:
  256. 1 : object > value
  257. 0 : object = value
  258. -1 : object < value
  259. In addition, the return code is S_OK if the object = value and
  260. S_FALSE otherwise.
  261. Arguments:
  262. Return Value:
  263. S_OK - object = value
  264. S_FALSE - object != value
  265. --*/
  266. {
  267. HRESULT hr = S_OK;
  268. CComPtr<IHsmStoragePool> pHsmStoragePool;
  269. WsbTraceIn(OLESTR("CHsmStoragePool::CompareTo"), OLESTR(""));
  270. // Did they give us a valid item to compare to?
  271. try {
  272. WsbAssert(pCollectable != NULL, E_POINTER);
  273. // We need the IWsbLong interface to get the value of the object.
  274. WsbAffirmHr(pCollectable->QueryInterface(IID_IHsmStoragePool, (void**) &pHsmStoragePool));
  275. hr = pHsmStoragePool->CompareToIHsmStoragePool(this, pResult);
  276. } WsbCatch(hr);
  277. WsbTraceOut(OLESTR("CHsmStoragePool::CompareTo"), OLESTR("hr = <%ls>, pResult = <%d>"), WsbHrAsString(hr), pResult);
  278. return(hr);
  279. }
  280. HRESULT
  281. CHsmStoragePool::CompareToIHsmStoragePool (
  282. IN IHsmStoragePool* pHsmStoragePool,
  283. OUT short* pResult
  284. )
  285. {
  286. HRESULT hr = S_OK;
  287. GUID l_Id;
  288. BOOL areGuidsEqual;
  289. WsbTraceIn(OLESTR("CHsmStoragePool::CompareToIHsmStoragePool"), OLESTR(""));
  290. try {
  291. // Did they give us a valid item to compare to?
  292. WsbAssert(pHsmStoragePool != NULL, E_POINTER);
  293. WsbAffirmHr(((IHsmStoragePool *)pHsmStoragePool)->GetId(&l_Id));
  294. // Make sure the GUID matches. Then see if the SegStartLoc is in the range of this entry
  295. areGuidsEqual = IsEqualGUID(m_Id, l_Id);
  296. WsbAffirm( (areGuidsEqual == TRUE), S_FALSE);
  297. } WsbCatch(hr);
  298. WsbTraceOut(OLESTR("CHsmStoragePool::CompareToIHsmStoragePool"), OLESTR("hr = <%ls>, pResult = <%d>"), WsbHrAsString(hr), pResult);
  299. return(hr);
  300. }
  301. HRESULT
  302. CHsmStoragePool::GetMediaSet(
  303. GUID *pMediaSetId,
  304. BSTR *pMediaSetName
  305. )
  306. /*++
  307. Routine Description:
  308. See IHsmStoragePool::
  309. Arguments:
  310. See IHsmStoragePool::
  311. Return Value:
  312. See IHsmStoragePool::
  313. --*/
  314. {
  315. HRESULT hr = S_OK;
  316. WsbTraceIn(OLESTR("CHsmStoragePool::GetMediaSet"),OLESTR(""));
  317. try {
  318. WsbAssert(0 != pMediaSetId, E_POINTER);
  319. WsbAssert(0 != pMediaSetName, E_POINTER);
  320. *pMediaSetName = WsbAllocString( m_MediaSetName );
  321. *pMediaSetId = m_MediaSetId;
  322. } WsbCatch( hr );
  323. WsbTraceOut(OLESTR("CHsmStoragePool::GetMediaSet"),
  324. OLESTR("hr = <%ls>, Id = <%ls>>"),WsbHrAsString(hr), WsbPtrToGuidAsString(pMediaSetId));
  325. return( hr );
  326. }
  327. HRESULT
  328. CHsmStoragePool::SetMediaSet(
  329. GUID mediaSetId,
  330. BSTR mediaSetName
  331. )
  332. /*++
  333. Routine Description:
  334. See IHsmStoragePool::
  335. Arguments:
  336. See IHsmStoragePool::
  337. Return Value:
  338. See IHsmStoragePool::
  339. --*/
  340. {
  341. HRESULT hr = S_OK;
  342. WsbTraceIn(OLESTR("CHsmStoragePool::SetMediaSet"),OLESTR(""));
  343. try {
  344. m_MediaSetId = mediaSetId;
  345. m_MediaSetName = mediaSetName;
  346. m_isDirty = TRUE;
  347. } WsbCatch( hr );
  348. WsbTraceOut(OLESTR("CHsmStoragePool::SetMediaSet"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  349. return( hr );
  350. }
  351. HRESULT
  352. CHsmStoragePool::GetNumOnlineMedia(
  353. ULONG *pNumOnlineMedia
  354. )
  355. /*++
  356. Routine Description:
  357. See IHsmStoragePool::
  358. Arguments:
  359. See IHsmStoragePool::
  360. Return Value:
  361. See IHsmStoragePool::
  362. --*/
  363. {
  364. HRESULT hr = S_OK;
  365. WsbTraceIn(OLESTR("CHsmStoragePool::GetNumOnlineMedia"),OLESTR(""));
  366. try {
  367. WsbAffirm(0 != pNumOnlineMedia, E_POINTER);
  368. *pNumOnlineMedia = m_NumOnlineMedia;
  369. } WsbCatch( hr );
  370. WsbTraceOut(OLESTR("CHsmStoragePool::GetNumOnlineMedia"),
  371. OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  372. return( hr );
  373. }
  374. HRESULT
  375. CHsmStoragePool::SetNumOnlineMedia(
  376. ULONG numOnlineMedia
  377. )
  378. /*++
  379. Routine Description:
  380. See IHsmStoragePool::
  381. Arguments:
  382. See IHsmStoragePool::
  383. Return Value:
  384. See IHsmStoragePool::
  385. --*/
  386. {
  387. HRESULT hr = S_OK;
  388. WsbTraceIn(OLESTR("CHsmStoragePool::SetNumOnlineMedia"),OLESTR(""));
  389. m_NumOnlineMedia = numOnlineMedia;
  390. m_isDirty = TRUE;
  391. WsbTraceOut(OLESTR("CHsmStoragePool::SetNumOnlineMedia"),
  392. OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  393. return( hr );
  394. }
  395. HRESULT
  396. CHsmStoragePool::GetNumMediaCopies(
  397. USHORT *pNumMediaCopies
  398. )
  399. /*++
  400. Routine Description:
  401. See IHsmStoragePool::
  402. Arguments:
  403. See IHsmStoragePool::
  404. Return Value:
  405. See IHsmStoragePool::
  406. --*/
  407. {
  408. HRESULT hr = S_OK;
  409. WsbTraceIn(OLESTR("CHsmStoragePool::GetNumMediaCopies"),OLESTR(""));
  410. try {
  411. WsbAffirm(0 != pNumMediaCopies, E_POINTER);
  412. *pNumMediaCopies = m_NumMediaCopies;
  413. } WsbCatch( hr );
  414. WsbTraceOut(OLESTR("CHsmStoragePool::GetNumMediaCopies"),
  415. OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  416. return( hr );
  417. }
  418. HRESULT
  419. CHsmStoragePool::SetNumMediaCopies(
  420. USHORT numMediaCopies
  421. )
  422. /*++
  423. Routine Description:
  424. See IHsmStoragePool::
  425. Arguments:
  426. See IHsmStoragePool::
  427. Return Value:
  428. See IHsmStoragePool::
  429. --*/
  430. {
  431. HRESULT hr = S_OK;
  432. WsbTraceIn(OLESTR("CHsmStoragePool::SetNumMediaCopies"),OLESTR(""));
  433. m_NumMediaCopies = numMediaCopies;
  434. m_isDirty = TRUE;
  435. WsbTraceOut(OLESTR("CHsmStoragePool::SetNumMediaCopies"),OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  436. return( hr );
  437. }
  438. HRESULT
  439. CHsmStoragePool::GetManagementPolicy(
  440. GUID *pManagementPolicyId
  441. )
  442. /*++
  443. Routine Description:
  444. See IHsmStoragePool::
  445. Arguments:
  446. See IHsmStoragePool::
  447. Return Value:
  448. See IHsmStoragePool::
  449. --*/
  450. {
  451. HRESULT hr = S_OK;
  452. WsbTraceIn(OLESTR("CHsmStoragePool::GetManagementPolicy"),OLESTR(""));
  453. try {
  454. WsbAffirm(0 != pManagementPolicyId, E_POINTER);
  455. *pManagementPolicyId = m_PolicyId;
  456. } WsbCatch( hr );
  457. WsbTraceOut(OLESTR("CHsmStoragePool::GetManagementPolicy"),OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  458. return( hr );
  459. }
  460. HRESULT
  461. CHsmStoragePool::SetManagementPolicy(
  462. GUID managementPolicyId
  463. )
  464. /*++
  465. Routine Description:
  466. See IHsmStoragePool::
  467. Arguments:
  468. See IHsmStoragePool::
  469. Return Value:
  470. See IHsmStoragePool::
  471. --*/
  472. {
  473. HRESULT hr = S_OK;
  474. WsbTraceIn(OLESTR("CHsmStoragePool::SetManagementPolicy"),OLESTR(""));
  475. m_PolicyId = managementPolicyId;
  476. m_isDirty = TRUE;
  477. WsbTraceOut(OLESTR("CHsmStoragePool::SetManagementPolicy"),OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  478. return( hr );
  479. }
  480. HRESULT
  481. CHsmStoragePool::GetRmsMediaSet (
  482. IUnknown **ppIRmsMediaSet
  483. )
  484. /*++
  485. Routine Description:
  486. See IHsmStoragePool::
  487. Arguments:
  488. See IHsmStoragePool::
  489. Return Value:
  490. See IHsmStoragePool::
  491. --*/
  492. {
  493. HRESULT hr = S_OK;
  494. WsbTraceIn(OLESTR("CHsmStoragePool::GetRmsMediaSet"),OLESTR(""));
  495. try {
  496. WsbAffirm(0 != ppIRmsMediaSet, E_POINTER );
  497. hr = E_NOTIMPL;
  498. } WsbCatch( hr );
  499. WsbTraceOut(OLESTR("CHsmStoragePool::GetRmsMediaSet"),OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  500. return( hr );
  501. }
  502. #define HSM_DEFAULT_MAXSIZE_OPTICAL (1024)
  503. #define HSM_DEFAULT_MAXSIZE_TAPE (1024*10)
  504. HRESULT
  505. CHsmStoragePool::InitFromRmsMediaSet (
  506. IUnknown *pIRmsMediaSet
  507. )
  508. /*++
  509. Routine Description:
  510. See IHsmStoragePool::
  511. Arguments:
  512. See IHsmStoragePool::
  513. Return Value:
  514. See IHsmStoragePool::
  515. --*/
  516. {
  517. HRESULT hr = S_OK;
  518. WsbTraceIn(OLESTR("CHsmStoragePool::InitFromRmsMediaSet"),OLESTR(""));
  519. try {
  520. WsbAffirm(0 != pIRmsMediaSet, E_POINTER );
  521. //
  522. // Get the real interface
  523. //
  524. CComPtr<IRmsMediaSet> l_pIRmsMediaSet;
  525. WsbAffirmHr(pIRmsMediaSet->QueryInterface(IID_IRmsMediaSet, (void **)&l_pIRmsMediaSet));
  526. WsbAffirmHr(l_pIRmsMediaSet->GetMediaSetId(&m_MediaSetId));
  527. m_MediaSetName.Free();
  528. WsbAffirmHr(l_pIRmsMediaSet->GetName(&m_MediaSetName));
  529. // Set in the Registry which media type is being used
  530. // Set in the Registry max-file-size-to-migrate (in MB)
  531. // Note: This hack should be removed when HSM supports more than one media type on the same system
  532. LONG mediaType;
  533. DWORD dwType;
  534. DWORD dwSize;
  535. WsbAffirmHr(l_pIRmsMediaSet->GetMediaSupported(&mediaType));
  536. switch (mediaType) {
  537. case RmsMediaOptical:
  538. case RmsMediaFixed:
  539. case RmsMediaDVD:
  540. dwType = HSM_VALUE_TYPE_DIRECTACCESS;
  541. dwSize = HSM_DEFAULT_MAXSIZE_OPTICAL;
  542. break;
  543. case RmsMedia8mm:
  544. case RmsMedia4mm:
  545. case RmsMediaDLT:
  546. case RmsMediaTape:
  547. dwType = HSM_VALUE_TYPE_SEQUENTIAL;
  548. dwSize = HSM_DEFAULT_MAXSIZE_TAPE;
  549. break;
  550. default:
  551. // This is not expected, however, we set tape as default
  552. WsbTraceAlways(OLESTR("CHsmStoragePool::InitFromRmsMediaSet : Got an unexpected media type %ld !!!\n"), mediaType);
  553. dwType = HSM_VALUE_TYPE_SEQUENTIAL;
  554. dwSize = HSM_DEFAULT_MAXSIZE_TAPE;
  555. break;
  556. }
  557. WsbAffirmHr(WsbSetRegistryValueDWORD(NULL, HSM_ENGINE_REGISTRY_STRING, HSM_MEDIA_TYPE, dwType));
  558. WsbAffirmHr(WsbSetRegistryValueDWORD(NULL, HSM_ENGINE_REGISTRY_STRING, HSM_MAX_FILE_TO_MIGRATE, dwSize));
  559. } WsbCatch( hr );
  560. WsbTraceOut(OLESTR("CHsmStoragePool::InitFromRmsMediaSet"),OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  561. return( hr );
  562. }
  563. HRESULT
  564. CHsmStoragePool::GetMediaSetType (
  565. USHORT *pMediaType
  566. )
  567. /*++
  568. Routine Description:
  569. Gets the media type of the corresponding media set
  570. Arguments:
  571. pMediaType - media type, currently, the only options are direct-access or sequential
  572. Return Value:
  573. S_OK for success
  574. Notes:
  575. Future: Might consider keeping the media type instead of asking the media-set object again and again -
  576. Media type is not a dynamic propery. However, this reuires a change in the .col file structure.
  577. --*/
  578. {
  579. HRESULT hr = S_OK;
  580. WsbTraceIn(OLESTR("CHsmStoragePool::GetMediaSetType"),OLESTR(""));
  581. try {
  582. WsbAffirm(0 != pMediaType, E_POINTER );
  583. // Get media-set object
  584. CComPtr<IHsmServer> pHsmServer;
  585. CComPtr<IRmsServer> pRmsServer;
  586. CComPtr<IRmsMediaSet> pRmsMediaSet;
  587. WsbAssertHr(HsmConnectFromId(HSMCONN_TYPE_HSM, GUID_NULL, IID_IHsmServer, (void**) &pHsmServer));
  588. WsbAffirmHr(pHsmServer->GetHsmMediaMgr(&pRmsServer));
  589. WsbAffirmHr(pRmsServer->CreateObject(m_MediaSetId, CLSID_CRmsMediaSet, IID_IRmsMediaSet, RmsOpenExisting, (void **)&pRmsMediaSet));
  590. // Determine media type
  591. LONG mediaType;
  592. WsbAffirmHr(pRmsMediaSet->GetMediaSupported(&mediaType));
  593. switch (mediaType) {
  594. case RmsMediaOptical:
  595. case RmsMediaFixed:
  596. case RmsMediaDVD:
  597. *pMediaType = HSM_VALUE_TYPE_DIRECTACCESS;
  598. break;
  599. case RmsMedia8mm:
  600. case RmsMedia4mm:
  601. case RmsMediaDLT:
  602. case RmsMediaTape:
  603. *pMediaType = HSM_VALUE_TYPE_SEQUENTIAL;
  604. break;
  605. default:
  606. // This is not expected, however, we set tape as default
  607. WsbTraceAlways(OLESTR("CHsmStoragePool::GetMediaSetType : Got an unexpected media type %hu !!!\n"), *pMediaType);
  608. *pMediaType = HSM_VALUE_TYPE_SEQUENTIAL;
  609. break;
  610. }
  611. } WsbCatch( hr );
  612. WsbTraceOut(OLESTR("CHsmStoragePool::GetMediaSetType"),OLESTR("Media-type = %hu hr = <%ls>"), *pMediaType, WsbHrAsString(hr));
  613. return( hr );
  614. }