Pierre Schweitzer <heis_spiter@hotmail.com>
authorAleksey Bragin <aleksey@reactos.org>
Fri, 22 Feb 2008 10:50:26 +0000 (10:50 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Fri, 22 Feb 2008 10:50:26 +0000 (10:50 +0000)
- Implement FsRtlDissectName() based on MSDN description. Improvements and bugfixes to the patch were made by Aleksey Bragin.

svn path=/trunk/; revision=32447

reactos/ntoskrnl/fsrtl/name.c

index f887d9f..c45ef18 100644 (file)
@@ -139,7 +139,45 @@ FsRtlDissectName(IN UNICODE_STRING Name,
                  OUT PUNICODE_STRING FirstPart,\r
                  OUT PUNICODE_STRING RemainingPart)\r
 {\r
-    KEBUGCHECK(0);\r
+    ULONG FirstPosition, i;\r
+    ULONG SkipFirstSlash = 0;\r
+\r
+    /* Just quit if the string is empty */\r
+    if (!Name.Length) return;\r
+\r
+    /* Find first backslash */\r
+    FirstPosition = Name.Length / sizeof(WCHAR) ;\r
+    for (i = 0; i < Name.Length / sizeof(WCHAR); i++)\r
+    {\r
+        /* If we found one... */\r
+        if (Name.Buffer[i] == '\\')\r
+        {\r
+            /* If it begins string, just notice it and continue */\r
+            if (i == 0)\r
+            {\r
+                SkipFirstSlash = 1;\r
+            }\r
+            else\r
+            {\r
+                /* Else, save its position and break out of the loop */\r
+                FirstPosition = i;\r
+                break;\r
+            }\r
+        }\r
+    }\r
+\r
+    /* Set up the first result string */\r
+    FirstPart->Buffer = Name.Buffer + SkipFirstSlash;\r
+    FirstPart->Length = (FirstPosition - SkipFirstSlash) * sizeof(WCHAR);\r
+    FirstPart->MaximumLength = Name.MaximumLength - FirstPart->Length;\r
+\r
+    /* And second one, if necessary */\r
+    if (FirstPosition < (Name.Length / sizeof(WCHAR)))\r
+    {\r
+        RemainingPart->Buffer = Name.Buffer + FirstPosition + 1;\r
+        RemainingPart->Length = (Name.Length - FirstPosition) * sizeof(WCHAR);\r
+        RemainingPart->MaximumLength = Name.MaximumLength - RemainingPart->Length;\r
+    }\r
 }\r
 \r
 /*++\r