[KERNEL32_WINETEST]
[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 /* callers must guess the buffer size */
48 SetLastError(0xdeadbeef);
49 ret = QueryDosDeviceA( NULL, NULL, 0 );
50 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
51 "QueryDosDeviceA(no buffer): returned %u, le=%u\n", ret, GetLastError());
52
53 buffer = HeapAlloc( GetProcessHeap(), 0, buflen );
54 SetLastError(0xdeadbeef);
55 ret = QueryDosDeviceA( NULL, buffer, buflen );
56 ok((ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER),
57 "QueryDosDeviceA failed to return list, last error %u\n", GetLastError());
58
59 if (ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
60 p = buffer;
61 for (;;) {
62 if (!strlen(p)) break;
63 ret2 = QueryDosDeviceA( p, buffer2, sizeof(buffer2) );
64 ok(ret2, "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", p, GetLastError());
65 p += strlen(p) + 1;
66 if (ret <= (p-buffer)) break;
67 }
68 }
69
70 for (;drivestr[0] <= 'z'; drivestr[0]++) {
71 /* Older W2K fails with ERROR_INSUFFICIENT_BUFFER when buflen is > 32767 */
72 ret = QueryDosDeviceA( drivestr, buffer, buflen - 1);
73 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
74 "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", drivestr, GetLastError());
75 if(ret) {
76 for (p = buffer; *p; p++) *p = toupper(*p);
77 if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE;
78 }
79 }
80 ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
81 HeapFree( GetProcessHeap(), 0, buffer );
82 }
83
84 static void test_define_dos_deviceA(void)
85 {
86 char drivestr[3];
87 char buf[MAX_PATH];
88 DWORD ret;
89
90 /* Find an unused drive letter */
91 drivestr[1] = ':';
92 drivestr[2] = 0;
93 for (drivestr[0] = 'a'; drivestr[0] <= 'z'; drivestr[0]++) {
94 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf));
95 if (!ret) break;
96 }
97 if (drivestr[0] > 'z') {
98 skip("can't test creating a dos drive, none available\n");
99 return;
100 }
101
102 /* Map it to point to the current directory */
103 ret = GetCurrentDirectory(sizeof(buf), buf);
104 ok(ret, "GetCurrentDir\n");
105
106 ret = DefineDosDeviceA(0, drivestr, buf);
107 todo_wine
108 ok(ret, "Could not make drive %s point to %s!\n", drivestr, buf);
109
110 if (!ret) {
111 skip("can't test removing fake drive\n");
112 } else {
113 ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL);
114 ok(ret, "Could not remove fake drive %s!\n", drivestr);
115 }
116 }
117
118 static void test_FindFirstVolume(void)
119 {
120 char volume[51];
121 HANDLE handle;
122
123 /* not present before w2k */
124 if (!pFindFirstVolumeA) {
125 win_skip("FindFirstVolumeA not found\n");
126 return;
127 }
128
129 handle = pFindFirstVolumeA( volume, 0 );
130 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
131 ok( GetLastError() == ERROR_MORE_DATA || /* XP */
132 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Vista */
133 "wrong error %u\n", GetLastError() );
134 handle = pFindFirstVolumeA( volume, 49 );
135 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
136 ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE, "wrong error %u\n", GetLastError() );
137 handle = pFindFirstVolumeA( volume, 51 );
138 ok( handle != INVALID_HANDLE_VALUE, "failed err %u\n", GetLastError() );
139 if (handle != INVALID_HANDLE_VALUE)
140 {
141 do
142 {
143 ok( strlen(volume) == 49, "bad volume name %s\n", volume );
144 ok( !memcmp( volume, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume );
145 ok( !memcmp( volume + 47, "}\\", 2 ), "bad volume name %s\n", volume );
146 } while (pFindNextVolumeA( handle, volume, MAX_PATH ));
147 ok( GetLastError() == ERROR_NO_MORE_FILES, "wrong error %u\n", GetLastError() );
148 pFindVolumeClose( handle );
149 }
150 }
151
152 static void test_GetVolumeNameForVolumeMountPointA(void)
153 {
154 BOOL ret;
155 char volume[MAX_PATH], path[] = "c:\\";
156 DWORD len = sizeof(volume), reti;
157 char temp_path[MAX_PATH];
158
159 /* not present before w2k */
160 if (!pGetVolumeNameForVolumeMountPointA) {
161 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
162 return;
163 }
164
165 reti = GetTempPathA(MAX_PATH, temp_path);
166 ok(reti != 0, "GetTempPathA error %d\n", GetLastError());
167 ok(reti < MAX_PATH, "temp path should fit into MAX_PATH\n");
168
169 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 0);
170 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
171 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
172 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
173 "wrong error, last=%d\n", GetLastError());
174
175 if (0) { /* these crash on XP */
176 ret = pGetVolumeNameForVolumeMountPointA(path, NULL, len);
177 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
178
179 ret = pGetVolumeNameForVolumeMountPointA(NULL, volume, len);
180 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
181 }
182
183 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
184 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
185 ok(!strncmp( volume, "\\\\?\\Volume{", 11),
186 "GetVolumeNameForVolumeMountPointA failed to return valid string <%s>\n",
187 volume);
188
189 /* test with too small buffer */
190 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 10);
191 ok(ret == FALSE && GetLastError() == ERROR_FILENAME_EXCED_RANGE,
192 "GetVolumeNameForVolumeMountPointA failed, wrong error returned, was %d, should be ERROR_FILENAME_EXCED_RANGE\n",
193 GetLastError());
194
195 /* Try on a arbitrary directory */
196 /* On FAT filesystems it seems that GetLastError() is set to
197 ERROR_INVALID_FUNCTION. */
198 ret = pGetVolumeNameForVolumeMountPointA(temp_path, volume, len);
199 ok(ret == FALSE && (GetLastError() == ERROR_NOT_A_REPARSE_POINT ||
200 GetLastError() == ERROR_INVALID_FUNCTION),
201 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
202 temp_path, GetLastError());
203
204 /* Try on a nonexistent dos drive */
205 path[2] = 0;
206 for (;path[0] <= 'z'; path[0]++) {
207 ret = QueryDosDeviceA( path, volume, len);
208 if(!ret) break;
209 }
210 if (path[0] <= 'z')
211 {
212 path[2] = '\\';
213 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
214 ok(ret == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND,
215 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
216 path, GetLastError());
217
218 /* Try without trailing \ and on a nonexistent dos drive */
219 path[2] = 0;
220 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
221 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
222 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
223 path, GetLastError());
224 }
225 }
226
227 static void test_GetVolumeNameForVolumeMountPointW(void)
228 {
229 BOOL ret;
230 WCHAR volume[MAX_PATH], path[] = {'c',':','\\',0};
231 DWORD len = sizeof(volume) / sizeof(WCHAR);
232
233 /* not present before w2k */
234 if (!pGetVolumeNameForVolumeMountPointW) {
235 win_skip("GetVolumeNameForVolumeMountPointW not found\n");
236 return;
237 }
238
239 ret = pGetVolumeNameForVolumeMountPointW(path, volume, 0);
240 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
241 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
242 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
243 "wrong error, last=%d\n", GetLastError());
244
245 if (0) { /* these crash on XP */
246 ret = pGetVolumeNameForVolumeMountPointW(path, NULL, len);
247 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
248
249 ret = pGetVolumeNameForVolumeMountPointW(NULL, volume, len);
250 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
251 }
252
253 ret = pGetVolumeNameForVolumeMountPointW(path, volume, len);
254 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n");
255 }
256
257 static void test_GetLogicalDriveStringsA(void)
258 {
259 UINT size, size2;
260 char *buf, *ptr;
261
262 ok( pGetLogicalDriveStringsA != NULL, "GetLogicalDriveStringsA not available\n");
263 if(!pGetLogicalDriveStringsA) {
264 return;
265 }
266
267 size = pGetLogicalDriveStringsA(0, NULL);
268 ok(size%4 == 1, "size = %d\n", size);
269
270 buf = HeapAlloc(GetProcessHeap(), 0, size);
271
272 *buf = 0;
273 size2 = pGetLogicalDriveStringsA(2, buf);
274 ok(size2 == size, "size2 = %d\n", size2);
275 ok(!*buf, "buf changed\n");
276
277 size2 = pGetLogicalDriveStringsA(size, buf);
278 ok(size2 == size-1, "size2 = %d\n", size2);
279
280 for(ptr = buf; ptr < buf+size2; ptr += 4) {
281 ok(('A' <= *ptr && *ptr <= 'Z'), "device name '%c' is not uppercase\n", *ptr);
282 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
283 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
284 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
285 }
286 ok(!*ptr, "buf[size2] is not nullbyte\n");
287
288 HeapFree(GetProcessHeap(), 0, buf);
289 }
290
291 static void test_GetLogicalDriveStringsW(void)
292 {
293 UINT size, size2;
294 WCHAR *buf, *ptr;
295
296 ok( pGetLogicalDriveStringsW != NULL, "GetLogicalDriveStringsW not available\n");
297 if(!pGetLogicalDriveStringsW) {
298 return;
299 }
300
301 SetLastError(0xdeadbeef);
302 size = pGetLogicalDriveStringsW(0, NULL);
303 if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
304 win_skip("GetLogicalDriveStringsW not implemented\n");
305 return;
306 }
307 ok(size%4 == 1, "size = %d\n", size);
308
309 buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
310
311 *buf = 0;
312 size2 = pGetLogicalDriveStringsW(2, buf);
313 ok(size2 == size, "size2 = %d\n", size2);
314 ok(!*buf, "buf changed\n");
315
316 size2 = pGetLogicalDriveStringsW(size, buf);
317 ok(size2 == size-1, "size2 = %d\n", size2);
318
319 for(ptr = buf; ptr < buf+size2; ptr += 4) {
320 ok('A' <= *ptr && *ptr <= 'Z', "device name '%c' is not uppercase\n", *ptr);
321 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
322 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
323 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
324 }
325 ok(!*ptr, "buf[size2] is not nullbyte\n");
326
327 HeapFree(GetProcessHeap(), 0, buf);
328 }
329
330 static void test_GetVolumeInformationA(void)
331 {
332 BOOL ret;
333 UINT result;
334 char Root_Colon[]="C:";
335 char Root_Slash[]="C:\\";
336 char Root_UNC[]="\\\\?\\C:\\";
337 char volume[MAX_PATH+1];
338 DWORD vol_name_size=MAX_PATH+1, vol_serial_num=-1, max_comp_len=0, fs_flags=0, fs_name_len=MAX_PATH+1;
339 char vol_name_buf[MAX_PATH+1], fs_name_buf[MAX_PATH+1];
340 char windowsdir[MAX_PATH+10];
341 char currentdir[MAX_PATH+1];
342
343 ok( pGetVolumeInformationA != NULL, "GetVolumeInformationA not found\n");
344 if(!pGetVolumeInformationA) {
345 return;
346 }
347
348 /* get windows drive letter and update strings for testing */
349 result = GetWindowsDirectory(windowsdir, sizeof(windowsdir));
350 ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
351 ok(result != 0, "GetWindowsDirectory: error %d\n", GetLastError());
352 Root_Colon[0] = windowsdir[0];
353 Root_Slash[0] = windowsdir[0];
354 Root_UNC[4] = windowsdir[0];
355
356 result = GetCurrentDirectory(MAX_PATH, currentdir);
357 ok(result, "GetCurrentDirectory: error %d\n", GetLastError());
358 /* Note that GetCurrentDir yields no trailing slash for subdirs */
359
360 /* check for NO error on no trailing \ when current dir is root dir */
361 ret = SetCurrentDirectory(Root_Slash);
362 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
363 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
364 NULL, NULL, fs_name_buf, fs_name_len);
365 ok(ret, "GetVolumeInformationA root failed, last error %u\n", GetLastError());
366
367 /* check for error on no trailing \ when current dir is subdir (windows) of queried drive */
368 ret = SetCurrentDirectory(windowsdir);
369 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
370 SetLastError(0xdeadbeef);
371 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
372 NULL, NULL, fs_name_buf, fs_name_len);
373 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
374 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
375
376 /* reset current directory */
377 ret = SetCurrentDirectory(currentdir);
378 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
379
380 if (toupper(currentdir[0]) == toupper(windowsdir[0])) {
381 skip("Please re-run from another device than %c:\n", windowsdir[0]);
382 /* FIXME: Use GetLogicalDrives to find another device to avoid this skip. */
383 } else {
384 char Root_Env[]="=C:"; /* where MS maintains the per volume directory */
385 Root_Env[1] = windowsdir[0];
386
387 /* C:\windows becomes the current directory on drive C: */
388 /* Note that paths to subdirs are stored without trailing slash, like what GetCurrentDir yields. */
389 ret = SetEnvironmentVariable(Root_Env, windowsdir);
390 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
391
392 ret = SetCurrentDirectory(windowsdir);
393 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
394 ret = SetCurrentDirectory(currentdir);
395 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
396
397 /* windows dir is current on the root drive, call fails */
398 SetLastError(0xdeadbeef);
399 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
400 NULL, NULL, fs_name_buf, fs_name_len);
401 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
402 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
403
404 /* Try normal drive letter with trailing \ */
405 ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size, NULL,
406 NULL, NULL, fs_name_buf, fs_name_len);
407 ok(ret, "GetVolumeInformationA with \\ failed, last error %u\n", GetLastError());
408
409 ret = SetCurrentDirectory(Root_Slash);
410 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
411 ret = SetCurrentDirectory(currentdir);
412 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
413
414 /* windows dir is STILL CURRENT on root drive; the call fails as before, */
415 /* proving that SetCurrentDir did not remember the other drive's directory */
416 SetLastError(0xdeadbeef);
417 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
418 NULL, NULL, fs_name_buf, fs_name_len);
419 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
420 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
421
422 /* Now C:\ becomes the current directory on drive C: */
423 ret = SetEnvironmentVariable(Root_Env, Root_Slash); /* set =C:=C:\ */
424 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
425
426 /* \ is current on root drive, call succeeds */
427 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
428 NULL, NULL, fs_name_buf, fs_name_len);
429 ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
430
431 /* again, SetCurrentDirectory on another drive does not matter */
432 ret = SetCurrentDirectory(Root_Slash);
433 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
434 ret = SetCurrentDirectory(currentdir);
435 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
436
437 /* \ is current on root drive, call succeeds */
438 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
439 NULL, NULL, fs_name_buf, fs_name_len);
440 ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
441 }
442
443 /* try null root directory to return "root of the current directory" */
444 ret = pGetVolumeInformationA(NULL, vol_name_buf, vol_name_size, NULL,
445 NULL, NULL, fs_name_buf, fs_name_len);
446 ok(ret, "GetVolumeInformationA failed on null root dir, last error %u\n", GetLastError());
447
448 /* Try normal drive letter with trailing \ */
449 ret = pGetVolumeInformationA(Root_Slash, 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 failed, root=%s, last error=%u\n", Root_Slash, GetLastError());
452
453 /* try again with drive letter and the "disable parsing" prefix */
454 SetLastError(0xdeadbeef);
455 ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
456 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
457 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
458
459 /* try again with device name space */
460 Root_UNC[2] = '.';
461 SetLastError(0xdeadbeef);
462 ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
463 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
464 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
465
466 /* try again with a directory off the root - should generate error */
467 if (windowsdir[strlen(windowsdir)-1] != '\\') strcat(windowsdir, "\\");
468 SetLastError(0xdeadbeef);
469 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
470 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
471 ok(!ret && (GetLastError()==ERROR_DIR_NOT_ROOT),
472 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
473 /* A subdir with trailing \ yields DIR_NOT_ROOT instead of INVALID_NAME */
474 if (windowsdir[strlen(windowsdir)-1] == '\\') windowsdir[strlen(windowsdir)-1] = 0;
475 SetLastError(0xdeadbeef);
476 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
477 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
478 ok(!ret && (GetLastError()==ERROR_INVALID_NAME),
479 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
480
481 if (!pGetVolumeNameForVolumeMountPointA) {
482 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
483 return;
484 }
485 /* get the unique volume name for the windows drive */
486 ret = pGetVolumeNameForVolumeMountPointA(Root_Slash, volume, MAX_PATH);
487 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
488
489 /* try again with unique volume name */
490 ret = pGetVolumeInformationA(volume, vol_name_buf, vol_name_size,
491 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
492 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", volume, GetLastError());
493 }
494
495 /* Test to check that unique volume name from windows dir mount point */
496 /* matches at least one of the unique volume names returned from the */
497 /* FindFirstVolumeA/FindNextVolumeA list. */
498 static void test_enum_vols(void)
499 {
500 DWORD ret;
501 HANDLE hFind = INVALID_HANDLE_VALUE;
502 char Volume_1[MAX_PATH] = {0};
503 char Volume_2[MAX_PATH] = {0};
504 char path[] = "c:\\";
505 BOOL found = FALSE;
506 char windowsdir[MAX_PATH];
507
508 if (!pGetVolumeNameForVolumeMountPointA) {
509 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
510 return;
511 }
512
513 /*get windows drive letter and update strings for testing */
514 ret = GetWindowsDirectory( windowsdir, sizeof(windowsdir) );
515 ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
516 ok(ret != 0, "GetWindowsDirecory: error %d\n", GetLastError());
517 path[0] = windowsdir[0];
518
519 /* get the unique volume name for the windows drive */
520 ret = pGetVolumeNameForVolumeMountPointA( path, Volume_1, MAX_PATH );
521 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
522 ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1);
523
524 /* get first unique volume name of list */
525 hFind = pFindFirstVolumeA( Volume_2, MAX_PATH );
526 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstVolume failed, err=%u\n",
527 GetLastError());
528 /* ReactOS */
529 if (hFind != INVALID_HANDLE_VALUE) {
530 do
531 {
532 /* validate correct length of unique volume name */
533 ok(strlen(Volume_2) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1);
534 if (memcmp(Volume_1, Volume_2, 49) == 0)
535 {
536 found = TRUE;
537 break;
538 }
539 } while (pFindNextVolumeA( hFind, Volume_2, MAX_PATH ));
540 ok(found, "volume name %s not found by Find[First/Next]Volume\n", Volume_1);
541 pFindVolumeClose( hFind );
542 }
543 }
544
545 static void test_disk_extents(void)
546 {
547 BOOL ret;
548 DWORD size;
549 HANDLE handle;
550 static DWORD data[16];
551
552 handle = CreateFileA( "\\\\.\\c:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
553 if (handle == INVALID_HANDLE_VALUE)
554 {
555 win_skip("can't open c: drive %u\n", GetLastError());
556 return;
557 }
558 size = 0;
559 ret = DeviceIoControl( handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, &data,
560 sizeof(data), &data, sizeof(data), &size, NULL );
561 if (!ret && GetLastError() == ERROR_INVALID_FUNCTION)
562 {
563 win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
564 CloseHandle( handle );
565 return;
566 }
567 ok(ret, "DeviceIoControl failed %u\n", GetLastError());
568 ok(size == 32, "expected 32, got %u\n", size);
569 CloseHandle( handle );
570 }
571
572 static void test_GetVolumePathNamesForVolumeNameA(void)
573 {
574 BOOL ret;
575 char volume[MAX_PATH], buffer[MAX_PATH];
576 DWORD len, error;
577
578 if (!pGetVolumePathNamesForVolumeNameA || !pGetVolumeNameForVolumeMountPointA)
579 {
580 win_skip("required functions not found\n");
581 return;
582 }
583
584 ret = pGetVolumeNameForVolumeMountPointA( "c:\\", volume, sizeof(volume) );
585 ok(ret, "failed to get volume name %u\n", GetLastError());
586 trace("c:\\ -> %s\n", volume);
587
588 SetLastError( 0xdeadbeef );
589 ret = pGetVolumePathNamesForVolumeNameA( NULL, 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( "", NULL, 0, NULL );
596 error = GetLastError();
597 ok(!ret, "expected failure\n");
598 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
599
600 SetLastError( 0xdeadbeef );
601 ret = pGetVolumePathNamesForVolumeNameA( volume, NULL, 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 SetLastError( 0xdeadbeef );
607 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, 0, NULL );
608 error = GetLastError();
609 ok(!ret, "expected failure\n");
610 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
611
612 memset( buffer, 0xff, sizeof(buffer) );
613 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), NULL );
614 ok(ret, "failed to get path names %u\n", GetLastError());
615 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
616 ok(!buffer[4], "expected double null-terminated buffer\n");
617
618 len = 0;
619 SetLastError( 0xdeadbeef );
620 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, &len );
621 error = GetLastError();
622 ok(!ret, "expected failure\n");
623 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
624
625 len = 0;
626 SetLastError( 0xdeadbeef );
627 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, sizeof(buffer), &len );
628 error = GetLastError();
629 ok(!ret, "expected failure\n");
630 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
631
632 len = 0;
633 SetLastError( 0xdeadbeef );
634 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
635 error = GetLastError();
636 ok(!ret, "expected failure\n");
637 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
638
639 len = 0;
640 SetLastError( 0xdeadbeef );
641 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
642 error = GetLastError();
643 ok(!ret, "expected failure\n");
644 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
645
646 len = 0;
647 memset( buffer, 0xff, sizeof(buffer) );
648 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), &len );
649 ok(ret, "failed to get path names %u\n", GetLastError());
650 ok(len == 5 || broken(len == 2), "expected 5 got %u\n", len);
651 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
652 ok(!buffer[4], "expected double null-terminated buffer\n");
653 }
654
655 static void test_GetVolumePathNamesForVolumeNameW(void)
656 {
657 static const WCHAR empty[] = {0};
658 static const WCHAR drive_c[] = {'c',':','\\',0};
659 static const WCHAR volume_null[] = {'\\','\\','?','\\','V','o','l','u','m','e',
660 '{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0','0',
661 '-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',0};
662 BOOL ret;
663 WCHAR volume[MAX_PATH], buffer[MAX_PATH];
664 DWORD len, error;
665
666 if (!pGetVolumePathNamesForVolumeNameW || !pGetVolumeNameForVolumeMountPointW)
667 {
668 win_skip("required functions not found\n");
669 return;
670 }
671
672 ret = pGetVolumeNameForVolumeMountPointW( drive_c, volume, sizeof(volume)/sizeof(volume[0]) );
673 ok(ret, "failed to get volume name %u\n", GetLastError());
674
675 SetLastError( 0xdeadbeef );
676 ret = pGetVolumePathNamesForVolumeNameW( empty, NULL, 0, NULL );
677 error = GetLastError();
678 ok(!ret, "expected failure\n");
679 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
680
681 SetLastError( 0xdeadbeef );
682 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, 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 SetLastError( 0xdeadbeef );
688 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, 0, NULL );
689 error = GetLastError();
690 ok(!ret, "expected failure\n");
691 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
692
693 if (0) { /* crash */
694 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, sizeof(buffer), NULL );
695 ok(ret, "failed to get path names %u\n", GetLastError());
696 }
697
698 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), NULL );
699 ok(ret, "failed to get path names %u\n", GetLastError());
700
701 len = 0;
702 memset( buffer, 0xff, sizeof(buffer) );
703 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
704 ok(ret, "failed to get path names %u\n", GetLastError());
705 ok(len == 5, "expected 5 got %u\n", len);
706 ok(!buffer[4], "expected double null-terminated buffer\n");
707
708 len = 0;
709 volume[1] = '?';
710 volume[lstrlenW( volume ) - 1] = 0;
711 SetLastError( 0xdeadbeef );
712 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
713 error = GetLastError();
714 ok(!ret, "expected failure\n");
715 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
716
717 len = 0;
718 volume[0] = '\\';
719 volume[1] = 0;
720 SetLastError( 0xdeadbeef );
721 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
722 error = GetLastError();
723 ok(!ret, "expected failure\n");
724 todo_wine ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
725
726 len = 0;
727 lstrcpyW( volume, volume_null );
728 SetLastError( 0xdeadbeef );
729 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
730 error = GetLastError();
731 ok(!ret, "expected failure\n");
732 ok(error == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND got %u\n", error);
733 }
734
735 START_TEST(volume)
736 {
737 hdll = GetModuleHandleA("kernel32.dll");
738 pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointA");
739 pGetVolumeNameForVolumeMountPointW = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointW");
740 pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
741 pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
742 pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
743 pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
744 pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
745 pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
746 pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA");
747 pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW");
748
749 test_query_dos_deviceA();
750 test_define_dos_deviceA();
751 test_FindFirstVolume();
752 test_GetVolumeNameForVolumeMountPointA();
753 test_GetVolumeNameForVolumeMountPointW();
754 test_GetLogicalDriveStringsA();
755 test_GetLogicalDriveStringsW();
756 test_GetVolumeInformationA();
757 test_enum_vols();
758 test_disk_extents();
759 test_GetVolumePathNamesForVolumeNameA();
760 test_GetVolumePathNamesForVolumeNameW();
761 }