最近学习scsi和DeviceIoControl,下载了微软WDK一些例子,以下代码精简自Windows-driver-samples-master\storage\tools\spti\src\spti.c ,略有修改。
#include <windows.h> #include <stdio.h> #include <strsafe.h> void QueryPropertyForDevice(HANDLE); void PrintDeviceDescriptor(PSTORAGE_DEVICE_DESCRIPTOR); int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: %s \n", argv[0] ); printf("Examples:\n"); printf(" %s g: (PrintDeviceDescriptor)\n", argv[0]); } char filepath[7]; StringCbPrintf(filepath, sizeof(filepath), "\\\\.\\%s", argv[1]); HANDLE hDevice = CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hDevice == INVALID_HANDLE_VALUE) { unsigned long errorCode = GetLastError(); printf("Error opening %s.