IOCTL_DISK_READ



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

  • gz compression rates with custom buffer callback
    ... what I want to do is a classic output-buffer callback function that gzencodethe buffer. ... There's a native function for that, I know, but I want a little more: compression stats. ... The flag is set, so I can now send the HTTP header to tell the browser we're gonna send some encoded stuff, and then actually encode it. ...
    (comp.lang.php)
  • Re: callback function immediatly called with an empty buffer
    ... > I try to record a wavefile with wavein API. ... > Waveinprepareheader and waveinAddbuffer work fine, with a waveheader ... > buffer large to hold a few seconds audio. ... > Strangely, just after waveinstart, the callback function is executed, ...
    (microsoft.public.win32.programmer.mmedia)
  • Re: sending HTTP requests... newbie (continued)
    ... places, find the missing .dll files, rediscovering that a lot of file are missing from the different versions of the download libraries, ... constant and the pointer to your callback function. ... typedef struct CurlBuffer ... CurlBuffer buffer; ...
    (comp.programming)
  • Re: ISampleGrabber
    ... I setup the address to my callback function in SamplGrabber filter.. ... But when it runs I see blank black image (the zero content of the Sample ... I'm not sure how you are determining that the buffer is full of ...
    (microsoft.public.win32.programmer.directx.video)
  • Question about SetupDiGetClassDevs and SetupDiEnumDeviceInterfaces
    ... SetupDiEnumDeviceInfo(hDevInfo, j, &DeviceInfoData) ... but now I want to enumerate all the DEVICE INTERFACE CLASS that a single ... LPTSTR buffer = NULL; ... ULONG le = GetLastError; ...
    (microsoft.public.development.device.drivers)

Loading