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.

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