kernel32: Move some directory functions to kernelbase.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-08-12 16:15:16 +02:00
parent 05d00276c6
commit 2c73a08655
7 changed files with 206 additions and 174 deletions

View File

@ -268,12 +268,12 @@
# @ stub CreateBoundaryDescriptorA
# @ stub CreateBoundaryDescriptorW
@ stdcall CreateConsoleScreenBuffer(long long ptr long ptr)
@ stdcall CreateDirectoryA(str ptr)
@ stdcall -import CreateDirectoryA(str ptr)
@ stdcall CreateDirectoryExA(str str ptr)
@ stdcall CreateDirectoryExW(wstr wstr ptr)
@ stdcall -import CreateDirectoryExW(wstr wstr ptr)
# @ stub CreateDirectoryTransactedA
# @ stub CreateDirectoryTransactedW
@ stdcall CreateDirectoryW(wstr ptr)
@ stdcall -import CreateDirectoryW(wstr ptr)
@ stdcall -import CreateEventA(ptr long long str)
@ stdcall -import CreateEventExA(ptr str long long)
@ stdcall -import CreateEventExW(ptr wstr long long)
@ -835,8 +835,8 @@
@ stdcall GetSystemTimeAsFileTime(ptr) ntdll.NtQuerySystemTime
@ stdcall GetSystemTimePreciseAsFileTime(ptr)
@ stdcall GetSystemTimes(ptr ptr ptr)
@ stdcall GetSystemWindowsDirectoryA(ptr long)
@ stdcall GetSystemWindowsDirectoryW(ptr long)
@ stdcall -import GetSystemWindowsDirectoryA(ptr long)
@ stdcall -import GetSystemWindowsDirectoryW(ptr long)
@ stdcall GetSystemWow64DirectoryA(ptr long)
@ stdcall GetSystemWow64DirectoryW(ptr long)
@ stdcall GetTapeParameters(ptr long ptr ptr)
@ -887,8 +887,8 @@
@ stdcall GetVolumePathNameW(wstr ptr long)
@ stdcall GetVolumePathNamesForVolumeNameA(str ptr long ptr)
@ stdcall GetVolumePathNamesForVolumeNameW(wstr ptr long ptr)
@ stdcall GetWindowsDirectoryA(ptr long)
@ stdcall GetWindowsDirectoryW(ptr long)
@ stdcall -import GetWindowsDirectoryA(ptr long)
@ stdcall -import GetWindowsDirectoryW(ptr long)
@ stdcall GetWriteWatch(long ptr long ptr ptr ptr)
# @ stub GetXStateFeaturesMask
@ stdcall GlobalAddAtomA(str)
@ -1601,10 +1601,10 @@
@ stdcall WideCharToMultiByte(long long wstr long ptr long ptr ptr)
@ stdcall WinExec(str long)
@ stdcall Wow64EnableWow64FsRedirection(long)
@ stdcall Wow64DisableWow64FsRedirection(ptr)
@ stdcall -import Wow64DisableWow64FsRedirection(ptr)
@ stdcall Wow64GetThreadContext(long ptr)
# @ stub Wow64GetThreadSelectorEntry
@ stdcall Wow64RevertWow64FsRedirection(ptr)
@ stdcall -import Wow64RevertWow64FsRedirection(ptr)
@ stdcall Wow64SetThreadContext(long ptr)
# @ stub Wow64SuspendThread
@ stdcall WriteConsoleA(long ptr long ptr ptr)

View File

