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.

213 lines
5.1 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 ULONG ConvertSectOffset(SECT sect, OFFSET off,
  38. USHORT uShift)
  39. {
  40. ULONG ulTemp = ((ULONG)sect << uShift) + HEADERSIZE +
  41. (ULONG)off;
  42. msfDebugOut((DEB_ITRACE,"Convert got %lu\n",ulTemp));
  43. return ulTemp;
  44. }
  45. //+-------------------------------------------------------------------------
  46. //
  47. // Method: CMStream::GetStart, private
  48. //
  49. // Synopsis: Given an SID, return the starting sector
  50. //
  51. // Arguments: [sid] -- Sid to find start for
  52. //
  53. // Returns: Starting sector for given SID.
  54. //
  55. // Notes: This function only works for controls structures,
  56. // not for ordinary streams.
  57. //
  58. //--------------------------------------------------------------------------
  59. inline SECT CMStream::GetStart(SID sid) const
  60. {
  61. SECT sectRet;
  62. msfAssert(sid > MAXREGSID);
  63. if (SIDFAT == sid)
  64. {
  65. sectRet = _hdr.GetFatStart();
  66. }
  67. else if (SIDDIR == sid)
  68. {
  69. sectRet = _hdr.GetDirStart();
  70. }
  71. else if (SIDDIF == sid)
  72. {
  73. sectRet = _hdr.GetDifStart();
  74. }
  75. else
  76. {
  77. msfAssert(SIDMINIFAT == sid);
  78. sectRet = _hdr.GetMiniFatStart();
  79. }
  80. return sectRet;
  81. }
  82. //+---------------------------------------------------------------------------
  83. //
  84. // Member: CMStream::GetSect, private
  85. //
  86. // Synopsis: For a given SID and sect, return the location of that
  87. // sector in the multistream.
  88. //
  89. // Arguments: [sid] -- SID of sector to locate
  90. // [sect] -- Offset into chain to locate
  91. // [psect] -- Pointer to return location.
  92. //
  93. // Returns: Appropriate status code
  94. //
  95. // Modifies:
  96. //
  97. // Notes:
  98. //
  99. //----------------------------------------------------------------------------
  100. inline SCODE CMStream::GetSect(SID sid, SECT sect, SECT *psect)
  101. {
  102. SCODE sc;
  103. SECT start;
  104. if (sid == SIDFAT)
  105. {
  106. msfChk(_fatDif.GetFatSect(sect, &start));
  107. }
  108. else if (sid == SIDDIF)
  109. {
  110. msfChk(_fatDif.GetSect(sect, &start));
  111. }
  112. else
  113. {
  114. start = GetStart(sid);
  115. msfChk(_fat.GetSect(start, sect, &start));
  116. }
  117. *psect = start;
  118. Err:
  119. return sc;
  120. }
  121. //+-------------------------------------------------------------------------
  122. //
  123. // Member: CMStream::SetSize, public
  124. //
  125. // Synposis: Sets the size of the parent LStream to match
  126. // current Fat information.
  127. //
  128. // Arguments: None.
  129. //
  130. // Returns: Error code from call to parent LStream SetSize()
  131. //
  132. // Algorithm: Query the Fat for the last sector used.
  133. // Convert that sector into a byte offset.
  134. // Call SetSize on the parent LStream.
  135. //
  136. //---------------------------------------------------------------------------
  137. inline SCODE CMStream::SetSize(VOID)
  138. {
  139. SCODE sc = S_OK;
  140. ULONG ulSize;
  141. ULARGE_INTEGER cbSize;
  142. msfDebugOut((DEB_TRACE,"In CMStream::SetSize()\n"));
  143. SECT sectMax;
  144. msfChk(_fat.GetMaxSect(&sectMax));
  145. ulSize = ConvertSectOffset(sectMax, 0, GetSectorShift());
  146. ULISet32(cbSize, ulSize);
  147. msfHChk((*_pplstParent)->SetSize(cbSize));
  148. msfDebugOut((DEB_ITRACE,"Exiting CMStream::SetSize()\n"));
  149. Err:
  150. return sc;
  151. }
  152. //+-------------------------------------------------------------------------
  153. //
  154. // Member: CMStream::SetMiniSize, public
  155. //
  156. // Synposis: Sets the size of the MiniFat storage stream to match
  157. // current Fat information.
  158. //
  159. // Arguments: None.
  160. //
  161. // Returns: Error code from call to stream SetSize()
  162. //
  163. // Algorithm: Query the Fat for the last sector used.
  164. // Convert that sector into a byte offset.
  165. // Call SetSize on the Minifat storage stream.
  166. //
  167. //---------------------------------------------------------------------------
  168. inline SCODE CMStream::SetMiniSize(VOID)
  169. {
  170. SCODE sc;
  171. ULONG ulNewSize;
  172. SECT sectMax;
  173. msfChk(_fatMini.GetMaxSect(&sectMax));
  174. ulNewSize = sectMax << MINISECTORSHIFT;
  175. msfChk(_pdsministream->CDirectStream::SetSize(ulNewSize));
  176. Err:
  177. return sc;
  178. }
  179. #endif //__MREAD_HXX__