Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WinCE 6.0 disk raw data read

173 views
Skip to first unread message

asroma via PocketPCJunkies.com

unread,
Nov 29, 2009, 8:05:11 PM11/29/09
to
I want to read disk raw data in WinCE 6.0, because I need each file's
"location of extent" in "directory record".

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

Rob

unread,
Nov 30, 2009, 4:46:01 AM11/30/09
to

Maybe you need an outbuf too ?

Kind Regards,
Rob.
www.robtso.nl

"asroma via PocketPCJunkies.com" wrote:

> .
>

asroma via PocketPCJunkies.com

unread,
Nov 30, 2009, 10:56:22 AM11/30/09
to
In case of IOCTL_DISK_READ, it only need InBuf.
But InBuf include output buffer that is lpBuffer.

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]

Valter Minute [eMVP]

unread,
Dec 1, 2009, 4:29:49 AM12/1/09
to
asroma via PocketPCJunkies.com wrote:
> I want to read disk raw data in WinCE 6.0, because I need each file's
> "location of extent" in "directory record".
>
> 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?
[...]

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)

cjay

unread,
Dec 3, 2009, 4:39:01 AM12/3/09
to

The following is some code I use for this application. It came from some code
I wrote which creates an image of an entire disk. The only real difference
that I can see between this and your code is that it dynamically creates a
buffer of the correct size per sector. Are you sure that the sector size is
2KBytes and not larger for example 4KBytes?

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:

> .
>

0 new messages