SetFilePosition, ReadFile failed with ERROR_NOT_SUPPORTED (50)
So I used DeviceIoControl as below. but DeviceIoControl failed with
ERROR_SECTOR_NOT_FOUND (27)
Disk has no problem because it can be read with FindFirstFile successfully.
Is it prohibitted accessing disk raw data in WinCE 6.0?
m_hFile = CreateFile("DSK2:", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
UCHAR lpBuffer[2048];
SG_REQ InBuf;
InBuf.sr_start = nSector; // 0 ~ 20
InBuf.sr_num_sec = 1;
InBuf.sr_num_sg = 1;
InBuf.sr_status = 0;
InBuf.sr_callback = NULL;
InBuf.sr_sglist[0].sb_buf = lpBuffer;
InBuf.sr_sglist[0].sb_len = 2048 * InBuf.sr_num_sec;
DWORD dwReadByte = 0;
if ( DeviceIoControl(m_hFile, IOCTL_DISK_READ, &InBuf, sizeof(InBuf),
NULL, 0,
&dwReadByte, 0) == 0 )
{
SLOG(0, _T("DeviceIoControl fail, %d\r\n"), GetLastError());
return 0;
}
CloseHandle(m_hFile);
--
Message posted via http://www.pocketpcjunkies.com
Kind Regards,
Rob.
www.robtso.nl
"asroma via PocketPCJunkies.com" wrote:
> .
>
Rob wrote:
>Maybe you need an outbuf too ?
>
>Kind Regards,
>Rob.
>www.robtso.nl
>
>> I want to read disk raw data in WinCE 6.0, because I need each file's
>> "location of extent" in "directory record".
>[quoted text clipped - 30 lines]
Judging from the return code it seems that nSector has some strange
value (out of the valid sector numbers range).
If you have source code of your block driver (if it's one of the
standard drivers it's under WINCE600\PUBLIC\COMMON\OAK\DRIVERS\BLOCK)
and put a breakpoint inside DSK_IoCtl where the IOCTL_DISK_READ request
is handled.
--
Valter Minute (eMVP)
Training, support and development for Windows CE:
www.fortechembeddedlabs.it
My embedded programming and cooking blog:
www.geekswithblogs.net/WindowsEmbeddedCookbook
Windows Embedded support forums in Italian:
http://social.msdn.microsoft.com/Forums/it-IT/windowsembeddedit/threads
(the reply address of this message is invalid)
HANDLE hDisk = INVALID_HANDLE_VALUE;
DISK_INFO diskInfo;
SG_REQ sg;
LPBYTE lpSector = NULL;
DWORD dwXfer, dwCount;
BOOL rc = FALSE;
hDisk = CreateFile(L"DSK1:", 0, GENERIC_READ|GENERIC_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, NULL);
if (hDisk == INVALID_HANDLE_VALUE || hDisk == NULL)
{
rc = FALSE;
goto _exit;
}
memset(&diskInfo, 0, sizeof(DISK_INFO));
rc = DeviceIoControl(hDisk, IOCTL_DISK_GETINFO, NULL, 0, &diskInfo,
sizeof(DISK_INFO), &dwXfer, NULL);
if (!rc)
{
rc = FALSE;
goto _exit;
}
lpSector = LocalAlloc(LPTR, diskInfo.di_bytes_per_sect);
if (lpSector == NULL)
{
rc = FALSE;
goto _exit;
}
for(dwCount=0;dwCount<diskInfo.di_sectors;dwCount++)
{
sg.sr_start = dwCount;
sg.sr_num_sec = 1;
sg.sr_num_sg = 1;
sg.sr_status = 0;
sg.sr_callback = NULL;
sg.sr_sglist[0].sb_buf = lpSector;
sg.sr_sglist[0].sb_len = diskInfo.di_bytes_per_sect;
// Read the sector
rc = DeviceIoControl(hDisk, IOCTL_DISK_READ, &sg, sizeof(SG_REQ), NULL, 0,
&dwXfer, NULL);
if (rc == FALSE) goto _exit;
}
// Operation completed
rc = TRUE;
_exit:
if (lpSector != NULL)
{
LocalFree(lpSector);
lpSector = NULL;
}
if (hDisk != INVALID_HANDLE_VALUE && hDisk!=NULL)
{
CloseHandle(hDisk);
hDisk = INVALID_HANDLE_VALUE;
}
Chris.
--
http://developce.blogspot.com/
"asroma via PocketPCJunkies.com" wrote:
> .
>