kernel32/tests: Add a IOCTL_DVD_READ_STRUCTURE (DvdCopyrightDescriptor) test.
[wine/multimedia.git] / dlls / kernel32 / tests / volume.c
blob45bac3177ae4808b3be31bbebefde0e9f994903f
1 /*
2 * Unit test suite for volume functions
4 * Copyright 2006 Stefan Leichter
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
22 #include "winbase.h"
23 #include "winioctl.h"
24 #include <stdio.h>
25 #include "ddk/ntddcdvd.h"
27 #include <pshpack1.h>
28 struct COMPLETE_DVD_LAYER_DESCRIPTOR
30 DVD_DESCRIPTOR_HEADER Header;
31 DVD_LAYER_DESCRIPTOR Descriptor;
32 UCHAR Padding;
34 #include <poppack.h>
35 C_ASSERT(sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR) == 22);
37 static HINSTANCE hdll;
38 static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointA)(LPCSTR, LPSTR, DWORD);
39 static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointW)(LPCWSTR, LPWSTR, DWORD);
40 static HANDLE (WINAPI *pFindFirstVolumeA)(LPSTR,DWORD);
41 static BOOL (WINAPI *pFindNextVolumeA)(HANDLE,LPSTR,DWORD);
42 static BOOL (WINAPI *pFindVolumeClose)(HANDLE);
43 static UINT (WINAPI *pGetLogicalDriveStringsA)(UINT,LPSTR);
44 static UINT (WINAPI *pGetLogicalDriveStringsW)(UINT,LPWSTR);
45 static BOOL (WINAPI *pGetVolumeInformationA)(LPCSTR, LPSTR, DWORD, LPDWORD, LPDWORD, LPDWORD, LPSTR, DWORD);
46 static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameA)(LPCSTR, LPSTR, DWORD, LPDWORD);
47 static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameW)(LPCWSTR, LPWSTR, DWORD, LPDWORD);
49 /* ############################### */
51 static void test_query_dos_deviceA(void)
53 char drivestr[] = "a:";
54 char *p, *buffer, buffer2[2000];
55 DWORD ret, ret2, buflen=32768;
56 BOOL found = FALSE;
58 /* callers must guess the buffer size */
59 SetLastError(0xdeadbeef);
60 ret = QueryDosDeviceA( NULL, NULL, 0 );
61 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
62 "QueryDosDeviceA(no buffer): returned %u, le=%u\n", ret, GetLastError());
64 buffer = HeapAlloc( GetProcessHeap(), 0, buflen );
65 SetLastError(0xdeadbeef);
66 ret = QueryDosDeviceA( NULL, buffer, buflen );
67 ok((ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER),
68 "QueryDosDeviceA failed to return list, last error %u\n", GetLastError());
70 if (ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
71 p = buffer;
72 for (;;) {
73 if (!strlen(p)) break;
74 ret2 = QueryDosDeviceA( p, buffer2, sizeof(buffer2) );
75 ok(ret2, "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", p, GetLastError());
76 p += strlen(p) + 1;
77 if (ret <= (p-buffer)) break;
81 for (;drivestr[0] <= 'z'; drivestr[0]++) {
82 /* Older W2K fails with ERROR_INSUFFICIENT_BUFFER when buflen is > 32767 */
83 ret = QueryDosDeviceA( drivestr, buffer, buflen - 1);
84 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
85 "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", drivestr, GetLastError());
86 if(ret) {
87 for (p = buffer; *p; p++) *p = toupper(*p);
88 if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE;
91 ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
92 HeapFree( GetProcessHeap(), 0, buffer );
95 static void test_define_dos_deviceA(void)
97 char drivestr[3];
98 char buf[MAX_PATH];
99 DWORD ret;
101 /* Find an unused drive letter */
102 drivestr[1] = ':';
103 drivestr[2] = 0;
104 for (drivestr[0] = 'a'; drivestr[0] <= 'z'; drivestr[0]++) {
105 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf));
106 if (!ret) break;
108 if (drivestr[0] > 'z') {
109 skip("can't test creating a dos drive, none available\n");
110 return;
113 /* Map it to point to the current directory */
114 ret = GetCurrentDirectory(sizeof(buf), buf);
115 ok(ret, "GetCurrentDir\n");
117 ret = DefineDosDeviceA(0, drivestr, buf);
118 todo_wine
119 ok(ret, "Could not make drive %s point to %s!\n", drivestr, buf);
121 if (!ret) {
122 skip("can't test removing fake drive\n");
123 } else {
124 ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL);
125 ok(ret, "Could not remove fake drive %s!\n", drivestr);
129 static void test_FindFirstVolume(void)
131 char volume[51];
132 HANDLE handle;
134 /* not present before w2k */
135 if (!pFindFirstVolumeA) {
136 win_skip("FindFirstVolumeA not found\n");
137 return;
140 handle = pFindFirstVolumeA( volume, 0 );
141 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
142 ok( GetLastError() == ERROR_MORE_DATA || /* XP */
143 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Vista */
144 "wrong error %u\n", GetLastError() );
145 handle = pFindFirstVolumeA( volume, 49 );
146 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
147 ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE, "wrong error %u\n", GetLastError() );
148 handle = pFindFirstVolumeA( volume, 51 );
149 ok( handle != INVALID_HANDLE_VALUE, "failed err %u\n", GetLastError() );
150 if (handle != INVALID_HANDLE_VALUE)
154 ok( strlen(volume) == 49, "bad volume name %s\n", volume );
155 ok( !memcmp( volume, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume );
156 ok( !memcmp( volume + 47, "}\\", 2 ), "bad volume name %s\n", volume );
157 } while (pFindNextVolumeA( handle, volume, MAX_PATH ));
158 ok( GetLastError() == ERROR_NO_MORE_FILES, "wrong error %u\n", GetLastError() );
159 pFindVolumeClose( handle );
163 static void test_GetVolumeNameForVolumeMountPointA(void)
165 BOOL ret;
166 char volume[MAX_PATH], path[] = "c:\\";
167 DWORD len = sizeof(volume), reti;
168 char temp_path[MAX_PATH];
170 /* not present before w2k */
171 if (!pGetVolumeNameForVolumeMountPointA) {
172 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
173 return;
176 reti = GetTempPathA(MAX_PATH, temp_path);
177 ok(reti != 0, "GetTempPathA error %d\n", GetLastError());
178 ok(reti < MAX_PATH, "temp path should fit into MAX_PATH\n");
180 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 0);
181 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
182 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
183 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
184 "wrong error, last=%d\n", GetLastError());
186 if (0) { /* these crash on XP */
187 ret = pGetVolumeNameForVolumeMountPointA(path, NULL, len);
188 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
190 ret = pGetVolumeNameForVolumeMountPointA(NULL, volume, len);
191 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
194 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
195 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
196 ok(!strncmp( volume, "\\\\?\\Volume{", 11),
197 "GetVolumeNameForVolumeMountPointA failed to return valid string <%s>\n",
198 volume);
200 /* test with too small buffer */
201 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 10);
202 ok(ret == FALSE && GetLastError() == ERROR_FILENAME_EXCED_RANGE,
203 "GetVolumeNameForVolumeMountPointA failed, wrong error returned, was %d, should be ERROR_FILENAME_EXCED_RANGE\n",
204 GetLastError());
206 /* Try on a arbitrary directory */
207 /* On FAT filesystems it seems that GetLastError() is set to
208 ERROR_INVALID_FUNCTION. */
209 ret = pGetVolumeNameForVolumeMountPointA(temp_path, volume, len);
210 ok(ret == FALSE && (GetLastError() == ERROR_NOT_A_REPARSE_POINT ||
211 GetLastError() == ERROR_INVALID_FUNCTION),
212 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
213 temp_path, GetLastError());
215 /* Try on a nonexistent dos drive */
216 path[2] = 0;
217 for (;path[0] <= 'z'; path[0]++) {
218 ret = QueryDosDeviceA( path, volume, len);
219 if(!ret) break;
221 if (path[0] <= 'z')
223 path[2] = '\\';
224 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
225 ok(ret == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND,
226 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
227 path, GetLastError());
229 /* Try without trailing \ and on a nonexistent dos drive */
230 path[2] = 0;
231 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
232 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
233 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
234 path, GetLastError());
238 static void test_GetVolumeNameForVolumeMountPointW(void)
240 BOOL ret;
241 WCHAR volume[MAX_PATH], path[] = {'c',':','\\',0};
242 DWORD len = sizeof(volume) / sizeof(WCHAR);
244 /* not present before w2k */
245 if (!pGetVolumeNameForVolumeMountPointW) {
246 win_skip("GetVolumeNameForVolumeMountPointW not found\n");
247 return;
250 ret = pGetVolumeNameForVolumeMountPointW(path, volume, 0);
251 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
252 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
253 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
254 "wrong error, last=%d\n", GetLastError());
256 if (0) { /* these crash on XP */
257 ret = pGetVolumeNameForVolumeMountPointW(path, NULL, len);
258 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
260 ret = pGetVolumeNameForVolumeMountPointW(NULL, volume, len);
261 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
264 ret = pGetVolumeNameForVolumeMountPointW(path, volume, len);
265 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n");
268 static void test_GetLogicalDriveStringsA(void)
270 UINT size, size2;
271 char *buf, *ptr;
273 ok( pGetLogicalDriveStringsA != NULL, "GetLogicalDriveStringsA not available\n");
274 if(!pGetLogicalDriveStringsA) {
275 return;
278 size = pGetLogicalDriveStringsA(0, NULL);
279 ok(size%4 == 1, "size = %d\n", size);
281 buf = HeapAlloc(GetProcessHeap(), 0, size);
283 *buf = 0;
284 size2 = pGetLogicalDriveStringsA(2, buf);
285 ok(size2 == size, "size2 = %d\n", size2);
286 ok(!*buf, "buf changed\n");
288 size2 = pGetLogicalDriveStringsA(size, buf);
289 ok(size2 == size-1, "size2 = %d\n", size2);
291 for(ptr = buf; ptr < buf+size2; ptr += 4) {
292 ok(('A' <= *ptr && *ptr <= 'Z'), "device name '%c' is not uppercase\n", *ptr);
293 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
294 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
295 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
297 ok(!*ptr, "buf[size2] is not nullbyte\n");
299 HeapFree(GetProcessHeap(), 0, buf);
302 static void test_GetLogicalDriveStringsW(void)
304 UINT size, size2;
305 WCHAR *buf, *ptr;
307 ok( pGetLogicalDriveStringsW != NULL, "GetLogicalDriveStringsW not available\n");
308 if(!pGetLogicalDriveStringsW) {
309 return;
312 SetLastError(0xdeadbeef);
313 size = pGetLogicalDriveStringsW(0, NULL);
314 if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
315 win_skip("GetLogicalDriveStringsW not implemented\n");
316 return;
318 ok(size%4 == 1, "size = %d\n", size);
320 buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
322 *buf = 0;
323 size2 = pGetLogicalDriveStringsW(2, buf);
324 ok(size2 == size, "size2 = %d\n", size2);
325 ok(!*buf, "buf changed\n");
327 size2 = pGetLogicalDriveStringsW(size, buf);
328 ok(size2 == size-1, "size2 = %d\n", size2);
330 for(ptr = buf; ptr < buf+size2; ptr += 4) {
331 ok('A' <= *ptr && *ptr <= 'Z', "device name '%c' is not uppercase\n", *ptr);
332 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
333 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
334 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
336 ok(!*ptr, "buf[size2] is not nullbyte\n");
338 HeapFree(GetProcessHeap(), 0, buf);
341 static void test_GetVolumeInformationA(void)
343 BOOL ret;
344 UINT result;
345 char Root_Colon[]="C:";
346 char Root_Slash[]="C:\\";
347 char Root_UNC[]="\\\\?\\C:\\";
348 char volume[MAX_PATH+1];
349 DWORD vol_name_size=MAX_PATH+1, vol_serial_num=-1, max_comp_len=0, fs_flags=0, fs_name_len=MAX_PATH+1;
350 char vol_name_buf[MAX_PATH+1], fs_name_buf[MAX_PATH+1];
351 char windowsdir[MAX_PATH+10];
352 char currentdir[MAX_PATH+1];
354 ok( pGetVolumeInformationA != NULL, "GetVolumeInformationA not found\n");
355 if(!pGetVolumeInformationA) {
356 return;
359 /* get windows drive letter and update strings for testing */
360 result = GetWindowsDirectory(windowsdir, sizeof(windowsdir));
361 ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
362 ok(result != 0, "GetWindowsDirectory: error %d\n", GetLastError());
363 Root_Colon[0] = windowsdir[0];
364 Root_Slash[0] = windowsdir[0];
365 Root_UNC[4] = windowsdir[0];
367 result = GetCurrentDirectory(MAX_PATH, currentdir);
368 ok(result, "GetCurrentDirectory: error %d\n", GetLastError());
369 /* Note that GetCurrentDir yields no trailing slash for subdirs */
371 /* check for NO error on no trailing \ when current dir is root dir */
372 ret = SetCurrentDirectory(Root_Slash);
373 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
374 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
375 NULL, NULL, fs_name_buf, fs_name_len);
376 ok(ret, "GetVolumeInformationA root failed, last error %u\n", GetLastError());
378 /* check for error on no trailing \ when current dir is subdir (windows) of queried drive */
379 ret = SetCurrentDirectory(windowsdir);
380 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
381 SetLastError(0xdeadbeef);
382 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
383 NULL, NULL, fs_name_buf, fs_name_len);
384 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
385 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
387 /* reset current directory */
388 ret = SetCurrentDirectory(currentdir);
389 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
391 if (toupper(currentdir[0]) == toupper(windowsdir[0])) {
392 skip("Please re-run from another device than %c:\n", windowsdir[0]);
393 /* FIXME: Use GetLogicalDrives to find another device to avoid this skip. */
394 } else {
395 char Root_Env[]="=C:"; /* where MS maintains the per volume directory */
396 Root_Env[1] = windowsdir[0];
398 /* C:\windows becomes the current directory on drive C: */
399 /* Note that paths to subdirs are stored without trailing slash, like what GetCurrentDir yields. */
400 ret = SetEnvironmentVariable(Root_Env, windowsdir);
401 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
403 ret = SetCurrentDirectory(windowsdir);
404 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
405 ret = SetCurrentDirectory(currentdir);
406 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
408 /* windows dir is current on the root drive, call fails */
409 SetLastError(0xdeadbeef);
410 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
411 NULL, NULL, fs_name_buf, fs_name_len);
412 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
413 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
415 /* Try normal drive letter with trailing \ */
416 ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size, NULL,
417 NULL, NULL, fs_name_buf, fs_name_len);
418 ok(ret, "GetVolumeInformationA with \\ failed, last error %u\n", GetLastError());
420 ret = SetCurrentDirectory(Root_Slash);
421 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
422 ret = SetCurrentDirectory(currentdir);
423 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
425 /* windows dir is STILL CURRENT on root drive; the call fails as before, */
426 /* proving that SetCurrentDir did not remember the other drive's directory */
427 SetLastError(0xdeadbeef);
428 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
429 NULL, NULL, fs_name_buf, fs_name_len);
430 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
431 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
433 /* Now C:\ becomes the current directory on drive C: */
434 ret = SetEnvironmentVariable(Root_Env, Root_Slash); /* set =C:=C:\ */
435 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
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());
442 /* again, SetCurrentDirectory on another drive does not matter */
443 ret = SetCurrentDirectory(Root_Slash);
444 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
445 ret = SetCurrentDirectory(currentdir);
446 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
448 /* \ is current on root drive, call succeeds */
449 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
450 NULL, NULL, fs_name_buf, fs_name_len);
451 ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
454 /* try null root directory to return "root of the current directory" */
455 ret = pGetVolumeInformationA(NULL, vol_name_buf, vol_name_size, NULL,
456 NULL, NULL, fs_name_buf, fs_name_len);
457 ok(ret, "GetVolumeInformationA failed on null root dir, last error %u\n", GetLastError());
459 /* Try normal drive letter with trailing \ */
460 ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size,
461 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
462 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Slash, GetLastError());
464 /* try again with drive letter and the "disable parsing" prefix */
465 SetLastError(0xdeadbeef);
466 ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
467 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
468 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
470 /* try again with device name space */
471 Root_UNC[2] = '.';
472 SetLastError(0xdeadbeef);
473 ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
474 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
475 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
477 /* try again with a directory off the root - should generate error */
478 if (windowsdir[strlen(windowsdir)-1] != '\\') strcat(windowsdir, "\\");
479 SetLastError(0xdeadbeef);
480 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
481 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
482 ok(!ret && (GetLastError()==ERROR_DIR_NOT_ROOT),
483 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
484 /* A subdir with trailing \ yields DIR_NOT_ROOT instead of INVALID_NAME */
485 if (windowsdir[strlen(windowsdir)-1] == '\\') windowsdir[strlen(windowsdir)-1] = 0;
486 SetLastError(0xdeadbeef);
487 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
488 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
489 ok(!ret && (GetLastError()==ERROR_INVALID_NAME),
490 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
492 if (!pGetVolumeNameForVolumeMountPointA) {
493 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
494 return;
496 /* get the unique volume name for the windows drive */
497 ret = pGetVolumeNameForVolumeMountPointA(Root_Slash, volume, MAX_PATH);
498 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
500 /* try again with unique volume name */
501 ret = pGetVolumeInformationA(volume, vol_name_buf, vol_name_size,
502 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
503 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", volume, GetLastError());
506 /* Test to check that unique volume name from windows dir mount point */
507 /* matches at least one of the unique volume names returned from the */
508 /* FindFirstVolumeA/FindNextVolumeA list. */
509 static void test_enum_vols(void)
511 DWORD ret;
512 HANDLE hFind = INVALID_HANDLE_VALUE;
513 char Volume_1[MAX_PATH] = {0};
514 char Volume_2[MAX_PATH] = {0};
515 char path[] = "c:\\";
516 BOOL found = FALSE;
517 char windowsdir[MAX_PATH];
519 if (!pGetVolumeNameForVolumeMountPointA) {
520 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
521 return;
524 /*get windows drive letter and update strings for testing */
525 ret = GetWindowsDirectory( windowsdir, sizeof(windowsdir) );
526 ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
527 ok(ret != 0, "GetWindowsDirecory: error %d\n", GetLastError());
528 path[0] = windowsdir[0];
530 /* get the unique volume name for the windows drive */
531 ret = pGetVolumeNameForVolumeMountPointA( path, Volume_1, MAX_PATH );
532 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
533 ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1);
535 /* get first unique volume name of list */
536 hFind = pFindFirstVolumeA( Volume_2, MAX_PATH );
537 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstVolume failed, err=%u\n",
538 GetLastError());
542 /* validate correct length of unique volume name */
543 ok(strlen(Volume_2) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1);
544 if (memcmp(Volume_1, Volume_2, 49) == 0)
546 found = TRUE;
547 break;
549 } while (pFindNextVolumeA( hFind, Volume_2, MAX_PATH ));
550 ok(found, "volume name %s not found by Find[First/Next]Volume\n", Volume_1);
551 pFindVolumeClose( hFind );
554 static void test_disk_extents(void)
556 BOOL ret;
557 DWORD size;
558 HANDLE handle;
559 static DWORD data[16];
561 handle = CreateFileA( "\\\\.\\c:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
562 if (handle == INVALID_HANDLE_VALUE)
564 win_skip("can't open c: drive %u\n", GetLastError());
565 return;
567 size = 0;
568 ret = DeviceIoControl( handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, &data,
569 sizeof(data), &data, sizeof(data), &size, NULL );
570 if (!ret && GetLastError() == ERROR_INVALID_FUNCTION)
572 win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
573 CloseHandle( handle );
574 return;
576 ok(ret, "DeviceIoControl failed %u\n", GetLastError());
577 ok(size == 32, "expected 32, got %u\n", size);
578 CloseHandle( handle );
581 static void test_GetVolumePathNamesForVolumeNameA(void)
583 BOOL ret;
584 char volume[MAX_PATH], buffer[MAX_PATH];
585 DWORD len, error;
587 if (!pGetVolumePathNamesForVolumeNameA || !pGetVolumeNameForVolumeMountPointA)
589 win_skip("required functions not found\n");
590 return;
593 ret = pGetVolumeNameForVolumeMountPointA( "c:\\", volume, sizeof(volume) );
594 ok(ret, "failed to get volume name %u\n", GetLastError());
595 trace("c:\\ -> %s\n", volume);
597 SetLastError( 0xdeadbeef );
598 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, NULL );
599 error = GetLastError();
600 ok(!ret, "expected failure\n");
601 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
603 SetLastError( 0xdeadbeef );
604 ret = pGetVolumePathNamesForVolumeNameA( "", NULL, 0, NULL );
605 error = GetLastError();
606 ok(!ret, "expected failure\n");
607 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
609 SetLastError( 0xdeadbeef );
610 ret = pGetVolumePathNamesForVolumeNameA( volume, NULL, 0, NULL );
611 error = GetLastError();
612 ok(!ret, "expected failure\n");
613 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
615 SetLastError( 0xdeadbeef );
616 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, 0, NULL );
617 error = GetLastError();
618 ok(!ret, "expected failure\n");
619 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
621 memset( buffer, 0xff, sizeof(buffer) );
622 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), NULL );
623 ok(ret, "failed to get path names %u\n", GetLastError());
624 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
625 ok(!buffer[4], "expected double null-terminated buffer\n");
627 len = 0;
628 SetLastError( 0xdeadbeef );
629 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, &len );
630 error = GetLastError();
631 ok(!ret, "expected failure\n");
632 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
634 len = 0;
635 SetLastError( 0xdeadbeef );
636 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, sizeof(buffer), &len );
637 error = GetLastError();
638 ok(!ret, "expected failure\n");
639 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
641 len = 0;
642 SetLastError( 0xdeadbeef );
643 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
644 error = GetLastError();
645 ok(!ret, "expected failure\n");
646 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
648 len = 0;
649 SetLastError( 0xdeadbeef );
650 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
651 error = GetLastError();
652 ok(!ret, "expected failure\n");
653 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
655 len = 0;
656 memset( buffer, 0xff, sizeof(buffer) );
657 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), &len );
658 ok(ret, "failed to get path names %u\n", GetLastError());
659 ok(len == 5 || broken(len == 2), "expected 5 got %u\n", len);
660 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
661 ok(!buffer[4], "expected double null-terminated buffer\n");
664 static void test_GetVolumePathNamesForVolumeNameW(void)
666 static const WCHAR empty[] = {0};
667 static const WCHAR drive_c[] = {'c',':','\\',0};
668 static const WCHAR volume_null[] = {'\\','\\','?','\\','V','o','l','u','m','e',
669 '{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0','0',
670 '-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',0};
671 BOOL ret;
672 WCHAR volume[MAX_PATH], buffer[MAX_PATH];
673 DWORD len, error;
675 if (!pGetVolumePathNamesForVolumeNameW || !pGetVolumeNameForVolumeMountPointW)
677 win_skip("required functions not found\n");
678 return;
681 ret = pGetVolumeNameForVolumeMountPointW( drive_c, volume, sizeof(volume)/sizeof(volume[0]) );
682 ok(ret, "failed to get volume name %u\n", GetLastError());
684 SetLastError( 0xdeadbeef );
685 ret = pGetVolumePathNamesForVolumeNameW( empty, NULL, 0, NULL );
686 error = GetLastError();
687 ok(!ret, "expected failure\n");
688 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
690 SetLastError( 0xdeadbeef );
691 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, 0, NULL );
692 error = GetLastError();
693 ok(!ret, "expected failure\n");
694 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
696 SetLastError( 0xdeadbeef );
697 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, 0, NULL );
698 error = GetLastError();
699 ok(!ret, "expected failure\n");
700 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
702 if (0) { /* crash */
703 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, sizeof(buffer), NULL );
704 ok(ret, "failed to get path names %u\n", GetLastError());
707 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), NULL );
708 ok(ret, "failed to get path names %u\n", GetLastError());
710 len = 0;
711 memset( buffer, 0xff, sizeof(buffer) );
712 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
713 ok(ret, "failed to get path names %u\n", GetLastError());
714 ok(len == 5, "expected 5 got %u\n", len);
715 ok(!buffer[4], "expected double null-terminated buffer\n");
717 len = 0;
718 volume[1] = '?';
719 volume[lstrlenW( volume ) - 1] = 0;
720 SetLastError( 0xdeadbeef );
721 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
722 error = GetLastError();
723 ok(!ret, "expected failure\n");
724 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
726 len = 0;
727 volume[0] = '\\';
728 volume[1] = 0;
729 SetLastError( 0xdeadbeef );
730 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
731 error = GetLastError();
732 ok(!ret, "expected failure\n");
733 todo_wine ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
735 len = 0;
736 lstrcpyW( volume, volume_null );
737 SetLastError( 0xdeadbeef );
738 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
739 error = GetLastError();
740 ok(!ret, "expected failure\n");
741 ok(error == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND got %u\n", error);
744 static void test_dvd_read_structure(HANDLE handle)
746 int i;
747 DWORD nbBytes;
748 BOOL ret;
749 DVD_READ_STRUCTURE dvdReadStructure;
750 DVD_LAYER_DESCRIPTOR dvdLayerDescriptor;
751 struct COMPLETE_DVD_LAYER_DESCRIPTOR completeDvdLayerDescriptor;
752 DVD_COPYRIGHT_DESCRIPTOR dvdCopyrightDescriptor;
754 dvdReadStructure.BlockByteOffset.QuadPart = 0;
755 dvdReadStructure.SessionId = 0;
756 dvdReadStructure.LayerNumber = 0;
759 /* DvdPhysicalDescriptor */
760 dvdReadStructure.Format = 0;
762 SetLastError(0xdeadbeef);
764 /* Test whether this ioctl is supported */
765 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
766 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
767 if ((!ret && GetLastError() == ERROR_INVALID_FUNCTION)
768 || (!ret && GetLastError() == ERROR_NOT_SUPPORTED))
770 skip("IOCTL_DVD_READ_STRUCTURE not supported\n");
771 return;
774 ok(ret || broken(GetLastError() == ERROR_NOT_READY) || broken(GetLastError() == ERROR_INVALID_PARAMETER),
775 "IOCTL_DVD_READ_STRUCTURE (DvdPhysicalDescriptor) failed, last error = %u\n", GetLastError());
776 if(!ret)
777 return;
779 /* Confirm there is always a header before the actual data */
780 ok( completeDvdLayerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdLayerDescriptor.Header.Length);
781 ok( completeDvdLayerDescriptor.Header.Reserved[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[0]);
782 ok( completeDvdLayerDescriptor.Header.Reserved[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[1]);
784 /* TODO: Also check completeDvdLayerDescriptor.Descriptor content (via IOCTL_SCSI_PASS_THROUGH_DIRECT ?) */
786 /* Insufficient output buffer */
787 for(i=0; i<sizeof(DVD_DESCRIPTOR_HEADER); i++)
789 SetLastError(0xdeadbeef);
791 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
792 &completeDvdLayerDescriptor, i, &nbBytes, NULL);
793 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,"IOCTL_DVD_READ_STRUCTURE should fail with small buffer\n");
796 SetLastError(0xdeadbeef);
798 /* On newer version, an output buffer of sizeof(DVD_READ_STRUCTURE) size fails.
799 I think this is to force developpers to realize that there is a header before the actual content */
800 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
801 &dvdLayerDescriptor, sizeof(DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
802 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER) || broken(ret) /* < Win7 */,
803 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
805 SetLastError(0xdeadbeef);
807 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, NULL, sizeof(DVD_READ_STRUCTURE),
808 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
809 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER),
810 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
812 /* Test wrong input parameters */
813 for(i=0; i<sizeof(DVD_READ_STRUCTURE); i++)
815 SetLastError(0xdeadbeef);
817 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, i,
818 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
819 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER),
820 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
824 /* DvdCopyrightDescriptor */
825 dvdReadStructure.Format = 1;
827 SetLastError(0xdeadbeef);
829 /* Strangely, with NULL lpOutBuffer, last error is insufficient buffer, not invalid parameter as we could expect */
830 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
831 NULL, sizeof(DVD_COPYRIGHT_DESCRIPTOR), &nbBytes, NULL);
832 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret, GetLastError());
834 for(i=0; i<sizeof(DVD_COPYRIGHT_DESCRIPTOR); i++)
836 SetLastError(0xdeadbeef);
838 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
839 &dvdCopyrightDescriptor, i, &nbBytes, NULL);
840 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret, GetLastError());
844 static void test_cdrom_ioctl(void)
846 char drive_letter, drive_path[] = "A:\\", drive_full_path[] = "\\\\.\\A:";
847 DWORD bitmask;
848 HANDLE handle;
850 bitmask = GetLogicalDrives();
851 if(!bitmask)
853 trace("GetLogicalDrives failed : %u\n", GetLastError());
854 return;
857 for(drive_letter='A'; drive_letter<='Z'; drive_letter++)
859 if(!(bitmask & (1 << (drive_letter-'A') )))
860 continue;
862 drive_path[0] = drive_letter;
863 if(GetDriveTypeA(drive_path) != DRIVE_CDROM)
865 trace("Skipping %c:, not a CDROM drive.\n", drive_letter);
866 continue;
869 trace("Testing with %c:\n", drive_letter);
871 drive_full_path[4] = drive_letter;
872 handle = CreateFileA(drive_full_path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
873 if(handle == INVALID_HANDLE_VALUE)
875 trace("Failed to open the device : %u\n", GetLastError());
876 continue;
879 /* Add your tests here */
880 test_dvd_read_structure(handle);
882 CloseHandle(handle);
887 START_TEST(volume)
889 hdll = GetModuleHandleA("kernel32.dll");
890 pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointA");
891 pGetVolumeNameForVolumeMountPointW = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointW");
892 pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
893 pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
894 pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
895 pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
896 pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
897 pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
898 pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA");
899 pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW");
901 test_query_dos_deviceA();
902 test_define_dos_deviceA();
903 test_FindFirstVolume();
904 test_GetVolumeNameForVolumeMountPointA();
905 test_GetVolumeNameForVolumeMountPointW();
906 test_GetLogicalDriveStringsA();
907 test_GetLogicalDriveStringsW();
908 test_GetVolumeInformationA();
909 test_enum_vols();
910 test_disk_extents();
911 test_GetVolumePathNamesForVolumeNameA();
912 test_GetVolumePathNamesForVolumeNameW();
913 test_cdrom_ioctl();