2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Keyboard class driver
4 * FILE: drivers/input/kbdclass/misc.c
5 * PURPOSE: Misceallenous operations
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
14 static IO_COMPLETION_ROUTINE ForwardIrpAndWaitCompletion
;
17 ForwardIrpAndWaitCompletion(
18 IN PDEVICE_OBJECT DeviceObject
,
22 if (Irp
->PendingReturned
)
23 KeSetEvent((PKEVENT
)Context
, IO_NO_INCREMENT
, FALSE
);
24 return STATUS_MORE_PROCESSING_REQUIRED
;
29 IN PDEVICE_OBJECT DeviceObject
,
32 PDEVICE_OBJECT LowerDevice
;
36 ASSERT(!((PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->IsClassDO
);
37 LowerDevice
= ((PPORT_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->LowerDevice
;
39 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
40 IoCopyCurrentIrpStackLocationToNext(Irp
);
42 TRACE_(CLASS_NAME
, "Calling lower device %p\n", LowerDevice
);
43 IoSetCompletionRoutine(Irp
, ForwardIrpAndWaitCompletion
, &Event
, TRUE
, TRUE
, TRUE
);
45 Status
= IoCallDriver(LowerDevice
, Irp
);
46 if (Status
== STATUS_PENDING
)
48 Status
= KeWaitForSingleObject(&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
49 if (NT_SUCCESS(Status
))
50 Status
= Irp
->IoStatus
.Status
;
58 IN PDEVICE_OBJECT DeviceObject
,
61 PDEVICE_OBJECT LowerDevice
;
63 ASSERT(!((PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->IsClassDO
);
64 LowerDevice
= ((PPORT_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->LowerDevice
;
66 IoSkipCurrentIrpStackLocation(Irp
);
67 return IoCallDriver(LowerDevice
, Irp
);
71 DuplicateUnicodeString(
73 IN PCUNICODE_STRING SourceString
,
74 OUT PUNICODE_STRING DestinationString
)
76 if (SourceString
== NULL
|| DestinationString
== NULL
77 || SourceString
->Length
> SourceString
->MaximumLength
78 || (SourceString
->Length
== 0 && SourceString
->MaximumLength
> 0 && SourceString
->Buffer
== NULL
)
79 || Flags
== RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
|| Flags
>= 4)
81 return STATUS_INVALID_PARAMETER
;
85 if ((SourceString
->Length
== 0)
86 && (Flags
!= (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
|
87 RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
)))
89 DestinationString
->Length
= 0;
90 DestinationString
->MaximumLength
= 0;
91 DestinationString
->Buffer
= NULL
;
95 USHORT DestMaxLength
= SourceString
->Length
;
97 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
98 DestMaxLength
+= sizeof(UNICODE_NULL
);
100 DestinationString
->Buffer
= ExAllocatePoolWithTag(PagedPool
, DestMaxLength
, CLASS_TAG
);
101 if (DestinationString
->Buffer
== NULL
)
102 return STATUS_NO_MEMORY
;
104 RtlCopyMemory(DestinationString
->Buffer
, SourceString
->Buffer
, SourceString
->Length
);
105 DestinationString
->Length
= SourceString
->Length
;
106 DestinationString
->MaximumLength
= DestMaxLength
;
108 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
109 DestinationString
->Buffer
[DestinationString
->Length
/ sizeof(WCHAR
)] = 0;
112 return STATUS_SUCCESS
;