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.

2240 lines
64 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. CWsbStringPtr strGuid;
  757. WsbAffirmHr(WsbSafeGuidAsString(m_Master.id, strGuid));
  758. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" id = %ls,"),
  759. (WCHAR *)strGuid));
  760. WsbAffirmHr(WsbSafeGuidAsString(m_Master.ntmsId, strGuid));
  761. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" ntmsId = %ls,"),
  762. (WCHAR *)strGuid));
  763. WsbAffirmHr(WsbSafeGuidAsString(m_Master.storagePoolId, strGuid));
  764. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" StoragePoolId = %ls,"),
  765. (WCHAR *)strGuid));
  766. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RS Media Name = %ls,"), (OLECHAR *)m_Master.description));
  767. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RMS Media Name = %ls,"), (OLECHAR *)m_Master.name));
  768. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Media Type = %u,"), m_Master.type));
  769. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Last Update = %ls,"),
  770. WsbFiletimeAsString(FALSE, m_Master.lastUpdate)));
  771. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Last Error = %ls,"), WsbHrAsString(m_Master.lastError)));
  772. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Is Recall Only = %ls,"), WsbBoolAsString(m_Master.recallOnly)));
  773. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Free Bytes = %ls,"),
  774. WsbQuickString(WsbLonglongAsString(m_Master.freeBytes))));
  775. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Capacity = %ls,"),
  776. WsbQuickString(WsbLonglongAsString(m_Master.capacity))));
  777. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Logical Valid Bytes = %ls,"),
  778. WsbQuickString(WsbLonglongAsString(m_LogicalValidBytes))));
  779. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" NextRemoteDataSet = %u,"), m_Master.nextRemoteDataSet));
  780. WsbAffirmHr(CWsbDbEntity::Print(pStream));
  781. //
  782. // Last Known Good Master
  783. //
  784. WsbAffirmHr(WsbSafeGuidAsString(m_LastKnownGoodMaster.id, strGuid));
  785. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR("\n Last Known Good id = %ls,"),
  786. (WCHAR *)strGuid));
  787. WsbAffirmHr(WsbSafeGuidAsString(m_LastKnownGoodMaster.ntmsId, strGuid));
  788. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" ntmsId = %ls,"),
  789. (WCHAR *)strGuid));
  790. WsbAffirmHr(WsbSafeGuidAsString(m_LastKnownGoodMaster.storagePoolId, strGuid));
  791. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" StoragePoolId = %ls,"),
  792. (WCHAR *)strGuid));
  793. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RS Media Name = %ls,"), (OLECHAR *)m_LastKnownGoodMaster.description));
  794. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RMS Media Name = %ls,"), (OLECHAR *)m_LastKnownGoodMaster.name));
  795. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Media Type = %u,"), m_LastKnownGoodMaster.type));
  796. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Last Update = %ls,"),
  797. WsbFiletimeAsString(FALSE, m_LastKnownGoodMaster.lastUpdate)));
  798. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Last Error = %ls,"), WsbHrAsString(m_LastKnownGoodMaster.lastError)));
  799. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Is Recall Only = %ls,"), WsbBoolAsString(m_LastKnownGoodMaster.recallOnly)));
  800. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Free Bytes = %ls,"),
  801. WsbQuickString(WsbLonglongAsString(m_LastKnownGoodMaster.freeBytes))));
  802. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Capacity = %ls,"),
  803. WsbQuickString(WsbLonglongAsString(m_LastKnownGoodMaster.capacity))));
  804. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" NextRemoteDataSet = %u,"), m_LastKnownGoodMaster.nextRemoteDataSet));
  805. //
  806. // Media Copies
  807. //
  808. for (int i = 0; i < HSM_MAX_NUMBER_MEDIA_COPIES; i++ ) {
  809. WsbAffirmHr(WsbSafeGuidAsString(m_Copy[i].id, strGuid));
  810. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR("\n RS Media Copy %d RMS ID = %ls,") ,(i+1), (WCHAR *)strGuid));
  811. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RS Media Name = %ls,") , (OLECHAR *)m_Copy[i].description));
  812. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RMS Media Name = %ls,") , (OLECHAR *)m_Copy[i].name));
  813. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Last Update = %ls,") , WsbFiletimeAsString(FALSE,m_Copy[i].lastUpdate)));
  814. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Last Error = %ls,") , WsbHrAsString(m_Copy[i].lastError)));
  815. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" NextRemoteDataSet = %u,") , m_Copy[i].nextRemoteDataSet));
  816. }
  817. } WsbCatch(hr);
  818. WsbTraceOut(OLESTR("CMediaInfo::Print"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  819. return(hr);
  820. }
  821. HRESULT CMediaInfo::Save
  822. (
  823. IN IStream* pStream,
  824. IN BOOL clearDirty
  825. )
  826. /*++
  827. Implements:
  828. IPersistStream::Save().
  829. --*/
  830. {
  831. HRESULT hr = S_OK;
  832. WsbTraceIn(OLESTR("CMediaInfo::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  833. WsbTrace(OLESTR("ID = <%ls>, rmsId = <%ls>, stgPoolId = <%ls>\n"),
  834. WsbQuickString(WsbGuidAsString(m_Master.id)),
  835. WsbQuickString(WsbGuidAsString(m_Master.ntmsId)),
  836. WsbQuickString(WsbGuidAsString(m_Master.storagePoolId)));
  837. WsbTrace(OLESTR("Description = <%ls>, name = <%ls>, type = <%u>\n"),
  838. (OLECHAR *)m_Master.description,
  839. (OLECHAR *)m_Master.name,
  840. m_Master.type);
  841. WsbTrace(OLESTR("FreeBytes = <%ls>, capacity = <%ls>, lastError = <%ls>\n"),
  842. WsbQuickString(WsbLonglongAsString(m_Master.freeBytes)),
  843. WsbQuickString(WsbLonglongAsString(m_Master.capacity)),
  844. WsbHrAsString(m_Master.lastError));
  845. WsbTrace(OLESTR("RecallOnly = <%ls>, NextRemotDataSet = <%u>\n"),
  846. WsbBoolAsString(m_Master.recallOnly),
  847. m_Master.nextRemoteDataSet);
  848. WsbTrace(OLESTR("LastUpdate = <%ls>, logicalValidBytes = <%ls>, Recreate = <%ls>\n"),
  849. WsbFiletimeAsString(FALSE, m_Master.lastUpdate),
  850. WsbLonglongAsString(m_LogicalValidBytes),
  851. WsbBoolAsString(m_Recreate));
  852. try {
  853. WsbAssert(0 != pStream, E_POINTER);
  854. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.id));
  855. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.ntmsId));
  856. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.storagePoolId));
  857. WsbAffirmHr(WsbSaveToStream(pStream, (OLECHAR *)m_Master.description));
  858. WsbAffirmHr(WsbSaveToStream(pStream, (OLECHAR *)m_Master.name));
  859. WsbAffirmHr(WsbSaveToStream(pStream, (LONG)m_Master.type));
  860. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.freeBytes));
  861. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.capacity));
  862. WsbAffirmHr(WsbSaveToStream(pStream, (LONG)m_Master.lastError));
  863. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.recallOnly));
  864. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.lastUpdate));
  865. WsbAffirmHr(WsbSaveToStream(pStream, m_Master.nextRemoteDataSet));
  866. WsbAffirmHr(WsbSaveToStream(pStream, m_LogicalValidBytes));
  867. WsbAffirmHr(WsbSaveToStream(pStream, m_Recreate));
  868. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.id));
  869. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.ntmsId));
  870. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.storagePoolId));
  871. WsbAffirmHr(WsbSaveToStream(pStream, (OLECHAR *)m_LastKnownGoodMaster.description));
  872. WsbAffirmHr(WsbSaveToStream(pStream, (OLECHAR *)m_LastKnownGoodMaster.name));
  873. WsbAffirmHr(WsbSaveToStream(pStream, (LONG)m_LastKnownGoodMaster.type));
  874. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.freeBytes));
  875. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.capacity));
  876. WsbAffirmHr(WsbSaveToStream(pStream, (LONG)m_LastKnownGoodMaster.lastError));
  877. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.recallOnly));
  878. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.lastUpdate));
  879. WsbAffirmHr(WsbSaveToStream(pStream, m_LastKnownGoodMaster.nextRemoteDataSet));
  880. for (int i = 0; i < HSM_MAX_NUMBER_MEDIA_COPIES; i++ ) {
  881. WsbAffirmHr(WsbSaveToStream(pStream, m_Copy[i].id));
  882. WsbAffirmHr(WsbSaveToStream(pStream, m_Copy[i].description));
  883. WsbAffirmHr(WsbSaveToStream(pStream, m_Copy[i].name));
  884. WsbAffirmHr(WsbSaveToStream(pStream, m_Copy[i].lastUpdate));
  885. WsbAffirmHr(WsbSaveToStream(pStream, (LONG)(m_Copy[i].lastError)));
  886. WsbAffirmHr(WsbSaveToStream(pStream, m_Copy[i].nextRemoteDataSet));
  887. }
  888. // If we got it saved and we were asked to clear the dirty bit, then
  889. // do so now.
  890. if (clearDirty) {
  891. m_isDirty = FALSE;
  892. }
  893. } WsbCatch(hr);
  894. WsbTraceOut(OLESTR("CMediaInfo::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  895. return(hr);
  896. }
  897. HRESULT
  898. CMediaInfo::SetName(
  899. OLECHAR *name
  900. )
  901. /*++
  902. Implements:
  903. IMediaInfo::SetName
  904. --*/
  905. {
  906. HRESULT hr = S_OK;
  907. WsbTraceIn(OLESTR("CMediaInfo::SetName"),OLESTR("Name = <%ls>"), name);
  908. try {
  909. WsbAssertPointer(name);
  910. m_Master.name = name;
  911. } WsbCatch(hr);
  912. WsbTraceOut(OLESTR("CMediaInfo::SetName"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  913. return(hr);
  914. }
  915. HRESULT
  916. CMediaInfo::SetCapacity(
  917. LONGLONG capacity
  918. )
  919. /*++
  920. Implements:
  921. IMediaInfo::SetCapacity
  922. --*/
  923. {
  924. HRESULT hr = S_OK;
  925. WsbTraceIn(OLESTR("CMediaInfo::SetCapacity"),OLESTR("Capacity = <%ls>"), WsbLonglongAsString(capacity));
  926. try {
  927. m_Master.capacity = capacity;
  928. } WsbCatch(hr);
  929. WsbTraceOut(OLESTR("CMediaInfo::SetCapacity"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  930. return(hr);
  931. }
  932. HRESULT
  933. CMediaInfo::SetCopyName(
  934. USHORT copyNumber,
  935. OLECHAR *name
  936. )
  937. /*++
  938. Implements:
  939. IMediaInfo::SetCopyName
  940. --*/
  941. {
  942. HRESULT hr = S_OK;
  943. WsbTraceIn(OLESTR("CMediaInfo::SetCopyName"),OLESTR("copy = <%u>, Name = <%ls>"), copyNumber, name);
  944. try {
  945. // This method is not being used and currently we don't save the copy name in RSS database
  946. // due to Windows Bugs 407340
  947. WsbThrow(E_NOTIMPL);
  948. /*** WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  949. E_INVALIDARG);
  950. m_Copy[copyNumber - 1].name = name; ***/
  951. } WsbCatch(hr);
  952. WsbTraceOut(OLESTR("CMediaInfo::SetCopyName"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  953. return(hr);
  954. }
  955. HRESULT
  956. CMediaInfo::SetCopyNextRemoteDataSet(
  957. USHORT copyNumber,
  958. SHORT nextRemoteDataSet
  959. )
  960. /*++
  961. Implements:
  962. IMediaInfo::SetCopyNextRemoteDataSet
  963. --*/
  964. {
  965. HRESULT hr = S_OK;
  966. WsbTraceIn(OLESTR("CMediaInfo::SetCopyNextRemoteDataSet"),OLESTR("copy = <%u>, NextRemoteDataSet = <%d>"), copyNumber, nextRemoteDataSet);
  967. try {
  968. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  969. E_INVALIDARG);
  970. m_Copy[copyNumber - 1].nextRemoteDataSet = nextRemoteDataSet;
  971. } WsbCatch(hr);
  972. WsbTraceOut(OLESTR("CMediaInfo::SetCopyNextRemoteDataSet"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  973. return(hr);
  974. }
  975. HRESULT
  976. CMediaInfo::SetCopyDescription(
  977. USHORT copyNumber,
  978. OLECHAR *description
  979. )
  980. /*++
  981. Implements:
  982. IMediaInfo::SetCopyDescription
  983. --*/
  984. {
  985. HRESULT hr = S_OK;
  986. WsbTraceIn(OLESTR("CMediaInfo::SetCopyDescription"),OLESTR("copy = <%u>, description = <%ls>"), copyNumber, description);
  987. try {
  988. // This method is not being used and currently we don't save the copy description in RSS database
  989. // due to Windows Bugs 407340
  990. WsbThrow(E_NOTIMPL);
  991. /*** WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  992. E_INVALIDARG);
  993. m_Copy[copyNumber - 1].description = description; ***/
  994. } WsbCatch(hr);
  995. WsbTraceOut(OLESTR("CMediaInfo::SetCopyDescription"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  996. return(hr);
  997. }
  998. HRESULT
  999. CMediaInfo::SetCopyInfo(
  1000. USHORT copyNumber,
  1001. GUID mediaSubsystemId,
  1002. OLECHAR *description,
  1003. OLECHAR *name,
  1004. FILETIME update,
  1005. HRESULT lastError,
  1006. SHORT nextRemoteDataSet
  1007. )
  1008. /*++
  1009. Implements:
  1010. IMediaInfo::SetCopyInfo
  1011. --*/
  1012. {
  1013. HRESULT hr = S_OK;
  1014. WsbTraceIn(OLESTR("CMediaInfo::SetCopyInfo"),OLESTR("copy = <%u>, SubsystemId = <%ls>, Description = <%ls>, Name = <%ls>, update = <%ls>, lastError = <%ls>, NextRemoteDataSet = <%d> "),
  1015. copyNumber, WsbGuidAsString(mediaSubsystemId), description, name, WsbFiletimeAsString(FALSE, update),WsbHrAsString(lastError));
  1016. try {
  1017. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  1018. E_INVALIDARG);
  1019. m_Copy[copyNumber - 1].id = mediaSubsystemId;
  1020. // We don't save the copy name & description in RSS database anymore due to Windows Bugs 407340
  1021. // The strings in the structure are already initialize to a null string so there's no need to set them again
  1022. /*** m_Copy[copyNumber - 1].description = description;
  1023. m_Copy[copyNumber - 1].name = name; ***/
  1024. m_Copy[copyNumber - 1].lastUpdate = update;
  1025. m_Copy[copyNumber - 1].lastError = lastError;
  1026. m_Copy[copyNumber - 1].nextRemoteDataSet = nextRemoteDataSet;
  1027. } WsbCatch(hr);
  1028. WsbTraceOut(OLESTR("CMediaInfo::SetCopyInfo"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1029. return(hr);
  1030. }
  1031. HRESULT
  1032. CMediaInfo::SetCopyLastError(
  1033. USHORT copyNumber,
  1034. HRESULT lastError
  1035. )
  1036. /*++
  1037. Implements:
  1038. IMediaInfo::SetCopyLastError
  1039. --*/
  1040. {
  1041. HRESULT hr = S_OK;
  1042. WsbTraceIn(OLESTR("CMediaInfo::SetCopyLastError"),OLESTR("Last Error = <%ls>"), WsbHrAsString(lastError));
  1043. try {
  1044. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  1045. E_INVALIDARG);
  1046. m_Copy[copyNumber - 1].lastError = lastError;
  1047. } WsbCatch(hr);
  1048. WsbTraceOut(OLESTR("CMediaInfo::SetCopyLastError"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1049. return(hr);
  1050. }
  1051. HRESULT
  1052. CMediaInfo::SetCopyMediaSubsystemId(
  1053. USHORT copyNumber,
  1054. GUID mediaSubsystemId
  1055. )
  1056. /*++
  1057. Implements:
  1058. IMediaInfo::SetCopyMediaSubsystemId
  1059. --*/
  1060. {
  1061. HRESULT hr = S_OK;
  1062. WsbTraceIn(OLESTR("CMediaInfo::SetCopyMediaSubsystemId"),OLESTR("SubsystemId = <%ls>"), WsbGuidAsString(mediaSubsystemId));
  1063. try {
  1064. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  1065. E_INVALIDARG);
  1066. m_Copy[copyNumber - 1].id = mediaSubsystemId;
  1067. } WsbCatch(hr);
  1068. WsbTraceOut(OLESTR("CMediaInfo::SetCopyMediaSubsystemId"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1069. return(hr);
  1070. }
  1071. HRESULT
  1072. CMediaInfo::SetCopyUpdate(
  1073. USHORT copyNumber,
  1074. FILETIME update
  1075. )
  1076. /*++
  1077. Implements:
  1078. IMediaInfo::SetCopyUpdate
  1079. --*/
  1080. {
  1081. HRESULT hr = S_OK;
  1082. WsbTraceIn(OLESTR("CMediaInfo::SetCopyUpdate"),OLESTR("update = <%ls>"), WsbFiletimeAsString(FALSE, update));
  1083. try {
  1084. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  1085. E_INVALIDARG);
  1086. m_Copy[copyNumber - 1].lastUpdate = update;
  1087. } WsbCatch(hr);
  1088. WsbTraceOut(OLESTR("CMediaInfo::SetCopyUpdate"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1089. return(hr);
  1090. }
  1091. HRESULT
  1092. CMediaInfo::SetDescription(
  1093. OLECHAR *description
  1094. )
  1095. /*++
  1096. Implements:
  1097. IMediaInfo::SetDescription
  1098. --*/
  1099. {
  1100. HRESULT hr = S_OK;
  1101. WsbTraceIn(OLESTR("CMediaInfo::SetDescription"),OLESTR("description = <%ls>"), description);
  1102. try {
  1103. WsbAssertPointer(description);
  1104. m_Master.description = description;
  1105. } WsbCatch(hr);
  1106. WsbTraceOut(OLESTR("CMediaInfo::SetDescription"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1107. return(hr);
  1108. }
  1109. HRESULT
  1110. CMediaInfo::SetFreeBytes(
  1111. LONGLONG FreeBytes
  1112. )
  1113. /*++
  1114. Implements:
  1115. IMediaInfo::SetFreeBytes
  1116. --*/
  1117. {
  1118. HRESULT hr = S_OK;
  1119. WsbTraceIn(OLESTR("CMediaInfo::SetFreeBytes"),OLESTR("Free Space = <%ls>"), WsbLonglongAsString(FreeBytes));
  1120. try {
  1121. m_Master.freeBytes = FreeBytes;
  1122. } WsbCatch(hr);
  1123. WsbTraceOut(OLESTR("CMediaInfo::SetFreeBytes"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1124. return(hr);
  1125. }
  1126. HRESULT
  1127. CMediaInfo::SetId(
  1128. GUID id
  1129. )
  1130. /*++
  1131. Implements:
  1132. IMediaInfo::SetId
  1133. --*/
  1134. {
  1135. HRESULT hr = S_OK;
  1136. WsbTraceIn(OLESTR("CMediaInfo::SetId"),OLESTR("ID = <%ls>"), WsbGuidAsString(id));
  1137. try {
  1138. m_Master.id = id;
  1139. } WsbCatch(hr);
  1140. WsbTraceOut(OLESTR("CMediaInfo::SetId"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1141. return(hr);
  1142. }
  1143. HRESULT
  1144. CMediaInfo::SetLastError(
  1145. HRESULT lastError
  1146. )
  1147. /*++
  1148. Implements:
  1149. IMediaInfo::SetLastError
  1150. --*/
  1151. {
  1152. HRESULT hr = S_OK;
  1153. WsbTraceIn(OLESTR("CMediaInfo::SetLastError"),OLESTR("last error = <%ls>"), WsbHrAsString(lastError));
  1154. try {
  1155. m_Master.lastError = lastError;
  1156. } WsbCatch(hr);
  1157. WsbTraceOut(OLESTR("CMediaInfo::SetLastError"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1158. return(hr);
  1159. }
  1160. HRESULT
  1161. CMediaInfo::SetLogicalValidBytes(
  1162. LONGLONG logicalValidBytes
  1163. )
  1164. /*++
  1165. Implements:
  1166. IMediaInfo::SetLogicalValidBytes
  1167. --*/
  1168. {
  1169. HRESULT hr = S_OK;
  1170. WsbTraceIn(OLESTR("CMediaInfo::SetLogicalValidBytes"),OLESTR("LogicalValidBytes = <%ls>"), WsbLonglongAsString(logicalValidBytes));
  1171. try {
  1172. m_LogicalValidBytes = logicalValidBytes;
  1173. } WsbCatch(hr);
  1174. WsbTraceOut(OLESTR("CMediaInfo::SetLogicalValidBytes"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1175. return(hr);
  1176. }
  1177. HRESULT
  1178. CMediaInfo::SetMediaInfo
  1179. (
  1180. GUID mediaId,
  1181. GUID mediaSubsystemId,
  1182. GUID storagePoolId,
  1183. LONGLONG FreeBytes,
  1184. LONGLONG Capacity,
  1185. HRESULT lastError,
  1186. short nextRemoteDataSet,
  1187. OLECHAR *description,
  1188. HSM_JOB_MEDIA_TYPE type,
  1189. OLECHAR *name,
  1190. BOOL RecallOnly,
  1191. FILETIME update,
  1192. LONGLONG logicalValidBytes,
  1193. BOOL recreate
  1194. )
  1195. /*++
  1196. Implements:
  1197. IMediaInfo::SetMediaInfo().
  1198. --*/
  1199. {
  1200. WsbTraceIn(OLESTR("CMediaInfo::SetMediaInfo"), OLESTR(""));
  1201. WsbTrace(OLESTR("CMediaInfo::SetMediaInfo id = <%ls>, SubsystemId = <%ls>, StoragePoolId = <%ls>\n"),
  1202. WsbGuidAsString(mediaId),
  1203. WsbQuickString(WsbGuidAsString(mediaSubsystemId)),
  1204. WsbQuickString(WsbGuidAsString(storagePoolId)));
  1205. WsbTrace(OLESTR("CMediaInfo::SetMediaInfo FreeBytes = <%ls>, Capacity = <%ls>, lastError = <%ls>\n"),
  1206. WsbLonglongAsString(FreeBytes),
  1207. WsbQuickString(WsbLonglongAsString(Capacity)),
  1208. WsbHrAsString(lastError));
  1209. WsbTrace(OLESTR("CMediaInfo::SetMediaInfo NextRemoteDataSet = <%d>, Description = <%ls>, Type = <%d>\n"),
  1210. nextRemoteDataSet,
  1211. (OLECHAR *)description,
  1212. type);
  1213. WsbTrace(OLESTR("CMediaInfo::SetMediaInfo Name = <%ls>, RecallOnly = <%ls>, update = <%ls>\n"),
  1214. (OLECHAR *)name,
  1215. WsbBoolAsString(RecallOnly),
  1216. WsbFiletimeAsString(FALSE, update));
  1217. WsbTrace(OLESTR("CMediaInfo::SetMediaInfo logicalValidBytes = <%ls>, recreate = <%ls>\n)"),
  1218. WsbLonglongAsString(logicalValidBytes), WsbBoolAsString(m_Recreate));
  1219. m_isDirty = TRUE;
  1220. m_Master.id = mediaId;
  1221. m_Master.ntmsId = mediaSubsystemId;
  1222. m_Master.storagePoolId = storagePoolId;
  1223. m_Master.freeBytes = FreeBytes;
  1224. m_Master.capacity = Capacity;
  1225. m_Master.lastError = lastError;
  1226. m_Master.description = description;
  1227. m_Master.type = type;
  1228. m_Master.name = name;
  1229. m_Master.recallOnly = RecallOnly;
  1230. m_Master.lastUpdate = update;
  1231. m_Master.nextRemoteDataSet = nextRemoteDataSet;
  1232. m_LogicalValidBytes = logicalValidBytes;
  1233. m_Recreate = recreate;
  1234. WsbTraceOut(OLESTR("CMediaInfo::SetMediaInfo"), OLESTR("hr = <%ls>"),WsbHrAsString(S_OK));
  1235. return(S_OK);
  1236. }
  1237. HRESULT
  1238. CMediaInfo::SetMediaSubsystemId(
  1239. GUID mediaSubsystemId
  1240. )
  1241. /*++
  1242. Implements:
  1243. IMediaInfo::SetMediaSubsystemId
  1244. --*/
  1245. {
  1246. HRESULT hr = S_OK;
  1247. WsbTraceIn(OLESTR("CMediaInfo::SetMediaSubsystemId "),OLESTR("Subsystem Id = <%ls>"),
  1248. WsbGuidAsString(mediaSubsystemId));
  1249. try {
  1250. m_Master.ntmsId = mediaSubsystemId;
  1251. } WsbCatch(hr);
  1252. WsbTraceOut(OLESTR("CMediaInfo::SetMediaSubsystemId "), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1253. return(hr);
  1254. }
  1255. HRESULT
  1256. CMediaInfo::SetNextRemoteDataSet(
  1257. short nextRemoteDataSet
  1258. )
  1259. /*++
  1260. Implements:
  1261. IMediaInfo::SetNextRemoteDataSet
  1262. --*/
  1263. {
  1264. HRESULT hr = S_OK;
  1265. WsbTraceIn(OLESTR("CMediaInfo::SetNextRemoteDataSet"),OLESTR("Data Set = <%u>"), nextRemoteDataSet);
  1266. try {
  1267. m_Master.nextRemoteDataSet = nextRemoteDataSet;
  1268. m_LastKnownGoodMaster.nextRemoteDataSet = nextRemoteDataSet;
  1269. //
  1270. // Handle exception case where a copy reports more data sets than the
  1271. // master. This occurs when we increment the data set count, but
  1272. // never write to the media, then create a media copy, then write
  1273. // to the master which decrements the data set count to handle the
  1274. // missing data set, then finally increment the data set count.
  1275. for (int i=0; i< HSM_MAX_NUMBER_MEDIA_COPIES; i++) {
  1276. if (m_Copy[i].nextRemoteDataSet > 0) {
  1277. if (nextRemoteDataSet < m_Copy[i].nextRemoteDataSet) {
  1278. WsbAssert(nextRemoteDataSet+1 == m_Copy[i].nextRemoteDataSet, E_UNEXPECTED);
  1279. m_Copy[i].nextRemoteDataSet--;
  1280. }
  1281. }
  1282. }
  1283. } WsbCatch(hr);
  1284. WsbTraceOut(OLESTR("CMediaInfo::SetNextRemoteDataSet"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1285. return(hr);
  1286. }
  1287. HRESULT
  1288. CMediaInfo::SetRecallOnlyStatus(
  1289. BOOL RecallOnlyStatus
  1290. )
  1291. /*++
  1292. Implements:
  1293. IMediaInfo::SetRecallOnlyStatus
  1294. --*/
  1295. {
  1296. HRESULT hr = S_OK;
  1297. WsbTraceIn(OLESTR("CMediaInfo::SetRecallOnlyStatus"),OLESTR("Read Only Status = <%ls>"),
  1298. WsbBoolAsString(RecallOnlyStatus));
  1299. try {
  1300. m_Master.recallOnly = RecallOnlyStatus;
  1301. } WsbCatch(hr);
  1302. WsbTraceOut(OLESTR("CMediaInfo::SetRecallOnlyStatus"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1303. return(hr);
  1304. }
  1305. HRESULT
  1306. CMediaInfo::SetStoragePoolId(
  1307. GUID storagePoolId
  1308. )
  1309. /*++
  1310. Implements:
  1311. IMediaInfo::SetStoragePoolId
  1312. --*/
  1313. {
  1314. HRESULT hr = S_OK;
  1315. WsbTraceIn(OLESTR("CMediaInfo::SetStoragePoolId"),OLESTR("Storage Pool Id = <%ls>"),
  1316. WsbGuidAsString(storagePoolId));
  1317. try {
  1318. m_Master.storagePoolId = storagePoolId;
  1319. } WsbCatch(hr);
  1320. WsbTraceOut(OLESTR("CMediaInfo::SetStoragePoolId"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1321. return(hr);
  1322. }
  1323. HRESULT
  1324. CMediaInfo::SetType(
  1325. HSM_JOB_MEDIA_TYPE type
  1326. )
  1327. /*++
  1328. Implements:
  1329. IMediaInfo::SetType
  1330. --*/
  1331. {
  1332. HRESULT hr = S_OK;
  1333. WsbTraceIn(OLESTR("CMediaInfo::SetType"),OLESTR("type = <%u>"), (USHORT)type);
  1334. try {
  1335. m_Master.type = type;
  1336. } WsbCatch(hr);
  1337. WsbTraceOut(OLESTR("CMediaInfo::SetType"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1338. return(hr);
  1339. }
  1340. HRESULT
  1341. CMediaInfo::SetUpdate(
  1342. FILETIME update
  1343. )
  1344. /*++
  1345. Implements:
  1346. IMediaInfo::SetUpdate
  1347. --*/
  1348. {
  1349. HRESULT hr = S_OK;
  1350. WsbTraceIn(OLESTR("CMediaInfo::SetUpdate"),OLESTR("Update = <%ls>"),
  1351. WsbFiletimeAsString(FALSE, update));
  1352. try {
  1353. m_Master.lastUpdate = update;
  1354. } WsbCatch(hr);
  1355. WsbTraceOut(OLESTR("CMediaInfo::SetUpdate"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1356. return(hr);
  1357. }
  1358. HRESULT
  1359. CMediaInfo::Test
  1360. (
  1361. OUT USHORT *pTestsPassed,
  1362. OUT USHORT *pTestsFailed
  1363. )
  1364. /*++
  1365. Implements:
  1366. IWsbTestable::Test().
  1367. --*/
  1368. {
  1369. HRESULT hr = S_OK;
  1370. CComPtr<IMediaInfo> pMediaInfo1;
  1371. CComPtr<IMediaInfo> pMediaInfo2;
  1372. WsbTraceIn(OLESTR("CMediaInfo::Test"), OLESTR(""));
  1373. *pTestsPassed = *pTestsFailed = 0;
  1374. try {
  1375. hr = E_NOTIMPL;
  1376. } WsbCatch(hr);
  1377. WsbTraceOut(OLESTR("CMediaInfo::Test"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  1378. return( hr );
  1379. }
  1380. HRESULT
  1381. CMediaInfo::UpdateKey(
  1382. IWsbDbKey *pKey
  1383. )
  1384. /*++
  1385. Implements:
  1386. IWsbDbEntity::UpdateKey
  1387. --*/
  1388. {
  1389. HRESULT hr = S_OK;
  1390. WsbTraceIn(OLESTR("CMediaInfo::UpdateKey"),OLESTR(""));
  1391. try {
  1392. WsbAffirmHr(pKey->SetToGuid(m_Master.id));
  1393. } WsbCatch(hr);
  1394. WsbTraceOut(OLESTR("CMediaInfo::UpdateKey"),OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  1395. return(hr);
  1396. }
  1397. HRESULT
  1398. CMediaInfo::SetRecreate(
  1399. BOOL recreate
  1400. )
  1401. /*++
  1402. Implements:
  1403. IMediaInfo::SetRecreate
  1404. --*/
  1405. {
  1406. HRESULT hr = S_OK;
  1407. WsbTraceIn(OLESTR("CMediaInfo::SetRecreate"),OLESTR("Recreate = <%ls>"), WsbBoolAsString(recreate));
  1408. try {
  1409. m_Recreate = recreate;
  1410. } WsbCatch(hr);
  1411. WsbTraceOut(OLESTR("CMediaInfo::SetRecreate"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1412. return(hr);
  1413. }
  1414. HRESULT
  1415. CMediaInfo::GetRecreate(
  1416. BOOL *pRecreate
  1417. )
  1418. /*++
  1419. Implements:
  1420. IMediaInfo::GetRecreate
  1421. --*/
  1422. {
  1423. HRESULT hr = S_OK;
  1424. WsbTraceIn(OLESTR("CMediaInfo::GetRecreate"),OLESTR(""));
  1425. try {
  1426. WsbAssertPointer(pRecreate);
  1427. *pRecreate = m_Recreate;
  1428. } WsbCatch(hr);
  1429. WsbTraceOut(OLESTR("CMediaInfo::GetRecreate"), OLESTR("hr = <%ls>, recreate = <%ls>"),
  1430. WsbHrAsString(hr), WsbPtrToBoolAsString(pRecreate));
  1431. return(hr);
  1432. }
  1433. HRESULT
  1434. CMediaInfo::GetLastKnownGoodMasterInfo(
  1435. GUID* pId,
  1436. GUID *pNtmsId,
  1437. GUID *pStoragePoolId,
  1438. LONGLONG *pFreeBytes,
  1439. LONGLONG *pCapacity,
  1440. HRESULT *pLastError,
  1441. OLECHAR **pDescription,
  1442. ULONG descriptionBufferSize,
  1443. HSM_JOB_MEDIA_TYPE *pType,
  1444. OLECHAR **pName,
  1445. ULONG nameBufferSize,
  1446. BOOL *pRecallOnly,
  1447. FILETIME *pUpdate,
  1448. SHORT *pNextRemoteDataSet
  1449. )
  1450. /*++
  1451. Implements:
  1452. IMediaInfo::GetLastKnownGoodMasterInfo
  1453. --*/
  1454. {
  1455. HRESULT hr = S_OK;
  1456. WsbTraceIn(OLESTR("CMediaInfo::GetLastKnownGoodMasterInfo"),OLESTR(""));
  1457. try {
  1458. //Make sure we can provide data memebers
  1459. if (0 != pId) {
  1460. *pId = m_LastKnownGoodMaster.id;
  1461. }
  1462. if (0 != pNtmsId) {
  1463. *pNtmsId = m_LastKnownGoodMaster.ntmsId;
  1464. }
  1465. if (0 != pStoragePoolId) {
  1466. *pStoragePoolId = m_LastKnownGoodMaster.storagePoolId;
  1467. }
  1468. if (0 != pDescription) {
  1469. CWsbStringPtr tmpString;
  1470. tmpString = m_LastKnownGoodMaster.description;
  1471. tmpString.CopyTo(pDescription, descriptionBufferSize);
  1472. }
  1473. if (0 != pName) {
  1474. CWsbStringPtr tmpString;
  1475. tmpString = m_LastKnownGoodMaster.name;
  1476. tmpString.CopyTo(pName, nameBufferSize);
  1477. }
  1478. if (0 != pType) {
  1479. *pType = m_LastKnownGoodMaster.type;
  1480. }
  1481. if (0 != pUpdate) {
  1482. *pUpdate = m_LastKnownGoodMaster.lastUpdate;
  1483. }
  1484. if (0 != pLastError) {
  1485. *pLastError = m_LastKnownGoodMaster.lastError;
  1486. }
  1487. if (0 != pRecallOnly) {
  1488. *pRecallOnly = m_LastKnownGoodMaster.recallOnly;
  1489. }
  1490. if (0 != pFreeBytes) {
  1491. *pFreeBytes = m_LastKnownGoodMaster.freeBytes;
  1492. }
  1493. if (0 != pCapacity) {
  1494. *pCapacity = m_LastKnownGoodMaster.capacity;
  1495. }
  1496. if (0 != pNextRemoteDataSet) {
  1497. *pNextRemoteDataSet = m_LastKnownGoodMaster.nextRemoteDataSet;
  1498. }
  1499. } WsbCatch(hr);
  1500. WsbTrace(OLESTR("CMediaInfo::GetLastKnownGoodMasterInfo Id = <%ls>, ntmsId = <%ls>, StgPoolId = <%ls>\n"),
  1501. WsbPtrToGuidAsString(pId), WsbQuickString(WsbPtrToGuidAsString(pNtmsId)),
  1502. WsbQuickString(WsbPtrToGuidAsString(pStoragePoolId)));
  1503. WsbTrace(OLESTR("CMediaInfo::GetLastKnownGoodMasterInfo Free = <%ls>, Cap = <%ls>, Last Error = <%ls>\n"),
  1504. WsbPtrToLonglongAsString(pFreeBytes),WsbQuickString(WsbPtrToLonglongAsString(pCapacity)),
  1505. WsbPtrToHrAsString(pLastError));
  1506. WsbTrace(OLESTR("CMediaInfo::GetLastKnownGoodMasterInfo Description = <%ls>, Type = <%d)\n"),
  1507. WsbPtrToStringAsString(pDescription),
  1508. WsbQuickString(WsbPtrToShortAsString((SHORT *)pType)));
  1509. WsbTrace(OLESTR("CMediaInfo::GetLastKnownGoodMasterInfo Name = <%ls>, RecallOnly = <%ls>, Update = <%ls>, NextRemoteDataSet = <%ls>\n"),
  1510. WsbQuickString(WsbPtrToStringAsString(pName)),
  1511. WsbQuickString(WsbPtrToBoolAsString(pRecallOnly)),
  1512. WsbPtrToFiletimeAsString(FALSE, pUpdate),
  1513. WsbPtrToShortAsString(pNextRemoteDataSet));
  1514. WsbTraceOut(OLESTR("CMediaInfo::GetLastKnownGoodMasterInfo"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1515. return(hr);
  1516. }
  1517. HRESULT
  1518. CMediaInfo::GetLKGMasterNextRemoteDataSet(
  1519. short *pNextRemoteDataSet
  1520. )
  1521. /*++
  1522. Implements:
  1523. IMediaInfo::GetLKGMasterNextRemoteDataSet
  1524. --*/
  1525. {
  1526. HRESULT hr = S_OK;
  1527. WsbTraceIn(OLESTR("CMediaInfo::GetLKGMasterNextRemoteDataSet"),OLESTR(""));
  1528. try {
  1529. WsbAssertPointer(pNextRemoteDataSet);
  1530. *pNextRemoteDataSet = m_LastKnownGoodMaster.nextRemoteDataSet;
  1531. } WsbCatch(hr);
  1532. WsbTraceOut(OLESTR("CMediaInfo::GetLKGMasterNextRemoteDataSet"), OLESTR("hr = <%ls>, Next Last-Known-Good-Master Remote-Data-Set = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString(pNextRemoteDataSet));
  1533. return(hr);
  1534. }
  1535. HRESULT
  1536. CMediaInfo::SetLastKnownGoodMasterInfo
  1537. (
  1538. GUID mediaId,
  1539. GUID mediaSubsystemId,
  1540. GUID storagePoolId,
  1541. LONGLONG FreeBytes,
  1542. LONGLONG Capacity,
  1543. HRESULT lastError,
  1544. OLECHAR *description,
  1545. HSM_JOB_MEDIA_TYPE type,
  1546. OLECHAR *name,
  1547. BOOL RecallOnly,
  1548. FILETIME update,
  1549. SHORT nextRemoteDataSet
  1550. )
  1551. /*++
  1552. Implements:
  1553. IMediaInfo::SetLastKnownGoodMasterInfo().
  1554. --*/
  1555. {
  1556. WsbTraceIn(OLESTR("CMediaInfo::SetLastKnownGoodMasterInfo"), OLESTR(""));
  1557. WsbTrace(OLESTR("CMediaInfo::SetLastKnownGoodMasterInfo"), OLESTR("id = <%ls>, SubsystemId = <%ls>, StoragePoolId = <%ls>\n"),
  1558. WsbGuidAsString(mediaId),
  1559. WsbQuickString(WsbGuidAsString(mediaSubsystemId)),
  1560. WsbQuickString(WsbGuidAsString(storagePoolId)));
  1561. WsbTrace(OLESTR("CMediaInfo::SetLastKnownGoodMasterInfo"), OLESTR("FreeBytes = <%ls>, Capacity = <%ls>, lastError = <%ls>\n"),
  1562. WsbLonglongAsString(FreeBytes),
  1563. WsbQuickString(WsbLonglongAsString(Capacity)),
  1564. WsbHrAsString(lastError));
  1565. WsbTrace(OLESTR("CMediaInfo::SetLastKnownGoodMasterInfo"), OLESTR("Description = <%ls>, Type = <%d>\n"),
  1566. (OLECHAR *)description,
  1567. type);
  1568. WsbTrace(OLESTR("CMediaInfo::SetLastKnownGoodMasterInfo"), OLESTR("Name = <%ls>, RecallOnly = <%ls>, update = <%ls>, nextRemoteDataSet = <%d>\n"),
  1569. (OLECHAR *)name,
  1570. WsbBoolAsString(RecallOnly),
  1571. WsbFiletimeAsString(FALSE, update),
  1572. nextRemoteDataSet);
  1573. m_isDirty = TRUE;
  1574. m_LastKnownGoodMaster.id = mediaId;
  1575. m_LastKnownGoodMaster.ntmsId = mediaSubsystemId;
  1576. m_LastKnownGoodMaster.storagePoolId = storagePoolId;
  1577. m_LastKnownGoodMaster.freeBytes = FreeBytes;
  1578. m_LastKnownGoodMaster.capacity = Capacity;
  1579. m_LastKnownGoodMaster.lastError = lastError;
  1580. m_LastKnownGoodMaster.type = type;
  1581. /*** These strings are not being used for anything and we need to save space in the media record - see Windows Bugs 407340
  1582. m_LastKnownGoodMaster.description = description;
  1583. m_LastKnownGoodMaster.name = name; ***/
  1584. m_LastKnownGoodMaster.recallOnly = RecallOnly;
  1585. m_LastKnownGoodMaster.lastUpdate = update;
  1586. m_LastKnownGoodMaster.nextRemoteDataSet = nextRemoteDataSet;
  1587. WsbTraceOut(OLESTR("CMediaInfo::SetLastKnownGoodMasterInfo"), OLESTR("hr = <%ls>"),WsbHrAsString(S_OK));
  1588. return(S_OK);
  1589. }
  1590. HRESULT
  1591. CMediaInfo::DeleteCopy(
  1592. USHORT copyNumber
  1593. )
  1594. /*++
  1595. Implements:
  1596. IMediaInfo::DeleteCopy
  1597. --*/
  1598. {
  1599. HRESULT hr = S_OK;
  1600. WsbTraceIn(OLESTR("CMediaInfo::DeleteCopy"),OLESTR("copy = <%u>"), copyNumber);
  1601. try {
  1602. //
  1603. // Make sure we have a valid copy number
  1604. //
  1605. WsbAffirm(((0 < copyNumber) && (copyNumber <= HSM_MAX_NUMBER_MEDIA_COPIES)),
  1606. E_INVALIDARG);
  1607. //
  1608. // Null out the existing copy information
  1609. //
  1610. m_Copy[copyNumber - 1].id = GUID_NULL;
  1611. m_Copy[copyNumber - 1].description = OLESTR("");
  1612. m_Copy[copyNumber - 1].name = OLESTR("");
  1613. m_Copy[copyNumber - 1].lastUpdate = WsbLLtoFT(0);
  1614. m_Copy[copyNumber - 1].lastError = S_OK;
  1615. m_Copy[copyNumber - 1].nextRemoteDataSet = 0;
  1616. } WsbCatch(hr);
  1617. WsbTraceOut(OLESTR("CMediaInfo::DeleteCopy"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1618. return(hr);
  1619. }
  1620. HRESULT
  1621. CMediaInfo::RecreateMaster( void )
  1622. /*++
  1623. Implements:
  1624. IMediaInfo::RecreateMaster
  1625. --*/
  1626. {
  1627. HRESULT hr = S_OK;
  1628. WsbTraceIn(OLESTR("CMediaInfo::RecreateMaster"),OLESTR(""));
  1629. try {
  1630. //
  1631. // Mark the master as one that needs to be recreated
  1632. //
  1633. m_Recreate = TRUE;
  1634. //
  1635. // Also, make sure we don't add data to this master
  1636. //
  1637. m_Master.recallOnly = TRUE;
  1638. } WsbCatch(hr);
  1639. WsbTraceOut(OLESTR("CMediaInfo::RecreateMaster"), OLESTR("hr = <%ls>"),
  1640. WsbHrAsString(hr));
  1641. return(hr);
  1642. }
  1643. //
  1644. // Internal (non COM) Helper functions
  1645. //
  1646. HRESULT
  1647. CMediaInfo::UpdateLastKnownGoodMaster( void )
  1648. /*++
  1649. Implements:
  1650. IMediaInfo::UpdateLastKnownGoodMaster
  1651. --*/
  1652. {
  1653. HRESULT hr = S_OK;
  1654. WsbTraceIn(OLESTR("CMediaInfo::UpdateLastKnownGoodMaster"),OLESTR(""));
  1655. m_LastKnownGoodMaster.id = m_Master.id;
  1656. m_LastKnownGoodMaster.ntmsId = m_Master.ntmsId;
  1657. m_LastKnownGoodMaster.storagePoolId = m_Master.storagePoolId;
  1658. m_LastKnownGoodMaster.freeBytes = m_Master.freeBytes;
  1659. m_LastKnownGoodMaster.capacity = m_Master.capacity;
  1660. m_LastKnownGoodMaster.lastError = m_Master.lastError;
  1661. m_LastKnownGoodMaster.type = m_Master.type;
  1662. // These strings are not being used for anything and we need to save space in the media record - see Windows Bugs 407340
  1663. m_LastKnownGoodMaster.description = OLESTR("");
  1664. m_LastKnownGoodMaster.name = OLESTR("");
  1665. /*** m_LastKnownGoodMaster.description = m_Master.description;
  1666. m_LastKnownGoodMaster.name = m_Master.name; ***/
  1667. m_LastKnownGoodMaster.recallOnly = m_Master.recallOnly;
  1668. m_LastKnownGoodMaster.lastUpdate = m_Master.lastUpdate;
  1669. m_LastKnownGoodMaster.nextRemoteDataSet = m_Master.nextRemoteDataSet;
  1670. WsbTraceOut(OLESTR("CMediaInfo::UpdateLastKnownGoodMaster"), OLESTR("hr = <%ls>"),
  1671. WsbHrAsString(hr));
  1672. return(hr);
  1673. }
  1674. HRESULT
  1675. CMediaInfo::WriteToDatabase( void )
  1676. /*++
  1677. Routine Description:
  1678. This function writes the information to the metadata
  1679. database. Note all other set functions require the
  1680. caller to call the Write() funtion for the entity.
  1681. Arguments:
  1682. None
  1683. Return Value:
  1684. S_OK: If the LastKnownGoodMaster is to be updated
  1685. --*/
  1686. {
  1687. HRESULT hr = S_OK;
  1688. BOOLEAN openedDb = FALSE;
  1689. CComPtr<IWsbDb> pSegmentDb;
  1690. CComPtr<IMediaInfo> pMediaInfo;
  1691. CComPtr<IHsmServer> pServer;
  1692. CComPtr<IWsbDbSession> pDbSession;
  1693. WsbTraceIn(OLESTR("CMediaInfo::WriteToDatabase"),OLESTR(""));
  1694. try {
  1695. //
  1696. // Find the database containing the record that matches this
  1697. // collectable.
  1698. //
  1699. WsbAffirmHr(CoCreateInstance( CLSID_HsmServer, 0, CLSCTX_SERVER, IID_IHsmServer, (void **)&pServer ));
  1700. WsbAffirmHr(pServer->GetSegmentDb(&pSegmentDb));
  1701. //
  1702. // Find the database entity
  1703. //
  1704. WsbAffirmHr(pSegmentDb->Open(&pDbSession));
  1705. openedDb = TRUE;
  1706. WsbTrace(OLESTR("CMediaInfo::WriteToDatabase - Opened the database\n"));
  1707. WsbAffirmHr(pSegmentDb->GetEntity(pDbSession, HSM_MEDIA_INFO_REC_TYPE, IID_IMediaInfo,
  1708. (void**)&pMediaInfo));
  1709. WsbAffirmHr(pMediaInfo->SetId(m_Master.id));
  1710. WsbAffirmHr(pMediaInfo->FindEQ());
  1711. //
  1712. // Write the changes to the database. To be sure that the "outside" world
  1713. // doesn't change anything but the allowed fields, just set the fields that are
  1714. // allowed to be changed.
  1715. //
  1716. WsbAffirmHr(pMediaInfo->SetRecreate(m_Recreate));
  1717. WsbAffirmHr(SetRecallOnlyStatus(m_Master.recallOnly));
  1718. for (int i = 1; i <= HSM_MAX_NUMBER_MEDIA_COPIES; i++) {
  1719. WsbAffirmHr(pMediaInfo->SetCopyInfo( (SHORT)i,
  1720. m_Copy[i-1].id,
  1721. (OLECHAR *)m_Copy[i-1].description,
  1722. (OLECHAR *)m_Copy[i-1].name,
  1723. m_Copy[i-1].lastUpdate,
  1724. m_Copy[i-1].lastError,
  1725. m_Copy[i-1].nextRemoteDataSet));
  1726. }
  1727. WsbAffirmHr(pMediaInfo->Write());
  1728. } WsbCatch(hr);
  1729. if (openedDb) {
  1730. WsbTrace(OLESTR("CMediaInfo::WriteToDatabase - Closing the database\n"));
  1731. pSegmentDb->Close(pDbSession);
  1732. pDbSession = 0;
  1733. openedDb = FALSE;
  1734. }
  1735. WsbTraceOut(OLESTR("CMediaInfo::WriteToDatabase"), OLESTR("hr = <%ls>"),
  1736. WsbHrAsString(hr));
  1737. return(hr);
  1738. }