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.

350 lines
8.1 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. FSINDEX _csectDir; // valid only for >512b sectors
  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 SetDirLength(const FSINDEX cDirSect);
  50. inline FSINDEX GetDirLength(VOID) const;
  51. inline SCODE SetFatLength(const FSINDEX cFatSect);
  52. inline FSINDEX GetFatLength(VOID) const;
  53. inline SCODE SetMiniFatLength(const FSINDEX cFatSect);
  54. inline FSINDEX GetMiniFatLength(VOID) const;
  55. inline SCODE SetDirStart(const SECT sect);
  56. inline SECT GetDirStart(VOID) const;
  57. inline SCODE SetFatStart(const SECT sect);
  58. inline SECT GetFatStart(VOID) const;
  59. inline SCODE SetMiniFatStart(const SECT sect);
  60. inline SECT GetMiniFatStart(VOID) const;
  61. inline SCODE SetDifStart(const SECT sect);
  62. inline SECT GetDifStart(VOID) const;
  63. inline SCODE SetDifLength(const FSINDEX cFatSect);
  64. inline FSINDEX GetDifLength(VOID) const;
  65. inline SECT GetFatSect(const FSINDEX oSect) const;
  66. inline SCODE SetFatSect(const FSINDEX oSect, const SECT sect);
  67. inline USHORT GetSectorShift(VOID) const;
  68. inline USHORT GetMiniSectorShift(VOID) const;
  69. inline ULONG GetMiniSectorCutoff(VOID) const;
  70. inline DFSIGNATURE GetCommitSig(VOID) const;
  71. inline void SetCommitSig(const DFSIGNATURE sig);
  72. // whether machine is using diff order from file format
  73. inline BOOL DiffByteOrder(VOID) const;
  74. inline void ByteSwap(VOID);
  75. private:
  76. SECT _sectFat[CSECTFAT];
  77. SCODE SetSig(const BYTE *pbSig);
  78. };
  79. inline SCODE CMSFHeader::SetDirLength(const FSINDEX cDirSect)
  80. {
  81. if (_uSectorShift > SECTORSHIFT512)
  82. {
  83. _csectDir = cDirSect;
  84. }
  85. return S_OK;
  86. }
  87. inline FSINDEX CMSFHeader::GetDirLength(VOID) const
  88. {
  89. return _csectDir;
  90. }
  91. inline SCODE CMSFHeader::SetFatLength(const FSINDEX cFatSect)
  92. {
  93. msfDebugOut((DEB_TRACE,"In CMSFHeader::SetFatLength(%lu)\n",cFatSect));
  94. _csectFat = cFatSect;
  95. msfDebugOut((DEB_TRACE,"Out CMSFHeader::SetFatLength()\n"));
  96. return S_OK;
  97. }
  98. inline FSINDEX CMSFHeader::GetFatLength(VOID) const
  99. {
  100. return _csectFat;
  101. }
  102. inline SCODE CMSFHeader::SetMiniFatLength(const FSINDEX cFatSect)
  103. {
  104. msfDebugOut((DEB_TRACE,"In CMSFHeader::SetMiniFatLength(%lu)\n",cFatSect));
  105. _csectMiniFat = cFatSect;
  106. msfDebugOut((DEB_TRACE,"Out CMSFHeader::SetMiniFatLength()\n"));
  107. return S_OK;
  108. }
  109. inline FSINDEX CMSFHeader::GetMiniFatLength(VOID) const
  110. {
  111. return(_csectMiniFat);
  112. }
  113. inline SCODE CMSFHeader::SetDirStart(const SECT sectNew)
  114. {
  115. _sectDirStart = sectNew;
  116. return S_OK;
  117. }
  118. inline SECT CMSFHeader::GetDirStart(VOID) const
  119. {
  120. return _sectDirStart;
  121. }
  122. inline SCODE CMSFHeader::SetFatStart(const SECT sectNew)
  123. {
  124. _sectFat[0] = sectNew;
  125. return S_OK;
  126. }
  127. inline SECT CMSFHeader::GetFatStart(VOID) const
  128. {
  129. return _sectFat[0];
  130. }
  131. //+-------------------------------------------------------------------------
  132. //
  133. // Member: CMSFHeader::SetMiniFatStart
  134. //
  135. // Synopsis: Sets minifat's first sector's index
  136. //
  137. // Arguments: [sectNew] -- sector index
  138. //
  139. // Returns: S_OK (necessary?)
  140. //
  141. // Modifies: _sectMiniFatStart
  142. //
  143. //--------------------------------------------------------------------------
  144. inline SCODE CMSFHeader::SetMiniFatStart(const SECT sectNew)
  145. {
  146. _sectMiniFatStart = sectNew;
  147. return S_OK;
  148. }
  149. //+-------------------------------------------------------------------------
  150. //
  151. // Member: CMSFHeader::GetMiniFatStart
  152. //
  153. // Synopsis: Gets minifat's first sector's index
  154. //
  155. // Returns: minifat's first sector's index
  156. //
  157. //--------------------------------------------------------------------------
  158. inline SECT CMSFHeader::GetMiniFatStart(VOID) const
  159. {
  160. return(_sectMiniFatStart);
  161. }
  162. inline SCODE CMSFHeader::SetDifStart(const SECT sectNew)
  163. {
  164. _sectDifStart = sectNew;
  165. return S_OK;
  166. }
  167. inline SECT CMSFHeader::GetDifStart(VOID) const
  168. {
  169. return _sectDifStart;
  170. }
  171. inline SECT CMSFHeader::GetFatSect(const FSINDEX oSect) const
  172. {
  173. msfAssert(oSect < CSECTFAT);
  174. return _sectFat[oSect];
  175. }
  176. inline SCODE CMSFHeader::SetFatSect(const FSINDEX oSect, const SECT sect)
  177. {
  178. msfAssert(oSect < CSECTFAT);
  179. _sectFat[oSect] = sect;
  180. return S_OK;
  181. }
  182. inline SCODE CMSFHeader::SetDifLength(const FSINDEX cFatSect)
  183. {
  184. _csectDif = cFatSect;
  185. return S_OK;
  186. }
  187. inline FSINDEX CMSFHeader::GetDifLength(VOID) const
  188. {
  189. return _csectDif;
  190. }
  191. inline USHORT CMSFHeader::GetSectorShift(VOID) const
  192. {
  193. return _uSectorShift;
  194. }
  195. inline DFSIGNATURE CMSFHeader::GetCommitSig(VOID) const
  196. {
  197. return _signature;
  198. }
  199. inline void CMSFHeader::SetCommitSig(const DFSIGNATURE sig)
  200. {
  201. _signature = sig;
  202. }
  203. inline USHORT CMSFHeader::GetMiniSectorShift(VOID) const
  204. {
  205. return _uMiniSectorShift;
  206. }
  207. inline ULONG CMSFHeader::GetMiniSectorCutoff(VOID) const
  208. {
  209. return _ulMiniSectorCutoff;
  210. }
  211. inline USHORT CMSFHeader::GetMinorVersion(VOID) const
  212. {
  213. return _uMinorVersion;
  214. }
  215. inline USHORT CMSFHeader::GetDllVersion(VOID) const
  216. {
  217. return _uDllVersion;
  218. }
  219. // we always store Litte Endian on disk
  220. #define DISK_BYTE_ORDER 0xFFFE
  221. // whether machine is using diff order than file format
  222. inline BOOL CMSFHeader::DiffByteOrder(VOID) const
  223. {
  224. // _uByteOrder stores what the machine will see
  225. // when it reads in a Little Endian 0xFFFE on disk
  226. #ifndef _GENERATE_REVERSE_
  227. return _uByteOrder != DISK_BYTE_ORDER;
  228. #else
  229. return _uByteOrder == DISK_BYTE_ORDER;
  230. #endif
  231. }
  232. inline void CMSFHeader::ByteSwap(VOID)
  233. {
  234. if (DiffByteOrder())
  235. {
  236. ::ByteSwap(& _uMinorVersion);
  237. ::ByteSwap(& _uDllVersion);
  238. // note: _uByteOrder should not be swapped so that we know
  239. // which Endian the machine is operating in.
  240. ::ByteSwap(& _uSectorShift);
  241. ::ByteSwap(& _uMiniSectorShift);
  242. ::ByteSwap(& _usReserved);
  243. ::ByteSwap(& _ulReserved1);
  244. ::ByteSwap(& _csectDir);
  245. ::ByteSwap(& _csectFat);
  246. ::ByteSwap(& _sectDirStart);
  247. ::ByteSwap(& _signature);
  248. ::ByteSwap(& _ulMiniSectorCutoff);
  249. ::ByteSwap(& _sectMiniFatStart);
  250. ::ByteSwap(& _csectMiniFat);
  251. ::ByteSwap(& _sectDifStart);
  252. ::ByteSwap(& _csectDif);
  253. // swapping the Fat table
  254. for (int cnt=0; cnt < CSECTFAT; cnt++)
  255. ::ByteSwap( &(_sectFat[cnt]) );
  256. }
  257. }
  258. const ULONG OACCESS = 0xFFFFFF00;
  259. const ULONG OREADLOCK = OACCESS + 1;
  260. const ULONG CREADLOCKS = 16;
  261. const ULONG OUPDATE = OREADLOCK + CREADLOCKS + 1;
  262. const ULONG OOPENLOCK = OUPDATE + 1;
  263. const ULONG COPENLOCKS = 20;
  264. const ULONG OOPENREADLOCK = OOPENLOCK;
  265. const ULONG OOPENWRITELOCK = OOPENLOCK + COPENLOCKS;
  266. const ULONG OOPENDENYREADLOCK = OOPENWRITELOCK + COPENLOCKS;
  267. const ULONG OOPENDENYWRITELOCK = OOPENDENYREADLOCK + COPENLOCKS;
  268. const ULONG OLOCKREGIONEND = OOPENDENYWRITELOCK + COPENLOCKS;
  269. #endif //__HEADER_HXX__