ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

misc.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:     ReactOS i8042 (ps/2 keyboard-mouse controller) driver
00003  * LICENSE:     GPL - See COPYING in the top level directory
00004  * FILE:        drivers/input/i8042prt/misc.c
00005  * PURPOSE:     Misceallenous operations
00006  * PROGRAMMERS: Copyright 2006-2007 Hervé Poussineau (hpoussin@reactos.org)
00007  */
00008 
00009 /* INCLUDES ******************************************************************/
00010 
00011 #include "i8042prt.h"
00012 
00013 /* FUNCTIONS *****************************************************************/
00014 static IO_COMPLETION_ROUTINE ForwardIrpAndWaitCompletion;
00015 
00016 static NTSTATUS NTAPI
00017 ForwardIrpAndWaitCompletion(
00018     IN PDEVICE_OBJECT DeviceObject,
00019     IN PIRP Irp,
00020     IN PVOID Context)
00021 {
00022     UNREFERENCED_PARAMETER(DeviceObject);
00023     if (Irp->PendingReturned)
00024         KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
00025     return STATUS_MORE_PROCESSING_REQUIRED;
00026 }
00027 
00028 NTSTATUS NTAPI
00029 ForwardIrpAndWait(
00030     IN PDEVICE_OBJECT DeviceObject,
00031     IN PIRP Irp)
00032 {
00033     KEVENT Event;
00034     NTSTATUS Status;
00035     PDEVICE_OBJECT LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
00036     ASSERT(LowerDevice);
00037 
00038     KeInitializeEvent(&Event, NotificationEvent, FALSE);
00039     IoCopyCurrentIrpStackLocationToNext(Irp);
00040 
00041     IoSetCompletionRoutine(Irp, ForwardIrpAndWaitCompletion, &Event, TRUE, TRUE, TRUE);
00042 
00043     Status = IoCallDriver(LowerDevice, Irp);
00044     if (Status == STATUS_PENDING)
00045     {
00046         Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
00047         if (NT_SUCCESS(Status))
00048             Status = Irp->IoStatus.Status;
00049     }
00050 
00051     return Status;
00052 }
00053 
00054 NTSTATUS NTAPI
00055 ForwardIrpAndForget(
00056     IN PDEVICE_OBJECT DeviceObject,
00057     IN PIRP Irp)
00058 {
00059     PDEVICE_OBJECT LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
00060 
00061     ASSERT(LowerDevice);
00062 
00063     IoSkipCurrentIrpStackLocation(Irp);
00064     return IoCallDriver(LowerDevice, Irp);
00065 }
00066 
00067 NTSTATUS
00068 DuplicateUnicodeString(
00069     IN ULONG Flags,
00070     IN PCUNICODE_STRING SourceString,
00071     OUT PUNICODE_STRING DestinationString)
00072 {
00073     if (SourceString == NULL || DestinationString == NULL
00074      || SourceString->Length > SourceString->MaximumLength
00075      || (SourceString->Length == 0 && SourceString->MaximumLength > 0 && SourceString->Buffer == NULL)
00076      || Flags == RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING || Flags >= 4)
00077     {
00078         return STATUS_INVALID_PARAMETER;
00079     }
00080 
00081 
00082     if ((SourceString->Length == 0)
00083      && (Flags != (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE | 
00084                    RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING)))
00085     {
00086         DestinationString->Length = 0;
00087         DestinationString->MaximumLength = 0;
00088         DestinationString->Buffer = NULL;
00089     }
00090     else
00091     {
00092         USHORT DestMaxLength = SourceString->Length;
00093 
00094         if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE)
00095             DestMaxLength += sizeof(UNICODE_NULL);
00096 
00097         DestinationString->Buffer = ExAllocatePoolWithTag(PagedPool, DestMaxLength, I8042PRT_TAG);
00098         if (DestinationString->Buffer == NULL)
00099             return STATUS_NO_MEMORY;
00100 
00101         RtlCopyMemory(DestinationString->Buffer, SourceString->Buffer, SourceString->Length);
00102         DestinationString->Length = SourceString->Length;
00103         DestinationString->MaximumLength = DestMaxLength;
00104 
00105         if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE)
00106             DestinationString->Buffer[DestinationString->Length / sizeof(WCHAR)] = 0;
00107     }
00108 
00109     return STATUS_SUCCESS;
00110 }

Generated on Sat May 26 2012 04:15:48 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.