ReactOS  0.4.15-dev-1152-g6c94e4f
PrivMoveFileIdentityW.c File Reference
#include "precomp.h"
#include <ndk/iofuncs.h>
Include dependency graph for PrivMoveFileIdentityW.c:

Go to the source code of this file.

Functions

static BOOL (WINAPI *pPrivMoveFileIdentityW)(LPCWSTR
 
static BOOL QueryFileInfo (LPCWSTR File, PFILE_BASIC_INFORMATION FileBasicInfo, PFILE_STANDARD_INFORMATION FileStandardInfo)
 
static VOID TestPrivMoveFileIdentityW (VOID)
 
 START_TEST (PrivMoveFileIdentityW)
 

Variables

static const WCHAR FileName [] = L"TestFile.xxx"
 
static const CHAR FileNameA [] = "TestFile.xxx"
 
static const WCHAR FileName2 [] = L"TestFile2.xxx"
 
static LPCWSTR
 
static DWORD
 

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pPrivMoveFileIdentityW)
static

◆ QueryFileInfo()

static BOOL QueryFileInfo ( LPCWSTR  File,
PFILE_BASIC_INFORMATION  FileBasicInfo,
PFILE_STANDARD_INFORMATION  FileStandardInfo 
)
static

Definition at line 20 of file PrivMoveFileIdentityW.c.

24 {
25  HANDLE hFile;
28 
32  NULL);
34  {
35  return FALSE;
36  }
37 
40  if (!NT_SUCCESS(Status))
41  {
43  return FALSE;
44  }
45 
46  Status = NtQueryInformationFile(hFile, &IoStatusBlock, FileStandardInfo,
48 
50  return NT_SUCCESS(Status);
51 }
#define CloseHandle
Definition: compat.h:487
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:136
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:523
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtQueryInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
#define SYNCHRONIZE
Definition: nt_native.h:61
_In_ HANDLE hFile
Definition: mswsock.h:90
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define FileStandardInformation
Definition: propsheet.cpp:61
#define CreateFileW
Definition: compat.h:489
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
Definition: File.h:15

Referenced by TestPrivMoveFileIdentityW().

◆ START_TEST()

START_TEST ( PrivMoveFileIdentityW  )

Definition at line 142 of file PrivMoveFileIdentityW.c.

143 {
144  HMODULE hKern = GetModuleHandleA("kernel32.dll");
145  pPrivMoveFileIdentityW = (void *)GetProcAddress(hKern, "PrivMoveFileIdentityW");
146 
148 }
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static VOID TestPrivMoveFileIdentityW(VOID)
#define GetProcAddress(x, y)
Definition: compat.h:501

◆ TestPrivMoveFileIdentityW()

static VOID TestPrivMoveFileIdentityW ( VOID  )
static

Definition at line 55 of file PrivMoveFileIdentityW.c.

56 {
57  FILE_BASIC_INFORMATION FileBasicInfo;
58  FILE_STANDARD_INFORMATION FileStandardInfo;
59  LARGE_INTEGER CreationTime, EndOfFile;
60  HANDLE hDest;
61  WCHAR Self[MAX_PATH];
62  OFSTRUCT ReOpen;
63  BOOL Ret;
64 
67 
68  if (GetModuleFileNameW(NULL, Self, MAX_PATH) == 0)
69  {
70  win_skip("Failed finding self\n");
71  return;
72  }
73 
74  if (!QueryFileInfo(Self, &FileBasicInfo, &FileStandardInfo))
75  {
76  win_skip("Failed querying self\n");
77  return;
78  }
79 
80  CreationTime = FileBasicInfo.CreationTime;
81  EndOfFile = FileStandardInfo.EndOfFile;
82 
83  Sleep(150);
84 
88  NULL);
89  if (hDest == INVALID_HANDLE_VALUE)
90  {
91  win_skip("Failed creating new\n");
92  return;
93  }
94 
95  CloseHandle(hDest);
96 
97  ok(QueryFileInfo(FileName, &FileBasicInfo, &FileStandardInfo) == TRUE, "QueryFileInfo returned FALSE\n");
98  ok(FileBasicInfo.CreationTime.QuadPart != CreationTime.QuadPart, "Equal creation times\n");
99  ok(FileStandardInfo.EndOfFile.QuadPart == 0LL, "File wasn't created empty: %I64d\n", FileStandardInfo.EndOfFile.QuadPart);
100  SetLastError(0xdeadbeef);
101  Ret = pPrivMoveFileIdentityW(Self, FileName, 0);
102  ok(Ret == FALSE, "PrivMoveFileIdentityW succeeded unexpectedly\n");
103  ok(GetLastError() == ERROR_SHARING_VIOLATION, "Last error: %#lx\n", GetLastError());
104  ok(QueryFileInfo(FileName, &FileBasicInfo, &FileStandardInfo) == TRUE, "QueryFileInfo returned FALSE\n");
105  ok(FileBasicInfo.CreationTime.QuadPart != CreationTime.QuadPart, "Equal creation times\n");
106  ok(FileStandardInfo.EndOfFile.QuadPart == 0LL, "File wasn't created empty: %I64d\n", FileStandardInfo.EndOfFile.QuadPart);
107  SetLastError(0xdeadbeef);
108  Ret = pPrivMoveFileIdentityW(Self, FileName, 2);
109  ok(Ret == TRUE, "PrivMoveFileIdentityW failed with %#lx\n", GetLastError());
110  ok(QueryFileInfo(FileName, &FileBasicInfo, &FileStandardInfo) == TRUE, "QueryFileInfo returned FALSE\n");
111  ok(FileBasicInfo.CreationTime.QuadPart == CreationTime.QuadPart, "Creation time didn't change\n");
112  ok(FileStandardInfo.EndOfFile.QuadPart == 0LL, "File not empty anymore: %I64d\n", FileStandardInfo.EndOfFile.QuadPart);
113  ok(QueryFileInfo(Self, &FileBasicInfo, &FileStandardInfo) == TRUE, "QueryFileInfo returned FALSE\n");
114  ok(FileBasicInfo.CreationTime.QuadPart == CreationTime.QuadPart, "Creation time changed\n");
115  ok(FileStandardInfo.EndOfFile.QuadPart == EndOfFile.QuadPart, "File size changed: %I64d\n", FileStandardInfo.EndOfFile.QuadPart);
116 
120  NULL);
121  if (hDest == INVALID_HANDLE_VALUE)
122  {
123  win_skip("Failed creating new\n");
124  return;
125  }
126 
127  CloseHandle(hDest);
128 
129  ok(QueryFileInfo(FileName2, &FileBasicInfo, &FileStandardInfo) == TRUE, "QueryFileInfo returned FALSE\n");
130  ok(FileBasicInfo.CreationTime.QuadPart != CreationTime.QuadPart, "Equal creation times\n");
131  SetLastError(0xdeadbeef);
132  Ret = pPrivMoveFileIdentityW(FileName, FileName2, 3);
133  ok(Ret == TRUE, "PrivMoveFileIdentityW failed with %#lx\n", GetLastError());
134  ok(QueryFileInfo(FileName2, &FileBasicInfo, &FileStandardInfo) == TRUE, "QueryFileInfo returned FALSE\n");
135  ok(FileBasicInfo.CreationTime.QuadPart == CreationTime.QuadPart, "Creation time didn't change\n");
136  ok(OpenFile(FileNameA, &ReOpen, OF_EXIST) == HFILE_ERROR, "Source file still exists\n");
137 
140 }
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
#define CloseHandle
Definition: compat.h:487
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define LL
Definition: tui.h:84
#define TRUE
Definition: types.h:120
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:136
static BOOL QueryFileInfo(LPCWSTR File, PFILE_BASIC_INFORMATION FileBasicInfo, PFILE_STANDARD_INFORMATION FileStandardInfo)
#define HFILE_ERROR
Definition: winbase.h:111
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
smooth NULL
Definition: ftsmooth.c:416
HFILE WINAPI OpenFile(LPCSTR lpFileName, LPOFSTRUCT lpReOpenBuff, UINT uStyle)
Definition: create.c:368
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
#define SetLastError(x)
Definition: compat.h:500
LARGE_INTEGER CreationTime
Definition: nt_native.h:939
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define ERROR_SHARING_VIOLATION
Definition: winerror.h:135
#define SYNCHRONIZE
Definition: nt_native.h:61
#define OF_EXIST
Definition: winbase.h:127
#define CREATE_ALWAYS
Definition: disk.h:72
#define ok(value,...)
Definition: atltest.h:57
#define CreateFileW
Definition: compat.h:489
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
static const WCHAR FileName2[]
static const CHAR FileNameA[]
#define win_skip
Definition: test.h:149
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by START_TEST().

Variable Documentation

◆ DWORD

Definition at line 16 of file PrivMoveFileIdentityW.c.

◆ FileName

const WCHAR FileName[] = L"TestFile.xxx"
static

Definition at line 12 of file PrivMoveFileIdentityW.c.

◆ FileName2

const WCHAR FileName2[] = L"TestFile2.xxx"
static

Definition at line 14 of file PrivMoveFileIdentityW.c.

Referenced by START_TEST(), and TestPrivMoveFileIdentityW().

◆ FileNameA

const CHAR FileNameA[] = "TestFile.xxx"
static

◆ LPCWSTR

Definition at line 16 of file PrivMoveFileIdentityW.c.