⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ondisk.c

📁 s3c2450 bsp for wince 5.0 PM_REL_0.04_080519 经验证,完全没问题
💻 C
📖 第 1 页 / 共 5 页
字号:
		NULL,
		&ValType,
		(LPBYTE) &(pDisk->nBmlPartitionId),
		&nBytes);

    if ((ERROR_SUCCESS != status) || (0 == nBytes))
    {
        STDRV_ERR_PRINT((TEXT("[OND:ERR]  GetBmlId - RegQueryValueEx() returned %d, nBytes=%d\r\n"),
			status, nBytes));
    }
    else
    {
        STDRV_RTL_PRINT((TEXT("[OND:MSG]  GetBmlId - BmlPartitionId = %d\r\n"),
			pDisk->nBmlPartitionId));
    }

#if ONDISK_MULTIPARTITION
	// Get WMRStartSector from Builtin key
	status = RegQueryValueEx(DriverKey,
		TEXT("WMRStartSector"),
		NULL,
		&ValType,
		(LPBYTE) &(pDisk->nWMRStartSector),
		&nBytes);

	if ((ERROR_SUCCESS != status) || (0 == nBytes))
	{
        STDRV_ERR_PRINT((TEXT("[OND:ERR]  GetBmlId - RegQueryValueEx() returned %d, nBytes=%d\r\n"),
			status, nBytes));
	}
	else
	{
        STDRV_RTL_PRINT((TEXT("[OND:MSG]  GetBmlId - StartSector = %d\r\n"),
			pDisk->nWMRStartSector));
	}

	// Get WMRStartSector from Builtin key
	status = RegQueryValueEx(DriverKey,
		TEXT("WMRNumOfSector"),
		NULL,
		&ValType,
		(LPBYTE) &(pDisk->nWMRNumOfSector),
		&nBytes);

	if ((ERROR_SUCCESS != status) || (0 == nBytes))
	{
        STDRV_ERR_PRINT((TEXT("[OND:ERR]  GetBmlId - RegQueryValueEx() returned %d, nBytes=%d\r\n"),
			status, nBytes));
	}
	else
	{
        STDRV_RTL_PRINT((TEXT("[OND:MSG]  GetBmlId - NumOfSector = %u\r\n"),
			(UINT32)(pDisk->nWMRNumOfSector)));
	}
#endif

	// Get BmlVolumeId from Builtin Key
	status = RegQueryValueEx(DriverKey,
		TEXT("BmlVolumeId"),
		NULL,
		&ValType,
		(LPBYTE) &(pDisk->nVol),
		&nBytes);

    if ((ERROR_SUCCESS != status) || (0 == nBytes))
    {
        STDRV_ERR_PRINT((TEXT("[OND:ERR]  GetBmlId - RegQueryValueEx() returned %d, nBytes=%d\r\n"),
			status, nBytes));
    }
    else
    {
        STDRV_RTL_PRINT((TEXT("[OND:MSG]  GetBmlId - BmlVolumeId = %d\r\n"),
			pDisk->nVol));
    }

    status = RegCloseKey(DriverKey);

    if (ERROR_SUCCESS != status)
    {
    	STDRV_ERR_PRINT((TEXT("[OND:ERR]  GetBmlId - RegCloseKey() returned %d\r\n"),
			status));
        return FALSE;
    }

    LeaveCriticalSection(&(pDisk->d_DiskCardCrit));

    return TRUE;
}


static BOOL
GetDeviceInfo(PDISK                 pDisk,
              PSTORAGEDEVICEINFO    psdi)
{
    HKEY  DriverKey;
    DWORD ValType;
    DWORD status;
    DWORD dwSize;
	DWORD dwPartType=0;

    STDRV_RTL_PRINT((TEXT("[OND:OUT] ++GetDeviceInfo()\r\n")));

    EnterCriticalSection(&(pDisk->d_DiskCardCrit));

    DriverKey = OpenDriverKey(pDisk->d_ActivePath);
    if (DriverKey)
    {
        dwSize = sizeof(psdi->szProfile);
        status = RegQueryValueEx(DriverKey,
			TEXT("Profile"),
			NULL,
			&ValType,
			(LPBYTE)psdi->szProfile,
			&dwSize);

        if ((status != ERROR_SUCCESS) || (dwSize > sizeof(psdi->szProfile)))
        {
            STDRV_LOG_PRINT((TEXT("[OND:   ] GetFolderName - RegQueryValueEx(Profile) returned %d\r\n"),
				status));
            STDRV_RTL_PRINT((TEXT("[OND:   ] GetFolderName - RegQueryValueEx(Profile) returned %d\r\n"),
				status));
            wcscpy( psdi->szProfile, L"Default");
        }
        else
        {
            STDRV_LOG_PRINT((TEXT("[OND:   ] GetProfileName - Profile = %s, length = %d\r\n"),
				psdi->szProfile, dwSize));
            STDRV_RTL_PRINT((TEXT("[OND:   ] GetProfileName - Profile = %s, length = %d\r\n"),
				psdi->szProfile, dwSize));
        }
        dwSize=sizeof(DWORD);
        status = RegQueryValueEx(DriverKey,
			TEXT("Order"),
			NULL,
			&ValType,
			(LPBYTE)dwPartType,
			&dwSize);

        if (status == ERROR_SUCCESS)
        {
            STDRV_LOG_PRINT((TEXT("[OND:   ] Order = %d, length = %d\r\n"),
				dwPartType, dwSize));
            STDRV_RTL_PRINT((TEXT("[OND:   ] Order = %d, length = %d\r\n"),
				dwPartType, dwSize));
        }

        RegCloseKey(DriverKey);
    }

    psdi->cbSize        = sizeof(STORAGEDEVICEINFO);
    psdi->dwDeviceClass = STORAGE_DEVICE_CLASS_BLOCK;
    psdi->dwDeviceType  = STORAGE_DEVICE_TYPE_FLASH;
    psdi->dwDeviceFlags = STORAGE_DEVICE_FLAG_READWRITE;

    LeaveCriticalSection(&(pDisk->d_DiskCardCrit));

    STDRV_RTL_PRINT((TEXT("[OND:OUT] --GetDeviceInfo()\r\n")));

    return TRUE;
}


/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*      GetStorageID                                                         */
/* DESCRIPTION                                                               */
/*      free all resources associated with the specified disk                */
/* PARAMETERS                                                                */
/*      pDisk       NFLAT_PS driver own structure pointer                    */
/* RETURN VALUES                                                             */
/*      none                                                                 */
/*                                                                           */
/*****************************************************************************/
static BOOL
GetStorageID(PDISK                      pDisk,
             PSTORAGE_IDENTIFICATION    psid,
             DWORD                      cBytes,
             DWORD                     *pcBytes)
{
    STDRV_RTL_PRINT((TEXT("[OND:MSG] ++GetStorageID \r\n")));

    if (cBytes < sizeof(*psid))
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }
    else
    {
        // initialize the error status in case there are no errors
        SetLastError(ERROR_SUCCESS);
    }

    __try
    {
        psid->dwSize                = sizeof(*psid);
        psid->dwFlags               = 0;  // can be or of {MANUFACTUREID,SERIALNUM}_INVALID
        psid->dwManufactureIDOffset = psid->dwSerialNumOffset = 0;
    }
    __except (EXCEPTION_EXECUTE_HANDLER)
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }

    STDRV_RTL_PRINT((TEXT("[OND:MSG] --GetStorageID \r\n")));

    return TRUE;
}


