📄 atamain.cpp
字号:
// NULL - error.
//
//--------------------------------------------------------------------------
EXTERN_C DWORD DSK_Open( HANDLE pHandle,
DWORD dwAccess,
DWORD dwShareMode)
{
CDisk *pDisk = (CDisk *)pHandle;
DEBUGMSG
(
ZONE_MAIN,
(
TEXT("ATAPI:DSK_Open request Handle = %08 dwAccess=%08X dwShareMode=%08X\r\n"),
pHandle,
dwAccess,
dwShareMode
)
);
EnterCriticalSection( &g_csMain);
if (!AtaIsValidDisk(pDisk))
{
pDisk = NULL;
}
LeaveCriticalSection( &g_csMain);
if (pDisk)
{
pDisk->Open();
}
return (DWORD)pDisk;
}
//--------------------------------------------------------------------------
//
// DSK_Close - This function closes the device identified by DSK_Open.
//
// Input: pHandle - Pointer to Handle returned by DSK_Open function
// and used to identify the open context of the device
//
// Return: TRUE - ok.
// FALSE - error.
//
//--------------------------------------------------------------------------
EXTERN_C BOOL DSK_Close(DWORD pHandle)
{
CDisk *pDisk = (CDisk *)pHandle;
DEBUGMSG( ZONE_MAIN, (TEXT("ATAPI:DSK_Close request Handle = %08X\r\n"), pHandle));
EnterCriticalSection( &g_csMain);
if (!AtaIsValidDisk(pDisk))
{
pDisk = NULL;
}
LeaveCriticalSection( &g_csMain);
if (pDisk)
{
pDisk->Close();
}
return (pDisk!= NULL);
}
//--------------------------------------------------------------------------
//
// DSK_IOcontrol: Ioctl command processing entry point
//
// Input: Standard Ioctl inputs.
//
// Return: TRUE - ok
// FALSE - error.
//
//
//--------------------------------------------------------------------------
EXTERN_C BOOL DSK_IOControl(DWORD pHandle, //Handle to the device
DWORD dwIoControlCode,//Specifies the control code
PBYTE pInBuf, //Pointer to a buffer that contains the data required to perform the operation.
DWORD nInBufSize, //Size, in bytes, of pInBuf
PBYTE pOutBuf, //Pointer to a buffer that receives the operation's output data.
DWORD nOutBufSize, //Size, in bytes, of pOutBuf
PDWORD pBytesReturned,//Pointer to a variable that receives the size, in bytes, of the data stored into the buffer pointed to by pOutBuf.
PDWORD pOverlapped) //Ignored; set to NULL.
{
BOOL fRet = FALSE;
CDisk *pDisk = (CDisk *)pHandle;
DEBUGMSG( ZONE_MAIN, (TEXT("ATAPI:DSK_IOControl request Handle = %08X dwCode=%ld\r\n"), pHandle, dwIoControlCode));
EnterCriticalSection( &g_csMain);
if (!AtaIsValidDisk(pDisk))
{
pDisk = NULL;
}
LeaveCriticalSection( &g_csMain);
if (pDisk) {
if (dwIoControlCode == DISK_IOCTL_INITIALIZED)
{
fRet = pDisk->PostInit( (PPOST_INIT_BUF) pInBuf);
}
else
{
IOREQ IOReq;
memset( &IOReq, 0, sizeof(IOReq));
IOReq.dwCode = dwIoControlCode;
IOReq.pInBuf = pInBuf;
IOReq.dwInBufSize = nInBufSize;
IOReq.pOutBuf = pOutBuf;
IOReq.dwOutBufSize = nOutBufSize;
IOReq.pBytesReturned = pBytesReturned;
IOReq.hProcess = GetCallerProcess();
__try
{
DEBUGMSG( ZONE_IOCTL, (TEXT("Enter ioctl %08X\r\n"), dwIoControlCode));
fRet = pDisk->PerformIoctl(&IOReq);
DEBUGMSG( ZONE_IOCTL, (TEXT("Exit ioctl %08X\r\n"), dwIoControlCode));
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DEBUGMSG( ZONE_ERROR, (TEXT("ATAPI:Exception in PerformIoctl !!!\r\n")));
fRet = FALSE;
SetLastError(ERROR_GEN_FAILURE);
}
}
}
return fRet;
}
// Not implemented by ATAPI driver ...use IOCTL instead
EXTERN_C DWORD DSK_Read(DWORD Handle, LPVOID pBuffer, DWORD dwNumBytes)
{
SetLastError(ERROR_NOT_SUPPORTED);
return 0;
}
// Not implemented by ATAPI driver ...use IOCTL instead
EXTERN_C DWORD DSK_Write(DWORD Handle, LPCVOID pBuffer, DWORD dwNumBytes)
{
SetLastError(ERROR_NOT_SUPPORTED);
return 0;
}
// Not implemented by ATAPI driver ...use IOCTL instead
EXTERN_C DWORD DSK_Seek(DWORD Handle, long lDistance, DWORD dwMoveMethod)
{
SetLastError(ERROR_NOT_SUPPORTED);
return 0;
}
EXTERN_C void DSK_PowerUp(void)
{
EnterCriticalSection(&g_csMain);
CDisk *pDisk = g_pDiskRoot;
while(pDisk)
{
pDisk->PowerUp();
pDisk = pDisk->m_pNextDisk;
}
LeaveCriticalSection(&g_csMain);
}
EXTERN_C void DSK_PowerDown(void)
{
EnterCriticalSection(&g_csMain);
CDisk *pDisk = g_pDiskRoot;
while(pDisk) {
pDisk->PowerDown();
pDisk = pDisk->m_pNextDisk;
}
LeaveCriticalSection(&g_csMain);
}
BOOL ReadIoInfo(HKEY hDevKey, TCHAR *szValueName, PDWORD pdwData)
{
TCHAR szData[MAX_PATH];
TCHAR *szStopString;
DWORD cbData;
DWORD dwType;
cbData = sizeof(szData);
DWORD dwIndex = 0;
if (ERROR_SUCCESS == RegQueryValueEx( hDevKey, szValueName, NULL, &dwType, (PBYTE)szData, &cbData) && (dwType == REG_MULTI_SZ)) {
PWSTR szTemp = szData;
while(szTemp) {
pdwData[dwIndex] = wcstol( szTemp, &szStopString, 16);
if (++dwIndex > 4)
break;
szTemp += (wcslen(szTemp)+1);
}
return (dwIndex == 5);
}
return FALSE;
}
//--------------------------------------------------------------------------
//
// ATAPIMain - The Main Dll load entry point
//
// Input: DllInstance - a Handle to the DLL. The value is the base address of the DLL.
// The HINSTANCE of a DLL is the same as the HMODULE of the DLL, so hinstDLL
// can be used in subsequent calls to the GetModuleFileName function and other
// functions that require a module handle.
//
// dwReason - a flag indicating why the DLL entry-point function is being called.
// This parameter can be one of the following values:
// Return: TRUE - ok.
// FALSE - error.
//
// NOTES Register Debug Zones only.
// This function is an optional method of entry into a dynamic-link library (DLL).
// If the function is used, it is called by the system when processes and threads
// are initialized and terminated, or upon calls to the LoadLibrary and FreeLibrary
// functions.
// DllMain is a placeholder for the library-defined function name.
// You must specify the actual name you use when you build your DLL.
// For more information, see the documentation included with your development tools.
//
//--------------------------------------------------------------------------
BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
g_hInstance = (HINSTANCE)hInstance;
InitializeCriticalSection(&g_csMain);
DEBUGMSG( ZONE_INIT, (TEXT("ATAPI DLL_PROCESS_ATTACH\r\n")));
DEBUGREGISTER((HINSTANCE)hInstance);
DisableThreadLibraryCalls((HMODULE) hInstance);
break;
case DLL_PROCESS_DETACH:
DeleteCriticalSection(&g_csMain);
DEBUGMSG( ZONE_INIT, (TEXT("ATAPI DLL_PROCESS_DETACH\r\n")));
break;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -