📄 falmain.cpp
字号:
}
RETAILMSG(1,(TEXT("Initialize the FAL XIP check start:%d\r\n"),GetTickCount() ));
if (pRegion->regionType == XIP) {
g_FalObjects[iRegion] = new XipFal(dwStartLogSector, dwStartPhysSector, !dwUpdateReadOnly);
}
else {
// If this is a read-only filesys region and we are not updating it, then the
// FAL object should be created as read-only
BOOL fReadOnly = FALSE;
if ((pRegion->regionType == READONLY_FILESYS) && !dwUpdateReadOnly) {
fReadOnly = TRUE;
}
g_FalObjects[iRegion] = new FileSysFal(dwStartLogSector, dwStartPhysSector, fReadOnly);
}
if(!g_FalObjects[iRegion] || !g_FalObjects[iRegion]->StartupFAL(pRegion)) {
ReportError((TEXT("FLASHDRV.DLL:Unable to initialize FAL!\r\n")));
goto INIT_ERROR;
}
dwStartPhysSector += g_FalObjects[iRegion]->GetNumPhysSectors();
dwStartLogSector += g_FalObjects[iRegion]->GetNumLogSectors();
g_dwAvailableSectors += g_FalObjects[iRegion]->GetNumLogSectors();
}
RETAILMSG(1,(TEXT("DSK_Init stop:%d\r\n"),GetTickCount() ));
//----- 9. Cache the handle to the device and then return it to DEVICE.EXE -----
g_pDevice = pDevice;
return (DWORD)pDevice;
INIT_ERROR:
DSK_Deinit((DWORD)pDevice);
return (DWORD)NULL;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: DSK_Deinit()
Description: Unloads the console device
Returns: Boolean indicating success; DEVICE.EXE does not
check the return code.
-------------------------------------------------------------------*/
BOOL DSK_Deinit(DWORD dwContext)
{
PDEVICE pDevice = (PDEVICE) dwContext;
DEBUGMSG(ZONE_FUNCTION,(TEXT("FLASHDRV.DLL:Deinit()\r\n")));
//----- 1. If this not the last user of the FLASH device, then return -----
if(InterlockedDecrement(&g_lReferenceCount) > 0)
{
return TRUE;
}
//----- 2. Close the FLASH device -----
DSK_Close(dwContext);
//----- 3. De-initialize the FAL -----
if (g_pFlashMediaInfo && g_FalObjects) {
for (DWORD iRegion = 0; iRegion < g_pFlashMediaInfo->dwNumRegions; iRegion++) {
if(g_FalObjects[iRegion]) {
g_FalObjects[iRegion]->ShutdownFAL();
delete g_FalObjects[iRegion];
}
}
}
delete[] g_FalObjects;
if (g_pFlashMediaInfo)
{
LocalFree (g_pFlashMediaInfo);
}
//----- 4. De-initialize the FLASH Media Driver (FMD) -----
if(!FMD.pDeInit(pDevice->hFMD))
{
ReportError((TEXT("FLASHDRV.DLL:Unable to de-initialize FLASH Media Driver (FMD).\r\n")));
}
//----- 5. Unhook any shimmed FMD functions -----
if (pDevice->hFMDHook)
{
FMDHOOK_UnhookInterface(pDevice->hFMDHook, &FMD);
}
//----- 6. Free the FLASH device handle -----
if(pDevice)
{
pDevice->dwID = 'DEAD';
LocalFree(pDevice);
}
//----- 7. Delete the Logical --> Physical Mapper's critical section -----
DeleteCriticalSection(&g_csFlashDevice);
DeleteCriticalSection(&g_csMain);
if (g_hCoreDll) {
pRegCloseKey fnRegCloseKey = (pRegCloseKey)GetProcAddress(g_hCoreDll, TEXT("RegCloseKey"));
if (fnRegCloseKey)
fnRegCloseKey (g_hDeviceKey);
FreeLibrary (g_hCoreDll);
}
return TRUE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: DSK_Open()
Description: Clears the console screen and restores defaults
Returns: Context data for the console device
-------------------------------------------------------------------*/
DWORD
DSK_Open(
DWORD dwData, // pdev
DWORD dwAccess,
DWORD dwShareMode)
{
DEBUGMSG(ZONE_FUNCTION,(TEXT("FLASHDRV.DLL:Open()\r\n")));
return dwData;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: DSK_Close()
Description: Closes the console
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL DSK_Close(DWORD Handle)
{
DEBUGMSG(ZONE_FUNCTION,(TEXT("FLASHDRV.DLL:Close()\r\n")));
return TRUE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: DSK_Read()
Description: Not Used. The file system performs read commands by
issuing the appopriate IOCTL. See DSK_IoControl()
for details.
Returns: FALSE
-------------------------------------------------------------------*/
DWORD
DSK_Read(
DWORD Handle,
LPVOID pBuffer, // Output buffer
DWORD dwNumBytes) // Buffer size in bytes
{
DEBUGMSG(ZONE_FUNCTION,(TEXT("FLASHDRV.DLL:Read()\r\n")));
return FALSE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: DSK_Write()
Description: Not Used. The file system performs write commands by
issuing the appopriate IOCTL. See DSK_IoControl()
for details.
Returns: FALSE
-------------------------------------------------------------------*/
DWORD DSK_Write(
DWORD Handle,
LPCVOID pBuffer,
DWORD dwInBytes)
{
DEBUGMSG(ZONE_FUNCTION,(TEXT("FLASHDRV.DLL:Write()\r\n")));
return FALSE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: DSK_Seek()
Description: Seeks are not supported.
Returns: FALSE
-------------------------------------------------------------------*/
DWORD
DSK_Seek(
DWORD Handle,
long lDistance,
DWORD dwMoveMethod
)
{
DEBUGMSG(ZONE_FUNCTION,(TEXT("FLASHDRV.DLL:Seek()\r\n")));
return FALSE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: DSK_IOControl()
Description: I/O Control function. File systems use this function to:
* initialize the media (DISK_IOCTL_INITIALIZED)
* read from the media (DISK_IOCTL_READ)
* write to the media (DISK_IOCTL_WRITE)
* get info about media (DISK_IOCTL_GETINFO)
* set info for media (DISK_IOCTL_SETINFO)
* get name of the media (DISK_IOCTL_GETNAME)
* format the media (DISK_IOCTL_FORMAT_MEDIA)
* deletes specified sectors (IOCTL_DISK_DELETE_SECTORS)
Note that in all cases, accessing the actual media is
performed by the FLASH Media Driver (FMD).
Additionally, OEMs are free to implement their own user-defined
IOCTLs for allowing applications to call directly into the FMD.
Returns: Boolean indicating success.
-------------------------------------------------------------------*/
BOOL
DSK_IOControl(
DWORD Handle,
DWORD dwIoControlCode,
PBYTE pInBuf,
DWORD nInBufSize,
PBYTE pOutBuf,
DWORD nOutBufSize,
PDWORD pBytesReturned)
{
BOOL fRet = FALSE;
// RETAILMSG(1,(TEXT("DSK_IOControl(%X) start:%d\r\n"),dwIoControlCode,GetTickCount() ));
EnterCriticalSection(&g_csMain);
EnterCriticalSection(&g_csFlashDevice);
__try
{
//----- 1. Check the function parameters to make sure we can handle the request... -----
switch (dwIoControlCode)
{
case DISK_IOCTL_INITIALIZED:
if(pInBuf == NULL)
{
goto PARAMETER_ERROR;
}
break;
case DISK_IOCTL_READ:case IOCTL_DISK_READ:
case DISK_IOCTL_WRITE:case IOCTL_DISK_WRITE:
if(pInBuf == NULL || nInBufSize < sizeof(SG_REQ))
{
goto PARAMETER_ERROR;
}
break;
case IOCTL_DISK_GETINFO:
if(pOutBuf == NULL || nOutBufSize != sizeof(DISK_INFO))
{
goto PARAMETER_ERROR;
}
break;
case DISK_IOCTL_GETINFO:
case DISK_IOCTL_SETINFO:case IOCTL_DISK_SETINFO:
if(pInBuf == NULL || nInBufSize != sizeof(DISK_INFO))
{
goto PARAMETER_ERROR;
}
break;
case DISK_IOCTL_GETNAME:case IOCTL_DISK_GETNAME:
if(pOutBuf == NULL || nOutBufSize == 0)
{
goto PARAMETER_ERROR;
}
break;
case DISK_IOCTL_FORMAT_MEDIA: case IOCTL_DISK_FORMAT_MEDIA:
break;
case IOCTL_DISK_DELETE_SECTORS:
//ctg case IOCTL_DISK_SET_SECURE_WIPE_FLAG:
if(pInBuf == NULL || nInBufSize != sizeof(DELETE_SECTOR_INFO))
{
goto PARAMETER_ERROR;
}
break;
/*ctg
case IOCTL_DISK_SECURE_WIPE:
if(pInBuf == NULL || nInBufSize != sizeof(DELETE_SECTOR_INFO))
{
goto PARAMETER_ERROR;
}
break;
*/
case IOCTL_DISK_DEVICE_INFO:
if(pInBuf == NULL || nInBufSize != sizeof(STORAGEDEVICEINFO))
{
goto PARAMETER_ERROR;
}
break;
case IOCTL_DISK_GET_SECTOR_ADDR:
if(pInBuf == NULL || pOutBuf == NULL || nInBufSize != nOutBufSize)
{
goto PARAMETER_ERROR;
}
break;
case IOCTL_POWER_CAPABILITIES:
if(pOutBuf == NULL || nOutBufSize < sizeof(POWER_CAPABILITIES) || pBytesReturned == NULL)
{
goto PARAMETER_ERROR;
}
break;
case IOCTL_POWER_SET:
if(pOutBuf == NULL || nOutBufSize < sizeof(CEDEVICE_POWER_STATE) || pBytesReturned == NULL)
{
goto PARAMETER_ERROR;
}
break;
case IOCTL_POWER_GET:
if(pOutBuf == NULL || nOutBufSize < sizeof(CEDEVICE_POWER_STATE) || pBytesReturned == NULL)
{
goto PARAMETER_ERROR;
}
break;
default:
// Pass any other IOCTL through to the FMD.
fRet = FMD.pOEMIoControl(dwIoControlCode, pInBuf, nInBufSize, pOutBuf, nOutBufSize, pBytesReturned);
goto IO_EXIT;
}
//----- 2. Now handle the IOCTL request... -----
switch (dwIoControlCode)
{
case DISK_IOCTL_INITIALIZED:
break;
case DISK_IOCTL_READ:case IOCTL_DISK_READ:
DEBUGMSG(ZONE_FUNCTION,(TEXT("FLASHDRV.DLL:DSK_IOControl(DISK_IOCTL_READ)\r\n")));
//----- Service this scatter/gather READ request -----
if(!(fRet = ReadFromMedia((PSG_REQ)pInBuf)))
{
ReportError((TEXT("FLASHDRV.DLL:ReadFromMedia() failed.\r\n")));
}
break;
case DISK_IOCTL_WRITE:case IOCTL_DISK_WRITE:
DEBUGMSG(ZONE_FUNCTION,(TEXT("FLASHDRV.DLL:DSK_IOControl(DISK_IOCTL_WRITE)\r\n")));
//----- Service this scatter/gather WRITE request -----
if(!(fRet = WriteToMedia((PSG_REQ)pInBuf)))
{
ReportError((TEXT("FLASHDRV.DLL:WriteToMedia() failed.\r\n")));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -