2 * PROJECT: ReactOS i8042 (ps/2 keyboard-mouse controller) driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/input/i8042prt/misc.c
5 * PURPOSE: Misceallenous operations
6 * PROGRAMMERS: Copyright 2006-2007 Hervé Poussineau (hpoussin@reactos.org)
9 /* INCLUDES ******************************************************************/
13 /* FUNCTIONS *****************************************************************/
14 static IO_COMPLETION_ROUTINE ForwardIrpAndWaitCompletion
;
17 ForwardIrpAndWaitCompletion(
18 IN PDEVICE_OBJECT DeviceObject
,
22 UNREFERENCED_PARAMETER(DeviceObject
);
23 if (Irp
->PendingReturned
)
24 KeSetEvent((PKEVENT
)Context
, IO_NO_INCREMENT
, FALSE
);
25 return STATUS_MORE_PROCESSING_REQUIRED
;
30 IN PDEVICE_OBJECT DeviceObject
,
35 PDEVICE_OBJECT LowerDevice
= ((PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->LowerDevice
;
38 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
39 IoCopyCurrentIrpStackLocationToNext(Irp
);
41 IoSetCompletionRoutine(Irp
, ForwardIrpAndWaitCompletion
, &Event
, TRUE
, TRUE
, TRUE
);
43 Status
= IoCallDriver(LowerDevice
, Irp
);
44 if (Status
== STATUS_PENDING
)
46 Status
= KeWaitForSingleObject(&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
47 if (NT_SUCCESS(Status
))
48 Status
= Irp
->IoStatus
.Status
;
56 IN PDEVICE_OBJECT DeviceObject
,
59 PDEVICE_OBJECT LowerDevice
= ((PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->LowerDevice
;
63 IoSkipCurrentIrpStackLocation(Irp
);
64 return IoCallDriver(LowerDevice
, Irp
);
68 DuplicateUnicodeString(
70 IN PCUNICODE_STRING SourceString
,
71 OUT PUNICODE_STRING DestinationString
)
73 if (SourceString
== NULL
|| DestinationString
== NULL
74 || SourceString
->Length
> SourceString
->MaximumLength
75 || (SourceString
->Length
== 0 && SourceString
->MaximumLength
> 0 && SourceString
->Buffer
== NULL
)
76 || Flags
== RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
|| Flags
>= 4)
78 return STATUS_INVALID_PARAMETER
;
82 if ((SourceString
->Length
== 0)
83 && (Flags
!= (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
|
84 RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
)))
86 DestinationString
->Length
= 0;
87 DestinationString
->MaximumLength
= 0;
88 DestinationString
->Buffer
= NULL
;
92 USHORT DestMaxLength
= SourceString
->Length
;
94 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
95 DestMaxLength
+= sizeof(UNICODE_NULL
);
97 DestinationString
->Buffer
= ExAllocatePoolWithTag(PagedPool
, DestMaxLength
, I8042PRT_TAG
);
98 if (DestinationString
->Buffer
== NULL
)
99 return STATUS_NO_MEMORY
;
101 RtlCopyMemory(DestinationString
->Buffer
, SourceString
->Buffer
, SourceString
->Length
);
102 DestinationString
->Length
= SourceString
->Length
;
103 DestinationString
->MaximumLength
= DestMaxLength
;
105 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
106 DestinationString
->Buffer
[DestinationString
->Length
/ sizeof(WCHAR
)] = 0;
109 return STATUS_SUCCESS
;