ReactOS 0.4.16-dev-250-g3ecd236
main.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Named Pipe FileSystem
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/filesystems/npfs/main.c
5 * PURPOSE: Named Pipe FileSystem Driver Initialization
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include "npfs.h"
12
13// File ID number for NPFS bugchecking support
14#define NPFS_BUGCHECK_FILE_ID (NPFS_BUGCHECK_MAIN)
15
16/* GLOBALS ********************************************************************/
17
22
24{
25 sizeof(FAST_IO_DISPATCH),
26 NULL,
27 NpFastRead,
28 NpFastWrite,
29};
30
31/* FUNCTIONS ******************************************************************/
32
42{
44 PWSTR CurrentString;
46 PNPFS_ALIAS CurrentAlias;
47 UNICODE_STRING TempString;
48 PUNICODE_STRING CurrentTargetName;
49
50 /* Check if we have the expected type */
52 {
54 }
55
56 /* Check if only the size is requested */
57 if (QueryContext->SizeOnly)
58 {
59 /* Count this entry */
60 QueryContext->NumberOfEntries++;
61
62 /* Get the length of the value name (i.e. the target name). */
63 Length = wcslen(ValueName) * sizeof(WCHAR);
64
65 /* Add the size of the name plus a '\' and a UNICODE_STRING structure */
66 QueryContext->FullSize += Length + sizeof(UNICODE_NULL) +
68 sizeof(UNICODE_STRING);
69
70 /* Loop while we have alias names */
71 CurrentString = ValueData;
72 while (*CurrentString != UNICODE_NULL)
73 {
74 /* Count this alias */
75 QueryContext->NumberOfAliases++;
76
77 /* Get the length of the current string (i.e. the alias name) */
78 Length = wcslen(CurrentString) * sizeof(WCHAR);
79
80 /* Count the length plus the size of an NPFS_ALIAS structure */
81 QueryContext->FullSize += Length + sizeof(UNICODE_NULL) + sizeof(NPFS_ALIAS);
82
83 /* Go to the next string */
84 CurrentString += (Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR);
85 }
86 }
87 else
88 {
89 /* Get the next name string pointer */
90 CurrentTargetName = QueryContext->CurrentTargetName++;
91
92 /* Get the length of the value name (i.e. the target name). */
93 Length = wcslen(ValueName) * sizeof(WCHAR);
94
95 /* Initialize the current name string (one char more than the name) */
96 CurrentTargetName->Buffer = QueryContext->CurrentStringPointer;
97 CurrentTargetName->Length = Length + sizeof(OBJ_NAME_PATH_SEPARATOR);
98 CurrentTargetName->MaximumLength = CurrentTargetName->Length + sizeof(UNICODE_NULL);
99
100 /* Update the current string pointer */
101 QueryContext->CurrentStringPointer +=
102 CurrentTargetName->MaximumLength / sizeof(WCHAR);
103
104 /* Prepend a '\' before the name */
105 CurrentTargetName->Buffer[0] = OBJ_NAME_PATH_SEPARATOR;
106
107 /* Append the value name (including the NULL termination) */
108 RtlCopyMemory(&CurrentTargetName->Buffer[1],
109 ValueName,
110 Length + sizeof(UNICODE_NULL));
111
112 /* Upcase the target name */
113 RtlUpcaseUnicodeString(CurrentTargetName, CurrentTargetName, 0);
114
115 /* Loop while we have alias names */
116 CurrentString = ValueData;
117 while (*CurrentString != UNICODE_NULL)
118 {
119 /* Get the next alias pointer */
120 CurrentAlias = QueryContext->CurrentAlias++;
121
122 /* Get the length of the current string (i.e. the alias name) */
123 Length = wcslen(CurrentString) * sizeof(WCHAR);
124
125 /* Setup the alias structure */
126 CurrentAlias->TargetName = CurrentTargetName;
127 CurrentAlias->Name.Buffer = QueryContext->CurrentStringPointer;
128 CurrentAlias->Name.Length = Length;
129 CurrentAlias->Name.MaximumLength = Length + sizeof(UNICODE_NULL);
130
131 /* Upcase the alias name */
132 TempString.Buffer = CurrentString;
133 TempString.Length = Length;
134 RtlUpcaseUnicodeString(&CurrentAlias->Name,
135 &TempString,
136 FALSE);
137
138 /* Update the current string pointer */
139 QueryContext->CurrentStringPointer +=
140 CurrentAlias->Name.MaximumLength / sizeof(WCHAR);
141
142 /* Go to the next string */
143 CurrentString += (Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR);
144 }
145 }
146
147 return STATUS_SUCCESS;
148}
149
150LONG
151NTAPI
153 _In_ PCUNICODE_STRING String1,
155{
156 ULONG Count;
157 PWCHAR P1, P2;
158
159 /* First check if the string sizes match */
160 if (String1->Length != String2->Length)
161 {
162 /* They don't, return positive if the first is longer, negative otherwise */
163 return String1->Length - String2->Length;
164 }
165
166 /* Now loop all characters */
167 Count = String1->Length / sizeof(WCHAR);
168 P1 = String1->Buffer;
169 P2 = String2->Buffer;
170 while (Count)
171 {
172 /* Check if they don't match */
173 if (*P1 != *P2)
174 {
175 /* Return positive if the first char is greater, negative otherwise */
176 return *P1 - *P2;
177 }
178
179 /* Go to the next buffer position */
180 P1++;
181 P2++;
182 Count--;
183 }
184
185 /* All characters matched, return 0 */
186 return 0;
187}
188
190NTAPI
192{
197 ULONG i;
198 PNPFS_ALIAS CurrentAlias, *AliasPointer;
199
200 /* Initialize the query table */
203 QueryTable[0].Name = NULL;
209 QueryTable[1].Flags = 0;
210 QueryTable[1].Name = NULL;
211
212 /* Setup the query context */
213 Context.SizeOnly = 1;
214 Context.FullSize = 0;
215 Context.NumberOfAliases = 0;
216 Context.NumberOfEntries = 0;
217
218 /* Query the registry values (calculate length only) */
220 L"Npfs\\Aliases",
222 &Context,
223 NULL);
224 if (!NT_SUCCESS(Status))
225 {
227 return STATUS_SUCCESS;
228
229 return Status;
230 }
231
232 /* Check if there is anything */
233 if (Context.FullSize == 0)
234 {
235 /* Nothing to do, return success */
236 return STATUS_SUCCESS;
237 }
238
239 /* Allocate a structure large enough to hold all the data */
241 if (NpAliases == NULL)
243
244 /* Now setup the actual pointers in the context */
245 Context.CurrentTargetName = NpAliases;
246 CurrentAlias = (PNPFS_ALIAS)&Context.CurrentTargetName[Context.NumberOfEntries];
247 Context.CurrentAlias = CurrentAlias;
248 Context.CurrentStringPointer = (PWCHAR)&CurrentAlias[Context.NumberOfAliases];
249
250 /* This time query the real data */
251 Context.SizeOnly = FALSE;
253 L"Npfs\\Aliases",
255 &Context,
256 NULL);
257 if (!NT_SUCCESS(Status))
258 {
260 NpAliases = NULL;
261 return Status;
262 }
263
264 /* Make sure we didn't go past the end of the allocation! */
265 NT_ASSERT((PUCHAR)Context.CurrentStringPointer <=
266 ((PUCHAR)NpAliases + Context.FullSize));
267
268 /* Loop all aliases we got */
269 for (i = 0; i < Context.NumberOfAliases; i++)
270 {
271 /* Get the length and check what list to use */
272 Length = CurrentAlias->Name.Length;
273 if ((Length >= MIN_INDEXED_LENGTH * sizeof(WCHAR)) &&
274 (Length <= MAX_INDEXED_LENGTH * sizeof(WCHAR)))
275 {
276 /* For this length range, we use an indexed list */
277 AliasPointer = &NpAliasListByLength[(Length / sizeof(WCHAR)) - 5];
278 }
279 else
280 {
281 /* Length is outside of the range, use the default list */
282 AliasPointer = &NpAliasList;
283 }
284
285 /* Loop through all aliases already in the list until we find one that
286 is greater than our current alias */
287 while ((*AliasPointer != NULL) &&
288 (NpCompareAliasNames(&CurrentAlias->Name,
289 &(*AliasPointer)->Name) > 0))
290 {
291 /* Go to the next alias */
292 AliasPointer = &(*AliasPointer)->Next;
293 }
294
295 /* Insert the alias in the list */
296 CurrentAlias->Next = *AliasPointer;
297 *AliasPointer = CurrentAlias;
298
299 /* Go to the next alias in the array */
300 CurrentAlias++;
301 }
302
303 return STATUS_SUCCESS;
304}
305
306
308NTAPI
310 IN PIRP Irp)
311{
312 TRACE("Entered\n");
314
315 Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
316 Irp->IoStatus.Information = 0;
317
320}
321
322
324NTAPI
327{
332
333 DPRINT("Next-Generation NPFS-Advanced\n");
334
336 if (!NT_SUCCESS(Status))
337 {
338 DPRINT1("Failed to initialize aliases!\n");
339 return Status;
340 }
341
342 DriverObject->MajorFunction[IRP_MJ_CREATE] = NpFsdCreate;
344 DriverObject->MajorFunction[IRP_MJ_CLOSE] = NpFsdClose;
345 DriverObject->MajorFunction[IRP_MJ_READ] = NpFsdRead;
346 DriverObject->MajorFunction[IRP_MJ_WRITE] = NpFsdWrite;
350 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = NpFsdCleanup;
356
357 DriverObject->DriverUnload = NULL;
358
359 DriverObject->FastIoDispatch = &NpFastIoDispatch;
360
361 RtlInitUnicodeString(&DeviceName, L"\\Device\\NamedPipe");
363 sizeof(NP_VCB),
364 &DeviceName,
366 0,
367 FALSE,
368 &DeviceObject);
369 if (!NT_SUCCESS(Status))
370 {
371 DPRINT1("Failed to create named pipe device! (Status %lx)\n", Status);
372 return Status;
373 }
374
375 /* Initialize the device object */
378
379 /* Initialize the Volume Control Block (VCB) */
380 NpVcb = DeviceObject->DeviceExtension;
384 return STATUS_SUCCESS;
385}
386
387/* EOF */
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
DRIVER_INITIALIZE DriverEntry
Definition: main.c:9
NTSTATUS NTAPI NpFsdCleanup(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: cleanup.c:58
NTSTATUS NTAPI NpFsdClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: close.c:59
NTSTATUS NTAPI NpFsdCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: create.c:360
NTSTATUS NTAPI NpFsdCreateNamedPipe(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: create.c:791
NTSTATUS NTAPI NpFsdQueryInformation(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fileinfo.c:461
NTSTATUS NTAPI NpFsdSetInformation(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fileinfo.c:114
LONG NTAPI NpCompareAliasNames(_In_ PCUNICODE_STRING String1, _In_ PCUNICODE_STRING String2)
Definition: main.c:152
PNPFS_ALIAS NpAliasList
Definition: main.c:20
NTSTATUS NTAPI NpFsdDirectoryControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: main.c:309
FAST_IO_DISPATCH NpFastIoDispatch
Definition: main.c:23
PDEVICE_OBJECT NpfsDeviceObject
Definition: main.c:18
NTSTATUS NTAPI NpReadAlias(PWSTR ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueLength, PVOID Context, PVOID EntryContext)
Definition: main.c:35
PVOID NpAliases
Definition: main.c:19
PNPFS_ALIAS NpAliasListByLength[MAX_INDEXED_LENGTH+1 - MIN_INDEXED_LENGTH]
Definition: main.c:21
NTSTATUS NTAPI NpInitializeAliases(VOID)
Definition: main.c:191
VOID NTAPI NpInitializeVcb(VOID)
Definition: strucsup.c:130
struct _NPFS_ALIAS * PNPFS_ALIAS
PNP_VCB NpVcb
Definition: strucsup.c:19
NTSTATUS NTAPI NpFsdQuerySecurityInfo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: seinfo.c:100
NTSTATUS NTAPI NpFsdWrite(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: write.c:175
NTSTATUS NTAPI NpCreateRootDcb(VOID)
Definition: strucsup.c:165
NTSTATUS NTAPI NpFsdQueryVolumeInformation(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volinfo.c:181
NTSTATUS NTAPI NpFsdRead(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: read.c:159
NTSTATUS NTAPI NpFsdSetSecurityInfo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: seinfo.c:125
#define MAX_INDEXED_LENGTH
Definition: npfs.h:33
#define MIN_INDEXED_LENGTH
Definition: npfs.h:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define DO_LONG_TERM_REQUESTS
Definition: env_spec_w32.h:401
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
struct _UNICODE_STRING UNICODE_STRING
#define NonPagedPool
Definition: env_spec_w32.h:307
NTSTATUS NTAPI NpFsdFlushBuffers(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: flushbuf.c:70
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ const STRING * String2
Definition: rtlfuncs.h:2369
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:4219
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4220
#define _In_
Definition: no_sal2.h:158
int Count
Definition: noreturn.cpp:7
NTSTATUS NTAPI NpFsdFileSystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fsctrl.c:857
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RTL_QUERY_REGISTRY_NOEXPAND
Definition: nt_native.h:139
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define RTL_REGISTRY_SERVICES
Definition: nt_native.h:162
#define REG_NONE
Definition: nt_native.h:1492
#define RTL_REGISTRY_OPTIONAL
Definition: nt_native.h:169
#define UNICODE_NULL
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define IoCompleteRequest
Definition: irp.c:1240
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
unsigned short USHORT
Definition: pedump.c:61
#define FILE_DEVICE_NAMED_PIPE
Definition: winioctl.h:62
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
#define TRACE(s)
Definition: solgame.cpp:4
PUNICODE_STRING TargetName
Definition: npfs.h:294
struct _NPFS_ALIAS * Next
Definition: npfs.h:293
UNICODE_STRING Name
Definition: npfs.h:295
PUNICODE_STRING CurrentTargetName
Definition: npfs.h:306
PNPFS_ALIAS CurrentAlias
Definition: npfs.h:305
PWCHAR CurrentStringPointer
Definition: npfs.h:307
Definition: npfs.h:278
PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine
Definition: nt_native.h:109
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:282
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:275
#define IRP_MJ_CREATE_NAMED_PIPE
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define IRP_MJ_QUERY_SECURITY
struct _FAST_IO_DISPATCH FAST_IO_DISPATCH
#define IRP_MJ_FLUSH_BUFFERS
#define IRP_MJ_SET_SECURITY
#define IRP_MJ_CLEANUP
#define NT_ASSERT
Definition: rtlfuncs.h:3327
__wchar_t WCHAR
Definition: xmlstorage.h:180