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.

377 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 1990-2000 Microsoft Corporation
  3. Module Name:
  4. fatntfs.hxx
  5. Abstract:
  6. This module implements the FAT_NTFS conversion class.
  7. Author:
  8. Ramon J. San Andres (ramonsa) 23-Sep-1991
  9. --*/
  10. #if !defined( _FAT_NTFS_)
  11. #define _FATNTFS_
  12. //
  13. // ULIB header files
  14. //
  15. #include "volume.hxx"
  16. #include "ifsentry.hxx"
  17. // IFSUTIL header files
  18. #include "numset.hxx"
  19. //
  20. // FAT header files
  21. //
  22. #include "fat.hxx"
  23. #include "rfatsa.hxx"
  24. #include "eaheader.hxx"
  25. #include "easet.hxx"
  26. //
  27. // NTFS header files
  28. //
  29. #include "untfs.hxx"
  30. #include "frs.hxx"
  31. #include "mft.hxx"
  32. #include "mftfile.hxx"
  33. #include "mftref.hxx"
  34. #include "ntfsbit.hxx"
  35. #include "ntfssa.hxx"
  36. #include "attrdef.hxx"
  37. #include "badfile.hxx"
  38. #include "bootfile.hxx"
  39. #include "bitfrs.hxx"
  40. #include "indxtree.hxx"
  41. #include "upcase.hxx"
  42. //
  43. // Length of a buffer containing an file name.
  44. //
  45. #define NAMEBUFFERSIZE 255
  46. //
  47. // Forward references
  48. //
  49. DECLARE_CLASS( EA_HEADER );
  50. DECLARE_CLASS( FATDIR );
  51. DECLARE_CLASS( REAL_FAT_SA );
  52. DECLARE_CLASS( LOG_IO_DP_DRIVE );
  53. DECLARE_CLASS( MESSAGE );
  54. DECLARE_CLASS( FAT_NTFS );
  55. DECLARE_CLASS( NTFS_INDEX_TREE );
  56. DECLARE_CLASS( NTFS_FILE_RECORD_SEGMENT );
  57. class FAT_NTFS : public OBJECT {
  58. public:
  59. DECLARE_CONSTRUCTOR( FAT_NTFS );
  60. VIRTUAL
  61. ~FAT_NTFS (
  62. );
  63. NONVIRTUAL
  64. VOID
  65. Construct (
  66. );
  67. NONVIRTUAL
  68. BOOLEAN
  69. Initialize(
  70. IN OUT PLOG_IO_DP_DRIVE Drive,
  71. IN OUT PREAL_FAT_SA FatSa,
  72. IN PCWSTRING CvtZoneFileName,
  73. IN OUT PMESSAGE Message DEFAULT NULL,
  74. IN ULONG Flags DEFAULT 0
  75. );
  76. NONVIRTUAL
  77. BOOLEAN
  78. Convert(
  79. OUT PCONVERT_STATUS Status
  80. );
  81. private:
  82. NONVIRTUAL
  83. VOID
  84. Destroy (
  85. );
  86. NONVIRTUAL
  87. BOOLEAN
  88. CheckSpaceAndCreateHoles (
  89. );
  90. NONVIRTUAL
  91. LCN
  92. FatClusterToLcn (
  93. IN ULONG Cluster
  94. );
  95. NONVIRTUAL
  96. BOOLEAN
  97. ConvertDirectory (
  98. IN PFATDIR Directory,
  99. IN PFAT_DIRENT DirEntry,
  100. IN OUT PNTFS_FILE_RECORD_SEGMENT FrsDir
  101. );
  102. NONVIRTUAL
  103. BOOLEAN
  104. ConvertDir (
  105. IN PFATDIR Directory,
  106. IN OUT PNTFS_INDEX_TREE Index,
  107. IN OUT PNTFS_FILE_RECORD_SEGMENT FrsDir
  108. );
  109. NONVIRTUAL
  110. BOOLEAN
  111. ConvertExtendedAttributes (
  112. IN PFAT_DIRENT Dirent,
  113. IN OUT PNTFS_FILE_RECORD_SEGMENT Frs
  114. );
  115. NONVIRTUAL
  116. BOOLEAN
  117. ConvertExtendedAttributes (
  118. IN OUT PNTFS_FILE_RECORD_SEGMENT Frs,
  119. IN USHORT EaSetClusterNumber
  120. );
  121. NONVIRTUAL
  122. BOOLEAN
  123. ConvertFile (
  124. IN PFAT_DIRENT Dirent,
  125. IN OUT PNTFS_FILE_RECORD_SEGMENT File
  126. );
  127. NONVIRTUAL
  128. BOOLEAN
  129. ConvertFileData (
  130. IN PFAT_DIRENT Dirent,
  131. IN PNTFS_FILE_RECORD_SEGMENT Frs
  132. );
  133. NONVIRTUAL
  134. BOOLEAN
  135. ConvertFileDataNonResident (
  136. IN PFAT_DIRENT Dirent,
  137. IN PNTFS_FILE_RECORD_SEGMENT Frs
  138. );
  139. NONVIRTUAL
  140. BOOLEAN
  141. ConvertFileDataResident (
  142. IN PFAT_DIRENT Dirent,
  143. IN PNTFS_FILE_RECORD_SEGMENT Frs
  144. );
  145. NONVIRTUAL
  146. BOOLEAN
  147. ConvertFileSystem (
  148. );
  149. NONVIRTUAL
  150. BOOLEAN
  151. ConvertOneExtendedAttribute (
  152. IN OUT PNTFS_FILE_RECORD_SEGMENT Frs,
  153. IN PEA Ea
  154. );
  155. NONVIRTUAL
  156. BOOLEAN
  157. ConvertRoot (
  158. IN PFATDIR Directory
  159. );
  160. NONVIRTUAL
  161. BOOLEAN
  162. CreateBitmaps (
  163. );
  164. NONVIRTUAL
  165. BOOLEAN
  166. CreateElementary (
  167. );
  168. NONVIRTUAL
  169. BOOLEAN
  170. FreeReservedSectors (
  171. );
  172. NONVIRTUAL
  173. BOOLEAN
  174. MakeDirectoryFrs (
  175. IN PFAT_DIRENT Dirent,
  176. IN PNTFS_FILE_RECORD_SEGMENT ParentFrs,
  177. OUT PNTFS_FILE_RECORD_SEGMENT FrsDir,
  178. OUT PNTFS_INDEX_TREE RootIndex
  179. );
  180. NONVIRTUAL
  181. BOOLEAN
  182. QueryNeededHoles (
  183. OUT PINTSTACK HoleStack
  184. );
  185. NONVIRTUAL
  186. VOID
  187. QuerySectorsNeededForConversion (
  188. IN PCENSUS_REPORT Census,
  189. IN PBIG_INT SectorsNeeded
  190. );
  191. NONVIRTUAL
  192. BOOLEAN
  193. ReserveCluster (
  194. IN ULONG Cluster
  195. );
  196. NONVIRTUAL
  197. BOOLEAN
  198. CheckGeometryMatch(
  199. );
  200. NONVIRTUAL
  201. BOOLEAN
  202. WriteBoot (
  203. );
  204. //
  205. // FAT stuff
  206. //
  207. PREAL_FAT_SA _FatSa; // Fat SuperArea
  208. HMEM _EAMemory; // Mem for EAHeader
  209. EA_HEADER _EAHeader; // EA header
  210. ULONG _EAFileFirstCluster; // EA file starting cluster
  211. ULONG _CvtZoneFileFirstCluster; // Convert Zone file starting cluster
  212. ULONG _CvtZoneSize; // convert zone file size in clusters
  213. //
  214. // NTFS stuff
  215. //
  216. NTFS_SA _NtfsSa; // NTFS SuperArea
  217. ULONG _ClusterFactor; // Cluster factor
  218. ULONG _ClustersPerIndexBuffer;// Default clusters per index buffer
  219. NTFS_BITMAP _ReservedBitmap; // Bitmap of reserved sectors
  220. NTFS_BITMAP _VolumeBitmap; // Volume Bitmap
  221. NTFS_UPCASE_TABLE _UpcaseTable; // Volume upcase table.
  222. NUMBER_SET _BadLcn; // Bad clusters
  223. ULONG _LogFileClusters; // Size of Log File
  224. NTFS_MFT_FILE _Mft; // Master File Table File
  225. DSTRING _RootIndexName; // Root index name
  226. ULONG _FrsSize;
  227. //
  228. // Other stuff
  229. //
  230. PLOG_IO_DP_DRIVE _Drive; // Drive
  231. PMESSAGE _Message; // Message
  232. CONVERT_STATUS _Status; // Conversion status
  233. ULONG _Flags; // Flags passed to convert
  234. ULONG _NumberOfFiles; // Number of files on disk
  235. ULONG _NumberOfDirectories; // Number of dirs on disk
  236. LCN _FreeSectorsBefore; // Free sectors before conversion
  237. LCN _FreeSectorsAfter; // Free sectors after conversion
  238. PFILE_NAME _FileNameBuffer; // Buffer for file name attribute
  239. ULONG _ClusterRatio; // Sectors ratio between NTFS vs FAT clusters
  240. #if DBG
  241. //
  242. // Debug stuff
  243. //
  244. NONVIRTUAL
  245. VOID
  246. PrintAtLevel (
  247. );
  248. #endif
  249. ULONG _Level; // Indentation level for verbose output
  250. };
  251. INLINE
  252. LCN
  253. FAT_NTFS::FatClusterToLcn (
  254. IN ULONG Cluster
  255. )
  256. /*++
  257. Routine Description:
  258. Converts a FAT cluster to an LCN
  259. Arguments:
  260. Cluster - Supplies the cluster number
  261. Return Value:
  262. LCN - The first LCN of the cluster
  263. --*/
  264. {
  265. return _FatSa->QueryStartDataLbn() + (Cluster - FirstDiskCluster) * _FatSa->QuerySectorsPerCluster();
  266. }
  267. #if DBG
  268. INLINE
  269. VOID
  270. FAT_NTFS::PrintAtLevel (
  271. )
  272. /*++
  273. Routine Description:
  274. Prints a certain number of spaces corresponding to the value of
  275. _Level. Is used to print the directory structure on the debug
  276. terminal in a nice way.
  277. Arguments:
  278. None
  279. Return Value:
  280. None
  281. --*/
  282. {
  283. ULONG l = _Level;
  284. while ( l-- ) {
  285. DebugPrintTrace(( " " ));
  286. }
  287. }
  288. #endif // DBG
  289. #endif // _FAT_NTFS_