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.

181 lines
3.2 KiB

  1. //
  2. // DISK.H - Classes for partition table manipulation
  3. //
  4. // Revision History:
  5. //
  6. #ifndef _SRT__DISK_H_
  7. #define _SRT__DISK_H_
  8. extern "C"
  9. {
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <ntdddisk.h>
  14. #include <diskguid.h>
  15. }
  16. #include <windows.h>
  17. #include <sys.h>
  18. class CDrive;
  19. #define PARTITION_NAME_LENGTH 36
  20. typedef struct Geometry {
  21. LONGLONG cylinders;
  22. MEDIA_TYPE mediaType;
  23. ULONG tracksPerCylinder; // heads
  24. ULONG sectorsPerTrack;
  25. ULONG bytesPerSector; // sectorSize
  26. ULONGLONG totalSectorCount; // cylinders*tracksPerCylinder*sectorsPerTrack
  27. ULONG bytesPerCylinder; // tracksPerCylinder*sectorsPerTack*bytesPerSector
  28. ULONG bytesPerTrack; // sectorsPerTack*bytesPerSector
  29. } GEOMETRY, *PGEOMETRY;
  30. class CDrive
  31. {
  32. public:
  33. ULONG m_diskNumber;
  34. ULONG m_numPartitions;
  35. LONGLONG m_length;
  36. GEOMETRY m_geometry;
  37. LONGLONG m_trueLength;
  38. BOOLEAN m_isNEC98;
  39. PARTITION_STYLE m_style; // The partitioning style of the disk (MBR, GPT, unknown)
  40. union { // Information specific to the partitioning style
  41. struct { // The discriminator of the union is the field "style"
  42. ULONG m_signature;
  43. } m_mbr;
  44. struct {
  45. GUID m_diskId;
  46. LONGLONG m_startingUsableOffset;
  47. LONGLONG m_usableLength;
  48. ULONG m_maxPartitionCount;
  49. } m_gpt;
  50. } m_info;
  51. public:
  52. HRESULT
  53. Initialize(
  54. LPCTSTR lpszLogicalDrive
  55. );
  56. ~CDrive(
  57. );
  58. public:
  59. HRESULT
  60. ReadBootRecord(
  61. LPCTSTR lpszLogicalDrive,
  62. UINT nSectors,
  63. PBYTE *buffer
  64. );
  65. HRESULT
  66. WriteBootRecord(
  67. LPCTSTR lpszLogicalDrive,
  68. UINT nSectors,
  69. PBYTE *buffer
  70. );
  71. HRESULT
  72. WriteBootRecordXP(
  73. LPCTSTR lpszLogicalDrive,
  74. UINT nSectors,
  75. PBYTE *buffer
  76. );
  77. };
  78. /*
  79. * Low level functions for manipulating disks, partitions,
  80. * volumes, filesystems
  81. */
  82. HANDLE
  83. LowOpenDisk(
  84. ULONG diskNumber
  85. );
  86. HANDLE
  87. LowOpenPartition(
  88. ULONG diskNumber,
  89. ULONG partitionNumber
  90. );
  91. HANDLE
  92. LowOpenPartition(
  93. LPCTSTR lpszLogicalDrive
  94. );
  95. HRESULT
  96. LowGetGeometry(
  97. HANDLE handle,
  98. PDISK_GEOMETRY geometry
  99. );
  100. HRESULT
  101. LowGetLength(
  102. HANDLE handle,
  103. PLONGLONG length
  104. );
  105. HRESULT
  106. LowReadSectors(
  107. HANDLE handle,
  108. ULONG sectorSize,
  109. ULONG startingSector,
  110. ULONG numberOfSectors,
  111. PVOID buffer
  112. );
  113. HRESULT
  114. LowWriteSectors(
  115. HANDLE handle,
  116. ULONG sectorSize,
  117. ULONG startingSector,
  118. ULONG numberOfSectors,
  119. PVOID buffer
  120. );
  121. HRESULT
  122. LowFsLock(
  123. HANDLE handle
  124. );
  125. HRESULT
  126. LowFsUnlock(
  127. HANDLE handle
  128. );
  129. HRESULT
  130. LowFsDismount(
  131. HANDLE handle
  132. );
  133. /*
  134. * Arithmetics
  135. */
  136. LONGLONG
  137. RoundUp(
  138. LONGLONG value,
  139. LONGLONG factor
  140. );
  141. LONGLONG
  142. RoundDown(
  143. LONGLONG value,
  144. LONGLONG factor
  145. );
  146. #endif // _SRT__DISK_H_