?? system.c
字號:
static UINT nAccessCnt = 0;
BIBDRV_LOG_PRINT((TEXT("[BIBDRV: IN] ++DoDiskRead()\r\n")));
/*
typedef struct _SG_REQ {
DWORD sr_start; // starting sector number
DWORD sr_num_sec; // number of sectors
DWORD sr_num_sg; // number of scatter/gather buffers
DWORD sr_status; // request status
PFN_REQDONE sr_callback; // request completion callback function
SG_BUF sr_sglist[1]; // first scatter/gather buffer
} SG_REQ, * PSG_REQ;
*/
pSgr = (PSG_REQ) pData;
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] ========= DoDiskRead Request Info ========= \r\n")));
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] \tpSgr->sr_start = %d(0x%x)\r\n"), pSgr->sr_start, pSgr->sr_start));
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] \tpSgr->sr_num_sec = %d\r\n"), pSgr->sr_num_sec));
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] \tpSgr->sr_num_sg = %d\r\n"), pSgr->sr_num_sg));
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] \tlast sector num = %d\r\n"), pSgr->sr_start + pSgr->sr_num_sec - 1));
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] \tpSgr->sr_status = 0x%x\r\n"), pSgr->sr_status));
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] =========================================== \r\n")));
/* BML Open Check */
if (pDisk->bIsBMLOpen == FALSE)
{
BIBDRV_ERR_PRINT((TEXT("[BIBDRV:ERR] pDisk BML Open Check Fail\r\n")));
status = ERROR_INVALID_PARAMETER;
goto ddi_exit;
}
/* Scatter/Gather buffer Bound Check */
if (pSgr->sr_num_sg > MAX_SG_BUF)
{
BIBDRV_ERR_PRINT((TEXT("[BIBDRV:ERR] Scatter/Gather buffer Bound Check Fail (Too many buffers)\r\n")));
status = ERROR_INVALID_PARAMETER;
goto ddi_exit;
}
pSgr->sr_status = ERROR_IO_PENDING;
/*----------------------------------------------*/
// Make sure request doesn't exceed the disk */
/*----------------------------------------------*/
if ((pSgr->sr_start + pSgr->sr_num_sec - 1) > pDisk->d_DiskInfo.di_total_sectors)
{
status = ERROR_SECTOR_NOT_FOUND;
BIBDRV_ERR_PRINT((TEXT("[BIBDRV:ERR] Request Sector OOB Check Fail(sector exceeded)\r\n")));
BIBDRV_ERR_PRINT((TEXT("[BIBDRV:ERR] - Disk Totol Sectors = %d\r\n"), pDisk->d_DiskInfo.di_total_sectors));
BIBDRV_ERR_PRINT((TEXT("[BIBDRV:ERR] - Requested pSgr->sr_start = %d\r\n"), pSgr->sr_start));
BIBDRV_ERR_PRINT((TEXT("[BIBDRV:ERR] - Requested pSgr->sr_num_sec= %d\r\n"), pSgr->sr_num_sec));
BIBDRV_ERR_PRINT((TEXT("[BIBDRV:ERR] - Requested last sector num = %d\r\n"), pSgr->sr_start + pSgr->sr_num_sec - 1));
goto ddi_exit;
}
status = ERROR_SUCCESS;
num_sg = pSgr->sr_num_sg;
pSg = &(pSgr->sr_sglist[0]);
bytes_this_sg = pSg->sb_len;
pBuf = MapPtrToProcess((LPVOID)pSg->sb_buf, GetCallerProcess());
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] ----------------------------------- \r\n")));
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] \tnum_sg = %d\r\n"), num_sg));
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] \tpSg = 0x%08x\r\n"), pSg));
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] \tbytes_this_sg = %d\r\n"), bytes_this_sg));
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] \tpSg->sb_buf = 0x%08x\r\n"), pSg->sb_buf));
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] \tpBuf = 0x%08x\r\n"), pBuf));
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] ----------------------------------- \r\n")));
EnterCriticalSection(&(pDisk->d_DiskCardCrit));
/*--------------------------*/
/* Read sectors from disk. */
/*--------------------------*/
while (num_sg)
{
nSecCount = ((bytes_this_sg - 1) / pDisk->d_DiskInfo.di_bytes_per_sect) + 1;
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] DoDiskRead StartSector=%d, nNumOfScts=%d, nAccessCnt=%d\r\n"),
pSgr->sr_start, nSecCount, nAccessCnt++));
#if defined(_READ_PERFORMANCE_MEASUREMENT_)
WatchTimerStart();
#endif //(_READ_PERFORMANCE_MEASUREMENT_)
for (nSecIdx = 0; nSecIdx < nSecCount; nSecIdx ++)
{
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] DoDiskRead %d bytes at sector %d\r\n"),
bytes_this_sg, pSgr->sr_start + nSecIdx));
/*----------------------*/
/* Sector(512byte) Read */
/*----------------------*/
nRes = RequestReadSecToHAL(pDisk, (UINT)pSgr->sr_start + nSecIdx, pBuf);
if (nRes != TRUE)
{
BIBDRV_ERR_PRINT((TEXT("[BIBDRV:ERR][DoDiskRead] %5d bytes at sector %5d, num_sg = %d\r\n"),
bytes_this_sg, pSgr->sr_start, num_sg));
status = ERROR_SECTOR_NOT_FOUND;
goto ddi_req_done;
}
pBuf += pDisk->d_DiskInfo.di_bytes_per_sect;
}
#if defined(_READ_PERFORMANCE_MEASUREMENT_)
WatchTimerStop();
#endif //(_READ_PERFORMANCE_MEASUREMENT_)
//
// Use the next scatter/gather buffer
//
num_sg --;
if (num_sg == 0)
{
break;
}
pSg ++;
pBuf = MapPtrToProcess((LPVOID)pSg->sb_buf, GetCallerProcess());
bytes_this_sg = pSg->sb_len;
} // while sg
ddi_req_done:
LeaveCriticalSection(&(pDisk->d_DiskCardCrit));
ddi_exit:
pSgr->sr_status = status;
BIBDRV_LOG_PRINT((TEXT("[BIBDRV:OUT] --DoDiskRead()\r\n")));
return status;
}
#if defined(_BIBDRV_CACHING_SECTORS_)
/*****************************************************************************/
/* */
/* NAME */
/* DoDiskReadWithCaching */
/* DESCRIPTION */
/* Do read operation from NAND flash memory */
/* PARAMETERS */
/* pDisk BIBDRV_PS driver own structure pointer */
/* pData PSQ_REQ structure pointer,it contains request information*/
/* for read operations */
/* RETURN VALUES */
/* If it successes, it returns TRUE. otherwize it returns FALSE */
/* */
/*****************************************************************************/
static DWORD
DoDiskReadWithCaching(PDISK pDisk,
PVOID pData)
{
DWORD status = ERROR_SUCCESS;
DWORD num_sg;
DWORD bytes_this_sg;
PSG_REQ pSgr;
PSG_BUF pSg;
PUCHAR pBuf;
BOOL nRes;
UINT nSecCount, nSecIdx;
static UINT nAccessCnt = 0;
/* BML Open Check */
if (pDisk->bIsFDMOpen == FALSE)
{
status = ERROR_INVALID_PARAMETER;
goto ddi_exit;
}
/* Scatter/Gather buffer Bound Check */
pSgr = (PSG_REQ)pData;
if (pSgr->sr_num_sg > MAX_SG_BUF)
{
status = ERROR_INVALID_PARAMETER;
goto ddi_exit;
}
pSgr->sr_status = ERROR_IO_PENDING;
//
// Make sure request doesn't exceed the disk
//
if ((pSgr->sr_start + pSgr->sr_num_sec - 1) > pDisk->d_DiskInfo.di_total_sectors)
{
status = ERROR_SECTOR_NOT_FOUND;
BIBDRV_ERR_PRINT((TEXT("[DoDiskRead] not found at sector = %d sec_num = %d\r\n"),
pSgr->sr_start, pSgr->sr_num_sec));
BIBDRV_ERR_PRINT((TEXT("[DoDiskRead] di_total_sectors = %d\r\n"), pDisk->d_DiskInfo.di_total_sectors));
goto ddi_exit;
}
status = ERROR_SUCCESS;
num_sg = pSgr->sr_num_sg;
pSg = &(pSgr->sr_sglist[0]);
bytes_this_sg = pSg->sb_len;
pBuf = MapPtrToProcess((LPVOID)pSg->sb_buf, GetCallerProcess());
BIBDRV_INF_PRINT((TEXT("[DoDiskRead] %5d bytes at sector %5d, num_sg = %d\r\n"),
bytes_this_sg, pSgr->sr_start, num_sg));
EnterCriticalSection(&(pDisk->d_DiskCardCrit));
//
// Read sectors from disk.
//
while (num_sg)
{
nSecCount = ((bytes_this_sg - 1) / pDisk->d_DiskInfo.di_bytes_per_sect) + 1;
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] Read StartSector=%d, nNumOfScts=%d, nAccessCnt=%d\r\n"),
pSgr->sr_start, nSecCount, nAccessCnt++));
#if defined(_READ_PERFORMANCE_MEASUREMENT_)
WatchTimerStart();
#endif //(_READ_PERFORMANCE_MEASUREMENT_)
for (nSecIdx = 0; nSecIdx < nSecCount; nSecIdx ++)
{
BIBDRV_INF_PRINT((TEXT("[BIBDRV:INF] DoDiskRead %d bytes at sector %d\r\n"),
bytes_this_sg, pSgr->sr_start + nSecIdx));
/*----------------------*/
/* Sector(512byte) Read */
/*----------------------*/
nRes = RequestReadSecToHALwithCaching(pDisk, (UINT) pSgr->sr_start + nSecIdx, pBuf);
if (nRes != TRUE)
{
BIBDRV_ERR_PRINT((TEXT("[BIBDRV:ERR][DoDiskReadWithCaching] %5d bytes at sector %5d, num_sg = %d\r\n"),
bytes_this_sg, pSgr->sr_start, num_sg));
status = ERROR_SECTOR_NOT_FOUND;
goto ddi_req_done;
}
pBuf += pDisk->d_DiskInfo.di_bytes_per_sect;
}
#if defined(_READ_PERFORMANCE_MEASUREMENT_)
WatchTimerStop();
#endif //(_READ_PERFORMANCE_MEASUREMENT_)
//
// Use the next scatter/gather buffer
//
num_sg --;
if (num_sg == 0)
{
break;
}
pSg ++;
pBuf = MapPtrToProcess((LPVOID)pSg->sb_buf, GetCallerProcess());
bytes_this_sg = pSg->sb_len;
} // while sg
ddi_req_done:
LeaveCriticalSection(&(pDisk->d_DiskCardCrit));
ddi_exit:
pSgr->sr_status = status;
return status;
}
#endif //(_BIBDRV_CACHING_SECTORS_)
/*****************************************************************************/
/* */
/* NAME */
/* GetDiskInfo */
/* DESCRIPTION */
/* Get disk information from pDisk structure */
/* PARAMETERS */
/* pDisk BIBDRV_PS driver own structure pointer */
/* pInfo DISK Information structure pointer */
/* RETURN VALUES */
/* it always returns ERROR_SUCCESS */
/* */
/*****************************************************************************/
static DWORD
GetDiskInfo(PDISK pDisk,
PDISK_INFO pInfo)
{
BIBDRV_LOG_PRINT((TEXT("[BIBDRV: IN] ++GetDiskInfo()\r\n")));
memcpy(pInfo, &(pDisk->d_DiskInfo), sizeof(DISK_INFO));
pInfo->di_flags &= ~DISK_INFO_FLAG_UNFORMATTED;
BIBDRV_INF_PRINT((TEXT("[NFALT:INF] \tpInfo->di_total_sectors =%d\r\n"), pInfo->di_total_sectors));
BIBDRV_INF_PRINT((TEXT("[NFALT:INF] \tpInfo->di_bytes_per_sect =%d\r\n"), pInfo->di_bytes_per_sect));
BIBDRV_INF_PRINT((TEXT("[NFALT:INF] \tpInfo->di_cylinders =%d\r\n"), pInfo->di_cylinders));
BIBDRV_INF_PRINT((TEXT("[NFALT:INF] \tpInfo->di_heads =%d\r\n"), pInfo->di_heads));
BIBDRV_INF_PRINT((TEXT("[NFALT:INF] \tpInfo->di_sectors =%d\r\n"), pInfo->di_sectors));
BIBDRV_INF_PRINT((TEXT("[NFALT:INF] \tpInfo->di_flags =%X\r\n"), pInfo->di_flags));
/*
The device supports demand paging.
Read and write requests are synchronous and do not involve
memory manager calls, loader operations, or thread switches.
pInfo->di_flags |= DISK_INFO_FLAG_PAGEABLE;
*/
/*
The device does not support CHS addressing;
values for di_cylinders, di_heads, and di_sectors may be simulations,
estimations, or not provided.
pInfo->di_flags |= DISK_INFO_FLAG_CHS_UNCERTAIN;
*/
/*
The device requires a low-level format with the IOCTL_DISK_FORMAT_MEDIA.
The FAT file system currently ignores this flag.
*/
BIBDRV_LOG_PRINT((TEXT("[BIBDRV:OUT] --GetDiskInfo()\r\n")));
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -