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 "wine/test.h"
26 static HINSTANCE hdll;
27 static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointA)(LPCSTR, LPSTR, DWORD);
28 static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointW)(LPCWSTR, LPWSTR, DWORD);
29 static HANDLE (WINAPI *pFindFirstVolumeA)(LPSTR,DWORD);
30 static BOOL (WINAPI *pFindNextVolumeA)(HANDLE,LPSTR,DWORD);
31 static BOOL (WINAPI *pFindVolumeClose)(HANDLE);
32 static UINT (WINAPI *pGetLogicalDriveStringsA)(UINT,LPSTR);
33 static UINT (WINAPI *pGetLogicalDriveStringsW)(UINT,LPWSTR);
34 static BOOL (WINAPI *pGetVolumeInformationA)(LPCSTR, LPSTR, DWORD, LPDWORD, LPDWORD, LPDWORD, LPSTR, DWORD);
35 static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameA)(LPCSTR, LPSTR, DWORD, LPDWORD);
36 static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameW)(LPCWSTR, LPWSTR, DWORD, LPDWORD);
38 /* ############################### */
40 static void test_query_dos_deviceA(void)
42 char drivestr[] = "a:";
43 char *p, *buffer, buffer2[2000];
44 DWORD ret, ret2, buflen=32768;
47 buffer = HeapAlloc( GetProcessHeap(), 0, buflen );
48 SetLastError(0xdeadbeef);
49 ret = QueryDosDeviceA( NULL, buffer, buflen );
50 ok((ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER),
51 "QueryDosDeviceA failed to return list, last error %u\n", GetLastError());
53 if (ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
56 if (!strlen(p)) break;
57 ret2 = QueryDosDeviceA( p, buffer2, sizeof(buffer2) );
58 ok(ret2, "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", p, GetLastError());
60 if (ret <= (p-buffer)) break;
64 for (;drivestr[0] <= 'z'; drivestr[0]++) {
65 /* Older W2K fails with ERROR_INSUFFICIENT_BUFFER when buflen is > 32767 */
66 ret = QueryDosDeviceA( drivestr, buffer, buflen - 1);
67 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
68 "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", drivestr, GetLastError());
70 for (p = buffer; *p; p++) *p = toupper(*p);
71 if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE;
74 ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
75 HeapFree( GetProcessHeap(), 0, buffer );
78 static void test_define_dos_deviceA(void)
84 /* Find an unused drive letter */
87 for (drivestr[0] = 'a'; drivestr[0] <= 'z'; drivestr[0]++) {
88 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf));
91 if (drivestr[0] > 'z') {
92 skip("can't test creating a dos drive, none available\n");
96 /* Map it to point to the current directory */
97 ret = GetCurrentDirectory(sizeof(buf), buf);
98 ok(ret, "GetCurrentDir\n");
100 ret = DefineDosDeviceA(0, drivestr, buf);
102 ok(ret, "Could not make drive %s point to %s!\n", drivestr, buf);
105 skip("can't test removing fake drive\n");
107 ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL);
108 ok(ret, "Could not remove fake drive %s!\n", drivestr);
112 static void test_FindFirstVolume(void)
117 /* not present before w2k */
118 if (!pFindFirstVolumeA) {
119 win_skip("FindFirstVolumeA not found\n");
123 handle = pFindFirstVolumeA( volume, 0 );
124 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
125 ok( GetLastError() == ERROR_MORE_DATA || /* XP */
126 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Vista */
127 "wrong error %u\n", GetLastError() );
128 handle = pFindFirstVolumeA( volume, 49 );
129 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
130 ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE, "wrong error %u\n", GetLastError() );
131 handle = pFindFirstVolumeA( volume, 51 );
132 ok( handle != INVALID_HANDLE_VALUE, "failed err %u\n", GetLastError() );
133 if (handle != INVALID_HANDLE_VALUE)
137 ok( strlen(volume) == 49, "bad volume name %s\n", volume );
138 ok( !memcmp( volume, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume );
139 ok( !memcmp( volume + 47, "}\\", 2 ), "bad volume name %s\n", volume );
140 } while (pFindNextVolumeA( handle, volume, MAX_PATH ));
141 ok( GetLastError() == ERROR_NO_MORE_FILES, "wrong error %u\n", GetLastError() );
142 pFindVolumeClose( handle );
146 static void test_GetVolumeNameForVolumeMountPointA(void)
149 char volume[MAX_PATH], path[] = "c:\\";
150 DWORD len = sizeof(volume), reti;
151 char temp_path[MAX_PATH];
153 /* not present before w2k */
154 if (!pGetVolumeNameForVolumeMountPointA) {
155 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
159 reti = GetTempPathA(MAX_PATH, temp_path);
160 ok(reti != 0, "GetTempPathA error %d\n", GetLastError());
161 ok(reti < MAX_PATH, "temp path should fit into MAX_PATH\n");
163 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 0);
164 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
165 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
166 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
167 "wrong error, last=%d\n", GetLastError());
169 if (0) { /* these crash on XP */
170 ret = pGetVolumeNameForVolumeMountPointA(path, NULL, len);
171 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
173 ret = pGetVolumeNameForVolumeMountPointA(NULL, volume, len);
174 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
177 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
178 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
179 ok(!strncmp( volume, "\\\\?\\Volume{", 11),
180 "GetVolumeNameForVolumeMountPointA failed to return valid string <%s>\n",
183 /* test with too small buffer */
184 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 10);
185 ok(ret == FALSE && GetLastError() == ERROR_FILENAME_EXCED_RANGE,
186 "GetVolumeNameForVolumeMountPointA failed, wrong error returned, was %d, should be ERROR_FILENAME_EXCED_RANGE\n",
189 /* Try on a arbitrary directory */
190 /* On FAT filesystems it seems that GetLastError() is set to
191 ERROR_INVALID_FUNCTION. */
192 ret = pGetVolumeNameForVolumeMountPointA(temp_path, volume, len);
193 ok(ret == FALSE && (GetLastError() == ERROR_NOT_A_REPARSE_POINT ||
194 GetLastError() == ERROR_INVALID_FUNCTION),
195 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
196 temp_path, GetLastError());
198 /* Try on a nonexistent dos drive */
200 for (;path[0] <= 'z'; path[0]++) {
201 ret = QueryDosDeviceA( path, volume, len);
207 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
208 ok(ret == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND,
209 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
210 path, GetLastError());
212 /* Try without trailing \ and on a nonexistent dos drive */
214 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
215 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
216 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
217 path, GetLastError());
221 static void test_GetVolumeNameForVolumeMountPointW(void)
224 WCHAR volume[MAX_PATH], path[] = {'c',':','\\',0};
225 DWORD len = sizeof(volume) / sizeof(WCHAR);
227 /* not present before w2k */
228 if (!pGetVolumeNameForVolumeMountPointW) {
229 win_skip("GetVolumeNameForVolumeMountPointW not found\n");
233 ret = pGetVolumeNameForVolumeMountPointW(path, volume, 0);
234 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
235 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
236 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
237 "wrong error, last=%d\n", GetLastError());
239 if (0) { /* these crash on XP */
240 ret = pGetVolumeNameForVolumeMountPointW(path, NULL, len);
241 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
243 ret = pGetVolumeNameForVolumeMountPointW(NULL, volume, len);
244 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
247 ret = pGetVolumeNameForVolumeMountPointW(path, volume, len);
248 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n");
251 static void test_GetLogicalDriveStringsA(void)
256 ok( pGetLogicalDriveStringsA != NULL, "GetLogicalDriveStringsA not available\n");
257 if(!pGetLogicalDriveStringsA) {
261 size = pGetLogicalDriveStringsA(0, NULL);
262 ok(size%4 == 1, "size = %d\n", size);
264 buf = HeapAlloc(GetProcessHeap(), 0, size);
267 size2 = pGetLogicalDriveStringsA(2, buf);
268 ok(size2 == size, "size2 = %d\n", size2);
269 ok(!*buf, "buf changed\n");
271 size2 = pGetLogicalDriveStringsA(size, buf);
272 ok(size2 == size-1, "size2 = %d\n", size2);
274 for(ptr = buf; ptr < buf+size2; ptr += 4) {
275 ok(('A' <= *ptr && *ptr <= 'Z'), "device name '%c' is not uppercase\n", *ptr);
276 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
277 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
278 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
280 ok(!*ptr, "buf[size2] is not nullbyte\n");
282 HeapFree(GetProcessHeap(), 0, buf);
285 static void test_GetLogicalDriveStringsW(void)
290 ok( pGetLogicalDriveStringsW != NULL, "GetLogicalDriveStringsW not available\n");
291 if(!pGetLogicalDriveStringsW) {
295 SetLastError(0xdeadbeef);
296 size = pGetLogicalDriveStringsW(0, NULL);
297 if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
298 win_skip("GetLogicalDriveStringsW not implemented\n");
301 ok(size%4 == 1, "size = %d\n", size);
303 buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
306 size2 = pGetLogicalDriveStringsW(2, buf);
307 ok(size2 == size, "size2 = %d\n", size2);
308 ok(!*buf, "buf changed\n");
310 size2 = pGetLogicalDriveStringsW(size, buf);
311 ok(size2 == size-1, "size2 = %d\n", size2);
313 for(ptr = buf; ptr < buf+size2; ptr += 4) {
314 ok('A' <= *ptr && *ptr <= 'Z', "device name '%c' is not uppercase\n", *ptr);
315 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
316 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
317 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
319 ok(!*ptr, "buf[size2] is not nullbyte\n");
321 HeapFree(GetProcessHeap(), 0, buf);
324 static void test_GetVolumeInformationA(void)
328 char Root_Colon[]="C:";
329 char Root_Slash[]="C:\\";
330 char Root_UNC[]="\\\\?\\C:\\";
331 char volume[MAX_PATH+1];
332 DWORD vol_name_size=MAX_PATH+1, vol_serial_num=-1, max_comp_len=0, fs_flags=0, fs_name_len=MAX_PATH+1;
333 char vol_name_buf[MAX_PATH+1], fs_name_buf[MAX_PATH+1];
334 char windowsdir[MAX_PATH+10];
335 char currentdir[MAX_PATH+1];
337 ok( pGetVolumeInformationA != NULL, "GetVolumeInformationA not found\n");
338 if(!pGetVolumeInformationA) {
342 /* get windows drive letter and update strings for testing */
343 result = GetWindowsDirectory(windowsdir, sizeof(windowsdir));
344 ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
345 ok(result != 0, "GetWindowsDirectory: error %d\n", GetLastError());
346 Root_Colon[0] = windowsdir[0];
347 Root_Slash[0] = windowsdir[0];
348 Root_UNC[4] = windowsdir[0];
350 result = GetCurrentDirectory(MAX_PATH, currentdir);
351 ok(result, "GetCurrentDirectory: error %d\n", GetLastError());
352 /* Note that GetCurrentDir yields no trailing slash for subdirs */
354 /* check for NO error on no trailing \ when current dir is root dir */
355 ret = SetCurrentDirectory(Root_Slash);
356 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
357 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
358 NULL, NULL, fs_name_buf, fs_name_len);
359 ok(ret, "GetVolumeInformationA root failed, last error %u\n", GetLastError());
361 /* check for error on no trailing \ when current dir is subdir (windows) of queried drive */
362 ret = SetCurrentDirectory(windowsdir);
363 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
364 SetLastError(0xdeadbeef);
365 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
366 NULL, NULL, fs_name_buf, fs_name_len);
367 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
368 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
370 /* reset current directory */
371 ret = SetCurrentDirectory(currentdir);
372 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
374 if (toupper(currentdir[0]) == toupper(windowsdir[0])) {
375 skip("Please re-run from another device than %c:\n", windowsdir[0]);
376 /* FIXME: Use GetLogicalDrives to find another device to avoid this skip. */
378 char Root_Env[]="=C:"; /* where MS maintains the per volume directory */
379 Root_Env[1] = windowsdir[0];
381 /* C:\windows becomes the current directory on drive C: */
382 /* Note that paths to subdirs are stored without trailing slash, like what GetCurrentDir yields. */
383 ret = SetEnvironmentVariable(Root_Env, windowsdir);
384 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
386 ret = SetCurrentDirectory(windowsdir);
387 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
388 ret = SetCurrentDirectory(currentdir);
389 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
391 /* windows dir is current on the root drive, call fails */
392 SetLastError(0xdeadbeef);
393 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
394 NULL, NULL, fs_name_buf, fs_name_len);
395 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
396 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
398 /* Try normal drive letter with trailing \ */
399 ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size, NULL,
400 NULL, NULL, fs_name_buf, fs_name_len);
401 ok(ret, "GetVolumeInformationA with \\ failed, last error %u\n", GetLastError());
403 ret = SetCurrentDirectory(Root_Slash);
404 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
405 ret = SetCurrentDirectory(currentdir);
406 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
408 /* windows dir is STILL CURRENT on root drive; the call fails as before, */
409 /* proving that SetCurrentDir did not remember the other drive's directory */
410 SetLastError(0xdeadbeef);
411 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
412 NULL, NULL, fs_name_buf, fs_name_len);
413 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
414 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
416 /* Now C:\ becomes the current directory on drive C: */
417 ret = SetEnvironmentVariable(Root_Env, Root_Slash); /* set =C:=C:\ */
418 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
420 /* \ is current on root drive, call succeeds */
421 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
422 NULL, NULL, fs_name_buf, fs_name_len);
423 ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
425 /* again, SetCurrentDirectory on another drive does not matter */
426 ret = SetCurrentDirectory(Root_Slash);
427 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
428 ret = SetCurrentDirectory(currentdir);
429 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
431 /* \ is current on root drive, call succeeds */
432 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
433 NULL, NULL, fs_name_buf, fs_name_len);
434 ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
437 /* try null root directory to return "root of the current directory" */
438 ret = pGetVolumeInformationA(NULL, vol_name_buf, vol_name_size, NULL,
439 NULL, NULL, fs_name_buf, fs_name_len);
440 ok(ret, "GetVolumeInformationA failed on null root dir, last error %u\n", GetLastError());
442 /* Try normal drive letter with trailing \ */
443 ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size,
444 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
445 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Slash, GetLastError());
447 /* try again with drive letter and the "disable parsing" prefix */
448 SetLastError(0xdeadbeef);
449 ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
450 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
451 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
453 /* try again with device name space */
455 SetLastError(0xdeadbeef);
456 ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
457 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
458 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
460 /* try again with a directory off the root - should generate error */
461 if (windowsdir[strlen(windowsdir)-1] != '\\') strcat(windowsdir, "\\");
462 SetLastError(0xdeadbeef);
463 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
464 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
465 ok(!ret && (GetLastError()==ERROR_DIR_NOT_ROOT),
466 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
467 /* A subdir with trailing \ yields DIR_NOT_ROOT instead of INVALID_NAME */
468 if (windowsdir[strlen(windowsdir)-1] == '\\') windowsdir[strlen(windowsdir)-1] = 0;
469 SetLastError(0xdeadbeef);
470 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
471 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
472 ok(!ret && (GetLastError()==ERROR_INVALID_NAME),
473 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
475 if (!pGetVolumeNameForVolumeMountPointA) {
476 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
479 /* get the unique volume name for the windows drive */
480 ret = pGetVolumeNameForVolumeMountPointA(Root_Slash, volume, MAX_PATH);
481 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
483 /* try again with unique volume name */
484 ret = pGetVolumeInformationA(volume, vol_name_buf, vol_name_size,
485 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
486 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", volume, GetLastError());
489 /* Test to check that unique volume name from windows dir mount point */
490 /* matches at least one of the unique volume names returned from the */
491 /* FindFirstVolumeA/FindNextVolumeA list. */
492 static void test_enum_vols(void)
495 HANDLE hFind = INVALID_HANDLE_VALUE;
496 char Volume_1[MAX_PATH] = {0};
497 char Volume_2[MAX_PATH] = {0};
498 char path[] = "c:\\";
500 char windowsdir[MAX_PATH];
502 if (!pGetVolumeNameForVolumeMountPointA) {
503 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
507 /*get windows drive letter and update strings for testing */
508 ret = GetWindowsDirectory( windowsdir, sizeof(windowsdir) );
509 ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
510 ok(ret != 0, "GetWindowsDirecory: error %d\n", GetLastError());
511 path[0] = windowsdir[0];
513 /* get the unique volume name for the windows drive */
514 ret = pGetVolumeNameForVolumeMountPointA( path, Volume_1, MAX_PATH );
515 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
516 ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1);
518 /* get first unique volume name of list */
519 hFind = pFindFirstVolumeA( Volume_2, MAX_PATH );
520 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstVolume failed, err=%u\n",
525 /* validate correct length of unique volume name */
526 ok(strlen(Volume_2) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1);
527 if (memcmp(Volume_1, Volume_2, 49) == 0)
532 } while (pFindNextVolumeA( hFind, Volume_2, MAX_PATH ));
533 ok(found, "volume name %s not found by Find[First/Next]Volume\n", Volume_1);
534 pFindVolumeClose( hFind );
537 static void test_disk_extents(void)
542 static DWORD data[16];
544 handle = CreateFileA( "\\\\.\\c:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
545 if (handle == INVALID_HANDLE_VALUE)
547 win_skip("can't open c: drive %u\n", GetLastError());
551 ret = DeviceIoControl( handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, &data,
552 sizeof(data), &data, sizeof(data), &size, NULL );
553 if (!ret && GetLastError() == ERROR_INVALID_FUNCTION)
555 win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
556 CloseHandle( handle );
559 ok(ret, "DeviceIoControl failed %u\n", GetLastError());
560 ok(size == 32, "expected 32, got %u\n", size);
561 CloseHandle( handle );
564 static void test_GetVolumePathNamesForVolumeNameA(void)
567 char volume[MAX_PATH], buffer[MAX_PATH];
570 if (!pGetVolumePathNamesForVolumeNameA || !pGetVolumeNameForVolumeMountPointA)
572 win_skip("required functions not found\n");
576 ret = pGetVolumeNameForVolumeMountPointA( "c:\\", volume, sizeof(volume) );
577 ok(ret, "failed to get volume name %u\n", GetLastError());
578 trace("c:\\ -> %s\n", volume);
580 SetLastError( 0xdeadbeef );
581 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, NULL );
582 error = GetLastError();
583 ok(!ret, "expected failure\n");
584 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
586 SetLastError( 0xdeadbeef );
587 ret = pGetVolumePathNamesForVolumeNameA( "", NULL, 0, NULL );
588 error = GetLastError();
589 ok(!ret, "expected failure\n");
590 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
592 SetLastError( 0xdeadbeef );
593 ret = pGetVolumePathNamesForVolumeNameA( volume, NULL, 0, NULL );
594 error = GetLastError();
595 ok(!ret, "expected failure\n");
596 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
598 SetLastError( 0xdeadbeef );
599 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, 0, NULL );
600 error = GetLastError();
601 ok(!ret, "expected failure\n");
602 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
604 memset( buffer, 0xff, sizeof(buffer) );
605 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), NULL );
606 ok(ret, "failed to get path names %u\n", GetLastError());
607 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
608 ok(!buffer[4], "expected double null-terminated buffer\n");
611 SetLastError( 0xdeadbeef );
612 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, &len );
613 error = GetLastError();
614 ok(!ret, "expected failure\n");
615 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
618 SetLastError( 0xdeadbeef );
619 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, sizeof(buffer), &len );
620 error = GetLastError();
621 ok(!ret, "expected failure\n");
622 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
625 SetLastError( 0xdeadbeef );
626 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
627 error = GetLastError();
628 ok(!ret, "expected failure\n");
629 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
632 SetLastError( 0xdeadbeef );
633 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
634 error = GetLastError();
635 ok(!ret, "expected failure\n");
636 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
639 memset( buffer, 0xff, sizeof(buffer) );
640 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), &len );
641 ok(ret, "failed to get path names %u\n", GetLastError());
642 ok(len == 5 || broken(len == 2), "expected 5 got %u\n", len);
643 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
644 ok(!buffer[4], "expected double null-terminated buffer\n");
647 static void test_GetVolumePathNamesForVolumeNameW(void)
649 static const WCHAR empty[] = {0};
650 static const WCHAR drive_c[] = {'c',':','\\',0};
651 static const WCHAR volume_null[] = {'\\','\\','?','\\','V','o','l','u','m','e',
652 '{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0','0',
653 '-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',0};
655 WCHAR volume[MAX_PATH], buffer[MAX_PATH];
658 if (!pGetVolumePathNamesForVolumeNameW || !pGetVolumeNameForVolumeMountPointW)
660 win_skip("required functions not found\n");
664 ret = pGetVolumeNameForVolumeMountPointW( drive_c, volume, sizeof(volume)/sizeof(volume[0]) );
665 ok(ret, "failed to get volume name %u\n", GetLastError());
667 SetLastError( 0xdeadbeef );
668 ret = pGetVolumePathNamesForVolumeNameW( empty, NULL, 0, NULL );
669 error = GetLastError();
670 ok(!ret, "expected failure\n");
671 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
673 SetLastError( 0xdeadbeef );
674 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, 0, NULL );
675 error = GetLastError();
676 ok(!ret, "expected failure\n");
677 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
679 SetLastError( 0xdeadbeef );
680 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, 0, NULL );
681 error = GetLastError();
682 ok(!ret, "expected failure\n");
683 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
686 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, sizeof(buffer), NULL );
687 ok(ret, "failed to get path names %u\n", GetLastError());
690 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), NULL );
691 ok(ret, "failed to get path names %u\n", GetLastError());
694 memset( buffer, 0xff, sizeof(buffer) );
695 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
696 ok(ret, "failed to get path names %u\n", GetLastError());
697 ok(len == 5, "expected 5 got %u\n", len);
698 ok(!buffer[4], "expected double null-terminated buffer\n");
702 volume[lstrlenW( volume ) - 1] = 0;
703 SetLastError( 0xdeadbeef );
704 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
705 error = GetLastError();
706 ok(!ret, "expected failure\n");
707 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
712 SetLastError( 0xdeadbeef );
713 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
714 error = GetLastError();
715 ok(!ret, "expected failure\n");
716 todo_wine ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
719 lstrcpyW( volume, volume_null );
720 SetLastError( 0xdeadbeef );
721 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
722 error = GetLastError();
723 ok(!ret, "expected failure\n");
724 ok(error == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND got %u\n", error);
729 hdll = GetModuleHandleA("kernel32.dll");
730 pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointA");
731 pGetVolumeNameForVolumeMountPointW = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointW");
732 pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
733 pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
734 pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
735 pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
736 pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
737 pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
738 pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA");
739 pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW");
741 test_query_dos_deviceA();
742 test_define_dos_deviceA();
743 test_FindFirstVolume();
744 test_GetVolumeNameForVolumeMountPointA();
745 test_GetVolumeNameForVolumeMountPointW();
746 test_GetLogicalDriveStringsA();
747 test_GetLogicalDriveStringsW();
748 test_GetVolumeInformationA();
751 test_GetVolumePathNamesForVolumeNameA();
752 test_GetVolumePathNamesForVolumeNameW();