Advertisement
Guest User

Untitled

a guest
May 27th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. UInt32 Resource::GetDiskInfoEx(PVoid buffer, UInt32 bufferSize, LPDWORD bytesReturned)
  2. {
  3. if (nullptr == buffer)
  4. {
  5. LogEvent(LOG_ERROR, L"Resource::GetDiskInfoEx: null buffer error: 0x%x", ERROR_INVALID_PARAMETER);
  6. return ERROR_INVALID_PARAMETER;
  7. }
  8.  
  9. struct StorageValueList
  10. {
  11. CLUSPROP_VALUE sig;
  12. GUID guid;
  13.  
  14. CLUSPROP_SCSI_ADDRESS scsiAddress;
  15. CLUSPROP_DISK_NUMBER diskNumber;
  16. CLUSPROP_PARTITION_INFO_EX partitionInfo;
  17. CLUSPROP_SYNTAX endmark;
  18. };
  19. *bytesReturned = sizeof(StorageValueList);
  20. if (bufferSize < sizeof(StorageValueList))
  21. {
  22. return ERROR_MORE_DATA;
  23. }
  24. ::ZeroMemory(buffer, bufferSize);
  25.  
  26. auto storage = static_cast<StorageValueList*>(buffer);
  27.  
  28. // CLUSPROP_DISK_SIGNATURE
  29. storage->sig.Syntax.dw = CLUSPROP_SYNTAX_DISK_GUID;
  30. storage->sig.cbLength = sizeof(GUID);
  31. storage->guid = m_diskInfo.GetVolumeGuid();
  32.  
  33. // CLUSPROP_SCSI_ADDRESS
  34. const auto& scsiAddress = m_diskInfo.GetScsiAddress();
  35. storage->scsiAddress.Syntax.dw = CLUSPROP_SYNTAX_SCSI_ADDRESS;
  36. storage->scsiAddress.Lun = scsiAddress.Lun;
  37. storage->scsiAddress.PathId = scsiAddress.PathId;
  38. storage->scsiAddress.PortNumber = scsiAddress.PortNumber;
  39. storage->scsiAddress.TargetId = scsiAddress.TargetId;
  40. storage->scsiAddress.cbLength = sizeof(storage->scsiAddress.dw);
  41.  
  42. // CLUSPROP_DISK_NUMBER
  43. storage->diskNumber.Syntax.dw = CLUSPROP_SYNTAX_DISK_NUMBER;
  44. // TODO: Is this correct value for
  45. storage->diskNumber.dw = m_diskDeviceNumber.load();
  46. storage->diskNumber.cbLength = sizeof(storage->diskNumber.dw);
  47.  
  48. // CLUSPROP_PARTITION_INFO_EX
  49. const auto& props = m_properties.Get();
  50. static const DWORD bufSize = MAX_PATH;
  51. TChar volumeName[bufSize] = { 0 };
  52. DWORD volumeSerialNumber = 0;
  53. DWORD maximumComponentLength = 0;
  54. DWORD fileSystemFlags;
  55. static const DWORD fileSystemNameBufferSize = sizeof(storage->partitionInfo.szFileSystem);
  56. TChar fileSystemName[fileSystemNameBufferSize] = { 0 };
  57. if (!GetVolumeInformation(props.MountPoint, volumeName, bufSize, &volumeSerialNumber, &maximumComponentLength, &fileSystemFlags, fileSystemName, fileSystemNameBufferSize))
  58. {
  59. const auto error = ::GetLastError();
  60. LogEvent(LOG_ERROR, L"Resource::GetDiskInfoEx: GetVolumeInformation error: 0x%x", error);
  61. return error;
  62. }
  63. LogEvent(LOG_INFORMATION, L"Resource::GetDiskInfoEx: volume information: name %s, serial number 0x%x, maximum component length %d, file system flags 0x%x, file system %s",
  64. volumeName, volumeSerialNumber, maximumComponentLength, fileSystemFlags, fileSystemName);
  65.  
  66. ULARGE_INTEGER totalNumberOfBytes = { 0 };
  67. ULARGE_INTEGER totalNumberOfFreeBytes = { 0 };
  68. //GetDiskFreeSpaceEx
  69.  
  70. storage->partitionInfo.Syntax.dw = CLUSPROP_SYNTAX_PARTITION_INFO_EX;
  71. storage->partitionInfo.dwFlags = CLUSPROP_PIFLAG_STICKY | CLUSPROP_PIFLAG_USABLE | CLUSPROP_PIFLAG_DEFAULT_QUORUM;
  72. // TODO: remove backslash
  73. wcscpy_s(storage->partitionInfo.szDeviceName, MAX_PATH, props.MountPoint);
  74. wcscpy_s(storage->partitionInfo.szVolumeLabel, MAX_PATH, volumeName);
  75. storage->partitionInfo.dwSerialNumber = volumeSerialNumber;
  76. storage->partitionInfo.rgdwMaximumComponentLength = maximumComponentLength;
  77. storage->partitionInfo.dwFileSystemFlags = fileSystemFlags;
  78. wcscpy_s(storage->partitionInfo.szFileSystem, fileSystemNameBufferSize, fileSystemName);
  79. storage->partitionInfo.TotalSizeInBytes = totalNumberOfBytes;
  80. storage->partitionInfo.FreeSizeInBytes = totalNumberOfFreeBytes;
  81. // TODO: Is this correct value for
  82. storage->partitionInfo.DeviceNumber = m_diskDeviceNumber.load();
  83. storage->partitionInfo.PartitionNumber = m_diskInfo.GetPartitionNumber();
  84. storage->partitionInfo.VolumeGuid = m_diskInfo.GetVolumeGuid();
  85. storage->partitionInfo.cbLength = sizeof(CLUS_PARTITION_INFO_EX);
  86.  
  87. // CLUSPROP_SYNTAX
  88. storage->endmark.dw = CLUSPROP_SYNTAX_ENDMARK;
  89.  
  90. return ERROR_SUCCESS;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement