📄 asyncapi.c
字号:
}
if (!NT_SUCCESS(ntStatus)) {
TRACE(TL_ERROR, ("SubmitIrpSync failed = 0x%x\n", ntStatus));
}
// need to free up everything associated with this allocate...
if (AsyncAddressData->pMdl)
IoFreeMdl(AsyncAddressData->pMdl);
if (AsyncAddressData->Buffer)
ExFreePool(AsyncAddressData->Buffer);
if (AsyncAddressData->AddressRange)
ExFreePool(AsyncAddressData->AddressRange);
if (AsyncAddressData)
ExFreePool(AsyncAddressData);
}
else {
// we couldn't match the handles!
TRACE(TL_ERROR, ("Invalid handle = 0x%x", hAddressRange));
ntStatus = STATUS_INVALID_PARAMETER;
goto Exit_FreeAddressRange;
}
Exit_FreeAddressRange:
if (pIrb)
{
ExFreePool(pIrb);
}
if (allocNewIrp)
{
Irp->IoStatus = ioStatus;
}
EXIT("t1394_FreeAddressRange", ntStatus);
return(ntStatus);
} // t1394_FreeAddressRange
NTSTATUS
t1394_GetAddressData(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN HANDLE hAddressRange,
IN ULONG nLength,
IN ULONG ulOffset,
OUT PVOID Data
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
KIRQL Irql;
PASYNC_ADDRESS_DATA AsyncAddressData;
ENTER("t1394_GetAddressData");
TRACE(TL_TRACE, ("hAddressRange = 0x%x\n", hAddressRange));
TRACE(TL_TRACE, ("nLength = 0x%x\n", nLength));
TRACE(TL_TRACE, ("ulOffset = 0x%x\n", ulOffset));
// have to find our struct...
KeAcquireSpinLock(&deviceExtension->AsyncSpinLock, &Irql);
AsyncAddressData = (PASYNC_ADDRESS_DATA) deviceExtension->AsyncAddressData.Flink;
while (AsyncAddressData) {
if (AsyncAddressData->hAddressRange == hAddressRange) {
PCHAR pBuffer;
ULONG i;
// found it, let's copy over the contents to our buffer
pBuffer = (PCHAR)((ULONG_PTR)AsyncAddressData->Buffer + ulOffset);
TRACE(TL_TRACE, ("pBuffer = 0x%x\n", pBuffer));
TRACE(TL_TRACE, ("Data = 0x%x\n", Data));
RtlCopyMemory(Data, pBuffer, nLength);
break;
}
else if (AsyncAddressData->AsyncAddressList.Flink == &deviceExtension->AsyncAddressData) {
AsyncAddressData = NULL;
break;
}
else
AsyncAddressData = (PASYNC_ADDRESS_DATA)AsyncAddressData->AsyncAddressList.Flink;
}
KeReleaseSpinLock(&deviceExtension->AsyncSpinLock, Irql);
// never found an entry...
if (!AsyncAddressData) {
ntStatus = STATUS_INVALID_PARAMETER;
}
EXIT("t1394_GetAddressData", ntStatus);
return(ntStatus);
} // t1394_GetAddressData
NTSTATUS
t1394_SetAddressData(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN HANDLE hAddressRange,
IN ULONG nLength,
IN ULONG ulOffset,
IN PVOID Data
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
KIRQL Irql;
PASYNC_ADDRESS_DATA AsyncAddressData;
ENTER("t1394_SetAddressData");
TRACE(TL_TRACE, ("hAddressRange = 0x%x\n", hAddressRange));
TRACE(TL_TRACE, ("nLength = 0x%x\n", nLength));
TRACE(TL_TRACE, ("ulOffset = 0x%x\n", ulOffset));
// have to find our struct...
KeAcquireSpinLock(&deviceExtension->AsyncSpinLock, &Irql);
AsyncAddressData = (PASYNC_ADDRESS_DATA) deviceExtension->AsyncAddressData.Flink;
while (AsyncAddressData) {
if (AsyncAddressData->hAddressRange == hAddressRange) {
PULONG pBuffer;
// found it, let's copy over the contents from data...
pBuffer = (PULONG)((ULONG_PTR)AsyncAddressData->Buffer + ulOffset);
TRACE(TL_TRACE, ("pBuffer = 0x%x\n", pBuffer));
TRACE(TL_TRACE, ("Data = 0x%x\n", Data));
RtlCopyMemory(pBuffer, Data, nLength);
break;
}
else if (AsyncAddressData->AsyncAddressList.Flink == &deviceExtension->AsyncAddressData) {
AsyncAddressData = NULL;
break;
}
else
AsyncAddressData = (PASYNC_ADDRESS_DATA)AsyncAddressData->AsyncAddressList.Flink;
}
KeReleaseSpinLock(&deviceExtension->AsyncSpinLock, Irql);
// never found an entry...
if (!AsyncAddressData) {
ntStatus = STATUS_INVALID_PARAMETER;
}
EXIT("t1394_SetAddressData", ntStatus);
return(ntStatus);
} // t1394_SetAddressData
NTSTATUS
t1394_AsyncRead(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN ULONG bRawMode,
IN ULONG bGetGeneration,
IN IO_ADDRESS DestinationAddress,
IN ULONG nNumberOfBytesToRead,
IN ULONG nBlockSize,
IN ULONG fulFlags,
IN ULONG ulGeneration,
IN OUT PULONG Data
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
PIRB pIrb = NULL;
PMDL pMdl = NULL;
PDEVICE_OBJECT NextDeviceObject = NULL;
PIRP newIrp = NULL;
BOOLEAN allocNewIrp = FALSE;
KEVENT Event;
IO_STATUS_BLOCK ioStatus;
ENTER("t1394_AsyncRead");
TRACE(TL_TRACE, ("bRawMode = %d\n", bRawMode));
TRACE(TL_TRACE, ("bGetGeneration = %d\n", bGetGeneration));
TRACE(TL_TRACE, ("DestinationAddress.IA_Destination_ID.NA_Bus_Number = 0x%x\n", DestinationAddress.IA_Destination_ID.NA_Bus_Number));
TRACE(TL_TRACE, ("DestinationAddress.IA_Destination_ID.NA_Node_Number = 0x%x\n", DestinationAddress.IA_Destination_ID.NA_Node_Number));
TRACE(TL_TRACE, ("DestinationAddress.IA_Destination_Offset.Off_High = 0x%x\n", DestinationAddress.IA_Destination_Offset.Off_High));
TRACE(TL_TRACE, ("DestinationAddress.IA_Destination_Offset.Off_Low = 0x%x\n", DestinationAddress.IA_Destination_Offset.Off_Low));
TRACE(TL_TRACE, ("nNumberOfBytesToRead = 0x%x\n", nNumberOfBytesToRead));
TRACE(TL_TRACE, ("nBlockSize = 0x%x\n", nBlockSize));
TRACE(TL_TRACE, ("fulFlags = 0x%x\n", fulFlags));
TRACE(TL_TRACE, ("ulGeneration = 0x%x\n", ulGeneration));
TRACE(TL_TRACE, ("Data = 0x%x\n", Data));
if (nNumberOfBytesToRead == 0) {
TRACE(TL_ERROR, ("Invalid nNumberOfBytesToRead size!\n"));
ntStatus = STATUS_INVALID_PARAMETER;
goto Exit_AsyncRead;
}
//
// get the location of the next device object in the stack
//
if (bRawMode) {
NextDeviceObject = deviceExtension->PortDeviceObject;
}
else {
NextDeviceObject = deviceExtension->StackDeviceObject;
}
//
// If this is a UserMode request create a newIrp so that the request
// will be issued from KernelMode
//
if (Irp->RequestorMode == UserMode) {
newIrp = IoBuildDeviceIoControlRequest (IOCTL_1394_CLASS, NextDeviceObject,
NULL, 0, NULL, 0, TRUE, &Event, &ioStatus);
if (!newIrp) {
TRACE(TL_ERROR, ("Failed to allocate newIrp!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_AsyncRead;
}
allocNewIrp = TRUE;
}
pIrb = ExAllocatePool(NonPagedPool, sizeof(IRB));
if (!pIrb) {
TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_AsyncRead;
} // if
RtlZeroMemory (pIrb, sizeof (IRB));
pIrb->FunctionNumber = REQUEST_ASYNC_READ;
pIrb->Flags = 0;
pIrb->u.AsyncRead.DestinationAddress = DestinationAddress;
pIrb->u.AsyncRead.nNumberOfBytesToRead = nNumberOfBytesToRead;
pIrb->u.AsyncRead.nBlockSize = nBlockSize;
pIrb->u.AsyncRead.fulFlags = fulFlags;
if (bGetGeneration) {
pIrb->u.AsyncRead.ulGeneration = deviceExtension->GenerationCount;
TRACE(TL_TRACE, ("Retrieved Generation Count = 0x%x\n", pIrb->u.AsyncRead.ulGeneration));
}
else {
pIrb->u.AsyncRead.ulGeneration = ulGeneration;
}
pMdl = IoAllocateMdl (Data,
nNumberOfBytesToRead,
FALSE,
FALSE,
NULL);
MmBuildMdlForNonPagedPool(pMdl);
pIrb->u.AsyncRead.Mdl = pMdl;
//
// If we allocated this irp, submit it asynchronously and wait for its
// completion event to be signaled. Otherwise submit it synchronously
//
if (allocNewIrp) {
KeInitializeEvent (&Event, NotificationEvent, FALSE);
ntStatus = t1394_SubmitIrpAsync (NextDeviceObject, newIrp, pIrb);
if (ntStatus == STATUS_PENDING) {
KeWaitForSingleObject (&Event, Executive, KernelMode, FALSE, NULL);
ntStatus = ioStatus.Status;
}
}
else {
ntStatus = t1394_SubmitIrpSynch(NextDeviceObject, Irp, pIrb);
}
if (!NT_SUCCESS(ntStatus)) {
TRACE(TL_ERROR, ("SubmitIrpSync failed = 0x%x\n", ntStatus));
if (ntStatus != STATUS_INVALID_GENERATION) {
}
}
else {
}
Exit_AsyncRead:
if (pMdl)
{
IoFreeMdl(pMdl);
}
if (pIrb)
{
ExFreePool(pIrb);
}
if (allocNewIrp)
{
Irp->IoStatus = ioStatus;
}
EXIT("t1394_AsyncRead", ntStatus);
return(ntStatus);
} // t1394_AsyncRead
NTSTATUS
t1394_AsyncWrite(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN ULONG bRawMode,
IN ULONG bGetGeneration,
IN IO_ADDRESS DestinationAddress,
IN ULONG nNumberOfBytesToWrite,
IN ULONG nBlockSize,
IN ULONG fulFlags,
IN ULONG ulGeneration,
IN OUT PULONG Data
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
PIRB pIrb = NULL;
PMDL pMdl = NULL;
PDEVICE_OBJECT NextDeviceObject = NULL;
PIRP newIrp = NULL;
BOOLEAN allocNewIrp = FALSE;
KEVENT Event;
IO_STATUS_BLOCK ioStatus;
ENTER("t1394_AsyncWrite");
TRACE(TL_TRACE, ("bRawMode = %d\n", bRawMode));
TRACE(TL_TRACE, ("bGetGeneration = %d\n", bGetGeneration));
TRACE(TL_TRACE, ("DestinationAddress.IA_Destination_ID.NA_Bus_Number = 0x%x\n", DestinationAddress.IA_Destination_ID.NA_Bus_Number));
TRACE(TL_TRACE, ("DestinationAddress.IA_Destination_ID.NA_Node_Number = 0x%x\n", DestinationAddress.IA_Destination_ID.NA_Node_Number));
TRACE(TL_TRACE, ("DestinationAddress.IA_Destination_Offset.Off_High = 0x%x\n", DestinationAddress.IA_Destination_Offset.Off_High));
TRACE(TL_TRACE, ("DestinationAddress.IA_Destination_Offset.Off_Low = 0x%x\n", DestinationAddress.IA_Destination_Offset.Off_Low));
TRACE(TL_TRACE, ("nNumberOfBytesToWrite = 0x%x\n", nNumberOfBytesToWrite));
TRACE(TL_TRACE, ("nBlockSize = 0x%x\n", nBlockSize));
TRACE(TL_TRACE, ("fulFlags = 0x%x\n", fulFlags));
TRACE(TL_TRACE, ("ulGeneration = 0x%x\n", ulGeneration));
TRACE(TL_TRACE, ("Data = 0x%x\n", Data));
if (nNumberOfBytesToWrite == 0) {
TRACE(TL_ERROR, ("Invalid nNumberOfBytesToWrite size!\n"));
ntStatus = STATUS_INVALID_PARAMETER;
goto Exit_AsyncWrite;
}
//
// get the location of the next device object in the stack
//
if (bRawMode) {
NextDeviceObject = deviceExtension->PortDeviceObject;
}
else {
NextDeviceObject = deviceExtension->StackDeviceObject;
}
//
// If this is a UserMode request create a newIrp so that the request
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -