http://www.armce.com/bbs/thread-113-1-2.html
常用代码段: 从block设备中读取扇区大小,扇区数,和总容量等。
- void GetStorageInfo()
- {
- DISK_INFO m_devinfo;
- BOOL buf=1;
- unsigned long BytesReturned;
- //这里DSK1:的名字要根据具体你的块设备index来的,sd卡的index一般不定死,但你可以用注册表工具从Active下面找到被加载的所有block设备,你可以知道哪个DSK是哪个存储设备。5楼更新了具体的方法。
- HANDLE h_nfd = CreateFile( L"DSK1:",
- GENERIC_READ,
- 0,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
- if(h_nfd==NULL)
- ::MessageBox ( NULL, L"ERRO in createfile", L"ERROR", 0);
- if ( FALSE == DeviceIoControl(
- h_nfd,
- IOCTL_DISK_GETINFO,
- NULL,
- 0,
- &m_devinfo
- sizeof(m_devinfo),
- &BytesReturned,
- NULL
- )) {
- ::MessageBox ( NULL, L"DISK_IOCTL_GETINFO", L"ERROR", 0);
- return ;
- }
- CString tmp;
- tmp.Format(L"di_bytes_per_sect=%d di_total_sectors =%d Total Captal=%d/r/n",inbuf.di_bytes_per_sect,inbuf.di_total_sectors,di_total_sectors*di_bytes_per_sect );
- ::MessageBox ( NULL, tmp, L"ERROR", 0);
- CloseHandle(h_nfd);
- }