ReactOS 0.4.15-dev-7942-gd23573b
misc.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Serial enumerator driver
4 * FILE: drivers/dd/serenum/misc.c
5 * PURPOSE: Miscellaneous operations
6 *
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.com)
8 */
9
10#include "serenum.h"
11
12#include <debug.h>
13
14/* I really want PCSZ strings as last arguments because
15 * PnP ids are ANSI-encoded in PnP device string
16 * identification */
20 ... /* list of PCSZ */)
21{
26 ULONG DestinationSize = 0;
28
30
31 /* Calculate length needed for destination unicode string */
34 while (Source != NULL)
35 {
37 DestinationSize += RtlAnsiStringToUnicodeSize(&AnsiString)
38 + sizeof(WCHAR) /* final NULL */;
40 }
41 va_end(args);
42 if (DestinationSize == 0)
43 {
45 return STATUS_SUCCESS;
46 }
47
48 /* Initialize destination string */
49 DestinationSize += sizeof(WCHAR); // final NULL
51 if (!Destination->Buffer)
54 Destination->MaximumLength = (USHORT)DestinationSize;
55
56 /* Copy arguments to destination string */
57 /* Use a temporary unicode string, which buffer is shared with
58 * destination string, to copy arguments */
64 while (Source != NULL)
65 {
68 if (!NT_SUCCESS(Status))
69 {
71 break;
72 }
73 Destination->Length += UnicodeString.Length + sizeof(WCHAR);
74 UnicodeString.MaximumLength -= UnicodeString.Length + sizeof(WCHAR);
75 UnicodeString.Buffer += UnicodeString.Length / sizeof(WCHAR) + 1;
76 UnicodeString.Length = 0;
78 }
79 va_end(args);
80 if (NT_SUCCESS(Status))
81 {
82 /* Finish multi-sz string */
83 Destination->Buffer[Destination->Length / sizeof(WCHAR)] = L'\0';
84 Destination->Length += sizeof(WCHAR);
85 }
86 return Status;
87}
88
92 IN PIRP Irp)
93{
94 PFDO_DEVICE_EXTENSION DeviceExtension;
95 PDEVICE_OBJECT LowerDevice;
96
97 DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
98 ASSERT(DeviceExtension->Common.IsFDO);
99
100 LowerDevice = DeviceExtension->LowerDevice;
101 ASSERT(LowerDevice);
102 TRACE_(SERENUM, "Calling lower device 0x%p\n", LowerDevice);
104 return IoCallDriver(LowerDevice, Irp);
105}
106
110 IN PIRP Irp)
111{
112 PPDO_DEVICE_EXTENSION DeviceExtension;
114
115 DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
116 ASSERT(!DeviceExtension->Common.IsFDO);
117
118 Fdo = DeviceExtension->AttachedFdo;
119 ASSERT(Fdo);
120 TRACE_(SERENUM, "Calling attached Fdo 0x%p\n", Fdo);
122 return IoCallDriver(Fdo, Irp);
123}
124
128 IN PIRP Irp)
129{
130 PDEVICE_OBJECT LowerDevice;
131
132 ASSERT(((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO);
133 LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
134 ASSERT(LowerDevice);
135
137 return IoCallDriver(LowerDevice, Irp);
138}
139
142 IN ULONG Flags,
145{
150 {
152 }
153
154
155 if ((SourceString->Length == 0)
158 {
162 }
163 else
164 {
165 USHORT DestMaxLength = SourceString->Length;
166
168 DestMaxLength += sizeof(UNICODE_NULL);
169
172 return STATUS_NO_MEMORY;
173
176 DestinationString->MaximumLength = DestMaxLength;
177
180 }
181
182 return STATUS_SUCCESS;
183}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define va_arg(ap, T)
Definition: acmsvcex.h:89
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TRACE_(x)
Definition: compat.h:76
@ AnsiString
Definition: dnslib.h:19
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
NTSTATUS DuplicateUnicodeString(IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
Definition: misc.c:31
NTSTATUS SerenumInitMultiSzString(OUT PUNICODE_STRING Destination,...)
Definition: misc.c:18
NTSTATUS NTAPI ForwardIrpToAttachedFdoAndForget(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: misc.c:108
NTSTATUS NTAPI ForwardIrpToLowerDeviceAndForget(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: misc.c:90
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
#define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
Definition: green.h:16
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: green.h:15
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1910
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3004
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1909
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define RtlAnsiStringToUnicodeSize(STRING)
Definition: nt_native.h:404
#define UNICODE_NULL
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
#define args
Definition: format.c:66
#define SERENUM_TAG
Definition: serenum.h:58
#define STATUS_SUCCESS
Definition: shellext.h:65
PDEVICE_OBJECT LowerDevice
Definition: i8042prt.h:130
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:84
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:59
PDEVICE_OBJECT AttachedFdo
Definition: parport.h:59
unsigned short Length
Definition: sprintf.c:451
void * Buffer
Definition: sprintf.c:453
unsigned short MaximumLength
Definition: sprintf.c:452
USHORT MaximumLength
Definition: env_spec_w32.h:370
Definition: match.c:390
uint16_t * PWSTR
Definition: typedefs.h:56
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
CONST char * PCSZ
Definition: umtypes.h:125
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__wchar_t WCHAR
Definition: xmlstorage.h:180