f4a0f143c7dd62968d6da3f2ceb8c138c938de8f
[reactos.git] / rostests / winetests / kernel32 / volume.c
1 /*
2 * Unit test suite for volume functions
3 *
4 * Copyright 2006 Stefan Leichter
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "wine/test.h"
22 #include "winbase.h"
23 #include "winioctl.h"
24 #include <stdio.h>
25
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);
37
38 /* ############################### */
39
40 static void test_query_dos_deviceA(void)
41 {
42 char drivestr[] = "a:";
43 char *p, *buffer, buffer2[2000];
44 DWORD ret, ret2, buflen=32768;
45 BOOL found = FALSE;
46
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());
52
53 if (ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
54 p = buffer;
55 for (;;) {
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());
59 p += strlen(p) + 1;
60 if (ret <= (p-buffer)) break;
61 }
62 }
63
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());
69 if(ret) {
70 for (p = buffer; *p; p++) *p = toupper(*p);
71 if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE;
72 }
73 }
74 ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
75 HeapFree( GetProcessHeap(), 0, buffer );
76 }
77
78 static void test_define_dos_deviceA(void)
79 {
80 char drivestr[3];
81 char buf[MAX_PATH];
82 DWORD ret;
83
84 /* Find an unused drive letter */
85 drivestr[1] = ':';
86 drivestr[2] = 0;
87 for (drivestr[0] = 'a'; drivestr[0] <= 'z'; drivestr[0]++) {
88 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf));
89 if (!ret) break;
90 }
91 if (drivestr[0] > 'z') {
92 skip("can't test creating a dos drive, none available\n");
93 return;
94 }
95
96 /* Map it to point to the current directory */
97 ret = GetCurrentDirectory(sizeof(buf), buf);
98 ok(ret, "GetCurrentDir\n");
99
100 ret = DefineDosDeviceA(0, drivestr, buf);
101 todo_wine
102 ok(ret, "Could not make drive %s point to %s!\n", drivestr, buf);
103
104 if (!ret) {
105 skip("can't test removing fake drive\n");
106 } else {
107 ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL);
108 ok(ret, "Could not remove fake drive %s!\n", drivestr);
109 }
110 }
111
112 static void test_FindFirstVolume(void)
113 {
114 char volume[51];
115 HANDLE handle;
116
117 /* not present before w2k */
118 if (!pFindFirstVolumeA) {
119 win_skip("FindFirstVolumeA not found\n");
120 return;
121 }
122
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)
134 {
135 do
136 {
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 );
143 }
144 }
145
146 static void test_GetVolumeNameForVolumeMountPointA(void)
147 {
148 BOOL ret;
149 char volume[MAX_PATH], path[] = "c:\\";
150 DWORD len = sizeof(volume), reti;
151 char temp_path[MAX_PATH];
152
153 /* not present before w2k */
154 if (!pGetVolumeNameForVolumeMountPointA) {
155 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
156 return;
157 }
158
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");
162
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());
168
169 if (0) { /* these crash on XP */
170 ret = pGetVolumeNameForVolumeMountPointA(path, NULL, len);
171 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
172
173 ret = pGetVolumeNameForVolumeMountPointA(NULL, volume, len);
174 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
175 }
176
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",
181 volume);
182
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",
187 GetLastError());
188
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());
197
198 /* Try on a nonexistent dos drive */
199 path[2] = 0;
200 for (;path[0] <= 'z'; path[0]++) {
201 ret = QueryDosDeviceA( path, volume, len);
202 if(!ret) break;
203 }
204 if (path[0] <= 'z')
205 {
206 path[2] = '\\';
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());
211
212 /* Try without trailing \ and on a nonexistent dos drive */
213 path[2] = 0;
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());
218 }
219 }
220
221 static void test_GetVolumeNameForVolumeMountPointW(void)
222 {
223 BOOL ret;
224 WCHAR volume[MAX_PATH], path[] = {'c',':','\\',0};
225 DWORD len = sizeof(volume) / sizeof(WCHAR);
226
227 /* not present before w2k */
228 if (!pGetVolumeNameForVolumeMountPointW) {
229 win_skip("GetVolumeNameForVolumeMountPointW not found\n");
230 return;
231 }
232
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());
238
239 if (0) { /* these crash on XP */
240 ret = pGetVolumeNameForVolumeMountPointW(path, NULL, len);
241 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
242
243 ret = pGetVolumeNameForVolumeMountPointW(NULL, volume, len);
244 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
245 }
246
247 ret = pGetVolumeNameForVolumeMountPointW(path, volume, len);
248 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n");
249 }
250
251 static void test_GetLogicalDriveStringsA(void)
252 {
253 UINT size, size2;
254 char *buf, *ptr;
255
256 ok( pGetLogicalDriveStringsA != NULL, "GetLogicalDriveStringsA not available\n");
257 if(!pGetLogicalDriveStringsA) {
258 return;
259 }
260
261 size = pGetLogicalDriveStringsA(0, NULL);
262 ok(size%4 == 1, "size = %d\n", size);
263
264 buf = HeapAlloc(GetProcessHeap(), 0, size);
265
266 *buf = 0;
267 size2 = pGetLogicalDriveStringsA(2, buf);
268 ok(size2 == size, "size2 = %d\n", size2);
269 ok(!*buf, "buf changed\n");
270
271 size2 = pGetLogicalDriveStringsA(size, buf);
272 ok(size2 == size-1, "size2 = %d\n", size2);
273
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]);
279 }
280 ok(!*ptr, "buf[size2] is not nullbyte\n");
281
282 HeapFree(GetProcessHeap(), 0, buf);
283 }
284
285 static void test_GetLogicalDriveStringsW(void)
286 {
287 UINT size, size2;
288 WCHAR *buf, *ptr;
289
290 ok( pGetLogicalDriveStringsW != NULL, "GetLogicalDriveStringsW not available\n");
291 if(!pGetLogicalDriveStringsW) {
292 return;
293 }
294
295 SetLastError(0xdeadbeef);
296 size = pGetLogicalDriveStringsW(0, NULL);
297 if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
298 win_skip("GetLogicalDriveStringsW not implemented\n");
299 return;
300 }
301 ok(size%4 == 1, "size = %d\n", size);
302
303 buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
304
305 *buf = 0;
306 size2 = pGetLogicalDriveStringsW(2, buf);
307 ok(size2 == size, "size2 = %d\n", size2);
308 ok(!*buf, "buf changed\n");
309
310 size2 = pGetLogicalDriveStringsW(size, buf);
311 ok(size2 == size-1, "size2 = %d\n", size2);
312
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]);
318 }
319 ok(!*ptr, "buf[size2] is not nullbyte\n");
320
321 HeapFree(GetProcessHeap(), 0, buf);
322 }
323
324 static void test_GetVolumeInformationA(void)
325 {
326 BOOL ret;
327 UINT result;
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];
336
337 ok( pGetVolumeInformationA != NULL, "GetVolumeInformationA not found\n");
338 if(!pGetVolumeInformationA) {
339 return;
340 }
341
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];
349
350 result = GetCurrentDirectory(MAX_PATH, currentdir);
351 ok(result, "GetCurrentDirectory: error %d\n", GetLastError());
352 /* Note that GetCurrentDir yields no trailing slash for subdirs */
353
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());
360
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());
369
370 /* reset current directory */
371 ret = SetCurrentDirectory(currentdir);
372 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
373
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. */
377 } else {
378 char Root_Env[]="=C:"; /* where MS maintains the per volume directory */
379 Root_Env[1] = windowsdir[0];
380
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);
385
386 ret = SetCurrentDirectory(windowsdir);
387 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
388 ret = SetCurrentDirectory(currentdir);
389 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
390
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());
397
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());
402
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());
407
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());
415
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);
419
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());
424
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());
430
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());
435 }
436
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());
441
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());
446
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());
452
453 /* try again with device name space */
454 Root_UNC[2] = '.';
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());
459
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());
474
475 if (!pGetVolumeNameForVolumeMountPointA) {
476 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
477 return;
478 }
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");
482
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());
487 }
488
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)
493 {
494 DWORD ret;
495 HANDLE hFind = INVALID_HANDLE_VALUE;
496 char Volume_1[MAX_PATH] = {0};
497 char Volume_2[MAX_PATH] = {0};
498 char path[] = "c:\\";
499 BOOL found = FALSE;
500 char windowsdir[MAX_PATH];
501
502 if (!pGetVolumeNameForVolumeMountPointA) {
503 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
504 return;
505 }
506
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];
512
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);
517
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",
521 GetLastError());
522 /* ReactOS */
523 if (hFind != INVALID_HANDLE_VALUE) {
524 do
525 {
526 /* validate correct length of unique volume name */
527 ok(strlen(Volume_2) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1);
528 if (memcmp(Volume_1, Volume_2, 49) == 0)
529 {
530 found = TRUE;
531 break;
532 }
533 } while (pFindNextVolumeA( hFind, Volume_2, MAX_PATH ));
534 ok(found, "volume name %s not found by Find[First/Next]Volume\n", Volume_1);
535 pFindVolumeClose( hFind );
536 }
537 }
538
539 static void test_disk_extents(void)
540 {
541 BOOL ret;
542 DWORD size;
543 HANDLE handle;
544 static DWORD data[16];
545
546 handle = CreateFileA( "\\\\.\\c:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
547 if (handle == INVALID_HANDLE_VALUE)
548 {
549 win_skip("can't open c: drive %u\n", GetLastError());
550 return;
551 }
552 size = 0;
553 ret = DeviceIoControl( handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, &data,
554 sizeof(data), &data, sizeof(data), &size, NULL );
555 if (!ret && GetLastError() == ERROR_INVALID_FUNCTION)
556 {
557 win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
558 CloseHandle( handle );
559 return;
560 }
561 ok(ret, "DeviceIoControl failed %u\n", GetLastError());
562 ok(size == 32, "expected 32, got %u\n", size);
563 CloseHandle( handle );
564 }
565
566 static void test_GetVolumePathNamesForVolumeNameA(void)
567 {
568 BOOL ret;
569 char volume[MAX_PATH], buffer[MAX_PATH];
570 DWORD len, error;
571
572 if (!pGetVolumePathNamesForVolumeNameA || !pGetVolumeNameForVolumeMountPointA)
573 {
574 win_skip("required functions not found\n");
575 return;
576 }
577
578 ret = pGetVolumeNameForVolumeMountPointA( "c:\\", volume, sizeof(volume) );
579 ok(ret, "failed to get volume name %u\n", GetLastError());
580 trace("c:\\ -> %s\n", volume);
581
582 SetLastError( 0xdeadbeef );
583 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, NULL );
584 error = GetLastError();
585 ok(!ret, "expected failure\n");
586 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
587
588 SetLastError( 0xdeadbeef );
589 ret = pGetVolumePathNamesForVolumeNameA( "", NULL, 0, NULL );
590 error = GetLastError();
591 ok(!ret, "expected failure\n");
592 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
593
594 SetLastError( 0xdeadbeef );
595 ret = pGetVolumePathNamesForVolumeNameA( volume, NULL, 0, NULL );
596 error = GetLastError();
597 ok(!ret, "expected failure\n");
598 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
599
600 SetLastError( 0xdeadbeef );
601 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, 0, NULL );
602 error = GetLastError();
603 ok(!ret, "expected failure\n");
604 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
605
606 memset( buffer, 0xff, sizeof(buffer) );
607 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), NULL );
608 ok(ret, "failed to get path names %u\n", GetLastError());
609 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
610 ok(!buffer[4], "expected double null-terminated buffer\n");
611
612 len = 0;
613 SetLastError( 0xdeadbeef );
614 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, &len );
615 error = GetLastError();
616 ok(!ret, "expected failure\n");
617 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
618
619 len = 0;
620 SetLastError( 0xdeadbeef );
621 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, sizeof(buffer), &len );
622 error = GetLastError();
623 ok(!ret, "expected failure\n");
624 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
625
626 len = 0;
627 SetLastError( 0xdeadbeef );
628 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
629 error = GetLastError();
630 ok(!ret, "expected failure\n");
631 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
632
633 len = 0;
634 SetLastError( 0xdeadbeef );
635 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
636 error = GetLastError();
637 ok(!ret, "expected failure\n");
638 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
639
640 len = 0;
641 memset( buffer, 0xff, sizeof(buffer) );
642 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), &len );
643 ok(ret, "failed to get path names %u\n", GetLastError());
644 ok(len == 5 || broken(len == 2), "expected 5 got %u\n", len);
645 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
646 ok(!buffer[4], "expected double null-terminated buffer\n");
647 }
648
649 static void test_GetVolumePathNamesForVolumeNameW(void)
650 {
651 static const WCHAR empty[] = {0};
652 static const WCHAR drive_c[] = {'c',':','\\',0};
653 static const WCHAR volume_null[] = {'\\','\\','?','\\','V','o','l','u','m','e',
654 '{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0','0',
655 '-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',0};
656 BOOL ret;
657 WCHAR volume[MAX_PATH], buffer[MAX_PATH];
658 DWORD len, error;
659
660 if (!pGetVolumePathNamesForVolumeNameW || !pGetVolumeNameForVolumeMountPointW)
661 {
662 win_skip("required functions not found\n");
663 return;
664 }
665
666 ret = pGetVolumeNameForVolumeMountPointW( drive_c, volume, sizeof(volume)/sizeof(volume[0]) );
667 ok(ret, "failed to get volume name %u\n", GetLastError());
668
669 SetLastError( 0xdeadbeef );
670 ret = pGetVolumePathNamesForVolumeNameW( empty, NULL, 0, NULL );
671 error = GetLastError();
672 ok(!ret, "expected failure\n");
673 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
674
675 SetLastError( 0xdeadbeef );
676 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, 0, NULL );
677 error = GetLastError();
678 ok(!ret, "expected failure\n");
679 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
680
681 SetLastError( 0xdeadbeef );
682 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, 0, NULL );
683 error = GetLastError();
684 ok(!ret, "expected failure\n");
685 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
686
687 if (0) { /* crash */
688 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, sizeof(buffer), NULL );
689 ok(ret, "failed to get path names %u\n", GetLastError());
690 }
691
692 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), NULL );
693 ok(ret, "failed to get path names %u\n", GetLastError());
694
695 len = 0;
696 memset( buffer, 0xff, sizeof(buffer) );
697 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
698 ok(ret, "failed to get path names %u\n", GetLastError());
699 ok(len == 5, "expected 5 got %u\n", len);
700 ok(!buffer[4], "expected double null-terminated buffer\n");
701
702 len = 0;
703 volume[1] = '?';
704 volume[lstrlenW( volume ) - 1] = 0;
705 SetLastError( 0xdeadbeef );
706 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
707 error = GetLastError();
708 ok(!ret, "expected failure\n");
709 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
710
711 len = 0;
712 volume[0] = '\\';
713 volume[1] = 0;
714 SetLastError( 0xdeadbeef );
715 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
716 error = GetLastError();
717 ok(!ret, "expected failure\n");
718 todo_wine ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
719
720 len = 0;
721 lstrcpyW( volume, volume_null );
722 SetLastError( 0xdeadbeef );
723 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
724 error = GetLastError();
725 ok(!ret, "expected failure\n");
726 ok(error == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND got %u\n", error);
727 }
728
729 START_TEST(volume)
730 {
731 hdll = GetModuleHandleA("kernel32.dll");
732 pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointA");
733 pGetVolumeNameForVolumeMountPointW = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointW");
734 pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
735 pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
736 pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
737 pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
738 pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
739 pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
740 pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA");
741 pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW");
742
743 test_query_dos_deviceA();
744 test_define_dos_deviceA();
745 test_FindFirstVolume();
746 test_GetVolumeNameForVolumeMountPointA();
747 test_GetVolumeNameForVolumeMountPointW();
748 test_GetLogicalDriveStringsA();
749 test_GetLogicalDriveStringsW();
750 test_GetVolumeInformationA();
751 test_enum_vols();
752 test_disk_extents();
753 test_GetVolumePathNamesForVolumeNameA();
754 test_GetVolumePathNamesForVolumeNameW();
755 }