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.

294 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. cvfexts.hxx
  5. Abstract:
  6. A class to manage the CVF_FAT_EXTENSIONS (otherwise known as
  7. the MDFAT) part of the doublespace volume.
  8. Author:
  9. Matthew Bradburn (mattbr) 27-Sep-93
  10. --*/
  11. #ifndef CVF_EXTS_DEFN
  12. #define CVF_EXTS_DEFN
  13. //
  14. // secStart : 21 starting sector number, minus 1
  15. // Reserved : 1 unused
  16. // csecCoded : 4 number of compressed sectors required, minus 1
  17. // csecPlain : 4 number of uncompressed sectors required, minus 1
  18. // fUncoded : 1 0: data stored compressed 1: data uncompressed
  19. // fUsed : 1 0: mdfat entry not in use 1: mdfat entry in use
  20. //
  21. #define CFE_START_SHIFT 0
  22. #define CFE_START_MASK 0x001fffff
  23. #define CFE_RESVD_SHIFT 21
  24. #define CFE_RESVD_MASK 0x00200000
  25. #define CFE_CODED_SHIFT 22
  26. #define CFE_CODED_MASK 0x03c00000
  27. #define CFE_PLAIN_SHIFT 26
  28. #define CFE_PLAIN_MASK 0x3c000000
  29. #define CFE_UNCODED_SHIFT 30
  30. #define CFE_UNCODED_MASK 0x40000000
  31. #define CFE_USED_SHIFT 31
  32. #define CFE_USED_MASK 0x80000000
  33. DECLARE_CLASS( CVF_FAT_EXTENS );
  34. class CVF_FAT_EXTENS : public SECRUN {
  35. public:
  36. DECLARE_CONSTRUCTOR(CVF_FAT_EXTENS);
  37. NONVIRTUAL
  38. ~CVF_FAT_EXTENS();
  39. NONVIRTUAL
  40. BOOLEAN
  41. Initialize(
  42. IN OUT PMEM Mem,
  43. IN OUT PLOG_IO_DP_DRIVE Drive,
  44. IN LBN StartSetor,
  45. IN ULONG NumberOfEntries,
  46. IN ULONG FirstEntry
  47. );
  48. NONVIRTUAL
  49. BOOLEAN
  50. Create(
  51. );
  52. NONVIRTUAL
  53. BOOLEAN
  54. IsClusterInUse(
  55. IN ULONG Cluster
  56. ) CONST;
  57. NONVIRTUAL
  58. VOID
  59. SetClusterInUse(
  60. IN ULONG Cluster,
  61. IN BOOLEAN fInUse
  62. );
  63. NONVIRTUAL
  64. ULONG
  65. QuerySectorFromCluster(
  66. IN ULONG Cluster,
  67. OUT PUCHAR NumSectors DEFAULT NULL
  68. );
  69. NONVIRTUAL
  70. VOID
  71. SetSectorForCluster(
  72. IN ULONG Cluster,
  73. IN ULONG Sector,
  74. IN UCHAR SectorCount
  75. );
  76. NONVIRTUAL
  77. BOOLEAN
  78. IsClusterCompressed(
  79. IN ULONG Cluster
  80. ) CONST;
  81. NONVIRTUAL
  82. VOID
  83. SetClusterCompressed(
  84. IN ULONG Cluster,
  85. IN BOOLEAN fCompressed
  86. );
  87. NONVIRTUAL
  88. UCHAR
  89. QuerySectorsRequiredForPlainData(
  90. IN ULONG Cluster
  91. ) CONST;
  92. NONVIRTUAL
  93. VOID
  94. SetSectorsRequiredForPlainData(
  95. IN ULONG Cluster,
  96. IN UCHAR SectorsRequired
  97. );
  98. private:
  99. NONVIRTUAL
  100. VOID
  101. Construct(
  102. );
  103. NONVIRTUAL
  104. VOID
  105. Destroy(
  106. );
  107. PULONG _mdfat;
  108. ULONG _num_entries;
  109. ULONG _first_entry;
  110. };
  111. INLINE BOOLEAN
  112. CVF_FAT_EXTENS::IsClusterInUse(
  113. IN ULONG Cluster
  114. ) CONST
  115. {
  116. ULONG CfeEntry = _mdfat[Cluster];
  117. return BOOLEAN((CfeEntry & CFE_USED_MASK) >> CFE_USED_SHIFT);
  118. }
  119. INLINE VOID
  120. CVF_FAT_EXTENS::SetClusterInUse(
  121. IN ULONG Cluster,
  122. IN BOOLEAN fInUse
  123. )
  124. {
  125. ULONG CfeEntry = _mdfat[Cluster];
  126. CfeEntry &= ~CFE_USED_MASK;
  127. CfeEntry |= fInUse << CFE_USED_SHIFT;
  128. _mdfat[Cluster] = CfeEntry;
  129. }
  130. INLINE ULONG
  131. CVF_FAT_EXTENS::QuerySectorFromCluster(
  132. IN ULONG Cluster,
  133. OUT PUCHAR NumSectors
  134. )
  135. /*++
  136. Routine Description:
  137. This routine takes a cluster number and uses the mdfat to return
  138. the sector number in which the data starts. Also the number of
  139. sectors used to store the cluster data is returned. Works for
  140. compressed and uncompressed sectors as well, and for clusters
  141. whether they're "In Use" or not. The number returned is the
  142. value from the CVF_FAT_EXTENSIONS plus 1.
  143. Arguments:
  144. Cluster - the cluster to get info for.
  145. Return Value:
  146. ULONG - the CVF starting sector number.
  147. --*/
  148. {
  149. ULONG CfeEntry = _mdfat[Cluster];
  150. if (NULL != NumSectors) {
  151. *NumSectors = (UCHAR)((CfeEntry & CFE_CODED_MASK) >> CFE_CODED_SHIFT) + 1;
  152. }
  153. return ((CfeEntry & CFE_START_MASK) >> CFE_START_SHIFT) + 1;
  154. }
  155. INLINE VOID
  156. CVF_FAT_EXTENS::SetSectorForCluster(
  157. IN ULONG Cluster,
  158. IN ULONG Sector,
  159. IN UCHAR SectorCount
  160. )
  161. /*++
  162. Routine Description:
  163. This routine sets the cluster->sector mapping, as well as
  164. the number of sectors required to store the compressed cluster.
  165. Arguments:
  166. Cluster - cluster number
  167. Sector - starting CVF sector number
  168. SectorCount - number of sectors required
  169. Return Value:
  170. None.
  171. --*/
  172. {
  173. ULONG CfeEntry = _mdfat[Cluster];
  174. DbgAssert(Sector > 0);
  175. DbgAssert(SectorCount > 0);
  176. CfeEntry &= ~CFE_START_MASK;
  177. CfeEntry |= (Sector - 1) << CFE_START_SHIFT;
  178. CfeEntry &= ~CFE_CODED_MASK;
  179. CfeEntry |= ((ULONG)(SectorCount - 1) << CFE_CODED_SHIFT);
  180. _mdfat[Cluster] = CfeEntry;
  181. }
  182. INLINE UCHAR
  183. CVF_FAT_EXTENS::QuerySectorsRequiredForPlainData(
  184. IN ULONG Cluster
  185. ) CONST
  186. {
  187. ULONG CfeEntry = _mdfat[Cluster];
  188. return (UCHAR)((CfeEntry & CFE_PLAIN_MASK) >> CFE_PLAIN_SHIFT) + 1;
  189. }
  190. INLINE VOID
  191. CVF_FAT_EXTENS::SetSectorsRequiredForPlainData(
  192. IN ULONG Cluster,
  193. IN UCHAR SectorsRequired
  194. )
  195. {
  196. ULONG CfeEntry = _mdfat[Cluster];
  197. DbgAssert(SectorsRequired > 0);
  198. CfeEntry &= ~CFE_PLAIN_MASK;
  199. CfeEntry |= (ULONG)(SectorsRequired - 1) << CFE_PLAIN_SHIFT;
  200. _mdfat[Cluster] = CfeEntry;
  201. }
  202. INLINE BOOLEAN
  203. CVF_FAT_EXTENS::IsClusterCompressed(
  204. IN ULONG Cluster
  205. ) CONST
  206. {
  207. ULONG CfeEntry = _mdfat[Cluster];
  208. return ! ((CfeEntry & CFE_UNCODED_MASK) >> CFE_UNCODED_SHIFT);
  209. }
  210. INLINE VOID
  211. CVF_FAT_EXTENS::SetClusterCompressed(
  212. IN ULONG Cluster,
  213. IN BOOLEAN fCompressed
  214. )
  215. {
  216. ULONG CfeEntry = _mdfat[Cluster];
  217. CfeEntry &= ~CFE_UNCODED_MASK;
  218. CfeEntry |= (ULONG)!fCompressed << CFE_UNCODED_SHIFT;
  219. _mdfat[Cluster] = CfeEntry;
  220. }
  221. #endif // CVF_EXTS_DEFN