阅读:1008回复:2
关于磁盘大小的问题
要获取磁盘大小
我用如下两种方式获取的值为什么不一样啊? 1.. DeviceIoControl 2..GetDiskFreeSpaceEx 代码如下: #ifdef DISK_GET_GEOMETRY HANDLE hDevice; BOOL bResult; DWORD junk; DISK_GEOMETRY dgt; #endif // #ifdef DISK_GET_GEOMETRY void CDiskOperateDlg::OnButton1() { #ifdef DISK_GET_GEOMETRY hDevice = CreateFile( "\\\\.\\I:", // "\\\\.\\c:", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hDevice == INVALID_HANDLE_VALUE) { TRACE("Failed to open volume I! \n"); return RET; } else { TRACE("Successful to open I:! \n"); } bResult = DeviceIoControl( hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &dgt, sizeof(dgt), &junk, (LPOVERLAPPED)NULL); if (!bResult) { TRACE("IOCTL failed... \n"); CloseHandle(hDevice); return RET; } TRACE("IOCTL successful... \n"); OUTPUT_DISKGEOMETRY(dgt); BOOL bRS; ULARGE_INTEGER fba, tnob, tnofb; bRS =GetDiskFreeSpaceEx("I:", &fba, &tnob, &tnofb); if(bRS==FALSE) { TRACE("Failed to get size of the volume %s \n", "I:"); } CloseHandle(hDevice); #endif // #ifdef DISK_GET_GEOMETRY } 下面是用DeviceIoControl获取的磁盘数据 The number of cylinder of the volume is 3 Fixed hard disk media The number of tracks per cylinder is 255 The number of sectors per track is 63 The number of bytes per sector is 512 计算磁盘总量为: 3*255*63*512 =23.5M 可我的优盘实际大小在磁盘管理中显示为: 31M 用 GetDiskFreeSpaceEx 获取的值是正确的 大虾解惑! |
|
沙发#
发布于:2004-07-26 11:03
急切等待中......
|
|
板凳#
发布于:2004-07-28 09:27
急切等待中......
急切等待中...... |
|