2003-04-12 02:10:13 +02:00
|
|
|
/*
|
|
|
|
* Ntdll path functions
|
|
|
|
*
|
2004-04-01 04:09:14 +02:00
|
|
|
* Copyright 2002, 2003, 2004 Alexandre Julliard
|
2003-04-17 01:15:29 +02:00
|
|
|
* Copyright 2003 Eric Pouech
|
2003-04-12 02:10:13 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-04-12 02:10:13 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2004-04-01 04:09:14 +02:00
|
|
|
#include <sys/types.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2004-04-16 07:00:46 +02:00
|
|
|
#include "winioctl.h"
|
2003-04-17 01:15:29 +02:00
|
|
|
#include "wine/debug.h"
|
2003-05-15 06:20:42 +02:00
|
|
|
#include "ntdll_misc.h"
|
2003-04-17 01:15:29 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(file);
|
2003-04-12 02:10:13 +02:00
|
|
|
|
|
|
|
#define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlDetermineDosPathNameType_U (NTDLL.@)
|
|
|
|
*/
|
|
|
|
DOS_PATHNAME_TYPE WINAPI RtlDetermineDosPathNameType_U( PCWSTR path )
|
|
|
|
{
|
|
|
|
if (IS_SEPARATOR(path[0]))
|
|
|
|
{
|
|
|
|
if (!IS_SEPARATOR(path[1])) return ABSOLUTE_PATH; /* "/foo" */
|
2018-08-24 05:50:04 +02:00
|
|
|
if (path[2] != '.' && path[2] != '?') return UNC_PATH; /* "//foo" */
|
|
|
|
if (IS_SEPARATOR(path[3])) return DEVICE_PATH; /* "//./foo" or "//?/foo" */
|
|
|
|
if (path[3]) return UNC_PATH; /* "//.foo" or "//?foo" */
|
|
|
|
return UNC_DOT_PATH; /* "//." or "//?" */
|
2003-04-12 02:10:13 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!path[0] || path[1] != ':') return RELATIVE_PATH; /* "foo" */
|
|
|
|
if (IS_SEPARATOR(path[2])) return ABSOLUTE_DRIVE_PATH; /* "c:/foo" */
|
|
|
|
return RELATIVE_DRIVE_PATH; /* "c:foo" */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlIsDosDeviceName_U (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Check if the given DOS path contains a DOS device name.
|
|
|
|
*
|
|
|
|
* Returns the length of the device name in the low word and its
|
|
|
|
* position in the high word (both in bytes, not WCHARs), or 0 if no
|
|
|
|
* device name is found.
|
|
|
|
*/
|
|
|
|
ULONG WINAPI RtlIsDosDeviceName_U( PCWSTR dos_name )
|
|
|
|
{
|
2011-12-16 13:07:20 +01:00
|
|
|
static const WCHAR auxW[] = {'A','U','X'};
|
|
|
|
static const WCHAR comW[] = {'C','O','M'};
|
|
|
|
static const WCHAR conW[] = {'C','O','N'};
|
|
|
|
static const WCHAR lptW[] = {'L','P','T'};
|
|
|
|
static const WCHAR nulW[] = {'N','U','L'};
|
|
|
|
static const WCHAR prnW[] = {'P','R','N'};
|
2020-06-25 22:27:26 +02:00
|
|
|
static const WCHAR coninW[] = {'C','O','N','I','N','$'};
|
|
|
|
static const WCHAR conoutW[] = {'C','O','N','O','U','T','$'};
|
2003-04-12 02:10:13 +02:00
|
|
|
|
|
|
|
const WCHAR *start, *end, *p;
|
|
|
|
|
|
|
|
switch(RtlDetermineDosPathNameType_U( dos_name ))
|
|
|
|
{
|
|
|
|
case INVALID_PATH:
|
|
|
|
case UNC_PATH:
|
|
|
|
return 0;
|
|
|
|
case DEVICE_PATH:
|
2020-12-04 00:36:32 +01:00
|
|
|
if (!wcsicmp( dos_name, L"\\\\.\\CON" ))
|
2003-04-12 02:10:13 +02:00
|
|
|
return MAKELONG( sizeof(conW), 4 * sizeof(WCHAR) ); /* 4 is length of \\.\ prefix */
|
|
|
|
return 0;
|
2008-10-29 15:21:51 +01:00
|
|
|
case ABSOLUTE_DRIVE_PATH:
|
|
|
|
case RELATIVE_DRIVE_PATH:
|
|
|
|
start = dos_name + 2; /* skip drive letter */
|
|
|
|
break;
|
2003-04-12 02:10:13 +02:00
|
|
|
default:
|
2008-10-29 15:21:51 +01:00
|
|
|
start = dos_name;
|
2003-04-12 02:10:13 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find start of file name */
|
2008-10-29 15:21:51 +01:00
|
|
|
for (p = start; *p; p++) if (IS_SEPARATOR(*p)) start = p + 1;
|
|
|
|
|
|
|
|
/* truncate at extension and ':' */
|
|
|
|
for (end = start; *end; end++) if (*end == '.' || *end == ':') break;
|
|
|
|
end--;
|
2003-04-12 02:10:13 +02:00
|
|
|
|
2006-06-21 15:35:13 +02:00
|
|
|
/* remove trailing spaces */
|
2008-10-29 15:21:51 +01:00
|
|
|
while (end >= start && *end == ' ') end--;
|
2003-04-12 02:10:13 +02:00
|
|
|
|
|
|
|
/* now we have a potential device name between start and end, check it */
|
|
|
|
switch(end - start + 1)
|
|
|
|
{
|
|
|
|
case 3:
|
2020-03-27 13:38:33 +01:00
|
|
|
if (wcsnicmp( start, auxW, 3 ) &&
|
|
|
|
wcsnicmp( start, conW, 3 ) &&
|
|
|
|
wcsnicmp( start, nulW, 3 ) &&
|
|
|
|
wcsnicmp( start, prnW, 3 )) break;
|
2003-04-12 02:10:13 +02:00
|
|
|
return MAKELONG( 3 * sizeof(WCHAR), (start - dos_name) * sizeof(WCHAR) );
|
|
|
|
case 4:
|
2020-03-27 13:38:33 +01:00
|
|
|
if (wcsnicmp( start, comW, 3 ) && wcsnicmp( start, lptW, 3 )) break;
|
2003-04-12 02:10:13 +02:00
|
|
|
if (*end <= '0' || *end > '9') break;
|
|
|
|
return MAKELONG( 4 * sizeof(WCHAR), (start - dos_name) * sizeof(WCHAR) );
|
2020-06-25 22:27:26 +02:00
|
|
|
case 6:
|
|
|
|
if (wcsnicmp( start, coninW, ARRAY_SIZE(coninW) )) break;
|
|
|
|
return MAKELONG( sizeof(coninW), (start - dos_name) * sizeof(WCHAR) );
|
|
|
|
case 7:
|
|
|
|
if (wcsnicmp( start, conoutW, ARRAY_SIZE(conoutW) )) break;
|
|
|
|
return MAKELONG( sizeof(conoutW), (start - dos_name) * sizeof(WCHAR) );
|
2003-04-12 02:10:13 +02:00
|
|
|
default: /* can't match anything */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2003-04-17 01:15:29 +02:00
|
|
|
|
2021-06-19 11:25:35 +02:00
|
|
|
/******************************************************************
|
|
|
|
* is_valid_directory
|
|
|
|
*
|
|
|
|
* Helper for RtlDosPathNameToNtPathName_U_WithStatus.
|
2021-08-27 12:57:46 +02:00
|
|
|
* Test if the path is an existing directory.
|
2021-06-19 11:25:35 +02:00
|
|
|
*/
|
|
|
|
static BOOL is_valid_directory(LPCWSTR path)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING ntpath;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
HANDLE handle;
|
|
|
|
NTSTATUS nts;
|
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U(path, &ntpath, NULL, NULL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.ObjectName = &ntpath;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
|
|
|
nts = NtOpenFile(&handle, FILE_READ_ATTRIBUTES | SYNCHRONIZE, &attr, &io,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
|
|
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
|
|
|
|
RtlFreeUnicodeString(&ntpath);
|
|
|
|
if (nts != STATUS_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
NtClose(handle);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-05-15 06:20:42 +02:00
|
|
|
/**************************************************************************
|
2017-10-23 08:48:21 +02:00
|
|
|
* RtlDosPathNameToNtPathName_U_WithStatus [NTDLL.@]
|
2003-05-15 06:20:42 +02:00
|
|
|
*
|
|
|
|
* dos_path: a DOS path name (fully qualified or not)
|
|
|
|
* ntpath: pointer to a UNICODE_STRING to hold the converted
|
|
|
|
* path name
|
|
|
|
* file_part:will point (in ntpath) to the file part in the path
|
|
|
|
* cd: directory reference (optional)
|
|
|
|
*
|
|
|
|
* FIXME:
|
|
|
|
* + fill the cd structure
|
|
|
|
*/
|
2017-10-23 08:48:21 +02:00
|
|
|
NTSTATUS WINAPI RtlDosPathNameToNtPathName_U_WithStatus(const WCHAR *dos_path, UNICODE_STRING *ntpath,
|
|
|
|
WCHAR **file_part, CURDIR *cd)
|
2003-05-15 06:20:42 +02:00
|
|
|
{
|
2018-08-24 05:50:07 +02:00
|
|
|
static const WCHAR global_prefix[] = {'\\','\\','?','\\'};
|
|
|
|
static const WCHAR global_prefix2[] = {'\\','?','?','\\'};
|
2021-06-19 11:25:35 +02:00
|
|
|
NTSTATUS nts = STATUS_SUCCESS;
|
|
|
|
ULONG sz, offset, dosdev;
|
2003-05-15 06:20:42 +02:00
|
|
|
WCHAR local[MAX_PATH];
|
2021-06-19 11:25:35 +02:00
|
|
|
LPWSTR ptr = local;
|
2003-05-15 06:20:42 +02:00
|
|
|
|
2017-10-23 08:48:21 +02:00
|
|
|
TRACE("(%s,%p,%p,%p)\n", debugstr_w(dos_path), ntpath, file_part, cd);
|
2003-05-15 06:20:42 +02:00
|
|
|
|
|
|
|
if (cd)
|
|
|
|
{
|
|
|
|
FIXME("Unsupported parameter\n");
|
|
|
|
memset(cd, 0, sizeof(*cd));
|
|
|
|
}
|
|
|
|
|
2017-10-23 08:48:21 +02:00
|
|
|
if (!dos_path || !*dos_path)
|
|
|
|
return STATUS_OBJECT_NAME_INVALID;
|
2003-05-15 06:20:42 +02:00
|
|
|
|
2018-08-24 05:50:07 +02:00
|
|
|
if (!memcmp(dos_path, global_prefix, sizeof(global_prefix)) ||
|
2021-12-30 15:49:38 +01:00
|
|
|
(!memcmp(dos_path, global_prefix2, sizeof(global_prefix2)) && dos_path[4]) ||
|
|
|
|
!wcsicmp( dos_path, L"\\\\.\\CON" ))
|
2003-05-15 06:20:42 +02:00
|
|
|
{
|
2020-03-31 11:50:16 +02:00
|
|
|
ntpath->Length = wcslen(dos_path) * sizeof(WCHAR);
|
2004-04-14 06:34:04 +02:00
|
|
|
ntpath->MaximumLength = ntpath->Length + sizeof(WCHAR);
|
|
|
|
ntpath->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, ntpath->MaximumLength);
|
2017-10-23 08:48:21 +02:00
|
|
|
if (!ntpath->Buffer) return STATUS_NO_MEMORY;
|
2004-04-14 06:34:04 +02:00
|
|
|
memcpy( ntpath->Buffer, dos_path, ntpath->MaximumLength );
|
|
|
|
ntpath->Buffer[1] = '?'; /* change \\?\ to \??\ */
|
2021-12-30 15:49:38 +01:00
|
|
|
ntpath->Buffer[2] = '?';
|
2005-10-18 16:12:25 +02:00
|
|
|
if (file_part)
|
|
|
|
{
|
2020-03-31 11:47:47 +02:00
|
|
|
if ((ptr = wcsrchr( ntpath->Buffer, '\\' )) && ptr[1]) *file_part = ptr + 1;
|
2005-10-18 16:12:25 +02:00
|
|
|
else *file_part = NULL;
|
|
|
|
}
|
2017-10-23 08:48:21 +02:00
|
|
|
return STATUS_SUCCESS;
|
2003-05-15 06:20:42 +02:00
|
|
|
}
|
2004-04-14 06:34:04 +02:00
|
|
|
|
2021-06-19 11:25:35 +02:00
|
|
|
dosdev = RtlIsDosDeviceName_U(dos_path);
|
|
|
|
if ((offset = HIWORD(dosdev)))
|
|
|
|
{
|
|
|
|
sz = offset + sizeof(WCHAR);
|
|
|
|
|
|
|
|
if (sz > sizeof(local) &&
|
|
|
|
(!(ptr = RtlAllocateHeap(GetProcessHeap(), 0, sz))))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
memcpy(ptr, dos_path, offset);
|
|
|
|
ptr[offset/sizeof(WCHAR)] = '\0';
|
2017-10-23 08:48:21 +02:00
|
|
|
|
2021-06-19 11:25:35 +02:00
|
|
|
if (!is_valid_directory(ptr))
|
|
|
|
{
|
|
|
|
nts = STATUS_OBJECT_NAME_INVALID;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2021-06-25 11:47:00 +02:00
|
|
|
if (file_part) *file_part = NULL;
|
2021-06-19 11:25:35 +02:00
|
|
|
|
|
|
|
sz = LOWORD(dosdev);
|
|
|
|
|
|
|
|
wcscpy(ptr, L"\\\\.\\");
|
|
|
|
memcpy(ptr + 4, dos_path + offset / sizeof(WCHAR), sz);
|
|
|
|
ptr[4 + sz / sizeof(WCHAR)] = '\0';
|
|
|
|
sz += 4 * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else
|
2003-05-15 06:20:42 +02:00
|
|
|
{
|
2021-06-19 11:25:35 +02:00
|
|
|
sz = RtlGetFullPathName_U(dos_path, sizeof(local), ptr, file_part);
|
|
|
|
if (sz == 0) return STATUS_OBJECT_NAME_INVALID;
|
|
|
|
|
|
|
|
if (sz > sizeof(local))
|
|
|
|
{
|
|
|
|
if (!(ptr = RtlAllocateHeap(GetProcessHeap(), 0, sz))) return STATUS_NO_MEMORY;
|
|
|
|
sz = RtlGetFullPathName_U(dos_path, sz, ptr, file_part);
|
|
|
|
}
|
2003-05-15 06:20:42 +02:00
|
|
|
}
|
2011-09-06 14:23:42 +02:00
|
|
|
sz += (1 /* NUL */ + 4 /* unc\ */ + 4 /* \??\ */) * sizeof(WCHAR);
|
|
|
|
if (sz > MAXWORD)
|
|
|
|
{
|
2021-06-19 11:25:35 +02:00
|
|
|
nts = STATUS_OBJECT_NAME_INVALID;
|
|
|
|
goto out;
|
2011-09-06 14:23:42 +02:00
|
|
|
}
|
2003-05-15 06:20:42 +02:00
|
|
|
|
2011-09-06 14:23:42 +02:00
|
|
|
ntpath->MaximumLength = sz;
|
2004-03-12 02:59:35 +01:00
|
|
|
ntpath->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, ntpath->MaximumLength);
|
2003-05-15 06:20:42 +02:00
|
|
|
if (!ntpath->Buffer)
|
|
|
|
{
|
2021-06-19 11:25:35 +02:00
|
|
|
nts = STATUS_NO_MEMORY;
|
|
|
|
goto out;
|
2003-05-15 06:20:42 +02:00
|
|
|
}
|
|
|
|
|
2020-12-04 00:36:32 +01:00
|
|
|
wcscpy(ntpath->Buffer, L"\\??\\");
|
2003-05-15 06:20:42 +02:00
|
|
|
switch (RtlDetermineDosPathNameType_U(ptr))
|
|
|
|
{
|
|
|
|
case UNC_PATH: /* \\foo */
|
2004-04-14 06:34:04 +02:00
|
|
|
offset = 2;
|
2020-12-04 00:36:32 +01:00
|
|
|
wcscat(ntpath->Buffer, L"UNC\\");
|
2003-05-15 06:20:42 +02:00
|
|
|
break;
|
|
|
|
case DEVICE_PATH: /* \\.\foo */
|
|
|
|
offset = 4;
|
|
|
|
break;
|
2004-04-14 06:34:04 +02:00
|
|
|
default:
|
2004-04-20 02:37:00 +02:00
|
|
|
offset = 0;
|
|
|
|
break;
|
2003-05-15 06:20:42 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 11:41:22 +02:00
|
|
|
wcscat(ntpath->Buffer, ptr + offset);
|
2020-03-31 11:50:16 +02:00
|
|
|
ntpath->Length = wcslen(ntpath->Buffer) * sizeof(WCHAR);
|
2003-05-15 06:20:42 +02:00
|
|
|
|
|
|
|
if (file_part && *file_part)
|
2020-03-31 11:50:16 +02:00
|
|
|
*file_part = ntpath->Buffer + ntpath->Length / sizeof(WCHAR) - wcslen(*file_part);
|
2003-05-15 06:20:42 +02:00
|
|
|
|
|
|
|
/* FIXME: cd filling */
|
|
|
|
|
2021-06-19 11:25:35 +02:00
|
|
|
out:
|
2004-03-12 02:59:35 +01:00
|
|
|
if (ptr != local) RtlFreeHeap(GetProcessHeap(), 0, ptr);
|
2021-06-19 11:25:35 +02:00
|
|
|
return nts;
|
2017-10-23 08:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* RtlDosPathNameToNtPathName_U [NTDLL.@]
|
|
|
|
*
|
|
|
|
* See RtlDosPathNameToNtPathName_U_WithStatus
|
|
|
|
*/
|
|
|
|
BOOLEAN WINAPI RtlDosPathNameToNtPathName_U(PCWSTR dos_path,
|
|
|
|
PUNICODE_STRING ntpath,
|
|
|
|
PWSTR* file_part,
|
|
|
|
CURDIR* cd)
|
|
|
|
{
|
|
|
|
return RtlDosPathNameToNtPathName_U_WithStatus(dos_path, ntpath, file_part, cd) == STATUS_SUCCESS;
|
2003-05-15 06:20:42 +02:00
|
|
|
}
|
|
|
|
|
2018-05-31 17:15:35 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* RtlDosPathNameToRelativeNtPathName_U_WithStatus [NTDLL.@]
|
|
|
|
*
|
|
|
|
* See RtlDosPathNameToNtPathName_U_WithStatus (except the last parameter)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlDosPathNameToRelativeNtPathName_U_WithStatus(const WCHAR *dos_path,
|
|
|
|
UNICODE_STRING *ntpath, WCHAR **file_part, RTL_RELATIVE_NAME *relative)
|
|
|
|
{
|
|
|
|
TRACE("(%s,%p,%p,%p)\n", debugstr_w(dos_path), ntpath, file_part, relative);
|
|
|
|
|
|
|
|
if (relative)
|
|
|
|
{
|
|
|
|
FIXME("Unsupported parameter\n");
|
|
|
|
memset(relative, 0, sizeof(*relative));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: fill parameter relative */
|
|
|
|
|
|
|
|
return RtlDosPathNameToNtPathName_U_WithStatus(dos_path, ntpath, file_part, NULL);
|
|
|
|
}
|
|
|
|
|
2018-06-11 10:27:37 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* RtlReleaseRelativeName [NTDLL.@]
|
|
|
|
*/
|
|
|
|
void WINAPI RtlReleaseRelativeName(RTL_RELATIVE_NAME *relative)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-06-16 03:24:30 +02:00
|
|
|
/******************************************************************
|
|
|
|
* RtlDosSearchPath_U
|
|
|
|
*
|
2008-04-08 23:22:43 +02:00
|
|
|
* Searches a file of name 'name' into a ';' separated list of paths
|
2003-06-16 03:24:30 +02:00
|
|
|
* (stored in paths)
|
|
|
|
* Doesn't seem to search elsewhere than the paths list
|
|
|
|
* Stores the result in buffer (file_part will point to the position
|
|
|
|
* of the file name in the buffer)
|
|
|
|
* FIXME:
|
|
|
|
* - how long shall the paths be ??? (MAX_PATH or larger with \\?\ constructs ???)
|
|
|
|
*/
|
|
|
|
ULONG WINAPI RtlDosSearchPath_U(LPCWSTR paths, LPCWSTR search, LPCWSTR ext,
|
|
|
|
ULONG buffer_size, LPWSTR buffer,
|
|
|
|
LPWSTR* file_part)
|
|
|
|
{
|
|
|
|
DOS_PATHNAME_TYPE type = RtlDetermineDosPathNameType_U(search);
|
|
|
|
ULONG len = 0;
|
|
|
|
|
|
|
|
if (type == RELATIVE_PATH)
|
|
|
|
{
|
|
|
|
ULONG allocated = 0, needed, filelen;
|
2003-10-07 05:46:34 +02:00
|
|
|
WCHAR *name = NULL;
|
2003-06-16 03:24:30 +02:00
|
|
|
|
2020-03-31 11:50:16 +02:00
|
|
|
filelen = 1 /* for \ */ + wcslen(search) + 1 /* \0 */;
|
2003-06-16 03:24:30 +02:00
|
|
|
|
2003-10-07 05:46:34 +02:00
|
|
|
/* Windows only checks for '.' without worrying about path components */
|
2020-03-31 11:43:50 +02:00
|
|
|
if (wcschr( search, '.' )) ext = NULL;
|
2020-03-31 11:50:16 +02:00
|
|
|
if (ext != NULL) filelen += wcslen(ext);
|
2003-06-16 03:24:30 +02:00
|
|
|
|
|
|
|
while (*paths)
|
|
|
|
{
|
|
|
|
LPCWSTR ptr;
|
|
|
|
|
|
|
|
for (needed = 0, ptr = paths; *ptr != 0 && *ptr++ != ';'; needed++);
|
|
|
|
if (needed + filelen > allocated)
|
|
|
|
{
|
2003-11-21 00:44:13 +01:00
|
|
|
if (!name) name = RtlAllocateHeap(GetProcessHeap(), 0,
|
|
|
|
(needed + filelen) * sizeof(WCHAR));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR *newname = RtlReAllocateHeap(GetProcessHeap(), 0, name,
|
|
|
|
(needed + filelen) * sizeof(WCHAR));
|
|
|
|
if (!newname) RtlFreeHeap(GetProcessHeap(), 0, name);
|
|
|
|
name = newname;
|
|
|
|
}
|
2003-06-16 03:24:30 +02:00
|
|
|
if (!name) return 0;
|
|
|
|
allocated = needed + filelen;
|
|
|
|
}
|
|
|
|
memmove(name, paths, needed * sizeof(WCHAR));
|
|
|
|
/* append '\\' if none is present */
|
|
|
|
if (needed > 0 && name[needed - 1] != '\\') name[needed++] = '\\';
|
2020-03-31 11:37:58 +02:00
|
|
|
wcscpy(&name[needed], search);
|
2020-03-31 11:41:22 +02:00
|
|
|
if (ext) wcscat(&name[needed], ext);
|
2003-06-16 03:24:30 +02:00
|
|
|
if (RtlDoesFileExists_U(name))
|
|
|
|
{
|
|
|
|
len = RtlGetFullPathName_U(name, buffer_size, buffer, file_part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
paths = ptr;
|
|
|
|
}
|
2004-03-12 02:59:35 +01:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, name);
|
2003-06-16 03:24:30 +02:00
|
|
|
}
|
|
|
|
else if (RtlDoesFileExists_U(search))
|
|
|
|
{
|
|
|
|
len = RtlGetFullPathName_U(search, buffer_size, buffer, file_part);
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2004-03-17 02:58:51 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* collapse_path
|
|
|
|
*
|
|
|
|
* Helper for RtlGetFullPathName_U.
|
|
|
|
* Get rid of . and .. components in the path.
|
|
|
|
*/
|
2004-03-22 23:59:25 +01:00
|
|
|
static inline void collapse_path( WCHAR *path, UINT mark )
|
2004-03-17 02:58:51 +01:00
|
|
|
{
|
|
|
|
WCHAR *p, *next;
|
|
|
|
|
2004-03-22 23:59:25 +01:00
|
|
|
/* convert every / into a \ */
|
|
|
|
for (p = path; *p; p++) if (*p == '/') *p = '\\';
|
|
|
|
|
|
|
|
/* collapse duplicate backslashes */
|
|
|
|
next = path + max( 1, mark );
|
|
|
|
for (p = next; *p; p++) if (*p != '\\' || next[-1] != '\\') *next++ = *p;
|
|
|
|
*next = 0;
|
2004-03-17 02:58:51 +01:00
|
|
|
|
2004-03-22 23:59:25 +01:00
|
|
|
p = path + mark;
|
2004-03-17 02:58:51 +01:00
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if (*p == '.')
|
|
|
|
{
|
|
|
|
switch(p[1])
|
|
|
|
{
|
|
|
|
case '\\': /* .\ component */
|
|
|
|
next = p + 2;
|
2020-03-31 11:50:16 +02:00
|
|
|
memmove( p, next, (wcslen(next) + 1) * sizeof(WCHAR) );
|
2004-03-17 02:58:51 +01:00
|
|
|
continue;
|
|
|
|
case 0: /* final . */
|
2004-03-22 23:59:25 +01:00
|
|
|
if (p > path + mark) p--;
|
2004-03-17 02:58:51 +01:00
|
|
|
*p = 0;
|
|
|
|
continue;
|
|
|
|
case '.':
|
|
|
|
if (p[2] == '\\') /* ..\ component */
|
|
|
|
{
|
|
|
|
next = p + 3;
|
2004-03-22 23:59:25 +01:00
|
|
|
if (p > path + mark)
|
|
|
|
{
|
|
|
|
p--;
|
|
|
|
while (p > path + mark && p[-1] != '\\') p--;
|
|
|
|
}
|
2020-03-31 11:50:16 +02:00
|
|
|
memmove( p, next, (wcslen(next) + 1) * sizeof(WCHAR) );
|
2004-03-17 02:58:51 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (!p[2]) /* final .. */
|
|
|
|
{
|
2004-03-22 23:59:25 +01:00
|
|
|
if (p > path + mark)
|
|
|
|
{
|
|
|
|
p--;
|
|
|
|
while (p > path + mark && p[-1] != '\\') p--;
|
|
|
|
if (p > path + mark) p--;
|
|
|
|
}
|
2004-03-17 02:58:51 +01:00
|
|
|
*p = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* skip to the next component */
|
|
|
|
while (*p && *p != '\\') p++;
|
2005-06-24 13:55:28 +02:00
|
|
|
if (*p == '\\')
|
|
|
|
{
|
|
|
|
/* remove last dot in previous dir name */
|
2020-03-31 11:50:16 +02:00
|
|
|
if (p > path + mark && p[-1] == '.') memmove( p-1, p, (wcslen(p) + 1) * sizeof(WCHAR) );
|
2005-06-24 13:55:28 +02:00
|
|
|
else p++;
|
|
|
|
}
|
2004-03-17 02:58:51 +01:00
|
|
|
}
|
2004-05-15 00:10:24 +02:00
|
|
|
|
|
|
|
/* remove trailing spaces and dots (yes, Windows really does that, don't ask) */
|
|
|
|
while (p > path + mark && (p[-1] == ' ' || p[-1] == '.')) p--;
|
|
|
|
*p = 0;
|
2004-03-17 02:58:51 +01:00
|
|
|
}
|
|
|
|
|
2004-04-14 06:34:04 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* skip_unc_prefix
|
|
|
|
*
|
|
|
|
* Skip the \\share\dir\ part of a file name. Helper for RtlGetFullPathName_U.
|
|
|
|
*/
|
|
|
|
static const WCHAR *skip_unc_prefix( const WCHAR *ptr )
|
|
|
|
{
|
|
|
|
ptr += 2;
|
|
|
|
while (*ptr && !IS_SEPARATOR(*ptr)) ptr++; /* share name */
|
|
|
|
while (IS_SEPARATOR(*ptr)) ptr++;
|
|
|
|
while (*ptr && !IS_SEPARATOR(*ptr)) ptr++; /* dir name */
|
|
|
|
while (IS_SEPARATOR(*ptr)) ptr++;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-15 06:20:42 +02:00
|
|
|
/******************************************************************
|
|
|
|
* get_full_path_helper
|
|
|
|
*
|
|
|
|
* Helper for RtlGetFullPathName_U
|
2004-01-20 02:40:23 +01:00
|
|
|
* Note: name and buffer are allowed to point to the same memory spot
|
2003-05-15 06:20:42 +02:00
|
|
|
*/
|
|
|
|
static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size)
|
|
|
|
{
|
2004-05-15 00:10:24 +02:00
|
|
|
ULONG reqsize = 0, mark = 0, dep = 0, deplen;
|
2004-03-22 23:59:25 +01:00
|
|
|
LPWSTR ins_str = NULL;
|
2004-03-17 02:58:51 +01:00
|
|
|
LPCWSTR ptr;
|
2004-01-20 02:40:23 +01:00
|
|
|
const UNICODE_STRING* cd;
|
|
|
|
WCHAR tmp[4];
|
2004-03-17 02:58:51 +01:00
|
|
|
|
2004-05-15 00:10:24 +02:00
|
|
|
/* return error if name only consists of spaces */
|
|
|
|
for (ptr = name; *ptr; ptr++) if (*ptr != ' ') break;
|
|
|
|
if (!*ptr) return 0;
|
2004-05-13 07:21:23 +02:00
|
|
|
|
2003-05-15 06:20:42 +02:00
|
|
|
RtlAcquirePebLock();
|
2004-01-20 02:40:23 +01:00
|
|
|
|
2004-04-16 02:10:03 +02:00
|
|
|
if (NtCurrentTeb()->Tib.SubSystemTib) /* FIXME: hack */
|
2004-04-16 07:00:46 +02:00
|
|
|
cd = &((WIN16_SUBSYSTEM_TIB *)NtCurrentTeb()->Tib.SubSystemTib)->curdir.DosPath;
|
2004-04-16 02:10:03 +02:00
|
|
|
else
|
2004-04-16 07:00:46 +02:00
|
|
|
cd = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectory.DosPath;
|
2003-05-15 06:20:42 +02:00
|
|
|
|
2008-04-22 23:05:03 +02:00
|
|
|
switch (RtlDetermineDosPathNameType_U(name))
|
2003-05-15 06:20:42 +02:00
|
|
|
{
|
|
|
|
case UNC_PATH: /* \\foo */
|
2004-04-14 06:34:04 +02:00
|
|
|
ptr = skip_unc_prefix( name );
|
2004-03-17 02:58:51 +01:00
|
|
|
mark = (ptr - name);
|
|
|
|
break;
|
|
|
|
|
2003-05-15 06:20:42 +02:00
|
|
|
case DEVICE_PATH: /* \\.\foo */
|
2004-03-17 02:58:51 +01:00
|
|
|
mark = 4;
|
2003-05-15 06:20:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ABSOLUTE_DRIVE_PATH: /* c:\foo */
|
2004-01-20 02:40:23 +01:00
|
|
|
reqsize = sizeof(WCHAR);
|
2016-07-28 14:24:05 +02:00
|
|
|
tmp[0] = name[0];
|
2004-01-20 02:40:23 +01:00
|
|
|
ins_str = tmp;
|
|
|
|
dep = 1;
|
2004-03-17 02:58:51 +01:00
|
|
|
mark = 3;
|
2003-05-15 06:20:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RELATIVE_DRIVE_PATH: /* c:foo */
|
2004-01-20 02:40:23 +01:00
|
|
|
dep = 2;
|
2020-03-30 12:05:16 +02:00
|
|
|
if (wcsnicmp( name, cd->Buffer, 2 ))
|
2003-05-15 06:20:42 +02:00
|
|
|
{
|
|
|
|
UNICODE_STRING var, val;
|
|
|
|
|
2004-01-20 02:40:23 +01:00
|
|
|
tmp[0] = '=';
|
|
|
|
tmp[1] = name[0];
|
|
|
|
tmp[2] = ':';
|
|
|
|
tmp[3] = '\0';
|
|
|
|
var.Length = 3 * sizeof(WCHAR);
|
|
|
|
var.MaximumLength = 4 * sizeof(WCHAR);
|
|
|
|
var.Buffer = tmp;
|
2003-05-15 06:20:42 +02:00
|
|
|
val.Length = 0;
|
|
|
|
val.MaximumLength = size;
|
2004-01-20 02:40:23 +01:00
|
|
|
val.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, size);
|
2003-05-15 06:20:42 +02:00
|
|
|
|
|
|
|
switch (RtlQueryEnvironmentVariable_U(NULL, &var, &val))
|
|
|
|
{
|
|
|
|
case STATUS_SUCCESS:
|
|
|
|
/* FIXME: Win2k seems to check that the environment variable actually points
|
|
|
|
* to an existing directory. If not, root of the drive is used
|
|
|
|
* (this seems also to be the only spot in RtlGetFullPathName that the
|
|
|
|
* existence of a part of a path is checked)
|
|
|
|
*/
|
2012-05-15 10:15:32 +02:00
|
|
|
/* fall through */
|
2003-05-15 06:20:42 +02:00
|
|
|
case STATUS_BUFFER_TOO_SMALL:
|
2004-01-20 02:40:23 +01:00
|
|
|
reqsize = val.Length + sizeof(WCHAR); /* append trailing '\\' */
|
|
|
|
val.Buffer[val.Length / sizeof(WCHAR)] = '\\';
|
|
|
|
ins_str = val.Buffer;
|
2003-05-15 06:20:42 +02:00
|
|
|
break;
|
|
|
|
case STATUS_VARIABLE_NOT_FOUND:
|
2004-01-20 02:40:23 +01:00
|
|
|
reqsize = 3 * sizeof(WCHAR);
|
|
|
|
tmp[0] = name[0];
|
|
|
|
tmp[1] = ':';
|
|
|
|
tmp[2] = '\\';
|
|
|
|
ins_str = tmp;
|
2010-01-08 16:07:12 +01:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, val.Buffer);
|
2003-05-15 06:20:42 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Unsupported status code\n");
|
2010-01-08 16:07:12 +01:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, val.Buffer);
|
2003-05-15 06:20:42 +02:00
|
|
|
break;
|
|
|
|
}
|
2004-03-17 02:58:51 +01:00
|
|
|
mark = 3;
|
2003-05-15 06:20:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case RELATIVE_PATH: /* foo */
|
2004-01-20 02:40:23 +01:00
|
|
|
reqsize = cd->Length;
|
|
|
|
ins_str = cd->Buffer;
|
2003-10-02 06:43:45 +02:00
|
|
|
if (cd->Buffer[1] != ':')
|
|
|
|
{
|
2004-04-14 06:34:04 +02:00
|
|
|
ptr = skip_unc_prefix( cd->Buffer );
|
2003-10-02 06:43:45 +02:00
|
|
|
mark = ptr - cd->Buffer;
|
|
|
|
}
|
2004-03-17 02:58:51 +01:00
|
|
|
else mark = 3;
|
2003-05-15 06:20:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ABSOLUTE_PATH: /* \xxx */
|
2004-04-01 04:09:14 +02:00
|
|
|
if (name[0] == '/') /* may be a Unix path */
|
|
|
|
{
|
2020-06-20 14:36:18 +02:00
|
|
|
char *unix_name;
|
2020-07-09 10:03:15 +02:00
|
|
|
WCHAR *nt_str;
|
2021-08-02 15:54:05 +02:00
|
|
|
ULONG buflen;
|
2020-07-09 10:03:15 +02:00
|
|
|
NTSTATUS status;
|
2021-02-28 11:29:17 +01:00
|
|
|
UNICODE_STRING str;
|
2021-08-02 15:54:05 +02:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
2021-02-28 11:29:17 +01:00
|
|
|
|
|
|
|
nt_str = RtlAllocateHeap( GetProcessHeap(), 0, (wcslen(name) + 9) * sizeof(WCHAR) );
|
|
|
|
wcscpy( nt_str, L"\\??\\unix" );
|
|
|
|
wcscat( nt_str, name );
|
|
|
|
RtlInitUnicodeString( &str, nt_str );
|
2021-08-02 15:54:05 +02:00
|
|
|
InitializeObjectAttributes( &attr, &str, 0, 0, NULL );
|
2021-02-28 11:29:17 +01:00
|
|
|
buflen = 3 * wcslen(name) + 1;
|
|
|
|
unix_name = RtlAllocateHeap( GetProcessHeap(), 0, buflen );
|
2021-08-02 15:54:05 +02:00
|
|
|
status = wine_nt_to_unix_file_name( &attr, unix_name, &buflen, FILE_OPEN_IF );
|
2021-03-02 12:04:00 +01:00
|
|
|
if (!status || status == STATUS_NO_SUCH_FILE)
|
2004-04-01 04:09:14 +02:00
|
|
|
{
|
2021-02-28 11:29:17 +01:00
|
|
|
buflen = wcslen(name) + 9;
|
2020-08-25 13:57:02 +02:00
|
|
|
status = wine_unix_to_nt_file_name( unix_name, nt_str, &buflen );
|
2020-07-09 10:03:15 +02:00
|
|
|
}
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, unix_name );
|
|
|
|
if (!status && buflen > 6 && nt_str[5] == ':')
|
|
|
|
{
|
|
|
|
reqsize = (buflen - 4) * sizeof(WCHAR);
|
2020-06-20 14:36:18 +02:00
|
|
|
if (reqsize <= size)
|
|
|
|
{
|
2020-07-09 10:03:15 +02:00
|
|
|
memcpy( buffer, nt_str + 4, reqsize );
|
2020-06-20 14:36:18 +02:00
|
|
|
collapse_path( buffer, 3 );
|
|
|
|
reqsize -= sizeof(WCHAR);
|
|
|
|
}
|
2020-07-09 10:03:15 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, nt_str );
|
2020-06-20 14:36:18 +02:00
|
|
|
goto done;
|
2004-04-01 04:09:14 +02:00
|
|
|
}
|
2020-07-09 10:03:15 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, nt_str );
|
2004-04-01 04:09:14 +02:00
|
|
|
}
|
2003-05-15 06:20:42 +02:00
|
|
|
if (cd->Buffer[1] == ':')
|
|
|
|
{
|
2004-01-20 02:40:23 +01:00
|
|
|
reqsize = 2 * sizeof(WCHAR);
|
|
|
|
tmp[0] = cd->Buffer[0];
|
|
|
|
tmp[1] = ':';
|
|
|
|
ins_str = tmp;
|
2004-03-17 02:58:51 +01:00
|
|
|
mark = 3;
|
2003-05-15 06:20:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-04-14 06:34:04 +02:00
|
|
|
ptr = skip_unc_prefix( cd->Buffer );
|
2004-01-20 02:40:23 +01:00
|
|
|
reqsize = (ptr - cd->Buffer) * sizeof(WCHAR);
|
|
|
|
mark = reqsize / sizeof(WCHAR);
|
|
|
|
ins_str = cd->Buffer;
|
2003-05-15 06:20:42 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNC_DOT_PATH: /* \\. */
|
2004-01-20 02:40:23 +01:00
|
|
|
reqsize = 4 * sizeof(WCHAR);
|
|
|
|
dep = 3;
|
|
|
|
tmp[0] = '\\';
|
|
|
|
tmp[1] = '\\';
|
|
|
|
tmp[2] = '.';
|
|
|
|
tmp[3] = '\\';
|
|
|
|
ins_str = tmp;
|
2004-03-17 02:58:51 +01:00
|
|
|
mark = 4;
|
2003-05-15 06:20:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INVALID_PATH:
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-01-20 02:40:23 +01:00
|
|
|
/* enough space ? */
|
2020-03-31 11:50:16 +02:00
|
|
|
deplen = wcslen(name + dep) * sizeof(WCHAR);
|
2004-01-20 02:40:23 +01:00
|
|
|
if (reqsize + deplen + sizeof(WCHAR) > size)
|
|
|
|
{
|
|
|
|
/* not enough space, return need size (including terminating '\0') */
|
|
|
|
reqsize += deplen + sizeof(WCHAR);
|
|
|
|
goto done;
|
|
|
|
}
|
2003-05-15 06:20:42 +02:00
|
|
|
|
2004-05-15 00:10:24 +02:00
|
|
|
memmove(buffer + reqsize / sizeof(WCHAR), name + dep, deplen + sizeof(WCHAR));
|
2004-01-20 02:40:23 +01:00
|
|
|
if (reqsize) memcpy(buffer, ins_str, reqsize);
|
2003-05-15 06:20:42 +02:00
|
|
|
|
2006-06-12 00:11:36 +02:00
|
|
|
if (ins_str != tmp && ins_str != cd->Buffer)
|
2004-01-20 02:40:23 +01:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, ins_str);
|
2003-05-15 06:20:42 +02:00
|
|
|
|
2004-03-22 23:59:25 +01:00
|
|
|
collapse_path( buffer, mark );
|
2020-03-31 11:50:16 +02:00
|
|
|
reqsize = wcslen(buffer) * sizeof(WCHAR);
|
2003-05-15 06:20:42 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
RtlReleasePebLock();
|
|
|
|
return reqsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* RtlGetFullPathName_U (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Returns the number of bytes written to buffer (not including the
|
|
|
|
* terminating NULL) if the function succeeds, or the required number of bytes
|
2003-10-04 05:06:58 +02:00
|
|
|
* (including the terminating NULL) if the buffer is too small.
|
2003-05-15 06:20:42 +02:00
|
|
|
*
|
|
|
|
* file_part will point to the filename part inside buffer (except if we use
|
|
|
|
* DOS device name, in which case file_in_buf is NULL)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
DWORD WINAPI RtlGetFullPathName_U(const WCHAR* name, ULONG size, WCHAR* buffer,
|
|
|
|
WCHAR** file_part)
|
|
|
|
{
|
2003-10-07 05:46:34 +02:00
|
|
|
WCHAR* ptr;
|
2003-05-15 06:20:42 +02:00
|
|
|
DWORD dosdev;
|
|
|
|
DWORD reqsize;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("(%s %u %p %p)\n", debugstr_w(name), size, buffer, file_part);
|
2003-05-15 06:20:42 +02:00
|
|
|
|
|
|
|
if (!name || !*name) return 0;
|
|
|
|
|
|
|
|
if (file_part) *file_part = NULL;
|
|
|
|
|
|
|
|
/* check for DOS device name */
|
|
|
|
dosdev = RtlIsDosDeviceName_U(name);
|
|
|
|
if (dosdev)
|
|
|
|
{
|
|
|
|
DWORD offset = HIWORD(dosdev) / sizeof(WCHAR); /* get it in WCHARs, not bytes */
|
|
|
|
DWORD sz = LOWORD(dosdev); /* in bytes */
|
|
|
|
|
|
|
|
if (8 + sz + 2 > size) return sz + 10;
|
2020-12-04 00:36:32 +01:00
|
|
|
wcscpy(buffer, L"\\\\.\\");
|
2003-05-15 06:20:42 +02:00
|
|
|
memmove(buffer + 4, name + offset, sz);
|
|
|
|
buffer[4 + sz / sizeof(WCHAR)] = '\0';
|
|
|
|
/* file_part isn't set in this case */
|
|
|
|
return sz + 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
reqsize = get_full_path_helper(name, buffer, size);
|
2004-05-13 07:21:23 +02:00
|
|
|
if (!reqsize) return 0;
|
2003-05-15 06:20:42 +02:00
|
|
|
if (reqsize > size)
|
|
|
|
{
|
2004-03-12 02:59:35 +01:00
|
|
|
LPWSTR tmp = RtlAllocateHeap(GetProcessHeap(), 0, reqsize);
|
2003-10-07 05:46:34 +02:00
|
|
|
reqsize = get_full_path_helper(name, tmp, reqsize);
|
2007-10-19 14:40:23 +02:00
|
|
|
if (reqsize + sizeof(WCHAR) > size) /* it may have worked the second time */
|
2003-10-07 05:46:34 +02:00
|
|
|
{
|
2004-03-12 02:59:35 +01:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, tmp);
|
2003-10-07 05:46:34 +02:00
|
|
|
return reqsize + sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
memcpy( buffer, tmp, reqsize + sizeof(WCHAR) );
|
2004-03-12 02:59:35 +01:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, tmp);
|
2003-05-15 06:20:42 +02:00
|
|
|
}
|
2003-10-07 05:46:34 +02:00
|
|
|
|
|
|
|
/* find file part */
|
2020-03-31 11:47:47 +02:00
|
|
|
if (file_part && (ptr = wcsrchr(buffer, '\\')) != NULL && ptr >= buffer + 2 && *++ptr)
|
2003-10-07 05:46:34 +02:00
|
|
|
*file_part = ptr;
|
2003-05-15 06:20:42 +02:00
|
|
|
return reqsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* RtlGetLongestNtPathLength [NTDLL.@]
|
|
|
|
*
|
|
|
|
* Get the longest allowed path length
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The longest allowed path length (277 characters under Win2k).
|
|
|
|
*/
|
|
|
|
DWORD WINAPI RtlGetLongestNtPathLength(void)
|
|
|
|
{
|
2005-07-14 14:33:30 +02:00
|
|
|
return MAX_NT_PATH_LENGTH;
|
2003-05-15 06:20:42 +02:00
|
|
|
}
|
|
|
|
|
2021-07-05 12:22:32 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* RtlDoesFileExists_U (NTDLL.@)
|
|
|
|
*/
|
|
|
|
BOOLEAN WINAPI RtlDoesFileExists_U(LPCWSTR file_name)
|
|
|
|
{
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
FILE_BASIC_INFORMATION basic_info;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( file_name, &nt_name, NULL, NULL )) return FALSE;
|
|
|
|
InitializeObjectAttributes( &attr, &nt_name, OBJ_CASE_INSENSITIVE, 0, NULL );
|
|
|
|
status = NtQueryAttributesFile(&attr, &basic_info);
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-17 01:15:29 +02:00
|
|
|
/******************************************************************
|
|
|
|
* RtlIsNameLegalDOS8Dot3 (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Returns TRUE iff unicode is a valid DOS (8+3) name.
|
|
|
|
* If the name is valid, oem gets filled with the corresponding OEM string
|
|
|
|
* spaces is set to TRUE if unicode contains spaces
|
|
|
|
*/
|
|
|
|
BOOLEAN WINAPI RtlIsNameLegalDOS8Dot3( const UNICODE_STRING *unicode,
|
|
|
|
OEM_STRING *oem, BOOLEAN *spaces )
|
|
|
|
{
|
2006-11-29 11:02:45 +01:00
|
|
|
static const char illegal[] = "*?<>|\"+=,;[]:/\\\345";
|
2003-04-17 01:15:29 +02:00
|
|
|
int dot = -1;
|
2004-08-14 01:53:44 +02:00
|
|
|
int i;
|
2003-04-17 01:15:29 +02:00
|
|
|
char buffer[12];
|
|
|
|
OEM_STRING oem_str;
|
|
|
|
BOOLEAN got_space = FALSE;
|
|
|
|
|
|
|
|
if (!oem)
|
|
|
|
{
|
|
|
|
oem_str.Length = sizeof(buffer);
|
|
|
|
oem_str.MaximumLength = sizeof(buffer);
|
|
|
|
oem_str.Buffer = buffer;
|
|
|
|
oem = &oem_str;
|
|
|
|
}
|
|
|
|
if (RtlUpcaseUnicodeStringToCountedOemString( oem, unicode, FALSE ) != STATUS_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (oem->Length > 12) return FALSE;
|
|
|
|
|
|
|
|
/* a starting . is invalid, except for . and .. */
|
2015-09-08 16:32:12 +02:00
|
|
|
if (oem->Length > 0 && oem->Buffer[0] == '.')
|
2003-04-17 01:15:29 +02:00
|
|
|
{
|
|
|
|
if (oem->Length != 1 && (oem->Length != 2 || oem->Buffer[1] != '.')) return FALSE;
|
|
|
|
if (spaces) *spaces = FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < oem->Length; i++)
|
|
|
|
{
|
|
|
|
switch (oem->Buffer[i])
|
|
|
|
{
|
|
|
|
case ' ':
|
|
|
|
/* leading/trailing spaces not allowed */
|
|
|
|
if (!i || i == oem->Length-1 || oem->Buffer[i+1] == '.') return FALSE;
|
|
|
|
got_space = TRUE;
|
|
|
|
break;
|
|
|
|
case '.':
|
|
|
|
if (dot != -1) return FALSE;
|
|
|
|
dot = i;
|
|
|
|
break;
|
|
|
|
default:
|
2004-01-15 01:20:46 +01:00
|
|
|
if (strchr(illegal, oem->Buffer[i])) return FALSE;
|
2003-04-17 01:15:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* check file part is shorter than 8, extension shorter than 3
|
|
|
|
* dot cannot be last in string
|
|
|
|
*/
|
|
|
|
if (dot == -1)
|
|
|
|
{
|
|
|
|
if (oem->Length > 8) return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (dot > 8 || (oem->Length - dot > 4) || dot == oem->Length - 1) return FALSE;
|
|
|
|
}
|
|
|
|
if (spaces) *spaces = got_space;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-05-15 06:20:42 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* RtlGetCurrentDirectory_U (NTDLL.@)
|
|
|
|
*
|
|
|
|
*/
|
2017-10-23 08:48:22 +02:00
|
|
|
ULONG WINAPI RtlGetCurrentDirectory_U(ULONG buflen, LPWSTR buf)
|
2003-05-15 06:20:42 +02:00
|
|
|
{
|
|
|
|
UNICODE_STRING* us;
|
|
|
|
ULONG len;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("(%u %p)\n", buflen, buf);
|
2003-05-15 06:20:42 +02:00
|
|
|
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
|
2004-04-16 02:10:03 +02:00
|
|
|
if (NtCurrentTeb()->Tib.SubSystemTib) /* FIXME: hack */
|
2004-04-16 07:00:46 +02:00
|
|
|
us = &((WIN16_SUBSYSTEM_TIB *)NtCurrentTeb()->Tib.SubSystemTib)->curdir.DosPath;
|
2004-04-16 02:10:03 +02:00
|
|
|
else
|
2004-04-16 07:00:46 +02:00
|
|
|
us = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectory.DosPath;
|
2004-04-16 02:10:03 +02:00
|
|
|
|
2003-05-15 06:20:42 +02:00
|
|
|
len = us->Length / sizeof(WCHAR);
|
|
|
|
if (us->Buffer[len - 1] == '\\' && us->Buffer[len - 2] != ':')
|
|
|
|
len--;
|
|
|
|
|
|
|
|
if (buflen / sizeof(WCHAR) > len)
|
|
|
|
{
|
|
|
|
memcpy(buf, us->Buffer, len * sizeof(WCHAR));
|
|
|
|
buf[len] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlReleasePebLock();
|
|
|
|
|
|
|
|
return len * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* RtlSetCurrentDirectory_U (NTDLL.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlSetCurrentDirectory_U(const UNICODE_STRING* dir)
|
|
|
|
{
|
2004-04-16 07:00:46 +02:00
|
|
|
FILE_FS_DEVICE_INFORMATION device_info;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING newdir;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
CURDIR *curdir;
|
|
|
|
HANDLE handle;
|
|
|
|
NTSTATUS nts;
|
|
|
|
ULONG size;
|
|
|
|
PWSTR ptr;
|
|
|
|
|
|
|
|
newdir.Buffer = NULL;
|
2003-05-15 06:20:42 +02:00
|
|
|
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
|
2004-04-16 02:10:03 +02:00
|
|
|
if (NtCurrentTeb()->Tib.SubSystemTib) /* FIXME: hack */
|
|
|
|
curdir = &((WIN16_SUBSYSTEM_TIB *)NtCurrentTeb()->Tib.SubSystemTib)->curdir;
|
|
|
|
else
|
2004-04-16 07:00:46 +02:00
|
|
|
curdir = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectory;
|
2003-05-15 06:20:42 +02:00
|
|
|
|
2004-04-16 07:00:46 +02:00
|
|
|
if (!RtlDosPathNameToNtPathName_U( dir->Buffer, &newdir, NULL, NULL ))
|
2003-05-15 06:20:42 +02:00
|
|
|
{
|
|
|
|
nts = STATUS_OBJECT_NAME_INVALID;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2004-04-16 07:00:46 +02:00
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.ObjectName = &newdir;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
2016-09-21 15:00:41 +02:00
|
|
|
nts = NtOpenFile( &handle, FILE_TRAVERSE | SYNCHRONIZE, &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
|
2004-04-16 07:00:46 +02:00
|
|
|
if (nts != STATUS_SUCCESS) goto out;
|
|
|
|
|
|
|
|
/* don't keep the directory handle open on removable media */
|
|
|
|
if (!NtQueryVolumeInformationFile( handle, &io, &device_info,
|
|
|
|
sizeof(device_info), FileFsDeviceInformation ) &&
|
|
|
|
(device_info.Characteristics & FILE_REMOVABLE_MEDIA))
|
2003-05-15 06:20:42 +02:00
|
|
|
{
|
2004-04-16 07:00:46 +02:00
|
|
|
NtClose( handle );
|
|
|
|
handle = 0;
|
2003-05-15 06:20:42 +02:00
|
|
|
}
|
|
|
|
|
2004-04-16 07:00:46 +02:00
|
|
|
if (curdir->Handle) NtClose( curdir->Handle );
|
|
|
|
curdir->Handle = handle;
|
2003-05-15 06:20:42 +02:00
|
|
|
|
|
|
|
/* append trailing \ if missing */
|
2004-04-16 07:00:46 +02:00
|
|
|
size = newdir.Length / sizeof(WCHAR);
|
|
|
|
ptr = newdir.Buffer;
|
|
|
|
ptr += 4; /* skip \??\ prefix */
|
|
|
|
size -= 4;
|
|
|
|
if (size && ptr[size - 1] != '\\') ptr[size++] = '\\';
|
2003-05-15 06:20:42 +02:00
|
|
|
|
2018-08-23 16:14:18 +02:00
|
|
|
/* convert \??\UNC\ path to \\ prefix */
|
2020-12-04 00:36:32 +01:00
|
|
|
if (size >= 4 && !wcsnicmp(ptr, L"UNC\\", 4))
|
2018-08-23 16:14:18 +02:00
|
|
|
{
|
|
|
|
ptr += 2;
|
|
|
|
size -= 2;
|
|
|
|
*ptr = '\\';
|
|
|
|
}
|
|
|
|
|
2004-04-16 07:00:46 +02:00
|
|
|
memcpy( curdir->DosPath.Buffer, ptr, size * sizeof(WCHAR));
|
|
|
|
curdir->DosPath.Buffer[size] = 0;
|
|
|
|
curdir->DosPath.Length = size * sizeof(WCHAR);
|
2003-05-15 06:20:42 +02:00
|
|
|
|
2004-04-16 07:00:46 +02:00
|
|
|
TRACE( "curdir now %s %p\n", debugstr_w(curdir->DosPath.Buffer), curdir->Handle );
|
2003-05-15 06:20:42 +02:00
|
|
|
|
2004-04-16 07:00:46 +02:00
|
|
|
out:
|
|
|
|
RtlFreeUnicodeString( &newdir );
|
2003-05-15 06:20:42 +02:00
|
|
|
RtlReleasePebLock();
|
|
|
|
return nts;
|
|
|
|
}
|