2 * Copyright 2020 Arkadiusz Hiler for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
24 static BOOL
is_process_elevated(void)
27 if (OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY
, &token
))
29 TOKEN_ELEVATION_TYPE type
;
33 ret
= GetTokenInformation( token
, TokenElevationType
, &type
, sizeof(type
), &size
);
35 return (ret
&& type
== TokenElevationTypeFull
);
40 static DWORD
runcmd(const char* cmd
)
42 STARTUPINFOA si
= { sizeof(STARTUPINFOA
) };
43 PROCESS_INFORMATION pi
;
47 /* Create a writable copy for CreateProcessA() */
48 wcmd
= HeapAlloc(GetProcessHeap(), 0, strlen(cmd
) + 1);
51 rc
= CreateProcessA(NULL
, wcmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
52 HeapFree(GetProcessHeap(), 0, wcmd
);
57 rc
= WaitForSingleObject(pi
.hProcess
, 5000);
59 if (rc
== WAIT_OBJECT_0
)
60 GetExitCodeProcess(pi
.hProcess
, &rc
);
62 TerminateProcess(pi
.hProcess
, 1);
64 CloseHandle(pi
.hThread
);
65 CloseHandle(pi
.hProcess
);
70 static void test_hardlink(void)
75 BY_HANDLE_FILE_INFORMATION info
;
77 hfile
= CreateFileA("file", GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
78 FILE_ATTRIBUTE_NORMAL
, NULL
);
79 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to create a file\n");
82 rc
= runcmd("fsutil");
83 if (rc
== 1 && !is_process_elevated())
85 win_skip("Cannot run fsutil without elevated privileges on Windows <= 7\n");
88 ok(rc
== 0, "failed to run fsutil\n");
90 rc
= runcmd("fsutil hardlink");
91 ok(rc
== 0, "failed to run fsutil hardlink\n");
93 rc
= runcmd("fsutil hardlink create link file");
94 ok(rc
== 0, "failed to create a hardlink\n");
96 hfile
= CreateFileA("link", GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
97 FILE_ATTRIBUTE_NORMAL
, NULL
);
98 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open the hardlink\n");
99 boolrc
= GetFileInformationByHandle(hfile
, &info
);
100 ok(boolrc
, "failed to get info about hardlink, error %#x\n", GetLastError());
103 ok(info
.nNumberOfLinks
== 2, "our link is not a hardlink");
105 rc
= runcmd("fsutil hardlink create link file");
106 ok(rc
== 1, "fsutil didn't complain about already existing destination\n");
108 rc
= runcmd("fsutil hardlink create newlink nonexistingfile");
109 ok(rc
== 1, "fsutil didn't complain about nonexisting source file\n");
111 boolrc
= DeleteFileA("link");
112 ok(boolrc
, "failed to delete the hardlink, error %#x\n", GetLastError());
113 boolrc
= DeleteFileA("file");
114 ok(boolrc
, "failed to delete the file, error %#x\n", GetLastError());
119 char tmpdir
[MAX_PATH
];
121 GetTempPathA(MAX_PATH
, tmpdir
);
122 SetCurrentDirectoryA(tmpdir
);