ciosinterface.cpp

来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C++ 代码 · 共 426 行

CPP
426
字号
/*____________________________________________________________________________
		Copyright (C) 2002 PGP Corporation
        All rights reserved.

        $Id: CIosInterface.cpp,v 1.4 2002/08/06 20:09:30 dallen Exp $
____________________________________________________________________________*/

#include "pgpClassesConfig.h"

#include "UDebug.h"
#include "UString.h"

#include "CDriverSubsystems.h"
#include "CInterface.h"
#include "CIosInterface.h"
#include "CPGPdiskHandler.h"

#include "DriverMain.h"
#include "UConstantNamesDrv98.h"

_USING_PGP

// Macros

#define FIELDOFFSET(type, field) ((DWORD)(&((type *)0)->field))


// Class CIosInterface member functions

PIOP 
CIosInterface::IlbDequeueIop(PDCB pDcb) const
{
	PIOP	pIop;
	PVOID	func	= reinterpret_cast<PVOID>(mIlb->ILB_dequeue_iop);

	__asm
	{
		push pDcb
		call [func]
		add esp, 4
		mov pIop, eax
	}

	return pIop;
}

ILB dude;

VOID 
CIosInterface::IlbEnqueueIop(PIOP pIop, PDCB pDcb) const
{
	PVOID	func	= reinterpret_cast<PVOID>(mIlb->ILB_enqueue_iop);

	__asm
	{
		push pDcb
		push pIop
		call [func]
		add esp, 8
	}
}

VOID 
CIosInterface::IlbInternalRequest(PIOP pIop, PDCB pDcb, void *calldown) const
{
	__asm
	{
		mov edi, pIop
		mov ebx, pDcb
		mov edx, calldown
	}

	(* (VOID (*)()) mIlb->ILB_internal_request)();
}

PGPBoolean 
CIosInterface::IlbIntIoCriteria(PIOP pIop) const
{
	PGPUInt32	result;
	PVOID		func	= mIlb->ILB_int_io_criteria_rtn;

	__asm
	{
		push pIop
		call [func]
		add esp, 4
		mov result, eax
	}

	return (result == 0);
}

PGPBoolean 
CIosInterface::IlbIoCriteria(PIOR pIor) const
{
	PGPUInt32	result;
	PVOID		func	= mIlb->ILB_io_criteria_rtn;

	__asm
	{
		push pIor
		call [func]
		add esp, 4
		mov result, eax
	}

	return (result == 0);
}

PGPUInt32 
CIosInterface::IlbService(PISP pIsp) const
{
	PFNISP		func	= mIlb->ILB_service_rtn;
	PGPUInt32	result;

	__asm
	{
		push pIsp
		call [func]
		add esp, 4
		mov result, eax
	}

	return result;
}

VOID 
CIosInterface::IlbWait10thSec() const
{
	PVOID	func	= mIlb->ILB_Wait_10th_Sec;

	__asm call [func]
}

DWORD 
CIosInterface::IrsGetDriveInfo(PGPUInt8 drive) const
{
	IRS_drv_get	irsDG;
	
	irsDG.IRS_filler_5	= IRS_GET_DRVINFO;
	irsDG.IRS_filler_6	= 0;
	irsDG.IRS_DrvLetter	= drive + 'A';
	irsDG.IRS_DrvFlags	= 0;

	IOS_Requestor_Service(reinterpret_cast<PIRS>(&irsDG));
	
	if (irsDG.IRS_filler_6 != 0)
		return 0xFFFFFFFF;
	else
		return irsDG.IRS_DrvFlags;
}

