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.

646 lines
12 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. fsarcvy.cpp
  5. Abstract:
  6. Defines the functions for the recovery record class.
  7. Author:
  8. Ron White [ronw] 8-Sep-1997
  9. Revision History:
  10. Steve Wimmer [stevew] 30-July-1998
  11. - updated CFsaRecoveryRec::GetClassId's WsbTraceOut to hold
  12. the proper function name
  13. --*/
  14. #include "stdafx.h"
  15. #include "wsb.h"
  16. #include "fsarcvy.h"
  17. #define WSB_TRACE_IS WSB_TRACE_BIT_FSA
  18. HRESULT
  19. CFsaRecoveryRec::GetBagId(
  20. OUT GUID* pId
  21. )
  22. /*++
  23. Implements:
  24. IFsaRecoveryRec::GetBagId
  25. --*/
  26. {
  27. HRESULT hr = S_OK;
  28. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetBagId"),OLESTR(""));
  29. try {
  30. WsbAssert(0 != pId, E_POINTER);
  31. *pId = m_BagId;
  32. } WsbCatch(hr);
  33. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetBagId"), OLESTR("hr = <%ls> Id = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pId));
  34. return(hr);
  35. }
  36. HRESULT
  37. CFsaRecoveryRec::GetBagOffset(
  38. OUT LONGLONG* pOffset
  39. )
  40. /*++
  41. Implements:
  42. IFsaRecoveryRec::GetBagOffset
  43. --*/
  44. {
  45. HRESULT hr = S_OK;
  46. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetBagOffset"),OLESTR(""));
  47. try {
  48. WsbAssert(0 != pOffset, E_POINTER);
  49. *pOffset = m_BagOffset;
  50. } WsbCatch(hr);
  51. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetBagOffset"), OLESTR("hr = <%ls> Offset = <%ls>"), WsbHrAsString(hr), WsbLonglongAsString(*pOffset));
  52. return(hr);
  53. }
  54. HRESULT
  55. CFsaRecoveryRec::GetFileId(
  56. OUT LONGLONG* pFileId
  57. )
  58. /*++
  59. Implements:
  60. IFsaRecoveryRec::GetFileId
  61. --*/
  62. {
  63. HRESULT hr = S_OK;
  64. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetFileId"),OLESTR(""));
  65. try {
  66. WsbAssert(0 != pFileId, E_POINTER);
  67. *pFileId = m_FileId;
  68. } WsbCatch(hr);
  69. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetFileId"),
  70. OLESTR("hr = <%ls> Size = <%ls>"), WsbHrAsString( hr ), WsbLonglongAsString( *pFileId ) );
  71. return(hr);
  72. }
  73. HRESULT
  74. CFsaRecoveryRec::GetOffsetSize(
  75. OUT LONGLONG* pOffset,
  76. OUT LONGLONG* pSize
  77. )
  78. /*++
  79. Implements:
  80. IFsaRecoveryRec::GetOffsetSize
  81. --*/
  82. {
  83. HRESULT hr = S_OK;
  84. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetOffsetSize"),OLESTR(""));
  85. try {
  86. WsbAssertPointer(pOffset);
  87. WsbAssertPointer(pSize);
  88. *pOffset = m_Offset;
  89. *pSize = m_Size;
  90. } WsbCatch(hr);
  91. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetOffsetSize"), OLESTR("hr = <%ls> Offset = %I64d, Size = %I64d"),
  92. WsbHrAsString(hr), *pOffset, *pSize);
  93. return(hr);
  94. }
  95. HRESULT
  96. CFsaRecoveryRec::GetPath(
  97. OUT OLECHAR** ppPath,
  98. IN ULONG bufferSize
  99. )
  100. /*++
  101. Implements:
  102. IFsaRecoveryRec::GetPath
  103. --*/
  104. {
  105. HRESULT hr = S_OK;
  106. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetPath"),OLESTR(""));
  107. try {
  108. WsbAssert(0 != ppPath, E_POINTER);
  109. WsbAffirmHr(m_Path.CopyTo(ppPath, bufferSize));
  110. WsbTrace( OLESTR("CFsaRecoveryRec::GetPath path = <%ls>\n"), *ppPath );
  111. } WsbCatch(hr);
  112. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetPath"),
  113. OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  114. return(hr);
  115. }
  116. HRESULT
  117. CFsaRecoveryRec::GetRecoveryCount(
  118. OUT LONG* pRecoveryCount
  119. )
  120. /*++
  121. Implements:
  122. IFsaRecoveryRec::GetRecoveryCount
  123. --*/
  124. {
  125. HRESULT hr = S_OK;
  126. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetRecoveryCount"),OLESTR(""));
  127. try {
  128. WsbAssertPointer(pRecoveryCount);
  129. *pRecoveryCount = m_RecoveryCount;
  130. } WsbCatch(hr);
  131. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetRecoveryCount"), OLESTR("hr = <%ls> RecoveryCount = %ld"),
  132. WsbHrAsString(hr), *pRecoveryCount);
  133. return(hr);
  134. }
  135. HRESULT
  136. CFsaRecoveryRec::GetStatus(
  137. OUT ULONG* pStatus
  138. )
  139. /*++
  140. Implements:
  141. IFsaRecoveryRec::GetStatus
  142. --*/
  143. {
  144. HRESULT hr = S_OK;
  145. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetStatus"),OLESTR(""));
  146. try {
  147. WsbAssertPointer(pStatus);
  148. *pStatus = m_Status;
  149. } WsbCatch(hr);
  150. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetStatus"), OLESTR("hr = <%ls> Status = %lx"),
  151. WsbHrAsString(hr), *pStatus);
  152. return(hr);
  153. }
  154. HRESULT
  155. CFsaRecoveryRec::FinalConstruct(
  156. void
  157. )
  158. /*++
  159. Implements:
  160. CComObjectRoot::FinalConstruct().
  161. --*/
  162. {
  163. HRESULT hr = S_OK;
  164. try {
  165. WsbAssertHr(CWsbDbEntity::FinalConstruct());
  166. m_BagId = GUID_NULL;
  167. m_BagOffset = 0;
  168. m_FileId = 0;
  169. m_Offset = 0;
  170. m_RecoveryCount = 0;
  171. m_Size = 0;
  172. m_Status = 0;
  173. } WsbCatch(hr);
  174. return(hr);
  175. }
  176. HRESULT
  177. CFsaRecoveryRec::FinalRelease(
  178. void
  179. )
  180. /*++
  181. Implements:
  182. CComObjectRoot::FinalRelease
  183. --*/
  184. {
  185. HRESULT hr = S_OK;
  186. CWsbDbEntity::FinalRelease();
  187. return(hr);
  188. }
  189. HRESULT CFsaRecoveryRec::GetClassID
  190. (
  191. OUT LPCLSID pclsid
  192. )
  193. /*++
  194. Implements:
  195. IPerist::GetClassID
  196. --*/
  197. {
  198. HRESULT hr = S_OK;
  199. WsbTraceIn(OLESTR("CFsaRecoveryRec::GetClassID"), OLESTR(""));
  200. try {
  201. WsbAssertPointer(pclsid);
  202. *pclsid = CLSID_CFsaRecoveryRec;
  203. } WsbCatch(hr);
  204. WsbTraceOut(OLESTR("CFsaRecoveryRec::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pclsid));
  205. return(hr);
  206. }
  207. HRESULT CFsaRecoveryRec::Load
  208. (
  209. IN IStream* pStream
  210. )
  211. /*++
  212. Implements:
  213. IPersistStream::Load
  214. --*/
  215. {
  216. HRESULT hr = S_OK;
  217. WsbTraceIn(OLESTR("CFsaRecoveryRec::Load"), OLESTR(""));
  218. try {
  219. OLECHAR* pPath = NULL;
  220. WsbAssertPointer(pStream);
  221. WsbAssertHr(WsbLoadFromStream(pStream, &m_BagId));
  222. WsbAssertHr(WsbLoadFromStream(pStream, &m_BagOffset));
  223. WsbAssertHr(WsbLoadFromStream(pStream, &m_FileId));
  224. WsbAssertHr(WsbLoadFromStream(pStream, &m_Offset));
  225. WsbAssertHr(WsbLoadFromStream(pStream, &m_Path, 0));
  226. WsbAssertHr(WsbLoadFromStream(pStream, &m_RecoveryCount));
  227. WsbAssertHr(WsbLoadFromStream(pStream, &m_Size));
  228. WsbAssertHr(WsbLoadFromStream(pStream, &m_Status));
  229. } WsbCatch(hr);
  230. WsbTraceOut(OLESTR("CFsaRecoveryRec::Load"),
  231. OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  232. return(hr);
  233. }
  234. HRESULT CFsaRecoveryRec::Print
  235. (
  236. IN IStream* pStream
  237. )
  238. /*++
  239. Implements:
  240. IWsbDbEntity::Print
  241. --*/
  242. {
  243. HRESULT hr = S_OK;
  244. WsbTraceIn(OLESTR("CFsaRecoveryRec::Print"), OLESTR(""));
  245. try {
  246. WsbAssertPointer(pStream);
  247. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" BagId = %ls"), WsbGuidAsString(m_BagId)));
  248. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" BagOffset = %I64d"), m_BagOffset));
  249. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" FileId = %I64d"), m_FileId));
  250. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Offset = %I64d"), m_Offset));
  251. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Size = %I64d"), m_Size));
  252. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" RecoveryCount = %ld"),
  253. m_RecoveryCount));
  254. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" Status = %lx"), m_Status));
  255. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(", Path = %ls"),
  256. static_cast<OLECHAR*>(m_Path)));
  257. } WsbCatch(hr);
  258. WsbTraceOut(OLESTR("CFsaRecoveryRec::Print"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  259. return(hr);
  260. }
  261. HRESULT CFsaRecoveryRec::Save
  262. (
  263. IN IStream* pStream,
  264. IN BOOL clearDirty
  265. )
  266. /*++
  267. Implements:
  268. IPersistStream::Save
  269. --*/
  270. {
  271. HRESULT hr = S_OK;
  272. WsbTraceIn(OLESTR("CFsaRecoveryRec::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  273. try {
  274. WsbAssertPointer(pStream);
  275. WsbAssertHr(WsbSaveToStream(pStream, m_BagId));
  276. WsbAssertHr(WsbSaveToStream(pStream, m_BagOffset));
  277. WsbAssertHr(WsbSaveToStream(pStream, m_FileId));
  278. WsbAssertHr(WsbSaveToStream(pStream, m_Offset));
  279. WsbAssertHr(WsbSaveToStream(pStream, m_Path));
  280. WsbAssertHr(WsbSaveToStream(pStream, m_RecoveryCount));
  281. WsbAssertHr(WsbSaveToStream(pStream, m_Size));
  282. WsbAssertHr(WsbSaveToStream(pStream, m_Status));
  283. // If we got it saved and we were asked to clear the dirty bit, then
  284. // do so now.
  285. if (clearDirty) {
  286. m_isDirty = FALSE;
  287. }
  288. } WsbCatch(hr);
  289. WsbTraceOut(OLESTR("CFsaRecoveryRec::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  290. return(hr);
  291. }
  292. HRESULT
  293. CFsaRecoveryRec::SetBagId(
  294. IN GUID BagId
  295. )
  296. /*++
  297. Implements:
  298. IFsaRecoveryRec::SetBagId
  299. --*/
  300. {
  301. HRESULT hr = S_OK;
  302. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetBagId"),OLESTR(""));
  303. m_BagId = BagId;
  304. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetBagId"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  305. return(hr);
  306. }
  307. HRESULT
  308. CFsaRecoveryRec::SetBagOffset(
  309. IN LONGLONG BagOffset
  310. )
  311. /*++
  312. Implements:
  313. IFsaRecoveryRec::SetBagOffset
  314. --*/
  315. {
  316. HRESULT hr = S_OK;
  317. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetBagOffset"),OLESTR(""));
  318. m_BagOffset = BagOffset;
  319. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetBagOffset"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  320. return(hr);
  321. }
  322. HRESULT
  323. CFsaRecoveryRec::SetFileId(
  324. IN LONGLONG FileId
  325. )
  326. /*++
  327. Implements:
  328. IFsaRecoveryRec::SetFileId
  329. --*/
  330. {
  331. HRESULT hr = S_OK;
  332. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetFileId"),OLESTR(""));
  333. try {
  334. m_FileId = FileId;
  335. } WsbCatch(hr);
  336. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetFileId"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  337. return(hr);
  338. }
  339. HRESULT
  340. CFsaRecoveryRec::SetOffsetSize(
  341. IN LONGLONG Offset,
  342. IN LONGLONG Size
  343. )
  344. /*++
  345. Implements:
  346. IFsaRecoveryRec::SetOffsetSize
  347. --*/
  348. {
  349. HRESULT hr = S_OK;
  350. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetOffsetSize"),OLESTR("Offset = %I64d, Size = %I64d"),
  351. Offset, Size);
  352. m_Offset = Offset;
  353. m_Size = Size;
  354. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetOffsetSize"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  355. return(hr);
  356. }
  357. HRESULT
  358. CFsaRecoveryRec::SetPath(
  359. IN OLECHAR* Path
  360. )
  361. /*++
  362. Implements:
  363. IFsaRecoveryRec::SetPath
  364. --*/
  365. {
  366. HRESULT hr = S_OK;
  367. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetPath"),OLESTR("Path = <%ls>"),
  368. Path);
  369. try {
  370. m_Path = Path;
  371. } WsbCatch(hr);
  372. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetPath"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  373. return(hr);
  374. }
  375. HRESULT
  376. CFsaRecoveryRec::SetRecoveryCount(
  377. IN LONG RecoveryCount
  378. )
  379. /*++
  380. Implements:
  381. IFsaRecoveryRec::SetRecoveryCount
  382. --*/
  383. {
  384. HRESULT hr = S_OK;
  385. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetRecoveryCount"),OLESTR("RecoveryCount = %ld"),
  386. RecoveryCount);
  387. m_RecoveryCount = RecoveryCount;
  388. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetRecoveryCount"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  389. return(hr);
  390. }
  391. HRESULT
  392. CFsaRecoveryRec::SetStatus(
  393. IN ULONG Status
  394. )
  395. /*++
  396. Implements:
  397. IFsaRecoveryRec::SetStatus
  398. --*/
  399. {
  400. HRESULT hr = S_OK;
  401. WsbTraceIn(OLESTR("CFsaRecoveryRec::SetStatus"),OLESTR("Status = %lx"),
  402. Status);
  403. m_Status = Status;
  404. WsbTraceOut(OLESTR("CFsaRecoveryRec::SetStatus"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  405. return(hr);
  406. }
  407. HRESULT
  408. CFsaRecoveryRec::UpdateKey(
  409. IWsbDbKey *pKey
  410. )
  411. /*++
  412. Implements:
  413. IWsbDbEntity::UpdateKey
  414. --*/
  415. {
  416. HRESULT hr = E_FAIL;
  417. try {
  418. UCHAR FileKey[RECOVERY_KEY_SIZE + 1];
  419. ULONG KeyType;
  420. WsbAffirmHr(pKey->GetType(&KeyType));
  421. if (RECOVERY_KEY_TYPE == KeyType) {
  422. WsbAffirmHr(SquashFilepath(m_Path, FileKey, RECOVERY_KEY_SIZE));
  423. WsbAffirmHr(pKey->SetToBytes(FileKey, RECOVERY_KEY_SIZE));
  424. hr = S_OK;
  425. }
  426. } WsbCatch(hr);
  427. return(hr);
  428. }