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.

333 lines
7.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1996.
  5. //
  6. // File: header.hxx
  7. //
  8. // Contents: MSF header class
  9. //
  10. // Classes: CMSFHeader
  11. //
  12. //--------------------------------------------------------------------------
  13. #ifndef __HEADER_HXX__
  14. #define __HEADER_HXX__
  15. #include "msf.hxx"
  16. #include "storagep.h"
  17. #define HDR_NOFORCE 0x0000
  18. #define HDR_FORCE 0x0001
  19. #define HDR_ALL 0x0002
  20. struct SPreHeader : protected SStorageFile
  21. {
  22. protected:
  23. USHORT _uMinorVersion;
  24. USHORT _uDllVersion;
  25. USHORT _uByteOrder;
  26. USHORT _uSectorShift;
  27. USHORT _uMiniSectorShift;
  28. USHORT _usReserved;
  29. ULONG _ulReserved1;
  30. ULONG _ulReserved2;
  31. FSINDEX _csectFat;
  32. SECT _sectDirStart;
  33. DFSIGNATURE _signature;
  34. ULONG _ulMiniSectorCutoff;
  35. SECT _sectMiniFatStart;
  36. FSINDEX _csectMiniFat;
  37. SECT _sectDifStart;
  38. FSINDEX _csectDif;
  39. };
  40. const USHORT CSECTFATREAL = (HEADERSIZE - sizeof(SPreHeader)) / sizeof(SECT);
  41. const USHORT CSECTFAT = CSECTFATREAL;
  42. class CMSFHeader: private SPreHeader
  43. {
  44. public:
  45. CMSFHeader(USHORT uSectorShift);
  46. SCODE Validate(VOID) const;
  47. inline USHORT GetMinorVersion(VOID) const;
  48. inline USHORT GetDllVersion(VOID) const;
  49. inline SCODE SetFatLength(const FSINDEX cFatSect);
  50. inline FSINDEX GetFatLength(VOID) const;
  51. inline SCODE SetMiniFatLength(const FSINDEX cFatSect);
  52. inline FSINDEX GetMiniFatLength(VOID) const;
  53. inline SCODE SetDirStart(const SECT sect);
  54. inline SECT GetDirStart(VOID) const;
  55. inline SCODE SetFatStart(const SECT sect);
  56. inline SECT GetFatStart(VOID) const;
  57. inline SCODE SetMiniFatStart(const SECT sect);
  58. inline SECT GetMiniFatStart(VOID) const;
  59. inline SCODE SetDifStart(const SECT sect);
  60. inline SECT GetDifStart(VOID) const;
  61. inline SCODE SetDifLength(const FSINDEX cFatSect);
  62. inline FSINDEX GetDifLength(VOID) const;
  63. inline SECT GetFatSect(const FSINDEX oSect) const;
  64. inline SCODE SetFatSect(const FSINDEX oSect, const SECT sect);
  65. inline USHORT GetSectorShift(VOID) const;
  66. inline USHORT GetMiniSectorShift(VOID) const;
  67. inline ULONG GetMiniSectorCutoff(VOID) const;
  68. inline DFSIGNATURE GetCommitSig(VOID) const;
  69. inline void SetCommitSig(const DFSIGNATURE sig);
  70. // whether machine is using diff order from file format
  71. inline BOOL DiffByteOrder(VOID) const;
  72. inline void ByteSwap(VOID);
  73. private:
  74. SECT _sectFat[CSECTFAT];
  75. SCODE SetSig(const BYTE *pbSig);
  76. };
  77. inline SCODE CMSFHeader::SetFatLength(const FSINDEX cFatSect)
  78. {
  79. msfDebugOut((DEB_TRACE,"In CMSFHeader::SetFatLength(%lu)\n",cFatSect));
  80. _csectFat = cFatSect;
  81. msfDebugOut((DEB_TRACE,"Out CMSFHeader::SetFatLength()\n"));
  82. return S_OK;
  83. }
  84. inline FSINDEX CMSFHeader::GetFatLength(VOID) const
  85. {
  86. return _csectFat;
  87. }
  88. inline SCODE CMSFHeader::SetMiniFatLength(const FSINDEX cFatSect)
  89. {
  90. msfDebugOut((DEB_TRACE,"In CMSFHeader::SetMiniFatLength(%lu)\n",cFatSect));
  91. _csectMiniFat = cFatSect;
  92. msfDebugOut((DEB_TRACE,"Out CMSFHeader::SetMiniFatLength()\n"));
  93. return S_OK;
  94. }
  95. inline FSINDEX CMSFHeader::GetMiniFatLength(VOID) const
  96. {
  97. return(_csectMiniFat);
  98. }
  99. inline SCODE CMSFHeader::SetDirStart(const SECT sectNew)
  100. {
  101. _sectDirStart = sectNew;
  102. return S_OK;
  103. }
  104. inline SECT CMSFHeader::GetDirStart(VOID) const
  105. {
  106. return _sectDirStart;
  107. }
  108. inline SCODE CMSFHeader::SetFatStart(const SECT sectNew)
  109. {
  110. _sectFat[0] = sectNew;
  111. return S_OK;
  112. }
  113. inline SECT CMSFHeader::GetFatStart(VOID) const
  114. {
  115. return _sectFat[0];
  116. }
  117. //+-------------------------------------------------------------------------
  118. //
  119. // Member: CMSFHeader::SetMiniFatStart
  120. //
  121. // Synopsis: Sets minifat's first sector's index
  122. //
  123. // Arguments: [sectNew] -- sector index
  124. //
  125. // Returns: S_OK (necessary?)
  126. //
  127. // Modifies: _sectMiniFatStart
  128. //
  129. //--------------------------------------------------------------------------
  130. inline SCODE CMSFHeader::SetMiniFatStart(const SECT sectNew)
  131. {
  132. _sectMiniFatStart = sectNew;
  133. return S_OK;
  134. }
  135. //+-------------------------------------------------------------------------
  136. //
  137. // Member: CMSFHeader::GetMiniFatStart
  138. //
  139. // Synopsis: Gets minifat's first sector's index
  140. //
  141. // Returns: minifat's first sector's index
  142. //
  143. //--------------------------------------------------------------------------
  144. inline SECT CMSFHeader::GetMiniFatStart(VOID) const
  145. {
  146. return(_sectMiniFatStart);
  147. }
  148. inline SCODE CMSFHeader::SetDifStart(const SECT sectNew)
  149. {
  150. _sectDifStart = sectNew;
  151. return S_OK;
  152. }
  153. inline SECT CMSFHeader::GetDifStart(VOID) const
  154. {
  155. return _sectDifStart;
  156. }
  157. inline SECT CMSFHeader::GetFatSect(const FSINDEX oSect) const
  158. {
  159. msfAssert(oSect < CSECTFAT);
  160. return _sectFat[oSect];
  161. }
  162. inline SCODE CMSFHeader::SetFatSect(const FSINDEX oSect, const SECT sect)
  163. {
  164. msfAssert(oSect < CSECTFAT);
  165. _sectFat[oSect] = sect;
  166. return S_OK;
  167. }
  168. inline SCODE CMSFHeader::SetDifLength(const FSINDEX cFatSect)
  169. {
  170. _csectDif = cFatSect;
  171. return S_OK;
  172. }
  173. inline FSINDEX CMSFHeader::GetDifLength(VOID) const
  174. {
  175. return _csectDif;
  176. }
  177. inline USHORT CMSFHeader::GetSectorShift(VOID) const
  178. {
  179. return _uSectorShift;
  180. }
  181. inline DFSIGNATURE CMSFHeader::GetCommitSig(VOID) const
  182. {
  183. return _signature;
  184. }
  185. inline void CMSFHeader::SetCommitSig(const DFSIGNATURE sig)
  186. {
  187. _signature = sig;
  188. }
  189. inline USHORT CMSFHeader::GetMiniSectorShift(VOID) const
  190. {
  191. return _uMiniSectorShift;
  192. }
  193. inline ULONG CMSFHeader::GetMiniSectorCutoff(VOID) const
  194. {
  195. return _ulMiniSectorCutoff;
  196. }
  197. inline USHORT CMSFHeader::GetMinorVersion(VOID) const
  198. {
  199. return _uMinorVersion;
  200. }
  201. inline USHORT CMSFHeader::GetDllVersion(VOID) const
  202. {
  203. return _uDllVersion;
  204. }
  205. // we always store Litte Endian on disk
  206. #define DISK_BYTE_ORDER 0xFFFE
  207. // whether machine is using diff order than file format
  208. inline BOOL CMSFHeader::DiffByteOrder(VOID) const
  209. {
  210. // _uByteOrder stores what the machine will see
  211. // when it reads in a Little Endian 0xFFFE on disk
  212. #ifndef _GENERATE_REVERSE_
  213. return _uByteOrder != DISK_BYTE_ORDER;
  214. #else
  215. return _uByteOrder == DISK_BYTE_ORDER;
  216. #endif
  217. }
  218. inline void CMSFHeader::ByteSwap(VOID)
  219. {
  220. if (DiffByteOrder())
  221. {
  222. ::ByteSwap(& _uMinorVersion);
  223. ::ByteSwap(& _uDllVersion);
  224. // note: _uByteOrder should not be swapped so that we know
  225. // which Endian the machine is operating in.
  226. ::ByteSwap(& _uSectorShift);
  227. ::ByteSwap(& _uMiniSectorShift);
  228. ::ByteSwap(& _usReserved);
  229. ::ByteSwap(& _ulReserved1);
  230. ::ByteSwap(& _ulReserved2);
  231. ::ByteSwap(& _csectFat);
  232. ::ByteSwap(& _sectDirStart);
  233. ::ByteSwap(& _signature);
  234. ::ByteSwap(& _ulMiniSectorCutoff);
  235. ::ByteSwap(& _sectMiniFatStart);
  236. ::ByteSwap(& _csectMiniFat);
  237. ::ByteSwap(& _sectDifStart);
  238. ::ByteSwap(& _csectDif);
  239. // swapping the Fat table
  240. for (int cnt=0; cnt < CSECTFAT; cnt++)
  241. ::ByteSwap( &(_sectFat[cnt]) );
  242. }
  243. }
  244. const ULONG OACCESS = 0xFFFFFF00;
  245. const ULONG OREADLOCK = OACCESS + 1;
  246. const ULONG CREADLOCKS = 16;
  247. const ULONG OUPDATE = OREADLOCK + CREADLOCKS + 1;
  248. const ULONG OOPENLOCK = OUPDATE + 1;
  249. const ULONG COPENLOCKS = 20;
  250. const ULONG OOPENREADLOCK = OOPENLOCK;
  251. const ULONG OOPENWRITELOCK = OOPENLOCK + COPENLOCKS;
  252. const ULONG OOPENDENYREADLOCK = OOPENWRITELOCK + COPENLOCKS;
  253. const ULONG OOPENDENYWRITELOCK = OOPENDENYREADLOCK + COPENLOCKS;
  254. #endif //__HEADER_HXX__