1 /*
2 * PROJECT: ReactOS Named Pipe FileSystem
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/filesystems/npfs/prefxsup.c
5 * PURPOSE: Pipes Prefixes Support
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_PREFXSUP)
15
16 /* FUNCTIONS ******************************************************************/
17
18 PNP_FCB
19 NTAPI
NpFindPrefix(IN PUNICODE_STRING Name,IN ULONG CaseInsensitiveIndex,IN PUNICODE_STRING Prefix)20 NpFindPrefix(IN PUNICODE_STRING Name,
21 IN ULONG CaseInsensitiveIndex,
22 IN PUNICODE_STRING Prefix)
23 {
24 PUNICODE_PREFIX_TABLE_ENTRY Entry;
25 PNP_FCB Fcb;
26 PAGED_CODE();
27
28 Entry = RtlFindUnicodePrefix(&NpVcb->PrefixTable,
29 Name,
30 CaseInsensitiveIndex);
31 if (!Entry) NpBugCheck(0, 0, 0);
32
33 Fcb = CONTAINING_RECORD(Entry, NP_FCB, PrefixTableEntry);
34
35 Prefix->Length = Name->Length - Fcb->FullName.Length;
36 Prefix->MaximumLength = Prefix->Length;
37 Prefix->Buffer = &Name->Buffer[Fcb->FullName.Length / sizeof(WCHAR)];
38
39 if ((Prefix->Length) && (Prefix->Buffer[0] == OBJ_NAME_PATH_SEPARATOR))
40 {
41 Prefix->Length -= sizeof(WCHAR);
42 Prefix->MaximumLength -= sizeof(WCHAR);
43 ++Prefix->Buffer;
44 }
45
46 return Fcb;
47 }
48
49 NTSTATUS
50 NTAPI
NpFindRelativePrefix(IN PNP_DCB Dcb,IN PUNICODE_STRING Name,IN ULONG CaseInsensitiveIndex,IN PUNICODE_STRING Prefix,OUT PNP_FCB * FoundFcb)51 NpFindRelativePrefix(IN PNP_DCB Dcb,
52 IN PUNICODE_STRING Name,
53 IN ULONG CaseInsensitiveIndex,
54 IN PUNICODE_STRING Prefix,
55 OUT PNP_FCB *FoundFcb)
56 {
57 PWCHAR Buffer;
58 PNP_FCB Fcb;
59 UNICODE_STRING RootName;
60 USHORT Length, MaximumLength;
61 PAGED_CODE();
62
63 Length = Name->Length;
64 MaximumLength = Length + sizeof(OBJ_NAME_PATH_SEPARATOR) + sizeof(UNICODE_NULL);
65 if (MaximumLength < Length) return STATUS_INVALID_PARAMETER;
66
67 ASSERT(Dcb->NodeType == NPFS_NTC_ROOT_DCB);
68
69 Buffer = ExAllocatePoolWithTag(PagedPool, MaximumLength, NPFS_NAME_BLOCK_TAG);
70 if (!Buffer)
71 {
72 return STATUS_INSUFFICIENT_RESOURCES;
73 }
74
75 *Buffer = OBJ_NAME_PATH_SEPARATOR;
76 RtlCopyMemory(Buffer + 1, Name->Buffer, Length);
77 Buffer[(Length / sizeof(WCHAR)) + 1] = UNICODE_NULL;
78
79 RootName.Length = Length + sizeof(OBJ_NAME_PATH_SEPARATOR);
80 RootName.MaximumLength = MaximumLength;
81 RootName.Buffer = Buffer;
82
83 Fcb = NpFindPrefix(&RootName, CaseInsensitiveIndex, Prefix);
84
85 ExFreePool(Buffer);
86
87 Prefix->Buffer = &Name->Buffer[(Length - Prefix->Length) / sizeof(WCHAR)];
88 *FoundFcb = Fcb;
89
90 return STATUS_SUCCESS;
91 }
92
93 /* EOF */
94