From: Vishnunithyasoundhar S <svishnunithyasoundhar@gmail.com> Support the \\?\ prefix by skipping it during path resolution while preserving it in the output. Added specific handling for extended UNC paths (\\?\UNC\) to mirror standard UNC behavior, ensuring these paths are treated as network shares and not local devices. Some paths that use the extended length path were filtered out as UNC paths - but not all of them are UNC. There can be UNC path that use extended length path but not all extended length paths are UNC paths. Added test. Signed-off-by: Vishnunithyasoundhar S <svishnunithyasoundhar@gmail.com> --- dlls/kernel32/tests/path.c | 25 ++++++++++++++++++++++--- dlls/kernelbase/file.c | 22 +++++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/dlls/kernel32/tests/path.c b/dlls/kernel32/tests/path.c index aa1833504d8..02a6dc83f87 100644 --- a/dlls/kernel32/tests/path.c +++ b/dlls/kernel32/tests/path.c @@ -1255,6 +1255,8 @@ static void test_GetLongPathNameW(void) static const WCHAR prefix[] = { '\\','\\','?','\\', 0}; static const WCHAR backslash[] = { '\\', 0}; static const WCHAR letterX[] = { 'X', 0}; + WCHAR shortpath2[MAX_PATH]; + WCHAR longpath[MAX_PATH]; SetLastError(0xdeadbeef); length = GetLongPathNameW(NULL,NULL,0); @@ -1298,12 +1300,9 @@ static void test_GetLongPathNameW(void) /* With prefix */ SetLastError(0xdeadbeef); length = GetLongPathNameW(shortpath, NULL, 0); - todo_wine - { ok(length == 0, "Expected 0, got %ld\n", length); ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_PATH_NOT_FOUND, got %ld\n", GetLastError()); - } file = CreateFileW(shortpath, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); @@ -1327,6 +1326,26 @@ static void test_GetLongPathNameW(void) length = GetLongPathNameW(shortpath, NULL, 0); ok(length == expanded, "Expected %ld, got %ld\n", expanded, length); + /* Test that extended prefix is preserved in output when converting from + * short to long path */ + shortpath2[0] = 0; + trace("---Extended prefix file path test here---\n"); // to be removed + length = GetShortPathNameW(dirpath, shortpath2, ARRAY_SIZE(shortpath2)); + ok(length, "GetShortPathNameW failed: %lu\n", GetLastError()); + ok(lstrcmpiW(dirpath, shortpath2) != 0, + "short path name isn't created, got %s\n", debugstr_w(shortpath2)); + + trace("dirpath: %s\n", wine_dbgstr_w(dirpath)); // to be removed + trace("shortpath2: %s\n", wine_dbgstr_w(shortpath2)); // to be removed + + SetLastError(0xdeadbeef); + length = GetLongPathNameW(shortpath2, longpath, ARRAY_SIZE(longpath)); + trace("longpath: %s\n", wine_dbgstr_w(longpath)); // to be removed + ok(length > 0, "GetLongPathNameW failed: %ld\n", GetLastError()); + ok(!wcsncmp(longpath, dirpath, lstrlenW(dirpath)), + "Expected path: %s, got: %s\n", wine_dbgstr_w(dirpath), + wine_dbgstr_w(longpath)); + /* NULL buffer with length crashes on Windows */ if (0) GetLongPathNameW(shortpath, NULL, 20); diff --git a/dlls/kernelbase/file.c b/dlls/kernelbase/file.c index 83977a2c40b..b3dcf23b64e 100644 --- a/dlls/kernelbase/file.c +++ b/dlls/kernelbase/file.c @@ -2116,7 +2116,27 @@ DWORD WINAPI DECLSPEC_HOTPATCH GetLongPathNameW( LPCWSTR shortpath, LPWSTR longp return 0; } - if (shortpath[0] == '\\' && shortpath[1] == '\\') + /* Handle \\?\ prefix (Extended Length Path) */ + if (wcslen(shortpath) >= 4 && shortpath[0] == '\\' && + shortpath[1] == '\\' && shortpath[2] == '?' && shortpath[3] == '\\') { + /* Filter out entended UNC */ + if (wcsnicmp(shortpath + 4, L"UNC\\", 4) == 0) { + lstrcatW(tmplongpath, L"UNC\\"); + lp = sp = 8; + FIXME("UNC Extended pathname %s\n", debugstr_w(shortpath)); + } else if (shortpath[4] && shortpath[5] == ':') { + tmplongpath[0] = '\\'; + tmplongpath[1] = '\\'; + tmplongpath[2] = '?'; + tmplongpath[3] = '\\'; + tmplongpath[4] = shortpath[4]; + tmplongpath[5] = shortpath[5]; + lp = 6; + sp = 6; + } + } + + if (sp == 0 && shortpath[0] == '\\' && shortpath[1] == '\\') { FIXME( "UNC pathname %s\n", debugstr_w(shortpath) ); tmplen = lstrlenW( shortpath ); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10192