我想挂钩所有BlockIo协议,但我不知道逻辑分区的BlockIo协议是否是基于逻辑分区所属的硬件设备的BlockIo协议产生的!我的钩子代码如下所示。
EFI_BLOCK_IO_PROTOCOL* OldBlockIO=NULL;
EFI_BLOCK_IO_PROTOCOL* NewBlockIO=NULL;
EFI_STATUS EFIAPI NewReadBlocks(IN EFI_BLOCK_IO_PROTOCOL *This,IN UINT32 MediaId,IN EFI_LBA LBA,IN UINTN BufferSize,OUT VOID *Buffer)
{
//do other things
return OldBlockIO->ReadBlocks(OldBlockIO,MediaId,LBA,BufferSize,Buffer);
}
EFI_STATUS EFIAPI NewWriteBlocks(IN EFI_BLOCK_IO_PROTOCOL *This,IN UINT32 MediaId,IN EFI_LBA LBA,IN UINTN BufferSize,IN VOID *Buffer)
{
//do other things
return OldBlockIO->WriteBlocks(OldBlockIO,OldBlockIO->Media->MediaId,LBA,BufferSize,Buffer);
}
EFI_STATUS EFIAPI HookBlockIOProtocol()
{
EFI_STATUS Status=EFI_SUCCESS;
/*
Allocating memory for NewBlockIO
copy OldBlockIo to NewBlockIo
*/
//overridde the members
NewBlockIO->ReadBlocks=(EFI_BLOCK_READ)NewReadBlocks;
NewBlockIO->WriteBlocks=(EFI_BLOCK_WRITE)NewWriteBlocks;
//hook block io using ReinstallProtocolInterface boot service
Status=gBS->ReinstallProtocolInterface(BlockControllerHandles[0],&gEfiBlockIoProtocolGuid,(VOID*)OldBlockIO[0],(VOID*)NewBlockIO[0]);
if (EFI_ERROR(Status))
{
gBS->FreePool((VOID*)NewBlockIO[0]);
Print(L"(HookBlockIOProtocol0:Print)gBS->ReinstallProtocolInterface for BlockControllerHandles[0]=%p failed,status=%d.\r\n",BlockControllerHandles[0],Status);
PauseProgram();
}
return Status;
}