2004-01-15 01:20:46 +01:00
|
|
|
/*
|
|
|
|
* File handling functions
|
|
|
|
*
|
|
|
|
* Copyright 1993 Erik Bos
|
2004-05-01 07:25:07 +02:00
|
|
|
* Copyright 1996, 2004 Alexandre Julliard
|
2004-01-15 01:20:46 +01:00
|
|
|
* Copyright 2003 Eric Pouech
|
|
|
|
*
|
|
|
|
* 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
|
2004-01-15 01:20:46 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2004-04-22 00:27:34 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
2004-01-15 01:20:46 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "ntstatus.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#define WIN32_NO_STATUS
|
2004-01-15 01:20:46 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
|
2004-03-26 00:41:04 +01:00
|
|
|
#include "kernel_private.h"
|
2004-01-15 01:20:46 +01:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(file);
|
|
|
|
|
|
|
|
#define MAX_PATHNAME_LEN 1024
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* 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;
|
|
|
|
BOOL is_ansi = AreFileApisANSI();
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &strW, nameW );
|
|
|
|
|
|
|
|
ret = is_ansi ? RtlUnicodeStringToAnsiSize(&strW) : RtlUnicodeStringToOemSize(&strW);
|
|
|
|
if (buffer && ret <= len)
|
|
|
|
{
|
|
|
|
ANSI_STRING str;
|
|
|
|
|
|
|
|
str.Buffer = buffer;
|
2010-02-01 13:22:41 +01:00
|
|
|
str.MaximumLength = min( len, UNICODE_STRING_MAX_CHARS );
|
2004-05-13 22:21:25 +02:00
|
|
|
if (is_ansi)
|
|
|
|
RtlUnicodeStringToAnsiString( &str, &strW, FALSE );
|
|
|
|
else
|
|
|
|
RtlUnicodeStringToOemString( &str, &strW, FALSE );
|
|
|
|
ret = str.Length; /* length without terminating 0 */
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2004-04-22 00:27:34 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* add_boot_rename_entry
|
|
|
|
*
|
|
|
|
* Adds an entry to the registry that is loaded when windows boots and
|
|
|
|
* checks if there are some files to be removed or renamed/moved.
|
|
|
|
* <fn1> has to be valid and <fn2> may be NULL. If both pointers are
|
|
|
|
* non-NULL then the file is moved, otherwise it is deleted. The
|
2011-07-27 13:38:43 +02:00
|
|
|
* entry of the registry key is always appended with two zero
|
2004-04-22 00:27:34 +02:00
|
|
|
* terminated strings. If <fn2> is NULL then the second entry is
|
|
|
|
* simply a single 0-byte. Otherwise the second filename goes
|
|
|
|
* there. The entries are prepended with \??\ before the path and the
|
|
|
|
* second filename gets also a '!' as the first character if
|
|
|
|
* MOVEFILE_REPLACE_EXISTING is set. After the final string another
|
|
|
|
* 0-byte follows to indicate the end of the strings.
|
|
|
|
* i.e.:
|
|
|
|
* \??\D:\test\file1[0]
|
|
|
|
* !\??\D:\test\file1_renamed[0]
|
|
|
|
* \??\D:\Test|delete[0]
|
|
|
|
* [0] <- file is to be deleted, second string empty
|
|
|
|
* \??\D:\test\file2[0]
|
|
|
|
* !\??\D:\test\file2_renamed[0]
|
|
|
|
* [0] <- indicates end of strings
|
|
|
|
*
|
|
|
|
* or:
|
|
|
|
* \??\D:\test\file1[0]
|
|
|
|
* !\??\D:\test\file1_renamed[0]
|
|
|
|
* \??\D:\Test|delete[0]
|
|
|
|
* [0] <- file is to be deleted, second string empty
|
|
|
|
* [0] <- indicates end of strings
|
|
|
|
*
|
|
|
|
*/
|
2004-04-30 06:16:23 +02:00
|
|
|
static BOOL add_boot_rename_entry( LPCWSTR source, LPCWSTR dest, DWORD flags )
|
2004-04-22 00:27:34 +02:00
|
|
|
{
|
|
|
|
static const WCHAR ValueName[] = {'P','e','n','d','i','n','g',
|
|
|
|
'F','i','l','e','R','e','n','a','m','e',
|
|
|
|
'O','p','e','r','a','t','i','o','n','s',0};
|
2015-11-19 12:53:33 +01:00
|
|
|
static const WCHAR SessionW[] = {'\\','R','e','g','i','s','t','r','y','\\',
|
|
|
|
'M','a','c','h','i','n','e','\\',
|
2004-04-22 00:27:34 +02:00
|
|
|
'S','y','s','t','e','m','\\',
|
|
|
|
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
|
|
|
|
'C','o','n','t','r','o','l','\\',
|
|
|
|
'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
|
|
|
|
static const int info_size = FIELD_OFFSET( KEY_VALUE_PARTIAL_INFORMATION, Data );
|
|
|
|
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
2004-04-30 06:16:23 +02:00
|
|
|
UNICODE_STRING nameW, source_name, dest_name;
|
2004-04-22 00:27:34 +02:00
|
|
|
KEY_VALUE_PARTIAL_INFORMATION *info;
|
|
|
|
BOOL rc = FALSE;
|
2005-06-17 15:58:33 +02:00
|
|
|
HANDLE Reboot = 0;
|
2004-04-30 06:16:23 +02:00
|
|
|
DWORD len1, len2;
|
2004-04-22 00:27:34 +02:00
|
|
|
DWORD DataSize = 0;
|
|
|
|
BYTE *Buffer = NULL;
|
|
|
|
WCHAR *p;
|
|
|
|
|
2004-04-30 06:16:23 +02:00
|
|
|
if (!RtlDosPathNameToNtPathName_U( source, &source_name, NULL, NULL ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_PATH_NOT_FOUND );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
dest_name.Buffer = NULL;
|
|
|
|
if (dest && !RtlDosPathNameToNtPathName_U( dest, &dest_name, NULL, NULL ))
|
|
|
|
{
|
|
|
|
RtlFreeUnicodeString( &source_name );
|
|
|
|
SetLastError( ERROR_PATH_NOT_FOUND );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-04-22 00:27:34 +02:00
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
RtlInitUnicodeString( &nameW, SessionW );
|
|
|
|
|
|
|
|
if (NtCreateKey( &Reboot, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) != STATUS_SUCCESS)
|
|
|
|
{
|
2010-07-25 03:21:26 +02:00
|
|
|
WARN("Error creating key for reboot management [%s]\n",
|
2004-04-22 00:27:34 +02:00
|
|
|
"SYSTEM\\CurrentControlSet\\Control\\Session Manager");
|
2004-04-30 06:16:23 +02:00
|
|
|
RtlFreeUnicodeString( &source_name );
|
|
|
|
RtlFreeUnicodeString( &dest_name );
|
2004-04-22 00:27:34 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-04-30 06:16:23 +02:00
|
|
|
len1 = source_name.Length + sizeof(WCHAR);
|
|
|
|
if (dest)
|
2004-04-22 00:27:34 +02:00
|
|
|
{
|
2004-04-30 06:16:23 +02:00
|
|
|
len2 = dest_name.Length + sizeof(WCHAR);
|
|
|
|
if (flags & MOVEFILE_REPLACE_EXISTING)
|
|
|
|
len2 += sizeof(WCHAR); /* Plus 1 because of the leading '!' */
|
2004-04-22 00:27:34 +02:00
|
|
|
}
|
2004-04-30 06:16:23 +02:00
|
|
|
else len2 = sizeof(WCHAR); /* minimum is the 0 characters for the empty second string */
|
2004-04-22 00:27:34 +02:00
|
|
|
|
|
|
|
RtlInitUnicodeString( &nameW, ValueName );
|
|
|
|
|
|
|
|
/* First we check if the key exists and if so how many bytes it already contains. */
|
|
|
|
if (NtQueryValueKey( Reboot, &nameW, KeyValuePartialInformation,
|
2010-02-16 14:28:41 +01:00
|
|
|
NULL, 0, &DataSize ) == STATUS_BUFFER_TOO_SMALL)
|
2004-04-22 00:27:34 +02:00
|
|
|
{
|
|
|
|
if (!(Buffer = HeapAlloc( GetProcessHeap(), 0, DataSize + len1 + len2 + sizeof(WCHAR) )))
|
|
|
|
goto Quit;
|
|
|
|
if (NtQueryValueKey( Reboot, &nameW, KeyValuePartialInformation,
|
|
|
|
Buffer, DataSize, &DataSize )) goto Quit;
|
|
|
|
info = (KEY_VALUE_PARTIAL_INFORMATION *)Buffer;
|
|
|
|
if (info->Type != REG_MULTI_SZ) goto Quit;
|
|
|
|
if (DataSize > sizeof(info)) DataSize -= sizeof(WCHAR); /* remove terminating null (will be added back later) */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DataSize = info_size;
|
|
|
|
if (!(Buffer = HeapAlloc( GetProcessHeap(), 0, DataSize + len1 + len2 + sizeof(WCHAR) )))
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
|
2004-04-30 06:16:23 +02:00
|
|
|
memcpy( Buffer + DataSize, source_name.Buffer, len1 );
|
2004-04-22 00:27:34 +02:00
|
|
|
DataSize += len1;
|
2004-04-30 06:16:23 +02:00
|
|
|
p = (WCHAR *)(Buffer + DataSize);
|
|
|
|
if (dest)
|
2004-04-22 00:27:34 +02:00
|
|
|
{
|
|
|
|
if (flags & MOVEFILE_REPLACE_EXISTING)
|
|
|
|
*p++ = '!';
|
2004-04-30 06:16:23 +02:00
|
|
|
memcpy( p, dest_name.Buffer, len2 );
|
2004-04-22 00:27:34 +02:00
|
|
|
DataSize += len2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*p = 0;
|
|
|
|
DataSize += sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add final null */
|
|
|
|
p = (WCHAR *)(Buffer + DataSize);
|
|
|
|
*p = 0;
|
|
|
|
DataSize += sizeof(WCHAR);
|
|
|
|
|
|
|
|
rc = !NtSetValueKey(Reboot, &nameW, 0, REG_MULTI_SZ, Buffer + info_size, DataSize - info_size);
|
|
|
|
|
|
|
|
Quit:
|
2004-04-30 06:16:23 +02:00
|
|
|
RtlFreeUnicodeString( &source_name );
|
|
|
|
RtlFreeUnicodeString( &dest_name );
|
2004-04-22 00:27:34 +02:00
|
|
|
if (Reboot) NtClose(Reboot);
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, Buffer );
|
2004-04-22 00:27:34 +02:00
|
|
|
return(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-15 01:20:46 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetShortPathNameA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetShortPathNameA( LPCSTR longpath, LPSTR shortpath, DWORD shortlen )
|
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
WCHAR *longpathW;
|
2004-01-15 01:20:46 +01:00
|
|
|
WCHAR shortpathW[MAX_PATH];
|
2004-05-13 22:21:25 +02:00
|
|
|
DWORD ret;
|
2004-01-15 01:20:46 +01:00
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_a(longpath));
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if (!(longpathW = FILE_name_AtoW( longpath, FALSE ))) return 0;
|
2004-01-15 01:20:46 +01:00
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
ret = GetShortPathNameW(longpathW, shortpathW, MAX_PATH);
|
2004-01-15 01:20:46 +01:00
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if (!ret) return 0;
|
|
|
|
if (ret > MAX_PATH)
|
2004-01-15 01:20:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_FILENAME_EXCED_RANGE);
|
2004-05-13 22:21:25 +02:00
|
|
|
return 0;
|
2004-01-15 01:20:46 +01:00
|
|
|
}
|
2004-05-13 22:21:25 +02:00
|
|
|
return copy_filename_WtoA( shortpathW, shortpath, shortlen );
|
2004-01-15 01:20:46 +01:00
|
|
|
}
|
2004-03-26 00:41:04 +01:00
|
|
|
|
2004-04-22 00:27:34 +02:00
|
|
|
|
2010-06-16 12:00:59 +02:00
|
|
|
static BOOL is_same_file(HANDLE h1, HANDLE h2)
|
|
|
|
{
|
2020-04-08 23:06:06 +02:00
|
|
|
FILE_ID_INFORMATION id1, id2;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
|
|
|
return !NtQueryInformationFile( h1, &io, &id1, sizeof(id1), FileIdInformation )
|
|
|
|
&& !NtQueryInformationFile( h2, &io, &id2, sizeof(id2), FileIdInformation )
|
|
|
|
&& !memcmp( &id1, &id2, sizeof(FILE_ID_INFORMATION) );
|
2010-06-16 12:00:59 +02:00
|
|
|
}
|
2004-04-22 00:27:34 +02:00
|
|
|
|
2004-05-01 07:25:07 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* CopyFileW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists )
|
2013-01-17 21:28:43 +01:00
|
|
|
{
|
|
|
|
return CopyFileExW( source, dest, NULL, NULL, NULL,
|
|
|
|
fail_if_exists ? COPY_FILE_FAIL_IF_EXISTS : 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* CopyFileA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CopyFileA( LPCSTR source, LPCSTR dest, BOOL fail_if_exists)
|
|
|
|
{
|
|
|
|
WCHAR *sourceW, *destW;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!(sourceW = FILE_name_AtoW( source, FALSE ))) return FALSE;
|
|
|
|
if (!(destW = FILE_name_AtoW( dest, TRUE ))) return FALSE;
|
|
|
|
|
|
|
|
ret = CopyFileW( sourceW, destW, fail_if_exists );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, destW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* CopyFileExW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CopyFileExW(LPCWSTR source, LPCWSTR dest,
|
|
|
|
LPPROGRESS_ROUTINE progress, LPVOID param,
|
|
|
|
LPBOOL cancel_ptr, DWORD flags)
|
2004-05-01 07:25:07 +02:00
|
|
|
{
|
2005-09-26 15:26:40 +02:00
|
|
|
static const int buffer_size = 65536;
|
2004-05-01 07:25:07 +02:00
|
|
|
HANDLE h1, h2;
|
|
|
|
BY_HANDLE_FILE_INFORMATION info;
|
|
|
|
DWORD count;
|
|
|
|
BOOL ret = FALSE;
|
2005-09-26 15:26:40 +02:00
|
|
|
char *buffer;
|
2004-05-01 07:25:07 +02:00
|
|
|
|
|
|
|
if (!source || !dest)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-09-26 15:26:40 +02:00
|
|
|
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-05-01 07:25:07 +02:00
|
|
|
|
2013-01-17 21:28:43 +01:00
|
|
|
TRACE("%s -> %s, %x\n", debugstr_w(source), debugstr_w(dest), flags);
|
2004-05-01 07:25:07 +02:00
|
|
|
|
2013-01-17 21:28:44 +01:00
|
|
|
if ((h1 = CreateFileW(source, GENERIC_READ,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
2004-05-01 07:25:07 +02:00
|
|
|
NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
WARN("Unable to open source %s\n", debugstr_w(source));
|
2007-08-30 10:28:20 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
2004-05-01 07:25:07 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetFileInformationByHandle( h1, &info ))
|
|
|
|
{
|
|
|
|
WARN("GetFileInformationByHandle returned error for %s\n", debugstr_w(source));
|
2007-08-30 10:28:20 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
2004-05-01 07:25:07 +02:00
|
|
|
CloseHandle( h1 );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-17 21:28:43 +01:00
|
|
|
if (!(flags & COPY_FILE_FAIL_IF_EXISTS))
|
2010-06-16 12:00:59 +02:00
|
|
|
{
|
|
|
|
BOOL same_file = FALSE;
|
|
|
|
h2 = CreateFileW( dest, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
OPEN_EXISTING, 0, 0);
|
|
|
|
if (h2 != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
same_file = is_same_file( h1, h2 );
|
|
|
|
CloseHandle( h2 );
|
|
|
|
}
|
|
|
|
if (same_file)
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
CloseHandle( h1 );
|
|
|
|
SetLastError( ERROR_SHARING_VIOLATION );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-14 07:48:10 +02:00
|
|
|
if ((h2 = CreateFileW( dest, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
2013-01-17 21:28:43 +01:00
|
|
|
(flags & COPY_FILE_FAIL_IF_EXISTS) ? CREATE_NEW : CREATE_ALWAYS,
|
2004-05-01 07:25:07 +02:00
|
|
|
info.dwFileAttributes, h1 )) == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
WARN("Unable to open dest %s\n", debugstr_w(dest));
|
2007-08-30 10:28:20 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
2004-05-01 07:25:07 +02:00
|
|
|
CloseHandle( h1 );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-09-26 15:26:40 +02:00
|
|
|
while (ReadFile( h1, buffer, buffer_size, &count, NULL ) && count)
|
2004-05-01 07:25:07 +02:00
|
|
|
{
|
|
|
|
char *p = buffer;
|
|
|
|
while (count != 0)
|
|
|
|
{
|
|
|
|
DWORD res;
|
|
|
|
if (!WriteFile( h2, p, count, &res, NULL ) || !res) goto done;
|
|
|
|
p += res;
|
|
|
|
count -= res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = TRUE;
|
|
|
|
done:
|
2005-03-01 11:42:22 +01:00
|
|
|
/* Maintain the timestamp of source file to destination file */
|
2005-09-26 15:26:40 +02:00
|
|
|
SetFileTime(h2, NULL, NULL, &info.ftLastWriteTime);
|
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
2004-05-01 07:25:07 +02:00
|
|
|
CloseHandle( h1 );
|
|
|
|
CloseHandle( h2 );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* CopyFileExA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CopyFileExA(LPCSTR sourceFilename, LPCSTR destFilename,
|
|
|
|
LPPROGRESS_ROUTINE progressRoutine, LPVOID appData,
|
|
|
|
LPBOOL cancelFlagPointer, DWORD copyFlags)
|
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
WCHAR *sourceW, *destW;
|
2004-05-01 07:25:07 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
/* can't use the TEB buffer since we may have a callback routine */
|
|
|
|
if (!(sourceW = FILE_name_AtoW( sourceFilename, TRUE ))) return FALSE;
|
|
|
|
if (!(destW = FILE_name_AtoW( destFilename, TRUE )))
|
2004-05-01 07:25:07 +02:00
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, sourceW );
|
2004-05-01 07:25:07 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-05-13 22:21:25 +02:00
|
|
|
ret = CopyFileExW(sourceW, destW, progressRoutine, appData,
|
2004-05-01 07:25:07 +02:00
|
|
|
cancelFlagPointer, copyFlags);
|
2004-05-13 22:21:25 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, sourceW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, destW );
|
2004-05-01 07:25:07 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-15 14:28:32 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* MoveFileTransactedA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI MoveFileTransactedA(const char *source, const char *dest, LPPROGRESS_ROUTINE progress, void *data, DWORD flags, HANDLE handle)
|
|
|
|
{
|
|
|
|
FIXME("(%s, %s, %p, %p, %d, %p)\n", debugstr_a(source), debugstr_a(dest), progress, data, flags, handle);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MoveFileTransactedW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI MoveFileTransactedW(const WCHAR *source, const WCHAR *dest, LPPROGRESS_ROUTINE progress, void *data, DWORD flags, HANDLE handle)
|
|
|
|
{
|
|
|
|
FIXME("(%s, %s, %p, %p, %d, %p)\n", debugstr_w(source), debugstr_w(dest), progress, data, flags, handle);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-05-01 07:25:07 +02:00
|
|
|
|
2004-04-22 00:27:34 +02:00
|
|
|
/**************************************************************************
|
2007-01-02 03:40:00 +01:00
|
|
|
* MoveFileWithProgressW (KERNEL32.@)
|
2004-04-22 00:27:34 +02:00
|
|
|
*/
|
2007-01-02 03:40:00 +01:00
|
|
|
BOOL WINAPI MoveFileWithProgressW( LPCWSTR source, LPCWSTR dest,
|
|
|
|
LPPROGRESS_ROUTINE fnProgress,
|
|
|
|
LPVOID param, DWORD flag )
|
2004-04-22 00:27:34 +02:00
|
|
|
{
|
2020-03-11 04:38:26 +01:00
|
|
|
FILE_RENAME_INFORMATION *rename_info;
|
2004-04-22 00:27:34 +02:00
|
|
|
FILE_BASIC_INFORMATION info;
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
2020-03-11 04:38:26 +01:00
|
|
|
HANDLE source_handle = 0;
|
|
|
|
ULONG size;
|
2004-04-22 00:27:34 +02:00
|
|
|
|
2007-01-02 03:40:00 +01:00
|
|
|
TRACE("(%s,%s,%p,%p,%04x)\n",
|
|
|
|
debugstr_w(source), debugstr_w(dest), fnProgress, param, flag );
|
2004-04-22 00:27:34 +02:00
|
|
|
|
|
|
|
if (flag & MOVEFILE_DELAY_UNTIL_REBOOT)
|
|
|
|
return add_boot_rename_entry( source, dest, flag );
|
|
|
|
|
|
|
|
if (!dest)
|
|
|
|
return DeleteFileW( source );
|
|
|
|
|
|
|
|
/* check if we are allowed to rename the source */
|
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( source, &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 = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
2018-10-14 09:44:40 +02:00
|
|
|
status = NtOpenFile( &source_handle, DELETE | SYNCHRONIZE, &attr, &io,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_SYNCHRONOUS_IO_NONALERT );
|
2004-04-22 00:27:34 +02:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
status = NtQueryInformationFile( source_handle, &io, &info, sizeof(info), FileBasicInformation );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( dest, &nt_name, NULL, NULL ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_PATH_NOT_FOUND );
|
|
|
|
goto error;
|
|
|
|
}
|
2018-10-14 09:44:37 +02:00
|
|
|
|
2020-03-11 04:38:26 +01:00
|
|
|
size = offsetof( FILE_RENAME_INFORMATION, FileName ) + nt_name.Length;
|
|
|
|
if (!(rename_info = HeapAlloc( GetProcessHeap(), 0, size )))
|
2004-04-22 00:27:34 +02:00
|
|
|
goto error;
|
2004-04-27 04:15:52 +02:00
|
|
|
|
2020-03-11 04:38:26 +01:00
|
|
|
rename_info->ReplaceIfExists = !!(flag & MOVEFILE_REPLACE_EXISTING);
|
|
|
|
rename_info->RootDirectory = NULL;
|
|
|
|
rename_info->FileNameLength = nt_name.Length;
|
|
|
|
memcpy( rename_info->FileName, nt_name.Buffer, nt_name.Length );
|
2004-04-27 04:15:52 +02:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
2020-03-11 04:38:26 +01:00
|
|
|
status = NtSetInformationFile( source_handle, &io, rename_info, size, FileRenameInformation );
|
2020-04-18 16:13:21 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, rename_info );
|
2020-03-11 04:38:26 +01:00
|
|
|
if (status == STATUS_NOT_SAME_DEVICE && (flag & MOVEFILE_COPY_ALLOWED))
|
2004-04-22 00:27:34 +02:00
|
|
|
{
|
2020-03-11 04:38:26 +01:00
|
|
|
NtClose( source_handle );
|
|
|
|
if (!CopyFileExW( source, dest, fnProgress, param, NULL,
|
|
|
|
flag & MOVEFILE_REPLACE_EXISTING ?
|
|
|
|
0 : COPY_FILE_FAIL_IF_EXISTS ))
|
|
|
|
return FALSE;
|
|
|
|
return DeleteFileW( source );
|
2004-04-22 00:27:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NtClose( source_handle );
|
2020-03-11 04:38:26 +01:00
|
|
|
return set_ntstatus( status );
|
2004-04-22 00:27:34 +02:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (source_handle) NtClose( source_handle );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2007-01-02 03:40:00 +01:00
|
|
|
* MoveFileWithProgressA (KERNEL32.@)
|
2004-04-22 00:27:34 +02:00
|
|
|
*/
|
2007-01-02 03:40:00 +01:00
|
|
|
BOOL WINAPI MoveFileWithProgressA( LPCSTR source, LPCSTR dest,
|
|
|
|
LPPROGRESS_ROUTINE fnProgress,
|
|
|
|
LPVOID param, DWORD flag )
|
2004-04-22 00:27:34 +02:00
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
WCHAR *sourceW, *destW;
|
2004-04-22 00:27:34 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if (!(sourceW = FILE_name_AtoW( source, FALSE ))) return FALSE;
|
2005-09-07 11:23:34 +02:00
|
|
|
if (dest)
|
|
|
|
{
|
|
|
|
if (!(destW = FILE_name_AtoW( dest, TRUE ))) return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
destW = NULL;
|
|
|
|
|
2007-01-02 03:40:00 +01:00
|
|
|
ret = MoveFileWithProgressW( sourceW, destW, fnProgress, param, flag );
|
2004-05-13 22:21:25 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, destW );
|
2004-04-22 00:27:34 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-01-02 03:40:00 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* MoveFileExW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI MoveFileExW( LPCWSTR source, LPCWSTR dest, DWORD flag )
|
|
|
|
{
|
|
|
|
return MoveFileWithProgressW( source, dest, NULL, NULL, flag );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MoveFileExA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI MoveFileExA( LPCSTR source, LPCSTR dest, DWORD flag )
|
|
|
|
{
|
|
|
|
return MoveFileWithProgressA( source, dest, NULL, NULL, flag );
|
|
|
|
}
|
|
|
|
|
2004-04-22 00:27:34 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MoveFileW (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Move file or directory
|
|
|
|
*/
|
|
|
|
BOOL WINAPI MoveFileW( LPCWSTR source, LPCWSTR dest )
|
|
|
|
{
|
|
|
|
return MoveFileExW( source, dest, MOVEFILE_COPY_ALLOWED );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MoveFileA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI MoveFileA( LPCSTR source, LPCSTR dest )
|
|
|
|
{
|
|
|
|
return MoveFileExA( source, dest, MOVEFILE_COPY_ALLOWED );
|
|
|
|
}
|
2004-04-23 04:46:18 +02:00
|
|
|
|
|
|
|
|
2008-07-22 13:19:22 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* CreateHardLinkW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreateHardLinkW(LPCWSTR lpFileName, LPCWSTR lpExistingFileName,
|
|
|
|
LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
|
|
|
{
|
2010-05-17 00:28:56 +02:00
|
|
|
UNICODE_STRING ntDest, ntSource;
|
2020-03-04 06:20:37 +01:00
|
|
|
FILE_LINK_INFORMATION *info = NULL;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
IO_STATUS_BLOCK io;
|
2010-05-17 00:28:56 +02:00
|
|
|
BOOL ret = FALSE;
|
2020-03-04 06:20:37 +01:00
|
|
|
HANDLE file;
|
|
|
|
ULONG size;
|
2010-05-17 00:28:56 +02:00
|
|
|
|
|
|
|
TRACE("(%s, %s, %p)\n", debugstr_w(lpFileName),
|
2008-07-22 13:19:22 +02:00
|
|
|
debugstr_w(lpExistingFileName), lpSecurityAttributes);
|
2010-05-17 00:28:56 +02:00
|
|
|
|
|
|
|
ntDest.Buffer = ntSource.Buffer = NULL;
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( lpFileName, &ntDest, NULL, NULL ) ||
|
|
|
|
!RtlDosPathNameToNtPathName_U( lpExistingFileName, &ntSource, NULL, NULL ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_PATH_NOT_FOUND );
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2020-03-04 06:20:37 +01:00
|
|
|
size = offsetof( FILE_LINK_INFORMATION, FileName ) + ntDest.Length;
|
|
|
|
if (!(info = HeapAlloc( GetProcessHeap(), 0, size )))
|
2010-05-17 00:28:56 +02:00
|
|
|
{
|
2020-03-04 06:20:37 +01:00
|
|
|
SetLastError( ERROR_OUTOFMEMORY );
|
|
|
|
goto err;
|
2010-05-17 00:28:56 +02:00
|
|
|
}
|
|
|
|
|
2020-03-04 06:20:37 +01:00
|
|
|
InitializeObjectAttributes( &attr, &ntSource, OBJ_CASE_INSENSITIVE, 0, NULL );
|
|
|
|
if (!(ret = set_ntstatus( NtOpenFile( &file, SYNCHRONIZE, &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT ) )))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
info->ReplaceIfExists = FALSE;
|
|
|
|
info->RootDirectory = NULL;
|
|
|
|
info->FileNameLength = ntDest.Length;
|
|
|
|
memcpy( info->FileName, ntDest.Buffer, ntDest.Length );
|
|
|
|
ret = set_ntstatus( NtSetInformationFile( file, &io, info, size, FileLinkInformation ) );
|
2010-05-17 00:28:56 +02:00
|
|
|
|
2020-03-04 06:20:37 +01:00
|
|
|
NtClose( file );
|
2010-05-17 00:28:56 +02:00
|
|
|
|
|
|
|
err:
|
|
|
|
RtlFreeUnicodeString( &ntSource );
|
|
|
|
RtlFreeUnicodeString( &ntDest );
|
2020-03-04 06:20:37 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, info );
|
2010-05-17 00:28:56 +02:00
|
|
|
return ret;
|
2008-07-22 13:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* CreateHardLinkA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreateHardLinkA(LPCSTR lpFileName, LPCSTR lpExistingFileName,
|
|
|
|
LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
|
|
|
{
|
2010-05-17 00:28:56 +02:00
|
|
|
WCHAR *sourceW, *destW;
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
if (!(sourceW = FILE_name_AtoW( lpExistingFileName, TRUE )))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!(destW = FILE_name_AtoW( lpFileName, TRUE )))
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, sourceW );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = CreateHardLinkW( destW, sourceW, lpSecurityAttributes );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, sourceW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, destW );
|
|
|
|
|
|
|
|
return res;
|
2008-07-22 13:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-27 04:27:09 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* CreateDirectoryExA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreateDirectoryExA( LPCSTR template, LPCSTR path, LPSECURITY_ATTRIBUTES sa )
|
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
WCHAR *pathW, *templateW = NULL;
|
2004-04-27 04:27:09 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if (!(pathW = FILE_name_AtoW( path, FALSE ))) return FALSE;
|
|
|
|
if (template && !(templateW = FILE_name_AtoW( template, TRUE ))) return FALSE;
|
2004-04-27 04:27:09 +02:00
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
ret = CreateDirectoryExW( templateW, pathW, sa );
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, templateW );
|
2004-04-27 04:27:09 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RemoveDirectoryW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI RemoveDirectoryW( LPCWSTR path )
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
ANSI_STRING unix_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 = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
2019-10-01 09:36:16 +02:00
|
|
|
if (!set_ntstatus( NtOpenFile( &handle, DELETE | SYNCHRONIZE, &attr, &io,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
|
|
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT )))
|
2016-05-03 03:22:24 +02:00
|
|
|
{
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-04-27 04:27:09 +02:00
|
|
|
|
2016-05-03 03:22:24 +02:00
|
|
|
status = wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, FALSE );
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
2019-10-01 09:36:16 +02:00
|
|
|
if (!set_ntstatus( status ))
|
2004-04-27 04:27:09 +02:00
|
|
|
{
|
2016-05-03 03:22:24 +02:00
|
|
|
NtClose( handle );
|
2004-04-27 04:27:09 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ret = (rmdir( unix_name.Buffer ) != -1))) FILE_SetDosError();
|
|
|
|
RtlFreeAnsiString( &unix_name );
|
|
|
|
NtClose( handle );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RemoveDirectoryA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI RemoveDirectoryA( LPCSTR path )
|
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
WCHAR *pathW;
|
2004-04-27 04:27:09 +02:00
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if (!(pathW = FILE_name_AtoW( path, FALSE ))) return FALSE;
|
|
|
|
return RemoveDirectoryW( pathW );
|
2004-04-27 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetSystemDirectoryW (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* See comment for GetWindowsDirectoryA.
|
|
|
|
*/
|
|
|
|
UINT WINAPI GetSystemDirectoryW( LPWSTR path, UINT count )
|
|
|
|
{
|
|
|
|
UINT len = strlenW( DIR_System ) + 1;
|
|
|
|
if (path && count >= len)
|
2004-04-28 03:04:24 +02:00
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
strcpyW( path, DIR_System );
|
|
|
|
len--;
|
2004-04-28 03:04:24 +02:00
|
|
|
}
|
2004-05-13 22:21:25 +02:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetSystemDirectoryA (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* See comment for GetWindowsDirectoryA.
|
|
|
|
*/
|
|
|
|
UINT WINAPI GetSystemDirectoryA( LPSTR path, UINT count )
|
|
|
|
{
|
|
|
|
return copy_filename_WtoA( DIR_System, path, count );
|
2004-04-28 03:04:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-06 15:09:29 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Wow64EnableWow64FsRedirection (KERNEL32.@)
|
2019-12-05 20:09:04 +01:00
|
|
|
*
|
|
|
|
* Microsoft C++ Redistributable installers are depending on all %eax bits being set.
|
2009-07-06 15:09:29 +02:00
|
|
|
*/
|
2019-12-05 20:09:04 +01:00
|
|
|
DWORD /*BOOLEAN*/ WINAPI KERNEL32_Wow64EnableWow64FsRedirection( BOOLEAN enable )
|
2009-07-06 15:09:29 +02:00
|
|
|
{
|
2019-10-01 09:36:16 +02:00
|
|
|
return set_ntstatus( RtlWow64EnableFsRedirection( enable ));
|
2009-07-06 15:09:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-23 04:46:18 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* wine_get_unix_file_name (KERNEL32.@) Not a Windows API
|
|
|
|
*
|
|
|
|
* Return the full Unix file name for a given path.
|
|
|
|
* Returned buffer must be freed by caller.
|
|
|
|
*/
|
2009-02-06 13:56:09 +01:00
|
|
|
char * CDECL wine_get_unix_file_name( LPCWSTR dosW )
|
2004-04-23 04:46:18 +02:00
|
|
|
{
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
ANSI_STRING unix_name;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( dosW, &nt_name, NULL, NULL )) return NULL;
|
2004-04-27 04:15:52 +02:00
|
|
|
status = wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN_IF, FALSE );
|
2004-04-23 04:46:18 +02:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
2005-08-11 13:07:17 +02:00
|
|
|
if (status && status != STATUS_NO_SUCH_FILE)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError( status ) );
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-04-23 04:46:18 +02:00
|
|
|
return unix_name.Buffer;
|
|
|
|
}
|
2005-08-11 13:07:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* wine_get_dos_file_name (KERNEL32.@) Not a Windows API
|
|
|
|
*
|
|
|
|
* Return the full DOS file name for a given Unix path.
|
|
|
|
* Returned buffer must be freed by caller.
|
|
|
|
*/
|
2009-02-06 13:56:09 +01:00
|
|
|
WCHAR * CDECL wine_get_dos_file_name( LPCSTR str )
|
2005-08-11 13:07:17 +02:00
|
|
|
{
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
ANSI_STRING unix_name;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
RtlInitAnsiString( &unix_name, str );
|
2019-10-01 09:36:16 +02:00
|
|
|
if (!set_ntstatus( wine_unix_to_nt_file_name( &unix_name, &nt_name ))) return NULL;
|
2010-07-22 21:38:59 +02:00
|
|
|
if (nt_name.Buffer[5] == ':')
|
|
|
|
{
|
|
|
|
/* get rid of the \??\ prefix */
|
|
|
|
/* FIXME: should implement RtlNtPathNameToDosPathName and use that instead */
|
|
|
|
len = nt_name.Length - 4 * sizeof(WCHAR);
|
|
|
|
memmove( nt_name.Buffer, nt_name.Buffer + 4, len );
|
|
|
|
nt_name.Buffer[len / sizeof(WCHAR)] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nt_name.Buffer[1] = '\\';
|
2005-08-11 13:07:17 +02:00
|
|
|
return nt_name.Buffer;
|
|
|
|
}
|
2014-12-02 21:35:06 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* CreateSymbolicLinkW (KERNEL32.@)
|
|
|
|
*/
|
2015-10-30 15:49:09 +01:00
|
|
|
BOOLEAN WINAPI CreateSymbolicLinkW(LPCWSTR link, LPCWSTR target, DWORD flags)
|
2014-12-02 21:35:06 +01:00
|
|
|
{
|
|
|
|
FIXME("(%s %s %d): stub\n", debugstr_w(link), debugstr_w(target), flags);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* CreateSymbolicLinkA (KERNEL32.@)
|
|
|
|
*/
|
2015-10-30 15:49:09 +01:00
|
|
|
BOOLEAN WINAPI CreateSymbolicLinkA(LPCSTR link, LPCSTR target, DWORD flags)
|
2014-12-02 21:35:06 +01:00
|
|
|
{
|
|
|
|
FIXME("(%s %s %d): stub\n", debugstr_a(link), debugstr_a(target), flags);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-02-04 21:51:42 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* CreateHardLinkTransactedA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreateHardLinkTransactedA(LPCSTR link, LPCSTR target, LPSECURITY_ATTRIBUTES sa, HANDLE transaction)
|
|
|
|
{
|
|
|
|
FIXME("(%s %s %p %p): stub\n", debugstr_a(link), debugstr_a(target), sa, transaction);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* CreateHardLinkTransactedW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreateHardLinkTransactedW(LPCWSTR link, LPCWSTR target, LPSECURITY_ATTRIBUTES sa, HANDLE transaction)
|
|
|
|
{
|
|
|
|
FIXME("(%s %s %p %p): stub\n", debugstr_w(link), debugstr_w(target), sa, transaction);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-05-12 20:31:01 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* CheckNameLegalDOS8Dot3A (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CheckNameLegalDOS8Dot3A(const char *name, char *oemname, DWORD oemname_len,
|
|
|
|
BOOL *contains_spaces, BOOL *is_legal)
|
|
|
|
{
|
|
|
|
WCHAR *nameW;
|
|
|
|
|
|
|
|
TRACE("(%s %p %u %p %p)\n", name, oemname,
|
|
|
|
oemname_len, contains_spaces, is_legal);
|
|
|
|
|
|
|
|
if (!name || !is_legal)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!(nameW = FILE_name_AtoW( name, FALSE ))) return FALSE;
|
|
|
|
|
|
|
|
return CheckNameLegalDOS8Dot3W( nameW, oemname, oemname_len, contains_spaces, is_legal );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* CheckNameLegalDOS8Dot3W (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CheckNameLegalDOS8Dot3W(const WCHAR *name, char *oemname, DWORD oemname_len,
|
|
|
|
BOOL *contains_spaces_ret, BOOL *is_legal)
|
|
|
|
{
|
|
|
|
OEM_STRING oem_str;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
BOOLEAN contains_spaces;
|
|
|
|
|
|
|
|
TRACE("(%s %p %u %p %p)\n", wine_dbgstr_w(name), oemname,
|
|
|
|
oemname_len, contains_spaces_ret, is_legal);
|
|
|
|
|
|
|
|
if (!name || !is_legal)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
|
|
|
|
if (oemname) {
|
|
|
|
oem_str.Length = oemname_len;
|
|
|
|
oem_str.MaximumLength = oemname_len;
|
|
|
|
oem_str.Buffer = oemname;
|
|
|
|
}
|
|
|
|
|
|
|
|
*is_legal = RtlIsNameLegalDOS8Dot3( &nameW, oemname ? &oem_str : NULL, &contains_spaces );
|
|
|
|
if (contains_spaces_ret) *contains_spaces_ret = contains_spaces;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-01-08 05:02:37 +01:00
|
|
|
|
2016-09-26 23:17:37 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* SetSearchPathMode (KERNEL32.@)
|
|
|
|
*/
|
2017-08-29 15:46:50 +02:00
|
|
|
BOOL WINAPI SetSearchPathMode( DWORD flags )
|
2016-01-08 05:02:37 +01:00
|
|
|
{
|
2019-10-01 09:35:59 +02:00
|
|
|
return set_ntstatus( RtlSetSearchPathMode( flags ));
|
2016-01-08 05:02:37 +01:00
|
|
|
}
|