Release 9.11.
[wine.git] / dlls / kernel32 / tests / volume.c
blobbaf055c08b09d0ee04c90db69d31f216e7e59ca5
1 /*
2 * Unit test suite for volume functions
4 * Copyright 2006 Stefan Leichter
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdio.h>
22 #include "ntstatus.h"
23 #define WIN32_NO_STATUS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winioctl.h"
27 #include "ntddstor.h"
28 #include "winternl.h"
29 #include "ddk/ntddcdvd.h"
30 #include "ddk/mountmgr.h"
31 #include "wine/test.h"
33 #include <pshpack1.h>
34 struct COMPLETE_DVD_LAYER_DESCRIPTOR
36 DVD_DESCRIPTOR_HEADER Header;
37 DVD_LAYER_DESCRIPTOR Descriptor;
38 UCHAR Padding;
40 #include <poppack.h>
41 C_ASSERT(sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR) == 22);
43 #include <pshpack1.h>
44 struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR
46 DVD_DESCRIPTOR_HEADER Header;
47 DVD_MANUFACTURER_DESCRIPTOR Descriptor;
48 UCHAR Padding;
50 #include <poppack.h>
51 C_ASSERT(sizeof(struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR) == 2053);
53 static HINSTANCE hdll;
54 static HANDLE (WINAPI *pFindFirstVolumeA)(LPSTR,DWORD);
55 static BOOL (WINAPI *pFindNextVolumeA)(HANDLE,LPSTR,DWORD);
56 static BOOL (WINAPI *pFindVolumeClose)(HANDLE);
57 static UINT (WINAPI *pGetLogicalDriveStringsA)(UINT,LPSTR);
58 static UINT (WINAPI *pGetLogicalDriveStringsW)(UINT,LPWSTR);
59 static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameA)(LPCSTR, LPSTR, DWORD, LPDWORD);
60 static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameW)(LPCWSTR, LPWSTR, DWORD, LPDWORD);
61 static BOOL (WINAPI *pCreateSymbolicLinkA)(const char *, const char *, DWORD);
62 static BOOL (WINAPI *pGetVolumeInformationByHandleW)(HANDLE, WCHAR *, DWORD, DWORD *, DWORD *, DWORD *, WCHAR *, DWORD);
64 /* ############################### */
66 static void test_query_dos_deviceA(void)
68 char drivestr[] = "a:";
69 char *p, *buffer, buffer2[2000];
70 DWORD ret, ret2, buflen=32768;
71 BOOL found = FALSE;
73 /* callers must guess the buffer size */
74 SetLastError(0xdeadbeef);
75 ret = QueryDosDeviceA( NULL, NULL, 0 );
76 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
77 "QueryDosDeviceA(no buffer): returned %lu, le=%lu\n", ret, GetLastError());
79 buffer = HeapAlloc( GetProcessHeap(), 0, buflen );
80 SetLastError(0xdeadbeef);
81 ret = QueryDosDeviceA( NULL, buffer, buflen );
82 ok((ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER),
83 "QueryDosDeviceA failed to return list, last error %lu\n", GetLastError());
85 if (ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
86 p = buffer;
87 for (;;) {
88 if (!*p) break;
89 ret2 = QueryDosDeviceA( p, buffer2, sizeof(buffer2) );
90 /* Win10+ exposes the security device which requires extra privileges to be queried. So skip it */
91 ok(ret2 || broken( !strcmp( p, "MSSECFLTSYS" ) && GetLastError() == ERROR_ACCESS_DENIED ),
92 "QueryDosDeviceA failed to return current mapping for %s, last error %lu\n", p, GetLastError());
93 p += strlen(p) + 1;
94 if (ret <= (p-buffer)) break;
98 for (;drivestr[0] <= 'z'; drivestr[0]++) {
99 /* Older W2K fails with ERROR_INSUFFICIENT_BUFFER when buflen is > 32767 */
100 ret = QueryDosDeviceA( drivestr, buffer, buflen - 1);
101 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
102 "QueryDosDeviceA failed to return current mapping for %s, last error %lu\n", drivestr, GetLastError());
103 if(ret) {
104 for (p = buffer; *p; p++) *p = toupper(*p);
105 if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE;
108 ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
109 HeapFree( GetProcessHeap(), 0, buffer );
112 static void test_dos_devices(void)
114 char buf[MAX_PATH], buf2[400];
115 char drivestr[3];
116 HANDLE file;
117 BOOL ret;
119 /* Find an unused drive letter */
120 drivestr[1] = ':';
121 drivestr[2] = 0;
122 for (drivestr[0] = 'a'; drivestr[0] <= 'z'; drivestr[0]++) {
123 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf));
124 if (!ret) break;
126 if (drivestr[0] > 'z') {
127 skip("can't test creating a dos drive, none available\n");
128 return;
131 ret = DefineDosDeviceA( 0, drivestr, "C:/windows/" );
132 ok(ret, "failed to define drive %s, error %lu\n", drivestr, GetLastError());
134 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf) );
135 ok(ret, "failed to query drive %s, error %lu\n", drivestr, GetLastError());
136 ok(!strcmp(buf, "\\??\\C:\\windows\\"), "got path %s\n", debugstr_a(buf));
138 sprintf(buf, "%s/system32", drivestr);
139 file = CreateFileA( buf, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
140 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
141 todo_wine ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
142 CloseHandle( file );
144 /* but it's not a volume mount point */
146 sprintf(buf, "%s\\", drivestr);
147 ret = GetVolumeNameForVolumeMountPointA( buf, buf2, sizeof(buf2) );
148 ok(!ret, "expected failure\n");
149 todo_wine ok(GetLastError() == ERROR_INVALID_PARAMETER, "got error %lu\n", GetLastError());
151 ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL);
152 ok(ret, "failed to remove drive %s, error %lu\n", drivestr, GetLastError());
154 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf) );
155 ok(!ret, "expected failure\n");
156 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "got error %lu\n", GetLastError());
158 sprintf(buf, "%s/system32", drivestr);
159 file = CreateFileA( buf, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
160 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
161 ok(file == INVALID_HANDLE_VALUE, "expected failure\n");
162 todo_wine ok(GetLastError() == ERROR_PATH_NOT_FOUND, "got error %lu\n", GetLastError());
164 /* try with DDD_RAW_TARGET_PATH */
166 ret = DefineDosDeviceA( DDD_RAW_TARGET_PATH, drivestr, "\\??\\C:\\windows\\" );
167 ok(ret, "failed to define drive %s, error %lu\n", drivestr, GetLastError());
169 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf) );
170 ok(ret, "failed to query drive %s, error %lu\n", drivestr, GetLastError());
171 ok(!strcmp(buf, "\\??\\C:\\windows\\"), "got path %s\n", debugstr_a(buf));
173 sprintf(buf, "%s/system32", drivestr);
174 file = CreateFileA( buf, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
175 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
176 todo_wine ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
177 CloseHandle( file );
179 sprintf(buf, "%s\\", drivestr);
180 ret = GetVolumeNameForVolumeMountPointA( buf, buf2, sizeof(buf2) );
181 ok(!ret, "expected failure\n");
182 todo_wine ok(GetLastError() == ERROR_INVALID_PARAMETER, "got error %lu\n", GetLastError());
184 ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL);
185 ok(ret, "failed to remove drive %s, error %lu\n", drivestr, GetLastError());
187 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf) );
188 ok(!ret, "expected failure\n");
189 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "got error %lu\n", GetLastError());
192 static void test_FindFirstVolume(void)
194 char volume[51];
195 HANDLE handle;
197 /* not present before w2k */
198 if (!pFindFirstVolumeA) {
199 win_skip("FindFirstVolumeA not found\n");
200 return;
203 handle = pFindFirstVolumeA( volume, 0 );
204 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
205 ok( GetLastError() == ERROR_MORE_DATA || /* XP */
206 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Vista */
207 "wrong error %lu\n", GetLastError() );
208 handle = pFindFirstVolumeA( volume, 49 );
209 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
210 ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE, "wrong error %lu\n", GetLastError() );
211 handle = pFindFirstVolumeA( volume, 51 );
212 ok( handle != INVALID_HANDLE_VALUE, "failed err %lu\n", GetLastError() );
213 if (handle != INVALID_HANDLE_VALUE)
217 ok( strlen(volume) == 49, "bad volume name %s\n", volume );
218 ok( !memcmp( volume, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume );
219 ok( !memcmp( volume + 47, "}\\", 2 ), "bad volume name %s\n", volume );
220 } while (pFindNextVolumeA( handle, volume, MAX_PATH ));
221 ok( GetLastError() == ERROR_NO_MORE_FILES, "wrong error %lu\n", GetLastError() );
222 pFindVolumeClose( handle );
226 static void test_GetVolumeNameForVolumeMountPointA(void)
228 BOOL ret;
229 char volume[MAX_PATH], path[] = "c:\\";
230 DWORD len = sizeof(volume), reti;
231 char temp_path[MAX_PATH];
233 reti = GetTempPathA(MAX_PATH, temp_path);
234 ok(reti != 0, "GetTempPathA error %ld\n", GetLastError());
235 ok(reti < MAX_PATH, "temp path should fit into MAX_PATH\n");
237 ret = GetVolumeNameForVolumeMountPointA(path, volume, 0);
238 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
239 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
240 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
241 "wrong error, last=%ld\n", GetLastError());
243 if (0) { /* these crash on XP */
244 ret = GetVolumeNameForVolumeMountPointA(path, NULL, len);
245 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
247 ret = GetVolumeNameForVolumeMountPointA(NULL, volume, len);
248 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
251 ret = GetVolumeNameForVolumeMountPointA(path, volume, len);
252 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
253 ok(!strncmp( volume, "\\\\?\\Volume{", 11),
254 "GetVolumeNameForVolumeMountPointA failed to return valid string <%s>\n",
255 volume);
257 /* test with too small buffer */
258 ret = GetVolumeNameForVolumeMountPointA(path, volume, 10);
259 ok(ret == FALSE && GetLastError() == ERROR_FILENAME_EXCED_RANGE,
260 "GetVolumeNameForVolumeMountPointA failed, wrong error returned, was %ld, should be ERROR_FILENAME_EXCED_RANGE\n",
261 GetLastError());
263 /* Try on an arbitrary directory */
264 /* On FAT filesystems it seems that GetLastError() is set to
265 ERROR_INVALID_FUNCTION. */
266 ret = GetVolumeNameForVolumeMountPointA(temp_path, volume, len);
267 ok(ret == FALSE && (GetLastError() == ERROR_NOT_A_REPARSE_POINT ||
268 GetLastError() == ERROR_INVALID_FUNCTION),
269 "GetVolumeNameForVolumeMountPointA failed on %s, last=%ld\n",
270 temp_path, GetLastError());
272 /* Try on a nonexistent dos drive */
273 path[2] = 0;
274 for (;path[0] <= 'z'; path[0]++) {
275 ret = QueryDosDeviceA( path, volume, len);
276 if(!ret) break;
278 if (path[0] <= 'z')
280 path[2] = '\\';
281 ret = GetVolumeNameForVolumeMountPointA(path, volume, len);
282 ok(ret == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND,
283 "GetVolumeNameForVolumeMountPointA failed on %s, last=%ld\n",
284 path, GetLastError());
286 /* Try without trailing \ and on a nonexistent dos drive */
287 path[2] = 0;
288 ret = GetVolumeNameForVolumeMountPointA(path, volume, len);
289 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
290 "GetVolumeNameForVolumeMountPointA failed on %s, last=%ld\n",
291 path, GetLastError());
295 static void test_GetVolumeNameForVolumeMountPointW(void)
297 BOOL ret;
298 WCHAR volume[MAX_PATH], path[] = {'c',':','\\',0};
299 DWORD len = ARRAY_SIZE(volume);
301 ret = GetVolumeNameForVolumeMountPointW(path, volume, 0);
302 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
303 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
304 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
305 "wrong error, last=%ld\n", GetLastError());
307 if (0) { /* these crash on XP */
308 ret = GetVolumeNameForVolumeMountPointW(path, NULL, len);
309 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
311 ret = GetVolumeNameForVolumeMountPointW(NULL, volume, len);
312 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
315 ret = GetVolumeNameForVolumeMountPointW(path, volume, len);
316 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n");
319 static void test_GetLogicalDriveStringsA(void)
321 UINT size, size2;
322 char *buf, *ptr;
324 ok( pGetLogicalDriveStringsA != NULL, "GetLogicalDriveStringsA not available\n");
325 if(!pGetLogicalDriveStringsA) {
326 return;
329 size = pGetLogicalDriveStringsA(0, NULL);
330 ok(size%4 == 1, "size = %d\n", size);
332 buf = HeapAlloc(GetProcessHeap(), 0, size);
334 *buf = 0;
335 size2 = pGetLogicalDriveStringsA(2, buf);
336 ok(size2 == size, "size2 = %d\n", size2);
337 ok(!*buf, "buf changed\n");
339 size2 = pGetLogicalDriveStringsA(size, buf);
340 ok(size2 == size-1, "size2 = %d\n", size2);
342 for(ptr = buf; ptr < buf+size2; ptr += 4) {
343 ok(('A' <= *ptr && *ptr <= 'Z'), "device name '%c' is not uppercase\n", *ptr);
344 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
345 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
346 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
348 ok(!*ptr, "buf[size2] is not nullbyte\n");
350 HeapFree(GetProcessHeap(), 0, buf);
353 static void test_GetLogicalDriveStringsW(void)
355 UINT size, size2;
356 WCHAR *buf, *ptr;
358 ok( pGetLogicalDriveStringsW != NULL, "GetLogicalDriveStringsW not available\n");
359 if(!pGetLogicalDriveStringsW) {
360 return;
363 SetLastError(0xdeadbeef);
364 size = pGetLogicalDriveStringsW(0, NULL);
365 if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
366 win_skip("GetLogicalDriveStringsW not implemented\n");
367 return;
369 ok(size%4 == 1, "size = %d\n", size);
371 buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
373 *buf = 0;
374 size2 = pGetLogicalDriveStringsW(2, buf);
375 ok(size2 == size, "size2 = %d\n", size2);
376 ok(!*buf, "buf changed\n");
378 size2 = pGetLogicalDriveStringsW(size, buf);
379 ok(size2 == size-1, "size2 = %d\n", size2);
381 for(ptr = buf; ptr < buf+size2; ptr += 4) {
382 ok('A' <= *ptr && *ptr <= 'Z', "device name '%c' is not uppercase\n", *ptr);
383 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
384 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
385 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
387 ok(!*ptr, "buf[size2] is not nullbyte\n");
389 HeapFree(GetProcessHeap(), 0, buf);
392 static void test_GetVolumeInformationA(void)
394 BOOL ret;
395 UINT result;
396 char Root_Colon[]="C:";
397 char Root_Slash[]="C:\\";
398 char Root_UNC[]="\\\\?\\C:\\";
399 char volume[MAX_PATH+1];
400 DWORD vol_name_size=MAX_PATH+1, vol_serial_num=-1, max_comp_len=0, fs_flags=0, fs_name_len=MAX_PATH+1;
401 char vol_name_buf[MAX_PATH+1], fs_name_buf[MAX_PATH+1];
402 char windowsdir[MAX_PATH+10];
403 char currentdir[MAX_PATH+1];
405 /* get windows drive letter and update strings for testing */
406 result = GetWindowsDirectoryA(windowsdir, sizeof(windowsdir));
407 ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
408 ok(result != 0, "GetWindowsDirectory: error %ld\n", GetLastError());
409 Root_Colon[0] = windowsdir[0];
410 Root_Slash[0] = windowsdir[0];
411 Root_UNC[4] = windowsdir[0];
413 result = GetCurrentDirectoryA(MAX_PATH, currentdir);
414 ok(result, "GetCurrentDirectory: error %ld\n", GetLastError());
415 /* Note that GetCurrentDir yields no trailing slash for subdirs */
417 /* check for NO error on no trailing \ when current dir is root dir */
418 ret = SetCurrentDirectoryA(Root_Slash);
419 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError());
420 ret = GetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
421 NULL, NULL, fs_name_buf, fs_name_len);
422 ok(ret, "GetVolumeInformationA root failed, last error %lu\n", GetLastError());
424 /* check for error on no trailing \ when current dir is subdir (windows) of queried drive */
425 ret = SetCurrentDirectoryA(windowsdir);
426 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError());
427 SetLastError(0xdeadbeef);
428 ret = GetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
429 NULL, NULL, fs_name_buf, fs_name_len);
430 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
431 "GetVolumeInformationA did%s fail, last error %lu\n", ret ? " not":"", GetLastError());
433 /* reset current directory */
434 ret = SetCurrentDirectoryA(currentdir);
435 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError());
437 if (toupper(currentdir[0]) == toupper(windowsdir[0])) {
438 skip("Please re-run from another device than %c:\n", windowsdir[0]);
439 /* FIXME: Use GetLogicalDrives to find another device to avoid this skip. */
440 } else {
441 char Root_Env[]="=C:"; /* where MS maintains the per volume directory */
442 Root_Env[1] = windowsdir[0];
444 /* C:\windows becomes the current directory on drive C: */
445 /* Note that paths to subdirs are stored without trailing slash, like what GetCurrentDir yields. */
446 ret = SetEnvironmentVariableA(Root_Env, windowsdir);
447 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
449 ret = SetCurrentDirectoryA(windowsdir);
450 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError());
451 ret = SetCurrentDirectoryA(currentdir);
452 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError());
454 /* windows dir is current on the root drive, call fails */
455 SetLastError(0xdeadbeef);
456 ret = GetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
457 NULL, NULL, fs_name_buf, fs_name_len);
458 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
459 "GetVolumeInformationA did%s fail, last error %lu\n", ret ? " not":"", GetLastError());
461 /* Try normal drive letter with trailing \ */
462 ret = GetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size, NULL,
463 NULL, NULL, fs_name_buf, fs_name_len);
464 ok(ret, "GetVolumeInformationA with \\ failed, last error %lu\n", GetLastError());
466 ret = SetCurrentDirectoryA(Root_Slash);
467 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError());
468 ret = SetCurrentDirectoryA(currentdir);
469 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError());
471 /* windows dir is STILL CURRENT on root drive; the call fails as before, */
472 /* proving that SetCurrentDir did not remember the other drive's directory */
473 SetLastError(0xdeadbeef);
474 ret = GetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
475 NULL, NULL, fs_name_buf, fs_name_len);
476 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
477 "GetVolumeInformationA did%s fail, last error %lu\n", ret ? " not":"", GetLastError());
479 /* Now C:\ becomes the current directory on drive C: */
480 ret = SetEnvironmentVariableA(Root_Env, Root_Slash); /* set =C:=C:\ */
481 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
483 /* \ is current on root drive, call succeeds */
484 ret = GetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
485 NULL, NULL, fs_name_buf, fs_name_len);
486 ok(ret, "GetVolumeInformationA failed, last error %lu\n", GetLastError());
488 /* again, SetCurrentDirectory on another drive does not matter */
489 ret = SetCurrentDirectoryA(Root_Slash);
490 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError());
491 ret = SetCurrentDirectoryA(currentdir);
492 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError());
494 /* \ is current on root drive, call succeeds */
495 ret = GetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
496 NULL, NULL, fs_name_buf, fs_name_len);
497 ok(ret, "GetVolumeInformationA failed, last error %lu\n", GetLastError());
500 /* try null root directory to return "root of the current directory" */
501 ret = GetVolumeInformationA(NULL, vol_name_buf, vol_name_size, NULL,
502 NULL, NULL, fs_name_buf, fs_name_len);
503 ok(ret, "GetVolumeInformationA failed on null root dir, last error %lu\n", GetLastError());
505 /* Try normal drive letter with trailing \ */
506 ret = GetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size,
507 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
508 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%lu\n", Root_Slash, GetLastError());
510 /* try again with drive letter and the "disable parsing" prefix */
511 SetLastError(0xdeadbeef);
512 ret = GetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
513 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
514 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%lu\n", ret ? " not":"", Root_UNC, GetLastError());
516 /* try again with device name space */
517 Root_UNC[2] = '.';
518 SetLastError(0xdeadbeef);
519 ret = GetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
520 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
521 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%lu\n", ret ? " not":"", Root_UNC, GetLastError());
523 /* try again with a directory off the root - should generate error */
524 if (windowsdir[strlen(windowsdir)-1] != '\\') strcat(windowsdir, "\\");
525 SetLastError(0xdeadbeef);
526 ret = GetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
527 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
528 ok(!ret && (GetLastError()==ERROR_DIR_NOT_ROOT),
529 "GetVolumeInformationA did%s fail, root=%s, last error=%lu\n", ret ? " not":"", windowsdir, GetLastError());
530 /* A subdir with trailing \ yields DIR_NOT_ROOT instead of INVALID_NAME */
531 if (windowsdir[strlen(windowsdir)-1] == '\\') windowsdir[strlen(windowsdir)-1] = 0;
532 SetLastError(0xdeadbeef);
533 ret = GetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
534 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
535 ok(!ret && (GetLastError()==ERROR_INVALID_NAME),
536 "GetVolumeInformationA did%s fail, root=%s, last error=%lu\n", ret ? " not":"", windowsdir, GetLastError());
538 /* get the unique volume name for the windows drive */
539 ret = GetVolumeNameForVolumeMountPointA(Root_Slash, volume, MAX_PATH);
540 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
542 /* try again with unique volume name */
543 ret = GetVolumeInformationA(volume, vol_name_buf, vol_name_size,
544 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
545 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%lu\n", volume, GetLastError());
548 /* Test to check that unique volume name from windows dir mount point */
549 /* matches at least one of the unique volume names returned from the */
550 /* FindFirstVolumeA/FindNextVolumeA list. */
551 static void test_enum_vols(void)
553 DWORD ret;
554 HANDLE hFind = INVALID_HANDLE_VALUE;
555 char Volume_1[MAX_PATH] = {0};
556 char Volume_2[MAX_PATH] = {0};
557 char path[] = "c:\\";
558 BOOL found = FALSE;
559 char windowsdir[MAX_PATH];
561 /*get windows drive letter and update strings for testing */
562 ret = GetWindowsDirectoryA( windowsdir, sizeof(windowsdir) );
563 ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
564 ok(ret != 0, "GetWindowsDirectory: error %ld\n", GetLastError());
565 path[0] = windowsdir[0];
567 /* get the unique volume name for the windows drive */
568 ret = GetVolumeNameForVolumeMountPointA( path, Volume_1, MAX_PATH );
569 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
570 ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1);
572 /* get first unique volume name of list */
573 hFind = pFindFirstVolumeA( Volume_2, MAX_PATH );
574 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstVolume failed, err=%lu\n",
575 GetLastError());
579 /* validate correct length of unique volume name */
580 ok(strlen(Volume_2) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1);
581 if (memcmp(Volume_1, Volume_2, 49) == 0)
583 found = TRUE;
584 break;
586 } while (pFindNextVolumeA( hFind, Volume_2, MAX_PATH ));
587 ok(found, "volume name %s not found by Find[First/Next]Volume\n", Volume_1);
588 pFindVolumeClose( hFind );
591 static void test_disk_extents(void)
593 BOOL ret;
594 DWORD size;
595 HANDLE handle;
596 static DWORD data[16];
598 handle = CreateFileA( "\\\\.\\c:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
599 if (handle == INVALID_HANDLE_VALUE)
601 win_skip("can't open c: drive %lu\n", GetLastError());
602 return;
604 size = 0;
605 ret = DeviceIoControl( handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, &data,
606 sizeof(data), &data, sizeof(data), &size, NULL );
607 if (!ret && GetLastError() == ERROR_INVALID_FUNCTION)
609 win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
610 CloseHandle( handle );
611 return;
613 ok(ret, "DeviceIoControl failed %lu\n", GetLastError());
614 ok(size == 32, "expected 32, got %lu\n", size);
615 CloseHandle( handle );
618 static void test_disk_query_property(void)
620 STORAGE_PROPERTY_QUERY query = {0};
621 STORAGE_DESCRIPTOR_HEADER header = {0};
622 STORAGE_DEVICE_DESCRIPTOR descriptor = {0};
623 HANDLE handle;
624 DWORD error;
625 DWORD size;
626 BOOL ret;
628 handle = CreateFileA("\\\\.\\PhysicalDrive0", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
629 0, 0);
630 if (handle == INVALID_HANDLE_VALUE)
632 win_skip("can't open \\\\.\\PhysicalDrive0 %#lx\n", GetLastError());
633 return;
636 query.PropertyId = StorageDeviceProperty;
637 query.QueryType = PropertyStandardQuery;
639 SetLastError(0xdeadbeef);
640 ret = DeviceIoControl(handle, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), &header, sizeof(header), &size,
641 NULL);
642 error = GetLastError();
643 ok(ret, "expect ret %#x, got %#x\n", TRUE, ret);
644 ok(error == 0xdeadbeef, "expect err %#x, got err %#lx\n", 0xdeadbeef, error);
645 ok(size == sizeof(header), "got size %ld\n", size);
646 ok(header.Version == sizeof(descriptor), "got header.Version %ld\n", header.Version);
647 ok(header.Size >= sizeof(descriptor), "got header.Size %ld\n", header.Size);
649 SetLastError(0xdeadbeef);
650 ret = DeviceIoControl(handle, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), &descriptor, sizeof(descriptor),
651 &size, NULL);
652 error = GetLastError();
653 ok(ret, "expect ret %#x, got %#x\n", TRUE, ret);
654 ok(error == 0xdeadbeef, "expect err %#x, got err %#lx\n", 0xdeadbeef, error);
655 ok(size == sizeof(descriptor), "got size %ld\n", size);
656 ok(descriptor.Version == sizeof(descriptor), "got descriptor.Version %ld\n", descriptor.Version);
657 ok(descriptor.Size >= sizeof(descriptor), "got descriptor.Size %ld\n", descriptor.Size);
659 CloseHandle(handle);
662 static void test_GetVolumePathNameA(void)
664 char volume_path[MAX_PATH], cwd[MAX_PATH], expect_path[MAX_PATH];
665 struct {
666 const char *file_name;
667 const char *path_name;
668 DWORD path_len;
669 DWORD error;
670 DWORD broken_error;
671 } test_paths[] = {
672 { /* test 0: NULL parameters, 0 output length */
673 NULL, NULL, 0,
674 ERROR_INVALID_PARAMETER, 0xdeadbeef /* winxp */
676 { /* empty input, NULL output, 0 output length */
677 "", NULL, 0,
678 ERROR_INVALID_PARAMETER, 0xdeadbeef /* winxp */
680 { /* valid input, NULL output, 0 output length */
681 "C:\\", NULL, 0,
682 ERROR_INVALID_PARAMETER, ERROR_FILENAME_EXCED_RANGE /* winxp */
684 { /* valid input, valid output, 0 output length */
685 "C:\\", "C:\\", 0,
686 ERROR_INVALID_PARAMETER, ERROR_FILENAME_EXCED_RANGE /* winxp */
688 { /* valid input, valid output, 1 output length */
689 "C:\\", "C:\\", 1,
690 ERROR_FILENAME_EXCED_RANGE, NO_ERROR
692 { /* test 5: valid input, valid output, valid output length */
693 "C:\\", "C:\\", sizeof(volume_path),
694 NO_ERROR, NO_ERROR
696 { /* lowercase input, uppercase output, valid output length */
697 "c:\\", "C:\\", sizeof(volume_path),
698 NO_ERROR, NO_ERROR
700 { /* really bogus input, valid output, 1 output length */
701 "\\\\$$$", "C:\\", 1,
702 ERROR_INVALID_NAME, ERROR_FILENAME_EXCED_RANGE
704 { /* a reasonable DOS path that is guaranteed to exist */
705 "C:\\windows\\system32", "C:\\", sizeof(volume_path),
706 NO_ERROR, NO_ERROR
708 { /* a reasonable DOS path that shouldn't exist */
709 "C:\\windows\\system32\\AnInvalidFolder", "C:\\", sizeof(volume_path),
710 NO_ERROR, NO_ERROR
712 { /* test 10: a reasonable NT-converted DOS path that shouldn't exist */
713 "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:\\", sizeof(volume_path),
714 NO_ERROR, NO_ERROR
716 { /* an unreasonable NT-converted DOS path */
717 "\\\\?\\InvalidDrive:\\AnInvalidFolder", "\\\\?\\InvalidDrive:\\" /* win2k, winxp */,
718 sizeof(volume_path),
719 ERROR_INVALID_NAME, NO_ERROR
721 { /* an unreasonable NT volume path */
722 "\\\\?\\Volume{00000000-00-0000-0000-000000000000}\\AnInvalidFolder",
723 "\\\\?\\Volume{00000000-00-0000-0000-000000000000}\\" /* win2k, winxp */,
724 sizeof(volume_path),
725 ERROR_INVALID_NAME, NO_ERROR
727 { /* an unreasonable NT-ish path */
728 "\\\\ReallyBogus\\InvalidDrive:\\AnInvalidFolder",
729 "\\\\ReallyBogus\\InvalidDrive:\\" /* win2k, winxp */, sizeof(volume_path),
730 ERROR_INVALID_NAME, NO_ERROR
733 "M::", "C:\\", 4,
734 ERROR_FILE_NOT_FOUND, ERROR_MORE_DATA
736 { /* test 15 */
737 "C:", "C:", 2,
738 ERROR_FILENAME_EXCED_RANGE, NO_ERROR
741 "C:", "C:", 3,
742 NO_ERROR, ERROR_FILENAME_EXCED_RANGE
745 "C:\\", "C:", 2,
746 ERROR_FILENAME_EXCED_RANGE, NO_ERROR
749 "C:\\", "C:", 3,
750 NO_ERROR, ERROR_FILENAME_EXCED_RANGE
753 "C::", "C:", 2,
754 ERROR_FILENAME_EXCED_RANGE, NO_ERROR
756 { /* test 20 */
757 "C::", "C:", 3,
758 NO_ERROR, ERROR_FILENAME_EXCED_RANGE
761 "C:\\windows\\system32\\AnInvalidFolder", "C:", 3,
762 NO_ERROR, ERROR_FILENAME_EXCED_RANGE
765 "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:", 3,
766 ERROR_FILENAME_EXCED_RANGE, NO_ERROR
769 "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:", 6,
770 ERROR_FILENAME_EXCED_RANGE, NO_ERROR
773 "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:", 7,
774 NO_ERROR, ERROR_FILENAME_EXCED_RANGE
776 { /* test 25 */
777 "\\\\?\\c:\\AnInvalidFolder", "\\\\?\\c:", 7,
778 NO_ERROR, ERROR_FILENAME_EXCED_RANGE
781 "C:/", "C:\\", 4,
782 NO_ERROR, ERROR_MORE_DATA
785 "M:/", "", 4,
786 ERROR_FILE_NOT_FOUND, ERROR_MORE_DATA
789 "?:ABC:DEF:\\AnInvalidFolder", "?:\\" /* win2k, winxp */, sizeof(volume_path),
790 ERROR_FILE_NOT_FOUND, NO_ERROR
793 "s:omefile", "S:\\" /* win2k, winxp */, sizeof(volume_path),
794 ERROR_FILE_NOT_FOUND, NO_ERROR
796 { /* test 30: a reasonable forward slash path that is guaranteed to exist */
797 "C:/windows/system32", "C:\\", sizeof(volume_path),
798 NO_ERROR, NO_ERROR
802 static const char *relative_tests[] =
804 "InvalidDrive:\\AnInvalidFolder",
805 "relative/path",
806 "somefile:def",
809 static const char *global_prefix_tests[] =
811 "\\??\\CdRom0",
812 "\\??\\ReallyBogus",
813 "\\??\\C:\\NonExistent",
814 "\\??\\M:\\NonExistent",
817 BOOL ret, success;
818 DWORD error;
819 UINT i;
821 for (i=0; i<ARRAY_SIZE(test_paths); i++)
823 BOOL broken_ret = test_paths[i].broken_error == NO_ERROR;
824 char *output = (test_paths[i].path_name != NULL ? volume_path : NULL);
825 BOOL expected_ret = test_paths[i].error == NO_ERROR;
827 volume_path[0] = 0;
828 if (test_paths[i].path_len < sizeof(volume_path))
829 volume_path[ test_paths[i].path_len ] = 0x11;
831 SetLastError( 0xdeadbeef );
832 ret = GetVolumePathNameA( test_paths[i].file_name, output, test_paths[i].path_len );
833 error = GetLastError();
834 ok(ret == expected_ret || broken(ret == broken_ret),
835 "GetVolumePathName test %d %s unexpectedly.\n",
836 i, test_paths[i].error == NO_ERROR ? "failed" : "succeeded");
838 if (ret)
840 ok(!strcmp( volume_path, test_paths[i].path_name )
841 || broken(!strcasecmp( volume_path, test_paths[i].path_name )), /* XP */
842 "GetVolumePathName test %d unexpectedly returned path %s (expected %s).\n",
843 i, volume_path, test_paths[i].path_name);
845 else
847 /* On success Windows always returns ERROR_MORE_DATA, so only worry about failure */
848 success = (error == test_paths[i].error || broken(error == test_paths[i].broken_error));
849 ok(success, "GetVolumePathName test %d unexpectedly returned error 0x%lx (expected 0x%lx).\n",
850 i, error, test_paths[i].error);
853 if (test_paths[i].path_len < sizeof(volume_path))
854 ok(volume_path[ test_paths[i].path_len ] == 0x11,
855 "GetVolumePathName test %d corrupted byte after end of buffer.\n", i);
858 ret = GetCurrentDirectoryA( sizeof(cwd), cwd );
859 ok(ret, "Failed to obtain the current working directory, error %lu.\n", GetLastError());
860 ret = GetVolumePathNameA( cwd, expect_path, sizeof(expect_path) );
861 ok(ret, "Failed to obtain the current volume path, error %lu.\n", GetLastError());
863 for (i = 0; i < ARRAY_SIZE(relative_tests); i++)
865 ret = GetVolumePathNameA( relative_tests[i], volume_path, sizeof(volume_path) );
866 ok(ret, "GetVolumePathName(%s) failed unexpectedly, error %lu.\n",
867 debugstr_a( relative_tests[i] ), GetLastError());
868 ok(!strcmp( volume_path, expect_path ), "%s: expected %s, got %s.\n",
869 debugstr_a( relative_tests[i] ), debugstr_a( expect_path ), debugstr_a( volume_path ));
872 cwd[3] = 0;
873 for (i = 0; i < ARRAY_SIZE(global_prefix_tests); i++)
875 ret = GetVolumePathNameA( global_prefix_tests[i], volume_path, sizeof(volume_path) );
876 ok(ret, "GetVolumePathName(%s) failed unexpectedly, error %lu.\n",
877 debugstr_a( global_prefix_tests[i] ), GetLastError());
878 ok(!strcmp( volume_path, cwd ), "%s: expected %s, got %s.\n",
879 debugstr_a( global_prefix_tests[i] ), debugstr_a( cwd ), debugstr_a( volume_path ));
882 ret = GetVolumePathNameA( "C:.", expect_path, sizeof(expect_path) );
883 ok(ret, "Failed to obtain the volume path, error %lu.\n", GetLastError());
885 SetLastError( 0xdeadbeef );
886 ret = GetVolumePathNameA( "C::", volume_path, 1 );
887 ok(!ret, "Expected failure.\n");
888 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE, "Got error %lu.\n", GetLastError());
890 ret = GetVolumePathNameA( "C::", volume_path, sizeof(volume_path) );
891 ok(ret, "Failed to obtain the volume path, error %lu.\n", GetLastError());
892 ok(!strcmp(volume_path, expect_path), "Expected %s, got %s.\n",
893 debugstr_a( expect_path ), debugstr_a( volume_path ));
895 ret = GetVolumePathNameA( "C:ABC:DEF:\\AnInvalidFolder", volume_path, sizeof(volume_path) );
896 ok(ret, "Failed to obtain the volume path, error %lu.\n", GetLastError());
897 ok(!strcmp(volume_path, expect_path), "Expected %s, got %s.\n",
898 debugstr_a( expect_path ), debugstr_a( volume_path ));
901 static void test_GetVolumePathNameW(void)
903 WCHAR volume_path[MAX_PATH];
904 BOOL ret;
906 volume_path[0] = 0;
907 volume_path[1] = 0x11;
908 ret = GetVolumePathNameW( L"C:\\", volume_path, 1 );
909 ok(!ret, "GetVolumePathNameW test succeeded unexpectedly.\n");
910 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE, "GetVolumePathNameW unexpectedly returned error 0x%lx (expected 0x%x).\n",
911 GetLastError(), ERROR_FILENAME_EXCED_RANGE);
912 ok(volume_path[1] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n");
914 volume_path[0] = 0;
915 volume_path[2] = 0x11;
916 ret = GetVolumePathNameW( L"C:\\", volume_path, 2 );
917 ok(!ret, "GetVolumePathNameW test succeeded unexpectedly.\n");
918 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE, "GetVolumePathNameW unexpectedly returned error 0x%lx (expected 0x%x).\n",
919 GetLastError(), ERROR_FILENAME_EXCED_RANGE);
920 ok(volume_path[2] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n");
922 volume_path[0] = 0;
923 volume_path[3] = 0x11;
924 ret = GetVolumePathNameW( L"C:\\", volume_path, 3 );
925 ok(ret || broken(!ret) /* win2k */, "GetVolumePathNameW test failed unexpectedly.\n");
926 ok(!memcmp(volume_path, L"C:\\", 3) || broken(!volume_path[0]) /* XP */,
927 "Got wrong path %s.\n", debugstr_w(volume_path));
928 ok(volume_path[3] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n");
930 volume_path[0] = 0;
931 volume_path[4] = 0x11;
932 ret = GetVolumePathNameW( L"C:\\", volume_path, 4 );
933 ok(ret, "GetVolumePathNameW test failed unexpectedly.\n");
934 ok(!wcscmp(volume_path, L"C:\\"), "Got wrong path %s.\n", debugstr_w(volume_path));
935 ok(volume_path[4] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n");
938 static void test_GetVolumePathNamesForVolumeNameA(void)
940 BOOL ret;
941 char volume[MAX_PATH], buffer[MAX_PATH];
942 DWORD len, error;
944 if (!pGetVolumePathNamesForVolumeNameA)
946 win_skip("required functions not found\n");
947 return;
950 ret = GetVolumeNameForVolumeMountPointA( "c:\\", volume, sizeof(volume) );
951 ok(ret, "failed to get volume name %lu\n", GetLastError());
952 trace("c:\\ -> %s\n", volume);
954 SetLastError( 0xdeadbeef );
955 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, NULL );
956 error = GetLastError();
957 ok(!ret, "expected failure\n");
958 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error);
960 SetLastError( 0xdeadbeef );
961 ret = pGetVolumePathNamesForVolumeNameA( "", NULL, 0, NULL );
962 error = GetLastError();
963 ok(!ret, "expected failure\n");
964 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error);
966 SetLastError( 0xdeadbeef );
967 ret = pGetVolumePathNamesForVolumeNameA( volume, NULL, 0, NULL );
968 error = GetLastError();
969 ok(!ret, "expected failure\n");
970 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %lu\n", error);
972 SetLastError( 0xdeadbeef );
973 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, 0, NULL );
974 error = GetLastError();
975 ok(!ret, "expected failure\n");
976 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %lu\n", error);
978 memset( buffer, 0xff, sizeof(buffer) );
979 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), NULL );
980 ok(ret, "failed to get path names %lu\n", GetLastError());
981 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
982 ok(!buffer[4], "expected double null-terminated buffer\n");
984 len = 0;
985 SetLastError( 0xdeadbeef );
986 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, &len );
987 error = GetLastError();
988 ok(!ret, "expected failure\n");
989 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error);
991 len = 0;
992 SetLastError( 0xdeadbeef );
993 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, sizeof(buffer), &len );
994 error = GetLastError();
995 ok(!ret, "expected failure\n");
996 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error);
998 len = 0;
999 SetLastError( 0xdeadbeef );
1000 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
1001 error = GetLastError();
1002 ok(!ret, "expected failure\n");
1003 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error);
1005 len = 0;
1006 SetLastError( 0xdeadbeef );
1007 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
1008 error = GetLastError();
1009 ok(!ret, "expected failure\n");
1010 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error);
1012 len = 0;
1013 memset( buffer, 0xff, sizeof(buffer) );
1014 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), &len );
1015 ok(ret, "failed to get path names %lu\n", GetLastError());
1016 ok(len == 5 || broken(len == 2), "expected 5 got %lu\n", len);
1017 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
1018 ok(!buffer[4], "expected double null-terminated buffer\n");
1021 static void test_GetVolumePathNamesForVolumeNameW(void)
1023 static const WCHAR empty[] = {0};
1024 static const WCHAR drive_c[] = {'c',':','\\',0};
1025 static const WCHAR volume_null[] = {'\\','\\','?','\\','V','o','l','u','m','e',
1026 '{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0','0',
1027 '-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',0};
1028 BOOL ret;
1029 WCHAR volume[MAX_PATH], buffer[MAX_PATH];
1030 DWORD len, error;
1032 if (!pGetVolumePathNamesForVolumeNameW)
1034 win_skip("required functions not found\n");
1035 return;
1038 ret = GetVolumeNameForVolumeMountPointW( drive_c, volume, ARRAY_SIZE(volume) );
1039 ok(ret, "failed to get volume name %lu\n", GetLastError());
1041 SetLastError( 0xdeadbeef );
1042 ret = pGetVolumePathNamesForVolumeNameW( empty, NULL, 0, NULL );
1043 error = GetLastError();
1044 ok(!ret, "expected failure\n");
1045 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error);
1047 SetLastError( 0xdeadbeef );
1048 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, 0, NULL );
1049 error = GetLastError();
1050 ok(!ret, "expected failure\n");
1051 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %lu\n", error);
1053 SetLastError( 0xdeadbeef );
1054 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, 0, NULL );
1055 error = GetLastError();
1056 ok(!ret, "expected failure\n");
1057 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %lu\n", error);
1059 if (0) { /* crash */
1060 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, ARRAY_SIZE(buffer), NULL );
1061 ok(ret, "failed to get path names %lu\n", GetLastError());
1064 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, ARRAY_SIZE(buffer), NULL );
1065 ok(ret, "failed to get path names %lu\n", GetLastError());
1067 len = 0;
1068 memset( buffer, 0xff, sizeof(buffer) );
1069 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, ARRAY_SIZE(buffer), &len );
1070 ok(ret, "failed to get path names %lu\n", GetLastError());
1071 ok(len == 5, "expected 5 got %lu\n", len);
1072 ok(!buffer[4], "expected double null-terminated buffer\n");
1074 len = 0;
1075 volume[1] = '?';
1076 volume[lstrlenW( volume ) - 1] = 0;
1077 SetLastError( 0xdeadbeef );
1078 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, ARRAY_SIZE(buffer), &len );
1079 error = GetLastError();
1080 ok(!ret, "expected failure\n");
1081 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error);
1083 len = 0;
1084 volume[0] = '\\';
1085 volume[1] = 0;
1086 SetLastError( 0xdeadbeef );
1087 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, ARRAY_SIZE(buffer), &len );
1088 error = GetLastError();
1089 ok(!ret, "expected failure\n");
1090 todo_wine ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %lu\n", error);
1092 len = 0;
1093 lstrcpyW( volume, volume_null );
1094 SetLastError( 0xdeadbeef );
1095 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, ARRAY_SIZE(buffer), &len );
1096 error = GetLastError();
1097 ok(!ret, "expected failure\n");
1098 ok(error == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND got %lu\n", error);
1101 static void test_dvd_read_structure(HANDLE handle)
1103 int i;
1104 DWORD nbBytes;
1105 BOOL ret;
1106 DVD_READ_STRUCTURE dvdReadStructure;
1107 DVD_LAYER_DESCRIPTOR dvdLayerDescriptor;
1108 struct COMPLETE_DVD_LAYER_DESCRIPTOR completeDvdLayerDescriptor;
1109 DVD_COPYRIGHT_DESCRIPTOR dvdCopyrightDescriptor;
1110 struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR completeDvdManufacturerDescriptor;
1112 dvdReadStructure.BlockByteOffset.QuadPart = 0;
1113 dvdReadStructure.SessionId = 0;
1114 dvdReadStructure.LayerNumber = 0;
1117 /* DvdPhysicalDescriptor */
1118 dvdReadStructure.Format = 0;
1120 SetLastError(0xdeadbeef);
1122 /* Test whether this ioctl is supported */
1123 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1124 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
1126 if(!ret)
1128 skip("IOCTL_DVD_READ_STRUCTURE not supported: %lu\n", GetLastError());
1129 return;
1132 /* Confirm there is always a header before the actual data */
1133 ok( completeDvdLayerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdLayerDescriptor.Header.Length);
1134 ok( completeDvdLayerDescriptor.Header.Reserved[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[0]);
1135 ok( completeDvdLayerDescriptor.Header.Reserved[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[1]);
1137 /* TODO: Also check completeDvdLayerDescriptor.Descriptor content (via IOCTL_SCSI_PASS_THROUGH_DIRECT ?) */
1139 /* Insufficient output buffer */
1140 for(i=0; i<sizeof(DVD_DESCRIPTOR_HEADER); i++)
1142 SetLastError(0xdeadbeef);
1144 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1145 &completeDvdLayerDescriptor, i, &nbBytes, NULL);
1146 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,"IOCTL_DVD_READ_STRUCTURE should fail with small buffer\n");
1149 SetLastError(0xdeadbeef);
1151 /* On newer version, an output buffer of sizeof(DVD_READ_STRUCTURE) size fails.
1152 I think this is to force developers to realize that there is a header before the actual content */
1153 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1154 &dvdLayerDescriptor, sizeof(DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
1155 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER) || broken(ret) /* < Win7 */,
1156 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
1158 SetLastError(0xdeadbeef);
1160 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, NULL, sizeof(DVD_READ_STRUCTURE),
1161 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
1162 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER),
1163 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
1165 /* Test wrong input parameters */
1166 for(i=0; i<sizeof(DVD_READ_STRUCTURE); i++)
1168 SetLastError(0xdeadbeef);
1170 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, i,
1171 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
1172 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER),
1173 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
1177 /* DvdCopyrightDescriptor */
1178 dvdReadStructure.Format = 1;
1180 SetLastError(0xdeadbeef);
1182 /* Strangely, with NULL lpOutBuffer, last error is insufficient buffer, not invalid parameter as we could expect */
1183 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1184 NULL, sizeof(DVD_COPYRIGHT_DESCRIPTOR), &nbBytes, NULL);
1185 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %lu\n", ret, GetLastError());
1187 for(i=0; i<sizeof(DVD_COPYRIGHT_DESCRIPTOR); i++)
1189 SetLastError(0xdeadbeef);
1191 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1192 &dvdCopyrightDescriptor, i, &nbBytes, NULL);
1193 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %lu\n", ret, GetLastError());
1197 /* DvdManufacturerDescriptor */
1198 dvdReadStructure.Format = 4;
1200 SetLastError(0xdeadbeef);
1202 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1203 &completeDvdManufacturerDescriptor, sizeof(DVD_MANUFACTURER_DESCRIPTOR), &nbBytes, NULL);
1204 ok(ret || broken(GetLastError() == ERROR_NOT_READY),
1205 "IOCTL_DVD_READ_STRUCTURE (DvdManufacturerDescriptor) failed, last error = %lu\n", GetLastError());
1206 if(!ret)
1207 return;
1209 /* Confirm there is always a header before the actual data */
1210 ok( completeDvdManufacturerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdManufacturerDescriptor.Header.Length);
1211 ok( completeDvdManufacturerDescriptor.Header.Reserved[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdManufacturerDescriptor.Header.Reserved[0]);
1212 ok( completeDvdManufacturerDescriptor.Header.Reserved[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdManufacturerDescriptor.Header.Reserved[1]);
1214 SetLastError(0xdeadbeef);
1216 /* Basic parameter check */
1217 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1218 NULL, sizeof(DVD_MANUFACTURER_DESCRIPTOR), &nbBytes, NULL);
1219 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %lu\n", ret, GetLastError());
1222 static void test_cdrom_ioctl(void)
1224 char drive_letter, drive_path[] = "A:\\", drive_full_path[] = "\\\\.\\A:";
1225 DWORD bitmask;
1226 HANDLE handle;
1228 bitmask = GetLogicalDrives();
1229 if(!bitmask)
1231 trace("GetLogicalDrives failed : %lu\n", GetLastError());
1232 return;
1235 for(drive_letter='A'; drive_letter<='Z'; drive_letter++)
1237 if(!(bitmask & (1 << (drive_letter-'A') )))
1238 continue;
1240 drive_path[0] = drive_letter;
1241 if(GetDriveTypeA(drive_path) != DRIVE_CDROM)
1243 trace("Skipping %c:, not a CDROM drive.\n", drive_letter);
1244 continue;
1247 trace("Testing with %c:\n", drive_letter);
1249 drive_full_path[4] = drive_letter;
1250 handle = CreateFileA(drive_full_path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
1251 if(handle == INVALID_HANDLE_VALUE)
1253 trace("Failed to open the device : %lu\n", GetLastError());
1254 continue;
1257 /* Add your tests here */
1258 test_dvd_read_structure(handle);
1260 CloseHandle(handle);
1265 static void test_mounted_folder(void)
1267 char name_buffer[200], path[MAX_PATH], volume_name[100], *p;
1268 FILE_NAME_INFORMATION *name = (FILE_NAME_INFORMATION *)name_buffer;
1269 FILE_ATTRIBUTE_TAG_INFO info;
1270 IO_STATUS_BLOCK io;
1271 BOOL ret, got_path;
1272 NTSTATUS status;
1273 HANDLE file;
1274 DWORD size;
1276 file = CreateFileA( "C:\\", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1277 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL );
1278 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
1280 status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileAttributeTagInformation );
1281 ok(!status, "got status %#lx\n", status);
1282 ok(!(info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
1283 && (info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY), "got attributes %#lx\n", info.FileAttributes);
1284 ok(!info.ReparseTag, "got reparse tag %#lx\n", info.ReparseTag);
1286 CloseHandle( file );
1288 file = CreateFileA( "C:\\", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1289 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
1290 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
1292 status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileAttributeTagInformation );
1293 ok(!status, "got status %#lx\n", status);
1294 ok(!(info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
1295 && (info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY), "got attributes %#lx\n", info.FileAttributes);
1296 ok(!info.ReparseTag, "got reparse tag %#lx\n", info.ReparseTag);
1298 CloseHandle( file );
1300 ret = GetFileAttributesA( "C:\\" );
1301 ok(!(ret & FILE_ATTRIBUTE_REPARSE_POINT) && (ret & FILE_ATTRIBUTE_DIRECTORY), "got attributes %#x\n", ret);
1303 ret = CreateDirectoryA("C:\\winetest_mnt", NULL);
1304 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
1306 skip("Not enough permissions to create a folder in the C: drive.\n");
1307 return;
1309 ok(ret, "got error %lu\n", GetLastError());
1311 ret = GetVolumeNameForVolumeMountPointA( "C:\\", volume_name, sizeof(volume_name) );
1312 ok(ret, "got error %lu\n", GetLastError());
1314 ret = SetVolumeMountPointA( "C:\\winetest_mnt\\", volume_name );
1315 if (!ret)
1317 skip("Not enough permissions to create a mounted folder.\n");
1318 RemoveDirectoryA( "C:\\winetest_mnt" );
1319 return;
1321 todo_wine ok(ret, "got error %lu\n", GetLastError());
1323 file = CreateFileA( "C:\\winetest_mnt", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1324 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL );
1325 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
1327 status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileAttributeTagInformation );
1328 ok(!status, "got status %#lx\n", status);
1329 ok((info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
1330 && (info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY), "got attributes %#lx\n", info.FileAttributes);
1331 ok(info.ReparseTag == IO_REPARSE_TAG_MOUNT_POINT, "got reparse tag %#lx\n", info.ReparseTag);
1333 status = NtQueryInformationFile( file, &io, name, sizeof(name_buffer), FileNameInformation );
1334 ok(!status, "got status %#lx\n", status);
1335 ok(name->FileNameLength == wcslen(L"\\winetest_mnt") * sizeof(WCHAR), "got length %lu\n", name->FileNameLength);
1336 ok(!wcsnicmp(name->FileName, L"\\winetest_mnt", wcslen(L"\\winetest_mnt")), "got name %s\n",
1337 debugstr_wn(name->FileName, name->FileNameLength / sizeof(WCHAR)));
1339 CloseHandle( file );
1341 file = CreateFileA( "C:\\winetest_mnt", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1342 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
1343 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
1345 status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileAttributeTagInformation );
1346 ok(!status, "got status %#lx\n", status);
1347 ok(!(info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
1348 && (info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY), "got attributes %#lx\n", info.FileAttributes);
1349 ok(!info.ReparseTag, "got reparse tag %#lx\n", info.ReparseTag);
1351 status = NtQueryInformationFile( file, &io, name, sizeof(name_buffer), FileNameInformation );
1352 ok(!status, "got status %#lx\n", status);
1353 ok(name->FileNameLength == wcslen(L"\\") * sizeof(WCHAR), "got length %lu\n", name->FileNameLength);
1354 ok(!wcsnicmp(name->FileName, L"\\", wcslen(L"\\")), "got name %s\n",
1355 debugstr_wn(name->FileName, name->FileNameLength / sizeof(WCHAR)));
1357 CloseHandle( file );
1359 ret = GetFileAttributesA( "C:\\winetest_mnt" );
1360 ok(ret != INVALID_FILE_ATTRIBUTES, "got error %lu\n", GetLastError());
1361 ok((ret & FILE_ATTRIBUTE_REPARSE_POINT) && (ret & FILE_ATTRIBUTE_DIRECTORY), "got attributes %#x\n", ret);
1363 file = CreateFileA( "C:\\winetest_mnt\\windows", 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
1364 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
1365 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
1367 status = NtQueryInformationFile( file, &io, name, sizeof(name_buffer), FileNameInformation );
1368 ok(!status, "got status %#lx\n", status);
1369 ok(name->FileNameLength == wcslen(L"\\windows") * sizeof(WCHAR), "got length %lu\n", name->FileNameLength);
1370 ok(!wcsnicmp(name->FileName, L"\\windows", wcslen(L"\\windows")), "got name %s\n",
1371 debugstr_wn(name->FileName, name->FileNameLength / sizeof(WCHAR)));
1373 CloseHandle( file );
1375 ret = GetVolumePathNameA( "C:\\winetest_mnt", path, sizeof(path) );
1376 ok(ret, "got error %lu\n", GetLastError());
1377 ok(!strcmp(path, "C:\\winetest_mnt\\"), "got %s\n", debugstr_a(path));
1378 SetLastError(0xdeadbeef);
1379 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_mnt", path, sizeof(path) );
1380 ok(!ret, "expected failure\n");
1381 ok(GetLastError() == ERROR_INVALID_NAME, "wrong error %lu\n", GetLastError());
1382 SetLastError(0xdeadbeef);
1383 ret = GetVolumeInformationA( "C:\\winetest_mnt", NULL, 0, NULL, NULL, NULL, NULL, 0 );
1384 ok(!ret, "expected failure\n");
1385 ok(GetLastError() == ERROR_INVALID_NAME, "wrong error %lu\n", GetLastError());
1387 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_mnt\\", path, sizeof(path) );
1388 ok(ret, "got error %lu\n", GetLastError());
1389 ok(!strcmp(path, volume_name), "expected %s, got %s\n", debugstr_a(volume_name), debugstr_a(path));
1390 ret = GetVolumeInformationA( "C:\\winetest_mnt\\", NULL, 0, NULL, NULL, NULL, NULL, 0 );
1391 ok(ret, "got error %lu\n", GetLastError());
1393 ret = GetVolumePathNameA( "C:\\winetest_mnt\\windows", path, sizeof(path) );
1394 ok(ret, "got error %lu\n", GetLastError());
1395 ok(!strcmp(path, "C:\\winetest_mnt\\"), "got %s\n", debugstr_a(path));
1396 SetLastError(0xdeadbeef);
1397 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_mnt\\windows\\", path, sizeof(path) );
1398 ok(!ret, "expected failure\n");
1399 ok(GetLastError() == ERROR_NOT_A_REPARSE_POINT, "wrong error %lu\n", GetLastError());
1400 SetLastError(0xdeadbeef);
1401 ret = GetVolumeInformationA( "C:\\winetest_mnt\\windows\\", NULL, 0, NULL, NULL, NULL, NULL, 0 );
1402 ok(!ret, "expected failure\n");
1403 ok(GetLastError() == ERROR_DIR_NOT_ROOT, "wrong error %lu\n", GetLastError());
1405 ret = GetVolumePathNameA( "C:\\winetest_mnt\\nonexistent\\", path, sizeof(path) );
1406 ok(ret, "got error %lu\n", GetLastError());
1407 ok(!strcmp(path, "C:\\winetest_mnt\\"), "got %s\n", debugstr_a(path));
1408 SetLastError(0xdeadbeef);
1409 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_mnt\\nonexistent\\", path, sizeof(path) );
1410 ok(!ret, "expected failure\n");
1411 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %lu\n", GetLastError());
1412 SetLastError(0xdeadbeef);
1413 ret = GetVolumeInformationA( "C:\\winetest_mnt\\nonexistent\\", NULL, 0, NULL, NULL, NULL, NULL, 0 );
1414 ok(!ret, "expected failure\n");
1415 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %lu\n", GetLastError());
1417 ret = GetVolumePathNameA( "C:\\winetest_mnt\\winetest_mnt", path, sizeof(path) );
1418 ok(ret, "got error %lu\n", GetLastError());
1419 ok(!strcmp(path, "C:\\winetest_mnt\\winetest_mnt\\"), "got %s\n", debugstr_a(path));
1420 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_mnt\\winetest_mnt\\", path, sizeof(path) );
1421 ok(ret, "got error %lu\n", GetLastError());
1422 ok(!strcmp(path, volume_name), "expected %s, got %s\n", debugstr_a(volume_name), debugstr_a(path));
1423 ret = GetVolumeInformationA( "C:\\winetest_mnt\\winetest_mnt\\", NULL, 0, NULL, NULL, NULL, NULL, 0 );
1424 ok(ret, "got error %lu\n", GetLastError());
1426 ret = GetVolumePathNameA( "C:/winetest_mnt/../winetest_mnt/.", path, sizeof(path) );
1427 ok(ret, "got error %lu\n", GetLastError());
1428 ok(!strcmp(path, "C:\\winetest_mnt\\"), "got %s\n", debugstr_a(path));
1429 ret = GetVolumeNameForVolumeMountPointA( "C:/winetest_mnt/../winetest_mnt/.\\", path, sizeof(path) );
1430 ok(ret, "got error %lu\n", GetLastError());
1431 ok(!strcmp(path, volume_name), "expected %s, got %s\n", debugstr_a(volume_name), debugstr_a(path));
1432 ret = GetVolumeInformationA( "C:/winetest_mnt/../winetest_mnt/.\\", NULL, 0, NULL, NULL, NULL, NULL, 0 );
1433 ok(ret, "got error %lu\n", GetLastError());
1435 ret = GetVolumePathNamesForVolumeNameA( volume_name, path, sizeof(path), &size );
1436 ok(ret, "got error %lu\n", GetLastError());
1437 got_path = FALSE;
1438 for (p = path; *p; p += strlen(p) + 1)
1440 if (!strcmp( p, "C:\\winetest_mnt\\" ))
1441 got_path = TRUE;
1442 ok(strcmp( p, "C:\\winetest_mnt\\winetest_mnt\\" ), "GetVolumePathNamesForVolumeName() should not recurse\n");
1444 ok(got_path, "mount point was not enumerated\n");
1446 /* test interaction with symbolic links */
1448 if (pCreateSymbolicLinkA)
1450 ret = pCreateSymbolicLinkA( "C:\\winetest_link", "C:\\winetest_mnt\\", SYMBOLIC_LINK_FLAG_DIRECTORY );
1451 ok(ret, "got error %lu\n", GetLastError());
1453 ret = GetVolumePathNameA( "C:\\winetest_link\\", path, sizeof(path) );
1454 ok(ret, "got error %lu\n", GetLastError());
1455 ok(!strcmp(path, "C:\\"), "got %s\n", path);
1456 SetLastError(0xdeadbeef);
1457 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_link\\", path, sizeof(path) );
1458 ok(!ret, "expected failure\n");
1459 ok(GetLastError() == ERROR_INVALID_PARAMETER
1460 || broken(GetLastError() == ERROR_SUCCESS) /* 2008 */, "wrong error %lu\n", GetLastError());
1461 ret = GetVolumeInformationA( "C:\\winetest_link\\", NULL, 0, NULL, NULL, NULL, NULL, 0 );
1462 ok(ret, "got error %lu\n", GetLastError());
1464 ret = GetVolumePathNameA( "C:\\winetest_link\\windows\\", path, sizeof(path) );
1465 ok(ret, "got error %lu\n", GetLastError());
1466 ok(!strcmp(path, "C:\\"), "got %s\n", path);
1467 SetLastError(0xdeadbeef);
1468 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_link\\windows\\", path, sizeof(path) );
1469 ok(!ret, "expected failure\n");
1470 ok(GetLastError() == ERROR_NOT_A_REPARSE_POINT, "wrong error %lu\n", GetLastError());
1471 SetLastError(0xdeadbeef);
1472 ret = GetVolumeInformationA( "C:\\winetest_link\\windows\\", NULL, 0, NULL, NULL, NULL, NULL, 0 );
1473 ok(!ret, "expected failure\n");
1474 ok(GetLastError() == ERROR_DIR_NOT_ROOT, "wrong error %lu\n", GetLastError());
1476 ret = GetVolumePathNameA( "C:\\winetest_link\\winetest_mnt", path, sizeof(path) );
1477 ok(ret, "got error %lu\n", GetLastError());
1478 ok(!strcmp(path, "C:\\winetest_link\\winetest_mnt\\"), "got %s\n", debugstr_a(path));
1479 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_link\\winetest_mnt\\", path, sizeof(path) );
1480 ok(ret, "got error %lu\n", GetLastError());
1481 ok(!strcmp(path, volume_name), "expected %s, got %s\n", debugstr_a(volume_name), debugstr_a(path));
1482 ret = GetVolumeInformationA( "C:\\winetest_link\\winetest_mnt\\", NULL, 0, NULL, NULL, NULL, NULL, 0 );
1483 ok(ret, "got error %lu\n", GetLastError());
1485 /* The following test makes it clear that when we encounter a symlink
1486 * while resolving, we resolve *every* junction in the path, i.e. both
1487 * mount points and symlinks. */
1488 ret = GetVolumePathNameA( "C:\\winetest_link\\winetest_mnt\\winetest_link\\windows\\", path, sizeof(path) );
1489 ok(ret, "got error %lu\n", GetLastError());
1490 ok(!strcmp(path, "C:\\") || !strcmp(path, "C:\\winetest_link\\winetest_mnt\\") /* 2008 */,
1491 "got %s\n", debugstr_a(path));
1493 file = CreateFileA( "C:\\winetest_link\\winetest_mnt\\winetest_link\\windows\\", 0,
1494 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
1495 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
1497 status = NtQueryInformationFile( file, &io, name, sizeof(name_buffer), FileNameInformation );
1498 ok(!status, "got status %#lx\n", status);
1499 ok(name->FileNameLength == wcslen(L"\\windows") * sizeof(WCHAR), "got length %lu\n", name->FileNameLength);
1500 ok(!wcsnicmp(name->FileName, L"\\windows", wcslen(L"\\windows")), "got name %s\n",
1501 debugstr_wn(name->FileName, name->FileNameLength / sizeof(WCHAR)));
1503 CloseHandle( file );
1505 ret = RemoveDirectoryA( "C:\\winetest_link\\" );
1506 ok(ret, "got error %lu\n", GetLastError());
1508 /* The following cannot be automatically tested:
1510 * Suppose C: and D: are mount points of different volumes. If C:/a is
1511 * symlinked to D:/b, GetVolumePathName("C:\\a") will return "D:\\" if
1512 * "a" is a directory, but "C:\\" if "a" is a file.
1513 * Moreover, if D: is mounted at C:/mnt, and C:/a is symlinked to
1514 * C:/mnt, GetVolumePathName("C:\\mnt\\b") will still return "D:\\". */
1517 ret = DeleteVolumeMountPointA( "C:\\winetest_mnt\\" );
1518 ok(ret, "got error %lu\n", GetLastError());
1519 ret = RemoveDirectoryA( "C:\\winetest_mnt" );
1520 ok(ret, "got error %lu\n", GetLastError());
1523 static void test_GetVolumeInformationByHandle(void)
1525 char DECLSPEC_ALIGN(8) buffer[50];
1526 FILE_FS_ATTRIBUTE_INFORMATION *attr_info = (void *)buffer;
1527 FILE_FS_VOLUME_INFORMATION *volume_info = (void *)buffer;
1528 DWORD serial, filename_len, flags;
1529 WCHAR label[20], fsname[20];
1530 char volume[MAX_PATH+1];
1531 IO_STATUS_BLOCK io;
1532 HANDLE file;
1533 NTSTATUS status;
1534 BOOL ret;
1536 if (!pGetVolumeInformationByHandleW)
1538 win_skip("GetVolumeInformationByHandleW is not present.\n");
1539 return;
1542 file = CreateFileA( "C:/windows", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1543 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
1544 ok(file != INVALID_HANDLE_VALUE, "failed to open file, error %lu\n", GetLastError());
1546 SetLastError(0xdeadbeef);
1547 ret = pGetVolumeInformationByHandleW( INVALID_HANDLE_VALUE, label, ARRAY_SIZE(label), &serial,
1548 &filename_len, &flags, fsname, ARRAY_SIZE(fsname) );
1549 ok(!ret, "expected failure\n");
1550 ok(GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError());
1552 ret = pGetVolumeInformationByHandleW( file, NULL, 0, NULL, NULL, NULL, NULL, 0 );
1553 ok(ret, "got error %lu\n", GetLastError());
1555 ret = pGetVolumeInformationByHandleW( file, label, ARRAY_SIZE(label), &serial,
1556 &filename_len, &flags, fsname, ARRAY_SIZE(fsname) );
1557 ok(ret, "got error %lu\n", GetLastError());
1559 memset(buffer, 0, sizeof(buffer));
1560 status = NtQueryVolumeInformationFile( file, &io, buffer, sizeof(buffer), FileFsAttributeInformation );
1561 ok(!status, "got status %#lx\n", status);
1562 ok(flags == attr_info->FileSystemAttributes, "expected flags %#lx, got %#lx\n",
1563 attr_info->FileSystemAttributes, flags);
1564 ok(filename_len == attr_info->MaximumComponentNameLength, "expected filename_len %lu, got %lu\n",
1565 attr_info->MaximumComponentNameLength, filename_len);
1566 ok(!wcscmp( fsname, attr_info->FileSystemName ), "expected fsname %s, got %s\n",
1567 debugstr_w( attr_info->FileSystemName ), debugstr_w( fsname ));
1568 ok(wcslen( fsname ) == attr_info->FileSystemNameLength / sizeof(WCHAR), "got %Iu\n", wcslen( fsname ));
1570 SetLastError(0xdeadbeef);
1571 ret = pGetVolumeInformationByHandleW( file, NULL, 0, NULL, &filename_len, &flags, fsname, 2 );
1572 ok(!ret, "expected failure\n");
1573 ok(GetLastError() == ERROR_BAD_LENGTH, "got error %lu\n", GetLastError());
1575 memset(buffer, 0, sizeof(buffer));
1576 status = NtQueryVolumeInformationFile( file, &io, buffer, sizeof(buffer), FileFsVolumeInformation );
1577 ok(!status, "got status %#lx\n", status);
1578 ok(serial == volume_info->VolumeSerialNumber, "expected serial %08lx, got %08lx\n",
1579 volume_info->VolumeSerialNumber, serial);
1580 ok(!wcscmp( label, volume_info->VolumeLabel ), "expected label %s, got %s\n",
1581 debugstr_w( volume_info->VolumeLabel ), debugstr_w( label ));
1582 ok(wcslen( label ) == volume_info->VolumeLabelLength / sizeof(WCHAR), "got %Iu\n", wcslen( label ));
1584 CloseHandle( file );
1586 /* get the unique volume name for the windows drive */
1587 ret = GetVolumeNameForVolumeMountPointA("C:\\", volume, MAX_PATH);
1588 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
1590 /* try again with unique volume name */
1592 file = CreateFileA( volume, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1593 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
1594 ok(file != INVALID_HANDLE_VALUE, "failed to open file, error %lu\n", GetLastError());
1596 ret = pGetVolumeInformationByHandleW( file, label, ARRAY_SIZE(label), &serial,
1597 &filename_len, &flags, fsname, ARRAY_SIZE(fsname) );
1598 ok(ret, "got error %lu\n", GetLastError());
1600 memset(buffer, 0, sizeof(buffer));
1601 status = NtQueryVolumeInformationFile( file, &io, buffer, sizeof(buffer), FileFsVolumeInformation );
1602 ok(!status, "got status %#lx\n", status);
1603 ok(serial == volume_info->VolumeSerialNumber, "expected serial %08lx, got %08lx\n",
1604 volume_info->VolumeSerialNumber, serial);
1605 ok(!wcscmp( label, volume_info->VolumeLabel ), "expected label %s, got %s\n",
1606 debugstr_w( volume_info->VolumeLabel ), debugstr_w( label ));
1607 ok(wcslen( label ) == volume_info->VolumeLabelLength / sizeof(WCHAR), "got %Iu\n", wcslen( label ));
1609 memset(buffer, 0, sizeof(buffer));
1610 status = NtQueryVolumeInformationFile( file, &io, buffer, sizeof(buffer), FileFsAttributeInformation );
1611 ok(!status, "got status %#lx\n", status);
1612 ok(flags == attr_info->FileSystemAttributes, "expected flags %#lx, got %#lx\n",
1613 attr_info->FileSystemAttributes, flags);
1614 ok(filename_len == attr_info->MaximumComponentNameLength, "expected filename_len %lu, got %lu\n",
1615 attr_info->MaximumComponentNameLength, filename_len);
1616 ok(!wcscmp( fsname, attr_info->FileSystemName ), "expected fsname %s, got %s\n",
1617 debugstr_w( attr_info->FileSystemName ), debugstr_w( fsname ));
1618 ok(wcslen( fsname ) == attr_info->FileSystemNameLength / sizeof(WCHAR), "got %Iu\n", wcslen( fsname ));
1620 CloseHandle( file );
1623 static void test_mountmgr_query_points(void)
1625 char input_buffer[64];
1626 MOUNTMGR_MOUNT_POINTS *output;
1627 MOUNTMGR_MOUNT_POINT *input = (MOUNTMGR_MOUNT_POINT *)input_buffer;
1628 IO_STATUS_BLOCK io;
1629 NTSTATUS status;
1630 HANDLE file;
1632 output = malloc(1024);
1634 file = CreateFileW( MOUNTMGR_DOS_DEVICE_NAME, 0, 0, NULL, OPEN_EXISTING, 0, NULL );
1635 ok(file != INVALID_HANDLE_VALUE, "failed to open mountmgr, error %lu\n", GetLastError());
1637 io.Status = 0xdeadf00d;
1638 io.Information = 0xdeadf00d;
1639 status = NtDeviceIoControlFile( file, NULL, NULL, NULL, &io,
1640 IOCTL_MOUNTMGR_QUERY_POINTS, NULL, 0, NULL, 0 );
1641 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
1642 ok(io.Status == 0xdeadf00d, "got status %#lx\n", io.Status);
1643 ok(io.Information == 0xdeadf00d, "got information %#Ix\n", io.Information);
1645 memset( input, 0, sizeof(*input) );
1647 io.Status = 0xdeadf00d;
1648 io.Information = 0xdeadf00d;
1649 status = NtDeviceIoControlFile( file, NULL, NULL, NULL, &io,
1650 IOCTL_MOUNTMGR_QUERY_POINTS, input, sizeof(*input) - 1, NULL, 0 );
1651 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
1652 ok(io.Status == 0xdeadf00d, "got status %#lx\n", io.Status);
1653 ok(io.Information == 0xdeadf00d, "got information %#Ix\n", io.Information);
1655 io.Status = 0xdeadf00d;
1656 io.Information = 0xdeadf00d;
1657 status = NtDeviceIoControlFile( file, NULL, NULL, NULL, &io,
1658 IOCTL_MOUNTMGR_QUERY_POINTS, input, sizeof(*input), NULL, 0 );
1659 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
1660 ok(io.Status == 0xdeadf00d, "got status %#lx\n", io.Status);
1661 ok(io.Information == 0xdeadf00d, "got information %#Ix\n", io.Information);
1663 io.Status = 0xdeadf00d;
1664 io.Information = 0xdeadf00d;
1665 memset(output, 0xcc, sizeof(*output));
1666 status = NtDeviceIoControlFile( file, NULL, NULL, NULL, &io,
1667 IOCTL_MOUNTMGR_QUERY_POINTS, input, sizeof(*input), output, sizeof(*output) - 1 );
1668 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
1669 ok(io.Status == 0xdeadf00d, "got status %#lx\n", io.Status);
1670 ok(io.Information == 0xdeadf00d, "got information %#Ix\n", io.Information);
1671 ok(output->Size == 0xcccccccc, "got size %lu\n", output->Size);
1672 ok(output->NumberOfMountPoints == 0xcccccccc, "got count %lu\n", output->NumberOfMountPoints);
1674 io.Status = 0xdeadf00d;
1675 io.Information = 0xdeadf00d;
1676 memset(output, 0xcc, sizeof(*output));
1677 status = NtDeviceIoControlFile( file, NULL, NULL, NULL, &io,
1678 IOCTL_MOUNTMGR_QUERY_POINTS, input, sizeof(*input), output, sizeof(*output) );
1679 ok(status == STATUS_BUFFER_OVERFLOW, "got %#lx\n", status);
1680 ok(io.Status == STATUS_BUFFER_OVERFLOW, "got status %#lx\n", io.Status);
1681 todo_wine ok(io.Information == offsetof(MOUNTMGR_MOUNT_POINTS, MountPoints[0]), "got information %#Ix\n", io.Information);
1682 ok(output->Size > offsetof(MOUNTMGR_MOUNT_POINTS, MountPoints[0]), "got size %lu\n", output->Size);
1683 todo_wine ok(output->NumberOfMountPoints && output->NumberOfMountPoints != 0xcccccccc,
1684 "got count %lu\n", output->NumberOfMountPoints);
1686 output = realloc(output, output->Size);
1688 io.Status = 0xdeadf00d;
1689 io.Information = 0xdeadf00d;
1690 status = NtDeviceIoControlFile( file, NULL, NULL, NULL, &io,
1691 IOCTL_MOUNTMGR_QUERY_POINTS, input, sizeof(*input), output, output->Size );
1692 ok(!status, "got %#lx\n", status);
1693 ok(!io.Status, "got status %#lx\n", io.Status);
1694 ok(io.Information == output->Size, "got size %lu, information %#Ix\n", output->Size, io.Information);
1695 ok(output->Size > offsetof(MOUNTMGR_MOUNT_POINTS, MountPoints[0]), "got size %lu\n", output->Size);
1696 ok(output->NumberOfMountPoints && output->NumberOfMountPoints != 0xcccccccc,
1697 "got count %lu\n", output->NumberOfMountPoints);
1699 CloseHandle( file );
1701 free(output);
1704 START_TEST(volume)
1706 hdll = GetModuleHandleA("kernel32.dll");
1707 pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
1708 pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
1709 pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
1710 pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
1711 pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
1712 pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA");
1713 pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW");
1714 pCreateSymbolicLinkA = (void *) GetProcAddress(hdll, "CreateSymbolicLinkA");
1715 pGetVolumeInformationByHandleW = (void *) GetProcAddress(hdll, "GetVolumeInformationByHandleW");
1717 test_query_dos_deviceA();
1718 test_dos_devices();
1719 test_FindFirstVolume();
1720 test_GetVolumePathNameA();
1721 test_GetVolumePathNameW();
1722 test_GetVolumeNameForVolumeMountPointA();
1723 test_GetVolumeNameForVolumeMountPointW();
1724 test_GetLogicalDriveStringsA();
1725 test_GetLogicalDriveStringsW();
1726 test_GetVolumeInformationA();
1727 test_enum_vols();
1728 test_disk_extents();
1729 test_disk_query_property();
1730 test_GetVolumePathNamesForVolumeNameA();
1731 test_GetVolumePathNamesForVolumeNameW();
1732 test_cdrom_ioctl();
1733 test_mounted_folder();
1734 test_GetVolumeInformationByHandle();
1735 test_mountmgr_query_points();