📄 ioctl.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
// File: ioctl.c
//
// This file implements the OEM's IO Control (IOCTL) functions and declares
// global variables used by the IOCTL component.
//
#include <partdrv.h>
#include <bsp.h>
#include <pmplatform.h>
//------------------------------------------------------------------------------
//
// Global: g_oalIoctlPlatformType/OEM
//
// Platform Type/OEM
//
LPCWSTR g_oalIoCtlPlatformType = IOCTL_PLATFORM_TYPE;
LPCWSTR g_oalIoCtlPlatformOEM = IOCTL_PLATFORM_OEM;
//------------------------------------------------------------------------------
//
// Global: g_oalIoctlProcessorVendor/Name/Core
//
// Processor information
//
LPCWSTR g_oalIoCtlProcessorVendor = IOCTL_PROCESSOR_VENDOR;
LPCWSTR g_oalIoCtlProcessorName = IOCTL_PROCESSOR_NAME;
LPCWSTR g_oalIoCtlProcessorCore = IOCTL_PROCESSOR_CORE;
//------------------------------------------------------------------------------
//
// Global: g_oalIoctlInstructionSet
//
// Processor instruction set identifier
//
UINT32 g_oalIoCtlInstructionSet = IOCTL_PROCESSOR_INSTRUCTION_SET;
//------------------------------------------------------------------------------
//
// Function: OALIoCtlHalReboot
// This function make a Warm Boot of the target device
//
static BOOL OALIoCtlHalReboot(
UINT32 code, VOID *pInpBuffer, UINT32 inpSize,
VOID *pOutBuffer, UINT32 outSize, UINT32 *pOutSize)
{
OALMSG(OAL_IOCTL&&OAL_FUNC, (TEXT("[OAL] ++OALIoCtlHalReboot()\r\n")));
//-----------------------------
// Disable DVS and Set to Full Speed
//-----------------------------
ChangeDVSLevel(SYS_L0);
OEMSWReset();
OALMSG(OAL_IOCTL&&OAL_FUNC, (TEXT("[OAL] --OALIoCtlHalReboot()\r\n")));
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: OALIoCtlHalGetHWEntropy
//
// Implements the IOCTL_HAL_GET_HWENTROPY handler. This function creates a
// 64-bit value which is unique to the hardware. This value never changes.
//
static BOOL OALIoCtlHalGetHWEntropy(
UINT32 dwIoControlCode, VOID *lpInBuf, UINT32 nInBufSize, VOID *lpOutBuf,
UINT32 nOutBufSize, UINT32* lpBytesReturned)
{
// TODO by Device Maker : This code is only sample.
// S3C6410 has IDs only for chip type not for each chip.
// If Device Maker wants unique ID for each device
// Device maker must modify this function.
// If Device has Ethernet Device, Use MAC address
// Recommended method is to use NAND's ID or UUIC's ID
// Device maker can make Unique ID with CHIP ID
UINT8 *UniqueID;
BOOL rc = FALSE;
OALMSG(OAL_IOCTL&&OAL_FUNC, (L"+OALIoCtlHalGetHWEntropy\r\n"));
UniqueID = (UINT8 *)OALArgsQuery(OAL_ARGS_QUERY_UUID);
// Check buffer size
if (lpBytesReturned != NULL)
{
*lpBytesReturned = sizeof(UINT8[16]);
}
if (lpOutBuf == NULL || nOutBufSize < sizeof(UINT8[16]))
{
NKSetLastError(ERROR_INSUFFICIENT_BUFFER);
OALMSG(OAL_WARN, (L"WARN: OALIoCtlHalGetHWEntropy: Buffer too small\r\n"));
}
else
{
// Copy pattern to output buffer
memcpy(lpOutBuf, UniqueID, sizeof(UINT8[16]));
// We are done
rc = TRUE;
}
// Indicate status
OALMSG(OAL_IOCTL&&OAL_FUNC, (L"-OALIoCtlHalGetHWEntropy(rc = %d)\r\n", rc));
return rc;
}
//------------------------------------------------------------------------------
//
// Function: OALIoCtlHalGetHiveCleanFlag
//
// This function is used by Filesys.exe to query the OEM to determine if the registry hives
// and user profiles should be deleted and recreated.
//
// Notes: During a OS start up, Filesys.exe calls HIVECLEANFLAG_SYSTEM twice and followed by
// HIVECLEANFLAG_USER. We'll clear the shared Args flag after that.
//
static BOOL OALIoCtlHalGetHiveCleanFlag(
UINT32 code, VOID *lpInBuf, UINT32 nInBufSize, VOID *lpOutBuf,
UINT32 nOutBufSize, UINT32 *pOutSize)
{
BOOL bRet = FALSE;
OALMSG(OAL_IOCTL&&OAL_FUNC, (TEXT("++OALIoCtlHalGetHiveCleanFlag()\r\n")));
if ( (lpInBuf == NULL)
|| (nInBufSize != sizeof(DWORD))
|| (lpOutBuf == NULL)
|| (nOutBufSize != sizeof(BOOL)))
{
OALMSG(OAL_ERROR, (TEXT("[OAL:ERR] OALIoCtlHalGetHiveCleanFlag() Invalid Input Parameter\r\n")));
return FALSE;
}
else
{
DWORD *pdwFlags = (DWORD*)lpInBuf;
BOOL *pbClean = (BOOL*)lpOutBuf;
// This is the global shared Args flag
BOOL *bHiveCleanFlag = (BOOL*) OALArgsQuery(BSP_ARGS_QUERY_HIVECLEAN);
*pbClean = *bHiveCleanFlag;
bRet = *bHiveCleanFlag;
if (*pdwFlags == HIVECLEANFLAG_SYSTEM)
{
if(bRet)
{
OALMSG(TRUE, (TEXT("[OAL] Clear System Hive\r\n")));
}
else
{
OALMSG(TRUE, (TEXT("[OAL] Not Clear System Hive\r\n")));
}
}
else if (*pdwFlags == HIVECLEANFLAG_USERS)
{
if(bRet)
{
OALMSG(TRUE, (TEXT("[OAL] Clear User Hive\r\n")));
}
else
{
OALMSG(TRUE, (TEXT("[OAL] Not Clear User Hive\r\n")));
}
// We are done checking HiveCleanFlag by now (system hive is checked before user hive).
// Now is the time to clear the global shared Args flag if it is set by switch or software.
*bHiveCleanFlag = FALSE;
}
else
{
OALMSG(OAL_ERROR, (TEXT("[OAL] Unknown Flag 0x%x\r\n"), *pdwFlags));
}
}
OALMSG(OAL_IOCTL&&OAL_FUNC, (TEXT("--OALIoCtlHalGetHiveCleanFlag()\r\n")));
return(bRet);
}
//------------------------------------------------------------------------------
//
// Function: OALIoCtlHalQueryFormatPartition
//
// This function is called by Filesys.exe to allow an OEM to specify whether a specific
// partition is to be formatted on mount. Before Filesys.exe calls this IOCTL, it checks
// the CheckForFormat registry value in the storage profile for your block driver.
//
static BOOL OALIoCtlHalQueryFormatPartition(
UINT32 code, VOID *lpInBuf, UINT32 nInBufSize, VOID *lpOutBuf,
UINT32 nOutBufSize, UINT32 *pOutSize)
{
OALMSG(OAL_IOCTL&&OAL_FUNC, (TEXT("++OALIoCtlHalFormatPartition()\r\n")));
if ( (lpInBuf == NULL)
||(nInBufSize != sizeof(STORAGECONTEXT))
|| (lpOutBuf == NULL)
|| (nOutBufSize < sizeof(BOOL)))
{
OALMSG(OAL_ERROR, (TEXT("[OAL:ERR] OALIoCtlHalFormatPartition() Invalid Input Parameter\r\n")));
return FALSE;
}
else
{
STORAGECONTEXT *pStore = (STORAGECONTEXT *)lpInBuf;
BOOL *pbClean = (BOOL *)lpOutBuf;
// This is the global shared Args flag
BOOL *bFormatPartFlag = (BOOL *) OALArgsQuery(BSP_ARGS_QUERY_FORMATPART);
OALMSG(OAL_VERBOSE, (TEXT("[OAL] Store partition info:\r\n")));
OALMSG(OAL_VERBOSE, (TEXT("[OAL] \tszPartitionName=%s\r\n"), pStore->PartInfo.szPartitionName));
OALMSG(OAL_VERBOSE, (TEXT("[OAL] \tsnNumSectors=%d\r\n"), pStore->PartInfo.snNumSectors));
OALMSG(OAL_VERBOSE, (TEXT("[OAL] \tdwAttributes=0x%x\r\n"), pStore->PartInfo.dwAttributes));
OALMSG(OAL_VERBOSE, (TEXT("[OAL] \tbPartType=0x%x\r\n"), pStore->PartInfo.bPartType));
// Set return value
*pbClean = *bFormatPartFlag;
// Clear the flag so that we don't do it again in next boot unless it is set again.
*bFormatPartFlag = FALSE;
if(*pbClean)
{
if(pStore->dwFlags & AFS_FLAG_BOOTABLE)
{
OALMSG(TRUE, (TEXT("[OAL] Clear Storage (System Registry Hive)\r\n")));
}
else
{
OALMSG(TRUE, (TEXT("[OAL] Clear Storage\r\n")));
}
}
else
{
OALMSG(TRUE, (TEXT("[OAL] Not Clear Storage\r\n")));
}
}
if(pOutSize)
{
*pOutSize = sizeof(UINT32);
}
OALMSG(OAL_IOCTL&&OAL_FUNC, (TEXT("--OALIoCtlHalFormatPartition()\r\n")));
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: OALIoCtlHalQueryDisplaySettings
//
// This function is called by GDI to query the kernel for information
// about a preferred resolution for the system to use.
//
static BOOL OALIoCtlHalQueryDisplaySettings(
UINT32 dwIoControlCode, VOID *lpInBuf, UINT32 nInBufSize,
VOID *lpOutBuf, UINT32 nOutBufSize, UINT32* lpBytesReturned)
{
DWORD dwErr = 0;
OALMSG(OAL_IOCTL&&OAL_FUNC, (TEXT("++OALIoCtlHalQueryDisplaySettings()\r\n")));
if (lpBytesReturned)
{
*lpBytesReturned = 0;
}
if (lpOutBuf == NULL)
{
dwErr = ERROR_INVALID_PARAMETER;
}
else if (sizeof(DWORD)*3 > nOutBufSize)
{
dwErr = ERROR_INSUFFICIENT_BUFFER;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -