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.

2609 lines
56 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. RmsCartg.cpp
  5. Abstract:
  6. Implementation of CRmsCartridge
  7. Author:
  8. Brian Dodd [brian] 15-Nov-1996
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "RmsCartg.h"
  13. #include "RmsNTMS.h"
  14. #include "RmsServr.h"
  15. int CRmsCartridge::s_InstanceCount = 0;
  16. #define RMS_USE_ACTIVE_COLLECTION 1
  17. ////////////////////////////////////////////////////////////////////////////////
  18. //
  19. // Base class implementations
  20. //
  21. STDMETHODIMP
  22. CRmsCartridge::CompareTo(
  23. IN IUnknown *pCollectable,
  24. OUT SHORT *pResult
  25. )
  26. /*++
  27. Implements:
  28. IWsbCollectable::CompareTo
  29. --*/
  30. {
  31. HRESULT hr = E_FAIL;
  32. SHORT result = 1;
  33. WsbTraceIn( OLESTR("CRmsCartridge::CompareTo"), OLESTR("") );
  34. try {
  35. // Validate arguments - Okay if pResult is NULL
  36. WsbAssertPointer( pCollectable );
  37. // We need the IRmsCartridge interface to get the value of the object.
  38. CComQIPtr<IRmsCartridge, &IID_IRmsCartridge> pCartridge = pCollectable;
  39. WsbAssertPointer( pCartridge );
  40. // Get find by option
  41. CComQIPtr<IRmsComObject, &IID_IRmsComObject> pObject = pCollectable;
  42. WsbAssertPointer( pObject );
  43. switch ( m_findBy ) {
  44. case RmsFindByName:
  45. {
  46. CWsbBstrPtr name;
  47. // Get name
  48. WsbAffirmHr( pCartridge->GetName( &name ) );
  49. // Compare the names
  50. result = (USHORT)wcscmp( m_Name, name );
  51. hr = ( 0 == result ) ? S_OK : S_FALSE;
  52. }
  53. break;
  54. case RmsFindByExternalLabel:
  55. {
  56. CWsbBstrPtr externalLabel;
  57. LONG externalNumber;
  58. // Get external label
  59. WsbAffirmHr( pCartridge->GetTagAndNumber(&externalLabel, &externalNumber) );
  60. // Compare the label
  61. result = (SHORT)wcscmp( m_externalLabel, externalLabel );
  62. hr = ( 0 == result ) ? S_OK : S_FALSE;
  63. }
  64. break;
  65. case RmsFindByExternalNumber:
  66. {
  67. CWsbBstrPtr externalLabel;
  68. LONG externalNumber;
  69. // Get external number
  70. WsbAffirmHr( pCartridge->GetTagAndNumber(&externalLabel, &externalNumber) );
  71. if( m_externalNumber == externalNumber ) {
  72. // External numbers match
  73. hr = S_OK;
  74. result = 0;
  75. }
  76. else {
  77. hr = S_FALSE;
  78. result = 1;
  79. }
  80. }
  81. break;
  82. case RmsFindByScratchMediaCriteria:
  83. {
  84. RmsStatus status;
  85. GUID mediaSetIdToFind, mediaSetId;
  86. WsbAssertHr(pCartridge->GetStatus((LONG *)&status));
  87. WsbAssertHr(pCartridge->GetMediaSetId(&mediaSetId));
  88. WsbAssertHr(GetMediaSetId(&mediaSetIdToFind));
  89. if ( (RmsStatusScratch == status) && (mediaSetIdToFind == mediaSetId)) {
  90. // Status is scratch
  91. hr = S_OK;
  92. result = 0;
  93. }
  94. else {
  95. hr = S_FALSE;
  96. result = 1;
  97. }
  98. }
  99. break;
  100. case RmsFindByCartridgeId:
  101. case RmsFindByObjectId:
  102. default:
  103. // Do CompareTo for object
  104. hr = CRmsComObject::CompareTo( pCollectable, &result );
  105. break;
  106. }
  107. }
  108. WsbCatch( hr );
  109. if ( SUCCEEDED(hr) && (0 != pResult) ) {
  110. *pResult = result;
  111. }
  112. WsbTraceOut( OLESTR("CRmsCartridge::CompareTo"),
  113. OLESTR("hr = <%ls>, result = <%ls>"),
  114. WsbHrAsString( hr ), WsbPtrToShortAsString( pResult ) );
  115. return hr;
  116. }
  117. HRESULT
  118. CRmsCartridge::FinalConstruct(
  119. void
  120. )
  121. /*++
  122. Implements:
  123. CComObjectRoot::FinalConstruct
  124. --*/
  125. {
  126. HRESULT hr = S_OK;
  127. WsbTraceIn(OLESTR("CRmsCartridge::FinalConstruct"), OLESTR("this = %p"),
  128. static_cast<void *>(this));
  129. try {
  130. WsbAssertHr(CWsbObject::FinalConstruct());
  131. // Initialize fields
  132. m_Name = OLESTR("");
  133. m_Description = OLESTR("");
  134. m_externalLabel = OLESTR("");
  135. m_externalNumber = 0;
  136. m_sizeofOnMediaId = 0;
  137. m_typeofOnMediaId = 0;
  138. m_pOnMediaId = 0;
  139. m_onMediaLabel = RMS_UNDEFINED_STRING;
  140. m_status = RmsStatusUnknown;
  141. m_type = RmsMediaUnknown;
  142. m_BlockSize = 0;
  143. m_isTwoSided = 0;
  144. m_isMounted = 0;
  145. m_isInTransit = 0;
  146. m_isAvailable = 0;
  147. m_isMountedSerialized = 0;
  148. m_home.SetLocation(0,GUID_NULL,GUID_NULL,0,0,0,0,0);
  149. m_location.SetLocation(0,GUID_NULL,GUID_NULL,0,0,0,0,0);
  150. m_destination.SetLocation(0,GUID_NULL,GUID_NULL,0,0,0,0,0);
  151. m_mailStop = RMS_UNDEFINED_STRING;
  152. m_pDrive = 0;
  153. m_sizeofInfo = 0;
  154. for (int i = 0; i < RMS_STR_MAX_CARTRIDGE_INFO; i++){
  155. m_info[i] = 0;
  156. }
  157. m_ownerClassId = GUID_NULL;
  158. m_pParts = 0;
  159. m_verifierClass = GUID_NULL;
  160. m_portalClass = GUID_NULL;
  161. m_pDataCache = NULL;
  162. m_DataCacheSize = 0;
  163. m_DataCacheUsed = 0;
  164. m_DataCacheStartPBA.QuadPart = 0;
  165. m_ManagedBy = RmsMediaManagerUnknown;
  166. } WsbCatch(hr);
  167. s_InstanceCount++;
  168. WsbTraceAlways(OLESTR("CRmsCartridge::s_InstanceCount += %d\n"), s_InstanceCount);
  169. WsbTraceOut(OLESTR("CRmsCartridge::FinalConstruct"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  170. return(hr);
  171. }
  172. STDMETHODIMP
  173. CRmsCartridge::FinalRelease(void)
  174. {
  175. HRESULT hr = S_OK;
  176. WsbTraceIn(OLESTR("CRmsCartridge::FinalRelease"), OLESTR("this = %p"),
  177. static_cast<void *>(this));
  178. try {
  179. if (m_pOnMediaId) {
  180. WsbFree(m_pOnMediaId);
  181. m_pOnMediaId = NULL;
  182. m_sizeofOnMediaId = 0;
  183. m_typeofOnMediaId = 0;
  184. }
  185. if (m_pDataCache) {
  186. WsbFree(m_pDataCache);
  187. m_pDataCache = NULL;
  188. m_DataCacheSize = 0;
  189. m_DataCacheUsed = 0;
  190. m_DataCacheStartPBA.QuadPart = 0;
  191. }
  192. CWsbObject::FinalRelease();
  193. } WsbCatch(hr);
  194. s_InstanceCount--;
  195. WsbTraceAlways(OLESTR("CRmsCartridge::s_InstanceCount -= %d\n"), s_InstanceCount);
  196. WsbTraceOut(OLESTR("CRmsCartridge::FinalRelease"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  197. return(hr);
  198. }
  199. STDMETHODIMP
  200. CRmsCartridge::GetClassID(
  201. OUT CLSID* pClsid
  202. )
  203. /*++
  204. Implements:
  205. IPersist::GetClassId
  206. --*/
  207. {
  208. HRESULT hr = S_OK;
  209. WsbTraceIn(OLESTR("CRmsCartridge::GetClassID"), OLESTR(""));
  210. try {
  211. WsbAssertPointer(pClsid);
  212. *pClsid = CLSID_CRmsCartridge;
  213. } WsbCatch(hr);
  214. WsbTraceOut(OLESTR("CRmsCartridge::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  215. return(hr);
  216. }
  217. STDMETHODIMP
  218. CRmsCartridge::GetSizeMax(
  219. OUT ULARGE_INTEGER* pcbSize
  220. )
  221. /*++
  222. Implements:
  223. IPersistStream::GetSizeMax
  224. --*/
  225. {
  226. HRESULT hr = E_NOTIMPL;
  227. // ULONG nameLen;
  228. // ULONG externalLabelLen;
  229. // ULONG mailStopLen;
  230. // WsbTraceIn(OLESTR("CRmsCartridge::GetSizeMax"), OLESTR(""));
  231. // try {
  232. // WsbAssert(0 != pcbSize, E_POINTER);
  233. // nameLen = SysStringByteLen(m_name);
  234. // externalLabelLen = SysStringByteLen(m_externalLabel);
  235. // mailStopLen = SysStringByteLen(m_mailStop);
  236. // // set up size of CRmsCartridge
  237. // pcbSize->QuadPart = WsbPersistSizeOf(GUID) + // m_cartridgeId
  238. // WsbPersistSizeOf(ULONG) + // length of m_name
  239. // nameLen + // m_name
  240. // WsbPersistSizeOf(ULONG) + // length of m_externalLabel
  241. // externalLabelLen + // m_externalLabel
  242. // WsbPersistSizeOf(LONG) + // m_externalNumber
  243. // WsbPersistSizeOf(LONG) + // m_status
  244. // WsbPersistSizeOf(LONG) + // m_type
  245. // WsbPersistSizeOf(BOOL) + // m_isTwoSided
  246. // WsbPersistSizeOf(CRmsLocator) + // m_home
  247. // WsbPersistSizeOf(CRmsLocator) + // m_location
  248. // WsbPersistSizeOf(ULONG) + // size of m_mailStop
  249. // mailStopLen + // m_mailStop
  250. // WsbPersistSizeOf(SHORT) + // m_sizeofInfo
  251. // RMS_STR_MAX_CARTRIDGE_INFO + // m_Info
  252. // WsbPersistSizeOf(CLSID) + // m_ownerClassId
  253. // // m_pParts
  254. //// WsbPersistSizeOf(CComPtr<IWsbIndexedCollection>) +
  255. // WsbPersistSizeOf(CLSID) + // m_verifierClass
  256. // WsbPersistSizeOf(CLSID); // m_portalClass
  257. // } WsbCatch(hr);
  258. WsbTraceOut(OLESTR("CRmsCartridge::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pcbSize));
  259. return(hr);
  260. }
  261. STDMETHODIMP
  262. CRmsCartridge::Load(
  263. IN IStream* pStream
  264. )
  265. /*++
  266. Implements:
  267. IPersistStream::Load
  268. --*/
  269. {
  270. HRESULT hr = S_OK;
  271. WsbTraceIn(OLESTR("CRmsCartridge::Load"), OLESTR(""));
  272. try {
  273. ULONG temp;
  274. WsbAssert(0 != pStream, E_POINTER);
  275. WsbAffirmHr(CRmsStorageInfo::Load(pStream));
  276. WsbAffirmHr(WsbLoadFromStream(pStream, &m_objectId));
  277. m_externalLabel.Free();
  278. WsbAffirmHr(WsbBstrFromStream(pStream, &m_externalLabel));
  279. WsbAffirmHr(WsbLoadFromStream(pStream, &m_externalNumber));
  280. WsbAffirmHr(WsbLoadFromStream(pStream, &temp));
  281. m_status = (RmsStatus)temp;
  282. WsbAffirmHr(WsbLoadFromStream(pStream, &temp));
  283. m_type = (RmsMedia)temp;
  284. WsbAffirmHr(WsbLoadFromStream(pStream, &m_BlockSize));
  285. WsbAffirmHr(WsbLoadFromStream(pStream, &m_isTwoSided));
  286. WsbAffirmHr(m_home.Load(pStream));
  287. WsbAffirmHr(m_location.Load(pStream));
  288. m_mailStop.Free();
  289. WsbAffirmHr(WsbBstrFromStream(pStream, &m_mailStop));
  290. // WsbAffirmHr(m_pParts->Load(pStream));
  291. WsbAffirmHr(WsbLoadFromStream(pStream, &m_sizeofInfo));
  292. WsbAffirmHr(WsbLoadFromStream(pStream, &m_info[0], MaxInfo));
  293. WsbAffirmHr(WsbLoadFromStream(pStream, &m_ownerClassId));
  294. WsbAffirmHr(WsbLoadFromStream(pStream, &m_verifierClass));
  295. WsbAffirmHr(WsbLoadFromStream(pStream, &m_portalClass));
  296. } WsbCatch(hr);
  297. WsbTraceOut(OLESTR("CRmsCartridge::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  298. return(hr);
  299. }
  300. STDMETHODIMP
  301. CRmsCartridge::Save(
  302. IN IStream* pStream,
  303. IN BOOL clearDirty
  304. )
  305. /*++
  306. Implements:
  307. IPersistStream::Save
  308. --*/
  309. {
  310. HRESULT hr = S_OK;
  311. WsbTraceIn(OLESTR("CRmsCartridge::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  312. try {
  313. WsbAssert(0 != pStream, E_POINTER);
  314. WsbAffirmHr(CRmsStorageInfo::Save(pStream, clearDirty));
  315. WsbAffirmHr(WsbSaveToStream(pStream, m_objectId));
  316. WsbAffirmHr(WsbBstrToStream(pStream, m_externalLabel));
  317. WsbAffirmHr(WsbSaveToStream(pStream, m_externalNumber));
  318. WsbAffirmHr(WsbSaveToStream(pStream, (ULONG) m_status));
  319. WsbAffirmHr(WsbSaveToStream(pStream, (ULONG) m_type));
  320. WsbAffirmHr(WsbSaveToStream(pStream, m_BlockSize));
  321. WsbAffirmHr(WsbSaveToStream(pStream, m_isTwoSided));
  322. WsbAffirmHr(m_home.Save(pStream, clearDirty));
  323. WsbAffirmHr(m_location.Save(pStream, clearDirty));
  324. WsbAffirmHr(WsbBstrToStream(pStream, m_mailStop));
  325. // WsbAffirmHr(m_pParts->Save(pStream, clearDirty));
  326. WsbAffirmHr(WsbSaveToStream(pStream, m_sizeofInfo));
  327. WsbAffirmHr(WsbSaveToStream(pStream, &m_info [0], MaxInfo));
  328. WsbAffirmHr(WsbSaveToStream(pStream, m_ownerClassId));
  329. WsbAffirmHr(WsbSaveToStream(pStream, m_verifierClass));
  330. WsbAffirmHr(WsbSaveToStream(pStream, m_portalClass));
  331. // Do we need to clear the dirty bit?
  332. if (clearDirty) {
  333. m_isDirty = FALSE;
  334. }
  335. } WsbCatch(hr);
  336. WsbTraceOut(OLESTR("CRmsCartridge::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  337. return(hr);
  338. }
  339. STDMETHODIMP
  340. CRmsCartridge::Test(
  341. OUT USHORT *pPassed,
  342. OUT USHORT *pFailed
  343. )
  344. /*++
  345. Implements:
  346. IWsbTestable::Test
  347. --*/
  348. {
  349. HRESULT hr = S_OK;
  350. CComPtr<IRmsCartridge> pCartridge1;
  351. CComPtr<IRmsCartridge> pCartridge2;
  352. CComPtr<IPersistFile> pFile1;
  353. CComPtr<IPersistFile> pFile2;
  354. LONG passFail;
  355. LONG i;
  356. CWsbBstrPtr bstrVal1 = OLESTR("5A5A5A");
  357. CWsbBstrPtr bstrVal2 = OLESTR("A5A5A5");
  358. CWsbBstrPtr bstrWork1;
  359. CWsbBstrPtr bstrWork2;
  360. LONG longVal1 = 0x11111111;
  361. LONG longVal2 = 0x22222222;
  362. LONG longVal3 = 0x33333333;
  363. LONG longVal4 = 0x44444444;
  364. LONG longWork0;
  365. LONG longWork1;
  366. LONG longWork2;
  367. LONG longWork3;
  368. LONG longWork4;
  369. LONG mediaTable [RMSMAXMEDIATYPES] = { RmsMediaUnknown,
  370. RmsMedia8mm,
  371. RmsMedia4mm,
  372. RmsMediaDLT,
  373. RmsMediaOptical,
  374. RmsMediaMO35,
  375. RmsMediaWORM,
  376. RmsMediaCDR,
  377. RmsMediaDVD,
  378. RmsMediaDisk,
  379. RmsMediaFixed,
  380. RmsMediaTape };
  381. GUID guidVal1 = { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
  382. GUID guidVal2 = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
  383. GUID guidWork1;
  384. GUID guidWork2;
  385. BOOL boolTrue = TRUE;
  386. BOOL boolFalse = FALSE;
  387. BOOL boolWork1;
  388. WsbTraceIn(OLESTR("CRmsCartridge::Test"), OLESTR(""));
  389. try {
  390. // Get the Cartridge interface.
  391. hr = S_OK;
  392. try {
  393. WsbAssertHr(((IUnknown*) (IRmsCartridge*) this)->QueryInterface(IID_IRmsCartridge, (void**) &pCartridge1));
  394. // Test SetName & GetName interface
  395. bstrWork1 = bstrVal1;
  396. SetName(bstrWork1);
  397. GetName(&bstrWork2);
  398. if (bstrWork1 == bstrWork2){
  399. (*pPassed)++;
  400. } else {
  401. (*pFailed)++;
  402. }
  403. // Test SetTagAndNumber & GetTagAndNumber
  404. bstrWork1 = bstrVal2;
  405. longWork1 = 99;
  406. SetTagAndNumber(bstrWork1, longWork1);
  407. GetTagAndNumber(&bstrWork2, &longWork2);
  408. if ((bstrWork1 == bstrWork2) && (longWork1 == longWork2)){
  409. (*pPassed)++;
  410. } else {
  411. (*pFailed)++;
  412. }
  413. // Test SetIsTwoSided & IsTwoSided to True
  414. hr = S_OK;
  415. try{
  416. WsbAffirmHr(SetIsTwoSided (TRUE));
  417. WsbAffirmHr(IsTwoSided ());
  418. } WsbCatch (hr);
  419. if (hr == S_OK){
  420. (*pPassed)++;
  421. } else {
  422. (*pFailed)++;
  423. }
  424. // Test SetTwoSided & IsTwoSided to FALSE
  425. hr = S_OK;
  426. try{
  427. WsbAffirmHr(SetIsTwoSided (FALSE));
  428. WsbAffirmHr(IsTwoSided ());
  429. } WsbCatch (hr);
  430. if (hr == S_OK){
  431. (*pFailed)++;
  432. } else {
  433. (*pPassed)++;
  434. }
  435. // Test SetStatus & GetStatus
  436. for (i = RmsStatusUnknown; i < RmsStatusCleaning; i++){
  437. longWork1 = i;
  438. SetStatus (longWork1);
  439. GetStatus (&longWork2);
  440. if (longWork1 == longWork2){
  441. (*pPassed)++;
  442. } else {
  443. (*pFailed)++;
  444. }
  445. }
  446. // Test SetType & GetType
  447. for (i = RmsMediaUnknown; i < RMSMAXMEDIATYPES; i++){
  448. longWork1 = mediaTable[i];
  449. SetType (longWork1);
  450. GetType (&longWork2);
  451. if (longWork1 == longWork2){
  452. (*pPassed)++;
  453. } else {
  454. (*pFailed)++;
  455. }
  456. }
  457. // Test SetHome & GetHome
  458. SetHome (RmsMediaOptical, guidVal1, guidVal2, longVal1, longVal2,
  459. longVal3, longVal4, boolTrue);
  460. GetHome (&longWork0, &guidWork1, &guidWork2, &longWork1, &longWork2,
  461. &longWork3, &longWork4, &boolWork1);
  462. passFail = 0;
  463. if (longWork0 == RmsMediaOptical){
  464. passFail++;
  465. }
  466. if (guidWork1 == guidVal1){
  467. passFail++;
  468. }
  469. if (guidWork2 == guidVal2){
  470. passFail++;
  471. }
  472. if (longWork1 == longVal1){
  473. passFail++;
  474. }
  475. if (longWork2 == longVal2){
  476. passFail++;
  477. }
  478. if (longWork3 == longVal3){
  479. passFail++;
  480. }
  481. if (longWork4 == longVal4){
  482. passFail++;
  483. }
  484. if (boolWork1 == TRUE){
  485. passFail++;
  486. }
  487. if (passFail == 8){
  488. (*pPassed)++;
  489. } else {
  490. (*pFailed)++;
  491. }
  492. // Test SetLocation & GetLocation
  493. SetLocation (RmsMediaOptical, guidVal1, guidVal2, longVal1, longVal2,
  494. longVal3, longVal4, boolTrue);
  495. GetLocation (&longWork0, &guidWork1, &guidWork2, &longWork1, &longWork2,
  496. &longWork3, &longWork4, &boolWork1);
  497. passFail = 0;
  498. if (longWork0 == RmsMediaOptical){
  499. passFail++;
  500. }
  501. if (guidWork1 == guidVal1){
  502. passFail++;
  503. }
  504. if (guidWork2 == guidVal2){
  505. passFail++;
  506. }
  507. if (longWork1 == longVal1){
  508. passFail++;
  509. }
  510. if (longWork2 == longVal2){
  511. passFail++;
  512. }
  513. if (longWork3 == longVal3){
  514. passFail++;
  515. }
  516. if (longWork4 == longVal4){
  517. passFail++;
  518. }
  519. if (boolWork1 == TRUE){
  520. passFail++;
  521. }
  522. if (passFail == 8){
  523. (*pPassed)++;
  524. } else {
  525. (*pFailed)++;
  526. }
  527. // Test SetMailStop & GetMailStop interface
  528. SetName(bstrVal1);
  529. GetName(&bstrWork1);
  530. if ((bstrWork1 = bstrVal1) == 0){
  531. (*pPassed)++;
  532. } else {
  533. (*pFailed)++;
  534. }
  535. } WsbCatch(hr);
  536. // Tally up the results
  537. hr = S_OK;
  538. if (*pFailed) {
  539. hr = S_FALSE;
  540. }
  541. } WsbCatch(hr);
  542. WsbTraceOut(OLESTR("CRmsCartridge::Test"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  543. return(hr);
  544. }
  545. ////////////////////////////////////////////////////////////////////////////////
  546. //
  547. // IRmsCartridge implementation
  548. //
  549. STDMETHODIMP
  550. CRmsCartridge::GetCartridgeId(
  551. GUID *pCartId
  552. )
  553. /*++
  554. Implements:
  555. IRmsCartridge::GetCartridgeId
  556. --*/
  557. {
  558. HRESULT hr = E_FAIL;
  559. try {
  560. WsbAssertPointer( pCartId );
  561. *pCartId = m_objectId;
  562. hr = S_OK;
  563. }
  564. WsbCatch(hr)
  565. return hr;
  566. }
  567. STDMETHODIMP
  568. CRmsCartridge::SetCartridgeId(
  569. GUID cartId
  570. )
  571. /*++
  572. Implements:
  573. IRmsCartridge::SetMediaSetId
  574. --*/
  575. {
  576. m_objectId = cartId;
  577. m_isDirty = TRUE;
  578. return S_OK;
  579. }
  580. STDMETHODIMP
  581. CRmsCartridge::GetMediaSetId(
  582. GUID *pMediaSetId
  583. )
  584. /*++
  585. Implements:
  586. IRmsCartridge::GetMediaSetId
  587. --*/
  588. {
  589. HRESULT hr = E_FAIL;
  590. try {
  591. WsbAssertPointer( pMediaSetId );
  592. *pMediaSetId = m_location.m_mediaSetId;
  593. hr = S_OK;
  594. }
  595. WsbCatch(hr)
  596. return hr;
  597. }
  598. STDMETHODIMP
  599. CRmsCartridge::SetMediaSetId(
  600. GUID mediaSetId
  601. )
  602. /*++
  603. Implements:
  604. IRmsCartridge::SetMediaSetId
  605. --*/
  606. {
  607. m_location.m_mediaSetId = mediaSetId;
  608. m_isDirty = TRUE;
  609. return S_OK;
  610. }
  611. STDMETHODIMP
  612. CRmsCartridge::GetName(
  613. BSTR *pName
  614. )
  615. /*++
  616. Implements:
  617. IRmsCartridge::GetName
  618. --*/
  619. {
  620. HRESULT hr = E_FAIL;
  621. try {
  622. WsbAssertPointer(pName);
  623. WsbAffirmHr( m_Name.CopyToBstr(pName) );
  624. hr = S_OK;
  625. }
  626. WsbCatch(hr);
  627. return hr;
  628. }
  629. STDMETHODIMP
  630. CRmsCartridge::SetName(
  631. BSTR name
  632. )
  633. /*++
  634. Implements:
  635. IRmsCartridge::SetName
  636. --*/
  637. {
  638. m_Name = name;
  639. m_isDirty = TRUE;
  640. return S_OK;
  641. }
  642. STDMETHODIMP
  643. CRmsCartridge::GetDescription(
  644. BSTR *pDescription
  645. )
  646. /*++
  647. Implements:
  648. IRmsCartridge::GetDescription
  649. --*/
  650. {
  651. HRESULT hr = E_FAIL;
  652. try {
  653. WsbAssertPointer(pDescription);
  654. WsbAffirmHr( m_Description.CopyToBstr(pDescription) );
  655. hr = S_OK;
  656. }
  657. WsbCatch(hr);
  658. return hr;
  659. }
  660. STDMETHODIMP
  661. CRmsCartridge::SetDescription(
  662. BSTR description
  663. )
  664. /*++
  665. Implements:
  666. IRmsCartridge::SetDescription
  667. --*/
  668. {
  669. m_Description = description;
  670. m_isDirty = TRUE;
  671. return S_OK;
  672. }
  673. STDMETHODIMP
  674. CRmsCartridge::GetTagAndNumber(
  675. BSTR *pTag,
  676. LONG *pNumber
  677. )
  678. /*++
  679. Implements:
  680. IRmsCartridge::GetTagAndNumber
  681. --*/
  682. {
  683. HRESULT hr = E_FAIL;
  684. try {
  685. WsbAssertPointer(pTag);
  686. WsbAssertPointer(pNumber);
  687. WsbAffirmHr( m_externalLabel.CopyToBstr(pTag) );
  688. *pNumber = m_externalNumber;
  689. hr = S_OK;
  690. }
  691. WsbCatch(hr);
  692. return hr;
  693. }
  694. STDMETHODIMP
  695. CRmsCartridge::SetTagAndNumber(
  696. BSTR tag,
  697. LONG number
  698. )
  699. /*++
  700. Implements:
  701. IRmsCartridge::SetTagAndNumber
  702. --*/
  703. {
  704. m_externalLabel = tag;
  705. m_externalNumber = number;
  706. m_isDirty = TRUE;
  707. return S_OK;
  708. }
  709. STDMETHODIMP
  710. CRmsCartridge::GetBarcode(
  711. BSTR *pBarcode
  712. )
  713. /*++
  714. Implements:
  715. IRmsCartridge::GetBarcode
  716. --*/
  717. {
  718. HRESULT hr = S_OK;
  719. try {
  720. WsbAssertPointer(pBarcode);
  721. WsbAffirm(wcslen((WCHAR*)m_externalLabel) > 0, E_FAIL);
  722. WsbAffirmHr(m_externalLabel.CopyToBstr(pBarcode));
  723. } WsbCatch(hr);
  724. return hr;
  725. }
  726. STDMETHODIMP
  727. CRmsCartridge::GetOnMediaIdentifier(
  728. BYTE *pIdentifier,
  729. LONG *pSize,
  730. LONG *pType
  731. )
  732. /*++
  733. Implements:
  734. IRmsCartridge::GetOnMediaIdentifier
  735. --*/
  736. {
  737. HRESULT hr = E_FAIL;
  738. try {
  739. WsbAssertPointer( pIdentifier );
  740. WsbAssertPointer( pSize );
  741. WsbAssertPointer( pType );
  742. memmove (pIdentifier, m_pOnMediaId, m_sizeofOnMediaId);
  743. *pSize = m_sizeofOnMediaId;
  744. *pType = m_typeofOnMediaId;
  745. hr = S_OK;
  746. }
  747. WsbCatch(hr);
  748. return hr;
  749. }
  750. STDMETHODIMP
  751. CRmsCartridge::SetOnMediaIdentifier(
  752. BYTE *pIdentifier,
  753. LONG size,
  754. LONG type
  755. )
  756. /*++
  757. Implements:
  758. IRmsCartridge::SetOnMediaIdentifier
  759. --*/
  760. {
  761. HRESULT hr = E_FAIL;
  762. try {
  763. WsbAssertPointer( pIdentifier );
  764. CComPtr<IRmsNTMS> pNtms;
  765. if ( m_pOnMediaId ) {
  766. WsbFree( m_pOnMediaId );
  767. m_pOnMediaId = 0;
  768. }
  769. m_pOnMediaId = (BYTE *)WsbAlloc( size );
  770. WsbAffirmPointer(m_pOnMediaId);
  771. memset(m_pOnMediaId, 0, size);
  772. memmove (m_pOnMediaId, pIdentifier, size);
  773. m_sizeofOnMediaId = size;
  774. m_typeofOnMediaId = type;
  775. m_isDirty = TRUE;
  776. if (RmsMediaManagerNTMS == m_ManagedBy) {
  777. // Now update any external database
  778. CComQIPtr<IRmsServer, &IID_IRmsServer> pServer = g_pServer;
  779. WsbAffirmHr( pServer->GetNTMS( &pNtms ) );
  780. WsbAffirmHr( pNtms->UpdateOmidInfo( m_objectId, pIdentifier, size, type ) );
  781. }
  782. hr = S_OK;
  783. } WsbCatch(hr);
  784. return hr;
  785. }
  786. STDMETHODIMP
  787. CRmsCartridge::GetOnMediaLabel(
  788. BSTR *pLabel
  789. )
  790. /*++
  791. Implements:
  792. IRmsCartridge::GetOnMediaLabel
  793. --*/
  794. {
  795. HRESULT hr = E_FAIL;
  796. try {
  797. WsbAssertPointer(pLabel);
  798. WsbAffirmHr( m_onMediaLabel.CopyToBstr(pLabel) );
  799. hr = S_OK;
  800. }
  801. WsbCatch(hr);
  802. return hr;
  803. }
  804. STDMETHODIMP
  805. CRmsCartridge::SetOnMediaLabel(
  806. BSTR label
  807. )
  808. /*++
  809. Implements:
  810. IRmsCartridge::SetOnMediaLabel
  811. --*/
  812. {
  813. m_onMediaLabel = label;
  814. m_isDirty = TRUE;
  815. return S_OK;
  816. }
  817. STDMETHODIMP CRmsCartridge::GetStatus(
  818. LONG *pStatus
  819. )
  820. /*++
  821. Implements:
  822. IRmsCartridge::GetStatus
  823. --*/
  824. {
  825. *pStatus = m_status;
  826. return S_OK;
  827. }
  828. STDMETHODIMP CRmsCartridge::SetStatus(
  829. LONG status
  830. )
  831. /*++
  832. Implements:
  833. IRmsCartridge::SetStatus
  834. --*/
  835. {
  836. m_status = (RmsStatus)status;
  837. m_isDirty = TRUE;
  838. return S_OK;
  839. }
  840. STDMETHODIMP
  841. CRmsCartridge::GetType(
  842. LONG *pType
  843. )
  844. /*++
  845. Implements:
  846. IRmsCartridge::GetType
  847. --*/
  848. {
  849. *pType = (LONG) m_type;
  850. return S_OK;
  851. }
  852. STDMETHODIMP
  853. CRmsCartridge::SetType(
  854. LONG type
  855. )
  856. /*++
  857. Implements:
  858. IRmsCartridge::SetType
  859. --*/
  860. {
  861. m_type = (RmsMedia) type;
  862. m_isDirty = TRUE;
  863. return S_OK;
  864. }
  865. STDMETHODIMP
  866. CRmsCartridge::GetBlockSize(
  867. LONG *pBlockSize
  868. )
  869. /*++
  870. Implements:
  871. IRmsCartridge::GetBlockSize
  872. --*/
  873. {
  874. HRESULT hr = S_OK;
  875. try {
  876. if (!m_BlockSize) {
  877. if (RmsMediaManagerNTMS == m_ManagedBy) {
  878. LONG blockSize;
  879. CComPtr<IRmsNTMS> pNtms;
  880. CComQIPtr<IRmsServer, &IID_IRmsServer> pServer = g_pServer;
  881. WsbAffirmHr(pServer->GetNTMS(&pNtms));
  882. if (S_OK == pNtms->GetBlockSize(m_objectId, &blockSize)) {
  883. m_BlockSize = blockSize;
  884. }
  885. }
  886. }
  887. *pBlockSize = m_BlockSize;
  888. } WsbCatch(hr);
  889. return hr;
  890. }
  891. STDMETHODIMP
  892. CRmsCartridge::SetBlockSize(
  893. LONG blockSize
  894. )
  895. /*++
  896. Implements:
  897. IRmsCartridge::SetBlockSize
  898. --*/
  899. {
  900. HRESULT hr = S_OK;
  901. try {
  902. if (RmsMediaManagerNTMS == m_ManagedBy) {
  903. // Update external database
  904. CComPtr<IRmsNTMS> pNtms;
  905. CComQIPtr<IRmsServer, &IID_IRmsServer> pServer = g_pServer;
  906. WsbAffirmHr(pServer->GetNTMS(&pNtms));
  907. WsbAffirmHr(pNtms->SetBlockSize(m_objectId, blockSize));
  908. }
  909. m_BlockSize = blockSize;
  910. m_isDirty = TRUE;
  911. } WsbCatch(hr);
  912. return hr;
  913. }
  914. STDMETHODIMP
  915. CRmsCartridge::SetIsTwoSided(
  916. BOOL flag
  917. )
  918. /*++
  919. Implements:
  920. IRmsCartridge::SetTwoSided
  921. --*/
  922. {
  923. m_isTwoSided = flag;
  924. m_isDirty = TRUE;
  925. return S_OK;
  926. }
  927. STDMETHODIMP
  928. CRmsCartridge::IsTwoSided(
  929. VOID
  930. )
  931. /*++
  932. Implements:
  933. IRmsCartridge::IsTwoSided
  934. --*/
  935. {
  936. HRESULT hr = E_FAIL;
  937. hr = m_isTwoSided ? S_OK : S_FALSE;
  938. return (hr);
  939. }
  940. STDMETHODIMP
  941. CRmsCartridge::SetIsMounted(
  942. BOOL flag
  943. )
  944. /*++
  945. Implements:
  946. IRmsCartridge::SetMounted
  947. --*/
  948. {
  949. m_isMounted = flag;
  950. if ( FALSE == m_isMounted ) {
  951. m_pDrive = 0;
  952. }
  953. return S_OK;
  954. }
  955. STDMETHODIMP
  956. CRmsCartridge::IsMounted(
  957. VOID
  958. )
  959. /*++
  960. Implements:
  961. IRmsCartridge::IsMounted
  962. --*/
  963. {
  964. HRESULT hr = E_FAIL;
  965. hr = m_isMounted ? S_OK : S_FALSE;
  966. return (hr);
  967. }
  968. STDMETHODIMP CRmsCartridge::GetHome(
  969. LONG *pType,
  970. GUID *pLibId,
  971. GUID *pMediaSetId,
  972. LONG *pPos,
  973. LONG *pAlt1,
  974. LONG *pAlt2,
  975. LONG *pAlt3,
  976. BOOL *pInvert
  977. )
  978. /*++
  979. Implements:
  980. IRmsCartridge::GetHome
  981. --*/
  982. {
  983. return m_home.GetLocation(pType,
  984. pLibId,
  985. pMediaSetId,
  986. pPos,
  987. pAlt1,
  988. pAlt2,
  989. pAlt3,
  990. pInvert);
  991. }
  992. STDMETHODIMP CRmsCartridge::SetHome(
  993. LONG type,
  994. GUID libId,
  995. GUID mediaSetId,
  996. LONG pos,
  997. LONG alt1,
  998. LONG alt2,
  999. LONG alt3,
  1000. BOOL invert
  1001. )
  1002. /*++
  1003. Implements:
  1004. IRmsCartridge::SetHome
  1005. --*/
  1006. {
  1007. return m_home.SetLocation(type,
  1008. libId,
  1009. mediaSetId,
  1010. pos,
  1011. alt1,
  1012. alt2,
  1013. alt3,
  1014. invert);
  1015. }
  1016. STDMETHODIMP
  1017. CRmsCartridge::GetLocation(
  1018. LONG *pType,
  1019. GUID *pLibId,
  1020. GUID *pMediaSetId,
  1021. LONG *pPos,
  1022. LONG *pAlt1,
  1023. LONG *pAlt2,
  1024. LONG *pAlt3,
  1025. BOOL *pInvert)
  1026. /*++
  1027. Implements:
  1028. IRmsCartridge::GetLocation
  1029. --*/
  1030. {
  1031. return m_location.GetLocation(pType,
  1032. pLibId,
  1033. pMediaSetId,
  1034. pPos,
  1035. pAlt1,
  1036. pAlt2,
  1037. pAlt3,
  1038. pInvert);
  1039. }
  1040. STDMETHODIMP
  1041. CRmsCartridge::SetLocation(
  1042. LONG type,
  1043. GUID libId,
  1044. GUID mediaSetId,
  1045. LONG pos,
  1046. LONG alt1,
  1047. LONG alt2,
  1048. LONG alt3,
  1049. BOOL invert)
  1050. /*++
  1051. Implements:
  1052. IRmsCartridge::SetLocation
  1053. --*/
  1054. {
  1055. return m_location.SetLocation(type,
  1056. libId,
  1057. mediaSetId,
  1058. pos,
  1059. alt1,
  1060. alt2,
  1061. alt3,
  1062. invert);
  1063. }
  1064. STDMETHODIMP
  1065. CRmsCartridge::GetMailStop(
  1066. BSTR *pMailStop
  1067. )
  1068. /*++
  1069. Implements:
  1070. IRmsCartridge::GetMailStop
  1071. --*/
  1072. {
  1073. HRESULT hr = E_FAIL;
  1074. try {
  1075. WsbAssertPointer (pMailStop);
  1076. WsbAffirmHr( m_mailStop.CopyToBstr(pMailStop) );
  1077. hr = S_OK;
  1078. }
  1079. WsbCatch(hr);
  1080. return hr;
  1081. }
  1082. STDMETHODIMP
  1083. CRmsCartridge::SetMailStop(
  1084. BSTR mailStop
  1085. )
  1086. /*++
  1087. Implements:
  1088. IRmsCartridge::SetMailStop
  1089. --*/
  1090. {
  1091. m_mailStop = mailStop;
  1092. m_isDirty = TRUE;
  1093. return S_OK;
  1094. }
  1095. STDMETHODIMP
  1096. CRmsCartridge::GetDrive(
  1097. IRmsDrive **ptr
  1098. )
  1099. /*++
  1100. Implements:
  1101. IRmsCartridge::GetDrive
  1102. --*/
  1103. {
  1104. HRESULT hr = E_FAIL;
  1105. try {
  1106. WsbAssertPointer( ptr );
  1107. WsbAffirmPointer(m_pDrive);
  1108. *ptr = m_pDrive;
  1109. m_pDrive.p->AddRef();
  1110. hr = S_OK;
  1111. } WsbCatch( hr );
  1112. return(hr);
  1113. }
  1114. STDMETHODIMP
  1115. CRmsCartridge::SetDrive(
  1116. IRmsDrive *ptr
  1117. )
  1118. /*++
  1119. Implements:
  1120. IRmsChangerElement::SetCartridge
  1121. --*/
  1122. {
  1123. HRESULT hr = E_FAIL;
  1124. try {
  1125. WsbAssertPointer( ptr );
  1126. CComQIPtr<IRmsChangerElement, &IID_IRmsChangerElement> pElmt = ptr;
  1127. WsbAffirmHr( pElmt->SetCartridge( this ) );
  1128. if ( m_pDrive )
  1129. m_pDrive = 0;
  1130. m_pDrive = ptr;
  1131. m_isMounted = TRUE;
  1132. hr = S_OK;
  1133. } WsbCatch( hr );
  1134. return(hr);
  1135. }
  1136. STDMETHODIMP
  1137. CRmsCartridge::GetInfo(
  1138. UCHAR *pInfo,
  1139. SHORT *pSize
  1140. )
  1141. /*++
  1142. Implements:
  1143. IRmsCartridge::GetInfo
  1144. --*/
  1145. {
  1146. HRESULT hr = E_FAIL;
  1147. try {
  1148. WsbAssertPointer( pInfo );
  1149. WsbAssertPointer( pSize );
  1150. memmove (pInfo, m_info, m_sizeofInfo);
  1151. *pSize = m_sizeofInfo;
  1152. hr = S_OK;
  1153. }
  1154. WsbCatch(hr);
  1155. return hr;
  1156. }
  1157. STDMETHODIMP
  1158. CRmsCartridge::SetInfo(
  1159. UCHAR *pInfo,
  1160. SHORT size
  1161. )
  1162. /*++
  1163. Implements:
  1164. IRmsCartridge::SetInfo
  1165. --*/
  1166. {
  1167. HRESULT hr = E_FAIL;
  1168. try {
  1169. WsbAssertPointer( pInfo );
  1170. memmove (m_info, pInfo, size);
  1171. m_sizeofInfo = size;
  1172. m_isDirty = TRUE;
  1173. hr = S_OK;
  1174. }
  1175. WsbCatch(hr);
  1176. return hr;
  1177. }
  1178. STDMETHODIMP
  1179. CRmsCartridge::GetOwnerClassId(
  1180. CLSID *pClassId
  1181. )
  1182. /*++
  1183. Implements:
  1184. IRmsCartridge::GetOwnerClassId
  1185. --*/
  1186. {
  1187. HRESULT hr = E_FAIL;
  1188. try {
  1189. WsbAssertPointer( pClassId );
  1190. *pClassId = m_ownerClassId;
  1191. hr = S_OK;
  1192. }
  1193. WsbCatch(hr);
  1194. return hr;
  1195. }
  1196. STDMETHODIMP
  1197. CRmsCartridge::SetOwnerClassId(
  1198. CLSID classId
  1199. )
  1200. /*++
  1201. Implements:
  1202. IRmsCartridge::SetOwnerClassId
  1203. --*/
  1204. {
  1205. m_ownerClassId = classId;
  1206. m_isDirty = TRUE;
  1207. return S_OK;
  1208. }
  1209. STDMETHODIMP
  1210. CRmsCartridge::GetPartitions(
  1211. IWsbIndexedCollection **ptr
  1212. )
  1213. /*++
  1214. Implements:
  1215. IRmsCartridge::GetPartitions
  1216. --*/
  1217. {
  1218. HRESULT hr = E_FAIL;
  1219. try {
  1220. WsbAssertPointer( ptr );
  1221. *ptr = m_pParts;
  1222. m_pParts.p->AddRef();
  1223. hr = S_OK;
  1224. }
  1225. WsbCatch(hr);
  1226. return hr;
  1227. }
  1228. STDMETHODIMP
  1229. CRmsCartridge::GetVerifierClass(
  1230. CLSID *pClassId
  1231. )
  1232. /*++
  1233. Implements:
  1234. IRmsCartridge::GetVerifierClass
  1235. --*/
  1236. {
  1237. HRESULT hr = E_FAIL;
  1238. try {
  1239. WsbAssertPointer( pClassId );
  1240. *pClassId = m_verifierClass;
  1241. hr = S_OK;
  1242. }
  1243. WsbCatch(hr);
  1244. return hr;
  1245. }
  1246. STDMETHODIMP
  1247. CRmsCartridge::SetVerifierClass(
  1248. CLSID classId
  1249. )
  1250. /*++
  1251. Implements:
  1252. IRmsCartridge::SetVerifierClass
  1253. --*/
  1254. {
  1255. m_verifierClass = classId;
  1256. m_isDirty = TRUE;
  1257. return S_OK;
  1258. }
  1259. STDMETHODIMP
  1260. CRmsCartridge::GetPortalClass(
  1261. CLSID *pClassId
  1262. )
  1263. /*++
  1264. Implements:
  1265. IRmsCartridge::GetPortalClass
  1266. --*/
  1267. {
  1268. HRESULT hr = E_FAIL;
  1269. try {
  1270. WsbAssertPointer( pClassId );
  1271. *pClassId = m_portalClass;
  1272. hr = S_OK;
  1273. }
  1274. WsbCatch(hr);
  1275. return hr;
  1276. }
  1277. STDMETHODIMP
  1278. CRmsCartridge::SetPortalClass(
  1279. CLSID classId
  1280. )
  1281. /*++
  1282. Implements:
  1283. IRmsCartridge::SetPortalClass
  1284. --*/
  1285. {
  1286. m_portalClass = classId;
  1287. m_isDirty = TRUE;
  1288. return S_OK;
  1289. }
  1290. STDMETHODIMP
  1291. CRmsCartridge::LoadDataCache(
  1292. OUT BYTE *pCache,
  1293. IN OUT ULONG *pSize,
  1294. OUT ULONG *pUsed,
  1295. OUT ULARGE_INTEGER *pStartPBA)
  1296. /*++
  1297. Implements:
  1298. IRmsCartridge::LoadDataCache
  1299. --*/
  1300. {
  1301. HRESULT hr = S_OK;
  1302. try {
  1303. WsbAssertPointer( pCache );
  1304. WsbAssertPointer( pSize );
  1305. WsbAssertPointer( pUsed );
  1306. WsbAssertPointer( pStartPBA );
  1307. if (m_pDataCache) {
  1308. // The saved cache size must match the target
  1309. WsbAssert(*pSize == m_DataCacheSize, E_INVALIDARG);
  1310. memmove (pCache, m_pDataCache, m_DataCacheUsed);
  1311. *pSize = m_DataCacheSize;
  1312. *pUsed = m_DataCacheUsed;
  1313. *pStartPBA = m_DataCacheStartPBA;
  1314. }
  1315. else {
  1316. hr = E_FAIL;
  1317. }
  1318. } WsbCatch(hr);
  1319. return hr;
  1320. }
  1321. STDMETHODIMP
  1322. CRmsCartridge::SaveDataCache(
  1323. IN BYTE *pCache,
  1324. IN ULONG size,
  1325. IN ULONG used,
  1326. IN ULARGE_INTEGER startPBA)
  1327. /*++
  1328. Implements:
  1329. IRmsCartridge::SaveDataCache
  1330. --*/
  1331. {
  1332. HRESULT hr = S_OK;
  1333. try {
  1334. WsbAssertPointer( pCache );
  1335. WsbAssert(size > 0, E_INVALIDARG);
  1336. WsbAssert(used <= size, E_INVALIDARG);
  1337. // Check that the current cache is big enough
  1338. // to handle the incomming buffer.
  1339. if (m_pDataCache && used > m_DataCacheSize) {
  1340. WsbFree(m_pDataCache);
  1341. m_pDataCache = NULL;
  1342. m_DataCacheSize = 0;
  1343. m_DataCacheUsed = 0;
  1344. m_DataCacheStartPBA.QuadPart = 0;
  1345. }
  1346. if (!m_pDataCache) {
  1347. m_pDataCache = (BYTE *) WsbAlloc(size);
  1348. WsbAssertPointer(m_pDataCache);
  1349. memset(m_pDataCache, 0, size);
  1350. m_DataCacheSize = size;
  1351. }
  1352. WsbAssert(used <= m_DataCacheSize, E_INVALIDARG);
  1353. memmove (m_pDataCache, pCache, used);
  1354. m_DataCacheUsed = used;
  1355. m_DataCacheStartPBA = startPBA;
  1356. m_isDirty = TRUE;
  1357. } WsbCatch(hr);
  1358. return hr;
  1359. }
  1360. STDMETHODIMP
  1361. CRmsCartridge::GetManagedBy(
  1362. OUT LONG *pManagedBy
  1363. )
  1364. /*++
  1365. Implements:
  1366. IRmsCartridge::GetManagedBy
  1367. --*/
  1368. {
  1369. HRESULT hr = S_OK;
  1370. try {
  1371. WsbAssertPointer( pManagedBy );
  1372. *pManagedBy = (LONG) m_ManagedBy;
  1373. } WsbCatch(hr);
  1374. return hr;
  1375. }
  1376. STDMETHODIMP
  1377. CRmsCartridge::SetManagedBy(
  1378. IN LONG managedBy
  1379. )
  1380. /*++
  1381. Implements:
  1382. IRmsCartridge::SetManagedBy
  1383. --*/
  1384. {
  1385. m_ManagedBy = (RmsMediaManager) managedBy;
  1386. return S_OK;
  1387. }
  1388. STDMETHODIMP
  1389. CRmsCartridge::Mount(
  1390. OUT IRmsDrive **ppDrive,
  1391. IN DWORD dwOptions,
  1392. IN DWORD threadId)
  1393. /*++
  1394. Implements:
  1395. IRmsCartridge::Mount
  1396. --*/
  1397. {
  1398. HRESULT hr = E_FAIL;
  1399. WsbTraceIn(OLESTR("CRmsCartridge::Mount"), OLESTR(""));
  1400. try {
  1401. CComPtr<IRmsDrive> pDrive;
  1402. // first check if the cartridge is already mounted
  1403. if ( S_OK == IsMounted() ) {
  1404. LONG refs;
  1405. WsbAffirmHr( m_pDrive->GetMountReference( &refs ) );
  1406. if ( refs ) {
  1407. // Does media type support concurrent mounts?
  1408. switch ( m_type ) {
  1409. case RmsMedia8mm:
  1410. case RmsMedia4mm:
  1411. case RmsMediaDLT:
  1412. case RmsMediaTape:
  1413. // Tape doesn't support concurrent access - queue another mount
  1414. if (RmsMediaManagerNTMS == m_ManagedBy) {
  1415. CComPtr<IRmsNTMS> pNtms;
  1416. CComQIPtr<IRmsServer, &IID_IRmsServer> pServer = g_pServer;
  1417. WsbAffirmHr(pServer->GetNTMS(&pNtms));
  1418. WsbAffirmHr(pNtms->Mount(this, &pDrive, dwOptions, threadId));
  1419. // We've successfully mounted the cartridge, so
  1420. // add it the the active cartridge list.
  1421. #if RMS_USE_ACTIVE_COLLECTION
  1422. CComPtr<IWsbIndexedCollection> pActiveCartridges;
  1423. WsbAffirmHr(pServer->GetActiveCartridges(&pActiveCartridges));
  1424. WsbAffirmHr(pActiveCartridges->Add((IRmsCartridge *)this));
  1425. #else
  1426. WsbAffirmHr(pServer->SetActiveCartridge((IRmsCartridge *)this));
  1427. #endif
  1428. } else {
  1429. WsbAffirmHr( RMS_E_CARTRIDGE_BUSY );
  1430. }
  1431. break;
  1432. case RmsMediaWORM:
  1433. WsbAssertHr( E_NOTIMPL );
  1434. break;
  1435. case RmsMediaMO35:
  1436. case RmsMediaCDR:
  1437. case RmsMediaDVD:
  1438. case RmsMediaOptical:
  1439. case RmsMediaDisk:
  1440. case RmsMediaFixed:
  1441. // Optical media and fixed disks supports concurrent access
  1442. if (m_isMountedSerialized && (dwOptions & RMS_SERIALIZE_MOUNT)) {
  1443. // If the media is already mounted for serialized operation, then we need
  1444. // to serialize the mount despite the media supporting concurrent mounts.
  1445. // For fixed disk (where we cannot serialize by issuing another RSM mount) -
  1446. // we fail the mount with RMS_E_CARTRIDGE_BUSY
  1447. if (RmsMediaManagerNTMS == m_ManagedBy) {
  1448. CComPtr<IRmsNTMS> pNtms;
  1449. CComQIPtr<IRmsServer, &IID_IRmsServer> pServer = g_pServer;
  1450. WsbAffirmHr(pServer->GetNTMS(&pNtms));
  1451. WsbAffirmHr(pNtms->Mount(this, &pDrive, dwOptions, threadId));
  1452. // We've successfully mounted the cartridge, so
  1453. // add it the the active cartridge list.
  1454. #if RMS_USE_ACTIVE_COLLECTION
  1455. CComPtr<IWsbIndexedCollection> pActiveCartridges;
  1456. WsbAffirmHr(pServer->GetActiveCartridges(&pActiveCartridges));
  1457. WsbAffirmHr(pActiveCartridges->Add((IRmsCartridge *)this));
  1458. #else
  1459. WsbAffirmHr(pServer->SetActiveCartridge((IRmsCartridge *)this));
  1460. #endif
  1461. } else {
  1462. WsbAffirmHr( RMS_E_CARTRIDGE_BUSY );
  1463. }
  1464. }
  1465. break;
  1466. default:
  1467. WsbAssertHr( E_UNEXPECTED );
  1468. break;
  1469. }
  1470. }
  1471. }
  1472. if ( S_FALSE == IsMounted() ) {
  1473. CComQIPtr<IRmsServer, &IID_IRmsServer> pServer = g_pServer;
  1474. if (RmsMediaManagerNTMS == m_ManagedBy) {
  1475. CComPtr<IRmsNTMS> pNtms;
  1476. WsbAffirmHr(pServer->GetNTMS(&pNtms));
  1477. WsbAffirmHr(pNtms->Mount(this, &pDrive, dwOptions, threadId));
  1478. }
  1479. else {
  1480. LONG type;
  1481. GUID libId, mediaSetId;
  1482. LONG pos, alt1, alt2, alt3;
  1483. BOOL invert;
  1484. WsbAssertHr( m_location.GetLocation( &type, &libId, &mediaSetId, &pos, &alt1, &alt2, &alt3, &invert ));
  1485. switch ( (RmsElement) type ) {
  1486. case RmsElementStage:
  1487. case RmsElementStorage:
  1488. {
  1489. CComPtr<IRmsLibrary> pLib;
  1490. CComPtr<IWsbIndexedCollection> pDrives;
  1491. WsbAffirmHr( pServer->FindLibraryById( libId, &pLib ));
  1492. // Select a drive
  1493. // TODO: This code will be added to the the library interface as a drive
  1494. // slection method. For now, if one is free we use it.
  1495. WsbAffirmHr( pLib->GetDrives( &pDrives ));
  1496. CComPtr<IWsbEnum> pEnumDrives;
  1497. WsbAffirmHr( pDrives->Enum( &pEnumDrives ));
  1498. WsbAssertPointer( pEnumDrives );
  1499. hr = pEnumDrives->First( IID_IRmsDrive, (void **)&pDrive );
  1500. // Search for a drive to mount to
  1501. while ( S_OK == hr ) {
  1502. hr = pDrive->SelectForMount();
  1503. if ( S_OK == hr ) {
  1504. CComPtr<IWsbIndexedCollection> pChangers;
  1505. CComPtr<IRmsMediumChanger> pChanger;
  1506. CComPtr<IWsbEnum> pEnumChangers;
  1507. WsbAffirmHr( pLib->GetChangers( &pChangers ));
  1508. WsbAssertHr( pChangers->Enum( &pEnumChangers ));
  1509. WsbAssertPointer( pEnumChangers );
  1510. // we'll just use the first changer for the move.
  1511. WsbAssertHr( pEnumChangers->First( IID_IRmsMediumChanger, (void **)&pChanger ));
  1512. WsbAffirmHr( pChanger->MoveCartridge( this, pDrive ));
  1513. WsbAffirmHr( SetIsMounted( TRUE ));
  1514. WsbAffirmHr( SetDrive( pDrive ));
  1515. break;
  1516. }
  1517. hr = pEnumDrives->Next( IID_IRmsDrive, (void **)&pDrive );
  1518. }
  1519. }
  1520. break;
  1521. case RmsElementShelf:
  1522. case RmsElementOffSite:
  1523. WsbAssertHr( E_NOTIMPL );
  1524. break;
  1525. case RmsElementDrive:
  1526. WsbAssertHr( E_UNEXPECTED );
  1527. break;
  1528. case RmsElementChanger:
  1529. case RmsElementIEPort:
  1530. WsbAssertHr( E_NOTIMPL );
  1531. break;
  1532. } // switch
  1533. }
  1534. if ( S_OK == IsMounted() ) {
  1535. // We've successfully mounted the cartridge, so
  1536. // add it the the active cartridge list.
  1537. #if RMS_USE_ACTIVE_COLLECTION
  1538. CComPtr<IWsbIndexedCollection> pActiveCartridges;
  1539. WsbAffirmHr(pServer->GetActiveCartridges(&pActiveCartridges));
  1540. WsbAffirmHr(pActiveCartridges->Add((IRmsCartridge *)this));
  1541. #else
  1542. WsbAffirmHr(pServer->SetActiveCartridge((IRmsCartridge *)this));
  1543. #endif
  1544. }
  1545. }
  1546. if ( S_OK == IsMounted() ) {
  1547. // Update serialization flag if needed
  1548. if (dwOptions & RMS_SERIALIZE_MOUNT) {
  1549. // This signals to serialize next mount for the same media
  1550. m_isMountedSerialized = TRUE;
  1551. }
  1552. // Final updates
  1553. switch ( m_type ) {
  1554. case RmsMedia8mm:
  1555. case RmsMedia4mm:
  1556. case RmsMediaDLT:
  1557. case RmsMediaTape:
  1558. // increment the object reference counter.
  1559. *ppDrive = m_pDrive;
  1560. WsbAffirmHr( m_pDrive.p->AddRef() );
  1561. // increment the mount reference counter.
  1562. WsbAffirmHr( m_pDrive->AddMountReference() );
  1563. // update stats
  1564. WsbAffirmHr( updateMountStats( TRUE, TRUE ) );
  1565. hr = S_OK;
  1566. break;
  1567. case RmsMediaWORM:
  1568. WsbAssertHr( E_NOTIMPL );
  1569. break;
  1570. case RmsMediaMO35:
  1571. case RmsMediaCDR:
  1572. case RmsMediaDVD:
  1573. case RmsMediaOptical:
  1574. case RmsMediaDisk:
  1575. case RmsMediaFixed:
  1576. // increment the object reference counter.
  1577. *ppDrive = m_pDrive;
  1578. WsbAffirmHr( m_pDrive.p->AddRef() );
  1579. // increment the mount reference counter.
  1580. WsbAffirmHr( m_pDrive->AddMountReference() );
  1581. // update stats
  1582. WsbAffirmHr( updateMountStats( TRUE, TRUE ) );
  1583. hr = S_OK;
  1584. break;
  1585. default:
  1586. WsbAssertHr( E_UNEXPECTED );
  1587. break;
  1588. }
  1589. }
  1590. } WsbCatch(hr)
  1591. WsbTraceOut(OLESTR("CRmsCartridge::Mount"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1592. return hr;
  1593. }
  1594. STDMETHODIMP
  1595. CRmsCartridge::Dismount(
  1596. IN DWORD dwOptions
  1597. )
  1598. /*++
  1599. Implements:
  1600. IRmsCartridge::Dismount
  1601. --*/
  1602. {
  1603. HRESULT hr = S_OK;
  1604. WsbTraceIn(OLESTR("CRmsCartridge::Dismount"), OLESTR("<%ld>"), dwOptions);
  1605. try {
  1606. // Update stats
  1607. WsbAffirmHr(updateMountStats(FALSE, FALSE));
  1608. // Decrement the mount reference counter.
  1609. //
  1610. // When the reference count for the cartridge goes to zero,
  1611. // and the dismount wait time has expired, we physically
  1612. // move the cartridge back to it's storage location.
  1613. WsbAssert(m_pDrive != 0, RMS_E_CARTRIDGE_NOT_MOUNTED);
  1614. WsbAffirmHr(m_pDrive->ReleaseMountReference(dwOptions));
  1615. } WsbCatch(hr)
  1616. WsbTraceOut(OLESTR("CRmsCartridge::Dismount"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1617. return hr;
  1618. }
  1619. HRESULT
  1620. CRmsCartridge::Home(IN DWORD dwOptions)
  1621. /*++
  1622. Implements:
  1623. IRmsDrive::Home
  1624. --*/
  1625. {
  1626. HRESULT hr S_OK;
  1627. WsbTraceIn(OLESTR("CRmsCartridge::Home"), OLESTR(""));
  1628. try {
  1629. CComQIPtr<IRmsServer, &IID_IRmsServer> pServer = g_pServer;
  1630. try {
  1631. /*
  1632. Tracking DataMovers is only partially implemented.
  1633. //
  1634. // Cleanup...
  1635. // Release all DataMovers that reference this cartridge.
  1636. //
  1637. CComPtr<IWsbEnum> pEnumDataMovers;
  1638. CComPtr<IWsbIndexedCollection> pDataMovers;
  1639. CComPtr<IRmsCartridge> pCart;
  1640. CComPtr<IDataMover> pMover;
  1641. WsbAffirmHr(pServer->GetDataMovers(&pDataMovers));
  1642. WsbAffirmHr(pDataMovers->Enum(&pEnumDataMovers));
  1643. WsbAssertPointer(pEnumDataMovers);
  1644. hr = pEnumDataMovers->First(IID_IDataMover, (void **)&pMover);
  1645. while (S_OK == hr) {
  1646. try {
  1647. GUID cartIdOfMover = GUID_NULL;
  1648. GUID cartId = GUID_NULL;
  1649. WsbAffirmHr(pMover->GetCartridge(&pCart));
  1650. WsbAffirmPointer(pCart);
  1651. WsbAffirmHr(pCart->GetCartridgeId(&cartIdOfMover));
  1652. WsbAffirmHr(GetCartridgeId(&cartId));
  1653. WsbAssert(cartId != GUID_NULL, E_UNEXPECTED);
  1654. //
  1655. // Does this mover reference this cartridge?
  1656. //
  1657. if (cartIdOfMover == cartId) {
  1658. //
  1659. // Cancel any outstanding I/O, and remove the mover
  1660. // from the list of active movers.
  1661. //
  1662. WsbAffirmHr(pMover->Cancel());
  1663. WsbAffirmHr(ReleaseDataMover(pMover));
  1664. }
  1665. } WsbCatch(hr);
  1666. pCart = 0;
  1667. pMover = 0;
  1668. hr = pEnumDataMovers->Next( IID_IDataMover, (void **)&pMover );
  1669. }
  1670. hr = S_OK;
  1671. */
  1672. LONG type;
  1673. GUID libId, mediaSetId;
  1674. LONG pos, alt1, alt2, alt3;
  1675. BOOL invert;
  1676. // We're physically moving the cartridge back to it's storage
  1677. // location.
  1678. WsbAssertHr( m_location.GetLocation( &type, &libId, &mediaSetId, &pos, &alt1, &alt2, &alt3, &invert ));
  1679. WsbAffirmHr(SetIsMounted(FALSE));
  1680. if (RmsMediaManagerNTMS == m_ManagedBy) {
  1681. CComPtr<IRmsNTMS> pNtms;
  1682. WsbAffirmHr(pServer->GetNTMS(&pNtms));
  1683. WsbAffirmHr(pNtms->Dismount(this, dwOptions));
  1684. }
  1685. else {
  1686. CComPtr<IRmsLibrary> pLib;
  1687. CComPtr<IWsbIndexedCollection> pChangers;
  1688. CComPtr<IRmsMediumChanger> pChanger;
  1689. CComPtr<IWsbEnum> pEnumChangers;
  1690. WsbAffirmHr(pServer->FindLibraryById(libId, &pLib));
  1691. WsbAffirmHr(pLib->GetChangers(&pChangers));
  1692. WsbAssertHr(pChangers->Enum( &pEnumChangers));
  1693. WsbAssertPointer(pEnumChangers);
  1694. // we'll just use the first changer for the move.
  1695. WsbAffirmHr(pEnumChangers->First(IID_IRmsMediumChanger, (void **)&pChanger));
  1696. WsbAffirmHr(pChanger->HomeCartridge(this));
  1697. }
  1698. } WsbCatch(hr)
  1699. #if RMS_USE_ACTIVE_COLLECTION
  1700. CComPtr<IWsbIndexedCollection> pActiveCartridges;
  1701. WsbAffirmHr(pServer->GetActiveCartridges(&pActiveCartridges));
  1702. WsbAffirmHr(pActiveCartridges->RemoveAndRelease((IRmsCartridge *)this));
  1703. ULONG activeCartridges;
  1704. WsbAffirmHr(pActiveCartridges->GetEntries( &activeCartridges));
  1705. WsbTrace(OLESTR("activeCartridges = <%u>\n"), activeCartridges);
  1706. #else
  1707. WsbAffirmHr(pServer->SetActiveCartridge(NULL));
  1708. #endif
  1709. } WsbCatch(hr)
  1710. WsbTraceOut(OLESTR("CRmsCartridge::Home"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1711. return hr;
  1712. }
  1713. HRESULT
  1714. CRmsCartridge::updateMountStats(
  1715. IN BOOL bRead,
  1716. IN BOOL bWrite
  1717. )
  1718. /*++
  1719. Updates storage info for the mounted partition
  1720. --*/
  1721. {
  1722. HRESULT hr = E_FAIL;
  1723. WsbTraceIn(OLESTR("CRmsCartridge::updateMountStats"), OLESTR(""));
  1724. try {
  1725. // We have not implemented partitions yet, everything
  1726. // is single sided... eventually the following need to be added to
  1727. // the correct partition. Should this be in a separate function?.
  1728. // For now we don't distinguish between reads and writes
  1729. if ( bRead ) m_readMountCounter++;
  1730. if ( bWrite ) m_writeMountCounter++;
  1731. // Update the read/write timestamps
  1732. // if ( bRead ) m_lastReadTimestamp;
  1733. // if ( bWrite ) m_lastWriteTimestamp;
  1734. hr = S_OK;
  1735. } WsbCatch(hr)
  1736. WsbTraceOut(OLESTR("CRmsCartridge::updateMountStats"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1737. return hr;
  1738. }
  1739. STDMETHODIMP
  1740. CRmsCartridge::CreateDataMover(
  1741. IDataMover **ptr
  1742. )
  1743. /*++
  1744. Implements:
  1745. IRmsDrive::CreateDataMover
  1746. --*/
  1747. {
  1748. HRESULT hr = S_OK;
  1749. try {
  1750. WsbAssertPointer(ptr);
  1751. if ( S_OK == IsMounted() ) {
  1752. WsbAssertPointer(m_pDrive );
  1753. WsbAffirmHr(m_pDrive->CreateDataMover(ptr));
  1754. }
  1755. else {
  1756. hr = RMS_E_RESOURCE_UNAVAILABLE;
  1757. }
  1758. } WsbCatch( hr );
  1759. return hr;
  1760. }
  1761. STDMETHODIMP
  1762. CRmsCartridge::ReleaseDataMover(
  1763. IN IDataMover *ptr
  1764. )
  1765. /*++
  1766. Implements:
  1767. IRmsCartridge::ReleaseDataMover
  1768. --*/
  1769. {
  1770. HRESULT hr = S_OK;
  1771. try {
  1772. WsbAssertPointer(ptr);
  1773. WsbAffirmPointer(m_pDrive);
  1774. WsbAffirmHr(m_pDrive->ReleaseDataMover(ptr));
  1775. } WsbCatch(hr);
  1776. return hr;
  1777. }
  1778. STDMETHODIMP
  1779. CRmsCartridge::SetIsAvailable(
  1780. BOOL flag
  1781. )
  1782. /*++
  1783. Implements:
  1784. IRmsCartridge::SetIsAvailable
  1785. --*/
  1786. {
  1787. m_isAvailable = flag;
  1788. return S_OK;
  1789. }
  1790. STDMETHODIMP
  1791. CRmsCartridge::IsAvailable(
  1792. VOID
  1793. )
  1794. /*++
  1795. Implements:
  1796. IRmsCartridge::IsAvailable
  1797. --*/
  1798. {
  1799. HRESULT hr = E_FAIL;
  1800. hr = m_isAvailable ? S_OK : S_FALSE;
  1801. return (hr);
  1802. }
  1803. STDMETHODIMP
  1804. CRmsCartridge::IsFixedBlockSize(void)
  1805. /*++
  1806. Implements:
  1807. IRmsCartridge::IsFixedBlockSize
  1808. --*/
  1809. {
  1810. HRESULT hr = S_OK;
  1811. WsbTraceIn(OLESTR("CRmsCartridge::IsFixedBlockSize"), OLESTR(""));
  1812. try {
  1813. switch ( m_type ) {
  1814. case RmsMedia8mm:
  1815. case RmsMedia4mm:
  1816. case RmsMediaDLT:
  1817. case RmsMediaTape:
  1818. hr = S_FALSE;
  1819. break;
  1820. case RmsMediaMO35:
  1821. case RmsMediaCDR:
  1822. case RmsMediaDVD:
  1823. case RmsMediaOptical:
  1824. case RmsMediaDisk:
  1825. case RmsMediaFixed:
  1826. hr = S_OK;
  1827. break;
  1828. default:
  1829. WsbAssertHr( E_UNEXPECTED );
  1830. break;
  1831. }
  1832. } WsbCatch(hr)
  1833. WsbTraceOut(OLESTR("CRmsCartridge::IsFixedBlockSize"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1834. return hr;
  1835. }