Re: IOCTL_DISK_READ
- From: "Andrew Rogers [MSFT]" <arogers@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 10 Oct 2005 10:44:36 -0700
If you memset the buffer to 0xFF, perform the read, and get back a buffer
full of zeros, it sounds like the read worked because the buffer contents
changed. It is possible that the sector you are reading actually contains
all zeros. Try reading a different sector, like sector 0.
The sr_callback feature is not currently supported, so you should always set
this field to NULL.
--
Andrew Rogers
Microsoft Windows CE Core OS
http://blogs.msdn.com/ce_base/
___________________________________________________________
To reply directly, remove "online" from my email address.
This posting is provided "AS IS" with no warranties, and confers no rights.
<frank433@xxxxxx> wrote in message
news:1128938428.904737.79740@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> is it possible to read some sectors of a sdcard with a call of
> DeviceIoControl/IOCTL_DISK_READ from a normal application? Or does this
> only works from within a device driver? I tried the following code, but
> it does not work (but I also don't get an error.)
>
> HANDLE hDevice = CreateFile(_T("DSK1:"),
> GENERIC_READ | GENERIC_WRITE,
> FILE_SHARE_READ | FILE_SHARE_WRITE,
> NULL,
> OPEN_EXISTING,
> 0,
> NULL);
> // hDevice is ok and GetLastError returns 0;
>
> SG_REQ lpInBuf;
> DWORD dwDummy = 0;
> LPBYTE lpOutBuf;
> lpOutBuf = (unsigned char *)malloc(512);
> memset(lpOutBuf, 0xFF, 512); // only to see the changes
> lpInBuf.sr_start = 1; // physical sector to read
> lpInBuf.sr_num_sec = 1; // read 1 sector
> lpInBuf.sr_num_sg = 1;
> lpInBuf.sr_status = 0; //ERROR_SUCCESS;
> lpInBuf.sr_callback = callbackDiskRead;
> lpInBuf.sr_sglist[0].sb_buf = ((LPBYTE) MapPtrToProcess(lpOutBuf,
> GetCurrentProcess()));
> lpInBuf.sr_sglist[0].sb_len = 512 * lpInBuf.sr_num_sec;
>
> DeviceIoControl(hDevice, // Handle to the device
> IOCTL_DISK_READ, // IOCTL for the operation
> &lpInBuf, // LP to a buffer (input data)
> sizeof(lpInBuf), // Size in Bytes of input data
> buffer
> NULL, // LP to a buffer for output data
> 0, // Size in Bytes of output buffer
> &dwDummy, // LP to variable (size of data in out
> buffer)
> NULL);
>
> DeviceIoControl returns true and GetLastError returns 0. But all bytes
> im my outputbuffer lpOutBuf are zero. I also tried lpInBuf.sr_callback
> = NULL; because my callback function is never called.
>
> Thanks,
> Frank
>
.
- Follow-Ups:
- Re: IOCTL_DISK_READ
- From: frank433@xxxxxx
- Re: IOCTL_DISK_READ
- References:
- IOCTL_DISK_READ
- From: frank433@xxxxxx
- IOCTL_DISK_READ
- Prev by Date: Re: Remotely control CE.Net device
- Next by Date: Using Message Queues to talk between processes.
- Previous by thread: IOCTL_DISK_READ
- Next by thread: Re: IOCTL_DISK_READ
- Index(es):
Relevant Pages
|