📄 asyncapi.c
字号:
// 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_AsyncWrite;
}
allocNewIrp = TRUE;
}
pIrb = ExAllocatePool(NonPagedPool, sizeof(IRB));
if (!pIrb) {
TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_AsyncWrite;
} // if
RtlZeroMemory (pIrb, sizeof (IRB));
pIrb->FunctionNumber = REQUEST_ASYNC_WRITE;
pIrb->Flags = 0;
pIrb->u.AsyncWrite.DestinationAddress = DestinationAddress;
pIrb->u.AsyncWrite.nNumberOfBytesToWrite = nNumberOfBytesToWrite;
pIrb->u.AsyncWrite.nBlockSize = nBlockSize;
pIrb->u.AsyncWrite.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,
nNumberOfBytesToWrite,
FALSE,
FALSE,
NULL);
MmBuildMdlForNonPagedPool(pMdl);
pIrb->u.AsyncWrite.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_AsyncWrite:
if (pMdl)
{
IoFreeMdl(pMdl);
}
if (pIrb)
{
ExFreePool(pIrb);
}
if (allocNewIrp)
{
Irp->IoStatus = ioStatus;
}
EXIT("t1394_AsyncWrite", ntStatus);
return(ntStatus);
} // t1394_AsyncWrite
NTSTATUS
t1394_AsyncLock(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN ULONG bRawMode,
IN ULONG bGetGeneration,
IN IO_ADDRESS DestinationAddress,
IN ULONG nNumberOfArgBytes,
IN ULONG nNumberOfDataBytes,
IN ULONG fulTransactionType,
IN ULONG fulFlags,
IN ULONG Arguments[2],
IN ULONG DataValues[2],
IN ULONG ulGeneration,
IN OUT PVOID Buffer
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
PIRB pIrb = NULL;
PDEVICE_OBJECT NextDeviceObject = NULL;
PIRP newIrp = NULL;
BOOLEAN allocNewIrp = FALSE;
KEVENT Event;
IO_STATUS_BLOCK ioStatus;
ENTER("t1394_AsyncLock");
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, ("nNumberOfArgBytes = 0x%x\n", nNumberOfArgBytes));
TRACE(TL_TRACE, ("nNumberOfDataBytes = 0x%x\n", nNumberOfDataBytes));
TRACE(TL_TRACE, ("fulTransactionType = 0x%x\n", fulTransactionType));
TRACE(TL_TRACE, ("fulFlags = 0x%x\n", fulFlags));
TRACE(TL_TRACE, ("Arguments[0] = 0x%x\n", Arguments[0]));
TRACE(TL_TRACE, ("Arguments[1] = 0x%x\n", Arguments[1]));
TRACE(TL_TRACE, ("DataValues[0] = 0x%x\n", DataValues[0]));
TRACE(TL_TRACE, ("DataValues[1] = 0x%x\n", DataValues[1]));
TRACE(TL_TRACE, ("ulGeneration = 0x%x\n", ulGeneration));
TRACE(TL_TRACE, ("Buffer = 0x%x\n", Buffer));
//
// 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_AsyncLock;
}
allocNewIrp = TRUE;
}
pIrb = ExAllocatePool(NonPagedPool, sizeof(IRB));
if (!pIrb) {
TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_AsyncLock;
} // if
RtlZeroMemory (pIrb, sizeof (IRB));
pIrb->FunctionNumber = REQUEST_ASYNC_LOCK;
pIrb->Flags = 0;
pIrb->u.AsyncLock.DestinationAddress = DestinationAddress;
pIrb->u.AsyncLock.nNumberOfArgBytes = nNumberOfArgBytes;
pIrb->u.AsyncLock.nNumberOfDataBytes = nNumberOfDataBytes;
pIrb->u.AsyncLock.fulTransactionType = fulTransactionType;
pIrb->u.AsyncLock.fulFlags = fulFlags;
pIrb->u.AsyncLock.Arguments[0] = Arguments[0];
pIrb->u.AsyncLock.Arguments[1] = Arguments[1];
pIrb->u.AsyncLock.DataValues[0] = DataValues[0];
pIrb->u.AsyncLock.DataValues[1] = DataValues[1];
pIrb->u.AsyncLock.pBuffer = Buffer;
if (bGetGeneration) {
pIrb->u.AsyncLock.ulGeneration = deviceExtension->GenerationCount;
TRACE(TL_TRACE, ("Retrieved Generation Count = 0x%x\n", pIrb->u.AsyncLock.ulGeneration));
}
else {
pIrb->u.AsyncLock.ulGeneration = ulGeneration;
}
//
// 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) {
}
}
Exit_AsyncLock:
if (pIrb)
{
ExFreePool(pIrb);
}
if (allocNewIrp)
{
Irp->IoStatus = ioStatus;
}
EXIT("t1394_AsyncLock", ntStatus);
return(ntStatus);
} // t1394_AsyncLock
NTSTATUS
t1394_AsyncStream(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN ULONG nNumberOfBytesToStream,
IN ULONG fulFlags,
IN ULONG ulTag,
IN ULONG nChannel,
IN ULONG ulSynch,
IN UCHAR nSpeed,
IN OUT PULONG Data
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
PIRB pIrb = NULL;
PMDL pMdl = NULL;
PIRP newIrp = NULL;
BOOLEAN allocNewIrp = FALSE;
KEVENT Event;
IO_STATUS_BLOCK ioStatus;
ENTER("t1394_AsyncStream");
TRACE(TL_TRACE, ("nNumberOfBytesToStream = 0x%x\n", nNumberOfBytesToStream));
TRACE(TL_TRACE, ("fulFlags = 0x%x\n", fulFlags));
TRACE(TL_TRACE, ("ulTag = 0x%x\n", ulTag));
TRACE(TL_TRACE, ("nChannel = 0x%x\n", nChannel));
TRACE(TL_TRACE, ("ulSynch = 0x%x\n", ulSynch));
TRACE(TL_TRACE, ("nSpeed = 0x%x\n", nSpeed));
if (nNumberOfBytesToStream == 0) {
TRACE(TL_ERROR, ("Invalid nNumberOfBytesToStream size!\n"));
ntStatus = STATUS_INVALID_PARAMETER;
goto Exit_AsyncStream;
}
//
// 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, deviceExtension->StackDeviceObject,
NULL, 0, NULL, 0, TRUE, &Event, &ioStatus);
if (!newIrp) {
TRACE(TL_ERROR, ("Failed to allocate newIrp!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_AsyncStream;
}
allocNewIrp = TRUE;
}
pIrb = ExAllocatePool(NonPagedPool, sizeof(IRB));
if (!pIrb) {
TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_AsyncStream;
} // if
RtlZeroMemory (pIrb, sizeof (IRB));
pIrb->FunctionNumber = REQUEST_ASYNC_STREAM;
pIrb->Flags = 0;
pIrb->u.AsyncStream.nNumberOfBytesToStream = nNumberOfBytesToStream;
pIrb->u.AsyncStream.fulFlags = fulFlags;
pIrb->u.AsyncStream.ulTag = ulTag;
pIrb->u.AsyncStream.nChannel = nChannel;
pIrb->u.AsyncStream.ulSynch = ulSynch;
pIrb->u.AsyncStream.nSpeed = nSpeed;
pMdl = IoAllocateMdl (Data,
nNumberOfBytesToStream,
FALSE,
FALSE,
NULL);
if (!pMdl) {
TRACE(TL_ERROR, ("Failed to allocate pMdl!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_AsyncStream;
}
MmBuildMdlForNonPagedPool(pMdl);
pIrb->u.AsyncStream.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 (deviceExtension->StackDeviceObject, newIrp, pIrb);
if (ntStatus == STATUS_PENDING) {
KeWaitForSingleObject (&Event, Executive, KernelMode, FALSE, NULL);
ntStatus = ioStatus.Status;
}
}
else {
ntStatus = t1394_SubmitIrpSynch(deviceExtension->StackDeviceObject, Irp, pIrb);
}
if (!NT_SUCCESS(ntStatus)) {
TRACE(TL_ERROR, ("SubmitIrpSync failed = 0x%x\n", ntStatus));
}
Exit_AsyncStream:
if (pMdl)
{
IoFreeMdl(pMdl);
}
if (pIrb)
{
ExFreePool(pIrb);
}
if (allocNewIrp)
{
Irp->IoStatus = ioStatus;
}
EXIT("t1394_AsyncStream", ntStatus);
return(ntStatus);
} // t1394_AsyncStream
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -