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.

180 lines
4.3 KiB

  1. #ifndef __DISKUTIL_H_
  2. #define __DISKUTIL_H_
  3. #ifndef _DBG_PRINT_INSTANCES
  4. #define _DBG_PRINT_INSTANCES 0
  5. #endif
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #pragma warning ( disable : 4201 )
  10. #include <ntdddisk.h>
  11. #include <ntddvol.h>
  12. extern BOOL bUseNT4InstanceNames;
  13. extern HANDLE hLibHeap; // Handle to DLL Heap
  14. extern LONG g_lRefreshInterval;
  15. #define DU_MAX_VOLUMES ((WORD)0xFFFF)
  16. #define DU_MAX_DRIVES ((WORD)0xFFFF)
  17. #define DU_MAX_PARTITIONS ((WORD)0xFFFF)
  18. #define INITIAL_NUM_VOL_LIST_ENTRIES ((DWORD)0x0000001A)
  19. #define DVE_DEV_NAME_LEN ((DWORD)368)
  20. typedef struct _DRIVE_VOLUME_ENTRY {
  21. union {
  22. DWORD dwDriveId; // 00-03
  23. struct {
  24. WORD wPartNo;
  25. WORD wDriveNo;
  26. };
  27. };
  28. WORD wcDriveLetter; // 04-05
  29. WORD wReserved; // 06-07
  30. union {
  31. WCHAR szVolumeManager[8];
  32. ULONG64 llVolMgr[2];
  33. }; // 08-17
  34. DWORD dwVolumeNumber; // 18-1B
  35. HANDLE hVolume; // 1C-17
  36. WCHAR wszInstanceName[DVE_DEV_NAME_LEN]; // 20-1FF
  37. UNICODE_STRING DeviceName;
  38. ULONGLONG TotalBytes;
  39. ULONGLONG FreeBytes;
  40. LONGLONG LastRefreshTime;
  41. } DRIVE_VOLUME_ENTRY, *PDRIVE_VOLUME_ENTRY;
  42. typedef struct _DRIVE_LIST {
  43. LIST_ENTRY Entry;
  44. DRIVE_VOLUME_ENTRY DiskEntry;
  45. } DRIVE_LIST, *PDRIVE_LIST;
  46. #define LL_PARTMGR_0 ((LONGLONG)0x0074007200610050) //"Part"
  47. #define LL_PARTMGR_1 ((LONGLONG)0x002000720067006D) //"mgr "
  48. #define LL_PHYSDISK_0 ((LONGLONG)0x0073007900680050) //"Phys"
  49. #define LL_PHYSDISK_1 ((LONGLONG)0x006B007300690044) //"Disk"
  50. #define LL_LOGIDISK_0 ((LONGLONG)0x00690067006F004C) //"Logi"
  51. #define LL_LOGIDISK_1 ((LONGLONG)0x006B007300690044) //"Disk"
  52. #pragma warning ( default : 4201 )
  53. __inline
  54. BOOL
  55. IsPhysicalDrive (PDISK_PERFORMANCE pPerfInf) {
  56. LPWSTR szName = &pPerfInf->StorageManagerName[0];
  57. if ( ((ULONG_PTR) szName & 0x07) != 0) {
  58. if (!wcsncmp(szName, L"Partmgr ", sizeof(LONG64)))
  59. return TRUE;
  60. if (!wcsncmp(szName, L"PhysDisk", sizeof(LONG64)))
  61. return TRUE;
  62. return FALSE;
  63. }
  64. else
  65. if (((*(LONGLONG *)(szName[0]) == LL_PARTMGR_0) &&
  66. (*(LONGLONG *)(szName[4]) == LL_PARTMGR_1)) ||
  67. ((*(LONGLONG *)(szName[0]) == LL_PHYSDISK_0) &&
  68. (*(LONGLONG *)(szName[4]) == LL_PHYSDISK_1))) {
  69. return TRUE;
  70. } else {
  71. return FALSE;
  72. }
  73. }
  74. DWORD
  75. BuildPhysDiskList (
  76. HANDLE hDiskPerf,
  77. PDRIVE_VOLUME_ENTRY pList,
  78. LPDWORD pdwNumEntries
  79. );
  80. DWORD
  81. MakePhysDiskInstanceNames (
  82. PDRIVE_VOLUME_ENTRY pPhysDiskList,
  83. DWORD dwNumPhysDiskListItems,
  84. LPDWORD pdwMaxDriveNo,
  85. PDRIVE_VOLUME_ENTRY pVolumeList,
  86. DWORD dwNumVolumeListItems
  87. );
  88. DWORD
  89. BuildVolumeList (
  90. PDRIVE_VOLUME_ENTRY pList,
  91. LPDWORD pdwNumEntries
  92. );
  93. DWORD
  94. MapLoadedDisks (
  95. HANDLE hDiskPerf,
  96. PDRIVE_VOLUME_ENTRY pList,
  97. LPDWORD pdwNumEntries,
  98. LPDWORD pdwMaxVolumeNo,
  99. LPDWORD pdwWmiItemCount
  100. );
  101. DWORD
  102. GetDriveNameString (
  103. LPCWSTR szDevicePath,
  104. DWORD cchDevicePathSize,
  105. PDRIVE_VOLUME_ENTRY pList,
  106. DWORD dwNumEntries,
  107. LPWSTR szNameBuffer,
  108. LPDWORD pcchNameBufferSize,
  109. LPCWSTR szVolumeManagerName,
  110. DWORD dwVolumeNumber,
  111. PDRIVE_VOLUME_ENTRY *ppVolume
  112. );
  113. DWORD
  114. CompressPhysDiskTable (
  115. PDRIVE_VOLUME_ENTRY pOrigTable,
  116. DWORD dwOrigCount,
  117. PDRIVE_VOLUME_ENTRY pNewTable,
  118. DWORD dwNewCount
  119. );
  120. BOOL
  121. GetPhysicalDriveNameString (
  122. DWORD dwDriveNumber,
  123. PDRIVE_VOLUME_ENTRY pList,
  124. DWORD dwNumEntries,
  125. LPWSTR szNameBuffer
  126. );
  127. DWORD
  128. FindNewVolumes (
  129. PDRIVE_VOLUME_ENTRY *ppPhysDiskList,
  130. LPDWORD pdwNumPhysDiskListEntries,
  131. PDRIVE_VOLUME_ENTRY pVolumeList,
  132. DWORD dwNumVolumeListItems
  133. );
  134. #if DBG
  135. extern ULONG_PTR HeapUsed;
  136. VOID
  137. PerfDiskDebugPrint(
  138. ULONG DebugPrintLevel,
  139. PCCHAR DebugMessage,
  140. ...
  141. );
  142. #define DebugPrint(x) PerfDiskDebugPrint x
  143. #else
  144. #define DebugPrint(x)
  145. #endif // DBG
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif // __DISKUTIL_H_