📄 ondisk.c
字号:
{
if (nDstOffset == 0)
{
nSizeOfSGBuf = pSg->sb_len;
pSGBuf = MapPtrToProcess((LPVOID)pSg->sb_buf, GetCallerProcess());
}
if (nSizeOfSGBuf <= nCpBytes)
{
memcpy((UCHAR*)(pSecBuf + nSrcOffset), (UCHAR*)(pSGBuf + nDstOffset), nSizeOfSGBuf);
nSrcOffset += nSizeOfSGBuf;
nDstOffset = 0;
nCpBytes -= nSizeOfSGBuf;
pSg++;
}
else
{
memcpy((UCHAR*)(pSecBuf + nSrcOffset), (UCHAR*)(pSGBuf + nDstOffset), nCpBytes);
nDstOffset += nCpBytes;
nSizeOfSGBuf -= nCpBytes;
nCpBytes = 0;
}
}
// RETAILMSG(1, (TEXT("FTL_Write3 : nStartSecNo = 0x%x, nNumOfSects = 0x%x \r\n"), nStartSecNo, nNumOfScts));
nRet = FTL_Write((nStartSecNo << OND_SECTOR_SHIFT), /* Start Logical Sector Number */
(nNumOfScts << OND_SECTOR_SHIFT), /* Number of Sectors */
pSecBuf); /* Pointer ot buffer */
if (nRet != FTL_SUCCESS)
{
STDRV_ERR_PRINT((TEXT("[OND:ERR](DoDiskWrite) FTL_Write Error=0x%x\r\n"), nRet));
free(pSecBuf);
status = ERROR_SECTOR_NOT_FOUND;
goto ddi_req_done;
}
nStartSecNo += nNumOfScts;
if (nSGBufLen < ((WMR_SECTOR_SIZE << OND_SECTOR_SHIFT) * nNumOfScts))
{
free(pSecBuf);
break;
}
else
{
nSGBufLen -= ((WMR_SECTOR_SIZE << OND_SECTOR_SHIFT) * nNumOfScts);
}
free(pSecBuf);
}
}
ddi_req_done:
ddi_exit:
pSgr->sr_status = status;
LeaveCriticalSection(&(pDisk->d_DiskCardCrit));
STDRV_LOG_PRINT((TEXT("[OND: IN] --DoDiskWrite()\r\n")));
return status;
}
/*****************************************************************************/
/* */
/* NAME */
/* DoDiskDeleteSectors */
/* DESCRIPTION */
/* Do delete operation from NAND flash memory */
/* PARAMETERS */
/* pDisk PocketStoreII driver own structure pointer */
/* pData PSQ_REQ structure pointer,it contains request information*/
/* for delete operations */
/* RETURN VALUES */
/* If it successes, it returns TRUE. otherwize it returns FALSE */
/* */
/*****************************************************************************/
static DWORD
DoDiskDeleteSectors(PDISK pDisk,
PVOID pData)
{
DWORD status = ERROR_SUCCESS;
UINT iStartSector, iNumSectors;
DELETE_SECTOR_INFO *pSecInfo;
INT32 nRet;
STDRV_LOG_PRINT((TEXT("[OND:LOG] ++DoDiskDeleteSectors()\r\n")));
EnterCriticalSection(&(pDisk->d_DiskCardCrit));
pSecInfo = (DELETE_SECTOR_INFO *) pData;
iStartSector = pSecInfo->startsector;
iNumSectors = pSecInfo->numsectors;
if (pDisk->bIsFTLOpen == FALSE)
{
status = ERROR_INVALID_PARAMETER;
goto ddi_exit;
}
/* Bound Check for StartSector */
if (iStartSector > pDisk->d_DiskInfo.di_total_sectors ||
iStartSector < 0)
{
STDRV_ERR_PRINT((TEXT("[OND:SECT DEL ERR] at iStartSector %5d\r\n"), iStartSector));
status = ERROR_SECTOR_NOT_FOUND;
goto ddi_exit;
}
/* Bound Check for FinalSector */
if ((iStartSector + iNumSectors) > pDisk->d_DiskInfo.di_total_sectors ||
(iStartSector + iNumSectors) < 0)
{
STDRV_ERR_PRINT((TEXT("[OND:SECT DEL ERR] at iEndSector %5d\r\n"), iStartSector + iNumSectors - 1));
status = ERROR_SECTOR_NOT_FOUND;
goto ddi_exit;
}
STDRV_INF_PRINT((TEXT("[OND:INF] >>DoDiskDeleteSectors<< at sector[%5d ~ %5d]\r\n"),
iStartSector, iStartSector + iNumSectors - 1));
STDRV_INF_PRINT((TEXT("[OND:INF] &DD:SEC:%08d,SN:%04d\r\n"),iStartSector, iNumSectors));
status = ERROR_SUCCESS;
#if STL_DELETE_DBG
nRet = STL_Delete(pDisk->nVol,
pDisk->nBmlPartitionId,
(iStartSector << OND_SECTOR_SHIFT),
(iNumSectors << OND_SECTOR_SHIFT));
#else
STDRV_INF_PRINT((TEXT("[OND:INF] Call STL_Delete func. Return FTL_SUCCESS forcefully for debugging.\r\n")));
nRet = FTL_SUCCESS;
#endif
if (nRet != FTL_SUCCESS)
{
STDRV_ERR_PRINT((TEXT("[OND:SEC DEL ERR] at sector %5d to \r\n"), iStartSector, iNumSectors));
status = ERROR_SECTOR_NOT_FOUND;
}
ddi_exit:
LeaveCriticalSection(&(pDisk->d_DiskCardCrit));
STDRV_LOG_PRINT((TEXT("[OND:LOG] --DoDiskDeleteSectors()\r\n")));
return status;
}
/*****************************************************************************/
/* */
/* NAME */
/* GetDiskInfo */
/* DESCRIPTION */
/* Get disk information from pDisk structure */
/* PARAMETERS */
/* pDisk PocketStoreII driver own structure pointer */
/* pInfo DISK Information structure pointer */
/* RETURN VALUES */
/* it always returns ERROR_SUCCESS */
/* */
/*****************************************************************************/
static DWORD
GetDiskInfo(PDISK pDisk,
PDISK_INFO pInfo)
{
STDRV_LOG_PRINT((TEXT("[OND: IN] ++GetDiskInfo()\r\n")));
EnterCriticalSection(&(pDisk->d_DiskCardCrit));
*pInfo = pDisk->d_DiskInfo;
LeaveCriticalSection(&(pDisk->d_DiskCardCrit));
STDRV_LOG_PRINT((TEXT("[OND: IN] --GetDiskInfo()\r\n")));
return ERROR_SUCCESS;
}
/*****************************************************************************/
/* */
/* NAME */
/* SetDiskInfo */
/* DESCRIPTION */
/* Set disk information to pDisk structure */
/* PARAMETERS */
/* pDisk PocketStoreII driver own structure pointer */
/* pInfo DISK Information structure pointer */
/* RETURN VALUES */
/* it always returns ERROR_SUCCESS */
/* */
/*****************************************************************************/
static DWORD
SetDiskInfo(PDISK pDisk,
PDISK_INFO pInfo)
{
STDRV_LOG_PRINT((TEXT("[OND: IN] ++SetDiskInfo()\r\n")));
pDisk->d_DiskInfo = *pInfo;
STDRV_LOG_PRINT((TEXT("[OND:OUT] --SetDiskInfo()\r\n")));
return ERROR_SUCCESS;
}
/*****************************************************************************/
/* */
/* NAME */
/* CreateDiskObject */
/* DESCRIPTION */
/* Create a DISK structure, init some fields and link it. */
/* PARAMETERS */
/* none */
/* RETURN VALUES */
/* new DISK structure pointer */
/* */
/*****************************************************************************/
static PDISK
CreateDiskObject(VOID)
{
PDISK pDisk;
STDRV_LOG_PRINT((TEXT("[OND: IN] ++CreateDiskObject()\r\n")));
pDisk = LocalAlloc(LPTR, sizeof(DISK));
if (pDisk != NULL)
{
/* Disk Handle data init */
pDisk->hDevice = NULL;
pDisk->d_OpenCount = 0;
pDisk->d_ActivePath = NULL;
pDisk->DoThreading = TRUE;
pDisk->SecPerCluster = 0;
pDisk->FirstDataSector = 0;
pDisk->bIsFTLOpen = FALSE;
/* Initialize Critical Section handle for each disk handle */
InitializeCriticalSection(&(pDisk->d_DiskCardCrit));
pDisk->pd_next = v_DiskList;
v_DiskList = pDisk;
}
STDRV_LOG_PRINT((TEXT("[OND: ] --CreateDiskObject()\r\n")));
return pDisk;
}
/*****************************************************************************/
/* */
/* NAME */
/* IsValidDisk */
/* DESCRIPTION */
/* This function checks Disk validation */
/* IsValidDisk - verify that pDisk points to something in our list */
/* PARAMETERS */
/* pDisk */
/* Pointer to disk handle */
/* RETURN VALUES */
/* Return TRUE if pDisk is valid, FALSE if not. */
/* */
/*****************************************************************************/
static BOOL
IsValidDisk(PDISK pDisk)
{
PDISK pd;
BOOL bRet = FALSE;
STDRV_LOG_PRINT((TEXT("[OND: IN] ++IsValidDisk()\r\n")));
pd = v_DiskList;
while (pd)
{
if (pd == pDisk)
{
bRet = TRUE;
break;
}
pd = pd->pd_next;
}
STDRV_LOG_PRINT((TEXT("[OND:OUT] --IsValidDisk()\r\n")));
return bRet;
} // IsValidDisk
//#define _SUPPORT_HAL_WRAPPER_
/*****************************************************************************/
/* */
/* NAME */
/* InitializeNAND */
/* DESCRIPTION */
/* This function initializes NAND Disk Handle */
/* PARAMETERS */
/* pDisk */
/* Disk handle */
/* RETURN VALUES */
/* Return TRUE if pDisk is valid, FALSE if not. */
/* NOTE */
/* call from InitDisk from DSK_Init */
/* */
/*****************************************************************************/
static BOOL
InitializeNAND(PDISK pDisk)
{
#if defined(_SUPPORT_HAL_WRAPPER_)
VFLPacket stPacket;
INT nResult;
#endif
BOOL bRet = FALSE;
STDRV_LOG_PRINT((TEXT("[OND: IN] ++InitializeNAND()\r\n")));
#if defined(_SUPPORT_HAL_WRAPPER_)
do {
STDRV_LOG_PRINT((TEXT("[OND: IN] _SUPPORT_HAL_WRAPPER_\r\n")));
/* VFL Init */
stPacket.nCtrlCode = PM_HAL_VFL_INIT;
KernelIoControl(IOCTL_POCKETSTOREII_CMD, /* Io Control Code */
&stPacket, /* Input buffer (Additional Control Code) */
sizeof(stPacket), /* Size of Input buffer */
NULL, /* Output buffer */
0, /* Size of Output buffer */
&nResult); /* Error Return */
if (nResult != VFL_SUCCESS)
{
STDRV_ERR_PRINT((TEXT("[OND:ERR] VFL_Init() failure. ERR Code=%x\r\n"), nResult));
break;
}
/* WFL Open */
stPacket.nCtrlCode = PM_HAL_VFL_OPEN;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -