ReactOS  0.4.13-dev-443-g10f00f8
file.c File Reference
#include "precomp.h"
#include <time.h>
#include <fileapi.h>
Include dependency graph for file.c:

Go to the source code of this file.

Classes

struct  test_list
 

Macros

#define IsDotDir(x)   ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
 
#define PATTERN_OFFSET   0x10
 
#define M(x)   {x, # x}
 
#define CHECK_NAME(fn)   (strcmp((fn), "file1") == 0 || strcmp((fn), "file2") == 0 || strcmp((fn), "dir1") == 0)
 
#define CHECK_LEVEL(fn)   (level != FindExInfoBasic || !(fn)[0])
 

Functions

static HANDLE (WINAPI *pFindFirstFileExA)(LPCSTR
 
static BOOL (WINAPI *pReplaceFileA)(LPCSTR
 
static UINT (WINAPI *pGetSystemWindowsDirectoryA)(LPSTR
 
static DWORD (WINAPI *pQueueUserAPC)(PAPCFUNC pfnAPC
 
static HRESULT (WINAPI *pCopyFile2)(PCWSTR
 
static NTSTATUS (WINAPI *pNtCreateFile)(PHANDLE
 
static void (WINAPI *pRtlInitAnsiString)(PANSI_STRING
 
static void InitFunctionPointers (void)
 
static void test__hread (void)
 
static void test__hwrite (void)
 
static void test__lclose (void)
 
static void get_nt_pathW (const char *name, UNICODE_STRING *nameW)
 
static void test__lcreat (void)
 
static void test__llseek (void)
 
static void test__llopen (void)
 
static void test__lread (void)
 
static void test__lwrite (void)
 
static void test_CopyFileA (void)
 
static void test_CopyFileW (void)
 
static void test_CopyFile2 (void)
 
static DWORD WINAPI copy_progress_cb (LARGE_INTEGER total_size, LARGE_INTEGER total_transferred, LARGE_INTEGER stream_size, LARGE_INTEGER stream_transferred, DWORD stream, DWORD reason, HANDLE source, HANDLE dest, LPVOID userdata)
 
static void test_CopyFileEx (void)
 
static void dumpmem (unsigned char *mem, int len)
 
static void test_CreateFileA (void)
 
static void test_CreateFileW (void)
 
static void test_CreateFile2 (void)
 
static void test_GetTempFileNameA (void)
 
static void test_DeleteFileA (void)
 
static void test_DeleteFileW (void)
 
static void test_MoveFileA (void)
 
static void test_MoveFileW (void)
 
static void test_offset_in_overlapped_structure (void)
 
static void test_LockFile (void)
 
static BOOL create_fake_dll (LPCSTR filename)
 
static unsigned int map_file_access (unsigned int access)
 
static BOOL is_sharing_compatible (DWORD access1, DWORD sharing1, DWORD access2, DWORD sharing2)
 
static BOOL is_sharing_map_compatible (DWORD map_access, DWORD access2, DWORD sharing2)
 
static void test_file_sharing (void)
 
static char get_windows_drive (void)
 
static void test_FindFirstFileA (void)
 
static void test_FindNextFileA (void)
 
static void test_FindFirstFileExA (FINDEX_INFO_LEVELS level, FINDEX_SEARCH_OPS search_ops, DWORD flags)
 
static void test_FindFirstFile_wildcards (void)
 
static int test_Mapfile_createtemp (HANDLE *handle)
 
static void test_MapFile (void)
 
static void test_GetFileType (void)
 
static void CALLBACK FileIOComplete (DWORD dwError, DWORD dwBytes, LPOVERLAPPED ovl)
 
static void test_async_file_errors (void)
 
static void CALLBACK user_apc (ULONG_PTR param)
 
static void test_read_write (void)
 
static void test_OpenFile (void)
 
static void test_overlapped (void)
 
static void test_RemoveDirectory (void)
 
static BOOL check_file_time (const FILETIME *ft1, const FILETIME *ft2, UINT tolerance)
 
static void test_ReplaceFileA (void)
 
static void test_ReplaceFileW (void)
 
static void test_CreateFile (void)
 
static void test_GetFileInformationByHandleEx (void)
 
static void test_OpenFileById (void)
 
static void test_SetFileValidData (void)
 
static void test_WriteFileGather (void)
 
static unsigned file_map_access (unsigned access)
 
static BOOL is_access_compatible (unsigned obj_access, unsigned desired_access)
 
static void test_file_access (void)
 
static void test_GetFinalPathNameByHandleA (void)
 
static void test_GetFinalPathNameByHandleW (void)
 
static void test_SetFileInformationByHandle (void)
 
static void test_GetFileAttributesExW (void)
 
 START_TEST (file)
 

Variables

static FINDEX_INFO_LEVELS
 
static LPVOID
 
static FINDEX_SEARCH_OPS
 
static DWORD
 
static LPCSTR
 
static LPCWSTR
 
static UINT
 
static LPSTR
 
static HANDLE hThread
 
static HANDLE ULONG_PTR dwData
 
static FILE_INFO_BY_HANDLE_CLASS
 
static LPFILE_ID_DESCRIPTOR
 
static LPSECURITY_ATTRIBUTES
 
static LONGLONG
 
static PCWSTR
 
static LPWSTR
 
static ACCESS_MASK
 
static POBJECT_ATTRIBUTES
 
static PIO_STATUS_BLOCK
 
static PLARGE_INTEGER
 
static ULONG
 
static PVOID
 
static PUNICODE_STRING
 
static PWSTR CURDIR *static PCANSI_STRING
 
static PWSTR CURDIR *static BOOLEAN
 
static PCSZ
 
static char filename [MAX_PATH]
 
static const char sillytext []
 
struct {
   const char *   path
 
   BOOL   expected
 
invalid_char_tests []
 
static int completion_count
 
static BOOL user_apc_ran
 

Macro Definition Documentation

◆ CHECK_LEVEL

#define CHECK_LEVEL (   fn)    (level != FindExInfoBasic || !(fn)[0])

◆ CHECK_NAME

#define CHECK_NAME (   fn)    (strcmp((fn), "file1") == 0 || strcmp((fn), "file2") == 0 || strcmp((fn), "dir1") == 0)

◆ IsDotDir

#define IsDotDir (   x)    ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))

Definition at line 1853 of file file.c.

◆ M

#define M (   x)    {x, # x}

◆ PATTERN_OFFSET

#define PATTERN_OFFSET   0x10

Definition at line 2004 of file file.c.

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pReplaceFileA)
static

◆ check_file_time()

static BOOL check_file_time ( const FILETIME ft1,
const FILETIME ft2,
UINT  tolerance 
)
static

Definition at line 3585 of file file.c.

3586 {
3587  ULONGLONG t1 = ((ULONGLONG)ft1->dwHighDateTime << 32) | ft1->dwLowDateTime;
3588  ULONGLONG t2 = ((ULONGLONG)ft2->dwHighDateTime << 32) | ft2->dwLowDateTime;
3589  return abs(t1 - t2) <= tolerance;
3590 }
#define abs(i)
Definition: fconv.c:206
DWORD dwHighDateTime
Definition: mapidefs.h:66
uint64_t ULONGLONG
Definition: typedefs.h:65
DWORD dwLowDateTime
Definition: mapidefs.h:65

Referenced by test_ReplaceFileA().

◆ copy_progress_cb()

static DWORD WINAPI copy_progress_cb ( LARGE_INTEGER  total_size,
LARGE_INTEGER  total_transferred,
LARGE_INTEGER  stream_size,
LARGE_INTEGER  stream_transferred,
DWORD  stream,
DWORD  reason,
HANDLE  source,
HANDLE  dest,
LPVOID  userdata 
)
static

Definition at line 1111 of file file.c.

1114 {
1115  ok(reason == CALLBACK_STREAM_SWITCH, "expected CALLBACK_STREAM_SWITCH, got %u\n", reason);
1116  CloseHandle(userdata);
1117  return PROGRESS_CANCEL;
1118 }
#define CloseHandle
Definition: compat.h:398
#define CALLBACK_STREAM_SWITCH
Definition: winbase.h:151
#define ok(value,...)
#define PROGRESS_CANCEL
Definition: winbase.h:147
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904

Referenced by test_CopyFileEx().

◆ create_fake_dll()

static BOOL create_fake_dll ( LPCSTR  filename)
static

Definition at line 2209 of file file.c.

2210 {
2213  IMAGE_SECTION_HEADER *sec;
2214  BYTE *buffer;
2215  DWORD lfanew = sizeof(*dos);
2216  DWORD size = lfanew + sizeof(*nt) + sizeof(*sec);
2217  DWORD written;
2218  BOOL ret;
2219 
2221  if (file == INVALID_HANDLE_VALUE) return FALSE;
2222 
2224 
2227  dos->e_cblp = sizeof(*dos);
2228  dos->e_cp = 1;
2229  dos->e_cparhdr = lfanew / 16;
2230  dos->e_minalloc = 0;
2231  dos->e_maxalloc = 0xffff;
2232  dos->e_ss = 0x0000;
2233  dos->e_sp = 0x00b8;
2234  dos->e_lfarlc = lfanew;
2235  dos->e_lfanew = lfanew;
2236 
2237  nt = (IMAGE_NT_HEADERS *)(buffer + lfanew);
2239 #if defined __i386__
2241 #elif defined __x86_64__
2243 #elif defined __powerpc__
2245 #elif defined __arm__
2247 #elif defined __aarch64__
2249 #else
2250 # error You must specify the machine type
2251 #endif
2258  nt->OptionalHeader.ImageBase = 0x10000000;
2260  nt->OptionalHeader.FileAlignment = 0x1000;
2267  nt->OptionalHeader.SizeOfImage = 0x2000;
2271 
2272  sec = (IMAGE_SECTION_HEADER *)(nt + 1);
2273  memcpy( sec->Name, ".rodata", sizeof(".rodata") );
2274  sec->Misc.VirtualSize = 0x1000;
2275  sec->VirtualAddress = 0x1000;
2276  sec->SizeOfRawData = 0;
2277  sec->PointerToRawData = 0;
2278  sec->Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE;
2279 
2280  ret = WriteFile( file, buffer, size, &written, NULL ) && written == size;
2281  HeapFree( GetProcessHeap(), 0, buffer );
2282  CloseHandle( file );
2283  return ret;
2284 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define CloseHandle
Definition: compat.h:398
#define IMAGE_FILE_MACHINE_ARM64
Definition: compat.h:118
#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES
Definition: ntddk_ex.h:135
#define IMAGE_SCN_MEM_READ
Definition: ntimage.h:240
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
GLuint buffer
Definition: glext.h:5915
WORD MinorOperatingSystemVersion
Definition: ntddk_ex.h:161
const char * filename
Definition: ioapi.h:135
#define IMAGE_FILE_MACHINE_AMD64
Definition: ntimage.h:17
#define IMAGE_FILE_MACHINE_POWERPC
Definition: compat.h:117
IMAGE_NT_HEADERS nt
Definition: module.c:50
#define IMAGE_FILE_DLL
Definition: pedump.c:169
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
WORD MajorOperatingSystemVersion
Definition: ntddk_ex.h:160
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
static HANDLE PIO_APC_ROUTINE void PIO_STATUS_BLOCK void * buffer
Definition: file.c:88
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
WORD SizeOfOptionalHeader
Definition: ntddk_ex.h:127
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
#define IMAGE_FILE_MACHINE_I386
Definition: pedump.c:174
struct _IMAGE_OPTIONAL_HEADER IMAGE_OPTIONAL_HEADER
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define IMAGE_FILE_EXECUTABLE_IMAGE
Definition: pedump.c:160
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IMAGE_SCN_MEM_WRITE
Definition: ntimage.h:241
int ret
IMAGE_DOS_HEADER dos
Definition: module.c:49
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define GENERIC_READ
Definition: compat.h:124
#define CREATE_ALWAYS
Definition: disk.h:72
#define IMAGE_FILE_MACHINE_ARMNT
Definition: compat.h:116
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define IMAGE_NT_OPTIONAL_HDR_MAGIC
Definition: ntimage.h:387
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
#define HeapFree(x, y, z)
Definition: compat.h:394
#define IMAGE_SUBSYSTEM_WINDOWS_GUI
Definition: ntimage.h:437
Definition: fci.c:126

Referenced by test_file_sharing().

◆ dumpmem()

static void dumpmem ( unsigned char mem,
int  len 
)
static

Definition at line 1165 of file file.c.

1166 {
1167  int x = 0;
1168  char hex[49], *p;
1169  char txt[17], *c;
1170 
1171  while (x < len)
1172  {
1173  p = hex;
1174  c = txt;
1175  do {
1176  p += sprintf(p, "%02x ", mem[x]);
1177  *c++ = (mem[x] >= 32 && mem[x] <= 127) ? mem[x] : '.';
1178  } while (++x % 16 && x < len);
1179  *c = '\0';
1180  trace("%04x: %-48s- %s\n", x, hex, txt);
1181  }
1182 }
#define trace(...)
Definition: kmt_test.h:217
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
static const char hex[16]
Definition: profile.c:123
#define sprintf(buf, format,...)
Definition: sprintf.c:55
const GLubyte * c
Definition: glext.h:8905
GLenum GLsizei len
Definition: glext.h:6722
Definition: mem.c:156
#define c
Definition: ke_i.h:80
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by test_CreateFileA().

◆ DWORD()

static DWORD ( WINAPI pQueueUserAPC)
static

◆ file_map_access()

static unsigned file_map_access ( unsigned  access)
static

Definition at line 4487 of file file.c.

4488 {
4494 }
#define FILE_GENERIC_READ
Definition: nt_native.h:653
#define GENERIC_ALL
Definition: nt_native.h:92
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
#define GENERIC_WRITE
Definition: nt_native.h:90
#define FILE_GENERIC_EXECUTE
Definition: nt_native.h:668
#define GENERIC_READ
Definition: compat.h:124
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define GENERIC_EXECUTE
Definition: nt_native.h:91

Referenced by is_access_compatible().

◆ FileIOComplete()

static void CALLBACK FileIOComplete ( DWORD  dwError,
DWORD  dwBytes,
LPOVERLAPPED  ovl 
)
static

Definition at line 3074 of file file.c.

3075 {
3076 /* printf("(%ld, %ld, %p { %ld, %ld, %ld, %ld, %p })\n", dwError, dwBytes, ovl, ovl->Internal, ovl->InternalHigh, ovl->Offset, ovl->OffsetHigh, ovl->hEvent);*/
3077  ReleaseSemaphore(ovl->hEvent, 1, NULL);
3078  completion_count++;
3079 }
HANDLE hEvent
Definition: winbase.h:792
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:488
static int completion_count
Definition: file.c:3072

Referenced by test_async_file_errors().

◆ get_nt_pathW()

static void get_nt_pathW ( const char name,
UNICODE_STRING nameW 
)
static

Definition at line 254 of file file.c.

255 {
259  BOOLEAN ret;
260 
261  pRtlInitAnsiString( &str, name );
262 
263  status = pRtlAnsiStringToUnicodeString( &strW, &str, TRUE );
264  ok( !status, "RtlAnsiStringToUnicodeString failed with %08x\n", status );
265 
266  ret = pRtlDosPathNameToNtPathName_U( strW.Buffer, nameW, NULL, NULL );
267  ok( ret, "RtlDosPathNameToNtPathName_U failed\n" );
268 
269  pRtlFreeUnicodeString( &strW );
270 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
WCHAR strW[12]
Definition: clipboard.c:2029
#define ok(value,...)
const WCHAR * str
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR nameW[]
Definition: main.c:46
int ret
Definition: name.c:36
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by test__lcreat().

◆ get_windows_drive()

static char get_windows_drive ( void  )
static

Definition at line 2501 of file file.c.

2502 {
2503  char windowsdir[MAX_PATH];
2504  GetWindowsDirectoryA(windowsdir, sizeof(windowsdir));
2505  return windowsdir[0];
2506 }
#define MAX_PATH
Definition: compat.h:26
UINT WINAPI GetWindowsDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2336

Referenced by test_FindFirstFileA(), and test_FindNextFileA().

◆ HANDLE()

static HANDLE ( WINAPI pFindFirstFileExA)
static

◆ HRESULT()

static HRESULT ( WINAPI pCopyFile2)
static

◆ InitFunctionPointers()

static void InitFunctionPointers ( void  )
static

Definition at line 72 of file file.c.

73 {
74  HMODULE hntdll = GetModuleHandleA("ntdll");
75  HMODULE hkernel32 = GetModuleHandleA("kernel32");
76 
77  pNtCreateFile = (void *)GetProcAddress(hntdll, "NtCreateFile");
78  pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U");
79  pRtlAnsiStringToUnicodeString = (void *)GetProcAddress(hntdll, "RtlAnsiStringToUnicodeString");
80  pRtlInitAnsiString = (void *)GetProcAddress(hntdll, "RtlInitAnsiString");
81  pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
82 
83  pFindFirstFileExA=(void*)GetProcAddress(hkernel32, "FindFirstFileExA");
84  pReplaceFileA=(void*)GetProcAddress(hkernel32, "ReplaceFileA");
85  pReplaceFileW=(void*)GetProcAddress(hkernel32, "ReplaceFileW");
86  pGetSystemWindowsDirectoryA=(void*)GetProcAddress(hkernel32, "GetSystemWindowsDirectoryA");
87  pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hkernel32, "GetVolumeNameForVolumeMountPointA");
88  pQueueUserAPC = (void *) GetProcAddress(hkernel32, "QueueUserAPC");
89  pGetFileInformationByHandleEx = (void *) GetProcAddress(hkernel32, "GetFileInformationByHandleEx");
90  pOpenFileById = (void *) GetProcAddress(hkernel32, "OpenFileById");
91  pSetFileValidData = (void *) GetProcAddress(hkernel32, "SetFileValidData");
92  pCopyFile2 = (void *) GetProcAddress(hkernel32, "CopyFile2");
93  pCreateFile2 = (void *) GetProcAddress(hkernel32, "CreateFile2");
94  pGetFinalPathNameByHandleA = (void *) GetProcAddress(hkernel32, "GetFinalPathNameByHandleA");
95  pGetFinalPathNameByHandleW = (void *) GetProcAddress(hkernel32, "GetFinalPathNameByHandleW");
96  pSetFileInformationByHandle = (void *) GetProcAddress(hkernel32, "SetFileInformationByHandle");
97 }
static HINSTANCE hkernel32
Definition: process.c:66
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
static HINSTANCE hntdll
Definition: process.c:66
#define GetProcAddress(x, y)
Definition: compat.h:410

Referenced by START_TEST().

◆ is_access_compatible()

static BOOL is_access_compatible ( unsigned  obj_access,
unsigned  desired_access 
)
static

Definition at line 4496 of file file.c.

4497 {
4498  obj_access = file_map_access(obj_access);
4499  desired_access = file_map_access(desired_access);
4500  return (obj_access & desired_access) == desired_access;
4501 }
static unsigned file_map_access(unsigned access)
Definition: file.c:4487

Referenced by test_file_access().

◆ is_sharing_compatible()

static BOOL is_sharing_compatible ( DWORD  access1,
DWORD  sharing1,
DWORD  access2,
DWORD  sharing2 
)
static

Definition at line 2295 of file file.c.

2296 {
2297  access1 = map_file_access( access1 );
2298  access2 = map_file_access( access2 );
2301 
2302  if (!access1) sharing1 = FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE;
2303  if (!access2) sharing2 = FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE;
2304 
2305  if ((access1 & (FILE_READ_DATA|FILE_EXECUTE)) && !(sharing2 & FILE_SHARE_READ)) return FALSE;
2306  if ((access1 & (FILE_WRITE_DATA|FILE_APPEND_DATA)) && !(sharing2 & FILE_SHARE_WRITE)) return FALSE;
2307  if ((access1 & DELETE) && !(sharing2 & FILE_SHARE_DELETE)) return FALSE;
2308  if ((access2 & (FILE_READ_DATA|FILE_EXECUTE)) && !(sharing1 & FILE_SHARE_READ)) return FALSE;
2309  if ((access2 & (FILE_WRITE_DATA|FILE_APPEND_DATA)) && !(sharing1 & FILE_SHARE_WRITE)) return FALSE;
2310  if ((access2 & DELETE) && !(sharing1 & FILE_SHARE_DELETE)) return FALSE;
2311  return TRUE;
2312 }
#define TRUE
Definition: types.h:120
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_APPEND_DATA
Definition: nt_native.h:634
#define FILE_SHARE_READ
Definition: compat.h:125
#define FILE_READ_DATA
Definition: nt_native.h:628
#define FILE_WRITE_DATA
Definition: nt_native.h:631
static unsigned int map_file_access(unsigned int access)
Definition: file.c:2286
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define FILE_EXECUTE
Definition: nt_native.h:642
#define DELETE
Definition: nt_native.h:57

Referenced by test_file_sharing().

◆ is_sharing_map_compatible()

static BOOL is_sharing_map_compatible ( DWORD  map_access,
DWORD  access2,
DWORD  sharing2 
)
static

Definition at line 2314 of file file.c.

2315 {
2316  if ((map_access == PAGE_READWRITE || map_access == PAGE_EXECUTE_READWRITE) &&
2317  !(sharing2 & FILE_SHARE_WRITE)) return FALSE;
2318  access2 = map_file_access( access2 );
2319  if ((map_access & SEC_IMAGE) && (access2 & FILE_WRITE_DATA)) return FALSE;
2320  return TRUE;
2321 }
#define TRUE
Definition: types.h:120
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_WRITE_DATA
Definition: nt_native.h:631
static unsigned int map_file_access(unsigned int access)
Definition: file.c:2286
#define SEC_IMAGE
Definition: mmtypes.h:96
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by test_file_sharing().

◆ map_file_access()

static unsigned int map_file_access ( unsigned int  access)
static

Definition at line 2286 of file file.c.

2287 {
2293 }
#define FILE_GENERIC_READ
Definition: nt_native.h:653
#define GENERIC_ALL
Definition: nt_native.h:92
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
#define GENERIC_WRITE
Definition: nt_native.h:90
#define FILE_GENERIC_EXECUTE
Definition: nt_native.h:668
#define GENERIC_READ
Definition: compat.h:124
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define GENERIC_EXECUTE
Definition: nt_native.h:91

Referenced by is_sharing_compatible(), and is_sharing_map_compatible().

◆ NTSTATUS()

static NTSTATUS ( WINAPI pNtCreateFile)
static

◆ START_TEST()

START_TEST ( file  )

Definition at line 4906 of file file.c.

4907 {
4908  char temp_path[MAX_PATH];
4909  DWORD ret;
4910 
4912 
4914  ok(ret != 0, "GetTempPath error %u\n", GetLastError());
4915  ret = GetTempFileNameA(temp_path, "tmp", 0, filename);
4916  ok(ret != 0, "GetTempFileName error %u\n", GetLastError());
4918  ok(ret != 0, "DeleteFile error %u\n", GetLastError());
4919 
4920  test__hread( );
4921  test__hwrite( );
4922  test__lclose( );
4923  test__lcreat( );
4924  test__llseek( );
4925  test__llopen( );
4926  test__lread( );
4927  test__lwrite( );
4929  test_CopyFileA();
4930  test_CopyFileW();
4931  test_CopyFile2();
4932  test_CopyFileEx();
4933  test_CreateFile();
4934  test_CreateFileA();
4935  test_CreateFileW();
4936  test_CreateFile2();
4937  test_DeleteFileA();
4938  test_DeleteFileW();
4939  test_MoveFileA();
4940  test_MoveFileW();
4948  /* FindExLimitToDirectories is ignored if the file system doesn't support directory filtering */
4953  test_LockFile();
4956  test_MapFile();
4957  test_GetFileType();
4959  test_read_write();
4960  test_OpenFile();
4961  test_overlapped();
4969  test_file_access();
4974 }
static void test_FindFirstFile_wildcards(void)
Definition: file.c:2902
static void test_GetFinalPathNameByHandleW(void)
Definition: file.c:4696
static void test_CreateFileA(void)
Definition: file.c:1184
static void test_GetFileAttributesExW(void)
Definition: file.c:4882
static void InitFunctionPointers(void)
Definition: file.c:72
static void test_overlapped(void)
Definition: file.c:3486
static void test_CreateFile(void)
Definition: file.c:3890
static void test_RemoveDirectory(void)
Definition: file.c:3563
static void test_CopyFileEx(void)
Definition: file.c:1120
static void test_MapFile(void)
Definition: file.c:3007
static void test_LockFile(void)
Definition: file.c:2079
static void test_FindFirstFileA(void)
Definition: file.c:2582
static void test_SetFileValidData(void)
Definition: file.c:4293
static void test_async_file_errors(void)
Definition: file.c:3081
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static void test_MoveFileA(void)
Definition: file.c:1855
static void test_CopyFileA(void)
Definition: file.c:675
static void test_file_access(void)
Definition: file.c:4503
const char * filename
Definition: ioapi.h:135
static void test_ReplaceFileW(void)
Definition: file.c:3806
static void test_GetFileType(void)
Definition: file.c:3051
static void test__lread(void)
Definition: file.c:544
static void test_GetFileInformationByHandleEx(void)
Definition: file.c:4023
static void test__lcreat(void)
Definition: file.c:272
#define ok(value,...)
static void test_CopyFileW(void)
Definition: file.c:847
static void test__hwrite(void)
Definition: file.c:146
static void test_ReplaceFileA(void)
Definition: file.c:3592
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
static void test_CreateFile2(void)
Definition: file.c:1630
#define FIND_FIRST_EX_CASE_SENSITIVE
Definition: winbase.h:231
static void test__llopen(void)
Definition: file.c:504
static void test_GetFinalPathNameByHandleA(void)
Definition: file.c:4609
static void test_OpenFile(void)
Definition: file.c:3292
static void test_DeleteFileA(void)
Definition: file.c:1748
#define MAX_PATH
Definition: compat.h:26
static void test__hread(void)
Definition: file.c:99
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FIND_FIRST_EX_LARGE_FETCH
Definition: winbase.h:232
static void test__lclose(void)
Definition: file.c:233
static void test_read_write(void)
Definition: file.c:3130
int ret
static void test_DeleteFileW(void)
Definition: file.c:1801
static void test__lwrite(void)
Definition: file.c:589
static void test_offset_in_overlapped_structure(void)
Definition: file.c:2006
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
static void test_OpenFileById(void)
Definition: file.c:4189
static void test_FindFirstFileExA(FINDEX_INFO_LEVELS level, FINDEX_SEARCH_OPS search_ops, DWORD flags)
Definition: file.c:2799
static void test_SetFileInformationByHandle(void)
Definition: file.c:4819
static void test__llseek(void)
Definition: file.c:466
static void test_CopyFile2(void)
Definition: file.c:882
static void test_file_sharing(void)
Definition: file.c:2323
static void test_FindNextFileA(void)
Definition: file.c:2780
static void test_CreateFileW(void)
Definition: file.c:1541
static void test_GetTempFileNameA(void)
Definition: file.c:1711
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
static void test_WriteFileGather(void)
Definition: file.c:4430
static void test_MoveFileW(void)
Definition: file.c:1972
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

◆ test__hread()

static void test__hread ( void  )
static

Definition at line 99 of file file.c.

100 {
101  HFILE filehandle;
102  char buffer[10000];
103  LONG bytes_read;
104  LONG bytes_wanted;
105  LONG i;
106  BOOL ret;
107 
108  SetFileAttributesA(filename,FILE_ATTRIBUTE_NORMAL); /* be sure to remove stale files */
110  filehandle = _lcreat( filename, 0 );
111  if (filehandle == HFILE_ERROR)
112  {
113  ok(0,"couldn't create file \"%s\" (err=%d)\n",filename,GetLastError());
114  return;
115  }
116 
117  ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
118 
119  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
120 
121  filehandle = _lopen( filename, OF_READ );
122 
123  ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%d)\n", filename, GetLastError( ) );
124 
125  bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
126 
127  ok( lstrlenA( sillytext ) == bytes_read, "file read size error\n" );
128 
129  for (bytes_wanted = 0; bytes_wanted < lstrlenA( sillytext ); bytes_wanted++)
130  {
131  ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
132  ok( _hread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value\n" );
133  for (i = 0; i < bytes_wanted; i++)
134  {
135  ok( buffer[i] == sillytext[i], "that's not what's written\n" );
136  }
137  }
138 
139  ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
140 
141  ret = DeleteFileA( filename );
142  ok( ret != 0, "DeleteFile failed (%d)\n", GetLastError( ) );
143 }
#define OF_READ
Definition: winbase.h:116
LONG WINAPI _llseek(HFILE hFile, LONG lOffset, int iOrigin)
Definition: lfile.c:149
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
HFILE WINAPI _lcreat(LPCSTR lpPathName, int iAttribute)
Definition: lfile.c:116
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLuint buffer
Definition: glext.h:5915
long WINAPI _hread(HFILE hFile, LPVOID lpBuffer, long lBytes)
Definition: lfile.c:20
const char * filename
Definition: ioapi.h:135
int WINAPI _lclose(HFILE hFile)
Definition: lfile.c:138
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define HFILE_ERROR
Definition: winbase.h:111
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
long WINAPI _hwrite(HFILE hFile, LPCSTR lpBuffer, long lBytes)
Definition: lfile.c:41
#define ok(value,...)
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:926
HFILE WINAPI _lopen(LPCSTR lpPathName, int iReadWrite)
Definition: lfile.c:70
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define FILE_BEGIN
Definition: winbase.h:112
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
int HFILE
Definition: windef.h:283
static const char sillytext[]
Definition: file.c:52

Referenced by START_TEST().

◆ test__hwrite()

static void test__hwrite ( void  )
static

Definition at line 146 of file file.c.

147 {
148  HFILE filehandle;
149  char buffer[10000];
150  LONG bytes_read;
151  LONG bytes_written;
152  ULONG blocks;
153  LONG i;
154  char *contents;
155  HLOCAL memory_object;
156  char checksum[1];
157  BOOL ret;
158 
159  filehandle = _lcreat( filename, 0 );
160  if (filehandle == HFILE_ERROR)
161  {
162  ok(0,"couldn't create file \"%s\" (err=%d)\n",filename,GetLastError());
163  return;
164  }
165 
166  ok( HFILE_ERROR != _hwrite( filehandle, "", 0 ), "_hwrite complains\n" );
167 
168  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
169 
170  filehandle = _lopen( filename, OF_READ );
171 
172  bytes_read = _hread( filehandle, buffer, 1);
173 
174  ok( 0 == bytes_read, "file read size error\n" );
175 
176  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
177 
178  filehandle = _lopen( filename, OF_READWRITE );
179 
180  bytes_written = 0;
181  checksum[0] = '\0';
182  srand( (unsigned)time( NULL ) );
183  for (blocks = 0; blocks < 100; blocks++)
184  {
185  for (i = 0; i < (LONG)sizeof( buffer ); i++)
186  {
187  buffer[i] = rand( );
188  checksum[0] = checksum[0] + buffer[i];
189  }
190  ok( HFILE_ERROR != _hwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains\n" );
191  bytes_written = bytes_written + sizeof( buffer );
192  }
193 
194  ok( HFILE_ERROR != _hwrite( filehandle, checksum, 1 ), "_hwrite complains\n" );
195  bytes_written++;
196 
197  ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
198 
199  memory_object = LocalAlloc( LPTR, bytes_written );
200 
201  ok( 0 != memory_object, "LocalAlloc fails. (Could be out of memory.)\n" );
202 
203  contents = LocalLock( memory_object );
204  ok( NULL != contents, "LocalLock whines\n" );
205 
206  filehandle = _lopen( filename, OF_READ );
207 
208  contents = LocalLock( memory_object );
209  ok( NULL != contents, "LocalLock whines\n" );
210 
211  ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length\n" );
212 
213  checksum[0] = '\0';
214  i = 0;
215  do
216  {
217  checksum[0] = checksum[0] + contents[i];
218  i++;
219  }
220  while (i < bytes_written - 1);
221 
222  ok( checksum[0] == contents[i], "stored checksum differ from computed checksum\n" );
223 
224  ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
225 
226  ret = DeleteFileA( filename );
227  ok( ret != 0, "DeleteFile failed (%d)\n", GetLastError( ) );
228 
229  LocalFree( contents );
230 }
#define OF_READ
Definition: winbase.h:116
HFILE WINAPI _lcreat(LPCSTR lpPathName, int iAttribute)
Definition: lfile.c:116
void __cdecl srand(_In_ unsigned int _Seed)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLuint buffer
Definition: glext.h:5915
long WINAPI _hread(HFILE hFile, LPVOID lpBuffer, long lBytes)
Definition: lfile.c:20
__u16 time
Definition: mkdosfs.c:366
const char * filename
Definition: ioapi.h:135
int WINAPI _lclose(HFILE hFile)
Definition: lfile.c:138
static HANDLE PIO_APC_ROUTINE void PIO_STATUS_BLOCK void * buffer
Definition: file.c:88
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define HFILE_ERROR
Definition: winbase.h:111
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
long WINAPI _hwrite(HFILE hFile, LPCSTR lpBuffer, long lBytes)
Definition: lfile.c:41
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
static int blocks
Definition: mkdosfs.c:527
HFILE WINAPI _lopen(LPCSTR lpPathName, int iReadWrite)
Definition: lfile.c:70
int ret
static cab_ULONG checksum(const cab_UBYTE *data, cab_UWORD bytes, cab_ULONG csum)
Definition: fdi.c:353
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
LPVOID NTAPI LocalLock(HLOCAL hMem)
Definition: heapmem.c:1599
#define OF_READWRITE
Definition: winbase.h:117
unsigned int ULONG
Definition: retypes.h:1
#define LPTR
Definition: winbase.h:362
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
int HFILE
Definition: windef.h:283

Referenced by START_TEST().

◆ test__lclose()

static void test__lclose ( void  )
static

Definition at line 233 of file file.c.

234 {
235  HFILE filehandle;
236  BOOL ret;
237 
238  filehandle = _lcreat( filename, 0 );
239  if (filehandle == HFILE_ERROR)
240  {
241  ok(0,"couldn't create file \"%s\" (err=%d)\n",filename,GetLastError());
242  return;
243  }
244 
245  ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
246 
247  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
248 
249  ret = DeleteFileA( filename );
250  ok( ret != 0, "DeleteFile failed (%d)\n", GetLastError( ) );
251 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
HFILE WINAPI _lcreat(LPCSTR lpPathName, int iAttribute)
Definition: lfile.c:116
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
const char * filename
Definition: ioapi.h:135
int WINAPI _lclose(HFILE hFile)
Definition: lfile.c:138
#define HFILE_ERROR
Definition: winbase.h:111
unsigned int BOOL
Definition: ntddk_ex.h:94
long WINAPI _hwrite(HFILE hFile, LPCSTR lpBuffer, long lBytes)
Definition: lfile.c:41
#define ok(value,...)
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
int ret
int HFILE
Definition: windef.h:283
static const char sillytext[]
Definition: file.c:52

Referenced by START_TEST().

◆ test__lcreat()

static void test__lcreat ( void  )
static

Definition at line 272 of file file.c.

273 {
277  HFILE filehandle;
278  char buffer[10000];
279  WIN32_FIND_DATAA search_results;
280  char slashname[] = "testfi/";
281  int err;
282  HANDLE find, file;
284  BOOL ret;
285 
286  filehandle = _lcreat( filename, 0 );
287  if (filehandle == HFILE_ERROR)
288  {
289  ok(0,"couldn't create file \"%s\" (err=%d)\n",filename,GetLastError());
290  return;
291  }
292 
293  ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
294 
295  ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
296 
297  ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" );
298 
299  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
300 
301  find = FindFirstFileA( filename, &search_results );
302  ok( INVALID_HANDLE_VALUE != find, "should be able to find file\n" );
303  FindClose( find );
304 
306  ok( ret != 0, "DeleteFile failed (%d)\n", GetLastError());
307 
308  filehandle = _lcreat( filename, 1 ); /* readonly */
309  ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%d)\n", filename, GetLastError( ) );
310 
311  ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write never the less\n" );
312 
313  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
314 
315  find = FindFirstFileA( filename, &search_results );
316  ok( INVALID_HANDLE_VALUE != find, "should be able to find file\n" );
317  FindClose( find );
318 
319  SetLastError( 0xdeadbeef );
320  ok( 0 == DeleteFileA( filename ), "shouldn't be able to delete a readonly file\n" );
321  ok( GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError() );
322 
323  ok( SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL ) != 0, "couldn't change attributes on file\n" );
324 
325  ok( DeleteFileA( filename ) != 0, "now it should be possible to delete the file!\n" );
326 
327  filehandle = _lcreat( filename, 1 ); /* readonly */
328  ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%d)\n", filename, GetLastError() );
329  ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen(sillytext) ),
330  "_hwrite shouldn't be able to write never the less\n" );
331  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
332 
333  find = FindFirstFileA( filename, &search_results );
334  ok( INVALID_HANDLE_VALUE != find, "should be able to find file\n" );
335  FindClose( find );
336 
338  attr.Length = sizeof(attr);
339  attr.RootDirectory = 0;
340  attr.Attributes = OBJ_CASE_INSENSITIVE;
341  attr.ObjectName = &filenameW;
342  attr.SecurityDescriptor = NULL;
343  attr.SecurityQualityOfService = NULL;
344 
345  status = pNtCreateFile( &file, GENERIC_READ | GENERIC_WRITE | DELETE, &attr, &io, NULL, 0,
348  ok( status == STATUS_ACCESS_DENIED, "expected STATUS_ACCESS_DENIED, got %08x\n", status );
349  ok( GetFileAttributesA( filename ) != INVALID_FILE_ATTRIBUTES, "file was deleted\n" );
350 
351  status = pNtCreateFile( &file, DELETE, &attr, &io, NULL, 0,
354  ok( status == STATUS_CANNOT_DELETE, "expected STATUS_CANNOT_DELETE, got %08x\n", status );
355 
356  status = pNtCreateFile( &file, DELETE, &attr, &io, NULL, 0,
359  ok( status == STATUS_NOT_A_DIRECTORY, "expected STATUS_NOT_A_DIRECTORY, got %08x\n", status );
360 
361  status = pNtCreateFile( &file, DELETE, &attr, &io, NULL, 0,
364  todo_wine
365  ok( status == STATUS_CANNOT_DELETE, "expected STATUS_CANNOT_DELETE, got %08x\n", status );
366  if (!status) CloseHandle( file );
367 
368  pRtlFreeUnicodeString( &filenameW );
369 
370  todo_wine
371  ok( GetFileAttributesA( filename ) != INVALID_FILE_ATTRIBUTES, "file was deleted\n" );
372  todo_wine
373  ok( SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL ) != 0, "couldn't change attributes on file\n" );
374  todo_wine
375  ok( DeleteFileA( filename ) != 0, "now it should be possible to delete the file\n" );
376 
377  filehandle = _lcreat( filename, 2 );
378  ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%d)\n", filename, GetLastError( ) );
379 
380  ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
381 
382  ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
383 
384  ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" );
385 
386  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
387 
388  find = FindFirstFileA( filename, &search_results );
389  ok( INVALID_HANDLE_VALUE != find, "should STILL be able to find file\n" );
390  FindClose( find );
391 
392  ret = DeleteFileA( filename );
393  ok( ret, "DeleteFile failed (%d)\n", GetLastError( ) );
394 
395  filehandle = _lcreat( filename, 4 ); /* SYSTEM file */
396  ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%d)\n", filename, GetLastError( ) );
397 
398  ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
399 
400  ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
401 
402  ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" );
403 
404  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
405 
406  find = FindFirstFileA( filename, &search_results );
407  ok( INVALID_HANDLE_VALUE != find, "should STILL be able to find file\n" );
408  FindClose( find );
409 
410  ret = DeleteFileA( filename );
411  ok( ret, "DeleteFile failed (%d)\n", GetLastError( ) );
412 
413  filehandle=_lcreat (slashname, 0); /* illegal name */
414  if (HFILE_ERROR==filehandle) {
415  err=GetLastError ();
417  "creating file \"%s\" failed with error %d\n", slashname, err);
418  } else { /* only NT succeeds */
419  _lclose(filehandle);
420  find=FindFirstFileA (slashname, &search_results);
422  {
423  ret = FindClose (find);
424  ok (0 != ret, "FindClose complains (%d)\n", GetLastError ());
425  slashname[strlen(slashname)-1]=0;
426  ok (!strcmp (slashname, search_results.cFileName),
427  "found unexpected name \"%s\"\n", search_results.cFileName);
428  ok (FILE_ATTRIBUTE_ARCHIVE==search_results.dwFileAttributes,
429  "attributes of file \"%s\" are 0x%04x\n", search_results.cFileName,
430  search_results.dwFileAttributes);
431  }
432  ret = DeleteFileA( slashname );
433  ok( ret, "DeleteFile failed (%d)\n", GetLastError( ) );
434  }
435 
436  filehandle=_lcreat (filename, 8); /* illegal attribute */
437  if (HFILE_ERROR==filehandle)
438  ok (0, "couldn't create volume label \"%s\"\n", filename);
439  else {
440  _lclose(filehandle);
441  find=FindFirstFileA (filename, &search_results);
443  ok (0, "file \"%s\" not found\n", filename);
444  else {
445  const char *name = strrchr(filename, '\\');
446 
447  if (name) name++;
448  else name = filename;
449 
450  ret = FindClose(find);
451  ok ( 0 != ret, "FindClose complains (%d)\n", GetLastError ());
452  ok (!strcmp (name, search_results.cFileName),
453  "expected \"%s\", got \"%s\"\n", name, search_results.cFileName);
454  search_results.dwFileAttributes &= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
455  search_results.dwFileAttributes &= ~FILE_ATTRIBUTE_COMPRESSED;
456  ok (FILE_ATTRIBUTE_ARCHIVE==search_results.dwFileAttributes,
457  "attributes of file \"%s\" are 0x%04x\n", search_results.cFileName,
458  search_results.dwFileAttributes);
459  }
460  ret = DeleteFileA( filename );
461  ok( ret, "DeleteFile failed (%d)\n", GetLastError( ) );
462  }
463 }
#define CloseHandle
Definition: compat.h:398
#define FILE_OPEN_IF
Definition: from_kernel.h:56
LONG WINAPI _llseek(HFILE hFile, LONG lOffset, int iOrigin)
Definition: lfile.c:149
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static void get_nt_pathW(const char *name, UNICODE_STRING *nameW)
Definition: file.c:254
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
HFILE WINAPI _lcreat(LPCSTR lpPathName, int iAttribute)
Definition: lfile.c:116
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLuint buffer
Definition: glext.h:5915
long WINAPI _hread(HFILE hFile, LPVOID lpBuffer, long lBytes)
Definition: lfile.c:20
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
const char * filename
Definition: ioapi.h:135
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
Definition: ntifs_ex.h:384
int WINAPI _lclose(HFILE hFile)
Definition: lfile.c:138
#define FILE_SHARE_READ
Definition: compat.h:125
static const WCHAR filenameW[]
Definition: amstream.c:41
#define STATUS_NOT_A_DIRECTORY
Definition: udferr_usr.h:169
#define HFILE_ERROR
Definition: winbase.h:111
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
unsigned int BOOL
Definition: ntddk_ex.h:94
long WINAPI _hwrite(HFILE hFile, LPCSTR lpBuffer, long lBytes)
Definition: lfile.c:41
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:786
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:926
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
const char file[]
Definition: icontest.c:11
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define SetLastError(x)
Definition: compat.h:409
Definition: cookie.c:170
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define FILE_ATTRIBUTE_COMPRESSED
Definition: nt_native.h:711
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define FILE_ATTRIBUTE_ARCHIVE
Definition: nt_native.h:706
#define STATUS_CANNOT_DELETE
Definition: shellext.h:66
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
__u8 attr
Definition: mkdosfs.c:359
#define todo_wine
Definition: test.h:154
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define GENERIC_READ
Definition: compat.h:124
#define err(...)
#define FILE_OPEN
Definition: from_kernel.h:54
#define FILE_BEGIN
Definition: winbase.h:112
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
static TAGID TAGID find
Definition: db.cpp:153
static char filename[MAX_PATH]
Definition: file.c:51
Definition: name.c:36
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ERROR_INVALID_NAME
Definition: compat.h:93
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
static HANDLE PIO_APC_ROUTINE PVOID PIO_STATUS_BLOCK io
Definition: file.c:100
static SERVICE_STATUS status
Definition: service.c:31
int HFILE
Definition: windef.h:283
HANDLE WINAPI FindFirstFileA(IN LPCSTR lpFileName, OUT LPWIN32_FIND_DATAA lpFindFileData)
Definition: find.c:263
static const char sillytext[]
Definition: file.c:52
#define DELETE
Definition: nt_native.h:57
Definition: fci.c:126
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
Definition: ps.c:97

Referenced by START_TEST().

◆ test__llopen()

static void test__llopen ( void  )
static

Definition at line 504 of file file.c.

505 {
506  HFILE filehandle;
507  UINT bytes_read;
508  char buffer[10000];
509  BOOL ret;
510 
511  filehandle = _lcreat( filename, 0 );
512  if (filehandle == HFILE_ERROR)
513  {
514  ok(0,"couldn't create file \"%s\" (err=%d)\n",filename,GetLastError());
515  return;
516  }
517 
518  ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
519  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
520 
521  filehandle = _lopen( filename, OF_READ );
522  ok( HFILE_ERROR == _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write!\n" );
523  bytes_read = _hread( filehandle, buffer, strlen( sillytext ) );
524  ok( strlen( sillytext ) == bytes_read, "file read size error\n" );
525  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
526 
527  filehandle = _lopen( filename, OF_READWRITE );
528  bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
529  ok( strlen( sillytext ) == bytes_read, "file read size error\n" );
530  ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine\n" );
531  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
532 
533  filehandle = _lopen( filename, OF_WRITE );
534  ok( HFILE_ERROR == _hread( filehandle, buffer, 1 ), "you should only be able to write this file\n" );
535  ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine\n" );
536  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
537 
538  ret = DeleteFileA( filename );
539  ok( ret, "DeleteFile failed (%d)\n", GetLastError( ) );
540  /* TODO - add tests for the SHARE modes - use two processes to pull this one off */
541 }
#define OF_READ
Definition: winbase.h:116
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
HFILE WINAPI _lcreat(LPCSTR lpPathName, int iAttribute)
Definition: lfile.c:116
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLuint buffer
Definition: glext.h:5915
long WINAPI _hread(HFILE hFile, LPVOID lpBuffer, long lBytes)
Definition: lfile.c:20
const char * filename
Definition: ioapi.h:135
int WINAPI _lclose(HFILE hFile)
Definition: lfile.c:138
#define HFILE_ERROR
Definition: winbase.h:111
unsigned int BOOL
Definition: ntddk_ex.h:94
long WINAPI _hwrite(HFILE hFile, LPCSTR lpBuffer, long lBytes)
Definition: lfile.c:41
#define ok(value,...)
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
HFILE WINAPI _lopen(LPCSTR lpPathName, int iReadWrite)
Definition: lfile.c:70
int ret
#define OF_WRITE
Definition: winbase.h:118
#define OF_READWRITE
Definition: winbase.h:117
unsigned int UINT
Definition: ndis.h:50
int HFILE
Definition: windef.h:283
static const char sillytext[]
Definition: file.c:52

Referenced by START_TEST().

◆ test__llseek()

static void test__llseek ( void  )
static

Definition at line 466 of file file.c.

467 {
468  INT i;
469  HFILE filehandle;
470  char buffer[1];
471  LONG bytes_read;
472  BOOL ret;
473 
474  filehandle = _lcreat( filename, 0 );
475  if (filehandle == HFILE_ERROR)
476  {
477  ok(0,"couldn't create file \"%s\" (err=%d)\n",filename,GetLastError());
478  return;
479  }
480 
481  for (i = 0; i < 400; i++)
482  {
483  ok( _hwrite( filehandle, sillytext, strlen( sillytext ) ) != -1, "_hwrite complains\n" );
484  }
485  ok( _llseek( filehandle, 400 * strlen( sillytext ), FILE_CURRENT ) != -1, "should be able to seek\n" );
486  ok( _llseek( filehandle, 27 + 35 * strlen( sillytext ), FILE_BEGIN ) != -1, "should be able to seek\n" );
487 
488  bytes_read = _hread( filehandle, buffer, 1);
489  ok( 1 == bytes_read, "file read size error\n" );
490  ok( buffer[0] == sillytext[27], "_llseek error, it got lost seeking\n" );
491  ok( _llseek( filehandle, -400 * (LONG)strlen( sillytext ), FILE_END ) != -1, "should be able to seek\n" );
492 
493  bytes_read = _hread( filehandle, buffer, 1);
494  ok( 1 == bytes_read, "file read size error\n" );
495  ok( buffer[0] == sillytext[0], "_llseek error, it got lost seeking\n" );
496  ok( _llseek( filehandle, 1000000, FILE_END ) != -1, "should be able to seek past file; poor, poor Windows programmers\n" );
497  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
498 
499  ret = DeleteFileA( filename );
500  ok( ret, "DeleteFile failed (%d)\n", GetLastError( ) );
501 }
LONG WINAPI _llseek(HFILE hFile, LONG lOffset, int iOrigin)
Definition: lfile.c:149
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
HFILE WINAPI _lcreat(LPCSTR lpPathName, int iAttribute)
Definition: lfile.c:116
#define FILE_CURRENT
Definition: winbase.h:113
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLuint buffer
Definition: glext.h:5915
long WINAPI _hread(HFILE hFile, LPVOID lpBuffer, long lBytes)
Definition: lfile.c:20
const char * filename
Definition: ioapi.h:135
int32_t INT
Definition: typedefs.h:56
int WINAPI _lclose(HFILE hFile)
Definition: lfile.c:138
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define HFILE_ERROR
Definition: winbase.h:111
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
long WINAPI _hwrite(HFILE hFile, LPCSTR lpBuffer, long lBytes)
Definition: lfile.c:41
#define ok(value,...)
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define FILE_END
Definition: winbase.h:114
int ret
#define FILE_BEGIN
Definition: winbase.h:112
int HFILE
Definition: windef.h:283
static const char sillytext[]
Definition: file.c:52

Referenced by START_TEST().

◆ test__lread()

static void test__lread ( void  )
static

Definition at line 544 of file file.c.

545 {
546  HFILE filehandle;
547  char buffer[10000];
548  UINT bytes_read;
549  UINT bytes_wanted;
550  UINT i;
551  BOOL ret;
552 
553  filehandle = _lcreat( filename, 0 );
554  if (filehandle == HFILE_ERROR)
555  {
556  ok(0,"couldn't create file \"%s\" (err=%d)\n",filename,GetLastError());
557  return;
558  }
559 
560  ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
561 
562  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
563 
564  filehandle = _lopen( filename, OF_READ );
565 
566  ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%d)\n", filename, GetLastError());
567 
568  bytes_read = _lread( filehandle, buffer, 2 * strlen( sillytext ) );
569 
570  ok( lstrlenA( sillytext ) == bytes_read, "file read size error\n" );
571 
572  for (bytes_wanted = 0; bytes_wanted < strlen( sillytext ); bytes_wanted++)
573  {
574  ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
575  ok( _lread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value\n" );
576  for (i = 0; i < bytes_wanted; i++)
577  {
578  ok( buffer[i] == sillytext[i], "that's not what's written\n" );
579  }
580  }
581 
582  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
583 
584  ret = DeleteFileA( filename );
585  ok( ret, "DeleteFile failed (%d)\n", GetLastError( ) );
586 }
#define OF_READ
Definition: winbase.h:116
LONG WINAPI _llseek(HFILE hFile, LONG lOffset, int iOrigin)
Definition: lfile.c:149
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
HFILE WINAPI _lcreat(LPCSTR lpPathName, int iAttribute)
Definition: lfile.c:116
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLuint buffer
Definition: glext.h:5915
const char * filename
Definition: ioapi.h:135
int WINAPI _lclose(HFILE hFile)
Definition: lfile.c:138
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define HFILE_ERROR
Definition: winbase.h:111
unsigned int BOOL
Definition: ntddk_ex.h:94
long WINAPI _hwrite(HFILE hFile, LPCSTR lpBuffer, long lBytes)
Definition: lfile.c:41
UINT WINAPI _lread(_In_ HFILE hFile, _Out_writes_bytes_to_(uBytes, return) LPVOID lpBuffer, _In_ UINT uBytes)
#define ok(value,...)
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
HFILE WINAPI _lopen(LPCSTR lpPathName, int iReadWrite)
Definition: lfile.c:70
int ret
#define FILE_BEGIN
Definition: winbase.h:112
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
unsigned int UINT
Definition: ndis.h:50
int HFILE
Definition: windef.h:283
static const char sillytext[]
Definition: file.c:52

Referenced by START_TEST().

◆ test__lwrite()

static void test__lwrite ( void  )
static

Definition at line 589 of file file.c.

590 {
591  HFILE filehandle;
592  char buffer[10000];
593  UINT bytes_read;
594  UINT bytes_written;
595  UINT blocks;
596  INT i;
597  char *contents;
598  HLOCAL memory_object;
599  char checksum[1];
600  BOOL ret;
601 
602  filehandle = _lcreat( filename, 0 );
603  if (filehandle == HFILE_ERROR)
604  {
605  ok(0,"couldn't create file \"%s\" (err=%d)\n",filename,GetLastError());
606  return;
607  }
608 
609  ok( HFILE_ERROR != _lwrite( filehandle, "", 0 ), "_hwrite complains\n" );
610 
611  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
612 
613  filehandle = _lopen( filename, OF_READ );
614 
615  bytes_read = _hread( filehandle, buffer, 1);
616 
617  ok( 0 == bytes_read, "file read size error\n" );
618 
619  ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
620 
621  filehandle = _lopen( filename, OF_READWRITE );
622 
623  bytes_written = 0;
624  checksum[0] = '\0';
625  srand( (unsigned)time( NULL ) );
626  for (blocks = 0; blocks < 100; blocks++)
627  {
628  for (i = 0; i < (INT)sizeof( buffer ); i++)
629  {
630  buffer[i] = rand( );
631  checksum[0] = checksum[0] + buffer[i];
632  }
633  ok( HFILE_ERROR != _lwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains\n" );
634  bytes_written = bytes_written + sizeof( buffer );
635  }
636 
637  ok( HFILE_ERROR != _lwrite( filehandle, checksum, 1 ), "_hwrite complains\n" );
638  bytes_written++;
639 
640  ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
641 
642  memory_object = LocalAlloc( LPTR, bytes_written );
643 
644  ok( 0 != memory_object, "LocalAlloc fails, could be out of memory\n" );
645 
646  contents = LocalLock( memory_object );
647  ok( NULL != contents, "LocalLock whines\n" );
648 
649  filehandle = _lopen( filename, OF_READ );
650 
651  contents = LocalLock( memory_object );
652  ok( NULL != contents, "LocalLock whines\n" );
653 
654  ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length\n" );
655 
656  checksum[0] = '\0';
657  i = 0;
658  do
659  {
660  checksum[0] += contents[i];
661  i++;
662  }
663  while (i < bytes_written - 1);
664 
665  ok( checksum[0] == contents[i], "stored checksum differ from computed checksum\n" );
666 
667  ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
668 
669  ret = DeleteFileA( filename );
670  ok( ret, "DeleteFile failed (%d)\n", GetLastError( ) );
671 
672  LocalFree( contents );
673 }
#define OF_READ
Definition: winbase.h:116
HFILE WINAPI _lcreat(LPCSTR lpPathName, int iAttribute)
Definition: lfile.c:116
#define INT
Definition: polytest.cpp:20
void __cdecl srand(_In_ unsigned int _Seed)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLuint buffer
Definition: glext.h:5915
long WINAPI _hread(HFILE hFile, LPVOID lpBuffer, long lBytes)
Definition: lfile.c:20
__u16 time
Definition: mkdosfs.c:366
const char * filename
Definition: ioapi.h:135
int32_t INT
Definition: typedefs.h:56
int WINAPI _lclose(HFILE hFile)
Definition: lfile.c:138
static HANDLE PIO_APC_ROUTINE void PIO_STATUS_BLOCK void * buffer
Definition: file.c:88
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define HFILE_ERROR
Definition: winbase.h:111
unsigned int BOOL
Definition: ntddk_ex.h:94
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
static int blocks
Definition: mkdosfs.c:527
UINT WINAPI _lwrite(_In_ HFILE hFile, _In_reads_bytes_(uBytes) LPCCH lpBuffer, _In_ UINT uBytes)
HFILE WINAPI _lopen(LPCSTR lpPathName, int iReadWrite)
Definition: lfile.c:70
int ret
static cab_ULONG checksum(const cab_UBYTE *data, cab_UWORD bytes, cab_ULONG csum)
Definition: fdi.c:353
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
LPVOID NTAPI LocalLock(HLOCAL hMem)
Definition: heapmem.c:1599
#define OF_READWRITE
Definition: winbase.h:117
unsigned int UINT
Definition: ndis.h:50
#define LPTR
Definition: winbase.h:362
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
int HFILE
Definition: windef.h:283

Referenced by START_TEST().

◆ test_async_file_errors()

static void test_async_file_errors ( void  )
static

Definition at line 3081 of file file.c.

3082 {
3083  char szFile[MAX_PATH];
3084  HANDLE hSem = CreateSemaphoreW(NULL, 1, 1, NULL);
3085  HANDLE hFile;
3086  LPVOID lpBuffer = HeapAlloc(GetProcessHeap(), 0, 4096);
3087  OVERLAPPED ovl;
3088  S(U(ovl)).Offset = 0;
3089  S(U(ovl)).OffsetHigh = 0;
3090  ovl.hEvent = hSem;
3091  completion_count = 0;
3092  szFile[0] = '\0';
3093  GetWindowsDirectoryA(szFile, sizeof(szFile)/sizeof(szFile[0])-1-strlen("\\win.ini"));
3094  strcat(szFile, "\\win.ini");
3097  if (hFile == INVALID_HANDLE_VALUE) /* win9x doesn't like FILE_SHARE_DELETE */
3100  ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA(%s ...) failed\n", szFile);
3101  while (TRUE)
3102  {
3103  BOOL res;
3104  DWORD count;
3106  ;
3107  res = ReadFileEx(hFile, lpBuffer, 4096, &ovl, FileIOComplete);
3108  /*printf("Offset = %ld, result = %s\n", ovl.Offset, res ? "TRUE" : "FALSE");*/
3109  if (!res)
3110  break;
3111  if (!GetOverlappedResult(hFile, &ovl, &count, FALSE))
3112  break;
3113  S(U(ovl)).Offset += count;
3114  /* i/o completion routine only called if ReadFileEx returned success.
3115  * we only care about violations of this rule so undo what should have
3116  * been done */
3117  completion_count--;
3118  }
3119  ok(completion_count == 0, "completion routine should only be called when ReadFileEx succeeds (this rule was violated %d times)\n", completion_count);
3120  /*printf("Error = %ld\n", GetLastError());*/
3122 }
DWORD WINAPI WaitForSingleObjectEx(IN HANDLE hHandle, IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:94
#define TRUE
Definition: types.h:120
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreW(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes OPTIONAL, IN LONG lInitialCount, IN LONG lMaximumCount, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:444
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:204
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define U(x)
Definition: wordpad.c:44
#define S(x)
Definition: test.h:190
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
BOOL WINAPI ReadFileEx(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead OPTIONAL, IN LPOVERLAPPED lpOverlapped, IN LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
Definition: rw.c:299
unsigned int BOOL
Definition: ntddk_ex.h:94
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#define ok(value,...)
HANDLE hEvent
Definition: winbase.h:792
smooth NULL
Definition: ftsmooth.c:416
#define WAIT_IO_COMPLETION
Definition: winbase.h:392
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static void CALLBACK FileIOComplete(DWORD dwError, DWORD dwBytes, LPOVERLAPPED ovl)
Definition: file.c:3074
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define OPEN_ALWAYS
Definition: disk.h:70
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
UINT WINAPI GetWindowsDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2336
GLuint res
Definition: glext.h:9613
static int completion_count
Definition: file.c:3072
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
#define INFINITE
Definition: serial.h:102
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by START_TEST().

◆ test_CopyFile2()

static void test_CopyFile2 ( void  )
static

Definition at line 882 of file file.c.

883 {
884  static const WCHAR doesntexistW[] = {'d','o','e','s','n','t','e','x','i','s','t',0};
885  static const WCHAR prefix[] = {'p','f','x',0};
887  COPYFILE2_EXTENDED_PARAMETERS params;
888  HANDLE hfile, hmapfile;
889  FILETIME ft1, ft2;
890  DWORD ret, len;
891  char buf[10];
892  HRESULT hr;
893 
894  if (!pCopyFile2)
895  {
896  skip("CopyFile2 is not available\n");
897  return;
898  }
899 
901  ok(ret != 0, "GetTempPathW error %d\n", GetLastError());
902  ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
903 
904  ret = GetTempFileNameW(temp_path, prefix, 0, source);
905  ok(ret != 0, "GetTempFileNameW error %d\n", GetLastError());
906 
907  ret = GetTempFileNameW(temp_path, prefix, 0, dest);
908  ok(ret != 0, "GetTempFileNameW error %d\n", GetLastError());
909 
910  /* fail if exists */
911  memset(&params, 0, sizeof(params));
912  params.dwSize = sizeof(params);
913  params.dwCopyFlags = COPY_FILE_FAIL_IF_EXISTS;
914 
915  SetLastError(0xdeadbeef);
916  hr = pCopyFile2(source, dest, &params);
917  ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "CopyFile2: unexpected error 0x%08x\n", hr);
918  ok(GetLastError() == ERROR_FILE_EXISTS, "CopyFile2: last error %d\n", GetLastError());
919 
920  /* don't fail if exists */
921  params.dwSize = sizeof(params);
922  params.dwCopyFlags = 0;
923 
924  hr = pCopyFile2(source, dest, &params);
925  ok(hr == S_OK, "CopyFile2: error 0x%08x\n", hr);
926 
927  /* copying a file to itself must fail */
928  params.dwSize = sizeof(params);
929  params.dwCopyFlags = 0;
930 
931  SetLastError(0xdeadbeef);
932  hr = pCopyFile2(source, source, &params);
933  ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "CopyFile2: copying a file to itself didn't fail, 0x%08x\n", hr);
934  ok(GetLastError() == ERROR_SHARING_VIOLATION, "CopyFile2: last error %d\n", GetLastError());
935 
936  /* make the source have not zero size */
937  hfile = CreateFileW(source, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 );
938  ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file\n");
939  ret = WriteFile(hfile, prefix, sizeof(prefix), &len, NULL );
940  ok(ret && len == sizeof(prefix), "WriteFile error %d\n", GetLastError());
941  ok(GetFileSize(hfile, NULL) == sizeof(prefix), "source file has wrong size\n");
942 
943  /* get the file time and change it to prove the difference */
944  ret = GetFileTime(hfile, NULL, NULL, &ft1);
945  ok(ret, "GetFileTime error %d\n", GetLastError());
946  ft1.dwLowDateTime -= 600000000; /* 60 second */
947  ret = SetFileTime(hfile, NULL, NULL, &ft1);
948  ok(ret, "SetFileTime error %d\n", GetLastError());
949  GetFileTime(hfile, NULL, NULL, &ft1); /* get the actual time back */
950  CloseHandle(hfile);
951 
952  ret = GetTempFileNameW(temp_path, prefix, 0, dest);
953  ok(ret != 0, "GetTempFileNameA error %d\n", GetLastError());
954 
955  params.dwSize = sizeof(params);
956  params.dwCopyFlags = COPY_FILE_FAIL_IF_EXISTS;
957 
958  SetLastError(0xdeadbeef);
959  hr = pCopyFile2(source, dest, &params);
960  ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "CopyFile2: unexpected error 0x%08x\n", hr);
961  ok(GetLastError() == ERROR_FILE_EXISTS, "CopyFile2: last error %d\n", GetLastError());
962 
963  params.dwSize = sizeof(params);
964  params.dwCopyFlags = 0;
965  hr = pCopyFile2(source, dest, &params);
966  ok(ret, "CopyFile2: error 0x%08x\n", hr);
967 
968  /* copying from a read-locked source fails */
970  ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %d\n", GetLastError());
971 
972  params.dwSize = sizeof(params);
973  params.dwCopyFlags = 0;
974  SetLastError(0xdeadbeef);
975  hr = pCopyFile2(source, dest, &params);
976  ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "CopyFile2: unexpected error 0x%08x\n", hr);
977  ok(GetLastError() == ERROR_SHARING_VIOLATION, "CopyFile2: last error %d\n", GetLastError());
978 
979  /* in addition, the source is opened before the destination */
980  params.dwSize = sizeof(params);
981  params.dwCopyFlags = 0;
982  SetLastError(0xdeadbeef);
983  hr = pCopyFile2(doesntexistW, dest, &params);
984  ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
985  ok(GetLastError() == ERROR_FILE_NOT_FOUND, "CopyFile2: last error %d\n", GetLastError());
986  CloseHandle(hfile);
987 
988  /* copying from a r+w opened, r shared source succeeds */
990  ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %d\n", GetLastError());
991 
992  params.dwSize = sizeof(params);
993  params.dwCopyFlags = 0;
994  hr = pCopyFile2(source, dest, &params);
995  ok(hr == S_OK, "failed 0x%08x\n", hr);
996  CloseHandle(hfile);
997 
998  /* copying from a delete-locked source mostly succeeds */
1000  ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %d\n", GetLastError());
1001 
1002  params.dwSize = sizeof(params);
1003  params.dwCopyFlags = 0;
1004  hr = pCopyFile2(source, dest, &params);
1005  ok(hr == S_OK, "failed 0x%08x\n", hr);
1006  CloseHandle(hfile);
1007 
1008  /* copying to a write-locked destination fails */
1010  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %d\n", GetLastError());
1011 
1012  params.dwSize = sizeof(params);
1013  params.dwCopyFlags = 0;
1014  SetLastError(0xdeadbeef);
1015  hr = pCopyFile2(source, dest, FALSE);
1016  ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "CopyFile2: unexpected error 0x%08x\n", hr);
1017  ok(GetLastError() == ERROR_SHARING_VIOLATION, "CopyFile2: last error %d\n", GetLastError());
1018  CloseHandle(hfile);
1019 
1020  /* copying to a r+w opened, w shared destination mostly succeeds */
1022  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %d\n", GetLastError());
1023 
1024  params.dwSize = sizeof(params);
1025  params.dwCopyFlags = 0;
1026  hr = pCopyFile2(source, dest, FALSE);
1027  ok(hr == S_OK, "got 0x%08x\n", hr);
1028  CloseHandle(hfile);
1029 
1030  /* copying to a delete-locked destination fails, even when the destination is delete-shared */
1032  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %d\n", GetLastError());
1033 
1034  params.dwSize = sizeof(params);
1035  params.dwCopyFlags = 0;
1036  SetLastError(0xdeadbeef);
1037  hr = pCopyFile2(source, dest, &params);
1038  ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "CopyFile2: unexpected error 0x%08x\n", hr);
1039  ok(GetLastError() == ERROR_SHARING_VIOLATION, "CopyFile2: last error %d\n", GetLastError());
1040  CloseHandle(hfile);
1041 
1042  /* copy to a file that's opened the way Wine opens the source */
1044  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %d\n", GetLastError());
1045 
1046  params.dwSize = sizeof(params);
1047  params.dwCopyFlags = 0;
1048  hr = pCopyFile2(source, dest, &params);
1049  ok(hr == S_OK, "got 0x%08x\n", hr);
1050  CloseHandle(hfile);
1051 
1052  /* make sure that destination has correct size */
1054  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file\n");
1055  ret = GetFileSize(hfile, NULL);
1056  ok(ret == sizeof(prefix), "destination file has wrong size %d\n", ret);
1057 
1058  /* make sure that destination has the same filetime */
1059  ret = GetFileTime(hfile, NULL, NULL, &ft2);
1060  ok(ret, "GetFileTime error %d\n", GetLastError());
1061  ok(CompareFileTime(&ft1, &ft2) == 0, "destination file has wrong filetime\n");
1062 
1063  params.dwSize = sizeof(params);
1064  params.dwCopyFlags = 0;
1065  SetLastError(0xdeadbeef);
1066  hr = pCopyFile2(source, dest, &params);
1067  ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "CopyFile2: unexpected error 0x%08x\n", hr);
1068  ok(GetLastError() == ERROR_SHARING_VIOLATION, "CopyFile2: last error %d\n", GetLastError());
1069 
1070  /* make sure that destination still has correct size */
1071  ret = GetFileSize(hfile, NULL);
1072  ok(ret == sizeof(prefix), "destination file has wrong size %d\n", ret);
1073  ret = ReadFile(hfile, buf, sizeof(buf), &len, NULL);
1074  ok(ret && len == sizeof(prefix), "ReadFile: error %d\n", GetLastError());
1075  ok(!memcmp(prefix, buf, sizeof(prefix)), "buffer contents mismatch\n");
1076 
1077  /* check error on copying over a mapped file that was opened with FILE_SHARE_READ */
1078  hmapfile = CreateFileMappingW(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
1079  ok(hmapfile != NULL, "CreateFileMapping: error %d\n", GetLastError());
1080 
1081  params.dwSize = sizeof(params);
1082  params.dwCopyFlags = 0;
1083  SetLastError(0xdeadbeef);
1084  hr = pCopyFile2(source, dest, &params);
1085  ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "CopyFile2: unexpected error 0x%08x\n", hr);
1086  ok(GetLastError() == ERROR_SHARING_VIOLATION, "CopyFile2: last error %d\n", GetLastError());
1087 
1088  CloseHandle(hmapfile);
1089  CloseHandle(hfile);
1090 
1092  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file\n");
1093 
1094  /* check error on copying over a mapped file that was opened with FILE_SHARE_WRITE */
1095  hmapfile = CreateFileMappingW(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
1096  ok(hmapfile != NULL, "CreateFileMapping: error %d\n", GetLastError());
1097 
1098  params.dwSize = sizeof(params);
1099  params.dwCopyFlags = 0;
1100  hr = pCopyFile2(source, dest, &params);
1101  ok(hr == HRESULT_FROM_WIN32(ERROR_USER_MAPPED_FILE), "CopyFile2: unexpected error 0x%08x\n", hr);
1102  ok(GetLastError() == ERROR_USER_MAPPED_FILE, "CopyFile2: last error %d\n", GetLastError());
1103 
1104  CloseHandle(hmapfile);
1105  CloseHandle(hfile);
1106 
1108  DeleteFileW(dest);
1109 }
#define ERROR_USER_MAPPED_FILE
Definition: winerror.h:727
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define CloseHandle
Definition: compat.h:398
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
HRESULT hr
Definition: shlfolder.c:183
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
BOOL WINAPI SetFileTime(IN HANDLE hFile, CONST FILETIME *lpCreationTime OPTIONAL, CONST FILETIME *lpLastAccessTime OPTIONAL, CONST FILETIME *lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:1098
#define SEC_COMMIT
Definition: mmtypes.h:99
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2079
GLenum const GLfloat * params
Definition: glext.h:5645
#define COPY_FILE_FAIL_IF_EXISTS
Definition: winbase.h:205
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ok(value,...)
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define OPEN_EXISTING
Definition: compat.h:426
LONG WINAPI CompareFileTime(IN CONST FILETIME *lpFileTime1, IN CONST FILETIME *lpFileTime2)
Definition: time.c:106
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:401
#define MAX_PATH
Definition: compat.h:26
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define SetLastError(x)
Definition: compat.h:409
int ret
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
GLenum GLsizei len
Definition: glext.h:6722
#define GENERIC_READ
Definition: compat.h:124
#define ERROR_SHARING_VIOLATION
Definition: winerror.h:135
#define S_OK
Definition: intsafe.h:59
#define PAGE_READONLY
Definition: compat.h:127
#define CreateFileW
Definition: compat.h:400
#define skip(...)
static char * dest
Definition: rtl.c:135
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
#define memset(x, y, z)
Definition: compat.h:39
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:1046
DWORD dwLowDateTime
Definition: mapidefs.h:65
#define DELETE
Definition: nt_native.h:57
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

Referenced by START_TEST().

◆ test_CopyFileA()

static void test_CopyFileA ( void  )
static

Definition at line 675 of file file.c.

676 {
677  char temp_path[MAX_PATH];
678  char source[MAX_PATH], dest[MAX_PATH];
679  static const char prefix[] = "pfx";
680  HANDLE hfile;
681  HANDLE hmapfile;
682  FILETIME ft1, ft2;
683  char buf[10];
684  DWORD ret;
685  BOOL retok;
686 
688  ok(ret != 0, "GetTempPathA error %d\n", GetLastError());
689  ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
690 
691  ret = GetTempFileNameA(temp_path, prefix, 0, source);
692  ok(ret != 0, "GetTempFileNameA error %d\n", GetLastError());
693 
694  /* copying a file to itself must fail */
695  retok = CopyFileA(source, source, FALSE);
696  ok( !retok && (GetLastError() == ERROR_SHARING_VIOLATION || broken(GetLastError() == ERROR_FILE_EXISTS) /* Win 9x */),
697  "copying a file to itself didn't fail (ret=%d, err=%d)\n", retok, GetLastError());
698 
699  /* make the source have not zero size */
700  hfile = CreateFileA(source, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 );
701  ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file\n");
702  retok = WriteFile(hfile, prefix, sizeof(prefix), &ret, NULL );
703  ok( retok && ret == sizeof(prefix),
704  "WriteFile error %d\n", GetLastError());
705  ok(GetFileSize(hfile, NULL) == sizeof(prefix), "source file has wrong size\n");
706  /* get the file time and change it to prove the difference */
707  ret = GetFileTime(hfile, NULL, NULL, &ft1);
708  ok( ret, "GetFileTime error %d\n", GetLastError());
709  ft1.dwLowDateTime -= 600000000; /* 60 second */
710  ret = SetFileTime(hfile, NULL, NULL, &ft1);
711  ok( ret, "SetFileTime error %d\n", GetLastError());
712  GetFileTime(hfile, NULL, NULL, &ft1); /* get the actual time back */
713  CloseHandle(hfile);
714 
715  ret = GetTempFileNameA(temp_path, prefix, 0, dest);
716  ok(ret != 0, "GetTempFileNameA error %d\n", GetLastError());
717 
718  SetLastError(0xdeadbeef);
721  "CopyFileA: unexpected error %d\n", GetLastError());
722 
724  ok(ret, "CopyFileA: error %d\n", GetLastError());
725 
726  /* copying from a read-locked source fails */
728  ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %d\n", GetLastError());
729  retok = CopyFileA(source, dest, FALSE);
730  ok(!retok && GetLastError() == ERROR_SHARING_VIOLATION,
731  "copying from a read-locked file succeeded when it shouldn't have\n");
732  /* in addition, the source is opened before the destination */
733  retok = CopyFileA("25f99d3b-4ba4-4f66-88f5-2906886993cc", dest, FALSE);
734  ok(!retok && GetLastError() == ERROR_FILE_NOT_FOUND,
735  "copying from a file that doesn't exist failed in an unexpected way (ret=%d, err=%d)\n", retok, GetLastError());
736  CloseHandle(hfile);
737 
738  /* copying from a r+w opened, r shared source succeeds */
740  ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %d\n", GetLastError());
741  retok = CopyFileA(source, dest, FALSE);
742  ok(retok,
743  "copying from an r+w opened and r shared file failed (ret=%d, err=%d)\n", retok, GetLastError());
744  CloseHandle(hfile);
745 
746  /* copying from a delete-locked source mostly succeeds */
748  ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %d\n", GetLastError());
749  retok = CopyFileA(source, dest, FALSE);
750  ok(retok || broken(!retok && GetLastError() == ERROR_SHARING_VIOLATION) /* NT, 2000, XP */,
751  "copying from a delete-locked file failed (ret=%d, err=%d)\n", retok, GetLastError());
752  CloseHandle(hfile);
753 
754  /* copying to a write-locked destination fails */
756  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %d\n", GetLastError());
757  retok = CopyFileA(source, dest, FALSE);
758  ok(!retok && GetLastError() == ERROR_SHARING_VIOLATION,
759  "copying to a write-locked file didn't fail (ret=%d, err=%d)\n", retok, GetLastError());
760  CloseHandle(hfile);
761 
762  /* copying to a r+w opened, w shared destination mostly succeeds */
764  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %d\n", GetLastError());
765  retok = CopyFileA(source, dest, FALSE);
766  ok(retok || broken(!retok && GetLastError() == ERROR_SHARING_VIOLATION) /* Win 9x */,
767  "copying to a r+w opened and w shared file failed (ret=%d, err=%d)\n", retok, GetLastError());
768  CloseHandle(hfile);
769 
770  /* copying to a delete-locked destination fails, even when the destination is delete-shared */
772  ok(hfile != INVALID_HANDLE_VALUE || broken(GetLastError() == ERROR_INVALID_PARAMETER) /* Win 9x */,
773  "failed to open destination file, error %d\n", GetLastError());
774  if (hfile != INVALID_HANDLE_VALUE)
775  {
776  retok = CopyFileA(source, dest, FALSE);
777  ok(!retok && GetLastError() == ERROR_SHARING_VIOLATION,
778  "copying to a delete-locked shared file didn't fail (ret=%d, err=%d)\n", retok, GetLastError());
779  CloseHandle(hfile);
780  }
781 
782  /* copy to a file that's opened the way Wine opens the source */
784  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %d\n", GetLastError());
785  retok = CopyFileA(source, dest, FALSE);
786  ok(retok || broken(GetLastError() == ERROR_SHARING_VIOLATION) /* Win 9x */,
787  "copying to a file opened the way Wine opens the source failed (ret=%d, err=%d)\n", retok, GetLastError());
788  CloseHandle(hfile);
789 
790  /* make sure that destination has correct size */
792  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file\n");
793  ret = GetFileSize(hfile, NULL);
794  ok(ret == sizeof(prefix), "destination file has wrong size %d\n", ret);
795 
796  /* make sure that destination has the same filetime */
797  ret = GetFileTime(hfile, NULL, NULL, &ft2);
798  ok( ret, "GetFileTime error %d\n", GetLastError());
799  ok(CompareFileTime(&ft1, &ft2) == 0, "destination file has wrong filetime\n");
800 
801  SetLastError(0xdeadbeef);
804  "CopyFileA: ret = %d, unexpected error %d\n", ret, GetLastError());
805 
806  /* make sure that destination still has correct size */
807  ret = GetFileSize(hfile, NULL);
808  ok(ret == sizeof(prefix), "destination file has wrong size %d\n", ret);
809  retok = ReadFile(hfile, buf, sizeof(buf), &ret, NULL);
810  ok( retok && ret == sizeof(prefix),
811  "ReadFile: error %d\n", GetLastError());
812  ok(!memcmp(prefix, buf, sizeof(prefix)), "buffer contents mismatch\n");
813 
814  /* check error on copying over a mapped file that was opened with FILE_SHARE_READ */
815  hmapfile = CreateFileMappingW(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
816  ok(hmapfile != NULL, "CreateFileMapping: error %d\n", GetLastError());
817 
820  "CopyFileA with mapped dest file: expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
821 
822  CloseHandle(hmapfile);
823  CloseHandle(hfile);
824 
826  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file\n");
827 
828  /* check error on copying over a mapped file that was opened with FILE_SHARE_WRITE */
829  hmapfile = CreateFileMappingW(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
830  ok(hmapfile != NULL, "CreateFileMapping: error %d\n", GetLastError());
831 
833  ok(!ret, "CopyFileA: expected failure\n");
835  broken(GetLastError() == ERROR_SHARING_VIOLATION), /* Win9x */
836  "CopyFileA with mapped dest file: expected ERROR_USER_MAPPED_FILE, got %d\n", GetLastError());
837 
838  CloseHandle(hmapfile);
839  CloseHandle(hfile);
840 
842  ok(ret, "DeleteFileA: error %d\n", GetLastError());
843  ret = DeleteFileA(dest);
844  ok(ret, "DeleteFileA: error %d\n", GetLastError());
845 }
#define ERROR_USER_MAPPED_FILE
Definition: winerror.h:727
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI CopyFileA(IN LPCSTR lpExistingFileName, IN LPCSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:404
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
BOOL WINAPI SetFileTime(IN HANDLE hFile, CONST FILETIME *lpCreationTime OPTIONAL, CONST FILETIME *lpLastAccessTime OPTIONAL, CONST FILETIME *lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:1098
#define SEC_COMMIT
Definition: mmtypes.h:99
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define OPEN_EXISTING
Definition: compat.h:426
LONG WINAPI CompareFileTime(IN CONST FILETIME *lpFileTime1, IN CONST FILETIME *lpFileTime2)
Definition: time.c:106
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:401
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define SetLastError(x)
Definition: compat.h:409
int ret
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define GENERIC_READ
Definition: compat.h:124
#define ERROR_SHARING_VIOLATION
Definition: winerror.h:135
#define broken(x)
Definition: _sntprintf.h:21
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
#define PAGE_READONLY
Definition: compat.h:127
static char * dest
Definition: rtl.c:135
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:1046
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
DWORD dwLowDateTime
Definition: mapidefs.h:65
#define DELETE
Definition: nt_native.h:57
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

Referenced by START_TEST().

◆ test_CopyFileEx()

static void test_CopyFileEx ( void  )
static

Definition at line 1120 of file file.c.

1121 {
1122  char temp_path[MAX_PATH];
1123  char source[MAX_PATH], dest[MAX_PATH];
1124  static const char prefix[] = "pfx";
1125  HANDLE hfile;
1126  DWORD ret;
1127  BOOL retok;
1128 
1130  ok(ret != 0, "GetTempPathA error %d\n", GetLastError());
1131  ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
1132 
1133  ret = GetTempFileNameA(temp_path, prefix, 0, source);
1134  ok(ret != 0, "GetTempFileNameA error %d\n", GetLastError());
1135 
1136  ret = GetTempFileNameA(temp_path, prefix, 0, dest);
1137  ok(ret != 0, "GetTempFileNameA error %d\n", GetLastError());
1138 
1140  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %d\n", GetLastError());
1141  SetLastError(0xdeadbeef);
1142  retok = CopyFileExA(source, dest, copy_progress_cb, hfile, NULL, 0);
1143  ok(!retok, "CopyFileExA unexpectedly succeeded\n");
1144  ok(GetLastError() == ERROR_REQUEST_ABORTED, "expected ERROR_REQUEST_ABORTED, got %d\n", GetLastError());
1145  ok(GetFileAttributesA(dest) != INVALID_FILE_ATTRIBUTES, "file was deleted\n");
1146 
1148  NULL, OPEN_EXISTING, 0, 0);
1149  ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %d\n", GetLastError());
1150  SetLastError(0xdeadbeef);
1151  retok = CopyFileExA(source, dest, copy_progress_cb, hfile, NULL, 0);
1152  ok(!retok, "CopyFileExA unexpectedly succeeded\n");
1153  ok(GetLastError() == ERROR_REQUEST_ABORTED, "expected ERROR_REQUEST_ABORTED, got %d\n", GetLastError());
1154  ok(GetFileAttributesA(dest) == INVALID_FILE_ATTRIBUTES, "file was not deleted\n");
1155 
1156  ret = DeleteFileA(source);
1157  ok(ret, "DeleteFileA failed with error %d\n", GetLastError());
1158  ret = DeleteFileA(dest);
1159  ok(!ret, "DeleteFileA unexpectedly succeeded\n");
1160 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:786
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define OPEN_EXISTING
Definition: compat.h:426
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
int ret
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define GENERIC_READ
Definition: compat.h:124
BOOL WINAPI CopyFileExA(IN LPCSTR lpExistingFileName, IN LPCSTR lpNewFileName, IN LPPROGRESS_ROUTINE lpProgressRoutine OPTIONAL, IN LPVOID lpData OPTIONAL, IN LPBOOL pbCancel OPTIONAL, IN DWORD dwCopyFlags)
Definition: copy.c:366
#define ERROR_REQUEST_ABORTED
Definition: winerror.h:738
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
static DWORD WINAPI copy_progress_cb(LARGE_INTEGER total_size, LARGE_INTEGER total_transferred, LARGE_INTEGER stream_size, LARGE_INTEGER stream_transferred, DWORD stream, DWORD reason, HANDLE source, HANDLE dest, LPVOID userdata)
Definition: file.c:1111
static char * dest
Definition: rtl.c:135
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

Referenced by START_TEST().

◆ test_CopyFileW()

static void test_CopyFileW ( void  )
static

Definition at line 847 of file file.c.

848 {
851  static const WCHAR prefix[] = {'p','f','x',0};
852  DWORD ret;
853 
856  {
857  win_skip("GetTempPathW is not available\n");
858  return;
859  }
860  ok(ret != 0, "GetTempPathW error %d\n", GetLastError());
861  ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
862 
863  ret = GetTempFileNameW(temp_path, prefix, 0, source);
864  ok(ret != 0, "GetTempFileNameW error %d\n", GetLastError());
865 
866  ret = GetTempFileNameW(temp_path, prefix, 0, dest);
867  ok(ret != 0, "GetTempFileNameW error %d\n", GetLastError());
868 
871  "CopyFileW: unexpected error %d\n", GetLastError());
872 
874  ok(ret, "CopyFileW: error %d\n", GetLastError());
875 
877  ok(ret, "DeleteFileW: error %d\n", GetLastError());
878  ret = DeleteFileW(dest);
879  ok(ret, "DeleteFileW: error %d\n", GetLastError());
880 }
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define TRUE
Definition: types.h:120
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2079
#define ok(value,...)
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI CopyFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:439
#define MAX_PATH
Definition: compat.h:26
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
static char * dest
Definition: rtl.c:135
#define win_skip
Definition: test.h:141
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

Referenced by START_TEST().

◆ test_CreateFile()

static void test_CreateFile ( void  )
static

Definition at line 3890 of file file.c.

3891 {
3892  static const struct test_data
3893  {
3894  DWORD disposition, access, error, clean_up;
3895  } td[] =
3896  {
3897  /* 0 */ { 0, 0, ERROR_INVALID_PARAMETER, 0 },
3898  /* 1 */ { 0, GENERIC_READ, ERROR_INVALID_PARAMETER, 0 },
3900  /* 3 */ { CREATE_NEW, 0, ERROR_FILE_EXISTS, 1 },
3901  /* 4 */ { CREATE_NEW, 0, 0, 1 },
3902  /* 5 */ { CREATE_NEW, GENERIC_READ, 0, 1 },
3903  /* 6 */ { CREATE_NEW, GENERIC_WRITE, 0, 1 },
3904  /* 7 */ { CREATE_NEW, GENERIC_READ|GENERIC_WRITE, 0, 0 },
3905  /* 8 */ { CREATE_ALWAYS, 0, 0, 0 },
3906  /* 9 */ { CREATE_ALWAYS, GENERIC_READ, 0, 0 },
3907  /* 10*/ { CREATE_ALWAYS, GENERIC_WRITE, 0, 0 },
3908  /* 11*/ { CREATE_ALWAYS, GENERIC_READ|GENERIC_WRITE, 0, 1 },
3909  /* 12*/ { OPEN_EXISTING, 0, ERROR_FILE_NOT_FOUND, 0 },
3910  /* 13*/ { CREATE_ALWAYS, 0, 0, 0 },
3911  /* 14*/ { OPEN_EXISTING, 0, 0, 0 },
3912  /* 15*/ { OPEN_EXISTING, GENERIC_READ, 0, 0 },
3913  /* 16*/ { OPEN_EXISTING, GENERIC_WRITE, 0, 0 },
3914  /* 17*/ { OPEN_EXISTING, GENERIC_READ|GENERIC_WRITE, 0, 1 },
3915  /* 18*/ { OPEN_ALWAYS, 0, 0, 0 },
3916  /* 19*/ { OPEN_ALWAYS, GENERIC_READ, 0, 0 },
3917  /* 20*/ { OPEN_ALWAYS, GENERIC_WRITE, 0, 0 },
3918  /* 21*/ { OPEN_ALWAYS, GENERIC_READ|GENERIC_WRITE, 0, 0 },
3919  /* 22*/ { TRUNCATE_EXISTING, 0, ERROR_INVALID_PARAMETER, 0 },
3921  /* 24*/ { TRUNCATE_EXISTING, GENERIC_WRITE, 0, 0 },
3922  /* 25*/ { TRUNCATE_EXISTING, GENERIC_READ|GENERIC_WRITE, 0, 0 },
3924  };
3925  char temp_path[MAX_PATH];
3926  char file_name[MAX_PATH];
3927  DWORD i, ret, written;
3928  HANDLE hfile;
3929 
3931  GetTempFileNameA(temp_path, "tmp", 0, file_name);
3932 
3933  i = strlen(temp_path);
3934  if (i && temp_path[i - 1] == '\\') temp_path[i - 1] = 0;
3935 
3936  for (i = 0; i <= 5; i++)
3937  {
3938  SetLastError(0xdeadbeef);
3939  hfile = CreateFileA(temp_path, GENERIC_READ, 0, NULL, i, 0, 0);
3940  ok(hfile == INVALID_HANDLE_VALUE, "CreateFile should fail\n");
3941  if (i == 0 || i == 5)
3942  {
3943 /* FIXME: remove once Wine is fixed */
3944 todo_wine_if (i == 5)
3946  }
3947  else
3948  {
3949 /* FIXME: remove once Wine is fixed */
3950 todo_wine_if (i == 1)
3952  }
3953 
3954  SetLastError(0xdeadbeef);
3955  hfile = CreateFileA(temp_path, GENERIC_WRITE, 0, NULL, i, 0, 0);
3956  ok(hfile == INVALID_HANDLE_VALUE, "CreateFile should fail\n");
3957  if (i == 0)
3959  else
3960  {
3961 /* FIXME: remove once Wine is fixed */
3962 todo_wine_if (i == 1)
3964  }
3965  }
3966 
3967  for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3968  {
3969  SetLastError(0xdeadbeef);
3970  hfile = CreateFileA(file_name, td[i].access, 0, NULL, td[i].disposition, 0, 0);
3971  if (!td[i].error)
3972  {
3973  ok(hfile != INVALID_HANDLE_VALUE, "%d: CreateFile error %d\n", i, GetLastError());
3974  written = 0xdeadbeef;
3975  SetLastError(0xdeadbeef);
3976  ret = WriteFile(hfile, &td[i].error, sizeof(td[i].error), &written, NULL);
3977  if (td[i].access & GENERIC_WRITE)
3978  ok(ret, "%d: WriteFile error %d\n", i, GetLastError());
3979  else
3980  {
3981  ok(!ret, "%d: WriteFile should fail\n", i);
3982  ok(GetLastError() == ERROR_ACCESS_DENIED, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
3983  }
3984  SetLastError(0xdeadbeef);
3985  ret = SetFileTime(hfile, NULL, NULL, NULL);
3986  if (td[i].access & GENERIC_WRITE) /* actually FILE_WRITE_ATTRIBUTES */
3987  ok(ret, "%d: SetFileTime error %d\n", i, GetLastError());
3988  else
3989  {
3990  todo_wine
3991  {
3992  ok(!ret, "%d: SetFileTime should fail\n", i);
3993  ok(GetLastError() == ERROR_ACCESS_DENIED, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
3994  }
3995  }
3996  CloseHandle(hfile);
3997  }
3998  else
3999  {
4000  /* FIXME: remove the condition below once Wine is fixed */
4001  if (td[i].disposition == TRUNCATE_EXISTING && !(td[i].access & GENERIC_WRITE))
4002  {
4003  todo_wine
4004  {
4005  ok(hfile == INVALID_HANDLE_VALUE, "%d: CreateFile should fail\n", i);
4006  ok(GetLastError() == td[i].error, "%d: expected %d, got %d\n", i, td[i].error, GetLastError());
4007  }
4008  CloseHandle(hfile);
4009  }
4010  else
4011  {
4012  ok(hfile == INVALID_HANDLE_VALUE, "%d: CreateFile should fail\n", i);
4013  ok(GetLastError() == td[i].error, "%d: expected %d, got %d\n", i, td[i].error, GetLastError());
4014  }
4015  }
4016 
4017  if (td[i].clean_up) DeleteFileA(file_name);
4018  }
4019 
4021 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define CloseHandle
Definition: compat.h:398
#define error(str)
Definition: mkdosfs.c:1605
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * file_name(unsigned char *fixed)
Definition: file.c:58
GLdouble n
Definition: glext.h:7729
BOOL expected
Definition: file.c:2511
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI SetFileTime(IN HANDLE hFile, CONST FILETIME *lpCreationTime OPTIONAL, CONST FILETIME *lpLastAccessTime OPTIONAL, CONST FILETIME *lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:1098
else
Definition: tritemp.h:161
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define OPEN_EXISTING
Definition: compat.h:426
#define todo_wine_if(is_todo)
Definition: test.h:155
#define d
Definition: ke_i.h:81
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define MAX_PATH
Definition: compat.h:26
#define for
Definition: utility.h:88
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define OPEN_ALWAYS
Definition: disk.h:70
int ret
#define todo_wine
Definition: test.h:154
#define GENERIC_READ
Definition: compat.h:124
#define CREATE_ALWAYS
Definition: disk.h:72
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define CREATE_NEW
Definition: disk.h:69
#define TRUNCATE_EXISTING
Definition: disk.h:71
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

Referenced by START_TEST().

◆ test_CreateFile2()

static void test_CreateFile2 ( void  )
static

Definition at line 1630 of file file.c.

1631 {
1632  HANDLE hFile;
1636  static const WCHAR emptyW[]={'\0'};
1637  static const WCHAR prefix[] = {'p','f','x',0};
1638  static const WCHAR bogus[] = { '\\', '\\', '.', '\\', 'B', 'O', 'G', 'U', 'S', 0 };
1639  DWORD ret;
1640 
1641  if (!pCreateFile2)
1642  {
1643  win_skip("CreateFile2 is missing\n");
1644  return;
1645  }
1646 
1648  ok(ret != 0, "GetTempPathW error %d\n", GetLastError());
1649  ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
1650 
1651  ret = GetTempFileNameW(temp_path, prefix, 0, filename);
1652  ok(ret != 0, "GetTempFileNameW error %d\n", GetLastError());
1653 
1654  SetLastError(0xdeadbeef);
1655  exparams.dwSize = sizeof(exparams);
1657  exparams.dwFileFlags = 0;
1658  exparams.dwSecurityQosFlags = 0;
1659  exparams.lpSecurityAttributes = NULL;
1660  exparams.hTemplateFile = 0;
1661  hFile = pCreateFile2(filename, GENERIC_READ, 0, CREATE_NEW, &exparams);
1663  "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
1664 
1665  SetLastError(0xdeadbeef);
1666  hFile = pCreateFile2(filename, GENERIC_READ, FILE_SHARE_READ, CREATE_ALWAYS, &exparams);
1668  "hFile %p, last error %u\n", hFile, GetLastError());
1669  CloseHandle(hFile);
1670 
1671  SetLastError(0xdeadbeef);
1672  hFile = pCreateFile2(filename, GENERIC_READ, FILE_SHARE_READ, OPEN_ALWAYS, &exparams);
1674  "hFile %p, last error %u\n", hFile, GetLastError());
1675  CloseHandle(hFile);
1676 
1678  ok(ret, "DeleteFileW: error %d\n", GetLastError());
1679 
1680  SetLastError(0xdeadbeef);
1681  hFile = pCreateFile2(filename, GENERIC_READ, FILE_SHARE_READ, OPEN_ALWAYS, &exparams);
1683  "hFile %p, last error %u\n", hFile, GetLastError());
1684  CloseHandle(hFile);
1685 
1687  ok(ret, "DeleteFileW: error %d\n", GetLastError());
1688 
1689  hFile = pCreateFile2(emptyW, GENERIC_READ, 0, CREATE_NEW, &exparams);
1691  "CreateFile2(\"\") returned ret=%p error=%d\n",hFile,GetLastError());
1692 
1693  /* test the result of opening a nonexistent driver name */
1695  hFile = pCreateFile2(bogus, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING, &exparams);
1697  "CreateFile2 on invalid VxD name returned ret=%p error=%d\n",hFile,GetLastError());
1698 
1700  ok(ret == TRUE, "couldn't create temporary directory\n");
1702  hFile = pCreateFile2(filename, GENERIC_READ | GENERIC_WRITE, 0, OPEN_ALWAYS, &exparams);
1703  todo_wine
1705  "expected CreateFile2 to fail on existing directory, error: %d\n", GetLastError());
1706  CloseHandle(hFile);
1708  ok(ret, "DeleteFileW: error %d\n", GetLastError());
1709 }
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
const char * filename
Definition: ioapi.h:135
#define FILE_SHARE_READ
Definition: compat.h:125
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2079
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ok(value,...)
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
#define OPEN_EXISTING
Definition: compat.h:426
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define OPEN_ALWAYS
Definition: disk.h:70
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define todo_wine
Definition: test.h:154
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
LPSECURITY_ATTRIBUTES lpSecurityAttributes
Definition: fileapi.h:31
#define CREATE_ALWAYS
Definition: disk.h:72
static const WCHAR emptyW[]
Definition: navigate.c:36
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define CREATE_NEW
Definition: disk.h:69
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define win_skip
Definition: test.h:141
#define FILE_FLAG_RANDOM_ACCESS
Definition: disk.h:44
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

Referenced by START_TEST().

◆ test_CreateFileA()

static void test_CreateFileA ( void  )
static

Definition at line 1184 of file file.c.

1185 {
1186  HANDLE hFile;
1188  char filename[MAX_PATH];
1189  static const char prefix[] = "pfx";
1190  char windowsdir[MAX_PATH];
1191  char Volume_1[MAX_PATH];
1192  unsigned char buffer[512];
1193  char directory[] = "removeme";
1194  static const char nt_drive[] = "\\\\?\\A:";
1195  DWORD i, ret, len;
1196  static const struct test_list p[] =
1197  {
1198  {"", ERROR_PATH_NOT_FOUND, -1, FILE_ATTRIBUTE_NORMAL, TRUE }, /* dir as file w \ */
1199  {"", ERROR_SUCCESS, ERROR_PATH_NOT_FOUND, FILE_FLAG_BACKUP_SEMANTICS, FALSE }, /* dir as dir w \ */
1200  {"a", ERROR_FILE_NOT_FOUND, -1, FILE_ATTRIBUTE_NORMAL, FALSE }, /* non-exist file */
1201  {"a\\", ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND, FILE_ATTRIBUTE_NORMAL, FALSE }, /* non-exist dir */
1202  {"removeme", ERROR_ACCESS_DENIED, -1, FILE_ATTRIBUTE_NORMAL, FALSE }, /* exist dir w/o \ */
1203  {"removeme\\", ERROR_PATH_NOT_FOUND, -1, FILE_ATTRIBUTE_NORMAL, TRUE }, /* exst dir w \ */
1204  {"c:", ERROR_ACCESS_DENIED, ERROR_PATH_NOT_FOUND, FILE_ATTRIBUTE_NORMAL, FALSE }, /* device in file namespace */
1205  {"c:", ERROR_SUCCESS, ERROR_PATH_NOT_FOUND, FILE_FLAG_BACKUP_SEMANTICS, FALSE }, /* device in file namespace as dir */
1206  {"c:\\", ERROR_PATH_NOT_FOUND, ERROR_ACCESS_DENIED, FILE_ATTRIBUTE_NORMAL, TRUE }, /* root dir w \ */
1207  {"c:\\", ERROR_SUCCESS, ERROR_ACCESS_DENIED, FILE_FLAG_BACKUP_SEMANTICS, FALSE }, /* root dir w \ as dir */
1208  {"c:c:\\windows", ERROR_INVALID_NAME, -1, FILE_ATTRIBUTE_NORMAL, TRUE }, /* invalid path */
1209  {"\\\\?\\c:", ERROR_SUCCESS, ERROR_BAD_NETPATH, FILE_ATTRIBUTE_NORMAL,FALSE }, /* dev namespace drive */
1210  {"\\\\?\\c:\\", ERROR_PATH_NOT_FOUND, ERROR_BAD_NETPATH, FILE_ATTRIBUTE_NORMAL, TRUE }, /* dev namespace drive w \ */
1211  {NULL, 0, -1, 0, FALSE}
1212  };
1214  WCHAR curdir[MAX_PATH];
1215 
1217  ok(ret != 0, "GetTempPathA error %d\n", GetLastError());
1218  ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
1219 
1220  ret = GetTempFileNameA(temp_path, prefix, 0, filename);
1221  ok(ret != 0, "GetTempFileNameA error %d\n", GetLastError());
1222 
1223  SetLastError(0xdeadbeef);
1227  "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
1228 
1229  SetLastError(0xdeadbeef);
1233  "hFile %p, last error %u\n", hFile, GetLastError());
1234 
1235  CloseHandle(hFile);
1236 
1237  SetLastError(0xdeadbeef);
1241  "hFile %p, last error %u\n", hFile, GetLastError());
1242 
1243  CloseHandle(hFile);
1244 
1246  ok(ret, "DeleteFileA: error %d\n", GetLastError());
1247 
1248  SetLastError(0xdeadbeef);
1252  "hFile %p, last error %u\n", hFile, GetLastError());
1253 
1254  CloseHandle(hFile);
1255 
1257  ok(ret, "DeleteFileA: error %d\n", GetLastError());
1258 
1259  SetLastError(0xdeadbeef);
1261  ok(hFile == INVALID_HANDLE_VALUE, "hFile should have been INVALID_HANDLE_VALUE\n");
1263  broken(GetLastError() == ERROR_FILE_NOT_FOUND), /* Win98 */
1264  "LastError should have been ERROR_INVALID_NAME or ERROR_FILE_NOT_FOUND but got %u\n", GetLastError());
1265 
1266  /* get windows drive letter */
1267  ret = GetWindowsDirectoryA(windowsdir, sizeof(windowsdir));
1268  ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
1269  ok(ret != 0, "GetWindowsDirectory: error %d\n", GetLastError());
1270 
1271  /* test error return codes from CreateFile for some cases */
1273  ok(ret != 0, "GetTempPathA error %d\n", GetLastError());
1277  ok( ret, "Createdirectory failed, gle=%d\n", GetLastError() );
1278  /* set current drive & directory to known location */
1279  GetCurrentDirectoryW( MAX_PATH, curdir);
1281  i = 0;
1282  while (p[i].file)
1283  {
1284  filename[0] = 0;
1285  /* update the drive id in the table entry with the current one */
1286  if (p[i].file[1] == ':')
1287  {
1288  strcpy(filename, p[i].file);
1289  filename[0] = windowsdir[0];
1290  }
1291  else if (p[i].file[0] == '\\' && p[i].file[5] == ':')
1292  {
1293  strcpy(filename, p[i].file);
1294  filename[4] = windowsdir[0];
1295  }
1296  else
1297  {
1298  /* prefix the table entry with the current temp directory */
1300  strcat(filename, p[i].file);
1301  }
1305  p[i].options, NULL );
1306  /* if we get ACCESS_DENIED when we do not expect it, assume
1307  * no access to the volume
1308  */
1309  if (hFile == INVALID_HANDLE_VALUE &&
1311  p[i].err != ERROR_ACCESS_DENIED)
1312  {
1313  if (p[i].todo_flag)
1314  skip("Either no authority to volume, or is todo_wine for %s err=%d should be %d\n", filename, GetLastError(), p[i].err);
1315  else
1316  skip("Do not have authority to access volumes. Test for %s skipped\n", filename);
1317  }
1318  /* otherwise validate results with expectations */
1319  else
1320  {
1323  (p[i].err == GetLastError() || p[i].err2 == GetLastError())) ||
1325  "CreateFileA failed on %s, hFile %p, err=%u, should be %u\n",
1326  filename, hFile, GetLastError(), p[i].err);
1327  }
1328  if (hFile != INVALID_HANDLE_VALUE)
1329  CloseHandle( hFile );
1330  i++;
1331  }
1333  ok(ret, "RemoveDirectoryA: error %d\n", GetLastError());
1334  SetCurrentDirectoryW(curdir);
1335 
1336  /* test opening directory as a directory */
1339  NULL,
1340  OPEN_EXISTING,
1343  {
1345  "CreateFileA did not work, last error %u on volume <%s>\n",
1346  GetLastError(), temp_path );
1347 
1348  if (hFile != INVALID_HANDLE_VALUE)
1349  {
1350  ret = GetFileInformationByHandle( hFile, &Finfo );
1351  if (ret)
1352  {
1354  "CreateFileA probably did not open temp directory %s correctly\n file information does not include FILE_ATTRIBUTE_DIRECTORY, actual=0x%08x\n",
1355  temp_path, Finfo.dwFileAttributes);
1356  }
1357  CloseHandle( hFile );
1358  }
1359  }
1360  else
1361  skip("Probable Win9x, got ERROR_PATH_NOT_FOUND w/ FILE_FLAG_BACKUP_SEMANTICS or %s\n", temp_path);
1362 
1363 
1364  /* *** Test opening volumes/devices using drive letter *** */
1365 
1366  /* test using drive letter in non-rewrite format without trailing \ */
1367  /* this should work */
1368  strcpy(filename, nt_drive);
1369  filename[4] = windowsdir[0];
1374  if (hFile != INVALID_HANDLE_VALUE ||
1376  {
1377  /* if we have adm rights to volume, then try rest of tests */
1378  ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA did not open %s, last error=%u\n",
1379  filename, GetLastError());
1380  if (hFile != INVALID_HANDLE_VALUE)
1381  {
1382  /* if we opened the volume/device, try to read it. Since it */
1383  /* opened, we should be able to read it. We don't care about*/
1384  /* what the data is at this time. */
1385  len = 512;
1386  ret = ReadFile( hFile, buffer, len, &len, NULL );
1387  todo_wine ok(ret, "Failed to read volume, last error %u, %u, for %s\n",
1388  GetLastError(), ret, filename);
1389  if (ret)
1390  {
1391  trace("buffer is\n");
1392  dumpmem(buffer, 64);
1393  }
1394  CloseHandle( hFile );
1395  }
1396 
1397  /* test using drive letter with trailing \ and in non-rewrite */
1398  /* this should not work */
1399  strcpy(filename, nt_drive);
1400  filename[4] = windowsdir[0];
1401  strcat( filename, "\\" );
1406  todo_wine
1408  "CreateFileA should have returned ERROR_PATH_NOT_FOUND on %s, but got %u\n",
1409  filename, GetLastError());
1410  if (hFile != INVALID_HANDLE_VALUE)
1411  CloseHandle( hFile );
1412 
1413  /* test using temp path with trailing \ and in non-rewrite as dir */
1414  /* this should work */
1415  strcpy(filename, nt_drive);
1416  filename[4] = 0;
1423  "CreateFileA should have worked on %s, but got %u\n",
1424  filename, GetLastError());
1425  if (hFile != INVALID_HANDLE_VALUE)
1426  CloseHandle( hFile );
1427 
1428  /* test using drive letter without trailing \ and in device ns */
1429  /* this should work */
1430  strcpy(filename, nt_drive);
1431  filename[4] = windowsdir[0];
1432  filename[2] = '.';
1437  ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA did not open %s, last error=%u\n",
1438  filename, GetLastError());
1439  if (hFile != INVALID_HANDLE_VALUE)
1440  CloseHandle( hFile );
1441  }
1442  /* If we see ERROR_BAD_NETPATH then on Win9x or WinME, so skip */
1443  else if (GetLastError() == ERROR_BAD_NETPATH)
1444  skip("Probable Win9x, got ERROR_BAD_NETPATH (53)\n");
1445  else
1446  skip("Do not have authority to access volumes. Tests skipped\n");
1447 
1448 
1449  /* *** Test opening volumes/devices using GUID *** */
1450 
1451  if (pGetVolumeNameForVolumeMountPointA)
1452  {
1453  strcpy(filename, "c:\\");
1454  filename[0] = windowsdir[0];
1455  ret = pGetVolumeNameForVolumeMountPointA( filename, Volume_1, MAX_PATH );
1456  ok(ret, "GetVolumeNameForVolumeMountPointA failed, for %s, last error=%d\n", filename, GetLastError());
1457  if (ret)
1458  {
1459  ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name <%s>\n", Volume_1);
1460 
1461  /* test the result of opening a unique volume name (GUID)
1462  * with the trailing \
1463  * this should error out
1464  */
1465  strcpy(filename, Volume_1);
1470  todo_wine
1472  "CreateFileA should not have opened %s, hFile %p\n",
1473  filename, hFile);
1474  todo_wine
1476  "CreateFileA should have returned ERROR_PATH_NOT_FOUND on %s, but got %u\n",
1477  filename, GetLastError());
1478  if (hFile != INVALID_HANDLE_VALUE)
1479  CloseHandle( hFile );
1480 
1481  /* test the result of opening a unique volume name (GUID)
1482  * with the temp path string as dir
1483  * this should work
1484  */
1485  strcpy(filename, Volume_1);
1491  todo_wine
1493  "CreateFileA should have opened %s, but got %u\n",
1494  filename, GetLastError());
1495  if (hFile != INVALID_HANDLE_VALUE)
1496  CloseHandle( hFile );
1497 
1498  /* test the result of opening a unique volume name (GUID)
1499  * without the trailing \ and in device namespace
1500  * this should work
1501  */
1502  strcpy(filename, Volume_1);
1503  filename[2] = '.';
1504  filename[48] = 0;
1510  {
1511  /* if we have adm rights to volume, then try rest of tests */
1512  ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA did not open %s, last error=%u\n",
1513  filename, GetLastError());
1514  if (hFile != INVALID_HANDLE_VALUE)
1515  {
1516  /* if we opened the volume/device, try to read it. Since it */
1517  /* opened, we should be able to read it. We don't care about*/
1518  /* what the data is at this time. */
1519  len = 512;
1520  ret = ReadFile( hFile, buffer, len, &len, NULL );
1521  todo_wine ok(ret, "Failed to read volume, last error %u, %u, for %s\n",
1522  GetLastError(), ret, filename);
1523  if (ret)
1524  {
1525  trace("buffer is\n");
1526  dumpmem(buffer, 64);
1527  }
1528  CloseHandle(