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

📄 ondisk.c

📁 s3c2450 bsp for wince 5.0 PM_REL_0.04_080519 经验证,完全没问题
💻 C
📖 第 1 页 / 共 5 页
字号:
        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_Open() failure. ERR Code=%x\r\n"), nResult));

            break;
        }

        bRet = TRUE;

    } while(0);

#else   //_SUPPORT_HAL_WRAPPER_

    do {
        STDRV_LOG_PRINT((TEXT("[OND: IN] not _SUPPORT_HAL_WRAPPER_\r\n")));

        if (FIL_Init() != VFL_SUCCESS)
        {
            STDRV_ERR_PRINT((TEXT("[OND:ERR]  FIL_Init() failure.\r\n")));

            break;
        }

        if (VFL_Init() != VFL_SUCCESS)
        {
            STDRV_ERR_PRINT((TEXT("[OND:ERR]  VFL_Init() failure.\r\n")));

            break;
        }

        if (VFL_Open() != VFL_SUCCESS)
        {
            STDRV_ERR_PRINT((TEXT("[OND:ERR]  VFL_Open() failure.\r\n")));

            break;
        }

        bRet = TRUE;

    } while(0);

#endif  //_SUPPORT_HAL_WRAPPER_

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

    return bRet;
}


/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*      InitializeFTL                                                        */
/* DESCRIPTION                                                               */
/*      This function initializes Disk handle                                */
/* PARAMETERS                                                                */
/*      pDisk                                                                */
/*          Disk handle                                                      */
/*      ActiveKey                                                            */
/*          Pointer to active key                                            */
/* RETURN VALUES                                                             */
/*      Return TRUE if Operation success, FALSE if not.                      */
/* NOTE                                                                      */
/*      call from DSK_Init (actually InitDisk)                               */
/*                                                                           */
/*****************************************************************************/
static BOOL
InitializeFTL(PDISK pDisk)
{
	INT         nSTLRet;
	BOOL        bIsFormatNeeded;
	INT         nTryCnt;
	BOOL        bRet = FALSE;
	UINT32      TotalScts;

	STDRV_LOG_PRINT((TEXT("[OND: IN] ++InitializeFTL()\r\n")));

	bIsFormatNeeded = FALSE;

	nTryCnt = 10;

	while (nTryCnt --)
	{
		if (nTryCnt < 0)
		{
			STDRV_ERR_PRINT((L"[OND:   ]  FTL_Open try is 10 times. "
			L"ERROR:too many try..\r\n"));
			goto InitializeFTLError;
		}

		nSTLRet = FTL_Init();

		if (nSTLRet == FTL_CRITICAL_ERROR)
		{
			STDRV_ERR_PRINT((TEXT("[OND:ERR]  FTL_Init : errno = %d\r\n"), nSTLRet));
		}

		if (GetBmlPartitionId(pDisk) == FALSE)
		{
			STDRV_ERR_PRINT((TEXT("[OND:ERR]  GetBmlPartitionId() Error\r\n")));
			break;
		}

		STDRV_LOG_PRINT((TEXT("[OND:   ]  %dth Init FTL Try\r\n"), 10 - nTryCnt));
		STDRV_LOG_PRINT((TEXT("[OND:   ]  FTL_Init Success (RetCode = %d)\r\n"), nSTLRet));

		TotalScts                 = 0;  /* Output : The number of total logical sectors */

		/* Input  : size of buffer for SAM (percentage) */
		/*         if nSamBufFactor == 0, STL factor set*/
		/*         it as 100                            */

		/* FTL Open */
		nSTLRet = FTL_Open(&TotalScts);

		if (nSTLRet == FTL_SUCCESS)
		{
			bIsFormatNeeded = FALSE;
			STDRV_INF_PRINT((TEXT("[OND:INF]  TotalLogScts   = %d\r\n"), TotalScts));

#if ONDISK_MULTIPARTITION
			if (pDisk->nWMRNumOfSector == 0xFFFFFFFF)
			{
				pDisk->nWMRNumOfSector = TotalScts - pDisk->nWMRStartSector;  // calculate remained sector on multiple partition
			}
			else if (pDisk->nWMRNumOfSector > TotalScts)
			{
				STDRV_ERR_PRINT((TEXT("[OND:ERR] WMRNumOfSector size(%u) exceeded total sectors(%u).\r\n"), pDisk->nWMRNumOfSector, TotalScts));
				pDisk->nWMRNumOfSector = TotalScts;
				STDRV_ERR_PRINT((TEXT("[OND:ERR] WMRNumOfSector sets total sectors now.\r\n")));
			}

			pDisk->d_DiskInfo.di_total_sectors  = (pDisk->nWMRNumOfSector >> OND_SECTOR_SHIFT);
#else
			pDisk->d_DiskInfo.di_total_sectors  = (TotalScts >> OND_SECTOR_SHIFT);
#endif
			pDisk->d_DiskInfo.di_bytes_per_sect = (WMR_SECTOR_SIZE << OND_SECTOR_SHIFT);
			pDisk->d_DiskInfo.di_cylinders		= 0;
			pDisk->d_DiskInfo.di_heads			= 0;
			pDisk->d_DiskInfo.di_sectors		= 0;
			pDisk->d_DiskInfo.di_flags			=
			DISK_INFO_FLAG_CHS_UNCERTAIN | DISK_INFO_FLAG_PAGEABLE;

			STDRV_INF_PRINT((TEXT("[OND:	 ] total_sectors  = %d\r\n"), pDisk->d_DiskInfo.di_total_sectors));
			STDRV_INF_PRINT((TEXT("[OND:	 ] bytes_per_sect = %d\r\n"), pDisk->d_DiskInfo.di_bytes_per_sect));
			STDRV_INF_PRINT((TEXT("[OND:	 ] storage size   = %d\r\n"),
			pDisk->d_DiskInfo.di_total_sectors * pDisk->d_DiskInfo.di_bytes_per_sect));

			bRet = TRUE;
			break;  // exit while (1)
		}
		else if (nSTLRet == FTL_CRITICAL_ERROR)
		{
			STDRV_ERR_PRINT((TEXT("[OND:ERR] FTL_Open occurs Critical Error\r\n")));
			bIsFormatNeeded = TRUE;
		}
		else
		{
			STDRV_ERR_PRINT((TEXT("[OND:   ] FTL_Open unknown error\r\n")));
			goto InitializeFTLError;
		}

		STDRV_INF_PRINT((TEXT("[OND:INF] just before FTL formatted\r\n")));

		/* FTL_Format */
		if (bIsFormatNeeded == TRUE)
		{
			STDRV_INF_PRINT((TEXT("[OND:INF]  FTL_Format Start\r\n")));

			nSTLRet = FTL_Format();

			if (nSTLRet != FTL_SUCCESS)
			{
				STDRV_ERR_PRINT((TEXT("[OND:ERR]  FTL_Format Error = 0x%x\r\n"), nSTLRet));

				if (IsAPIReady(SH_WMGR) == TRUE)
				{
					MessageBoxW(NULL,
					TEXT("Can't be formatted"),
					TEXT("Low Format"),
					MB_OK | MB_ICONERROR | MB_TOPMOST | MB_SETFOREGROUND);
				}
				goto InitializeFTLError;
			}
			else
			{
				STDRV_INF_PRINT((TEXT("[OND:INF]  FTL_Format Complete\r\n")));

				// reset bIsFormatNeeded flag to FALSE.
				bIsFormatNeeded = FALSE;
			}
		}
	}

InitializeFTLError:

    return bRet;
}


/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*      InitDisk                                                             */
/* DESCRIPTION                                                               */
/*      This function initializes Disk handle                                */
/* PARAMETERS                                                                */
/*      pDisk                                                                */
/*          Disk handle                                                      */
/*      ActiveKey                                                            */
/*          Pointer to active key                                            */
/* RETURN VALUES                                                             */
/*      Return TRUE if Operation success, FALSE if not.                      */
/* NOTE                                                                      */
/*      call from DSK_Init                                                   */
/*                                                                           */
/*****************************************************************************/
static BOOL
InitDisk(PDISK  pDisk,
         LPTSTR ActiveKey)
{
	BOOL         bRet = FALSE;

	//
	// initialization by determining the NAND Flash capacity
	//
	pDisk->fBusy = FALSE;

	STDRV_LOG_PRINT((TEXT("[OND: IN] ++InitDisk()\r\n")));

	if (InitializeNAND(pDisk) == FALSE)
	{
		pDisk->bIsFTLOpen = FALSE;
		STDRV_ERR_PRINT((TEXT("[OND:ERR]  InitializeNAND Error\r\n")));
	}
	else
	{
		if (InitializeFTL(pDisk) == FALSE)
		{
			pDisk->bIsFTLOpen = FALSE;
			STDRV_ERR_PRINT((TEXT("[OND:ERR]  InitializeFTL Error\r\n")));
		}
		else
		{
			pDisk->bIsFTLOpen = TRUE;
			bRet = TRUE;
		}
	}

	return bRet;
}


/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*      DSK_Init                                                             */
/* DESCRIPTION                                                               */
/*      Create Disk Object, Initialize Disk Object                           */
/* PARAMETERS                                                                */
/*      dwContext   STDRVIF_PS driver own structure pointer                   */
/*                  registry path for this device's active key               */
/* RETURN VALUES                                                             */
/*      Returns context data for this Init instance                          */
/*                                                                           */
/*****************************************************************************/
DWORD
DSK_Init(DWORD dwContext)
{
    PDISK  pDisk;                           /* Disk Handle */
    LPWSTR ActivePath  = (LPWSTR)dwContext;
    LPWSTR ActivePath2 = (LPWSTR)dwContext;

    STDRV_LOG_PRINT((TEXT("[OND: IN] ++DSK_Init()\r\n")));

    EnterCriticalSection(&v_DiskCrit);

    if (v_DiskList == NULL)
    {
        STDRV_RTL_PRINT((TEXT("[OND:INF]  InitializeCriticalSection(&v_DiskCrit)\r\n")));
    }

    /* Disk Handle Creation */
    pDisk = CreateDiskObject();
    if (pDisk == NULL)
    {
        STDRV_ERR_PRINT((TEXT("[OND:ERR]  CreateDiskObject(PDISK) failed %d\r\n"), GetLastError()));
        return (DWORD)0;
    }

    /* if dwContext != (DWORD)NULL */
    if (ActivePath)
    {
        /* for using loader                     */
        /* get actual ActivePath memory address */
        //ActivePath2 = (LPWSTR) MapPtrToProcess((LPVOID)ActivePath, GetCallerProcess());
        ActivePath2 = (LPWSTR) MapCallerPtr((LPVOID)ActivePath,wcslen(ActivePath) * sizeof(WCHAR) + sizeof(WCHAR));

        if (NULL != ActivePath2)
        {
            ActivePath = ActivePath2;
        }

        /* Copy Active Path to pDisk Handle */
        if (pDisk->d_ActivePath = LocalAlloc(LPTR, wcslen(ActivePath) * sizeof(WCHAR) + sizeof(WCHAR)))
        {
            wcscpy(pDisk->d_ActivePath, ActivePath);
        }

        STDRV_INF_PRINT((TEXT("[OND:INF] : ActiveKey (copy) = %s (@ 0x%08X)\r\n"), pDisk->d_ActivePath, pDisk->d_ActivePath));
    }

    /* Initialize pDisk Handle */
    if (InitDisk(pDisk, ActivePath) == FALSE)
    {
        if (pDisk)
        {
            if (pDisk->d_ActivePath)
            {
                LocalFree(pDisk->d_ActivePath);
                pDisk->d_ActivePath = NULL;
            }
            CloseDisk(pDisk);
        }
        return 0;
    }

    // ToDo, FATCleanser Initialization code
    LeaveCriticalSection(&v_DiskCrit);

    STDRV_LOG_PRINT((TEXT("[OND:OUT] --DSK_Init() returning 0x%x\r\n"), pDisk));

    return (DWORD)pDisk;
}


/*****************************************************************************/
/*                                                                           */
/* NAME    

⌨️ 快捷键说明

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