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.

387 lines
9.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: dl.hxx
  7. //
  8. // Contents: Delta list headers for streams
  9. //
  10. // Classes: SDeltaBlock
  11. // CDeltaList
  12. //
  13. // History: 28-Jul-92 PhilipLa Created.
  14. //
  15. //--------------------------------------------------------------------------
  16. #ifndef __DL_HXX__
  17. #define __DL_HXX__
  18. #define DL_GET 0
  19. #define DL_CREATE 1
  20. #define DL_READ 2
  21. class CTransactedStream;
  22. SAFE_DFBASED_PTR(CBasedTransactedStreamPtr, CTransactedStream);
  23. #define CBITPERUSHORT 16
  24. //+-------------------------------------------------------------------------
  25. //
  26. // Class: SDeltaBlock (db)
  27. //
  28. // Purpose: A single block of delta list entries.
  29. //
  30. // Interface:
  31. //
  32. // History: 10-Jul-92 PhilipLa Created.
  33. //
  34. // Notes:
  35. //
  36. //--------------------------------------------------------------------------
  37. struct SDeltaBlock
  38. {
  39. public:
  40. #ifndef _MAC
  41. inline
  42. #endif
  43. SDeltaBlock();
  44. #ifndef _MAC
  45. inline
  46. #endif
  47. void *operator new(size_t size, IMalloc * const pMalloc);
  48. inline const BOOL IsOwned(const USHORT uOffset);
  49. inline void MakeOwn(const USHORT uOffset);
  50. inline void DisOwn(const USHORT uOffset);
  51. SECT _sect[CSECTPERBLOCK];
  52. USHORT _fOwn[(CSECTPERBLOCK / CBITPERUSHORT)];
  53. };
  54. SAFE_DFBASED_PTR(CBasedDeltaBlockPtr, SDeltaBlock);
  55. SAFE_DFBASED_PTR(CBasedDeltaBlockPtrPtr, CBasedDeltaBlockPtr);
  56. inline const BOOL SDeltaBlock::IsOwned(const USHORT uOffset)
  57. {
  58. msfAssert(uOffset < CSECTPERBLOCK);
  59. return (_fOwn[uOffset / CBITPERUSHORT] &
  60. (1 << (uOffset % CBITPERUSHORT))) != 0;
  61. }
  62. inline void SDeltaBlock::MakeOwn(const USHORT uOffset)
  63. {
  64. msfAssert(uOffset < CSECTPERBLOCK);
  65. msfAssert(!IsOwned(uOffset));
  66. msfAssert((uOffset / CBITPERUSHORT) < (CSECTPERBLOCK / CBITPERUSHORT));
  67. _fOwn[uOffset / CBITPERUSHORT] |= (1 << (uOffset % CBITPERUSHORT));
  68. }
  69. inline void SDeltaBlock::DisOwn(const USHORT uOffset)
  70. {
  71. msfAssert(uOffset < CSECTPERBLOCK);
  72. msfAssert(IsOwned(uOffset));
  73. msfAssert((uOffset / CBITPERUSHORT) < (CSECTPERBLOCK / CBITPERUSHORT));
  74. _fOwn[uOffset / CBITPERUSHORT] &= ~(1 << (uOffset % CBITPERUSHORT));
  75. }
  76. //+-------------------------------------------------------------------------
  77. //
  78. // Class: CDeltaList (dl)
  79. //
  80. // Purpose: Delta list for transacted streans.
  81. //
  82. // Interface:
  83. //
  84. // History: 21-Jan-92 PhilipLa Created.
  85. //
  86. // Notes:
  87. //
  88. //--------------------------------------------------------------------------
  89. class CDeltaList
  90. {
  91. public:
  92. CDeltaList(CMStream *pms, CMStream *pmsScratch);
  93. #ifdef LARGE_STREAMS
  94. SCODE Init(ULONGLONG ulSize, CTransactedStream *ptsParent);
  95. SCODE InitResize(ULONGLONG ulSize);
  96. #else
  97. SCODE Init(ULONG ulSize, CTransactedStream *ptsParent);
  98. SCODE InitResize(ULONG ulSize);
  99. #endif
  100. ~CDeltaList();
  101. SCODE GetMap(SECT sectOld, const DWORD dwFlags, SECT *psectRet);
  102. void BeginCommit(CTransactedStream *ptsParent);
  103. void EndCommit(CDeltaList *pdlNew, DFLAGS df);
  104. inline ILockBytes *GetDataILB(void);
  105. inline ILockBytes *GetControlILB(void);
  106. inline CFat * GetDataFat(void);
  107. inline CFat * GetControlFat(void);
  108. inline USHORT GetDataSectorSize(void);
  109. inline USHORT GetDataSectorShift(void);
  110. inline USHORT GetControlSectorSize(void);
  111. void Empty(void);
  112. inline BOOL IsEmpty(void);
  113. inline BOOL IsInMemory(void);
  114. inline BOOL IsInStream(void);
  115. inline BOOL IsNoScratch(void);
  116. SCODE IsOwned(SECT sect, SECT sectMap, BOOL *fOwn);
  117. inline CMStream * GetMStream();
  118. SCODE ReleaseInvalidSects(SECT sectMaxValid);
  119. private:
  120. CBasedDeltaBlockPtrPtr _apdb;
  121. ULONG _ulSize;
  122. CBasedMStreamPtr _pmsScratch;
  123. CBasedMStreamPtr _pms;
  124. CBasedTransactedStreamPtr _ptsParent;
  125. SECT _sectStart;
  126. SCODE InitStreamBlock(ULONG ul);
  127. SCODE ReadMap(SECT *psectStart, SECT sect, SECT *psectRet);
  128. SCODE WriteMap(SECT *psectStart, SECT sect, SECT sectMap);
  129. void FreeStream(SECT sectStart, ULONG ulSize);
  130. SCODE FindOffset(
  131. SECT *psectStart,
  132. SECT sect,
  133. ULARGE_INTEGER *pulRet,
  134. BOOL fWrite);
  135. SCODE DumpList(void);
  136. #if DBG == 1
  137. void PrintList(void);
  138. #endif
  139. void ReleaseBlock(ULONG oBlock);
  140. inline CBasedDeltaBlockPtr * GetNewDeltaArray(ULONG ulSize);
  141. };
  142. SAFE_DFBASED_PTR(CBasedDeltaListPtr, CDeltaList);
  143. //-----------------
  144. inline CMStream * CDeltaList::GetMStream()
  145. {
  146. if (!IsNoScratch())
  147. return _pmsScratch;
  148. else
  149. return _pms;
  150. }
  151. //+-------------------------------------------------------------------------
  152. //
  153. // Method: CDeltaList::GetDataILB, public
  154. //
  155. // Synopsis: Return pointer to ILockBytes for storing data
  156. //
  157. // History: 10-Jul-92 PhilipLa Created.
  158. //
  159. //--------------------------------------------------------------------------
  160. inline ILockBytes * CDeltaList::GetDataILB(void)
  161. {
  162. if (_pms)
  163. return _pms->GetILB();
  164. else
  165. return _pmsScratch->GetILB();
  166. }
  167. //+-------------------------------------------------------------------------
  168. //
  169. // Method: CDeltaList::GetControlILB, public
  170. //
  171. // Synopsis: Return pointer to ILockBytes for storing control information
  172. //
  173. // History: 10-Jul-92 PhilipLa Created.
  174. //
  175. //--------------------------------------------------------------------------
  176. inline ILockBytes * CDeltaList::GetControlILB(void)
  177. {
  178. return _pmsScratch->GetILB();
  179. }
  180. //+-------------------------------------------------------------------------
  181. //
  182. // Method: CDeltaList::GetDataFat, public
  183. //
  184. // Synopsis: Return pointer to fat to use for storing stream data
  185. //
  186. // History: 10-Jul-92 PhilipLa Created.
  187. //
  188. //--------------------------------------------------------------------------
  189. inline CFat * CDeltaList::GetDataFat(void)
  190. {
  191. if (_pms)
  192. return _pmsScratch->GetMiniFat();
  193. else
  194. return _pmsScratch->GetFat();
  195. }
  196. //+-------------------------------------------------------------------------
  197. //
  198. // Method: CDeltaList::GetControlFat, public
  199. //
  200. // Synopsis: Return pointer to fat to use for storing control information
  201. //
  202. // History: 10-Jul-92 PhilipLa Created.
  203. //
  204. //--------------------------------------------------------------------------
  205. inline CFat * CDeltaList::GetControlFat(void)
  206. {
  207. return _pmsScratch->GetFat();
  208. }
  209. //+-------------------------------------------------------------------------
  210. //
  211. // Method: CDeltaList::GetDataSectorSize, public
  212. //
  213. // Synopsis: Return sector size for storing stream data
  214. //
  215. // History: 10-Jul-92 PhilipLa Created.
  216. //
  217. //--------------------------------------------------------------------------
  218. inline USHORT CDeltaList::GetDataSectorSize(void)
  219. {
  220. if (_pms)
  221. return _pms->GetSectorSize();
  222. else
  223. return _pmsScratch->GetSectorSize();
  224. }
  225. //+-------------------------------------------------------------------------
  226. //
  227. // Method: CDeltaList::GetDataSectorShift, public
  228. //
  229. // Synopsis: Return sector size for storing stream data
  230. //
  231. // History: 10-Jul-92 PhilipLa Created.
  232. //
  233. //--------------------------------------------------------------------------
  234. inline USHORT CDeltaList::GetDataSectorShift(void)
  235. {
  236. if (_pms)
  237. return _pms->GetSectorShift();
  238. else
  239. return _pmsScratch->GetSectorShift();
  240. }
  241. //+-------------------------------------------------------------------------
  242. //
  243. // Method: CDeltaList::GetControlSectorSize, public
  244. //
  245. // Synopsis: Return sector size for storing control information
  246. //
  247. // History: 10-Jul-92 PhilipLa Created.
  248. //
  249. //--------------------------------------------------------------------------
  250. inline USHORT CDeltaList::GetControlSectorSize(void)
  251. {
  252. return _pmsScratch->GetSectorSize();
  253. }
  254. //+---------------------------------------------------------------------------
  255. //
  256. // Member: CDeltaList::IsNoScratch, public
  257. //
  258. // Synopsis: Return TRUE if the delta list is in no-scratch mode
  259. //
  260. // Arguments: None.
  261. //
  262. // History: 19-Nov-92 PhilipLa Created
  263. //
  264. //----------------------------------------------------------------------------
  265. inline BOOL CDeltaList::IsNoScratch(void)
  266. {
  267. return (_pms != NULL);
  268. }
  269. //+---------------------------------------------------------------------------
  270. //
  271. // Member: CDeltaList::IsEmpty, public
  272. //
  273. // Synopsis: Return TRUE if the delta list contains no changes.
  274. //
  275. // Arguments: None.
  276. //
  277. // History: 19-Nov-92 PhilipLa Created
  278. //
  279. //----------------------------------------------------------------------------
  280. inline BOOL CDeltaList::IsEmpty(void)
  281. {
  282. return ((_apdb == NULL) && (_sectStart == ENDOFCHAIN));
  283. }
  284. //+---------------------------------------------------------------------------
  285. //
  286. // Member: CDeltaList::IsInMemory, public
  287. //
  288. // Synopsis: Return TRUE if the delta list is in memory
  289. //
  290. // Arguments: None.
  291. //
  292. // History: 19-Nov-92 PhilipLa Created
  293. //
  294. //----------------------------------------------------------------------------
  295. inline BOOL CDeltaList::IsInMemory(void)
  296. {
  297. return (_apdb != NULL);
  298. }
  299. //+---------------------------------------------------------------------------
  300. //
  301. // Member: CDeltaList::IsInStream, public
  302. //
  303. // Synopsis: Return TRUE if the delta list is in a stream
  304. //
  305. // Arguments: None.
  306. //
  307. // History: 19-Nov-92 PhilipLa Created
  308. //
  309. //----------------------------------------------------------------------------
  310. inline BOOL CDeltaList::IsInStream(void)
  311. {
  312. return ((_apdb == NULL) && (_sectStart != ENDOFCHAIN));
  313. }
  314. #endif //__DL_HXX__