ReactOS 0.4.17-dev-573-g8315b8c
name.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/fsrtl/name.c
5 * PURPOSE: Provides name parsing and other support routines for FSDs
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Filip Navara (navaraf@reactos.org)
8 * Pierre Schweitzer (pierre.schweitzer@reactos.org)
9 * Aleksey Bragin (aleksey@reactos.org)
10 */
11
12/* INCLUDES ******************************************************************/
13
14#include <ntoskrnl.h>
15#define NDEBUG
16#include <debug.h>
17
18/* PUBLIC FUNCTIONS **********************************************************/
19
20/*++
21 * @name FsRtlAreNamesEqual
22 * @implemented
23 *
24 * Compare two strings to check if they match
25 *
26 * @param Name1
27 * First unicode string to compare
28 *
29 * @param Name2
30 * Second unicode string to compare
31 *
32 * @param IgnoreCase
33 * If TRUE, Case will be ignored when comparing strings
34 *
35 * @param UpcaseTable
36 * Table for upcase letters. If NULL is given, system one will be used
37 *
38 * @return TRUE if the strings are equal
39 *
40 * @remarks From Bo Branten's ntifs.h v25.
41 *
42 *--*/
49{
50 UNICODE_STRING UpcaseName1;
51 UNICODE_STRING UpcaseName2;
52 BOOLEAN StringsAreEqual, MemoryAllocated = FALSE;
53 USHORT i;
55 PAGED_CODE();
56
57 /* Well, first check their size */
58 if (Name1->Length != Name2->Length) return FALSE;
59
60 /* Check if the caller didn't give an upcase table */
61 if ((IgnoreCase) && !(UpcaseTable))
62 {
63 /* Upcase the string ourselves */
64 Status = RtlUpcaseUnicodeString(&UpcaseName1, Name1, TRUE);
66
67 /* Upcase the second string too */
68 Status = RtlUpcaseUnicodeString(&UpcaseName2, Name2, TRUE);
69 if (!NT_SUCCESS(Status))
70 {
71 RtlFreeUnicodeString(&UpcaseName1);
73 }
74
75 Name1 = &UpcaseName1;
76 Name2 = &UpcaseName2;
77
78 /* Make sure we go through the path below, but free the strings */
81 }
82
83 /* Do a case-sensitive search */
84 if (!IgnoreCase)
85 {
86 /* Use a raw memory compare */
87 StringsAreEqual = RtlEqualMemory(Name1->Buffer,
89 Name1->Length);
90
91 /* Check if we allocated strings */
93 {
94 /* Free them */
95 RtlFreeUnicodeString(&UpcaseName1);
96 RtlFreeUnicodeString(&UpcaseName2);
97 }
98
99 /* Return the equality */
100 return StringsAreEqual;
101 }
102 else
103 {
104 /* Case in-sensitive search */
105 for (i = 0; i < Name1->Length / sizeof(WCHAR); i++)
106 {
107 /* Check if the character matches */
108 if (UpcaseTable[Name1->Buffer[i]] != UpcaseTable[Name2->Buffer[i]])
109 {
110 /* Non-match found! */
111 return FALSE;
112 }
113 }
114
115 /* We finished the loop so we are equal */
116 return TRUE;
117 }
118}
119
120/*++
121 * @name FsRtlDissectName
122 * @implemented
123 *
124 * Dissects a given path name into first and remaining part.
125 *
126 * @param Name
127 * Unicode string to dissect.
128 *
129 * @param FirstPart
130 * Pointer to user supplied UNICODE_STRING, that will later point
131 * to the first part of the original name.
132 *
133 * @param RemainingPart
134 * Pointer to user supplied UNICODE_STRING, that will later point
135 * to the remaining part of the original name.
136 *
137 * @return None
138 *
139 * @remarks Example:
140 * Name: \test1\test2\test3
141 * FirstPart: test1
142 * RemainingPart: test2\test3
143 *
144 *--*/
145VOID
146NTAPI
150{
151 USHORT FirstPosition, i;
152 USHORT SkipFirstSlash = 0;
153 PAGED_CODE();
154
155 /* Zero the strings before continuing */
158
159 /* Just quit if the string is empty */
160 if (!Name.Length) return;
161
162 /* Find first backslash */
163 FirstPosition = Name.Length / sizeof(WCHAR) ;
164 for (i = 0; i < Name.Length / sizeof(WCHAR); i++)
165 {
166 /* If we found one... */
167 if (Name.Buffer[i] == L'\\')
168 {
169 /* If it begins string, just notice it and continue */
170 if (i == 0)
171 {
172 SkipFirstSlash = 1;
173 }
174 else
175 {
176 /* Else, save its position and break out of the loop */
177 FirstPosition = i;
178 break;
179 }
180 }
181 }
182
183 /* Set up the first result string */
184 FirstPart->Buffer = Name.Buffer + SkipFirstSlash;
185 FirstPart->Length = (FirstPosition - SkipFirstSlash) * sizeof(WCHAR);
187
188 /* And second one, if necessary */
189 if (FirstPosition < (Name.Length / sizeof(WCHAR)))
190 {
191 RemainingPart->Buffer = Name.Buffer + FirstPosition + 1;
192 RemainingPart->Length = Name.Length - (FirstPosition + 1) * sizeof(WCHAR);
194 }
195}
196
197/*++
198 * @name FsRtlDoesNameContainWildCards
199 * @implemented
200 *
201 * Checks if the given string contains WildCards
202 *
203 * @param Name
204 * Pointer to a UNICODE_STRING containing Name to examine
205 *
206 * @return TRUE if Name contains wildcards, FALSE otherwise
207 *
208 * @remarks From Bo Branten's ntifs.h v12.
209 *
210 *--*/
212NTAPI
214{
215 PWCHAR Ptr;
216 PAGED_CODE();
217
218 /* Loop through every character */
219 if (Name->Length)
220 {
221 Ptr = Name->Buffer + (Name->Length / sizeof(WCHAR)) - 1;
222 while ((Ptr >= Name->Buffer) && (*Ptr != L'\\'))
223 {
224 /* Check for Wildcard */
226 Ptr--;
227 }
228 }
229
230 /* Nothing Found */
231 return FALSE;
232}
#define PAGED_CODE()
static _In_ PUNICODE_STRING _In_ BOOLEAN _In_opt_ PWCH UpcaseTable
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
LPWSTR Name
Definition: desk.c:124
#define IgnoreCase
Definition: cdprocs.h:461
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
_Out_ PANSI_STRING _Out_ PANSI_STRING RemainingPart
Definition: fsrtlfuncs.h:379
_Must_inspect_result_ _In_ PCUNICODE_STRING Name2
Definition: fsrtlfuncs.h:796
#define FsRtlIsUnicodeCharacterWild(C)
Definition: fsrtlfuncs.h:1636
_Out_ PANSI_STRING FirstPart
Definition: fsrtlfuncs.h:378
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
Status
Definition: gdiplustypes.h:24
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
#define RtlEqualMemory(dst, src, len)
Definition: kdvm.h:18
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
CONST WCHAR * PCWCH
Definition: ntbasedef.h:423
BOOLEAN NTAPI FsRtlAreNamesEqual(IN PCUNICODE_STRING Name1, IN PCUNICODE_STRING Name2, IN BOOLEAN IgnoreCase, IN PCWCH UpcaseTable OPTIONAL)
Definition: name.c:45
BOOLEAN NTAPI FsRtlDoesNameContainWildCards(IN PUNICODE_STRING Name)
Definition: name.c:213
VOID NTAPI FsRtlDissectName(IN UNICODE_STRING Name, OUT PUNICODE_STRING FirstPart, OUT PUNICODE_STRING RemainingPart)
Definition: name.c:147
short WCHAR
Definition: pedump.c:58
unsigned short USHORT
Definition: pedump.c:61
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
USHORT MaximumLength
Definition: env_spec_w32.h:377
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
#define OUT
Definition: typedefs.h:40
_Out_ PSECURITY_DESCRIPTOR _Out_ PBOOLEAN MemoryAllocated
Definition: obfuncs.h:24