Re: IOCTL_DISK_READ

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
>


.



Relevant Pages

  • Re: Sockets and File Transfer and Corruption Problems
    ... For some reason when I load the winsock buffer with data and send it and I ... how it is loading the socket with the data but it's not working then if I ... chunks of data to arrive in same sizes as sent. ... in the file then another 1024 bytes of data is nothing but zeros. ...
    (microsoft.public.win32.programmer.networks)
  • Re: vm86.c audit_syscall_exit() call trashes registers
    ... Sometimes the EDID buffer would be all zeros. ... Also when audit is not enabled the audit ...
    (Linux-Kernel)
  • Re: zeropadding and fft in matlab
    ... Dave Robinson wrote: ... irzerosifft = real); ... be then create an empty buffer this size. ... This creates a buffer containing only zeros of the correct length. ...
    (comp.soft-sys.matlab)
  • Re: vm86.c audit_syscall_exit() call trashes registers
    ... The corruption originally looked like a race condition. ... Sometimes the EDID buffer would be all zeros. ... Sometimes it would contain partial data, and then the rest of the buffer filled with zeros. ...
    (Linux-Kernel)
  • Re: Simulink-buffer
    ... not come out of the buffer until the 2nd frame period). ... what if i have 100 input data and the buffer ... Zeros to the following frame?? ...
    (comp.soft-sys.matlab)