Author: mjansen
Date: Thu Mar  2 21:29:38 2017
New Revision: 74031

URL: http://svn.reactos.org/svn/reactos?rev=74031&view=rev
Log:
[NTDLL] Add implementation for RtlNtPathNameToDosPathName. CORE-12847 #resolve

Modified:
    trunk/reactos/dll/ntdll/def/ntdll.spec
    trunk/reactos/sdk/include/ndk/rtlfuncs.h
    trunk/reactos/sdk/lib/rtl/path.c
    trunk/rostests/apitests/ntdll/RtlNtPathNameToDosPathName.c

Modified: trunk/reactos/dll/ntdll/def/ntdll.spec
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/def/ntdll.spec?rev=74031&r1=74030&r2=74031&view=diff
==============================================================================
--- trunk/reactos/dll/ntdll/def/ntdll.spec      [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/def/ntdll.spec      [iso-8859-1] Thu Mar  2 
21:29:38 2017
@@ -784,7 +784,7 @@
 779 stdcall RtlNewSecurityObjectEx(ptr ptr ptr ptr long long ptr ptr)
 780 stdcall RtlNewSecurityObjectWithMultipleInheritance(ptr ptr ptr ptr long 
long long ptr ptr)
 781 stdcall RtlNormalizeProcessParams(ptr)
-782 stdcall RtlNtPathNameToDosPathName(ptr ptr ptr ptr) ; CHECKME
+782 stdcall RtlNtPathNameToDosPathName(long ptr ptr ptr) ; CHECKME (last arg)
 783 stdcall RtlNtStatusToDosError(long)
 784 stdcall RtlNtStatusToDosErrorNoTeb(long)
 785 stdcall RtlNumberGenericTableElements(ptr)

Modified: trunk/reactos/sdk/include/ndk/rtlfuncs.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/sdk/include/ndk/rtlfuncs.h?rev=74031&r1=74030&r2=74031&view=diff
==============================================================================
--- trunk/reactos/sdk/include/ndk/rtlfuncs.h    [iso-8859-1] (original)
+++ trunk/reactos/sdk/include/ndk/rtlfuncs.h    [iso-8859-1] Thu Mar  2 
21:29:38 2017
@@ -2816,6 +2816,23 @@
     _Out_opt_ PCWSTR *NtFileNamePart,
     _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo
 );
+
+
+#define RTL_UNCHANGED_UNK_PATH  1
+#define RTL_CONVERTED_UNC_PATH  2
+#define RTL_CONVERTED_NT_PATH   3
+#define RTL_UNCHANGED_DOS_PATH  4
+
+NTSYSAPI
+NTSTATUS
+NTAPI
+RtlNtPathNameToDosPathName(
+    _In_ ULONG Flags,
+    _Inout_ RTL_UNICODE_STRING_BUFFER* Path,
+    _Out_opt_ ULONG* PathType,
+    _Out_opt_ ULONG* Unknown
+);
+
 
 NTSYSAPI
 BOOLEAN

Modified: trunk/reactos/sdk/lib/rtl/path.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/sdk/lib/rtl/path.c?rev=74031&r1=74030&r2=74031&view=diff
==============================================================================
--- trunk/reactos/sdk/lib/rtl/path.c    [iso-8859-1] (original)
+++ trunk/reactos/sdk/lib/rtl/path.c    [iso-8859-1] Thu Mar  2 21:29:38 2017
@@ -44,6 +44,8 @@
 const UNICODE_STRING RtlpDosAUXDevice = RTL_CONSTANT_STRING(L"AUX");
 const UNICODE_STRING RtlpDosCONDevice = RTL_CONSTANT_STRING(L"CON");
 const UNICODE_STRING RtlpDosNULDevice = RTL_CONSTANT_STRING(L"NUL");
+
+const UNICODE_STRING RtlpDoubleSlashPrefix   = RTL_CONSTANT_STRING(L"\\\\");
 
 PRTLP_CURDIR_REF RtlpCurDirRef;
 
@@ -1787,13 +1789,89 @@
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
-NTSTATUS NTAPI
-RtlNtPathNameToDosPathName(ULONG Unknown1, ULONG Unknown2, ULONG Unknown3, 
ULONG Unknown4)
-{
-    DPRINT1("RtlNtPathNameToDosPathName: stub\n");
-    return STATUS_NOT_IMPLEMENTED;
+NTSTATUS NTAPI RtlNtPathNameToDosPathName(IN ULONG Flags,
+                                          IN OUT RTL_UNICODE_STRING_BUFFER* 
Path,
+                                          OUT ULONG* PathType,
+                                          ULONG* Unknown)
+{
+    PCUNICODE_STRING UsePrefix = NULL, AlternatePrefix = NULL;
+
+    if (PathType)
+        *PathType = 0;
+
+    if (!Path || Flags)
+        return STATUS_INVALID_PARAMETER;
+
+    /* The initial check is done on Path->String */
+    if (RtlPrefixUnicodeString(&RtlpDosDevicesUncPrefix, &Path->String, TRUE))
+    {
+        UsePrefix = &RtlpDosDevicesUncPrefix;
+        AlternatePrefix = &RtlpDoubleSlashPrefix;
+        if (PathType)
+            *PathType = RTL_CONVERTED_UNC_PATH;
+    }
+    else if (RtlPrefixUnicodeString(&RtlpDosDevicesPrefix, &Path->String, 
TRUE))
+    {
+        UsePrefix = &RtlpDosDevicesPrefix;
+        if (PathType)
+            *PathType = RTL_CONVERTED_NT_PATH;
+    }
+
+    if (UsePrefix)
+    {
+        NTSTATUS Status;
+
+        USHORT Len = Path->String.Length - UsePrefix->Length;
+        if (AlternatePrefix)
+            Len += AlternatePrefix->Length;
+
+        Status = RtlEnsureBufferSize(0, &Path->ByteBuffer, Len);
+        if (!NT_SUCCESS(Status))
+            return Status;
+
+        if (Len + sizeof(UNICODE_NULL) <= Path->ByteBuffer.Size)
+        {
+            /* Then, the contents of Path->ByteBuffer are always used... */
+            if (AlternatePrefix)
+            {
+                memcpy(Path->ByteBuffer.Buffer, AlternatePrefix->Buffer, 
AlternatePrefix->Length);
+                memmove(Path->ByteBuffer.Buffer + AlternatePrefix->Length, 
Path->ByteBuffer.Buffer + UsePrefix->Length,
+                    Len - AlternatePrefix->Length);
+            }
+            else
+            {
+                memmove(Path->ByteBuffer.Buffer, Path->ByteBuffer.Buffer + 
UsePrefix->Length, Len);
+            }
+            Path->String.Buffer = (PWSTR)Path->ByteBuffer.Buffer;
+            Path->String.Length = Len;
+            Path->String.MaximumLength = Path->ByteBuffer.Size;
+            Path->String.Buffer[Len / sizeof(WCHAR)] = UNICODE_NULL;
+        }
+        return STATUS_SUCCESS;
+    }
+
+    if (PathType)
+    {
+        switch (RtlDetermineDosPathNameType_Ustr(&Path->String))
+        {
+        case RtlPathTypeUncAbsolute:
+        case RtlPathTypeDriveAbsolute:
+        case RtlPathTypeLocalDevice:
+        case RtlPathTypeRootLocalDevice:
+            *PathType = RTL_UNCHANGED_DOS_PATH;
+            break;
+        case RtlPathTypeUnknown:
+        case RtlPathTypeDriveRelative:
+        case RtlPathTypeRooted:
+        case RtlPathTypeRelative:
+            *PathType = RTL_UNCHANGED_UNK_PATH;
+            break;
+        }
+    }
+
+    return STATUS_SUCCESS;
 }
 
 /*

Modified: trunk/rostests/apitests/ntdll/RtlNtPathNameToDosPathName.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/RtlNtPathNameToDosPathName.c?rev=74031&r1=74030&r2=74031&view=diff
==============================================================================
--- trunk/rostests/apitests/ntdll/RtlNtPathNameToDosPathName.c  [iso-8859-1] 
(original)
+++ trunk/rostests/apitests/ntdll/RtlNtPathNameToDosPathName.c  [iso-8859-1] 
Thu Mar  2 21:29:38 2017
@@ -42,11 +42,6 @@
     int Line;
 };
 
-
-#define RTL_UNCHANGED_UNK_PATH  1
-#define RTL_CONVERTED_UNC_PATH  2
-#define RTL_CONVERTED_NT_PATH   3
-#define RTL_UNCHANGED_DOS_PATH  4
 
 static struct test_entry test_data[] =
 {


Reply via email to