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.

212 lines
5.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: mread.hxx
  7. //
  8. // Contents: Multistream inline functions
  9. //
  10. // Classes: None.
  11. //
  12. // Functions: None
  13. //
  14. //--------------------------------------------------------------------------
  15. #ifndef __MREAD_HXX__
  16. #define __MREAD_HXX__
  17. #include "h/difat.hxx"
  18. #include "h/sstream.hxx"
  19. //+-------------------------------------------------------------------------
  20. //
  21. // Function: ConvertSectAndOffset
  22. //
  23. // Synopsis: Convert a sector and offset into a byte offset in
  24. // a stream.
  25. //
  26. // Arguments: [sect] -- Sector
  27. // [off] -- Offset
  28. // [uShift] -- Shift count for sectorsize
  29. //
  30. // Returns: Byte offset into stream.
  31. //
  32. // Algorithm: The byte offset is sect left-shifted uShift times,
  33. // plus the offset, plus SECTORSIZE bytes for the
  34. // header.
  35. //
  36. //--------------------------------------------------------------------------
  37. inline ULONGLONG ConvertSectOffset(SECT sect, OFFSET off,
  38. USHORT uShift)
  39. {
  40. ULONGLONG ulTemp = ((ULONGLONG)(sect+1) << uShift) + off;
  41. msfDebugOut((DEB_ITRACE,"Convert got %lu\n",ulTemp));
  42. return ulTemp;
  43. }
  44. //+-------------------------------------------------------------------------
  45. //
  46. // Method: CMStream::GetStart, private
  47. //
  48. // Synopsis: Given an SID, return the starting sector
  49. //
  50. // Arguments: [sid] -- Sid to find start for
  51. //
  52. // Returns: Starting sector for given SID.
  53. //
  54. // Notes: This function only works for controls structures,
  55. // not for ordinary streams.
  56. //
  57. //--------------------------------------------------------------------------
  58. inline SECT CMStream::GetStart(SID sid) const
  59. {
  60. SECT sectRet;
  61. msfAssert(sid > MAXREGSID);
  62. if (SIDFAT == sid)
  63. {
  64. sectRet = _hdr.GetFatStart();
  65. }
  66. else if (SIDDIR == sid)
  67. {
  68. sectRet = _hdr.GetDirStart();
  69. }
  70. else if (SIDDIF == sid)
  71. {
  72. sectRet = _hdr.GetDifStart();
  73. }
  74. else
  75. {
  76. msfAssert(SIDMINIFAT == sid);
  77. sectRet = _hdr.GetMiniFatStart();
  78. }
  79. return sectRet;
  80. }
  81. //+---------------------------------------------------------------------------
  82. //
  83. // Member: CMStream::GetSect, private
  84. //
  85. // Synopsis: For a given SID and sect, return the location of that
  86. // sector in the multistream.
  87. //
  88. // Arguments: [sid] -- SID of sector to locate
  89. // [sect] -- Offset into chain to locate
  90. // [psect] -- Pointer to return location.
  91. //
  92. // Returns: Appropriate status code
  93. //
  94. // Modifies:
  95. //
  96. // Notes:
  97. //
  98. //----------------------------------------------------------------------------
  99. inline SCODE CMStream::GetSect(SID sid, SECT sect, SECT *psect)
  100. {
  101. SCODE sc;
  102. SECT start;
  103. if (sid == SIDFAT)
  104. {
  105. msfChk(_fatDif.GetFatSect(sect, &start));
  106. }
  107. else if (sid == SIDDIF)
  108. {
  109. msfChk(_fatDif.GetSect(sect, &start));
  110. }
  111. else
  112. {
  113. start = GetStart(sid);
  114. msfChk(_fat.GetSect(start, sect, &start));
  115. }
  116. *psect = start;
  117. Err:
  118. return sc;
  119. }
  120. //+-------------------------------------------------------------------------
  121. //
  122. // Member: CMStream::SetSize, public
  123. //
  124. // Synposis: Sets the size of the parent LStream to match
  125. // current Fat information.
  126. //
  127. // Arguments: None.
  128. //
  129. // Returns: Error code from call to parent LStream SetSize()
  130. //
  131. // Algorithm: Query the Fat for the last sector used.
  132. // Convert that sector into a byte offset.
  133. // Call SetSize on the parent LStream.
  134. //
  135. //---------------------------------------------------------------------------
  136. inline SCODE CMStream::SetSize(VOID)
  137. {
  138. SCODE sc = S_OK;
  139. ULONGLONG ulSize;
  140. ULARGE_INTEGER cbSize;
  141. msfDebugOut((DEB_TRACE,"In CMStream::SetSize()\n"));
  142. SECT sectMax;
  143. msfChk(_fat.GetMaxSect(&sectMax));
  144. ulSize = ConvertSectOffset(sectMax, 0, GetSectorShift());
  145. cbSize.QuadPart = ulSize;
  146. msfHChk((*_pplstParent)->SetSize(cbSize));
  147. msfDebugOut((DEB_ITRACE,"Exiting CMStream::SetSize()\n"));
  148. Err:
  149. return sc;
  150. }
  151. //+-------------------------------------------------------------------------
  152. //
  153. // Member: CMStream::SetMiniSize, public
  154. //
  155. // Synposis: Sets the size of the MiniFat storage stream to match
  156. // current Fat information.
  157. //
  158. // Arguments: None.
  159. //
  160. // Returns: Error code from call to stream SetSize()
  161. //
  162. // Algorithm: Query the Fat for the last sector used.
  163. // Convert that sector into a byte offset.
  164. // Call SetSize on the Minifat storage stream.
  165. //
  166. //---------------------------------------------------------------------------
  167. inline SCODE CMStream::SetMiniSize(VOID)
  168. {
  169. SCODE sc;
  170. ULONG ulNewSize;
  171. SECT sectMax;
  172. msfChk(_fatMini.GetMaxSect(&sectMax));
  173. ulNewSize = sectMax << MINISECTORSHIFT;
  174. msfChk(_pdsministream->CDirectStream::SetSize(ulNewSize));
  175. Err:
  176. return sc;
  177. }
  178. #endif //__MREAD_HXX__