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.

253 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. cvf.hxx
  5. Abstract:
  6. This module contains basic declarations and definitions for
  7. the double-space file system format. Note that more extensive
  8. description of the file system structures may be found in
  9. ntos\fastfat\cvf.h
  10. Author:
  11. Bill McJohn [BillMc] 24-September-1993
  12. Revision History:
  13. Adapted from utils\ufat\inc\cvf.hxx
  14. --*/
  15. #if !defined( _CVF_DEFN_ )
  16. #define _CVF_DEFN_
  17. #include "bpb.h"
  18. // Manifest constants for fixed values on a Double Space drive:
  19. //
  20. CONST DoubleSpaceBytesPerSector = 512;
  21. CONST DoubleSpaceLog2BytesPerSector = 9;
  22. CONST DoubleSpaceSectorsPerCluster = 16;
  23. CONST DoubleSpaceLog2SectorsPerCluster = 4;
  24. CONST DoubleSpaceReservedSectors = 16;
  25. CONST DoubleSpaceFats = 1;
  26. CONST DoubleSpaceSectorsInRootDir = 32;
  27. CONST DoubleSpaceRootEntries = 512;
  28. CONST DoubleSpaceMediaByte = 0xf8;
  29. CONST DoubleSpaceSectorsPerTrack = 0x11;
  30. CONST DoubleSpaceHeads = 6;
  31. CONST DoubleSpaceHiddenSectors = 0;
  32. CONST DoubleSpaceReservedSectors2 = 31;
  33. CONST DSBytesPerBitmapPage = 2048;
  34. CONST DSSectorsPerBitmapPage = 4;
  35. CONST ULONG EIGHT_MEG = 8 * 1024L * 1024L;
  36. CONST DbSignatureLength = 4;
  37. CONST UCHAR FirstDbSignature[4 /* DbSignatureLength */] = { (UCHAR)0xf8, 'D', 'R', 0 };
  38. CONST UCHAR SecondDbSignature[4 /* DbSignatureLength */] = "MDR";
  39. #if 0
  40. // INLINE
  41. ULONG
  42. ComputeMaximumCapacity(
  43. IN ULONG HostDriveSize
  44. )
  45. /*++
  46. Routine Description:
  47. This function computes the maximum capacity for a compressed
  48. volume file on a host volume of a given size.
  49. Arguments:
  50. HostDriveSize -- Supplies the size in bytes of the host drive.
  51. Return Value:
  52. The appropriate Maximum Capacity.
  53. --*/
  54. {
  55. ULONG MaxCap;
  56. if( HostDriveSize < 20 * 1024L * 1024L ) {
  57. MaxCap = 16 * HostDriveSize;
  58. } else if ( HostDriveSize < 64 * 1024L * 1024L ) {
  59. MaxCap = 8 * HostDriveSize;
  60. } else {
  61. MaxCap = 4 * HostDriveSize;
  62. }
  63. if( MaxCap < 4 * 1024L * 1024L ) {
  64. MaxCap = 4 * 1024L * 1024L;
  65. } else if( MaxCap > 512 * 1024L * 1024L ) {
  66. MaxCap = 512 * 1024L * 1024L;
  67. }
  68. return MaxCap;
  69. }
  70. #endif
  71. typedef struct _PACKED_CVF_HEADER {
  72. //
  73. // First a typical start of a boot sector
  74. //
  75. UCHAR Jump[1]; // offset = 0x000 0
  76. UCHAR JmpOffset[2];
  77. UCHAR Oem[8]; // offset = 0x003 3
  78. PACKED_BIOS_PARAMETER_BLOCK PackedBpb; // offset = 0x00B 11
  79. //
  80. // Now the DblSpace extensions
  81. //
  82. UCHAR CvfFatExtensionsLbnMinus1[2]; // offset = 0x024 36
  83. UCHAR LogOfBytesPerSector[1]; // offset = 0x026 38
  84. UCHAR DosBootSectorLbn[2]; // offset = 0x027 39
  85. UCHAR DosRootDirectoryOffset[2]; // offset = 0x029 41
  86. UCHAR CvfHeapOffset[2]; // offset = 0x02B 43
  87. UCHAR CvfFatFirstDataEntry[2]; // offset = 0x02D 45
  88. UCHAR CvfBitmap2KSize[1]; // offset = 0x02F 47
  89. UCHAR Reserved1[2]; // offset = 0x030 48
  90. UCHAR LogOfSectorsPerCluster[1]; // offset = 0x032 50
  91. UCHAR Reserved2[2]; // offset = 0x033
  92. UCHAR MinFile[4]; // offset = 0x035
  93. UCHAR Reserved3[4]; // offset = 0x039
  94. UCHAR Is12BitFat[1]; // offset = 0x03D 61
  95. UCHAR CvfMaximumCapacity[2]; // offset = 0x03E 62
  96. UCHAR StartBootCode;
  97. } PACKED_CVF_HEADER; // sizeof = 0x040 64
  98. typedef PACKED_CVF_HEADER *PPACKED_CVF_HEADER;
  99. //
  100. // For the unpacked version we'll only define the necessary field and skip
  101. // the jump and oem fields.
  102. //
  103. typedef struct _CVF_HEADER {
  104. UCHAR Jump;
  105. USHORT JmpOffset;
  106. UCHAR Oem[8];
  107. BIOS_PARAMETER_BLOCK Bpb;
  108. USHORT CvfFatExtensionsLbnMinus1;
  109. UCHAR LogOfBytesPerSector;
  110. USHORT DosBootSectorLbn;
  111. USHORT DosRootDirectoryOffset;
  112. USHORT CvfHeapOffset;
  113. USHORT CvfFatFirstDataEntry;
  114. UCHAR CvfBitmap2KSize;
  115. UCHAR LogOfSectorsPerCluster;
  116. UCHAR Is12BitFat;
  117. ULONG MinFile;
  118. USHORT CvfMaximumCapacity;
  119. } CVF_HEADER;
  120. typedef CVF_HEADER *PCVF_HEADER;
  121. //
  122. // Here is NT's typical routine/macro to unpack the cvf header because DOS
  123. // doesn't bother to naturally align anything.
  124. //
  125. // VOID
  126. // CvfUnpackCvfHeader (
  127. // IN OUT PCVF_HEADER UnpackedHeader,
  128. // IN PPACKED_CVF_HEADER PackedHeader
  129. // );
  130. //
  131. #define CvfUnpackCvfHeader(UH,PH) { \
  132. \
  133. memcpy( &(UH)->Jump, &(PH)->Jump, 1 ); \
  134. memcpy( &(UH)->JmpOffset, &(PH)->JmpOffset, 2 ); \
  135. memcpy( &(UH)->Oem, &(PH)->Oem, 8 ); \
  136. UnpackBios( &(UH)->Bpb, &(PH)->PackedBpb ); \
  137. CopyUchar2( &(UH)->CvfFatExtensionsLbnMinus1, &(PH)->CvfFatExtensionsLbnMinus1[0] ); \
  138. CopyUchar1( &(UH)->LogOfBytesPerSector, &(PH)->LogOfBytesPerSector[0] ); \
  139. CopyUchar2( &(UH)->DosBootSectorLbn, &(PH)->DosBootSectorLbn[0] ); \
  140. CopyUchar2( &(UH)->DosRootDirectoryOffset, &(PH)->DosRootDirectoryOffset[0] ); \
  141. CopyUchar2( &(UH)->CvfHeapOffset, &(PH)->CvfHeapOffset[0] ); \
  142. CopyUchar2( &(UH)->CvfFatFirstDataEntry, &(PH)->CvfFatFirstDataEntry[0] ); \
  143. CopyUchar1( &(UH)->CvfBitmap2KSize, &(PH)->CvfBitmap2KSize[0] ); \
  144. CopyUchar1( &(UH)->LogOfSectorsPerCluster, &(PH)->LogOfSectorsPerCluster[0] ); \
  145. CopyUchar1( &(UH)->Is12BitFat, &(PH)->Is12BitFat[0] ); \
  146. CopyUchar4( &(UH)->MinFile, &(PH)->MinFile[0] ); \
  147. CopyUchar2( &(UH)->CvfMaximumCapacity, &(PH)->CvfMaximumCapacity[0] ); \
  148. }
  149. #define CvfPackCvfHeader(PH,UH) { \
  150. \
  151. memcpy( &(PH)->Jump, &(UH)->Jump, 1 ); \
  152. memcpy( &(PH)->JmpOffset, &(UH)->JmpOffset, 2 ); \
  153. memcpy( &(PH)->Oem, &(UH)->Oem, 8 ); \
  154. PackBios( &(UH)->Bpb, &(PH)->PackedBpb, ); \
  155. CopyUchar2( (PH)->CvfFatExtensionsLbnMinus1, &(UH)->CvfFatExtensionsLbnMinus1 ); \
  156. CopyUchar1( (PH)->LogOfBytesPerSector, &(UH)->LogOfBytesPerSector ); \
  157. CopyUchar2( (PH)->DosBootSectorLbn, &(UH)->DosBootSectorLbn ); \
  158. CopyUchar2( (PH)->DosRootDirectoryOffset, &(UH)->DosRootDirectoryOffset ); \
  159. CopyUchar2( (PH)->CvfHeapOffset, &(UH)->CvfHeapOffset ); \
  160. CopyUchar2( (PH)->CvfFatFirstDataEntry, &(UH)->CvfFatFirstDataEntry ); \
  161. CopyUchar1( (PH)->CvfBitmap2KSize, &(UH)->CvfBitmap2KSize ); \
  162. CopyUchar1( (PH)->LogOfSectorsPerCluster, &(UH)->LogOfSectorsPerCluster ); \
  163. CopyUchar1( (PH)->Is12BitFat, &(UH)->Is12BitFat ); \
  164. CopyUchar4( (PH)->MinFile, &(UH)->MinFile ); \
  165. CopyUchar2( (PH)->CvfMaximumCapacity, &(UH)->CvfMaximumCapacity ); \
  166. memset( (PH)->Reserved1, 0, 2 ); \
  167. memset( (PH)->Reserved2, 0, 2 ); \
  168. memset( (PH)->Reserved3, 0, 4 ); \
  169. }
  170. //
  171. // The CVF FAT EXTENSIONS is a table is ULONG entries. Each entry corresponds
  172. // to a FAT cluster. The entries describe where in the CVF_HEAP to locate
  173. // the data for the cluster. It indicates if the data is compressed and the
  174. // length of the compressed and uncompressed form.
  175. //
  176. typedef struct _CVF_FAT_EXTENSIONS {
  177. ULONG CvfHeapLbnMinus1 : 21;
  178. ULONG Reserved : 1;
  179. ULONG CompressedSectorLengthMinus1 : 4;
  180. ULONG UncompressedSectorLengthMinus1 : 4;
  181. ULONG IsDataUncompressed : 1;
  182. ULONG IsEntryInUse : 1;
  183. } CVF_FAT_EXTENSIONS;
  184. typedef CVF_FAT_EXTENSIONS *PCVF_FAT_EXTENSIONS;
  185. //
  186. // Some sizes are fixed so we'll declare them as manifest constants
  187. //
  188. #define CVF_MINIMUM_DISK_SIZE (512 * 1024L)
  189. #define CVF_FATFAILSAFE (1024L)
  190. #define CVF_MIN_HEAP_SECTORS (60)
  191. #define CVF_RESERVED_AREA_1_SECTOR_SIZE (1)
  192. #define CVF_RESERVED_AREA_2_SECTOR_SIZE (31)
  193. #define CVF_RESERVED_AREA_4_SECTOR_SIZE (2)
  194. #endif // _CVF_DEFN_