提交 8dfcdf87 编写于 作者: Z zzz

正常列出物理磁盘

/* 运行
cd /d D:\disk-recovery\sleuthkit\win32\Release\
win32PhyDiskList.exe

输出如下:
Volume Type:7, DeviceNumber:0, PartitionNumber:3
Volume Type:7, DeviceNumber:0, PartitionNumber:4
Volume Type:7, DeviceNumber:0, PartitionNumber:5
Volume Type:7, DeviceNumber:0, PartitionNumber:1
Volume Type:7, DeviceNumber:1, PartitionNumber:1
Volume Type:7, DeviceNumber:2, PartitionNumber:1
Volume Type:7, DeviceNumber:2, PartitionNumber:2

DeviceNumber取值 0,1,2 表示当前有3个物理磁盘
PartitionNumber表示该物理磁盘下的该分区
*/
上级 c1273dfe
// win32PhyDiskList.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
/*参考: https://stackoverflow.com/a/7584873
https://stackoverflow.com/questions/7584627/how-to-get-a-list-of-physical-storage-devices
*/
#include <windows.h>
#include <commctrl.h>
#include <winioctl.h>
//typedef struct _STORAGE_DEVICE_NUMBER {
// DEVICE_TYPE DeviceType;
// ULONG DeviceNumber;
// ULONG PartitionNumber;
//} STORAGE_DEVICE_NUMBER, *PSTORAGE_DEVICE_NUMBER;
void PrintVolumes()
{
char volName[MAX_PATH];
HANDLE hFVol;
DWORD bytes;
hFVol = FindFirstVolumeA(volName, sizeof(volName));
if (!hFVol)
{
printf("error...\n");
return;
}
do
{
size_t len = strlen(volName);
if (volName[len - 1] == '\\')
{
volName[len - 1] = 0;
--len;
}
/* printf("OpenVol %s\n", volName); */
HANDLE hVol = CreateFileA(volName, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (hVol == INVALID_HANDLE_VALUE)
continue;
STORAGE_DEVICE_NUMBER sdn = { 0 };
if (!DeviceIoControl(hVol, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL,
0, &sdn, sizeof(sdn), &bytes, NULL))
{
printf("error...\n");
continue;
}
CloseHandle(hVol);
printf("Volume Type:%d, DeviceNumber:%d, PartitionNumber:%d\n", (int)sdn.DeviceType, (int)sdn.DeviceNumber, (int)sdn.PartitionNumber);
/* if (sdn.DeviceType == FILE_DEVICE_DISK)
printf("\tIs a disk\n");
*/
} while (FindNextVolumeA(hFVol, volName, sizeof(volName)));
FindVolumeClose(hFVol);
}
int main()
{
PrintVolumes();
std::cout << "Hello World!\n";
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
/* 运行
cd /d D:\disk-recovery\sleuthkit\win32\Release\
win32PhyDiskList.exe
输出如下:
Volume Type:7, DeviceNumber:0, PartitionNumber:3
Volume Type:7, DeviceNumber:0, PartitionNumber:4
Volume Type:7, DeviceNumber:0, PartitionNumber:5
Volume Type:7, DeviceNumber:0, PartitionNumber:1
Volume Type:7, DeviceNumber:1, PartitionNumber:1
Volume Type:7, DeviceNumber:2, PartitionNumber:1
Volume Type:7, DeviceNumber:2, PartitionNumber:2
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
DeviceNumber取值 0,1,2 表示当前有3个物理磁盘
PartitionNumber表示该物理磁盘下的该分区
*/
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册