mshtml: Rename call_event to fire_event.
[wine] / dlls / kernel32 / tests / 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
523     do
524     {
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)
528         {
529             found = TRUE;
530             break;
531         }
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 );
535 }
536
537 static void test_disk_extents(void)
538 {
539     BOOL ret;
540     DWORD size;
541     HANDLE handle;
542     static DWORD data[16];
543
544     handle = CreateFileA( "\\\\.\\c:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
545     if (handle == INVALID_HANDLE_VALUE)
546     {
547         win_skip("can't open c: drive %u\n", GetLastError());
548         return;
549     }
550     size = 0;
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)
554     {
555         win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
556         CloseHandle( handle );
557         return;
558     }
559     ok(ret, "DeviceIoControl failed %u\n", GetLastError());
560     ok(size == 32, "expected 32, got %u\n", size);
561     CloseHandle( handle );
562 }
563
564 static void test_GetVolumePathNamesForVolumeNameA(void)
565 {
566     BOOL ret;
567     char volume[MAX_PATH], buffer[MAX_PATH];
568     DWORD len, error;
569
570     if (!pGetVolumePathNamesForVolumeNameA || !pGetVolumeNameForVolumeMountPointA)
571     {
572         win_skip("required functions not found\n");
573         return;
574     }
575
576     ret = pGetVolumeNameForVolumeMountPointA( "c:\\", volume, sizeof(volume) );
577     ok(ret, "failed to get volume name %u\n", GetLastError());
578     trace("c:\\ -> %s\n", volume);
579
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);
585
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);
591
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);
597
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);
603
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");
609
610     len = 0;
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);
616
617     len = 0;
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);
623
624     len = 0;
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);
630
631     len = 0;
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);
637
638     len = 0;
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");
645 }
646
647 static void test_GetVolumePathNamesForVolumeNameW(void)
648 {
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};
654     BOOL ret;
655     WCHAR volume[MAX_PATH], buffer[MAX_PATH];
656     DWORD len, error;
657
658     if (!pGetVolumePathNamesForVolumeNameW || !pGetVolumeNameForVolumeMountPointW)
659     {
660         win_skip("required functions not found\n");
661         return;
662     }
663
664     ret = pGetVolumeNameForVolumeMountPointW( drive_c, volume, sizeof(volume)/sizeof(volume[0]) );
665     ok(ret, "failed to get volume name %u\n", GetLastError());
666
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);
672
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);
678
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);
684
685     if (0) { /* crash */
686     ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, sizeof(buffer), NULL );
687     ok(ret, "failed to get path names %u\n", GetLastError());
688     }
689
690     ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), NULL );
691     ok(ret, "failed to get path names %u\n", GetLastError());
692
693     len = 0;
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");
699
700     len = 0;
701     volume[1] = '?';
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);
708
709     len = 0;
710     volume[0] = '\\';
711     volume[1] = 0;
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);
717
718     len = 0;
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);
725 }
726
727 START_TEST(volume)
728 {
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");
740
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();
749     test_enum_vols();
750     test_disk_extents();
751     test_GetVolumePathNamesForVolumeNameA();
752     test_GetVolumePathNamesForVolumeNameW();
753 }