@ -1604,67 +1604,6 @@ BOOL WINAPI CreateHardLinkA(LPCSTR lpFileName, LPCSTR lpExistingFileName,
}
/***********************************************************************
* CreateDirectoryW (KERNEL32.@)
* RETURNS:
* TRUE : success
* FALSE : failure
* ERROR_DISK_FULL: on full disk
* ERROR_ALREADY_EXISTS: if directory name exists (even as file)
* ERROR_ACCESS_DENIED: on permission problems
* ERROR_FILENAME_EXCED_RANGE: too long filename(s)
*/
BOOL WINAPI CreateDirectoryW( LPCWSTR path, LPSECURITY_ATTRIBUTES sa )
{
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nt_name;
IO_STATUS_BLOCK io;
NTSTATUS status;
HANDLE handle;
BOOL ret = FALSE;
TRACE( "%s\n", debugstr_w(path) );
if (!RtlDosPathNameToNtPathName_U( path, &nt_name, NULL, NULL ))
{
SetLastError( ERROR_PATH_NOT_FOUND );
return FALSE;
}
attr.Length = sizeof(attr);
attr.RootDirectory = 0;
attr.Attributes = OBJ_CASE_INSENSITIVE;
attr.ObjectName = &nt_name;
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
attr.SecurityQualityOfService = NULL;
status = NtCreateFile( &handle, GENERIC_READ | SYNCHRONIZE, &attr, &io, NULL,
FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_CREATE,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 );
if (status == STATUS_SUCCESS)
{
NtClose( handle );
ret = TRUE;
}
else SetLastError( RtlNtStatusToDosError(status) );
RtlFreeUnicodeString( &nt_name );
return ret;
}
/***********************************************************************
* CreateDirectoryA (KERNEL32.@)
*/
BOOL WINAPI CreateDirectoryA( LPCSTR path, LPSECURITY_ATTRIBUTES sa )
{
WCHAR *pathW;
if (!(pathW = FILE_name_AtoW( path, FALSE ))) return FALSE;
return CreateDirectoryW( pathW, sa );
}
/***********************************************************************
* CreateDirectoryExA (KERNEL32.@)
*/
@ -1682,15 +1621,6 @@ BOOL WINAPI CreateDirectoryExA( LPCSTR template, LPCSTR path, LPSECURITY_ATTRIBU
}
/***********************************************************************
* CreateDirectoryExW (KERNEL32.@)
*/
BOOL WINAPI CreateDirectoryExW( LPCWSTR template, LPCWSTR path, LPSECURITY_ATTRIBUTES sa )
{
return CreateDirectoryW( path, sa );
}
/***********************************************************************
* RemoveDirectoryW (KERNEL32.@)
*/
@ -1827,56 +1757,6 @@ BOOL WINAPI SetCurrentDirectoryA( LPCSTR dir )
}
/***********************************************************************
* GetWindowsDirectoryW (KERNEL32.@)
*
* See comment for GetWindowsDirectoryA.
*/
UINT WINAPI GetWindowsDirectoryW( LPWSTR path, UINT count )
{
UINT len = strlenW( DIR_Windows ) + 1;
if (path && count >= len)
{
strcpyW( path, DIR_Windows );
len--;
}
return len;
}
/***********************************************************************
* GetWindowsDirectoryA (KERNEL32.@)
*
* Return value:
* If buffer is large enough to hold full path and terminating '\0' character
* function copies path to buffer and returns length of the path without '\0'.
* Otherwise function returns required size including '\0' character and
* does not touch the buffer.
*/
UINT WINAPI GetWindowsDirectoryA( LPSTR path, UINT count )
{
return copy_filename_WtoA( DIR_Windows, path, count );
}
/***********************************************************************
* GetSystemWindowsDirectoryA (KERNEL32.@) W2K, TS4.0SP4
*/
UINT WINAPI GetSystemWindowsDirectoryA( LPSTR path, UINT count )
{
return GetWindowsDirectoryA( path, count );
}
/***********************************************************************
* GetSystemWindowsDirectoryW (KERNEL32.@) W2K, TS4.0SP4
*/
UINT WINAPI GetSystemWindowsDirectoryW( LPWSTR path, UINT count )
{
return GetWindowsDirectoryW( path, count );
}
/***********************************************************************
* GetSystemDirectoryW (KERNEL32.@)
*
@ -1958,28 +1838,6 @@ BOOLEAN WINAPI Wow64EnableWow64FsRedirection( BOOLEAN enable )
}
/***********************************************************************
* Wow64DisableWow64FsRedirection (KERNEL32.@)
*/
BOOL WINAPI Wow64DisableWow64FsRedirection( PVOID *old_value )
{
NTSTATUS status = RtlWow64EnableFsRedirectionEx( TRUE, (ULONG *)old_value );
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* Wow64RevertWow64FsRedirection (KERNEL32.@)
*/
BOOL WINAPI Wow64RevertWow64FsRedirection( PVOID old_value )
{
NTSTATUS status = RtlWow64EnableFsRedirection( !old_value );
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* NeedCurrentDirectoryForExePathW (KERNEL32.@)
*/

View File

@ -42,6 +42,9 @@
WINE_DEFAULT_DEBUG_CHANNEL(file);
const WCHAR windows_dir[] = {'C',':','\\','w','i','n','d','o','w','s',0};
const WCHAR system_dir[] = {'C',':','\\','w','i','n','d','o','w','s','\\','s','y','s','t','e','m','3','2',0};
static const WCHAR krnl386W[] = {'k','r','n','l','3','8','6','.','e','x','e','1','6',0};
static BOOL oem_file_apis;
@ -59,6 +62,35 @@ static void WINAPI read_write_apc( void *apc_user, PIO_STATUS_BLOCK io, ULONG re
***********************************************************************/
/***********************************************************************
* copy_filename_WtoA
*
* copy a file name back to OEM/Ansi, but only if the buffer is large enough
*/
static DWORD copy_filename_WtoA( LPCWSTR nameW, LPSTR buffer, DWORD len )
{
UNICODE_STRING strW;
DWORD ret;
RtlInitUnicodeString( &strW, nameW );
ret = oem_file_apis ? RtlUnicodeStringToOemSize( &strW ) : RtlUnicodeStringToAnsiSize( &strW );
if (buffer && ret <= len)
{
ANSI_STRING str;
str.Buffer = buffer;
str.MaximumLength = min( len, UNICODE_STRING_MAX_CHARS );
if (oem_file_apis)
RtlUnicodeStringToOemString( &str, &strW, FALSE );
else
RtlUnicodeStringToAnsiString( &str, &strW, FALSE );
ret = str.Length; /* length without terminating 0 */
}
return ret;
}
/***********************************************************************
* file_name_AtoW
*
@ -117,6 +149,63 @@ BOOL WINAPI DECLSPEC_HOTPATCH AreFileApisANSI(void)
}
/***********************************************************************
* CreateDirectoryA (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH CreateDirectoryA( LPCSTR path, LPSECURITY_ATTRIBUTES sa )
{
WCHAR *pathW;
if (!(pathW = file_name_AtoW( path, FALSE ))) return FALSE;
return CreateDirectoryW( pathW, sa );
}
/***********************************************************************
* CreateDirectoryW (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH CreateDirectoryW( LPCWSTR path, LPSECURITY_ATTRIBUTES sa )
{
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nt_name;
IO_STATUS_BLOCK io;
NTSTATUS status;
HANDLE handle;
TRACE( "%s\n", debugstr_w(path) );
if (!RtlDosPathNameToNtPathName_U( path, &nt_name, NULL, NULL ))
{
SetLastError( ERROR_PATH_NOT_FOUND );
return FALSE;
}
attr.Length = sizeof(attr);
attr.RootDirectory = 0;
attr.Attributes = OBJ_CASE_INSENSITIVE;
attr.ObjectName = &nt_name;
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
attr.SecurityQualityOfService = NULL;
status = NtCreateFile( &handle, GENERIC_READ | SYNCHRONIZE, &attr, &io, NULL,
FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_CREATE,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 );
if (status == STATUS_SUCCESS) NtClose( handle );
RtlFreeUnicodeString( &nt_name );
return set_ntstatus( status );
}
/***********************************************************************
* CreateDirectoryEx (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH CreateDirectoryExW( LPCWSTR template, LPCWSTR path,
LPSECURITY_ATTRIBUTES sa )
{
return CreateDirectoryW( path, sa );
}
/*************************************************************************
* CreateFile2 (kernelbase.@)
*/
@ -552,6 +641,72 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetFileAttributesExW( LPCWSTR name, GET_FILEEX_INF
}
/***********************************************************************
* GetSystemDirectoryA (kernelbase.@)
*/
UINT WINAPI DECLSPEC_HOTPATCH GetSystemDirectoryA( LPSTR path, UINT count )
{
return copy_filename_WtoA( system_dir, path, count );
}
/***********************************************************************
* GetSystemDirectoryW (kernelbase.@)
*/
UINT WINAPI DECLSPEC_HOTPATCH GetSystemDirectoryW( LPWSTR path, UINT count )
{
UINT len = lstrlenW( system_dir ) + 1;
if (path && count >= len)
{
lstrcpyW( path, system_dir );
len--;
}
return len;
}
/***********************************************************************
* GetSystemWindowsDirectoryA (kernelbase.@)
*/
UINT WINAPI DECLSPEC_HOTPATCH GetSystemWindowsDirectoryA( LPSTR path, UINT count )
{
return GetWindowsDirectoryA( path, count );
}
/***********************************************************************
* GetSystemWindowsDirectoryW (kernelbase.@)
*/
UINT WINAPI DECLSPEC_HOTPATCH GetSystemWindowsDirectoryW( LPWSTR path, UINT count )
{
return GetWindowsDirectoryW( path, count );
}
/***********************************************************************
* GetWindowsDirectoryA (kernelbase.@)
*/
UINT WINAPI DECLSPEC_HOTPATCH GetWindowsDirectoryA( LPSTR path, UINT count )
{
return copy_filename_WtoA( windows_dir, path, count );
}
/***********************************************************************
* GetWindowsDirectoryW (kernelbase.@)
*/
UINT WINAPI DECLSPEC_HOTPATCH GetWindowsDirectoryW( LPWSTR path, UINT count )
{
UINT len = lstrlenW( windows_dir ) + 1;
if (path && count >= len)
{
lstrcpyW( path, windows_dir );
len--;
}
return len;
}
/**************************************************************************
* SetFileApisToANSI (kernelbase.@)
*/
@ -624,6 +779,24 @@ BOOL WINAPI DECLSPEC_HOTPATCH SetFileAttributesW( LPCWSTR name, DWORD attributes
}
/***********************************************************************
* Wow64DisableWow64FsRedirection (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH Wow64DisableWow64FsRedirection( PVOID *old_value )
{
return set_ntstatus( RtlWow64EnableFsRedirectionEx( TRUE, (ULONG *)old_value ));
}
/***********************************************************************
* Wow64RevertWow64FsRedirection (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH Wow64RevertWow64FsRedirection( PVOID old_value )
{
return set_ntstatus( RtlWow64EnableFsRedirection( !old_value ));
}
/***********************************************************************
* Operations on file handles
***********************************************************************/

View File

@ -27,6 +27,9 @@
extern WCHAR *file_name_AtoW( LPCSTR name, BOOL alloc ) DECLSPEC_HIDDEN;
extern DWORD file_name_WtoA( LPCWSTR src, INT srclen, LPSTR dest, INT destlen ) DECLSPEC_HIDDEN;
extern const WCHAR windows_dir[] DECLSPEC_HIDDEN;
extern const WCHAR system_dir[] DECLSPEC_HIDDEN;
static inline BOOL is_console_handle(HANDLE h)
{
return h != INVALID_HANDLE_VALUE && ((UINT_PTR)h & 3) == 3;

View File

@ -175,9 +175,9 @@
# @ stub CreateAppContainerToken
# @ stub CreateBoundaryDescriptorW
@ stdcall CreateConsoleScreenBuffer(long long ptr long ptr) kernel32.CreateConsoleScreenBuffer
@ stdcall CreateDirectoryA(str ptr) kernel32.CreateDirectoryA
@ stdcall CreateDirectoryExW(wstr wstr ptr) kernel32.CreateDirectoryExW
@ stdcall CreateDirectoryW(wstr ptr) kernel32.CreateDirectoryW
@ stdcall CreateDirectoryA(str ptr)
@ stdcall CreateDirectoryExW(wstr wstr ptr)
@ stdcall CreateDirectoryW(wstr ptr)
# @ stub CreateEnclave
@ stdcall CreateEventA(ptr long long str)
@ stdcall CreateEventExA(ptr str long long)
@ -685,8 +685,8 @@
@ stdcall GetSystemDefaultLangID() kernel32.GetSystemDefaultLangID
@ stdcall GetSystemDefaultLocaleName(ptr long) kernel32.GetSystemDefaultLocaleName
@ stdcall GetSystemDefaultUILanguage() kernel32.GetSystemDefaultUILanguage
@ stdcall GetSystemDirectoryA(ptr long) kernel32.GetSystemDirectoryA
@ stdcall GetSystemDirectoryW(ptr long) kernel32.GetSystemDirectoryW
@ stdcall GetSystemDirectoryA(ptr long)
@ stdcall GetSystemDirectoryW(ptr long)
@ stdcall GetSystemFileCacheSize(ptr ptr ptr) kernel32.GetSystemFileCacheSize
@ stdcall GetSystemFirmwareTable(long long ptr long) kernel32.GetSystemFirmwareTable
@ stdcall GetSystemInfo(ptr) kernel32.GetSystemInfo
@ -700,8 +700,8 @@
@ stdcall GetSystemTimeAsFileTime(ptr) kernel32.GetSystemTimeAsFileTime
@ stdcall GetSystemTimePreciseAsFileTime(ptr) kernel32.GetSystemTimePreciseAsFileTime
@ stdcall GetSystemTimes(ptr ptr ptr) kernel32.GetSystemTimes
@ stdcall GetSystemWindowsDirectoryA(ptr long) kernel32.GetSystemWindowsDirectoryA
@ stdcall GetSystemWindowsDirectoryW(ptr long) kernel32.GetSystemWindowsDirectoryW
@ stdcall GetSystemWindowsDirectoryA(ptr long)
@ stdcall GetSystemWindowsDirectoryW(ptr long)
# @ stub GetSystemWow64Directory2A
# @ stub GetSystemWow64Directory2W
@ stdcall GetSystemWow64DirectoryA(ptr long) kernel32.GetSystemWow64DirectoryA
@ -760,8 +760,8 @@
@ stdcall GetVolumePathNameW(wstr ptr long) kernel32.GetVolumePathNameW
@ stdcall GetVolumePathNamesForVolumeNameW(wstr ptr long ptr) kernel32.GetVolumePathNamesForVolumeNameW
@ stdcall GetWindowsAccountDomainSid(ptr ptr ptr)
@ stdcall GetWindowsDirectoryA(ptr long) kernel32.GetWindowsDirectoryA
@ stdcall GetWindowsDirectoryW(ptr long) kernel32.GetWindowsDirectoryW
@ stdcall GetWindowsDirectoryA(ptr long)
@ stdcall GetWindowsDirectoryW(ptr long)
@ stdcall GetWriteWatch(long ptr long ptr ptr ptr) kernel32.GetWriteWatch
# @ stub GetWsChanges
# @ stub GetWsChangesEx
@ -1713,8 +1713,8 @@
# @ stub WerpNotifyLoadStringResource
# @ stub WerpNotifyUseStringResource
@ stdcall WideCharToMultiByte(long long wstr long ptr long ptr ptr) kernel32.WideCharToMultiByte
@ stdcall Wow64DisableWow64FsRedirection(ptr) kernel32.Wow64DisableWow64FsRedirection
@ stdcall Wow64RevertWow64FsRedirection(ptr) kernel32.Wow64RevertWow64FsRedirection
@ stdcall Wow64DisableWow64FsRedirection(ptr)
@ stdcall Wow64RevertWow64FsRedirection(ptr)
# @ stub Wow64SetThreadDefaultGuestMachine
# @ stub -arch=i386 Wow64Transition
@ stdcall WriteConsoleA(long ptr long ptr ptr) kernel32.WriteConsoleA

View File

@ -39,6 +39,7 @@
#include "shlwapi.h"
#include "sddl.h"
#include "kernelbase.h"
#include "wine/debug.h"
#include "wine/heap.h"
#include "wine/list.h"
@ -3075,7 +3076,6 @@ DWORD WINAPI EnumDynamicTimeZoneInformation(const DWORD index,
static const WCHAR mui_dltW[] = { 'M','U','I','_','D','l','t',0 };
WCHAR keyname[ARRAY_SIZE(dtzi->TimeZoneKeyName)];
HKEY time_zones_key, sub_key;
WCHAR sysdir[MAX_PATH];
LSTATUS ret;
DWORD size;
struct tz_reg_data
@ -3103,13 +3103,12 @@ DWORD WINAPI EnumDynamicTimeZoneInformation(const DWORD index,
ret = RegOpenKeyExW( time_zones_key, keyname, 0, KEY_QUERY_VALUE, &sub_key );
if (ret) goto cleanup;
GetSystemDirectoryW(sysdir, ARRAY_SIZE(sysdir));
size = sizeof(dtzi->StandardName);
ret = RegLoadMUIStringW( sub_key, mui_stdW, dtzi->StandardName, size, NULL, 0, sysdir );
ret = RegLoadMUIStringW( sub_key, mui_stdW, dtzi->StandardName, size, NULL, 0, system_dir );
if (ret) goto cleanup;
size = sizeof(dtzi->DaylightName);
ret = RegLoadMUIStringW( sub_key, mui_dltW, dtzi->DaylightName, size, NULL, 0, sysdir );
ret = RegLoadMUIStringW( sub_key, mui_dltW, dtzi->DaylightName, size, NULL, 0, system_dir );
if (ret) goto cleanup;
size = sizeof(tz_data);

View File

@ -38,6 +38,8 @@
#include "winternl.h"
#include "lzexpand.h"
#include "winerror.h"
#include "kernelbase.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(ver);
@ -1267,7 +1269,6 @@ DWORD WINAPI VerFindFileW( DWORD flags, LPCWSTR filename, LPCWSTR win_dir, LPCWS
DWORD retval = 0;
const WCHAR *curDir;
const WCHAR *destDir;
WCHAR winDir[MAX_PATH], systemDir[MAX_PATH];
TRACE("flags = %x filename=%s windir=%s appdir=%s curdirlen=%p(%u) destdirlen=%p(%u)\n",
flags, debugstr_w(filename), debugstr_w(win_dir), debugstr_w(app_dir),
@ -1276,12 +1277,11 @@ DWORD WINAPI VerFindFileW( DWORD flags, LPCWSTR filename, LPCWSTR win_dir, LPCWS
/* Figure out where the file should go; shared files default to the
system directory */
GetSystemDirectoryW(systemDir, ARRAY_SIZE(systemDir));
curDir = &emptyW;
if(flags & VFFF_ISSHAREDFILE)
{
destDir = systemDir;
destDir = system_dir;
/* Were we given a filename? If so, try to find the file. */
if(filename)
{
@ -1298,16 +1298,15 @@ DWORD WINAPI VerFindFileW( DWORD flags, LPCWSTR filename, LPCWSTR win_dir, LPCWS
destDir = app_dir ? app_dir : &emptyW;
if(filename)
{
GetWindowsDirectoryW( winDir, MAX_PATH );
if(file_existsW(destDir, filename, FALSE)) curDir = destDir;
else if(file_existsW(winDir, filename, FALSE))
else if(file_existsW(windows_dir, filename, FALSE))
{
curDir = winDir;
curDir = windows_dir;
retval |= VFF_CURNEDEST;
}
else if(file_existsW(systemDir, filename, FALSE))
else if (file_existsW(system_dir, filename, FALSE))
{
curDir = systemDir;
curDir = system_dir;
retval |= VFF_CURNEDEST;
}
}