hi,all,
Firstly, my new nandflash driver seems working well, and I could access nand
in device explorer by common file operation method. In one of my app,I need
access nandflash by DeviceIoControl. But when I sent IOCTL_DISK_READ to nand
store handle,it always complained invalid parameter. While i sent the same
parameters to SD or my old flash driver, it could work correctly.

MS said they provided flashmdd.dll, flashpart.dll to manage flash device, and
there is no source code for traceing. I am confused deeply.

#define USESTORE 1

int _tmain(int argc, TCHAR *argv[], TCHAR *envp[])
{
DWORD dwError;
BOOL fResult;
DWORD dwBytesReturned;

//open store of nandflash
_tcscpy(g_szDeviceName,_T("DSK1:")); //-->DSK1: for nand, DSK2 for SD

#if USESTORE
g_hStore = OpenStore(g_szDeviceName);
#else
g_hStore = CreateFile(g_szDeviceName, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,OPEN_EXISTING, 0,NULL);
#endif

if ((g_hStore == NULL) || (g_hStore == INVALID_HANDLE_VALUE)) {
dwError = GetLastError();
RETAILMSG(1, (_T(
"Failed to open store %s; error = %u\r\n"
), g_szDeviceName, dwError));
goto EXIT;
}
RETAILMSG(1, (_T("Opened store %s\r\n"), g_szDeviceName));

//read disk info

RETAILMSG(1,(_T("IOCTL_DISK_GETINFO =0x%X\r\n"),IOCTL_DISK_GETINFO));
// read disk information
fResult = DeviceIoControl(
g_hStore,
IOCTL_DISK_GETINFO,
NULL,
0,
&g_diDiskInfo,
sizeof(g_diDiskInfo),
&dwBytesReturned,
NULL);
if (!fResult) {
RETAILMSG(1,(_T("IOCTL_DISK_GETINFO Failed,GetLastError:0x%X\r\n"),
GetLastError()));
goto EXIT;
}
RETAILMSG(1, (_T("Get disk Info success %s\r\n"), g_szDeviceName));
DUMP_DISKINFO(g_diDiskInfo);


//read sector

PBYTE pBuffer = (PBYTE)LocalAlloc(LPTR, g_diDiskInfo.di_bytes_per_sect);
if (pBuffer != NULL)
{
DWORD adwPFNs[512];
memset(adwPFNs, 0, sizeof(adwPFNs));
BOOL bLockRes = LockPages(pBuffer, g_diDiskInfo.di_bytes_per_sect,
adwPFNs, LOCKFLAG_WRITE);
if (bLockRes)
{
bLockRes = UnlockPages(pBuffer, g_diDiskInfo.di_bytes_per_sect);
}
SG_REQ sgReq;
DWORD dwBytesReturned;
sgReq.sr_start = 1;
sgReq.sr_num_sec = 1;
sgReq.sr_num_sg = 1;
sgReq.sr_status = 0;
sgReq.sr_callback = NULL;
sgReq.sr_sglist[0].sb_buf = pBuffer;
sgReq.sr_sglist[0].sb_len = g_diDiskInfo.di_bytes_per_sect;

BOOL bResult = DeviceIoControl(g_hStore, IOCTL_DISK_READ, &sgReq,
sizeof(SG_REQ), NULL, 0, &dwBytesReturned,
NULL);
if (!bResult)
{
RETAILMSG(1,(_T("IOCTL_DISK_READ Failed:0x%X\r\n"),GetLastError()));
goto EXIT;
}
RETAILMSG(1,(_T("IOCTL_DISK_READ success...\r\n")));
}

EXIT:
if (pBuffer!=NULL)
{
LocalFree(pBuffer);
}
#if USESTORE
#else
CloseHandle(g_hStore);
#endif

return 0;
}


****************************
Debug info:

Opened store DSK1:

IOCTL_DISK_GETINFO =0x71C00

Get disk Info success DSK1:

DSK1: bytes per sector = 2048

DSK1: cylinders = 884

DSK1: flags = 0x8

DSK1: heads = 1

DSK1: sectors = 128

DSK1: total sectors = 113152

!!DecodeAPI: invalid handle! (h = 0297000a, iApiSet = 00000002 'NONE',
pActvProc
->dwId = 0297000a)

ObjectCall: returning 8037cce4

IOCTL_DISK_READ Failed:0x57

************************************
The IOCTL_DISK_GETINFO operation had passed correctly.

Is there any hint? any help will be appreciated!