WIN32磁盘操作代码
+ -

使用IOCTL_DISK_GET_DRIVE_GEOMETRY获取硬盘的布局

2021-09-07 165 0
typedef struct _DISK_GEOMETRY {
  LARGE_INTEGER Cylinders;
  MEDIA_TYPE    MediaType;
  ULONG         TracksPerCylinder;
  ULONG         SectorsPerTrack;
  ULONG         BytesPerSector;
} DISK_GEOMETRY, *PDISK_GEOMETRY;


 BOOL CDisk::GetDiskInfoById(int nId, DISK_GEOMETRY* dg)
{
     TCHAR buff[512];
     _stprintf_s(buff, TEXT("\\\\.\\PhysicalDrive%d"), nId);
     HANDLE hDevice = CreateFile(buff, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
     if (hDevice == INVALID_HANDLE_VALUE)
     {
         return FALSE;
     }

     ULONG rtn;
     BOOL bResult = DeviceIoControl(hDevice,
         IOCTL_DISK_GET_DRIVE_GEOMETRY,
         NULL, 0,
         dg, sizeof(*dg),
         &rtn,
         (LPOVERLAPPED)NULL);
     CloseHandle(hDevice);

     return bResult;
}

0 篇笔记 写笔记

使用IOCTL_DISK_GET_DRIVE_GEOMETRY获取硬盘的布局
typedef struct _DISK_GEOMETRY { LARGE_INTEGER Cylinders; MEDIA_TYPE MediaType; ULONG TracksPerCylinder; ULONG SectorsPerTra......
作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!