PGPBoolean 
CIosInterface::IrsIsDriveCompressed(PGPUInt8 drive, PGPUInt8& hostDrive) const
{
	IRS_drv_comp	irsDC;

	irsDC.IRS_i_d_c_hdr.IRS_func	= IRS_IS_DRVCOMPRESSED;
	irsDC.IRS_i_d_c_hdr.IRS_result	= 0;

	irsDC.IRS_i_d_c_drive	= drive;
	irsDC.IRS_i_d_c_flags	= 0;

	IOS_Requestor_Service(reinterpret_cast<PIRS>(&irsDC));
	
	if ((irsDC.IRS_i_d_c_hdr.IRS_result == IRS_SUCCESS) && 
		((irsDC.IRS_i_d_c_flags & IRS_I_D_C_COMP) || 
		 (irsDC.IRS_i_d_c_flags & IRS_I_D_C_PM_COMP)))
	{
		hostDrive = irsDC.IRS_i_d_c_drive;
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

PGPBoolean 
CIosInterface::IspAssociateDcb(
	PDCB		pDcb, 
	PGPUInt8	drive, 
	PGPUInt8	flags) const
{
	ISP_dcb_associate	ispDA;
	
	ispDA.ISP_d_a_hdr.ISP_func	= ISP_ASSOCIATE_DCB;
	ispDA.ISP_d_a_dcb			= reinterpret_cast<ULONG>(pDcb);
	ispDA.ISP_d_a_drive			= drive;
	ispDA.ISP_d_a_flags			= flags;
	
	IlbService(reinterpret_cast<PISP>(&ispDA));
	return (ispDA.ISP_d_a_hdr.ISP_result == 0);
}

PDDB 
CIosInterface::IspCreateDdb(PGPUInt16 size, PGPUInt8 flags) const
{
	ISP_ddb_create	ispDC;

	ispDC.ISP_ddb_hdr.ISP_func	= ISP_CREATE_DDB;
	ispDC.ISP_ddb_size			= size;
	ispDC.ISP_ddb_flags			= flags;
	
	IlbService(reinterpret_cast<PISP>(&ispDC));
	return reinterpret_cast<PDDB>(ispDC.ISP_ddb_ptr);
}

PIOP 
CIosInterface::IspCreateIop(
	PGPUInt16	size, 
	PGPUInt32	delta, 
	PGPUInt8	flags, 
	PIOP		pIop) const
{
	ISP_IOP_alloc	ispIA;

	if (IsntNull(pIop))
	{
		pgpAssert(flags & ISP_M_FL_EXTERNAL_IOP == ISP_M_FL_EXTERNAL_IOP);
	}

	ispIA.ISP_i_c_hdr.ISP_func	= ISP_CREATE_IOP;
	ispIA.ISP_IOP_size			= size;
	ispIA.ISP_delta_to_ior		= delta;
	ispIA.ISP_IOP_ptr			= (PGPUInt32) pIop;
	ispIA.ISP_i_c_flags			= flags;

	IlbService(reinterpret_cast<PISP>(&ispIA));

	if (ispIA.ISP_i_c_hdr.ISP_result == 0)
	{
		return reinterpret_cast<PIOP>(ispIA.ISP_IOP_ptr + delta - 
			FIELDOFFSET(IOP, IOP_ior));
	}
	else
	{
		return NULL;
	}
}

PGPBoolean 
CIosInterface::IspDeallocMem(void *pMem) const
{
	ISP_mem_dealloc	ispMD;
	
	ispMD.ISP_mem_da_hdr.ISP_func = ISP_DEALLOC_MEM;
	ispMD.ISP_mem_ptr_da = (ULONG) pMem;

	IlbService(reinterpret_cast<PISP>(&ispMD));
	return (ispMD.ISP_mem_da_hdr.ISP_result == 0);
}

PGPBoolean 
CIosInterface::IspDisassociateDcb(PGPUInt8 drive) const
{
	ISP_DISASSOC_DCB	ispDD;

	ispDD.ISP_dis_dcb_hdr.ISP_func = ISP_DISASSOCIATE_DCB;
	ispDD.ISP_dis_dcb_drive = drive;

	IlbService(reinterpret_cast<PISP>(&ispDD));
	return (ispDD.ISP_dis_dcb_hdr.ISP_result == 0);
}

PGPUInt8 
CIosInterface::IspDriveLetterPick(PDCB pDcb, PGPUInt8 flags) const
{
	ISP_pick_drive_letter	ispPDL;
	
	ispPDL.ISP_p_d_l_hdr.ISP_func	= ISP_DRIVE_LETTER_PICK;
	ispPDL.ISP_p_d_l_pdcb			= pDcb;
	ispPDL.ISP_p_d_l_flags			= flags;

	IlbService(reinterpret_cast<PISP>(&ispPDL));

	if (ispPDL.ISP_p_d_l_hdr.ISP_result == 0)
		return ispPDL.ISP_p_d_l_letter[0];
	else
		return 0xFF;
}

PDCB 
CIosInterface::IspGetDcb(PGPUInt8 drive) const
{
	ISP_dcb_get	ispDG;

	ispDG.ISP_g_d_hdr.ISP_func = ISP_GET_DCB;
	ispDG.ISP_g_d_drive = drive;

	IlbService(reinterpret_cast<PISP>(&ispDG));

	if (ispDG.ISP_g_d_hdr.ISP_result == 0)
		return reinterpret_cast<PDCB>(ispDG.ISP_g_d_dcb);
	else
		return NULL;
}

PGPBoolean 
CIosInterface::IspInsertCalldown(
	PDCB		pDcb, 
	void		*req, 
	PGPUInt16	expan, 
	PGPUInt32	flags) const
{
	ISP_calldown_insert	ispCI;

	pgpFillMemory(&ispCI, sizeof(ispCI), NULL);

	ispCI.ISP_i_cd_hdr.ISP_func	= ISP_INSERT_CALLDOWN;
	ispCI.ISP_i_cd_dcb			= reinterpret_cast<ULONG>(pDcb);
	ispCI.ISP_i_cd_req			= req;
	ispCI.ISP_i_cd_ddb			= reinterpret_cast<ULONG>(mDdb);
	ispCI.ISP_i_cd_expan_len	= expan;
	ispCI.ISP_i_cd_flags		= flags;
	ispCI.ISP_i_cd_lgn			= mLoadGroupNum;	

	IlbService(reinterpret_cast<PISP>(&ispCI));
	return (!ispCI.ISP_i_cd_hdr.ISP_result);
}

void * 
CIosInterface::IspAllocMem(PGPUInt16 memsize, PGPUInt8 flags) const
{
	ISP_mem_alloc	ispMA;

	ispMA.ISP_mem_a_hdr.ISP_func	= ISP_ALLOC_MEM;
	ispMA.ISP_mem_size				= memsize;
	ispMA.ISP_mem_type				= NULL;
	ispMA.ISP_mem_flags				= flags;

	IlbService(reinterpret_cast<PISP>(&ispMA));
	return reinterpret_cast<void *>(ispMA.ISP_mem_ptr);
}

void 
CIosInterface::ProcessAep(PAEP pAep)
{
	pgpAssertAddrValid(pAep, AEP);

	UDebug::DebugOut("PGPdisk: Received an %s.", 
		UConstantNamesDrv98::NameAepFunction(pAep->AEP_func));

	switch (pAep->AEP_func)
	{
	case AEP_DEVICE_INQUIRY:		// rcvd to ask how many DCBs we want
		pAep->AEP_result = AepDeviceInquiry(
			reinterpret_cast<PAEP_inquiry_device>(pAep));
		break;

	case AEP_INITIALIZE:			// recieved during IOS registration
		pAep->AEP_result = AepInitialize(
			reinterpret_cast<PAEP_bi_init>(pAep));
		break;

	case AEP_IOP_TIMEOUT:		// tells us an IOP timed out
		pAep->AEP_result = AepIopTimeout(
			reinterpret_cast<PAEP_iop_timeout_occurred>(pAep));
		break;

	default:						// default by returning success
		pAep->AEP_result = AEP_SUCCESS;
		break;
	}
}

CComboError 
CIosInterface::Startup()
{
	CComboError	error;

	mDrp = DriverMain::GetDriverDrpInitParam();
	mIlb = DriverMain::GetDriverIlbInitParam();

	// Register with the IOS.
	IOS_Register(mDrp);

	if (mDrp->DRP_reg_result != DRP_REMAIN_RESIDENT)
		error.pgpErr = kPGPError_VolumeOpFailed;

	return error;
}

PGPUInt16 
CIosInterface::AepDeviceInquiry(PAEP_inquiry_device pAEP)
{
	return AEP_NO_MORE_DEVICES;
}

PGPUInt16 
CIosInterface::AepInitialize(PAEP_bi_init pAep)
{
	mDdb = IspCreateDdb(sizeof(DDB), NULL);

	if (IsntNull(mDdb))
	{
		mLoadGroupNum = pAep->AEP_bi_i_hdr.AEP_lgn;
		return AEP_SUCCESS;
	}
	else
	{
		return AEP_FAILURE;
	}
}

PGPUInt16 
CIosInterface::AepIopTimeout(PAEP_iop_timeout_occurred pAEP)
{
	CIop	iop(reinterpret_cast<PIOP>(pAEP->AEP_i_t_o_iop));

	// see if this request is going TO a PGPdisk
	char	root[4]	= {UString::NumberToLetter(iop.Drive()), ':', '\\', '\0'};

	if (CDriverSubsystems::PGPdiskHandler().IsRootAMountedPGPdisk(root))
	{
		UDebug::DebugOut("PGPdisk: Resetting timed-out I/O to a PGPdisk.");
		iop.Timer() = iop.TimerOrig();
		
		return AEP_SUCCESS;
	}
	else
	{
		return AEP_FAILURE;
	}
}

⌨️ 快捷键说明

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