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.

355 lines
8.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1992.
  5. //
  6. // File: header.hxx
  7. //
  8. // Contents: MSF header class
  9. //
  10. // Classes: CMSFHeader
  11. //
  12. // History: 11-Dec-91 PhilipLa Created.
  13. // 24-Apr-92 AlexT Added data and acccess routines
  14. // for minifat, ministream.
  15. //
  16. //--------------------------------------------------------------------------
  17. #ifndef __HEADER_HXX__
  18. #define __HEADER_HXX__
  19. #include <storagep.h>
  20. #define HDR_NOFORCE 0x0000
  21. #define HDR_FORCE 0x0001
  22. #define HDR_ALL 0x0002
  23. struct SPreHeader : public SStorageFile
  24. {
  25. public:
  26. USHORT _uMinorVersion;
  27. USHORT _uDllVersion;
  28. USHORT _uByteOrder;
  29. USHORT _uSectorShift;
  30. USHORT _uMiniSectorShift;
  31. USHORT _usReserved;
  32. ULONG _ulReserved1;
  33. FSINDEX _csectDir; // valid only for >512b sectors
  34. FSINDEX _csectFat;
  35. SECT _sectDirStart;
  36. DFSIGNATURE _signature;
  37. ULONG _ulMiniSectorCutoff;
  38. SECT _sectMiniFatStart;
  39. FSINDEX _csectMiniFat;
  40. SECT _sectDifStart;
  41. FSINDEX _csectDif;
  42. };
  43. const USHORT CSECTFATREAL = (HEADERSIZE - sizeof(SPreHeader)) / sizeof(SECT);
  44. const USHORT CSECTFAT = CSECTFATREAL;
  45. class CMSFHeaderData: public SPreHeader
  46. {
  47. public:
  48. CMSFHeaderData(USHORT uSectorShift);
  49. SECT _sectFat[CSECTFAT];
  50. };
  51. class CMSFHeader
  52. {
  53. public:
  54. CMSFHeader(USHORT uSectorShift);
  55. SCODE Validate(VOID) const;
  56. inline USHORT GetMinorVersion(VOID) const;
  57. inline USHORT GetDllVersion(VOID) const;
  58. inline SCODE SetDirLength(const FSINDEX cDirSect);
  59. inline FSINDEX GetDirLength(VOID) const;
  60. inline SCODE SetFatLength(const FSINDEX cFatSect);
  61. inline FSINDEX GetFatLength(VOID) const;
  62. inline SCODE SetMiniFatLength(const FSINDEX cFatSect);
  63. inline FSINDEX GetMiniFatLength(VOID) const;
  64. inline SCODE SetDirStart(const SECT sect);
  65. inline SECT GetDirStart(VOID) const;
  66. inline SCODE SetFatStart(const SECT sect);
  67. inline SECT GetFatStart(VOID) const;
  68. inline SCODE SetMiniFatStart(const SECT sect);
  69. inline SECT GetMiniFatStart(VOID) const;
  70. inline SCODE SetDifStart(const SECT sect);
  71. inline SECT GetDifStart(VOID) const;
  72. inline SCODE SetDifLength(const FSINDEX cFatSect);
  73. inline FSINDEX GetDifLength(VOID) const;
  74. inline SECT GetFatSect(const FSINDEX oSect) const;
  75. inline SCODE SetFatSect(const FSINDEX oSect, const SECT sect);
  76. inline USHORT GetSectorShift(VOID) const;
  77. inline USHORT GetMiniSectorShift(VOID) const;
  78. inline ULONG GetMiniSectorCutoff(VOID) const;
  79. inline DFSIGNATURE GetCommitSig(VOID) const;
  80. inline void SetCommitSig(const DFSIGNATURE sig);
  81. inline BOOL IsDirty(void) const;
  82. inline CMSFHeaderData * GetData(void);
  83. inline void SetDirty(void);
  84. inline void ResetDirty(void);
  85. private:
  86. CMSFHeaderData _hdr;
  87. BOOL _fDirty;
  88. SCODE SetSig(const BYTE *pbSig);
  89. };
  90. inline SCODE CMSFHeader::SetDirLength(const FSINDEX cDirSect)
  91. {
  92. if (_hdr._uSectorShift > SECTORSHIFT512)
  93. {
  94. _hdr._csectDir = cDirSect;
  95. _fDirty = TRUE;
  96. }
  97. return S_OK;
  98. }
  99. inline FSINDEX CMSFHeader::GetDirLength(VOID) const
  100. {
  101. return _hdr._csectDir;
  102. }
  103. inline SCODE CMSFHeader::SetFatLength(const FSINDEX cFatSect)
  104. {
  105. msfDebugOut((DEB_ITRACE, "In CMSFHeader::SetFatLength(%lu)\n",cFatSect));
  106. _hdr._csectFat = cFatSect;
  107. _fDirty = TRUE;
  108. msfDebugOut((DEB_ITRACE, "Out CMSFHeader::SetFatLength()\n"));
  109. return S_OK;
  110. }
  111. inline FSINDEX CMSFHeader::GetFatLength(VOID) const
  112. {
  113. return _hdr._csectFat;
  114. }
  115. inline SCODE CMSFHeader::SetMiniFatLength(const FSINDEX cFatSect)
  116. {
  117. msfDebugOut((DEB_ITRACE, "In CMSFHeader::SetMiniFatLength(%lu)\n",
  118. cFatSect));
  119. _hdr._csectMiniFat = cFatSect;
  120. _fDirty = TRUE;
  121. msfDebugOut((DEB_ITRACE, "Out CMSFHeader::SetMiniFatLength()\n"));
  122. return S_OK;
  123. }
  124. inline FSINDEX CMSFHeader::GetMiniFatLength(VOID) const
  125. {
  126. return _hdr._csectMiniFat;
  127. }
  128. inline SCODE CMSFHeader::SetDirStart(const SECT sectNew)
  129. {
  130. _hdr._sectDirStart = sectNew;
  131. _fDirty = TRUE;
  132. return S_OK;
  133. }
  134. inline SECT CMSFHeader::GetDirStart(VOID) const
  135. {
  136. return _hdr._sectDirStart;
  137. }
  138. inline SCODE CMSFHeader::SetFatStart(const SECT sectNew)
  139. {
  140. _hdr._sectFat[0] = sectNew;
  141. _fDirty = TRUE;
  142. return S_OK;
  143. }
  144. inline SECT CMSFHeader::GetFatStart(VOID) const
  145. {
  146. return _hdr._sectFat[0];
  147. }
  148. //+-------------------------------------------------------------------------
  149. //
  150. // Member: CMSFHeader::SetMiniFatStart
  151. //
  152. // Synopsis: Sets minifat's first sector's index
  153. //
  154. // Arguments: [sectNew] -- sector index
  155. //
  156. // Returns: S_OK (necessary?)
  157. //
  158. // Modifies: _sectMiniFatStart
  159. //
  160. // History: 12-May-92 AlexT Added minifat support
  161. //
  162. //--------------------------------------------------------------------------
  163. inline SCODE CMSFHeader::SetMiniFatStart(const SECT sectNew)
  164. {
  165. _hdr._sectMiniFatStart = sectNew;
  166. _fDirty = TRUE;
  167. return S_OK;
  168. }
  169. //+-------------------------------------------------------------------------
  170. //
  171. // Member: CMSFHeader::GetMiniFatStart
  172. //
  173. // Synopsis: Gets minifat's first sector's index
  174. //
  175. // Returns: minifat's first sector's index
  176. //
  177. // History: 12-May-92 AlexT Added minifat support
  178. //
  179. //--------------------------------------------------------------------------
  180. inline SECT CMSFHeader::GetMiniFatStart(VOID) const
  181. {
  182. return _hdr._sectMiniFatStart;
  183. }
  184. inline SCODE CMSFHeader::SetDifStart(const SECT sectNew)
  185. {
  186. _hdr._sectDifStart = sectNew;
  187. _fDirty = TRUE;
  188. return S_OK;
  189. }
  190. inline SECT CMSFHeader::GetDifStart(VOID) const
  191. {
  192. return _hdr._sectDifStart;
  193. }
  194. inline SECT CMSFHeader::GetFatSect(const FSINDEX oSect) const
  195. {
  196. msfAssert(oSect < CSECTFAT);
  197. return _hdr._sectFat[oSect];
  198. }
  199. inline SCODE CMSFHeader::SetFatSect(const FSINDEX oSect, const SECT sect)
  200. {
  201. msfAssert(oSect < CSECTFAT);
  202. _hdr._sectFat[oSect] = sect;
  203. _fDirty = TRUE;
  204. return S_OK;
  205. }
  206. inline SCODE CMSFHeader::SetDifLength(const FSINDEX cFatSect)
  207. {
  208. _hdr._csectDif = cFatSect;
  209. _fDirty = TRUE;
  210. return S_OK;
  211. }
  212. inline FSINDEX CMSFHeader::GetDifLength(VOID) const
  213. {
  214. return _hdr._csectDif;
  215. }
  216. inline USHORT CMSFHeader::GetSectorShift(VOID) const
  217. {
  218. return _hdr._uSectorShift;
  219. }
  220. inline DFSIGNATURE CMSFHeader::GetCommitSig(VOID) const
  221. {
  222. return _hdr._signature;
  223. }
  224. inline void CMSFHeader::SetCommitSig(const DFSIGNATURE sig)
  225. {
  226. _hdr._signature = sig;
  227. _fDirty = TRUE;
  228. }
  229. inline USHORT CMSFHeader::GetMiniSectorShift(VOID) const
  230. {
  231. return _hdr._uMiniSectorShift;
  232. }
  233. inline ULONG CMSFHeader::GetMiniSectorCutoff(VOID) const
  234. {
  235. return _hdr._ulMiniSectorCutoff;
  236. }
  237. inline USHORT CMSFHeader::GetMinorVersion(VOID) const
  238. {
  239. return _hdr._uMinorVersion;
  240. }
  241. inline USHORT CMSFHeader::GetDllVersion(VOID) const
  242. {
  243. return _hdr._uDllVersion;
  244. }
  245. inline BOOL CMSFHeader::IsDirty(void) const
  246. {
  247. return _fDirty;
  248. }
  249. inline CMSFHeaderData * CMSFHeader::GetData(void)
  250. {
  251. return &_hdr;
  252. }
  253. inline void CMSFHeader::SetDirty(void)
  254. {
  255. _fDirty = TRUE;
  256. }
  257. inline void CMSFHeader::ResetDirty(void)
  258. {
  259. _fDirty = FALSE;
  260. }
  261. const ULONG OACCESS = 0x7FFFFF80;
  262. const ULONG OREADLOCK = OACCESS + 1; // 0x7FFFFF81
  263. const ULONG CREADLOCKS = 16;
  264. const ULONG OUPDATE = OREADLOCK + CREADLOCKS + 1; // 0x7FFFFF92
  265. const ULONG OOPENLOCK = OUPDATE + 1;
  266. const ULONG COPENLOCKS = 20;
  267. const ULONG OOPENREADLOCK = OOPENLOCK; // 0x7FFFFF93
  268. const ULONG OOPENWRITELOCK = OOPENLOCK + COPENLOCKS; // 0x7FFFFFA7
  269. const ULONG OOPENDENYREADLOCK = OOPENWRITELOCK + COPENLOCKS; // 0x7FFFFFBB
  270. const ULONG OOPENDENYWRITELOCK = OOPENDENYREADLOCK + COPENLOCKS; // 0x7FFFFFCF
  271. const ULONG OLOCKREGIONEND = OOPENDENYWRITELOCK + COPENLOCKS;
  272. #ifdef USE_NOSNAPSHOT
  273. const ULONG OOPENNOSNAPSHOTLOCK = OACCESS - COPENLOCKS;
  274. #endif
  275. #ifdef DIRECTWRITERLOCK
  276. const ULONG ODIRECTWRITERLOCK = OOPENNOSNAPSHOTLOCK - COPENLOCKS;
  277. #endif
  278. const ULONG OLOCKREGIONBEGIN = 0x7FFFFF00;
  279. const ULONG OLOCKREGIONEND_SECTORALIGNED = 0x80000000;
  280. #endif //__HEADER_HXX__