Use ObOpenObjectByPointer instead of creating ourselves the IRP_MJ_CREATE/CLEANUP/CLOSE IRPs

svn path=/trunk/; revision=22729
This commit is contained in:
Hervé Poussineau 2006-06-30 21:47:42 +00:00
parent f8b990739a
commit 5179858da1
2 changed files with 33 additions and 85 deletions

View file

@ -60,44 +60,6 @@ DeviceIoControl(
return Status;
}
static NTSTATUS
SendIrp(
IN PDEVICE_OBJECT DeviceObject,
IN ULONG MajorFunction)
{
KEVENT Event;
PIRP Irp;
IO_STATUS_BLOCK IoStatus;
NTSTATUS Status;
KeInitializeEvent(&Event, NotificationEvent, FALSE);
Irp = IoBuildSynchronousFsdRequest(
MajorFunction,
DeviceObject,
NULL,
0,
NULL,
&Event,
&IoStatus);
if (Irp == NULL)
{
DPRINT("IoBuildSynchronousFsdRequest() failed\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)
{
DPRINT("Operation pending\n");
KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
Status = IoStatus.Status;
}
return Status;
}
static NTSTATUS
ReadBytes(
IN PDEVICE_OBJECT LowerDevice,
@ -256,6 +218,7 @@ SerenumDetectPnpDevice(
IN PDEVICE_OBJECT DeviceObject,
IN PDEVICE_OBJECT LowerDevice)
{
HANDLE Handle = NULL;
UCHAR Buffer[256];
ULONG BaudRate;
ULONG_PTR TotalBytesReceived = 0;
@ -270,7 +233,14 @@ SerenumDetectPnpDevice(
NTSTATUS Status;
/* Open port */
Status = SendIrp(LowerDevice, IRP_MJ_CREATE);
Status = ObOpenObjectByPointer(
LowerDevice,
OBJ_KERNEL_HANDLE,
NULL,
0,
NULL,
KernelMode,
&Handle);
if (!NT_SUCCESS(Status)) goto ByeBye;
/* 1. COM port initialization, check for device enumerate */
@ -459,8 +429,8 @@ DisconnectIdle:
ByeBye:
/* Close port */
SendIrp(LowerDevice, IRP_MJ_CLOSE);
SendIrp(LowerDevice, IRP_MJ_CLEANUP);
if (Handle)
ZwClose(Handle);
return Status;
}
@ -469,6 +439,7 @@ SerenumDetectLegacyDevice(
IN PDEVICE_OBJECT DeviceObject,
IN PDEVICE_OBJECT LowerDevice)
{
HANDLE Handle = NULL;
ULONG Fcr, Mcr;
ULONG BaudRate;
ULONG Command;
@ -490,7 +461,14 @@ SerenumDetectLegacyDevice(
RtlZeroMemory(Buffer, sizeof(Buffer));
/* Open port */
Status = SendIrp(LowerDevice, IRP_MJ_CREATE);
Status = ObOpenObjectByPointer(
LowerDevice,
OBJ_EXCLUSIVE | OBJ_KERNEL_HANDLE,
NULL,
0,
NULL,
KernelMode,
&Handle);
if (!NT_SUCCESS(Status)) return Status;
/* Reset UART */
@ -610,7 +588,7 @@ SerenumDetectLegacyDevice(
ByeBye:
/* Close port */
SendIrp(LowerDevice, IRP_MJ_CLOSE);
SendIrp(LowerDevice, IRP_MJ_CLEANUP);
if (Handle)
ZwClose(Handle);
return Status;
}

View file

@ -63,44 +63,6 @@ DeviceIoControl(
return Status;
}
static NTSTATUS
SendIrp(
IN PDEVICE_OBJECT DeviceObject,
IN ULONG MajorFunction)
{
KEVENT Event;
PIRP Irp;
IO_STATUS_BLOCK IoStatus;
NTSTATUS Status;
KeInitializeEvent(&Event, NotificationEvent, FALSE);
Irp = IoBuildSynchronousFsdRequest(
MajorFunction,
DeviceObject,
NULL,
0,
NULL,
&Event,
&IoStatus);
if (Irp == NULL)
{
DPRINT("IoBuildSynchronousFsdRequest() failed\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)
{
DPRINT("Operation pending\n");
KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
Status = IoStatus.Status;
}
return Status;
}
static NTSTATUS
ReadBytes(
IN PDEVICE_OBJECT LowerDevice,
@ -155,6 +117,7 @@ SERMOUSE_MOUSE_TYPE
SermouseDetectLegacyDevice(
IN PDEVICE_OBJECT LowerDevice)
{
HANDLE Handle;
ULONG Fcr, Mcr;
ULONG BaudRate;
ULONG Command;
@ -170,7 +133,14 @@ SermouseDetectLegacyDevice(
RtlZeroMemory(Buffer, sizeof(Buffer));
/* Open port */
Status = SendIrp(LowerDevice, IRP_MJ_CREATE);
Status = ObOpenObjectByPointer(
LowerDevice,
OBJ_EXCLUSIVE | OBJ_KERNEL_HANDLE,
NULL,
0,
NULL,
KernelMode,
&Handle);
if (!NT_SUCCESS(Status)) return mtNone;
/* Reset UART */
@ -268,7 +238,7 @@ SermouseDetectLegacyDevice(
ByeBye:
/* Close port */
SendIrp(LowerDevice, IRP_MJ_CLOSE);
SendIrp(LowerDevice, IRP_MJ_CLEANUP);
if (Handle)
ZwClose(Handle);
return MouseType;
}