/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*      CloseDisk                                                            */
/* DESCRIPTION                                                               */
/*      free all resources associated with the specified disk                */
/* PARAMETERS                                                                */
/*      pDisk       PocketStoreII driver own structure pointer               */
/* RETURN VALUES                                                             */
/*      none                                                                 */
/*                                                                           */
/*****************************************************************************/
static VOID
CloseDisk(PDISK pDisk)
{
    PDISK pd;

    STDRV_LOG_PRINT((TEXT("[OND: IN]  +CloseDisk(pDisk=0x%x)\r\n"), pDisk));

    EnterCriticalSection(&(pDisk->d_DiskCardCrit));

    /*-----------------------------------------*/
    /* Remove it from the global list of disks */
    /*-----------------------------------------*/
    if (pDisk == v_DiskList)
    {
        v_DiskList = pDisk->pd_next;
    }
    else
    {
        pd = v_DiskList;
        while (pd->pd_next != NULL)
        {
            if (pd->pd_next == pDisk)
            {
                pd->pd_next = pDisk->pd_next;
                break;
            }
            pd = pd->pd_next;
        }
    }

    //
    // Try to ensure this is the only thread holding the disk crit sec
    //
    Sleep(50);
    EnterCriticalSection (&(pDisk->d_DiskCardCrit));
    LeaveCriticalSection (&(pDisk->d_DiskCardCrit));
    DeleteCriticalSection(&(pDisk->d_DiskCardCrit));

    /* Dealloc pDisk handle */
    LocalFree(pDisk);
    LeaveCriticalSection(&(pDisk->d_DiskCardCrit));

    STDRV_LOG_PRINT((TEXT("[OND:OUT] --CloseDisk()\r\n")));
}


/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*      DoDiskRead                                                           */
/* DESCRIPTION                                                               */
/*      Do read operation from NAND flash memory                             */
/* PARAMETERS                                                                */
/*      pDisk       PocketStoreII 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
DoDiskRead(PDISK pDisk,
           PVOID pData)
{
    DWORD   status = ERROR_SUCCESS;
    DWORD   nSizeOfSGBuf;
    PSG_REQ pSgr;
    PSG_BUF pSg;
    PUCHAR  pSGBuf;
    UINT    nStartSecNo, nNumOfSec, nSecNoIdx;
    UINT    nNumOfSG, nSGBufLen, nSGBufNum;
    UINT    nSizeOfSec;
    UCHAR  *pSecBuf;
    UINT    nSecBufOffset;

    /* For FTL_Read Function */
    INT32   nRet;
    UINT32  nNumOfScts;
    UINT32  nDstOffset;
    UINT32  nSrcOffset;
    UINT32  nCpBytes;

    EnterCriticalSection(&(pDisk->d_DiskCardCrit));

    pSgr        = (PSG_REQ)pData;
    nStartSecNo = pSgr->sr_start;
    nNumOfSec   = pSgr->sr_num_sec;
    nNumOfSG    = pSgr->sr_num_sg;
    nSizeOfSec  = pDisk->d_DiskInfo.di_bytes_per_sect;

    if (pDisk->bIsFTLOpen == FALSE)
    {
        status = ERROR_INVALID_PARAMETER;
        goto ddi_exit;
    }

    if (nNumOfSG > MAX_SG_BUF)
    {
        status = ERROR_INVALID_PARAMETER;
        goto ddi_exit;
    }

    nSGBufLen = 0;

    // calculate total buffer space of scatter gather buffers
    for (nSGBufNum = 0; nSGBufNum < nNumOfSG; nSGBufNum++)
    {
        nSGBufLen += pSgr->sr_sglist[nSGBufNum].sb_len;
    }

    // check total SG buffer space is enough for reqeusted size
    if (nSGBufLen < (nNumOfSec * nSizeOfSec))
    {
        STDRV_ERR_PRINT((TEXT("[OND:ERR] DoDiskRead: SG Buffer space %d bytes less than block read size %d bytes\r\n"),
			nSGBufLen, nNumOfSec * nSizeOfSec));

        status = ERROR_GEN_FAILURE;
        goto ddi_exit;
    }

    pSgr->sr_status = ERROR_IO_PENDING;

    //
    // Make sure request doesn't exceed the disk
    //

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -