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.

135 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. ntfs_rec.h
  5. Abstract:
  6. This module contains the mini-file system recognizer for NTFS.
  7. Author:
  8. Darryl E. Havens (darrylh) 8-dec-1992
  9. Environment:
  10. Kernel mode, local to I/O system
  11. Revision History:
  12. --*/
  13. //
  14. // The fundamental unit of allocation on an Ntfs volume is the
  15. // cluster. Format guarantees that the cluster size is an integral
  16. // power of two times the physical sector size of the device. Ntfs
  17. // reserves 64-bits to describe a cluster, in order to support
  18. // large disks. The LCN represents a physical cluster number on
  19. // the disk, and the VCN represents a virtual cluster number within
  20. // an attribute.
  21. //
  22. typedef LARGE_INTEGER LCN;
  23. typedef LCN *PLCN;
  24. typedef LARGE_INTEGER VCN;
  25. typedef VCN *PVCN;
  26. typedef LARGE_INTEGER LBO;
  27. typedef LBO *PLBO;
  28. typedef LARGE_INTEGER VBO;
  29. typedef VBO *PVBO;
  30. //
  31. // The boot sector is duplicated on the partition. The first copy
  32. // is on the first physical sector (LBN == 0) of the partition, and
  33. // the second copy is at <number sectors on partition> / 2. If the
  34. // first copy can not be read when trying to mount the disk, the
  35. // second copy may be read and has the identical contents. Format
  36. // must figure out which cluster the second boot record belongs in,
  37. // and it must zero all of the other sectors that happen to be in
  38. // the same cluster. The boot file minimally contains with two
  39. // clusters, which are the two clusters which contain the copies of
  40. // the boot record. If format knows that some system likes to put
  41. // code somewhere, then it should also align this requirement to
  42. // even clusters, and add that to the boot file as well.
  43. //
  44. // Part of the sector contains a BIOS Parameter Block. The BIOS in
  45. // the sector is packed (i.e., unaligned) so we'll supply an
  46. // unpacking macro to translate a packed BIOS into its unpacked
  47. // equivalent. The unpacked BIOS structure is already defined in
  48. // ntioapi.h so we only need to define the packed BIOS.
  49. //
  50. //
  51. // Define the Packed and Unpacked BIOS Parameter Block
  52. //
  53. typedef struct _PACKED_BIOS_PARAMETER_BLOCK {
  54. UCHAR BytesPerSector[2]; // offset = 0x000
  55. UCHAR SectorsPerCluster[1]; // offset = 0x002
  56. UCHAR ReservedSectors[2]; // offset = 0x003 (zero)
  57. UCHAR Fats[1]; // offset = 0x005 (zero)
  58. UCHAR RootEntries[2]; // offset = 0x006 (zero)
  59. UCHAR Sectors[2]; // offset = 0x008 (zero)
  60. UCHAR Media[1]; // offset = 0x00A
  61. UCHAR SectorsPerFat[2]; // offset = 0x00B (zero)
  62. UCHAR SectorsPerTrack[2]; // offset = 0x00D
  63. UCHAR Heads[2]; // offset = 0x00F
  64. UCHAR HiddenSectors[4]; // offset = 0x011 (zero)
  65. UCHAR LargeSectors[4]; // offset = 0x015 (zero)
  66. } PACKED_BIOS_PARAMETER_BLOCK; // sizeof = 0x019
  67. typedef PACKED_BIOS_PARAMETER_BLOCK *PPACKED_BIOS_PARAMETER_BLOCK;
  68. //
  69. // Define the boot sector. Note that MFT2 is exactly three file
  70. // record segments long, and it mirrors the first three file record
  71. // segments from the MFT, which are MFT, MFT2 and the Log File.
  72. //
  73. // The Oem field contains the ASCII characters "NTFS ".
  74. //
  75. // The Checksum field is a simple additive checksum of all of the
  76. // ULONGs which precede the Checksum ULONG. The rest of the sector
  77. // is not included in this Checksum.
  78. //
  79. typedef struct _PACKED_BOOT_SECTOR {
  80. UCHAR Jump[3]; // offset = 0x000
  81. UCHAR Oem[8]; // offset = 0x003
  82. PACKED_BIOS_PARAMETER_BLOCK PackedBpb; // offset = 0x00B
  83. UCHAR Unused[4]; // offset = 0x024
  84. LARGE_INTEGER NumberSectors; // offset = 0x028
  85. LCN MftStartLcn; // offset = 0x030
  86. LCN Mft2StartLcn; // offset = 0x038
  87. CHAR ClustersPerFileRecordSegment; // offset = 0x040
  88. UCHAR Reserved0[3];
  89. CHAR DefaultClustersPerIndexAllocationBuffer; // offset = 0x044
  90. UCHAR Reserved1[3];
  91. LARGE_INTEGER SerialNumber; // offset = 0x048
  92. ULONG Checksum; // offset = 0x050
  93. UCHAR BootStrap[0x200-0x054]; // offset = 0x054
  94. } PACKED_BOOT_SECTOR; // sizeof = 0x200
  95. typedef PACKED_BOOT_SECTOR *PPACKED_BOOT_SECTOR;
  96. //
  97. // Define the functions provided by this driver.
  98. //
  99. BOOLEAN
  100. IsNtfsVolume(
  101. IN PPACKED_BOOT_SECTOR BootSector,
  102. IN ULONG BytesPerSector,
  103. IN PLARGE_INTEGER NumberOfSectors
  104. );