Source code of Windows XP (NT5)
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.

2205 lines
61 KiB

  1. /*++
  2. Copyright (c) 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. MedInfo.cpp
  5. Abstract:
  6. This component is an object representation of the HSM Metadata media information
  7. record.
  8. Author:
  9. Cat Brant [cbrant] 27-Feb-1997
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "wsbgen.h"
  14. #include "engine.h"
  15. #include "metaint.h"
  16. #include "metalib.h"
  17. #include "MedInfo.h"
  18. #include "segdb.h"
  19. #undef WSB_TRACE_IS
  20. #define WSB_TRACE_IS WSB_TRACE_BIT_META
  21. static USHORT iCountMedinfo = 0;
  22. HRESULT
  23. CMediaInfo::FinalConstruct(
  24. void
  25. )
  26. /*++
  27. Routine Description:
  28. This method does some initialization of the object that is necessary
  29. after construction.
  30. Arguments:
  31. None.
  32. Return Value:
  33. S_OK
  34. Anything returned by CWsbDbEntity::FinalConstruct().
  35. --*/
  36. {
  37. HRESULT hr = S_OK;
  38. WsbTraceIn(OLESTR("CMediaInfo::FinalConstruct"),OLESTR(""));
  39. try {
  40. WsbAssertHr(CWsbDbEntity::FinalConstruct());
  41. //
  42. // Initialize the master media record
  43. //
  44. m_Master.id = GUID_NULL;
  45. m_Master.ntmsId = GUID_NULL;
  46. m_Master.storagePoolId = GUID_NULL;
  47. m_Master.description = OLESTR("");
  48. m_Master.name = OLESTR("");
  49. m_Master.type = HSM_JOB_MEDIA_TYPE_UNKNOWN;
  50. m_Master.lastUpdate = WsbLLtoFT(0);
  51. m_Master.lastError = S_OK;
  52. m_Master.recallOnly = FALSE;
  53. m_Master.freeBytes = 0;
  54. m_Master.capacity = 0;
  55. m_Master.nextRemoteDataSet = 0;
  56. m_Recreate = FALSE;
  57. m_LogicalValidBytes = 0;
  58. //
  59. // Now initialize the last known good master
  60. //
  61. m_LastKnownGoodMaster.id = GUID_NULL;
  62. m_LastKnownGoodMaster.ntmsId = GUID_NULL;
  63. m_LastKnownGoodMaster.storagePoolId = GUID_NULL;
  64. m_LastKnownGoodMaster.description = OLESTR("");
  65. m_LastKnownGoodMaster.name = OLESTR("");
  66. m_LastKnownGoodMaster.type = HSM_JOB_MEDIA_TYPE_UNKNOWN;
  67. m_LastKnownGoodMaster.lastUpdate = WsbLLtoFT(0);
  68. m_LastKnownGoodMaster.lastError = S_OK;
  69. m_LastKnownGoodMaster.recallOnly = FALSE;
  70. m_LastKnownGoodMaster.freeBytes = 0;
  71. m_LastKnownGoodMaster.capacity = 0;
  72. m_LastKnownGoodMaster.nextRemoteDataSet = 0;
  73. //
  74. // Initialize the master's copy media records
  75. //
  76. for (int i = 0; i < HSM_MAX_NUMBER_MEDIA_COPIES; i++) {
  77. m_Copy[i].id = GUID_NULL;
  78. m_Copy[i].description = OLESTR("");
  79. m_Copy[i].name = OLESTR("");
  80. m_Copy[i].lastUpdate = WsbLLtoFT(0);
  81. m_Copy[i].lastError = S_OK;
  82. m_Copy[i].nextRemoteDataSet = 0;
  83. }
  84. } WsbCatch(hr);
  85. iCountMedinfo++;
  86. WsbTraceOut(OLESTR("CMediaInfo::FinalConstruct"), OLESTR("hr = <%ls>, Count is <%d>"),
  87. WsbHrAsString(hr), iCountMedinfo);
  88. return(hr);
  89. }
  90. void
  91. CMediaInfo::FinalRelease(
  92. void
  93. )
  94. /*++
  95. Implements:
  96. CMediaInfo::FinalRelease().
  97. --*/
  98. {
  99. WsbTraceIn(OLESTR("CMediaInfo::FinalRelease"), OLESTR(""));
  100. CWsbDbEntity::FinalRelease();
  101. iCountMedinfo--;
  102. WsbTraceOut(OLESTR("CMediaInfo::FinalRelease"), OLESTR("Count is <%d>"), iCountMedinfo);
  103. }
  104. HRESULT
  105. CMediaInfo::GetName(
  106. OLECHAR **pName,
  107. ULONG bufferSize
  108. )
  109. /*++
  110. Implements:
  111. IMediaInfo::GetName
  112. --*/
  113. {
  114. HRESULT hr = S_OK;
  115. WsbTraceIn(OLESTR("CMediaInfo::GetName"),OLESTR("buffer size = <%lu>"), bufferSize);
  116. try {
  117. WsbAssertPointer(pName);
  118. CWsbStringPtr tmpName;
  119. tmpName = m_Master.name;
  120. WsbAffirmHr(tmpName.CopyTo(pName, bufferSize));
  121. } WsbCatch(hr);
  122. WsbTraceOut(OLESTR("CMediaInfo::GetName"), OLESTR("hr = <%ls>, Name = <%ls>"), WsbHrAsString(hr), WsbPtrToStringAsString(pName));
  123. return(hr);
  124. }
  125. HRESULT
  126. CMediaInfo::GetCapacity(
  127. LONGLONG *pCapacity
  128. )
  129. /*++
  130. Implements:
  131. IMediaInfo::GetCapacity
  132. --*/
  133. {
  134. HRESULT hr = S_OK;
  135. WsbTraceIn(OLESTR("CMediaInfo::GetCapacity"),OLESTR(""));
  136. try {
  137. WsbAssertPointer(pCapacity);
  138. *pCapacity = m_Master.capacity;
  139. } WsbCatch(hr);
  140. WsbTraceOut(OLESTR("CMediaInfo::GetCapacity"), OLESTR("hr = <%ls>, Capacity = <%ls>"), WsbHrAsString(hr), WsbPtrToLonglongAsString(pCapacity));
  141. return(hr);
  142. }
  143. HRESULT CMediaInfo::GetClassID
  144. (
  145. OUT LPCLSID pclsid
  146. )
  147. /*++
  148. Implements:
  149. IPerist::GetClassID()
  150. --*/
  151. {
  152. HRESULT hr = S_OK;
  153. WsbTraceIn(OLESTR("CMediaInfo::GetClassID"), OLESTR(""));
  154. try {
  155. WsbAssert(0 != pclsid, E_POINTER);
  156. *pclsid = CLSID_CMediaInfo;
  157. } WsbCatch(hr);
  158. WsbTraceOut(OLESTR("CMediaInfo::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pclsid));
  159. return(hr);
  160. }
  161. HRESULT
  162. CMediaInfo:: GetCopyName(
  163. USHORT copyNumber,
  164. OLECHAR **pName,
  165. ULONG bufferSize
  166. )
  167. /*++
  168. Implements:
  169. IMediaInfo::GetCopyName
  170. --*/
  171. {
  172. HRESULT hr = S_OK;
  173. WsbTraceIn(OLESTR("CMediaInfo::GetCopyName"),OLESTR(""));
  174. try {
  175. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  176. E_INVALIDARG);
  177. WsbAssertPointer(pName);
  178. CWsbStringPtr tmpString;
  179. tmpString = m_Copy[copyNumber - 1].name;
  180. WsbAffirmHr(tmpString.CopyTo(pName, bufferSize));
  181. } WsbCatch(hr);
  182. WsbTraceOut(OLESTR("CMediaInfo::GetCopyName"), OLESTR("hr = <%ls>, Name = <%ls>"), WsbHrAsString(hr), WsbPtrToStringAsString(pName));
  183. return(hr);
  184. }
  185. HRESULT
  186. CMediaInfo:: GetCopyNextRemoteDataSet(
  187. USHORT copyNumber,
  188. SHORT *pNextRemoteDataSet
  189. )
  190. /*++
  191. Implements:
  192. IMediaInfo::GetCopyNextRemoteDataSet
  193. --*/
  194. {
  195. HRESULT hr = S_OK;
  196. WsbTraceIn(OLESTR("CMediaInfo::GetCopyNextRemoteDataSet"),OLESTR(""));
  197. try {
  198. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  199. E_INVALIDARG);
  200. WsbAssertPointer(pNextRemoteDataSet);
  201. *pNextRemoteDataSet = m_Copy[copyNumber - 1].nextRemoteDataSet;
  202. } WsbCatch(hr);
  203. WsbTraceOut(OLESTR("CMediaInfo::GetCopyNextRemoteDataSet"), OLESTR("hr = <%ls>, NextRemoteDataSet = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString(pNextRemoteDataSet));
  204. return(hr);
  205. }
  206. HRESULT
  207. CMediaInfo::GetCopyDescription(
  208. USHORT copyNumber,
  209. OLECHAR **pDescription,
  210. ULONG bufferSize
  211. )
  212. /*++
  213. Implements:
  214. IMediaInfo::GetCopyDescription
  215. --*/
  216. {
  217. HRESULT hr = S_OK;
  218. WsbTraceIn(OLESTR("CMediaInfo::GetCopyDescription"),OLESTR("Copy = <%u>"), copyNumber);
  219. try {
  220. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  221. E_INVALIDARG);
  222. WsbAssertPointer(pDescription);
  223. CWsbStringPtr tmpDescription;
  224. tmpDescription = m_Copy[copyNumber - 1].description;
  225. WsbAffirmHr(tmpDescription.CopyTo(pDescription, bufferSize));
  226. } WsbCatch(hr);
  227. WsbTraceOut(OLESTR("CMediaInfo::GetCopyDescription"), OLESTR("hr = <%ls>, CopyDescription = <%ls>"), WsbHrAsString(hr), WsbPtrToStringAsString(pDescription));
  228. return(hr);
  229. }
  230. HRESULT
  231. CMediaInfo::GetCopyInfo(
  232. USHORT copyNumber,
  233. GUID *pMediaSubsystemId,
  234. OLECHAR **pDescription,
  235. ULONG descriptionBufferSize,
  236. OLECHAR **pName,
  237. ULONG nameBufferSize,
  238. FILETIME *pUpdate,
  239. HRESULT *pLastError,
  240. SHORT *pNextRemoteDataSet
  241. )
  242. /*++
  243. Implements:
  244. IMediaInfo::GetCopyInfo
  245. --*/
  246. {
  247. HRESULT hr = S_OK;
  248. WsbTraceIn(OLESTR("CMediaInfo::GetCopyInfo"),OLESTR("Copy is <%u>"), copyNumber);
  249. try {
  250. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  251. E_INVALIDARG);
  252. if (pMediaSubsystemId != 0) {
  253. *pMediaSubsystemId = m_Copy[copyNumber - 1].id;
  254. }
  255. if (pDescription != 0) {
  256. CWsbStringPtr tmpDescription;
  257. tmpDescription = m_Copy[copyNumber - 1].description;
  258. tmpDescription.CopyTo(pDescription, descriptionBufferSize);
  259. }
  260. if (pName != 0) {
  261. CWsbStringPtr tmpString;
  262. tmpString = m_Copy[copyNumber - 1].name;
  263. tmpString.CopyTo(pName, nameBufferSize);
  264. }
  265. if (pUpdate != 0) {
  266. *pUpdate = m_Copy[copyNumber - 1].lastUpdate;
  267. }
  268. if (pLastError != 0 ) {
  269. *pLastError = m_Copy[copyNumber - 1].lastError;
  270. }
  271. if (pNextRemoteDataSet != 0 ) {
  272. *pNextRemoteDataSet = m_Copy[copyNumber - 1].nextRemoteDataSet;
  273. }
  274. } WsbCatch(hr);
  275. WsbTraceOut(OLESTR("CMediaInfo::GetCopyInfo"),
  276. OLESTR("hr = <%ls>, SubSystemID = <%ls>, Description = <%ls>, Name = <%ls>, Update = <%ls>, LastError = <%ls>, NextRemoteDataSet = <%ls>"),
  277. WsbHrAsString(hr), WsbPtrToGuidAsString(pMediaSubsystemId),
  278. WsbQuickString(WsbPtrToStringAsString(pDescription)), WsbQuickString(WsbPtrToStringAsString(pName)),
  279. WsbPtrToFiletimeAsString(FALSE, pUpdate), WsbPtrToHrAsString(pLastError),
  280. WsbPtrToShortAsString(pNextRemoteDataSet));
  281. return(hr);
  282. }
  283. HRESULT
  284. CMediaInfo::GetCopyLastError(
  285. USHORT copyNumber,
  286. HRESULT *pLastError
  287. )
  288. /*++
  289. Implements:
  290. IMediaInfo::GetCopyLastError
  291. --*/
  292. {
  293. HRESULT hr = S_OK;
  294. WsbTraceIn(OLESTR("CMediaInfo::GetCopyLastError"),OLESTR("Copy is <%u>"), copyNumber);
  295. try {
  296. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  297. E_INVALIDARG);
  298. WsbAssertPointer(pLastError);
  299. *pLastError = m_Copy[copyNumber - 1].lastError;
  300. } WsbCatch(hr);
  301. WsbTraceOut(OLESTR("CMediaInfo::GetCopyLastError"), OLESTR("hr = <%ls>, Last Error = <%ls>"), WsbHrAsString(hr), WsbPtrToHrAsString(pLastError));
  302. return(hr);
  303. }
  304. HRESULT
  305. CMediaInfo::GetCopyMediaSubsystemId(
  306. USHORT copyNumber,
  307. GUID *pMediaSubsystemId
  308. )
  309. /*++
  310. Implements:
  311. IMediaInfo::GetCopyMediaSubsystemId
  312. --*/
  313. {
  314. HRESULT hr = S_OK;
  315. WsbTraceIn(OLESTR("CMediaInfo::GetCopyMediaSubsystemId"),OLESTR("Copy is <%u>"), copyNumber);
  316. try {
  317. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  318. E_INVALIDARG);
  319. WsbAssertPointer(pMediaSubsystemId);
  320. *pMediaSubsystemId = m_Copy[copyNumber - 1].id;
  321. } WsbCatch(hr);
  322. WsbTraceOut(OLESTR("CMediaInfo::GetCopyMediaSubsystemId"), OLESTR("hr = <%ls>, ID = <%ls>"), WsbHrAsString(hr), WsbPtrToGuidAsString(pMediaSubsystemId));
  323. return(hr);
  324. }
  325. HRESULT
  326. CMediaInfo::GetCopyUpdate(
  327. USHORT copyNumber,
  328. FILETIME *pUpdate
  329. )
  330. /*++
  331. Implements:
  332. IMediaInfo::GetCopyUpdate
  333. --*/
  334. {
  335. HRESULT hr = S_OK;
  336. WsbTraceIn(OLESTR("CMediaInfo::GetCopyUpdate"),OLESTR("Copy is <%u>"), copyNumber);
  337. try {
  338. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  339. E_INVALIDARG);
  340. WsbAssertPointer(pUpdate);
  341. *pUpdate = m_Copy[copyNumber - 1].lastUpdate;
  342. } WsbCatch(hr);
  343. WsbTraceOut(OLESTR("CMediaInfo::GetCopyUpdate"), OLESTR("hr = <%ls>, Update = <%ls>"), WsbHrAsString(hr), WsbPtrToFiletimeAsString(FALSE,pUpdate));
  344. return(hr);
  345. }
  346. HRESULT
  347. CMediaInfo::GetDescription(
  348. OLECHAR **pDescription,
  349. ULONG bufferSize
  350. )
  351. /*++
  352. Implements:
  353. IMediaInfo::GetDescription
  354. --*/
  355. {
  356. HRESULT hr = S_OK;
  357. WsbTraceIn(OLESTR("CMediaInfo::GetDescription"),OLESTR(""));
  358. try {
  359. WsbAssertPointer(pDescription);
  360. CWsbStringPtr tmpDescription;
  361. tmpDescription = m_Master.description;
  362. WsbAffirmHr(tmpDescription.CopyTo(pDescription, bufferSize));
  363. } WsbCatch(hr);
  364. WsbTraceOut(OLESTR("CMediaInfo::GetDescription"), OLESTR("hr = <%ls>, Description = <%ls>"), WsbHrAsString(hr), WsbPtrToStringAsString(pDescription));
  365. return(hr);
  366. }
  367. HRESULT
  368. CMediaInfo::GetFreeBytes(
  369. LONGLONG *pFreeBytes
  370. )
  371. /*++
  372. Implements:
  373. IMediaInfo::GetFreeBytes
  374. --*/
  375. {
  376. HRESULT hr = S_OK;
  377. WsbTraceIn(OLESTR("CMediaInfo::GetFreeBytes"),OLESTR(""));
  378. try {
  379. WsbAssertPointer(pFreeBytes);
  380. *pFreeBytes = m_Master.freeBytes;
  381. } WsbCatch(hr);
  382. WsbTraceOut(OLESTR("CMediaInfo::GetFreeBytes"), OLESTR("hr = <%ls>, Free Space = <%ls>"), WsbHrAsString(hr), WsbPtrToLonglongAsString(pFreeBytes));
  383. return(hr);
  384. }
  385. HRESULT
  386. CMediaInfo::GetId(
  387. GUID *pId
  388. )
  389. /*++
  390. Implements:
  391. IMediaInfo::GetId
  392. --*/
  393. {
  394. HRESULT hr = S_OK;
  395. WsbTraceIn(OLESTR("CMediaInfo::GetId"),OLESTR(""));
  396. try {
  397. WsbAssertPointer(pId);
  398. *pId = m_Master.id;
  399. } WsbCatch(hr);
  400. WsbTraceOut(OLESTR("CMediaInfo::GetId"), OLESTR("hr = <%ls>, Id = <%ls>"), WsbHrAsString(hr), WsbPtrToGuidAsString(pId));
  401. return(hr);
  402. }
  403. HRESULT
  404. CMediaInfo::GetLastError(
  405. HRESULT *pLastError
  406. )
  407. /*++
  408. Implements:
  409. IMediaInfo::GetLastError
  410. --*/
  411. {
  412. HRESULT hr = S_OK;
  413. WsbTraceIn(OLESTR("CMediaInfo::GetLastError"),OLESTR(""));
  414. try {
  415. WsbAssertPointer(pLastError);
  416. *pLastError = m_Master.lastError;
  417. } WsbCatch(hr);
  418. WsbTraceOut(OLESTR("CMediaInfo::GetLastError"), OLESTR("hr = <%ls>, LastError = <%ls>"), WsbHrAsString(hr), WsbPtrToHrAsString(pLastError));
  419. return(hr);
  420. }
  421. HRESULT
  422. CMediaInfo::GetLogicalValidBytes(
  423. LONGLONG *pLogicalValidBytes
  424. )
  425. /*++
  426. Implements:
  427. IMediaInfo::GetLogicalValidBytes
  428. --*/
  429. {
  430. HRESULT hr = S_OK;
  431. WsbTraceIn(OLESTR("CMediaInfo::GetLogicalValidBytes"),OLESTR(""));
  432. try {
  433. WsbAssertPointer(pLogicalValidBytes);
  434. *pLogicalValidBytes = m_LogicalValidBytes;
  435. } WsbCatch(hr);
  436. WsbTraceOut(OLESTR("CMediaInfo::GetLogicalValidBytes"), OLESTR("hr = <%ls>, LogicalValidBytes = <%ls>"), WsbHrAsString(hr), WsbPtrToLonglongAsString(pLogicalValidBytes));
  437. return(hr);
  438. }
  439. HRESULT
  440. CMediaInfo::GetMediaInfo(
  441. GUID* pMediaId,
  442. GUID *pMediaSubsystemId,
  443. GUID *pStoragePoolId,
  444. LONGLONG *pFreeBytes,
  445. LONGLONG *pCapacity,
  446. HRESULT *pLastError,
  447. SHORT *pNextRemoteDataSet,
  448. OLECHAR **pDescription,
  449. ULONG descriptionBufferSize,
  450. HSM_JOB_MEDIA_TYPE *pType,
  451. OLECHAR **pName,
  452. ULONG nameBufferSize,
  453. BOOL *pRecallOnly,
  454. FILETIME *pUpdate,
  455. LONGLONG *pLogicalValidBytes,
  456. BOOL *pRecreate
  457. )
  458. /*++
  459. Implements:
  460. IMediaInfo::GetMediaInfo
  461. --*/
  462. {
  463. HRESULT hr = S_OK;
  464. WsbTraceIn(OLESTR("CMediaInfo::GetMediaInfo"),OLESTR(""));
  465. try {
  466. //Make sure we can provide data memebers
  467. if (0 != pMediaId) {
  468. *pMediaId = m_Master.id;
  469. }
  470. if (0 != pMediaSubsystemId) {
  471. *pMediaSubsystemId = m_Master.ntmsId;
  472. }
  473. if (0 != pStoragePoolId) {
  474. *pStoragePoolId = m_Master.storagePoolId;
  475. }
  476. if (0 != pDescription) {
  477. CWsbStringPtr tmpString;
  478. tmpString = m_Master.description;
  479. WsbAffirmHr(tmpString.CopyTo(pDescription, descriptionBufferSize));
  480. }
  481. if (0 != pName) {
  482. CWsbStringPtr tmpString;
  483. tmpString = m_Master.name;
  484. tmpString.CopyTo(pName, nameBufferSize);
  485. }
  486. if (0 != pType) {
  487. *pType = m_Master.type;
  488. }
  489. if (0 != pUpdate) {
  490. *pUpdate = m_Master.lastUpdate;
  491. }
  492. if (0 != pLastError) {
  493. *pLastError = m_Master.lastError;
  494. }
  495. if (0 != pRecallOnly) {
  496. *pRecallOnly = m_Master.recallOnly;
  497. }
  498. if (0 != pFreeBytes) {
  499. *pFreeBytes = m_Master.freeBytes;
  500. }
  501. if (0 != pCapacity) {
  502. *pCapacity = m_Master.capacity;
  503. }
  504. if (0 != pNextRemoteDataSet) {
  505. *pNextRemoteDataSet = m_Master.nextRemoteDataSet;
  506. }
  507. if (0 != pLogicalValidBytes) {
  508. *pLogicalValidBytes = m_LogicalValidBytes;
  509. }
  510. if (0 != pRecreate) {
  511. *pRecreate = m_Recreate;
  512. }
  513. } WsbCatch(hr);
  514. WsbTrace(OLESTR("CMediaInfo::GetMediaInfo id = <%ls>, ntmsId = <%ls>, StgPoolId = <%ls>\n"),
  515. WsbPtrToGuidAsString(pMediaId), WsbQuickString(WsbPtrToGuidAsString(pMediaSubsystemId)),
  516. WsbQuickString(WsbPtrToGuidAsString(pStoragePoolId)));
  517. WsbTrace(OLESTR("CMediaInfo::GetMediaInfo Free = <%ls>, Cap = <%ls>, Last Error = <%ls>\n"),
  518. WsbPtrToLonglongAsString(pFreeBytes),WsbQuickString(WsbPtrToLonglongAsString(pCapacity)),
  519. WsbPtrToHrAsString(pLastError));
  520. WsbTrace(OLESTR("CMediaInfo::GetMediaInfo NextRemoteDataSet = <%ls>, Description = <%ls>, Type = <%ls>\n"),
  521. WsbPtrToShortAsString(pNextRemoteDataSet),
  522. WsbPtrToStringAsString(pDescription),
  523. WsbQuickString(WsbPtrToShortAsString((SHORT *)pType)));
  524. WsbTrace(OLESTR("CMediaInfo::GetMediaInfo Name = <%ls>, RecallOnly = <%ls>, Update = <%ls>\n"),
  525. WsbQuickString(WsbPtrToStringAsString(pName)),
  526. WsbQuickString(WsbPtrToBoolAsString(pRecallOnly)),
  527. WsbPtrToFiletimeAsString(FALSE, pUpdate));
  528. WsbTrace(OLESTR("CMediaInfo::GetMediaInfo LogicalValid = <%ls>, Recreate = <%ls>\n"),
  529. WsbQuickString(WsbPtrToLonglongAsString(pLogicalValidBytes)),
  530. WsbQuickString(WsbPtrToBoolAsString(pRecreate)));
  531. WsbTraceOut(OLESTR("CMediaInfo::GetMediaInfo"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  532. return(hr);
  533. }
  534. HRESULT
  535. CMediaInfo::GetMediaSubsystemId(
  536. GUID *pMediaSubsystemId
  537. )
  538. /*++
  539. Implements:
  540. IMediaInfo::GetMediaSubsystemId
  541. --*/
  542. {
  543. HRESULT hr = S_OK;
  544. WsbTraceIn(OLESTR("CMediaInfo::GetMediaSubsystemId"),OLESTR(""));
  545. try {
  546. WsbAssertPointer(pMediaSubsystemId);
  547. *pMediaSubsystemId = m_Master.ntmsId;
  548. } WsbCatch(hr);
  549. WsbTraceOut(OLESTR("CMediaInfo::GetMediaSubsystemId"), OLESTR("hr = <%ls>, SubsystemID = <%ls>"), WsbHrAsString(hr), WsbPtrToGuidAsString(pMediaSubsystemId));
  550. return(hr);
  551. }
  552. HRESULT
  553. CMediaInfo::GetNextRemoteDataSet(
  554. short *pNextRemoteDataSet
  555. )
  556. /*++
  557. Implements:
  558. IMediaInfo::GetNextRemoteDataSet
  559. --*/
  560. {
  561. HRESULT hr = S_OK;
  562. WsbTraceIn(OLESTR("CMediaInfo::GetNextRemoteDataSet"),OLESTR(""));
  563. try {
  564. WsbAssertPointer(pNextRemoteDataSet);
  565. *pNextRemoteDataSet = m_Master.nextRemoteDataSet;
  566. } WsbCatch(hr);
  567. WsbTraceOut(OLESTR("CMediaInfo::GetNextRemoteDataSet"), OLESTR("hr = <%ls>, Next Remote Data Set = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString(pNextRemoteDataSet));
  568. return(hr);
  569. }
  570. HRESULT
  571. CMediaInfo::GetRecallOnlyStatus(
  572. BOOL *pRecallOnlyStatus
  573. )
  574. /*++
  575. Implements:
  576. IMediaInfo::GetRecallOnlyStatus
  577. --*/
  578. {
  579. HRESULT hr = S_OK;
  580. WsbTraceIn(OLESTR("CMediaInfo::GetRecallOnlyStatus"),OLESTR(""));
  581. try {
  582. WsbAssertPointer(pRecallOnlyStatus);
  583. *pRecallOnlyStatus = m_Master.recallOnly;
  584. } WsbCatch(hr);
  585. WsbTraceOut(OLESTR("CMediaInfo::GetRecallOnlyStatus"), OLESTR("hr = <%ls>, Read only Status = <%ls>"), WsbHrAsString(hr), WsbPtrToBoolAsString(pRecallOnlyStatus));
  586. return(hr);
  587. }
  588. HRESULT CMediaInfo::GetSizeMax
  589. (
  590. OUT ULARGE_INTEGER* pcbSize
  591. )
  592. /*++
  593. Implements:
  594. IPersistStream::GetSizeMax().
  595. --*/
  596. {
  597. HRESULT hr = S_OK;
  598. WsbTraceIn(OLESTR("CMediaInfo::GetSizeMax"), OLESTR(""));
  599. try {
  600. hr = E_NOTIMPL;
  601. pcbSize = 0;
  602. } WsbCatch(hr);
  603. WsbTraceOut(OLESTR("CMediaInfo::GetSizeMax"),
  604. OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr),
  605. WsbPtrToUliAsString(pcbSize));
  606. return(hr);
  607. }
  608. HRESULT
  609. CMediaInfo::GetStoragePoolId(
  610. GUID *pStoragePoolId
  611. )
  612. /*++
  613. Implements:
  614. IMediaInfo::GetStoragePoolId
  615. --*/
  616. {
  617. HRESULT hr = S_OK;
  618. WsbTraceIn(OLESTR("CMediaInfo::GetStoragePoolId"),OLESTR(""));
  619. try {
  620. WsbAssertPointer(pStoragePoolId);
  621. *pStoragePoolId = m_Master.storagePoolId;
  622. } WsbCatch(hr);
  623. WsbTraceOut(OLESTR("CMediaInfo::GetStoragePoolId"), OLESTR("hr = <%ls>, Storage Pool Id = <%ls>"), WsbHrAsString(hr), WsbPtrToGuidAsString(pStoragePoolId));
  624. return(hr);
  625. }
  626. HRESULT
  627. CMediaInfo::GetType(
  628. HSM_JOB_MEDIA_TYPE *pType
  629. )
  630. /*++
  631. Implements:
  632. IMediaInfo::GetType
  633. --*/
  634. {
  635. HRESULT hr = S_OK;
  636. WsbTraceIn(OLESTR("CMediaInfo::GetType"),OLESTR(""));
  637. try {
  638. WsbAssertPointer(pType);
  639. *pType = m_Master.type;
  640. } WsbCatch(hr);
  641. WsbTraceOut(OLESTR("CMediaInfo::GetType"), OLESTR("hr = <%ls>, type = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString((SHORT *)pType));
  642. return(hr);
  643. }
  644. HRESULT
  645. CMediaInfo::GetUpdate(
  646. FILETIME *pUpdate
  647. )
  648. /*++
  649. Implements:
  650. IMediaInfo::GetUpdate
  651. --*/
  652. {
  653. HRESULT hr = S_OK;
  654. WsbTraceIn(OLESTR("CMediaInfo::GetUpdate"),OLESTR(""));
  655. try {
  656. WsbAssertPointer(pUpdate);
  657. *pUpdate = m_Master.lastUpdate;
  658. } WsbCatch(hr);
  659. WsbTraceOut(OLESTR("CMediaInfo::GetUpdate"), OLESTR("hr = <%ls>, Update = <%ls>"), WsbHrAsString(hr), WsbPtrToFiletimeAsString(FALSE, pUpdate));
  660. return(hr);
  661. }
  662. HRESULT CMediaInfo::Load
  663. (
  664. IN IStream* pStream
  665. )
  666. /*++
  667. Implements:
  668. IPersistStream::Load().
  669. --*/
  670. {
  671. HRESULT hr = S_OK;
  672. WsbTraceIn(OLESTR("CMediaInfo::Load"), OLESTR(""));
  673. try {
  674. WsbAssert(0 != pStream, E_POINTER);
  675. ULONG descriptionLen = (ULONG)SEG_DB_MAX_MEDIA_NAME_LEN;
  676. ULONG nameLen = (ULONG)SEG_DB_MAX_MEDIA_BAR_CODE_LEN;
  677. WsbAffirmHr(WsbLoadFromStream(pStream, &m_Master.id));
  678. WsbAffirmHr(WsbLoadFromStream(pStream, &m_Master.ntmsId));
  679. WsbAffirmHr(WsbLoadFromStream(pStream, &m_Master.storagePoolId));
  680. m_Master.description.Realloc(SEG_DB_MAX_MEDIA_NAME_LEN);
  681. WsbAffirmHr(WsbLoadFromStream(pStream, (OLECHAR **)&m_Master.description, descriptionLen));
  682. m_Master.name.Realloc(SEG_DB_MAX_MEDIA_BAR_CODE_LEN);
  683. WsbAffirmHr(WsbLoadFromStream(pStream, (OLECHAR **)&m_Master.name, nameLen));
  684. LONG tmpLong;
  685. WsbAffirmHr(WsbLoadFromStream(pStream, &tmpLong));
  686. m_Master.type = (HSM_JOB_MEDIA_TYPE)tmpLong;
  687. WsbAffirmHr(WsbLoadFromStream(pStream, &m_Master.freeBytes));
  688. WsbAffirmHr(WsbLoadFromStream(pStream, &m_Master.capacity));
  689. WsbAffirmHr(WsbLoadFromStream(pStream, (LONG *)&m_Master.lastError));
  690. WsbAffirmHr(WsbLoadFromStream(pStream, &m_Master.recallOnly));
  691. WsbAffirmHr(WsbLoadFromStream(pStream, &m_Master.lastUpdate));
  692. WsbAffirmHr(WsbLoadFromStream(pStream, &m_Master.nextRemoteDataSet));
  693. WsbAffirmHr(WsbLoadFromStream(pStream, &m_LogicalValidBytes));
  694. WsbAffirmHr(WsbLoadFromStream(pStream, &m_Recreate));
  695. WsbAffirmHr(WsbLoadFromStream(pStream, &m_LastKnownGoodMaster.id));
  696. WsbAffirmHr(WsbLoadFromStream(pStream, &m_LastKnownGoodMaster.ntmsId));
  697. WsbAffirmHr(WsbLoadFromStream(pStream, &m_LastKnownGoodMaster.storagePoolId));
  698. m_LastKnownGoodMaster.description.Realloc(SEG_DB_MAX_MEDIA_NAME_LEN);
  699. WsbAffirmHr(WsbLoadFromStream(pStream, (OLECHAR **)&m_LastKnownGoodMaster.description, descriptionLen));
  700. m_LastKnownGoodMaster.name.Realloc(SEG_DB_MAX_MEDIA_BAR_CODE_LEN);
  701. WsbAffirmHr(WsbLoadFromStream(pStream, (OLECHAR **)&m_LastKnownGoodMaster.name, nameLen));
  702. WsbAffirmHr(WsbLoadFromStream(pStream, &tmpLong));
  703. m_LastKnownGoodMaster.type = (HSM_JOB_MEDIA_TYPE)tmpLong;
  704. WsbAffirmHr(WsbLoadFromStream(pStream, &m_LastKnownGoodMaster.freeBytes));
  705. WsbAffirmHr(WsbLoadFromStream(pStream, &m_LastKnownGoodMaster.capacity));
  706. WsbAffirmHr(WsbLoadFromStream(pStream, (LONG *)&m_LastKnownGoodMaster.lastError));
  707. WsbAffirmHr(WsbLoadFromStream(pStream, &m_LastKnownGoodMaster.recallOnly));
  708. WsbAffirmHr(WsbLoadFromStream(pStream, &m_LastKnownGoodMaster.lastUpdate));
  709. WsbAffirmHr(WsbLoadFromStream(pStream, &m_LastKnownGoodMaster.nextRemoteDataSet));
  710. for (int i = 0; i < HSM_MAX_NUMBER_MEDIA_COPIES; i++ ) {
  711. WsbAffirmHr(WsbLoadFromStream(pStream, &(m_Copy[i].id)));
  712. m_Copy[i].description.Realloc(SEG_DB_MAX_MEDIA_NAME_LEN);
  713. WsbAffirmHr(WsbLoadFromStream(pStream, (OLECHAR **)&(m_Copy[i].description), descriptionLen));
  714. m_Copy[i].name.Realloc(SEG_DB_MAX_MEDIA_BAR_CODE_LEN);
  715. WsbAffirmHr(WsbLoadFromStream(pStream, (OLECHAR **)&(m_Copy[i].name), nameLen));
  716. WsbAffirmHr(WsbLoadFromStream(pStream, &(m_Copy[i].lastUpdate)));
  717. WsbAffirmHr(WsbLoadFromStream(pStream, (LONG *)&(m_Copy[i].lastError)));
  718. WsbAffirmHr(WsbLoadFromStream(pStream, &(m_Copy[i].nextRemoteDataSet)));
  719. }
  720. } WsbCatch(hr);
  721. WsbTrace(OLESTR("ID = <%ls>, rmsId = <%ls>, stgPoolId = <%ls>\n"),
  722. WsbQuickString(WsbGuidAsString(m_Master.id)),
  723. WsbQuickString(WsbGuidAsString(m_Master.ntmsId)),
  724. WsbQuickString(WsbGuidAsString(m_Master.storagePoolId)));
  725. WsbTrace(OLESTR("Description = <%ls>, name = <%ls>, type = <%u>\n"),
  726. (OLECHAR *)m_Master.description,
  727. (OLECHAR *)m_Master.name,
  728. m_Master.type);
  729. WsbTrace(OLESTR("FreeBytes = <%ls>, capacity = <%ls>, lastError = <%ls>\n"),
  730. WsbQuickString(WsbLonglongAsString(m_Master.freeBytes)),
  731. WsbQuickString(WsbLonglongAsString(m_Master.capacity)),
  732. WsbQuickString(WsbHrAsString(m_Master.lastError)));
  733. WsbTrace(OLESTR("RecallOnly = <%ls>, NextRemotDataSet = <%u>\n"),
  734. WsbBoolAsString(m_Master.recallOnly),
  735. m_Master.nextRemoteDataSet);
  736. WsbTrace(OLESTR("LastUpdate = <%ls>, logicalValidBytes = <%ls>, Recreate = <%ls>\n"),
  737. WsbFiletimeAsString(FALSE, m_Master.lastUpdate),
  738. WsbLonglongAsString(m_LogicalValidBytes),
  739. WsbBoolAsString(m_Recreate));
  740. WsbTraceOut(OLESTR("CMediaInfo::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  741. return(hr);
  742. }
  743. HRESULT CMediaInfo::Print
  744. (
  745. IN IStream* pStream
  746. )
  747. /*++
  748. Implements:
  749. IWsbDbEntity::Print
  750. --*/
  751. {
  752. HRESULT hr = S_OK;
  753. WsbTraceIn(OLESTR("CMediaInfo::Print"), OLESTR(""));
  754. try {
  755. WsbAssert(0 != pStream, E_POINTER);
  756. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" id = %ls,"),
  757. WsbGuidAsString(m_Master.id)));
  758. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" ntmsId = %ls,"),
  759. WsbGuidAsString(m_Master.ntmsId)));
  760. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" StoragePoolId = %ls,"),
  761. WsbGuidAsString(m_Master.storagePoolId)));
  762. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RS Media Name = %ls,"), (OLECHAR *)m_Master.description));
  763. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RMS Media Name = %ls,"), (OLECHAR *)m_Master.name));
  764. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Media Type = %u,"), m_Master.type));
  765. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Last Update = %ls,"),
  766. WsbFiletimeAsString(FALSE, m_Master.lastUpdate)));
  767. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Last Error = %ls,"), WsbHrAsString(m_Master.lastError)));
  768. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Is Recall Only = %ls,"), WsbBoolAsString(m_Master.recallOnly)));
  769. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Free Bytes = %ls,"),
  770. WsbQuickString(WsbLonglongAsString(m_Master.freeBytes))));
  771. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Capacity = %ls,"),
  772. WsbQuickString(WsbLonglongAsString(m_Master.capacity))));
  773. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Logical Valid Bytes = %ls,"),
  774. WsbQuickString(WsbLonglongAsString(m_LogicalValidBytes))));
  775. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" NextRemoteDataSet = %u,"), m_Master.nextRemoteDataSet));
  776. WsbAffirmHr(CWsbDbEntity::Print(pStream));
  777. //
  778. // Last Known Good Master
  779. //
  780. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR("\n Last Known Good id = %ls,"),
  781. WsbGuidAsString(m_LastKnownGoodMaster.id)));
  782. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" ntmsId = %ls,"),
  783. WsbGuidAsString(m_LastKnownGoodMaster.ntmsId)));
  784. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" StoragePoolId = %ls,"),
  785. WsbGuidAsString(m_LastKnownGoodMaster.storagePoolId)));
  786. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RS Media Name = %ls,"), (OLECHAR *)m_LastKnownGoodMaster.description));
  787. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RMS Media Name = %ls,"), (OLECHAR *)m_LastKnownGoodMaster.name));
  788. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Media Type = %u,"), m_LastKnownGoodMaster.type));
  789. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Last Update = %ls,"),
  790. WsbFiletimeAsString(FALSE, m_LastKnownGoodMaster.lastUpdate)));
  791. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Last Error = %ls,"), WsbHrAsString(m_LastKnownGoodMaster.lastError)));
  792. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Is Recall Only = %ls,"), WsbBoolAsString(m_LastKnownGoodMaster.recallOnly)));
  793. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Free Bytes = %ls,"),
  794. WsbQuickString(WsbLonglongAsString(m_LastKnownGoodMaster.freeBytes))));
  795. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Capacity = %ls,"),
  796. WsbQuickString(WsbLonglongAsString(m_LastKnownGoodMaster.capacity))));
  797. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" NextRemoteDataSet = %u,"), m_LastKnownGoodMaster.nextRemoteDataSet));
  798. //
  799. // Media Copies
  800. //
  801. for (int i = 0; i < HSM_MAX_NUMBER_MEDIA_COPIES; i++ ) {
  802. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR("\n RS Media Copy %d RMS ID = %ls,") ,(i+1), WsbGuidAsString(m_Copy[i].id)));
  803. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RS Media Name = %ls,") , (OLECHAR *)m_Copy[i].description));
  804. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RMS Media Name = %ls,") , (OLECHAR *)m_Copy[i].name));
  805. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Last Update = %ls,") , WsbFiletimeAsString(FALSE,m_Copy[i].lastUpdate)));
  806. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Last Error = %ls,") , WsbHrAsString(m_Copy[i].lastError)));
  807. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" NextRemoteDataSet = %u,") , m_Copy[i].nextRemoteDataSet));
  808. }
  809. } WsbCatch(hr);
  810. WsbTraceOut(OLESTR("CMediaInfo::Print"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  811. return(hr);
  812. }
  813. HRESULT CMediaInfo::Save
  814. (
  815. IN IStream* pStream,
  816. IN BOOL clearDirty
  817. )
  818. /*++
  819. Implements:
  820. IPersistStream::Save().
  821. --*/
  822. {
  823. HRESULT hr = S_OK;
  824. WsbTraceIn(OLESTR("CMediaInfo::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  825. WsbTrace(OLESTR("ID = <%ls>, rmsId = <%ls>, stgPoolId = <%ls>\n"),
  826. WsbQuickString(WsbGuidAsString(m_Master.id)),
  827. WsbQuickString(WsbGuidAsString(m_Master.ntmsId)),
  828. WsbQuickString(WsbGuidAsString(m_Master.storagePoolId)));
  829. WsbTrace(OLESTR("Description = <%ls>, name = <%ls>, type = <%u>\n"),
  830. (OLECHAR *)m_Master.description,
  831. (OLECHAR *)m_Master.name,
  832. m_Master.type);
  833. WsbTrace(OLESTR("FreeBytes = <%ls>, capacity = <%ls>, lastError = <%ls>\n"),
  834. WsbQuickString(WsbLonglongAsString(m_Master.freeBytes)),
  835. WsbQuickString(WsbLonglongAsString(m_Master.capacity)),
  836. WsbHrAsString(m_Master.lastError));
  837. WsbTrace(OLESTR("RecallOnly = <%ls>, NextRemotDataSet = <%u>\n"),
  838. WsbBoolAsString(m_Master.recallOnly),
  839. m_Master.nextRemoteDataSet);
  840. WsbTrace(OLESTR("LastUpdate = <%ls>, logicalValidBytes = <%ls>, Recreate = <%ls>\n"),
  841. WsbFiletimeAsString(FALSE, m_Master.lastUpdate),
  842. WsbLonglongAsString(m_LogicalValidBytes),
  843. WsbBoolAsString(m_Recreate));
  844. try {
  845. WsbAssert(0 != pStream, E_POINTER);
  846. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.id));
  847. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.ntmsId));
  848. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.storagePoolId));
  849. WsbAffirmHr(WsbSaveToStream(pStream, (OLECHAR *)m_Master.description));
  850. WsbAffirmHr(WsbSaveToStream(pStream, (OLECHAR *)m_Master.name));
  851. WsbAffirmHr(WsbSaveToStream(pStream, (LONG)m_Master.type));
  852. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.freeBytes));
  853. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.capacity));
  854. WsbAffirmHr(WsbSaveToStream(pStream, (LONG)m_Master.lastError));
  855. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.recallOnly));
  856. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.lastUpdate));
  857. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.nextRemoteDataSet));
  858. WsbAffirmHr(WsbSaveToStream(pStream, m_LogicalValidBytes));
  859. WsbAffirmHr(WsbSaveToStream(pStream, m_Recreate));
  860. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.id));
  861. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.ntmsId));
  862. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.storagePoolId));
  863. WsbAffirmHr(WsbSaveToStream(pStream, (OLECHAR *)m_LastKnownGoodMaster.description));
  864. WsbAffirmHr(WsbSaveToStream(pStream, (OLECHAR *)m_LastKnownGoodMaster.name));
  865. WsbAffirmHr(WsbSaveToStream(pStream, (LONG)m_LastKnownGoodMaster.type));
  866. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.freeBytes));
  867. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.capacity));
  868. WsbAffirmHr(WsbSaveToStream(pStream, (LONG)m_LastKnownGoodMaster.lastError));
  869. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.recallOnly));
  870. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.lastUpdate));
  871. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.nextRemoteDataSet));
  872. for (int i = 0; i < HSM_MAX_NUMBER_MEDIA_COPIES; i++ ) {
  873. WsbAffirmHr(WsbSaveToStream(pStream, m_Copy[i].id));
  874. WsbAffirmHr(WsbSaveToStream(pStream, m_Copy[i].description));
  875. WsbAffirmHr(WsbSaveToStream(pStream, m_Copy[i].name));
  876. WsbAffirmHr(WsbSaveToStream(pStream, m_Copy[i].lastUpdate));
  877. WsbAffirmHr(WsbSaveToStream(pStream, (LONG)(m_Copy[i].lastError)));
  878. WsbAffirmHr(WsbSaveToStream(pStream, m_Copy[i].nextRemoteDataSet));
  879. }
  880. // If we got it saved and we were asked to clear the dirty bit, then
  881. // do so now.
  882. if (clearDirty) {
  883. m_isDirty = FALSE;
  884. }
  885. } WsbCatch(hr);
  886. WsbTraceOut(OLESTR("CMediaInfo::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  887. return(hr);
  888. }
  889. HRESULT
  890. CMediaInfo::SetName(
  891. OLECHAR *name
  892. )
  893. /*++
  894. Implements:
  895. IMediaInfo::SetName
  896. --*/
  897. {
  898. HRESULT hr = S_OK;
  899. WsbTraceIn(OLESTR("CMediaInfo::SetName"),OLESTR("Name = <%ls>"), name);
  900. try {
  901. WsbAssertPointer(name);
  902. m_Master.name = name;
  903. } WsbCatch(hr);
  904. WsbTraceOut(OLESTR("CMediaInfo::SetName"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  905. return(hr);
  906. }
  907. HRESULT
  908. CMediaInfo::SetCapacity(
  909. LONGLONG capacity
  910. )
  911. /*++
  912. Implements:
  913. IMediaInfo::SetCapacity
  914. --*/
  915. {
  916. HRESULT hr = S_OK;
  917. WsbTraceIn(OLESTR("CMediaInfo::SetCapacity"),OLESTR("Capacity = <%ls>"), WsbLonglongAsString(capacity));
  918. try {
  919. m_Master.capacity = capacity;
  920. } WsbCatch(hr);
  921. WsbTraceOut(OLESTR("CMediaInfo::SetCapacity"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  922. return(hr);
  923. }
  924. HRESULT
  925. CMediaInfo::SetCopyName(
  926. USHORT copyNumber,
  927. OLECHAR *name
  928. )
  929. /*++
  930. Implements:
  931. IMediaInfo::SetCopyName
  932. --*/
  933. {
  934. HRESULT hr = S_OK;
  935. WsbTraceIn(OLESTR("CMediaInfo::SetCopyName"),OLESTR("copy = <%u>, Name = <%ls>"), copyNumber, name);
  936. try {
  937. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  938. E_INVALIDARG);
  939. m_Copy[copyNumber - 1].name = name;
  940. } WsbCatch(hr);
  941. WsbTraceOut(OLESTR("CMediaInfo::SetCopyName"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  942. return(hr);
  943. }
  944. HRESULT
  945. CMediaInfo::SetCopyNextRemoteDataSet(
  946. USHORT copyNumber,
  947. SHORT nextRemoteDataSet
  948. )
  949. /*++
  950. Implements:
  951. IMediaInfo::SetCopyNextRemoteDataSet
  952. --*/
  953. {
  954. HRESULT hr = S_OK;
  955. WsbTraceIn(OLESTR("CMediaInfo::SetCopyNextRemoteDataSet"),OLESTR("copy = <%u>, NextRemoteDataSet = <%d>"), copyNumber, nextRemoteDataSet);
  956. try {
  957. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  958. E_INVALIDARG);
  959. m_Copy[copyNumber - 1].nextRemoteDataSet = nextRemoteDataSet;
  960. } WsbCatch(hr);
  961. WsbTraceOut(OLESTR("CMediaInfo::SetCopyNextRemoteDataSet"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  962. return(hr);
  963. }
  964. HRESULT
  965. CMediaInfo::SetCopyDescription(
  966. USHORT copyNumber,
  967. OLECHAR *description
  968. )
  969. /*++
  970. Implements:
  971. IMediaInfo::SetCopyDescription
  972. --*/
  973. {
  974. HRESULT hr = S_OK;
  975. WsbTraceIn(OLESTR("CMediaInfo::SetCopyDescription"),OLESTR("copy = <%u>, description = <%ls>"), copyNumber, description);
  976. try {
  977. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  978. E_INVALIDARG);
  979. m_Copy[copyNumber - 1].description = description;
  980. } WsbCatch(hr);
  981. WsbTraceOut(OLESTR("CMediaInfo::SetCopyDescription"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  982. return(hr);
  983. }
  984. HRESULT
  985. CMediaInfo::SetCopyInfo(
  986. USHORT copyNumber,
  987. GUID mediaSubsystemId,
  988. OLECHAR *description,
  989. OLECHAR *name,
  990. FILETIME update,
  991. HRESULT lastError,
  992. SHORT nextRemoteDataSet
  993. )
  994. /*++
  995. Implements:
  996. IMediaInfo::SetCopyInfo
  997. --*/
  998. {
  999. HRESULT hr = S_OK;
  1000. WsbTraceIn(OLESTR("CMediaInfo::SetCopyInfo"),OLESTR("copy = <%u>, SubsystemId = <%ls>, Description = <%ls>, Name = <%ls>, update = <%ls>, lastError = <%ls>, NextRemoteDataSet = <%d> "),
  1001. copyNumber, WsbGuidAsString(mediaSubsystemId), description, name, WsbFiletimeAsString(FALSE, update),WsbHrAsString(lastError));
  1002. try {
  1003. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  1004. E_INVALIDARG);
  1005. m_Copy[copyNumber - 1].id = mediaSubsystemId;
  1006. m_Copy[copyNumber - 1].description = description;
  1007. m_Copy[copyNumber - 1].name = name;
  1008. m_Copy[copyNumber - 1].lastUpdate = update;
  1009. m_Copy[copyNumber - 1].lastError = lastError;
  1010. m_Copy[copyNumber - 1].nextRemoteDataSet = nextRemoteDataSet;
  1011. } WsbCatch(hr);
  1012. WsbTraceOut(OLESTR("CMediaInfo::SetCopyInfo"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1013. return(hr);
  1014. }
  1015. HRESULT
  1016. CMediaInfo::SetCopyLastError(
  1017. USHORT copyNumber,
  1018. HRESULT lastError
  1019. )
  1020. /*++
  1021. Implements:
  1022. IMediaInfo::SetCopyLastError
  1023. --*/
  1024. {
  1025. HRESULT hr = S_OK;
  1026. WsbTraceIn(OLESTR("CMediaInfo::SetCopyLastError"),OLESTR("Last Error = <%ls>"), WsbHrAsString(lastError));
  1027. try {
  1028. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  1029. E_INVALIDARG);
  1030. m_Copy[copyNumber - 1].lastError = lastError;
  1031. } WsbCatch(hr);
  1032. WsbTraceOut(OLESTR("CMediaInfo::SetCopyLastError"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1033. return(hr);
  1034. }
  1035. HRESULT
  1036. CMediaInfo::SetCopyMediaSubsystemId(
  1037. USHORT copyNumber,
  1038. GUID mediaSubsystemId
  1039. )
  1040. /*++
  1041. Implements:
  1042. IMediaInfo::SetCopyMediaSubsystemId
  1043. --*/
  1044. {
  1045. HRESULT hr = S_OK;
  1046. WsbTraceIn(OLESTR("CMediaInfo::SetCopyMediaSubsystemId"),OLESTR("SubsystemId = <%ls>"), WsbGuidAsString(mediaSubsystemId));
  1047. try {
  1048. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  1049. E_INVALIDARG);
  1050. m_Copy[copyNumber - 1].id = mediaSubsystemId;
  1051. } WsbCatch(hr);
  1052. WsbTraceOut(OLESTR("CMediaInfo::SetCopyMediaSubsystemId"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1053. return(hr);
  1054. }
  1055. HRESULT
  1056. CMediaInfo::SetCopyUpdate(
  1057. USHORT copyNumber,
  1058. FILETIME update
  1059. )
  1060. /*++
  1061. Implements:
  1062. IMediaInfo::SetCopyUpdate
  1063. --*/
  1064. {
  1065. HRESULT hr = S_OK;
  1066. WsbTraceIn(OLESTR("CMediaInfo::SetCopyUpdate"),OLESTR("update = <%ls>"), WsbFiletimeAsString(FALSE, update));
  1067. try {
  1068. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  1069. E_INVALIDARG);
  1070. m_Copy[copyNumber - 1].lastUpdate = update;
  1071. } WsbCatch(hr);
  1072. WsbTraceOut(OLESTR("CMediaInfo::SetCopyUpdate"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1073. return(hr);
  1074. }
  1075. HRESULT
  1076. CMediaInfo::SetDescription(
  1077. OLECHAR *description
  1078. )
  1079. /*++
  1080. Implements:
  1081. IMediaInfo::SetDescription
  1082. --*/
  1083. {
  1084. HRESULT hr = S_OK;
  1085. WsbTraceIn(OLESTR("CMediaInfo::SetDescription"),OLESTR("description = <%ls>"), description);
  1086. try {
  1087. WsbAssertPointer(description);
  1088. m_Master.description = description;
  1089. } WsbCatch(hr);
  1090. WsbTraceOut(OLESTR("CMediaInfo::SetDescription"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1091. return(hr);
  1092. }
  1093. HRESULT
  1094. CMediaInfo::SetFreeBytes(
  1095. LONGLONG FreeBytes
  1096. )
  1097. /*++
  1098. Implements:
  1099. IMediaInfo::SetFreeBytes
  1100. --*/
  1101. {
  1102. HRESULT hr = S_OK;
  1103. WsbTraceIn(OLESTR("CMediaInfo::SetFreeBytes"),OLESTR("Free Space = <%ls>"), WsbLonglongAsString(FreeBytes));
  1104. try {
  1105. m_Master.freeBytes = FreeBytes;
  1106. } WsbCatch(hr);
  1107. WsbTraceOut(OLESTR("CMediaInfo::SetFreeBytes"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1108. return(hr);
  1109. }
  1110. HRESULT
  1111. CMediaInfo::SetId(
  1112. GUID id
  1113. )
  1114. /*++
  1115. Implements:
  1116. IMediaInfo::SetId
  1117. --*/
  1118. {
  1119. HRESULT hr = S_OK;
  1120. WsbTraceIn(OLESTR("CMediaInfo::SetId"),OLESTR("ID = <%ls>"), WsbGuidAsString(id));
  1121. try {
  1122. m_Master.id = id;
  1123. } WsbCatch(hr);
  1124. WsbTraceOut(OLESTR("CMediaInfo::SetId"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1125. return(hr);
  1126. }
  1127. HRESULT
  1128. CMediaInfo::SetLastError(
  1129. HRESULT lastError
  1130. )
  1131. /*++
  1132. Implements:
  1133. IMediaInfo::SetLastError
  1134. --*/
  1135. {
  1136. HRESULT hr = S_OK;
  1137. WsbTraceIn(OLESTR("CMediaInfo::SetLastError"),OLESTR("last error = <%ls>"), WsbHrAsString(lastError));
  1138. try {
  1139. m_Master.lastError = lastError;
  1140. } WsbCatch(hr);
  1141. WsbTraceOut(OLESTR("CMediaInfo::SetLastError"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1142. return(hr);
  1143. }
  1144. HRESULT
  1145. CMediaInfo::SetLogicalValidBytes(
  1146. LONGLONG logicalValidBytes
  1147. )
  1148. /*++
  1149. Implements:
  1150. IMediaInfo::SetLogicalValidBytes
  1151. --*/
  1152. {
  1153. HRESULT hr = S_OK;
  1154. WsbTraceIn(OLESTR("CMediaInfo::SetLogicalValidBytes"),OLESTR("LogicalValidBytes = <%ls>"), WsbLonglongAsString(logicalValidBytes));
  1155. try {
  1156. m_LogicalValidBytes = logicalValidBytes;
  1157. } WsbCatch(hr);
  1158. WsbTraceOut(OLESTR("CMediaInfo::SetLogicalValidBytes"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1159. return(hr);
  1160. }
  1161. HRESULT
  1162. CMediaInfo::SetMediaInfo
  1163. (
  1164. GUID mediaId,
  1165. GUID mediaSubsystemId,
  1166. GUID storagePoolId,
  1167. LONGLONG FreeBytes,
  1168. LONGLONG Capacity,
  1169. HRESULT lastError,
  1170. short nextRemoteDataSet,
  1171. OLECHAR *description,
  1172. HSM_JOB_MEDIA_TYPE type,
  1173. OLECHAR *name,
  1174. BOOL RecallOnly,
  1175. FILETIME update,
  1176. LONGLONG logicalValidBytes,
  1177. BOOL recreate
  1178. )
  1179. /*++
  1180. Implements:
  1181. IMediaInfo::SetMediaInfo().
  1182. --*/
  1183. {
  1184. WsbTraceIn(OLESTR("CMediaInfo::SetMediaInfo"), OLESTR(""));
  1185. WsbTrace(OLESTR("CMediaInfo::SetMediaInfo id = <%ls>, SubsystemId = <%ls>, StoragePoolId = <%ls>\n"),
  1186. WsbGuidAsString(mediaId),
  1187. WsbQuickString(WsbGuidAsString(mediaSubsystemId)),
  1188. WsbQuickString(WsbGuidAsString(storagePoolId)));
  1189. WsbTrace(OLESTR("CMediaInfo::SetMediaInfo FreeBytes = <%ls>, Capacity = <%ls>, lastError = <%ls>\n"),
  1190. WsbLonglongAsString(FreeBytes),
  1191. WsbQuickString(WsbLonglongAsString(Capacity)),
  1192. WsbHrAsString(lastError));
  1193. WsbTrace(OLESTR("CMediaInfo::SetMediaInfo NextRemoteDataSet = <%d>, Description = <%ls>, Type = <%d>\n"),
  1194. nextRemoteDataSet,
  1195. (OLECHAR *)description,
  1196. type);
  1197. WsbTrace(OLESTR("CMediaInfo::SetMediaInfo Name = <%ls>, RecallOnly = <%ls>, update = <%ls>\n"),
  1198. (OLECHAR *)name,
  1199. WsbBoolAsString(RecallOnly),
  1200. WsbFiletimeAsString(FALSE, update));
  1201. WsbTrace(OLESTR("CMediaInfo::SetMediaInfo logicalValidBytes = <%ls>, recreate = <%ls>\n)"),
  1202. WsbLonglongAsString(logicalValidBytes), WsbBoolAsString(m_Recreate));
  1203. m_isDirty = TRUE;
  1204. m_Master.id = mediaId;
  1205. m_Master.ntmsId = mediaSubsystemId;
  1206. m_Master.storagePoolId = storagePoolId;
  1207. m_Master.freeBytes = FreeBytes;
  1208. m_Master.capacity = Capacity;
  1209. m_Master.lastError = lastError;
  1210. m_Master.description = description;
  1211. m_Master.type = type;
  1212. m_Master.name = name;
  1213. m_Master.recallOnly = RecallOnly;
  1214. m_Master.lastUpdate = update;
  1215. m_Master.nextRemoteDataSet = nextRemoteDataSet;
  1216. m_LogicalValidBytes = logicalValidBytes;
  1217. m_Recreate = recreate;
  1218. WsbTraceOut(OLESTR("CMediaInfo::SetMediaInfo"), OLESTR("hr = <%ls>"),WsbHrAsString(S_OK));
  1219. return(S_OK);
  1220. }
  1221. HRESULT
  1222. CMediaInfo::SetMediaSubsystemId(
  1223. GUID mediaSubsystemId
  1224. )
  1225. /*++
  1226. Implements:
  1227. IMediaInfo::SetMediaSubsystemId
  1228. --*/
  1229. {
  1230. HRESULT hr = S_OK;
  1231. WsbTraceIn(OLESTR("CMediaInfo::SetMediaSubsystemId "),OLESTR("Subsystem Id = <%ls>"),
  1232. WsbGuidAsString(mediaSubsystemId));
  1233. try {
  1234. m_Master.ntmsId = mediaSubsystemId;
  1235. } WsbCatch(hr);
  1236. WsbTraceOut(OLESTR("CMediaInfo::SetMediaSubsystemId "), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1237. return(hr);
  1238. }
  1239. HRESULT
  1240. CMediaInfo::SetNextRemoteDataSet(
  1241. short nextRemoteDataSet
  1242. )
  1243. /*++
  1244. Implements:
  1245. IMediaInfo::SetNextRemoteDataSet
  1246. --*/
  1247. {
  1248. HRESULT hr = S_OK;
  1249. WsbTraceIn(OLESTR("CMediaInfo::SetNextRemoteDataSet"),OLESTR("Data Set = <%u>"), nextRemoteDataSet);
  1250. try {
  1251. m_Master.nextRemoteDataSet = nextRemoteDataSet;
  1252. m_LastKnownGoodMaster.nextRemoteDataSet = nextRemoteDataSet;
  1253. //
  1254. // Handle exception case where a copy reports more data sets than the
  1255. // master. This occurs when we increment the data set count, but
  1256. // never write to the media, then create a media copy, then write
  1257. // to the master which decrements the data set count to handle the
  1258. // missing data set, then finally increment the data set count.
  1259. for (int i=0; i< HSM_MAX_NUMBER_MEDIA_COPIES; i++) {
  1260. if (m_Copy[i].nextRemoteDataSet > 0) {
  1261. if (nextRemoteDataSet < m_Copy[i].nextRemoteDataSet) {
  1262. WsbAssert(nextRemoteDataSet+1 == m_Copy[i].nextRemoteDataSet, E_UNEXPECTED);
  1263. m_Copy[i].nextRemoteDataSet--;
  1264. }
  1265. }
  1266. }
  1267. } WsbCatch(hr);
  1268. WsbTraceOut(OLESTR("CMediaInfo::SetNextRemoteDataSet"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1269. return(hr);
  1270. }
  1271. HRESULT
  1272. CMediaInfo::SetRecallOnlyStatus(
  1273. BOOL RecallOnlyStatus
  1274. )
  1275. /*++
  1276. Implements:
  1277. IMediaInfo::SetRecallOnlyStatus
  1278. --*/
  1279. {
  1280. HRESULT hr = S_OK;
  1281. WsbTraceIn(OLESTR("CMediaInfo::SetRecallOnlyStatus"),OLESTR("Read Only Status = <%ls>"),
  1282. WsbBoolAsString(RecallOnlyStatus));
  1283. try {
  1284. m_Master.recallOnly = RecallOnlyStatus;
  1285. } WsbCatch(hr);
  1286. WsbTraceOut(OLESTR("CMediaInfo::SetRecallOnlyStatus"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1287. return(hr);
  1288. }
  1289. HRESULT
  1290. CMediaInfo::SetStoragePoolId(
  1291. GUID storagePoolId
  1292. )
  1293. /*++
  1294. Implements:
  1295. IMediaInfo::SetStoragePoolId
  1296. --*/
  1297. {
  1298. HRESULT hr = S_OK;
  1299. WsbTraceIn(OLESTR("CMediaInfo::SetStoragePoolId"),OLESTR("Storage Pool Id = <%ls>"),
  1300. WsbGuidAsString(storagePoolId));
  1301. try {
  1302. m_Master.storagePoolId = storagePoolId;
  1303. } WsbCatch(hr);
  1304. WsbTraceOut(OLESTR("CMediaInfo::SetStoragePoolId"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1305. return(hr);
  1306. }
  1307. HRESULT
  1308. CMediaInfo::SetType(
  1309. HSM_JOB_MEDIA_TYPE type
  1310. )
  1311. /*++
  1312. Implements:
  1313. IMediaInfo::SetType
  1314. --*/
  1315. {
  1316. HRESULT hr = S_OK;
  1317. WsbTraceIn(OLESTR("CMediaInfo::SetType"),OLESTR("type = <%u>"), (USHORT)type);
  1318. try {
  1319. m_Master.type = type;
  1320. } WsbCatch(hr);
  1321. WsbTraceOut(OLESTR("CMediaInfo::SetType"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1322. return(hr);
  1323. }
  1324. HRESULT
  1325. CMediaInfo::SetUpdate(
  1326. FILETIME update
  1327. )
  1328. /*++
  1329. Implements:
  1330. IMediaInfo::SetUpdate
  1331. --*/
  1332. {
  1333. HRESULT hr = S_OK;
  1334. WsbTraceIn(OLESTR("CMediaInfo::SetUpdate"),OLESTR("Update = <%ls>"),
  1335. WsbFiletimeAsString(FALSE, update));
  1336. try {
  1337. m_Master.lastUpdate = update;
  1338. } WsbCatch(hr);
  1339. WsbTraceOut(OLESTR("CMediaInfo::SetUpdate"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1340. return(hr);
  1341. }
  1342. HRESULT
  1343. CMediaInfo::Test
  1344. (
  1345. OUT USHORT *pTestsPassed,
  1346. OUT USHORT *pTestsFailed
  1347. )
  1348. /*++
  1349. Implements:
  1350. IWsbTestable::Test().
  1351. --*/
  1352. {
  1353. HRESULT hr = S_OK;
  1354. CComPtr<IMediaInfo> pMediaInfo1;
  1355. CComPtr<IMediaInfo> pMediaInfo2;
  1356. WsbTraceIn(OLESTR("CMediaInfo::Test"), OLESTR(""));
  1357. *pTestsPassed = *pTestsFailed = 0;
  1358. try {
  1359. hr = E_NOTIMPL;
  1360. } WsbCatch(hr);
  1361. WsbTraceOut(OLESTR("CMediaInfo::Test"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  1362. return( hr );
  1363. }
  1364. HRESULT
  1365. CMediaInfo::UpdateKey(
  1366. IWsbDbKey *pKey
  1367. )
  1368. /*++
  1369. Implements:
  1370. IWsbDbEntity::UpdateKey
  1371. --*/
  1372. {
  1373. HRESULT hr = S_OK;
  1374. WsbTraceIn(OLESTR("CMediaInfo::UpdateKey"),OLESTR(""));
  1375. try {
  1376. WsbAffirmHr(pKey->SetToGuid(m_Master.id));
  1377. } WsbCatch(hr);
  1378. WsbTraceOut(OLESTR("CMediaInfo::UpdateKey"),OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  1379. return(hr);
  1380. }
  1381. HRESULT
  1382. CMediaInfo::SetRecreate(
  1383. BOOL recreate
  1384. )
  1385. /*++
  1386. Implements:
  1387. IMediaInfo::SetRecreate
  1388. --*/
  1389. {
  1390. HRESULT hr = S_OK;
  1391. WsbTraceIn(OLESTR("CMediaInfo::SetRecreate"),OLESTR("Recreate = <%ls>"), WsbBoolAsString(recreate));
  1392. try {
  1393. m_Recreate = recreate;
  1394. } WsbCatch(hr);
  1395. WsbTraceOut(OLESTR("CMediaInfo::SetRecreate"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1396. return(hr);
  1397. }
  1398. HRESULT
  1399. CMediaInfo::GetRecreate(
  1400. BOOL *pRecreate
  1401. )
  1402. /*++
  1403. Implements:
  1404. IMediaInfo::GetRecreate
  1405. --*/
  1406. {
  1407. HRESULT hr = S_OK;
  1408. WsbTraceIn(OLESTR("CMediaInfo::GetRecreate"),OLESTR(""));
  1409. try {
  1410. WsbAssertPointer(pRecreate);
  1411. *pRecreate = m_Recreate;
  1412. } WsbCatch(hr);
  1413. WsbTraceOut(OLESTR("CMediaInfo::GetRecreate"), OLESTR("hr = <%ls>, recreate = <%ls>"),
  1414. WsbHrAsString(hr), WsbPtrToBoolAsString(pRecreate));
  1415. return(hr);
  1416. }
  1417. HRESULT
  1418. CMediaInfo::GetLastKnownGoodMasterInfo(
  1419. GUID* pId,
  1420. GUID *pNtmsId,
  1421. GUID *pStoragePoolId,
  1422. LONGLONG *pFreeBytes,
  1423. LONGLONG *pCapacity,
  1424. HRESULT *pLastError,
  1425. OLECHAR **pDescription,
  1426. ULONG descriptionBufferSize,
  1427. HSM_JOB_MEDIA_TYPE *pType,
  1428. OLECHAR **pName,
  1429. ULONG nameBufferSize,
  1430. BOOL *pRecallOnly,
  1431. FILETIME *pUpdate,
  1432. SHORT *pNextRemoteDataSet
  1433. )
  1434. /*++
  1435. Implements:
  1436. IMediaInfo::GetLastKnownGoodMasterInfo
  1437. --*/
  1438. {
  1439. HRESULT hr = S_OK;
  1440. WsbTraceIn(OLESTR("CMediaInfo::GetLastKnownGoodMasterInfo"),OLESTR(""));
  1441. try {
  1442. //Make sure we can provide data memebers
  1443. if (0 != pId) {
  1444. *pId = m_LastKnownGoodMaster.id;
  1445. }
  1446. if (0 != pNtmsId) {
  1447. *pNtmsId = m_LastKnownGoodMaster.ntmsId;
  1448. }
  1449. if (0 != pStoragePoolId) {
  1450. *pStoragePoolId = m_LastKnownGoodMaster.storagePoolId;
  1451. }
  1452. if (0 != pDescription) {
  1453. CWsbStringPtr tmpString;
  1454. tmpString = m_LastKnownGoodMaster.description;
  1455. tmpString.CopyTo(pDescription, descriptionBufferSize);
  1456. }
  1457. if (0 != pName) {
  1458. CWsbStringPtr tmpString;
  1459. tmpString = m_LastKnownGoodMaster.name;
  1460. tmpString.CopyTo(pName, nameBufferSize);
  1461. }
  1462. if (0 != pType) {
  1463. *pType = m_LastKnownGoodMaster.type;
  1464. }
  1465. if (0 != pUpdate) {
  1466. *pUpdate = m_LastKnownGoodMaster.lastUpdate;
  1467. }
  1468. if (0 != pLastError) {
  1469. *pLastError = m_LastKnownGoodMaster.lastError;
  1470. }
  1471. if (0 != pRecallOnly) {
  1472. *pRecallOnly = m_LastKnownGoodMaster.recallOnly;
  1473. }
  1474. if (0 != pFreeBytes) {
  1475. *pFreeBytes = m_LastKnownGoodMaster.freeBytes;
  1476. }
  1477. if (0 != pCapacity) {
  1478. *pCapacity = m_LastKnownGoodMaster.capacity;
  1479. }
  1480. if (0 != pNextRemoteDataSet) {
  1481. *pNextRemoteDataSet = m_LastKnownGoodMaster.nextRemoteDataSet;
  1482. }
  1483. } WsbCatch(hr);
  1484. WsbTrace(OLESTR("CMediaInfo::GetLastKnownGoodMasterInfo Id = <%ls>, ntmsId = <%ls>, StgPoolId = <%ls>\n"),
  1485. WsbPtrToGuidAsString(pId), WsbQuickString(WsbPtrToGuidAsString(pNtmsId)),
  1486. WsbQuickString(WsbPtrToGuidAsString(pStoragePoolId)));
  1487. WsbTrace(OLESTR("CMediaInfo::GetLastKnownGoodMasterInfo Free = <%ls>, Cap = <%ls>, Last Error = <%ls>\n"),
  1488. WsbPtrToLonglongAsString(pFreeBytes),WsbQuickString(WsbPtrToLonglongAsString(pCapacity)),
  1489. WsbPtrToHrAsString(pLastError));
  1490. WsbTrace(OLESTR("CMediaInfo::GetLastKnownGoodMasterInfo Description = <%ls>, Type = <%d)\n"),
  1491. WsbPtrToStringAsString(pDescription),
  1492. WsbQuickString(WsbPtrToShortAsString((SHORT *)pType)));
  1493. WsbTrace(OLESTR("CMediaInfo::GetLastKnownGoodMasterInfo Name = <%ls>, RecallOnly = <%ls>, Update = <%ls>, NextRemoteDataSet = <%ls>\n"),
  1494. WsbQuickString(WsbPtrToStringAsString(pName)),
  1495. WsbQuickString(WsbPtrToBoolAsString(pRecallOnly)),
  1496. WsbPtrToFiletimeAsString(FALSE, pUpdate),
  1497. WsbPtrToShortAsString(pNextRemoteDataSet));
  1498. WsbTraceOut(OLESTR("CMediaInfo::GetLastKnownGoodMasterInfo"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1499. return(hr);
  1500. }
  1501. HRESULT
  1502. CMediaInfo::GetLKGMasterNextRemoteDataSet(
  1503. short *pNextRemoteDataSet
  1504. )
  1505. /*++
  1506. Implements:
  1507. IMediaInfo::GetLKGMasterNextRemoteDataSet
  1508. --*/
  1509. {
  1510. HRESULT hr = S_OK;
  1511. WsbTraceIn(OLESTR("CMediaInfo::GetLKGMasterNextRemoteDataSet"),OLESTR(""));
  1512. try {
  1513. WsbAssertPointer(pNextRemoteDataSet);
  1514. *pNextRemoteDataSet = m_LastKnownGoodMaster.nextRemoteDataSet;
  1515. } WsbCatch(hr);
  1516. WsbTraceOut(OLESTR("CMediaInfo::GetLKGMasterNextRemoteDataSet"), OLESTR("hr = <%ls>, Next Last-Known-Good-Master Remote-Data-Set = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString(pNextRemoteDataSet));
  1517. return(hr);
  1518. }
  1519. HRESULT
  1520. CMediaInfo::SetLastKnownGoodMasterInfo
  1521. (
  1522. GUID mediaId,
  1523. GUID mediaSubsystemId,
  1524. GUID storagePoolId,
  1525. LONGLONG FreeBytes,
  1526. LONGLONG Capacity,
  1527. HRESULT lastError,
  1528. OLECHAR *description,
  1529. HSM_JOB_MEDIA_TYPE type,
  1530. OLECHAR *name,
  1531. BOOL RecallOnly,
  1532. FILETIME update,
  1533. SHORT nextRemoteDataSet
  1534. )
  1535. /*++
  1536. Implements:
  1537. IMediaInfo::SetLastKnownGoodMasterInfo().
  1538. --*/
  1539. {
  1540. WsbTraceIn(OLESTR("CMediaInfo::SetLastKnownGoodMasterInfo"), OLESTR(""));
  1541. WsbTrace(OLESTR("CMediaInfo::SetLastKnownGoodMasterInfo"), OLESTR("id = <%ls>, SubsystemId = <%ls>, StoragePoolId = <%ls>\n"),
  1542. WsbGuidAsString(mediaId),
  1543. WsbQuickString(WsbGuidAsString(mediaSubsystemId)),
  1544. WsbQuickString(WsbGuidAsString(storagePoolId)));
  1545. WsbTrace(OLESTR("CMediaInfo::SetLastKnownGoodMasterInfo"), OLESTR("FreeBytes = <%ls>, Capacity = <%ls>, lastError = <%ls>\n"),
  1546. WsbLonglongAsString(FreeBytes),
  1547. WsbQuickString(WsbLonglongAsString(Capacity)),
  1548. WsbHrAsString(lastError));
  1549. WsbTrace(OLESTR("CMediaInfo::SetLastKnownGoodMasterInfo"), OLESTR("Description = <%ls>, Type = <%d>\n"),
  1550. (OLECHAR *)description,
  1551. type);
  1552. WsbTrace(OLESTR("CMediaInfo::SetLastKnownGoodMasterInfo"), OLESTR("Name = <%ls>, RecallOnly = <%ls>, update = <%ls>, nextRemoteDataSet = <%d>\n"),
  1553. (OLECHAR *)name,
  1554. WsbBoolAsString(RecallOnly),
  1555. WsbFiletimeAsString(FALSE, update),
  1556. nextRemoteDataSet);
  1557. m_isDirty = TRUE;
  1558. m_LastKnownGoodMaster.id = mediaId;
  1559. m_LastKnownGoodMaster.ntmsId = mediaSubsystemId;
  1560. m_LastKnownGoodMaster.storagePoolId = storagePoolId;
  1561. m_LastKnownGoodMaster.freeBytes = FreeBytes;
  1562. m_LastKnownGoodMaster.capacity = Capacity;
  1563. m_LastKnownGoodMaster.lastError = lastError;
  1564. m_LastKnownGoodMaster.description = description;
  1565. m_LastKnownGoodMaster.type = type;
  1566. m_LastKnownGoodMaster.name = name;
  1567. m_LastKnownGoodMaster.recallOnly = RecallOnly;
  1568. m_LastKnownGoodMaster.lastUpdate = update;
  1569. m_LastKnownGoodMaster.nextRemoteDataSet = nextRemoteDataSet;
  1570. WsbTraceOut(OLESTR("CMediaInfo::SetLastKnownGoodMasterInfo"), OLESTR("hr = <%ls>"),WsbHrAsString(S_OK));
  1571. return(S_OK);
  1572. }
  1573. HRESULT
  1574. CMediaInfo::DeleteCopy(
  1575. USHORT copyNumber
  1576. )
  1577. /*++
  1578. Implements:
  1579. IMediaInfo::DeleteCopy
  1580. --*/
  1581. {
  1582. HRESULT hr = S_OK;
  1583. WsbTraceIn(OLESTR("CMediaInfo::DeleteCopy"),OLESTR("copy = <%u>"), copyNumber);
  1584. try {
  1585. //
  1586. // Make sure we have a valid copy number
  1587. //
  1588. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  1589. E_INVALIDARG);
  1590. //
  1591. // Null out the existing copy information
  1592. //
  1593. m_Copy[copyNumber - 1].id = GUID_NULL;
  1594. m_Copy[copyNumber - 1].description = "";
  1595. m_Copy[copyNumber - 1].name = "";
  1596. m_Copy[copyNumber - 1].lastUpdate = WsbLLtoFT(0);
  1597. m_Copy[copyNumber - 1].lastError = S_OK;
  1598. m_Copy[copyNumber - 1].nextRemoteDataSet = 0;
  1599. } WsbCatch(hr);
  1600. WsbTraceOut(OLESTR("CMediaInfo::DeleteCopy"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1601. return(hr);
  1602. }
  1603. HRESULT
  1604. CMediaInfo::RecreateMaster( void )
  1605. /*++
  1606. Implements:
  1607. IMediaInfo::RecreateMaster
  1608. --*/
  1609. {
  1610. HRESULT hr = S_OK;
  1611. WsbTraceIn(OLESTR("CMediaInfo::RecreateMaster"),OLESTR(""));
  1612. try {
  1613. //
  1614. // Mark the master as one that needs to be recreated
  1615. //
  1616. m_Recreate = TRUE;
  1617. //
  1618. // Also, make sure we don't add data to this master
  1619. //
  1620. m_Master.recallOnly = TRUE;
  1621. } WsbCatch(hr);
  1622. WsbTraceOut(OLESTR("CMediaInfo::RecreateMaster"), OLESTR("hr = <%ls>"),
  1623. WsbHrAsString(hr));
  1624. return(hr);
  1625. }
  1626. //
  1627. // Internal (non COM) Helper functions
  1628. //
  1629. HRESULT
  1630. CMediaInfo::UpdateLastKnownGoodMaster( void )
  1631. /*++
  1632. Implements:
  1633. IMediaInfo::UpdateLastKnownGoodMaster
  1634. --*/
  1635. {
  1636. HRESULT hr = S_OK;
  1637. WsbTraceIn(OLESTR("CMediaInfo::UpdateLastKnownGoodMaster"),OLESTR(""));
  1638. m_LastKnownGoodMaster.id = m_Master.id;
  1639. m_LastKnownGoodMaster.ntmsId = m_Master.ntmsId;
  1640. m_LastKnownGoodMaster.storagePoolId = m_Master.storagePoolId;
  1641. m_LastKnownGoodMaster.freeBytes = m_Master.freeBytes;
  1642. m_LastKnownGoodMaster.capacity = m_Master.capacity;
  1643. m_LastKnownGoodMaster.lastError = m_Master.lastError;
  1644. m_LastKnownGoodMaster.description = m_Master.description;
  1645. m_LastKnownGoodMaster.type = m_Master.type;
  1646. m_LastKnownGoodMaster.name = m_Master.name;
  1647. m_LastKnownGoodMaster.recallOnly = m_Master.recallOnly;
  1648. m_LastKnownGoodMaster.lastUpdate = m_Master.lastUpdate;
  1649. m_LastKnownGoodMaster.nextRemoteDataSet = m_Master.nextRemoteDataSet;
  1650. WsbTraceOut(OLESTR("CMediaInfo::UpdateLastKnownGoodMaster"), OLESTR("hr = <%ls>"),
  1651. WsbHrAsString(hr));
  1652. return(hr);
  1653. }
  1654. HRESULT
  1655. CMediaInfo::WriteToDatabase( void )
  1656. /*++
  1657. Routine Description:
  1658. This function writes the information to the metadata
  1659. database. Note all other set functions require the
  1660. caller to call the Write() funtion for the entity.
  1661. Arguments:
  1662. None
  1663. Return Value:
  1664. S_OK: If the LastKnownGoodMaster is to be updated
  1665. --*/
  1666. {
  1667. HRESULT hr = S_OK;
  1668. BOOLEAN openedDb = FALSE;
  1669. CComPtr<IWsbDb> pSegmentDb;
  1670. CComPtr<IMediaInfo> pMediaInfo;
  1671. CComPtr<IHsmServer> pServer;
  1672. CComPtr<IWsbDbSession> pDbSession;
  1673. WsbTraceIn(OLESTR("CMediaInfo::WriteToDatabase"),OLESTR(""));
  1674. try {
  1675. //
  1676. // Find the database containing the record that matches this
  1677. // collectable.
  1678. //
  1679. WsbAffirmHr(CoCreateInstance( CLSID_HsmServer, 0, CLSCTX_SERVER, IID_IHsmServer, (void **)&pServer ));
  1680. WsbAffirmHr(pServer->GetSegmentDb(&pSegmentDb));
  1681. //
  1682. // Find the database entity
  1683. //
  1684. WsbAffirmHr(pSegmentDb->Open(&pDbSession));
  1685. openedDb = TRUE;
  1686. WsbTrace(OLESTR("CMediaInfo::WriteToDatabase - Opened the database\n"));
  1687. WsbAffirmHr(pSegmentDb->GetEntity(pDbSession, HSM_MEDIA_INFO_REC_TYPE, IID_IMediaInfo,
  1688. (void**)&pMediaInfo));
  1689. WsbAffirmHr(pMediaInfo->SetId(m_Master.id));
  1690. WsbAffirmHr(pMediaInfo->FindEQ());
  1691. //
  1692. // Write the changes to the database. To be sure that the "outside" world
  1693. // doesn't change anything but the allowed fields, just set the fields that are
  1694. // allowed to be changed.
  1695. //
  1696. WsbAffirmHr(pMediaInfo->SetRecreate(m_Recreate));
  1697. WsbAffirmHr(SetRecallOnlyStatus(m_Master.recallOnly));
  1698. for (int i = 1; i <= HSM_MAX_NUMBER_MEDIA_COPIES; i++) {
  1699. WsbAffirmHr(pMediaInfo->SetCopyInfo( (SHORT)i,
  1700. m_Copy[i-1].id,
  1701. (OLECHAR *)m_Copy[i-1].description,
  1702. (OLECHAR *)m_Copy[i-1].name,
  1703. m_Copy[i-1].lastUpdate,
  1704. m_Copy[i-1].lastError,
  1705. m_Copy[i-1].nextRemoteDataSet));
  1706. }
  1707. WsbAffirmHr(pMediaInfo->Write());
  1708. } WsbCatch(hr);
  1709. if (openedDb) {
  1710. WsbTrace(OLESTR("CMediaInfo::WriteToDatabase - Closing the database\n"));
  1711. pSegmentDb->Close(pDbSession);
  1712. pDbSession = 0;
  1713. openedDb = FALSE;
  1714. }
  1715. WsbTraceOut(OLESTR("CMediaInfo::WriteToDatabase"), OLESTR("hr = <%ls>"),
  1716. WsbHrAsString(hr));
  1717. return(hr);
  1718. }