📄 ioctl.c
字号:
/*++
Copyright (c) 1998 Microsoft Corporation
Module Name:
ioctl.c
Abstract
Author:
Peter Binder (pbinder) 4/13/98
Revision History:
Date Who What
-------- --------- ------------------------------------------------------------
4/13/98 pbinder taken from 1394diag/ohcidiag
--*/
#include "pch.h"
NTSTATUS
t1394Diag_IoControl(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PIO_STACK_LOCATION IrpSp;
PDEVICE_EXTENSION deviceExtension;
PVOID ioBuffer;
ULONG inputBufferLength;
ULONG outputBufferLength;
ULONG ioControlCode;
ENTER("t1394Diag_IoControl");
// Get a pointer to the current location in the Irp. This is where
// the function codes and parameters are located.
IrpSp = IoGetCurrentIrpStackLocation(Irp);
// Get a pointer to the device extension
deviceExtension = DeviceObject->DeviceExtension;
// Get the pointer to the input/output buffer and it's length
ioBuffer = Irp->AssociatedIrp.SystemBuffer;
inputBufferLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
outputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
// make sure our device isn't in shutdown mode...
if (deviceExtension->bShutdown) {
Irp->IoStatus.Status = STATUS_NO_SUCH_DEVICE;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return(ntStatus);
}
TRACE(TL_TRACE, ("Irp = 0x%x\n", Irp));
switch (IrpSp->MajorFunction) {
case IRP_MJ_DEVICE_CONTROL:
TRACE(TL_TRACE, ("t1394Diag_IoControl: IRP_MJ_DEVICE_CONTROL\n"));
ioControlCode = IrpSp->Parameters.DeviceIoControl.IoControlCode;
switch (ioControlCode) {
case IOCTL_ALLOCATE_ADDRESS_RANGE:
{
PALLOCATE_ADDRESS_RANGE AllocateAddressRange;
TRACE(TL_TRACE, ("IOCTL_ALLOCATE_ADDRESS_RANGE\n"));
if ((inputBufferLength < sizeof(ALLOCATE_ADDRESS_RANGE)) ||
(outputBufferLength < sizeof(ALLOCATE_ADDRESS_RANGE))) {
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
else {
AllocateAddressRange = (PALLOCATE_ADDRESS_RANGE)ioBuffer;
ntStatus = t1394Diag_AllocateAddressRange( DeviceObject,
Irp,
AllocateAddressRange->fulAllocateFlags,
AllocateAddressRange->fulFlags,
AllocateAddressRange->nLength,
AllocateAddressRange->MaxSegmentSize,
AllocateAddressRange->fulAccessType,
AllocateAddressRange->fulNotificationOptions,
&AllocateAddressRange->Required1394Offset,
&AllocateAddressRange->hAddressRange,
(PULONG)&AllocateAddressRange->Data
);
if (NT_SUCCESS(ntStatus))
Irp->IoStatus.Information = outputBufferLength;
}
}
break; // IOCTL_ALLOCATE_ADDRESS_RANGE
case IOCTL_FREE_ADDRESS_RANGE:
TRACE(TL_TRACE, ("IOCTL_FREE_ADDRESS_RANGE\n"));
if (inputBufferLength < sizeof(HANDLE)) {
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
else {
ntStatus = t1394Diag_FreeAddressRange( DeviceObject,
Irp,
*(PHANDLE)ioBuffer
);
}
break; // IOCTL_FREE_ADDRESS_RANGE
case IOCTL_ASYNC_READ:
{
PASYNC_READ AsyncRead;
TRACE(TL_TRACE, ("IOCTL_ASYNC_READ\n"));
if (inputBufferLength < sizeof(ASYNC_READ)) {
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
else {
AsyncRead = (PASYNC_READ)ioBuffer;
if ((outputBufferLength < sizeof(ASYNC_READ)) ||
(outputBufferLength-sizeof(ASYNC_READ) < AsyncRead->nNumberOfBytesToRead)) {
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
else {
ntStatus = t1394Diag_AsyncRead( DeviceObject,
Irp,
AsyncRead->bRawMode,
AsyncRead->bGetGeneration,
AsyncRead->DestinationAddress,
AsyncRead->nNumberOfBytesToRead,
AsyncRead->nBlockSize,
AsyncRead->fulFlags,
AsyncRead->ulGeneration,
(PULONG)&AsyncRead->Data
);
if (NT_SUCCESS(ntStatus))
Irp->IoStatus.Information = outputBufferLength;
}
}
}
break; // IOCTL_ASYNC_READ
case IOCTL_ASYNC_WRITE:
{
PASYNC_WRITE AsyncWrite;
TRACE(TL_TRACE, ("IOCTL_ASYNC_WRITE\n"));
if (inputBufferLength < sizeof(ASYNC_WRITE)) {
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
else {
AsyncWrite = (PASYNC_WRITE)ioBuffer;
if (inputBufferLength-sizeof(ASYNC_WRITE) < AsyncWrite->nNumberOfBytesToWrite) {
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
else {
ntStatus = t1394Diag_AsyncWrite( DeviceObject,
Irp,
AsyncWrite->bRawMode,
AsyncWrite->bGetGeneration,
AsyncWrite->DestinationAddress,
AsyncWrite->nNumberOfBytesToWrite,
AsyncWrite->nBlockSize,
AsyncWrite->fulFlags,
AsyncWrite->ulGeneration,
(PULONG)&AsyncWrite->Data
);
}
}
}
break; // IOCTL_ASYNC_WRITE
case IOCTL_ASYNC_LOCK:
{
PASYNC_LOCK AsyncLock;
TRACE(TL_TRACE, ("IOCTL_ASYNC_LOCK\n"));
if ((inputBufferLength < sizeof(ASYNC_LOCK)) ||
(outputBufferLength < sizeof(ASYNC_LOCK))) {
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
else {
AsyncLock = (PASYNC_LOCK)ioBuffer;
ntStatus = t1394Diag_AsyncLock( DeviceObject,
Irp,
AsyncLock->bRawMode,
AsyncLock->bGetGeneration,
AsyncLock->DestinationAddress,
AsyncLock->nNumberOfArgBytes,
AsyncLock->nNumberOfDataBytes,
AsyncLock->fulTransactionType,
AsyncLock->fulFlags,
AsyncLock->Arguments,
AsyncLock->DataValues,
AsyncLock->ulGeneration,
(PVOID)&AsyncLock->Buffer
);
if (NT_SUCCESS(ntStatus))
Irp->IoStatus.Information = outputBufferLength;
}
}
break; // IOCTL_ASYNC_LOCK
case IOCTL_ASYNC_STREAM:
{
PASYNC_STREAM AsyncStream;
TRACE(TL_TRACE, ("IOCTL_ASYNC_STREAM\n"));
if (inputBufferLength < sizeof(ASYNC_STREAM)) {
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
else {
AsyncStream = (PASYNC_STREAM)ioBuffer;
if (outputBufferLength < sizeof(ASYNC_STREAM)+AsyncStream->nNumberOfBytesToStream) {
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
else {
ntStatus = t1394Diag_AsyncStream( DeviceObject,
Irp,
AsyncStream->nNumberOfBytesToStream,
AsyncStream->fulFlags,
AsyncStream->ulTag,
AsyncStream->nChannel,
AsyncStream->ulSynch,
(UCHAR)AsyncStream->nSpeed,
(PULONG)&AsyncStream->Data
);
if (NT_SUCCESS(ntStatus))
Irp->IoStatus.Information = outputBufferLength;
}
}
}
break; // IOCTL_ASYNC_STREAM
case IOCTL_ISOCH_ALLOCATE_BANDWIDTH:
{
PISOCH_ALLOCATE_BANDWIDTH IsochAllocateBandwidth;
TRACE(TL_TRACE, ("IOCTL_ISOCH_ALLOCATE_BANDWIDTH\n"));
if ((inputBufferLength < sizeof(ISOCH_ALLOCATE_BANDWIDTH)) ||
(outputBufferLength < sizeof(ISOCH_ALLOCATE_BANDWIDTH))) {
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
else {
IsochAllocateBandwidth = (PISOCH_ALLOCATE_BANDWIDTH)ioBuffer;
ntStatus = t1394Diag_IsochAllocateBandwidth( DeviceObject,
Irp,
IsochAllocateBandwidth->nMaxBytesPerFrameRequested,
IsochAllocateBandwidth->fulSpeed,
&IsochAllocateBandwidth->hBandwidth,
&IsochAllocateBandwidth->BytesPerFrameAvailable,
&IsochAllocateBandwidth->SpeedSelected
);
if (NT_SUCCESS(ntStatus))
Irp->IoStatus.Information = outputBufferLength;
}
}
break; // IOCTL_ISOCH_ALLOCATE_BANDWIDTH
case IOCTL_ISOCH_ALLOCATE_CHANNEL:
{
PISOCH_ALLOCATE_CHANNEL IsochAllocateChannel;
TRACE(TL_TRACE, ("IOCTL_ISOCH_ALLOCATE_CHANNEL\n"));
if ((inputBufferLength < sizeof(ISOCH_ALLOCATE_CHANNEL)) ||
(outputBufferLength < sizeof(ISOCH_ALLOCATE_CHANNEL))) {
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
else {
IsochAllocateChannel = (PISOCH_ALLOCATE_CHANNEL)ioBuffer;
ntStatus = t1394Diag_IsochAllocateChannel( DeviceObject,
Irp,
IsochAllocateChannel->nRequestedChannel,
&IsochAllocateChannel->Channel,
&IsochAllocateChannel->ChannelsAvailable
);
if (NT_SUCCESS(ntStatus))
Irp->IoStatus.Information = outputBufferLength;
}
}
break; // IOCTL_ISOCH_ALLOCATE_CHANNEL
case IOCTL_ISOCH_ALLOCATE_RESOURCES:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -