2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Mouse class driver
4 * FILE: drivers/input/mouclass/misc.c
5 * PURPOSE: Misceallenous operations
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
12 static IO_COMPLETION_ROUTINE ForwardIrpAndWaitCompletion
;
15 ForwardIrpAndWaitCompletion(
16 IN PDEVICE_OBJECT DeviceObject
,
20 if (Irp
->PendingReturned
)
21 KeSetEvent((PKEVENT
)Context
, IO_NO_INCREMENT
, FALSE
);
22 return STATUS_MORE_PROCESSING_REQUIRED
;
27 IN PDEVICE_OBJECT DeviceObject
,
30 PDEVICE_OBJECT LowerDevice
;
34 ASSERT(!((PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->IsClassDO
);
35 LowerDevice
= ((PPORT_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->LowerDevice
;
37 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
38 IoCopyCurrentIrpStackLocationToNext(Irp
);
40 TRACE_(CLASS_NAME
, "Calling lower device %p\n", LowerDevice
);
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
;
61 ASSERT(!((PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->IsClassDO
);
62 LowerDevice
= ((PPORT_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->LowerDevice
;
64 IoSkipCurrentIrpStackLocation(Irp
);
65 return IoCallDriver(LowerDevice
, Irp
);
69 DuplicateUnicodeString(
71 IN PCUNICODE_STRING SourceString
,
72 OUT PUNICODE_STRING DestinationString
)
74 if (SourceString
== NULL
|| DestinationString
== NULL
75 || SourceString
->Length
> SourceString
->MaximumLength
76 || (SourceString
->Length
== 0 && SourceString
->MaximumLength
> 0 && SourceString
->Buffer
== NULL
)
77 || Flags
== RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
|| Flags
>= 4)
79 return STATUS_INVALID_PARAMETER
;
83 if ((SourceString
->Length
== 0)
84 && (Flags
!= (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
|
85 RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
)))
87 DestinationString
->Length
= 0;
88 DestinationString
->MaximumLength
= 0;
89 DestinationString
->Buffer
= NULL
;
93 USHORT DestMaxLength
= SourceString
->Length
;
95 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
96 DestMaxLength
+= sizeof(UNICODE_NULL
);
98 DestinationString
->Buffer
= ExAllocatePoolWithTag(PagedPool
, DestMaxLength
, CLASS_TAG
);
99 if (DestinationString
->Buffer
== NULL
)
100 return STATUS_NO_MEMORY
;
102 RtlCopyMemory(DestinationString
->Buffer
, SourceString
->Buffer
, SourceString
->Length
);
103 DestinationString
->Length
= SourceString
->Length
;
104 DestinationString
->MaximumLength
= DestMaxLength
;
106 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
107 DestinationString
->Buffer
[DestinationString
->Length
/ sizeof(WCHAR
)] = 0;
110 return STATUS_SUCCESS
;