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.

239 lines
5.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: vectfunc.hxx
  7. //
  8. // Contents: CPagedVector inline functions
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. //----------------------------------------------------------------------------
  15. #ifndef __VECTFUNC_HXX__
  16. #define __VECTFUNC_HXX__
  17. #define STG_S_FOUND MAKE_SCODE(SEVERITY_SUCCESS, FACILITY_STORAGE, 0x400)
  18. inline CMSFPage ** GetNewPageArray(ULONG ulSize)
  19. {
  20. msfAssert(ulSize > 0);
  21. if (ulSize > (_HEAP_MAXREQ / sizeof(CMSFPage *)))
  22. {
  23. return NULL;
  24. }
  25. return new CMSFPage *[(MAXINDEXTYPE)ulSize];
  26. }
  27. //+-------------------------------------------------------------------------
  28. //
  29. // Method: CPagedVector::ReleaseTable, public
  30. //
  31. // Synopsis: Release a table that is no longer needed.
  32. //
  33. // Arguments: [iTable] -- index into vector
  34. //
  35. // Returns: S_OK if call completed OK.
  36. //
  37. // Notes:
  38. //
  39. //--------------------------------------------------------------------------
  40. inline void CPagedVector::ReleaseTable(const FSINDEX iTable)
  41. {
  42. if ((_amp == NULL) || (_amp[iTable] == NULL))
  43. {
  44. _pmpt->ReleasePage(this, _sid, iTable);
  45. }
  46. else
  47. {
  48. _amp[iTable]->Release();
  49. }
  50. }
  51. //+-------------------------------------------------------------------------
  52. //
  53. // Method: CPagedVector::GetBits, public
  54. //
  55. // Synopsis: Return CVectBits for a given table
  56. //
  57. // Arguments: [iTable] -- Index of table to get bits for
  58. //
  59. // Returns: Pointer to CVectBits associated with table
  60. //
  61. //--------------------------------------------------------------------------
  62. inline CVectBits * CPagedVector::GetBits(const ULONG iTable)
  63. {
  64. msfAssert(iTable < _ulSize);
  65. return (_avb == NULL) ? ((CVectBits*)NULL) : &_avb[iTable];
  66. }
  67. //+---------------------------------------------------------------------------
  68. //
  69. // Member: CPagedVector::ResetDirty, public
  70. //
  71. // Synopsis: Reset the dirty bit on the specified page
  72. //
  73. // Arguments: [iTable] -- Table to reset bit on
  74. //
  75. // Notes: This function is always called on a page with an
  76. // open reference. Therefore, the page is
  77. // guaranteed to be in the page table, and that
  78. // FindPage call should never return an error.
  79. //
  80. //----------------------------------------------------------------------------
  81. inline void CPagedVector::ResetDirty(ULONG iTable)
  82. {
  83. SCODE sc;
  84. if (_amp == NULL)
  85. {
  86. CMSFPage *pmp;
  87. msfChk(_pmpt->FindPage(this, _sid, iTable, &pmp));
  88. msfAssert(sc == STG_S_FOUND);
  89. msfAssert(pmp->IsInUse() &&
  90. aMsg("Called ResetDirty on page not in use."));
  91. pmp->ResetDirty();
  92. }
  93. else
  94. {
  95. msfAssert(_amp != NULL);
  96. msfAssert(_amp[iTable] != NULL);
  97. _amp[iTable]->ResetDirty();
  98. }
  99. Err:
  100. return;
  101. }
  102. //+---------------------------------------------------------------------------
  103. //
  104. // Member: CPagedVector::SetSect, public
  105. //
  106. // Synopsis: Set the sector location of a page
  107. //
  108. // Arguments: [iTable] -- Table to set page for
  109. // [sect] -- Sector location of page
  110. //
  111. // Notes: This function is always called on a page with an
  112. // open reference. Therefore, the page is
  113. // guaranteed to be in the page table, and that
  114. // FindPage call should never return an error.
  115. //
  116. //----------------------------------------------------------------------------
  117. inline void CPagedVector::SetSect(const ULONG iTable, const SECT sect)
  118. {
  119. SCODE sc;
  120. if (_amp == NULL)
  121. {
  122. CMSFPage *pmp;
  123. msfChk(_pmpt->FindPage(this, _sid, iTable, &pmp));
  124. msfAssert(sc == STG_S_FOUND);
  125. msfAssert(pmp->IsInUse() &&
  126. aMsg("Called SetSect on page not in use."));
  127. pmp->SetSect(sect);
  128. }
  129. else
  130. {
  131. msfAssert(_amp != NULL);
  132. msfAssert(_amp[iTable] != NULL);
  133. _amp[iTable]->SetSect(sect);
  134. }
  135. Err:
  136. return;
  137. }
  138. //+---------------------------------------------------------------------------
  139. //
  140. // Member: CPagedVector::FreeTable, public
  141. //
  142. // Synopsis: Free a given table (NULL its pointer)
  143. //
  144. // Arguments: [iTable] -- Table to free
  145. //
  146. //----------------------------------------------------------------------------
  147. inline void CPagedVector::FreeTable(ULONG iTable)
  148. {
  149. if ((_amp != NULL) && (_amp[iTable] != NULL))
  150. {
  151. msfAssert(_amp[iTable]->GetVector() == this);
  152. _amp[iTable] = NULL;
  153. }
  154. }
  155. //+---------------------------------------------------------------------------
  156. //
  157. // Member: CPagedVector::SetParent, public
  158. //
  159. // Synopsis: Set the parent of this page table
  160. //
  161. // Arguments: [pms] -- Pointer to new parent
  162. //
  163. //----------------------------------------------------------------------------
  164. inline void CPagedVector::SetParent(CMStream *pms)
  165. {
  166. _pmsParent = pms;
  167. }
  168. //+---------------------------------------------------------------------------
  169. //
  170. // Member: CPagedVector::GetParent, public
  171. //
  172. // Synopsis: Return the parent MS pointer of a vector
  173. //
  174. //----------------------------------------------------------------------------
  175. inline CMStream* CPagedVector::GetParent(void) const
  176. {
  177. return _pmsParent;
  178. }
  179. //+---------------------------------------------------------------------------
  180. //
  181. // Member: CPagedVector::ResetBits, public
  182. //
  183. // Synopsis: Reset all the optimization bits in the vector
  184. //
  185. //----------------------------------------------------------------------------
  186. void CPagedVector::ResetBits(void)
  187. {
  188. if (_avb != NULL)
  189. {
  190. for (ULONG i = 0; i < _ulSize; i++)
  191. {
  192. _avb[i].full = FALSE;
  193. _avb[i].firstfree = 0;
  194. }
  195. }
  196. }
  197. #endif // #ifndef __VECTFUNC_HXX__