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"
25 #include "ddk/ntddcdvd.h"
28 struct COMPLETE_DVD_LAYER_DESCRIPTOR
30 DVD_DESCRIPTOR_HEADER Header
;
31 DVD_LAYER_DESCRIPTOR Descriptor
;
35 C_ASSERT(sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR
) == 22);
38 struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR
40 DVD_DESCRIPTOR_HEADER Header
;
41 DVD_MANUFACTURER_DESCRIPTOR Descriptor
;
45 C_ASSERT(sizeof(struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR
) == 2053);
47 static HINSTANCE hdll
;
48 static BOOL (WINAPI
* pGetVolumeNameForVolumeMountPointA
)(LPCSTR
, LPSTR
, DWORD
);
49 static BOOL (WINAPI
* pGetVolumeNameForVolumeMountPointW
)(LPCWSTR
, LPWSTR
, DWORD
);
50 static HANDLE (WINAPI
*pFindFirstVolumeA
)(LPSTR
,DWORD
);
51 static BOOL (WINAPI
*pFindNextVolumeA
)(HANDLE
,LPSTR
,DWORD
);
52 static BOOL (WINAPI
*pFindVolumeClose
)(HANDLE
);
53 static UINT (WINAPI
*pGetLogicalDriveStringsA
)(UINT
,LPSTR
);
54 static UINT (WINAPI
*pGetLogicalDriveStringsW
)(UINT
,LPWSTR
);
55 static BOOL (WINAPI
*pGetVolumeInformationA
)(LPCSTR
, LPSTR
, DWORD
, LPDWORD
, LPDWORD
, LPDWORD
, LPSTR
, DWORD
);
56 static BOOL (WINAPI
*pGetVolumePathNameA
)(LPCSTR
, LPSTR
, DWORD
);
57 static BOOL (WINAPI
*pGetVolumePathNameW
)(LPWSTR
, LPWSTR
, DWORD
);
58 static BOOL (WINAPI
*pGetVolumePathNamesForVolumeNameA
)(LPCSTR
, LPSTR
, DWORD
, LPDWORD
);
59 static BOOL (WINAPI
*pGetVolumePathNamesForVolumeNameW
)(LPCWSTR
, LPWSTR
, DWORD
, LPDWORD
);
61 /* ############################### */
63 static void test_query_dos_deviceA(void)
65 char drivestr
[] = "a:";
66 char *p
, *buffer
, buffer2
[2000];
67 DWORD ret
, ret2
, buflen
=32768;
70 /* callers must guess the buffer size */
71 SetLastError(0xdeadbeef);
72 ret
= QueryDosDeviceA( NULL
, NULL
, 0 );
73 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
74 "QueryDosDeviceA(no buffer): returned %u, le=%u\n", ret
, GetLastError());
76 buffer
= HeapAlloc( GetProcessHeap(), 0, buflen
);
77 SetLastError(0xdeadbeef);
78 ret
= QueryDosDeviceA( NULL
, buffer
, buflen
);
79 ok((ret
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER
),
80 "QueryDosDeviceA failed to return list, last error %u\n", GetLastError());
82 if (ret
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER
) {
85 if (!strlen(p
)) break;
86 ret2
= QueryDosDeviceA( p
, buffer2
, sizeof(buffer2
) );
87 ok(ret2
, "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", p
, GetLastError());
89 if (ret
<= (p
-buffer
)) break;
93 for (;drivestr
[0] <= 'z'; drivestr
[0]++) {
94 /* Older W2K fails with ERROR_INSUFFICIENT_BUFFER when buflen is > 32767 */
95 ret
= QueryDosDeviceA( drivestr
, buffer
, buflen
- 1);
96 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
97 "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", drivestr
, GetLastError());
99 for (p
= buffer
; *p
; p
++) *p
= toupper(*p
);
100 if (strstr(buffer
, "HARDDISK") || strstr(buffer
, "RAMDISK")) found
= TRUE
;
103 ok(found
, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
104 HeapFree( GetProcessHeap(), 0, buffer
);
107 static void test_define_dos_deviceA(void)
113 /* Find an unused drive letter */
116 for (drivestr
[0] = 'a'; drivestr
[0] <= 'z'; drivestr
[0]++) {
117 ret
= QueryDosDeviceA( drivestr
, buf
, sizeof(buf
));
120 if (drivestr
[0] > 'z') {
121 skip("can't test creating a dos drive, none available\n");
125 /* Map it to point to the current directory */
126 ret
= GetCurrentDirectoryA(sizeof(buf
), buf
);
127 ok(ret
, "GetCurrentDir\n");
129 ret
= DefineDosDeviceA(0, drivestr
, buf
);
131 ok(ret
, "Could not make drive %s point to %s!\n", drivestr
, buf
);
134 skip("can't test removing fake drive\n");
136 ret
= DefineDosDeviceA(DDD_REMOVE_DEFINITION
, drivestr
, NULL
);
137 ok(ret
, "Could not remove fake drive %s!\n", drivestr
);
141 static void test_FindFirstVolume(void)
146 /* not present before w2k */
147 if (!pFindFirstVolumeA
) {
148 win_skip("FindFirstVolumeA not found\n");
152 handle
= pFindFirstVolumeA( volume
, 0 );
153 ok( handle
== INVALID_HANDLE_VALUE
, "succeeded with short buffer\n" );
154 ok( GetLastError() == ERROR_MORE_DATA
|| /* XP */
155 GetLastError() == ERROR_FILENAME_EXCED_RANGE
, /* Vista */
156 "wrong error %u\n", GetLastError() );
157 handle
= pFindFirstVolumeA( volume
, 49 );
158 ok( handle
== INVALID_HANDLE_VALUE
, "succeeded with short buffer\n" );
159 ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE
, "wrong error %u\n", GetLastError() );
160 handle
= pFindFirstVolumeA( volume
, 51 );
161 ok( handle
!= INVALID_HANDLE_VALUE
, "failed err %u\n", GetLastError() );
162 if (handle
!= INVALID_HANDLE_VALUE
)
166 ok( strlen(volume
) == 49, "bad volume name %s\n", volume
);
167 ok( !memcmp( volume
, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume
);
168 ok( !memcmp( volume
+ 47, "}\\", 2 ), "bad volume name %s\n", volume
);
169 } while (pFindNextVolumeA( handle
, volume
, MAX_PATH
));
170 ok( GetLastError() == ERROR_NO_MORE_FILES
, "wrong error %u\n", GetLastError() );
171 pFindVolumeClose( handle
);
175 static void test_GetVolumeNameForVolumeMountPointA(void)
178 char volume
[MAX_PATH
], path
[] = "c:\\";
179 DWORD len
= sizeof(volume
), reti
;
180 char temp_path
[MAX_PATH
];
182 /* not present before w2k */
183 if (!pGetVolumeNameForVolumeMountPointA
) {
184 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
188 reti
= GetTempPathA(MAX_PATH
, temp_path
);
189 ok(reti
!= 0, "GetTempPathA error %d\n", GetLastError());
190 ok(reti
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
192 ret
= pGetVolumeNameForVolumeMountPointA(path
, volume
, 0);
193 ok(ret
== FALSE
, "GetVolumeNameForVolumeMountPointA succeeded\n");
194 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE
||
195 GetLastError() == ERROR_INVALID_PARAMETER
, /* Vista */
196 "wrong error, last=%d\n", GetLastError());
198 if (0) { /* these crash on XP */
199 ret
= pGetVolumeNameForVolumeMountPointA(path
, NULL
, len
);
200 ok(ret
== FALSE
, "GetVolumeNameForVolumeMountPointA succeeded\n");
202 ret
= pGetVolumeNameForVolumeMountPointA(NULL
, volume
, len
);
203 ok(ret
== FALSE
, "GetVolumeNameForVolumeMountPointA succeeded\n");
206 ret
= pGetVolumeNameForVolumeMountPointA(path
, volume
, len
);
207 ok(ret
== TRUE
, "GetVolumeNameForVolumeMountPointA failed\n");
208 ok(!strncmp( volume
, "\\\\?\\Volume{", 11),
209 "GetVolumeNameForVolumeMountPointA failed to return valid string <%s>\n",
212 /* test with too small buffer */
213 ret
= pGetVolumeNameForVolumeMountPointA(path
, volume
, 10);
214 ok(ret
== FALSE
&& GetLastError() == ERROR_FILENAME_EXCED_RANGE
,
215 "GetVolumeNameForVolumeMountPointA failed, wrong error returned, was %d, should be ERROR_FILENAME_EXCED_RANGE\n",
218 /* Try on an arbitrary directory */
219 /* On FAT filesystems it seems that GetLastError() is set to
220 ERROR_INVALID_FUNCTION. */
221 ret
= pGetVolumeNameForVolumeMountPointA(temp_path
, volume
, len
);
222 ok(ret
== FALSE
&& (GetLastError() == ERROR_NOT_A_REPARSE_POINT
||
223 GetLastError() == ERROR_INVALID_FUNCTION
),
224 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
225 temp_path
, GetLastError());
227 /* Try on a nonexistent dos drive */
229 for (;path
[0] <= 'z'; path
[0]++) {
230 ret
= QueryDosDeviceA( path
, volume
, len
);
236 ret
= pGetVolumeNameForVolumeMountPointA(path
, volume
, len
);
237 ok(ret
== FALSE
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
238 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
239 path
, GetLastError());
241 /* Try without trailing \ and on a nonexistent dos drive */
243 ret
= pGetVolumeNameForVolumeMountPointA(path
, volume
, len
);
244 ok(ret
== FALSE
&& GetLastError() == ERROR_INVALID_NAME
,
245 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
246 path
, GetLastError());
250 static void test_GetVolumeNameForVolumeMountPointW(void)
253 WCHAR volume
[MAX_PATH
], path
[] = {'c',':','\\',0};
254 DWORD len
= sizeof(volume
) / sizeof(WCHAR
);
256 /* not present before w2k */
257 if (!pGetVolumeNameForVolumeMountPointW
) {
258 win_skip("GetVolumeNameForVolumeMountPointW not found\n");
262 ret
= pGetVolumeNameForVolumeMountPointW(path
, volume
, 0);
263 ok(ret
== FALSE
, "GetVolumeNameForVolumeMountPointA succeeded\n");
264 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE
||
265 GetLastError() == ERROR_INVALID_PARAMETER
, /* Vista */
266 "wrong error, last=%d\n", GetLastError());
268 if (0) { /* these crash on XP */
269 ret
= pGetVolumeNameForVolumeMountPointW(path
, NULL
, len
);
270 ok(ret
== FALSE
, "GetVolumeNameForVolumeMountPointW succeeded\n");
272 ret
= pGetVolumeNameForVolumeMountPointW(NULL
, volume
, len
);
273 ok(ret
== FALSE
, "GetVolumeNameForVolumeMountPointW succeeded\n");
276 ret
= pGetVolumeNameForVolumeMountPointW(path
, volume
, len
);
277 ok(ret
== TRUE
, "GetVolumeNameForVolumeMountPointW failed\n");
280 static void test_GetLogicalDriveStringsA(void)
285 ok( pGetLogicalDriveStringsA
!= NULL
, "GetLogicalDriveStringsA not available\n");
286 if(!pGetLogicalDriveStringsA
) {
290 size
= pGetLogicalDriveStringsA(0, NULL
);
291 ok(size
%4 == 1, "size = %d\n", size
);
293 buf
= HeapAlloc(GetProcessHeap(), 0, size
);
296 size2
= pGetLogicalDriveStringsA(2, buf
);
297 ok(size2
== size
, "size2 = %d\n", size2
);
298 ok(!*buf
, "buf changed\n");
300 size2
= pGetLogicalDriveStringsA(size
, buf
);
301 ok(size2
== size
-1, "size2 = %d\n", size2
);
303 for(ptr
= buf
; ptr
< buf
+size2
; ptr
+= 4) {
304 ok(('A' <= *ptr
&& *ptr
<= 'Z'), "device name '%c' is not uppercase\n", *ptr
);
305 ok(ptr
[1] == ':', "ptr[1] = %c, expected ':'\n", ptr
[1]);
306 ok(ptr
[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr
[2]);
307 ok(!ptr
[3], "ptr[3] = %c expected nullbyte\n", ptr
[3]);
309 ok(!*ptr
, "buf[size2] is not nullbyte\n");
311 HeapFree(GetProcessHeap(), 0, buf
);
314 static void test_GetLogicalDriveStringsW(void)
319 ok( pGetLogicalDriveStringsW
!= NULL
, "GetLogicalDriveStringsW not available\n");
320 if(!pGetLogicalDriveStringsW
) {
324 SetLastError(0xdeadbeef);
325 size
= pGetLogicalDriveStringsW(0, NULL
);
326 if (size
== 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
) {
327 win_skip("GetLogicalDriveStringsW not implemented\n");
330 ok(size
%4 == 1, "size = %d\n", size
);
332 buf
= HeapAlloc(GetProcessHeap(), 0, size
*sizeof(WCHAR
));
335 size2
= pGetLogicalDriveStringsW(2, buf
);
336 ok(size2
== size
, "size2 = %d\n", size2
);
337 ok(!*buf
, "buf changed\n");
339 size2
= pGetLogicalDriveStringsW(size
, buf
);
340 ok(size2
== size
-1, "size2 = %d\n", size2
);
342 for(ptr
= buf
; ptr
< buf
+size2
; ptr
+= 4) {
343 ok('A' <= *ptr
&& *ptr
<= 'Z', "device name '%c' is not uppercase\n", *ptr
);
344 ok(ptr
[1] == ':', "ptr[1] = %c, expected ':'\n", ptr
[1]);
345 ok(ptr
[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr
[2]);
346 ok(!ptr
[3], "ptr[3] = %c expected nullbyte\n", ptr
[3]);
348 ok(!*ptr
, "buf[size2] is not nullbyte\n");
350 HeapFree(GetProcessHeap(), 0, buf
);
353 static void test_GetVolumeInformationA(void)
357 char Root_Colon
[]="C:";
358 char Root_Slash
[]="C:\\";
359 char Root_UNC
[]="\\\\?\\C:\\";
360 char volume
[MAX_PATH
+1];
361 DWORD vol_name_size
=MAX_PATH
+1, vol_serial_num
=-1, max_comp_len
=0, fs_flags
=0, fs_name_len
=MAX_PATH
+1;
362 char vol_name_buf
[MAX_PATH
+1], fs_name_buf
[MAX_PATH
+1];
363 char windowsdir
[MAX_PATH
+10];
364 char currentdir
[MAX_PATH
+1];
366 ok( pGetVolumeInformationA
!= NULL
, "GetVolumeInformationA not found\n");
367 if(!pGetVolumeInformationA
) {
371 /* get windows drive letter and update strings for testing */
372 result
= GetWindowsDirectoryA(windowsdir
, sizeof(windowsdir
));
373 ok(result
< sizeof(windowsdir
), "windowsdir is abnormally long!\n");
374 ok(result
!= 0, "GetWindowsDirectory: error %d\n", GetLastError());
375 Root_Colon
[0] = windowsdir
[0];
376 Root_Slash
[0] = windowsdir
[0];
377 Root_UNC
[4] = windowsdir
[0];
379 result
= GetCurrentDirectoryA(MAX_PATH
, currentdir
);
380 ok(result
, "GetCurrentDirectory: error %d\n", GetLastError());
381 /* Note that GetCurrentDir yields no trailing slash for subdirs */
383 /* check for NO error on no trailing \ when current dir is root dir */
384 ret
= SetCurrentDirectoryA(Root_Slash
);
385 ok(ret
, "SetCurrentDirectory: error %d\n", GetLastError());
386 ret
= pGetVolumeInformationA(Root_Colon
, vol_name_buf
, vol_name_size
, NULL
,
387 NULL
, NULL
, fs_name_buf
, fs_name_len
);
388 ok(ret
, "GetVolumeInformationA root failed, last error %u\n", GetLastError());
390 /* check for error on no trailing \ when current dir is subdir (windows) of queried drive */
391 ret
= SetCurrentDirectoryA(windowsdir
);
392 ok(ret
, "SetCurrentDirectory: error %d\n", GetLastError());
393 SetLastError(0xdeadbeef);
394 ret
= pGetVolumeInformationA(Root_Colon
, vol_name_buf
, vol_name_size
, NULL
,
395 NULL
, NULL
, fs_name_buf
, fs_name_len
);
396 ok(!ret
&& (GetLastError() == ERROR_INVALID_NAME
),
397 "GetVolumeInformationA did%s fail, last error %u\n", ret
? " not":"", GetLastError());
399 /* reset current directory */
400 ret
= SetCurrentDirectoryA(currentdir
);
401 ok(ret
, "SetCurrentDirectory: error %d\n", GetLastError());
403 if (toupper(currentdir
[0]) == toupper(windowsdir
[0])) {
404 skip("Please re-run from another device than %c:\n", windowsdir
[0]);
405 /* FIXME: Use GetLogicalDrives to find another device to avoid this skip. */
407 char Root_Env
[]="=C:"; /* where MS maintains the per volume directory */
408 Root_Env
[1] = windowsdir
[0];
410 /* C:\windows becomes the current directory on drive C: */
411 /* Note that paths to subdirs are stored without trailing slash, like what GetCurrentDir yields. */
412 ret
= SetEnvironmentVariableA(Root_Env
, windowsdir
);
413 ok(ret
, "SetEnvironmentVariable %s failed\n", Root_Env
);
415 ret
= SetCurrentDirectoryA(windowsdir
);
416 ok(ret
, "SetCurrentDirectory: error %d\n", GetLastError());
417 ret
= SetCurrentDirectoryA(currentdir
);
418 ok(ret
, "SetCurrentDirectory: error %d\n", GetLastError());
420 /* windows dir is current on the root drive, call fails */
421 SetLastError(0xdeadbeef);
422 ret
= pGetVolumeInformationA(Root_Colon
, vol_name_buf
, vol_name_size
, NULL
,
423 NULL
, NULL
, fs_name_buf
, fs_name_len
);
424 ok(!ret
&& (GetLastError() == ERROR_INVALID_NAME
),
425 "GetVolumeInformationA did%s fail, last error %u\n", ret
? " not":"", GetLastError());
427 /* Try normal drive letter with trailing \ */
428 ret
= pGetVolumeInformationA(Root_Slash
, vol_name_buf
, vol_name_size
, NULL
,
429 NULL
, NULL
, fs_name_buf
, fs_name_len
);
430 ok(ret
, "GetVolumeInformationA with \\ failed, last error %u\n", GetLastError());
432 ret
= SetCurrentDirectoryA(Root_Slash
);
433 ok(ret
, "SetCurrentDirectory: error %d\n", GetLastError());
434 ret
= SetCurrentDirectoryA(currentdir
);
435 ok(ret
, "SetCurrentDirectory: error %d\n", GetLastError());
437 /* windows dir is STILL CURRENT on root drive; the call fails as before, */
438 /* proving that SetCurrentDir did not remember the other drive's directory */
439 SetLastError(0xdeadbeef);
440 ret
= pGetVolumeInformationA(Root_Colon
, vol_name_buf
, vol_name_size
, NULL
,
441 NULL
, NULL
, fs_name_buf
, fs_name_len
);
442 ok(!ret
&& (GetLastError() == ERROR_INVALID_NAME
),
443 "GetVolumeInformationA did%s fail, last error %u\n", ret
? " not":"", GetLastError());
445 /* Now C:\ becomes the current directory on drive C: */
446 ret
= SetEnvironmentVariableA(Root_Env
, Root_Slash
); /* set =C:=C:\ */
447 ok(ret
, "SetEnvironmentVariable %s failed\n", Root_Env
);
449 /* \ is current on root drive, call succeeds */
450 ret
= pGetVolumeInformationA(Root_Colon
, vol_name_buf
, vol_name_size
, NULL
,
451 NULL
, NULL
, fs_name_buf
, fs_name_len
);
452 ok(ret
, "GetVolumeInformationA failed, last error %u\n", GetLastError());
454 /* again, SetCurrentDirectory on another drive does not matter */
455 ret
= SetCurrentDirectoryA(Root_Slash
);
456 ok(ret
, "SetCurrentDirectory: error %d\n", GetLastError());
457 ret
= SetCurrentDirectoryA(currentdir
);
458 ok(ret
, "SetCurrentDirectory: error %d\n", GetLastError());
460 /* \ is current on root drive, call succeeds */
461 ret
= pGetVolumeInformationA(Root_Colon
, vol_name_buf
, vol_name_size
, NULL
,
462 NULL
, NULL
, fs_name_buf
, fs_name_len
);
463 ok(ret
, "GetVolumeInformationA failed, last error %u\n", GetLastError());
466 /* try null root directory to return "root of the current directory" */
467 ret
= pGetVolumeInformationA(NULL
, vol_name_buf
, vol_name_size
, NULL
,
468 NULL
, NULL
, fs_name_buf
, fs_name_len
);
469 ok(ret
, "GetVolumeInformationA failed on null root dir, last error %u\n", GetLastError());
471 /* Try normal drive letter with trailing \ */
472 ret
= pGetVolumeInformationA(Root_Slash
, vol_name_buf
, vol_name_size
,
473 &vol_serial_num
, &max_comp_len
, &fs_flags
, fs_name_buf
, fs_name_len
);
474 ok(ret
, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Slash
, GetLastError());
476 /* try again with drive letter and the "disable parsing" prefix */
477 SetLastError(0xdeadbeef);
478 ret
= pGetVolumeInformationA(Root_UNC
, vol_name_buf
, vol_name_size
,
479 &vol_serial_num
, &max_comp_len
, &fs_flags
, fs_name_buf
, fs_name_len
);
480 ok(ret
, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret
? " not":"", Root_UNC
, GetLastError());
482 /* try again with device name space */
484 SetLastError(0xdeadbeef);
485 ret
= pGetVolumeInformationA(Root_UNC
, vol_name_buf
, vol_name_size
,
486 &vol_serial_num
, &max_comp_len
, &fs_flags
, fs_name_buf
, fs_name_len
);
487 ok(ret
, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret
? " not":"", Root_UNC
, GetLastError());
489 /* try again with a directory off the root - should generate error */
490 if (windowsdir
[strlen(windowsdir
)-1] != '\\') strcat(windowsdir
, "\\");
491 SetLastError(0xdeadbeef);
492 ret
= pGetVolumeInformationA(windowsdir
, vol_name_buf
, vol_name_size
,
493 &vol_serial_num
, &max_comp_len
, &fs_flags
, fs_name_buf
, fs_name_len
);
494 ok(!ret
&& (GetLastError()==ERROR_DIR_NOT_ROOT
),
495 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret
? " not":"", windowsdir
, GetLastError());
496 /* A subdir with trailing \ yields DIR_NOT_ROOT instead of INVALID_NAME */
497 if (windowsdir
[strlen(windowsdir
)-1] == '\\') windowsdir
[strlen(windowsdir
)-1] = 0;
498 SetLastError(0xdeadbeef);
499 ret
= pGetVolumeInformationA(windowsdir
, vol_name_buf
, vol_name_size
,
500 &vol_serial_num
, &max_comp_len
, &fs_flags
, fs_name_buf
, fs_name_len
);
501 ok(!ret
&& (GetLastError()==ERROR_INVALID_NAME
),
502 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret
? " not":"", windowsdir
, GetLastError());
504 if (!pGetVolumeNameForVolumeMountPointA
) {
505 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
508 /* get the unique volume name for the windows drive */
509 ret
= pGetVolumeNameForVolumeMountPointA(Root_Slash
, volume
, MAX_PATH
);
510 ok(ret
== TRUE
, "GetVolumeNameForVolumeMountPointA failed\n");
512 /* try again with unique volume name */
513 ret
= pGetVolumeInformationA(volume
, vol_name_buf
, vol_name_size
,
514 &vol_serial_num
, &max_comp_len
, &fs_flags
, fs_name_buf
, fs_name_len
);
515 ok(ret
, "GetVolumeInformationA failed, root=%s, last error=%u\n", volume
, GetLastError());
518 /* Test to check that unique volume name from windows dir mount point */
519 /* matches at least one of the unique volume names returned from the */
520 /* FindFirstVolumeA/FindNextVolumeA list. */
521 static void test_enum_vols(void)
524 HANDLE hFind
= INVALID_HANDLE_VALUE
;
525 char Volume_1
[MAX_PATH
] = {0};
526 char Volume_2
[MAX_PATH
] = {0};
527 char path
[] = "c:\\";
529 char windowsdir
[MAX_PATH
];
531 if (!pGetVolumeNameForVolumeMountPointA
) {
532 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
536 /*get windows drive letter and update strings for testing */
537 ret
= GetWindowsDirectoryA( windowsdir
, sizeof(windowsdir
) );
538 ok(ret
< sizeof(windowsdir
), "windowsdir is abnormally long!\n");
539 ok(ret
!= 0, "GetWindowsDirectory: error %d\n", GetLastError());
540 path
[0] = windowsdir
[0];
542 /* get the unique volume name for the windows drive */
543 ret
= pGetVolumeNameForVolumeMountPointA( path
, Volume_1
, MAX_PATH
);
544 ok(ret
== TRUE
, "GetVolumeNameForVolumeMountPointA failed\n");
545 ok(strlen(Volume_1
) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1
);
547 /* get first unique volume name of list */
548 hFind
= pFindFirstVolumeA( Volume_2
, MAX_PATH
);
549 ok(hFind
!= INVALID_HANDLE_VALUE
, "FindFirstVolume failed, err=%u\n",
554 /* validate correct length of unique volume name */
555 ok(strlen(Volume_2
) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1
);
556 if (memcmp(Volume_1
, Volume_2
, 49) == 0)
561 } while (pFindNextVolumeA( hFind
, Volume_2
, MAX_PATH
));
562 ok(found
, "volume name %s not found by Find[First/Next]Volume\n", Volume_1
);
563 pFindVolumeClose( hFind
);
566 static void test_disk_extents(void)
571 static DWORD data
[16];
573 handle
= CreateFileA( "\\\\.\\c:", GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
574 if (handle
== INVALID_HANDLE_VALUE
)
576 win_skip("can't open c: drive %u\n", GetLastError());
580 ret
= DeviceIoControl( handle
, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
, &data
,
581 sizeof(data
), &data
, sizeof(data
), &size
, NULL
);
582 if (!ret
&& GetLastError() == ERROR_INVALID_FUNCTION
)
584 win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
585 CloseHandle( handle
);
588 ok(ret
, "DeviceIoControl failed %u\n", GetLastError());
589 ok(size
== 32, "expected 32, got %u\n", size
);
590 CloseHandle( handle
);
593 static void test_GetVolumePathNameA(void)
595 char volume_path
[MAX_PATH
], cwd
[MAX_PATH
];
597 const char *file_name
;
598 const char *path_name
;
603 { /* test 0: NULL parameters, 0 output length */
605 ERROR_INVALID_PARAMETER
, 0xdeadbeef /* winxp */
607 { /* test 1: empty input, NULL output, 0 output length */
609 ERROR_INVALID_PARAMETER
, 0xdeadbeef /* winxp */
611 { /* test 2: valid input, NULL output, 0 output length */
613 ERROR_INVALID_PARAMETER
, ERROR_FILENAME_EXCED_RANGE
/* winxp */
615 { /* test 3: valid input, valid output, 0 output length */
617 ERROR_INVALID_PARAMETER
, ERROR_FILENAME_EXCED_RANGE
/* winxp */
619 { /* test 4: valid input, valid output, 1 output length */
621 ERROR_FILENAME_EXCED_RANGE
, NO_ERROR
623 { /* test 5: valid input, valid output, valid output length */
624 "C:\\", "C:\\", sizeof(volume_path
),
627 { /* test 6: lowercase input, uppercase output, valid output length */
628 "c:\\", "C:\\", sizeof(volume_path
),
631 { /* test 7: poor quality input, valid output, valid output length */
632 "C::", "C:\\", sizeof(volume_path
),
635 { /* test 8: really bogus input, valid output, 1 output length */
636 "\\\\$$$", "C:\\", 1,
637 ERROR_INVALID_NAME
, ERROR_FILENAME_EXCED_RANGE
639 { /* test 9: a reasonable DOS path that is guaranteed to exist */
640 "C:\\windows\\system32", "C:\\", sizeof(volume_path
),
643 { /* test 10: a reasonable DOS path that shouldn't exist */
644 "C:\\windows\\system32\\AnInvalidFolder", "C:\\", sizeof(volume_path
),
647 { /* test 11: a reasonable NT-converted DOS path that shouldn't exist */
648 "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:\\", sizeof(volume_path
),
651 { /* test 12: an unreasonable NT-converted DOS path */
652 "\\\\?\\InvalidDrive:\\AnInvalidFolder", "\\\\?\\InvalidDrive:\\" /* win2k, winxp */,
654 ERROR_INVALID_NAME
, NO_ERROR
656 { /* test 13: an unreasonable NT volume path */
657 "\\\\?\\Volume{00000000-00-0000-0000-000000000000}\\AnInvalidFolder",
658 "\\\\?\\Volume{00000000-00-0000-0000-000000000000}\\" /* win2k, winxp */,
660 ERROR_INVALID_NAME
, NO_ERROR
662 { /* test 14: an unreasonable NT-ish path */
663 "\\\\ReallyBogus\\InvalidDrive:\\AnInvalidFolder",
664 "\\\\ReallyBogus\\InvalidDrive:\\" /* win2k, winxp */, sizeof(volume_path
),
665 ERROR_INVALID_NAME
, NO_ERROR
667 { /* test 15: poor quality input, valid output, valid (but short) output length */
669 NO_ERROR
, ERROR_MORE_DATA
671 { /* test 16: unused drive letter */
673 ERROR_FILE_NOT_FOUND
, ERROR_MORE_DATA
675 { /* test 17: an unreasonable DOS path */
676 "InvalidDrive:\\AnInvalidFolder", "%CurrentDrive%\\", sizeof(volume_path
),
679 { /* test 18: a reasonable device path */
680 "\\??\\CdRom0", "%CurrentDrive%\\", sizeof(volume_path
),
683 { /* test 19: an unreasonable device path */
684 "\\??\\ReallyBogus", "%CurrentDrive%\\", sizeof(volume_path
),
689 ERROR_FILENAME_EXCED_RANGE
, NO_ERROR
693 NO_ERROR
, ERROR_FILENAME_EXCED_RANGE
697 ERROR_FILENAME_EXCED_RANGE
, NO_ERROR
701 NO_ERROR
, ERROR_FILENAME_EXCED_RANGE
705 ERROR_FILENAME_EXCED_RANGE
, NO_ERROR
709 NO_ERROR
, ERROR_FILENAME_EXCED_RANGE
713 NO_ERROR
, ERROR_MORE_DATA
716 "C:\\windows\\system32\\AnInvalidFolder", "C:", 3,
717 NO_ERROR
, ERROR_FILENAME_EXCED_RANGE
720 "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:", 3,
721 ERROR_FILENAME_EXCED_RANGE
, NO_ERROR
724 "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:", 6,
725 ERROR_FILENAME_EXCED_RANGE
, NO_ERROR
728 "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:", 7,
729 NO_ERROR
, ERROR_FILENAME_EXCED_RANGE
732 "\\\\?\\c:\\AnInvalidFolder", "\\\\?\\c:", 7,
733 NO_ERROR
, ERROR_FILENAME_EXCED_RANGE
737 NO_ERROR
, ERROR_MORE_DATA
741 ERROR_FILE_NOT_FOUND
, ERROR_MORE_DATA
744 "C:ABC:DEF:\\AnInvalidFolder", "C:\\", 4,
745 NO_ERROR
, ERROR_MORE_DATA
748 "?:ABC:DEF:\\AnInvalidFolder", "?:\\" /* win2k, winxp */, sizeof(volume_path
),
749 ERROR_FILE_NOT_FOUND
, NO_ERROR
752 "relative/path", "%CurrentDrive%\\", sizeof(volume_path
),
756 "/unix-style/absolute/path", "%CurrentDrive%\\", sizeof(volume_path
),
760 "\\??\\C:\\NonExistent", "%CurrentDrive%\\", sizeof(volume_path
),
764 "\\??\\M:\\NonExistent", "%CurrentDrive%\\", sizeof(volume_path
),
768 "somefile:def", "%CurrentDrive%\\", sizeof(volume_path
),
772 "s:omefile", "S:\\" /* win2k, winxp */, sizeof(volume_path
),
773 ERROR_FILE_NOT_FOUND
, NO_ERROR
780 /* GetVolumePathNameA is not present before w2k */
781 if (!pGetVolumePathNameA
)
783 win_skip("required functions not found\n");
787 /* Obtain the drive of the working directory */
788 ret
= GetCurrentDirectoryA( sizeof(cwd
), cwd
);
789 ok( ret
, "Failed to obtain the current working directory.\n" );
791 ret
= SetEnvironmentVariableA( "CurrentDrive", cwd
);
792 ok( ret
, "Failed to set an environment variable for the current working drive.\n" );
794 for (i
=0; i
<sizeof(test_paths
)/sizeof(test_paths
[0]); i
++)
796 BOOL broken_ret
= test_paths
[i
].broken_error
== NO_ERROR
;
797 char *output
= (test_paths
[i
].path_name
!= NULL
? volume_path
: NULL
);
798 BOOL expected_ret
= test_paths
[i
].error
== NO_ERROR
;
801 if (test_paths
[i
].path_len
< sizeof(volume_path
))
802 volume_path
[ test_paths
[i
].path_len
] = 0x11;
804 SetLastError( 0xdeadbeef );
805 ret
= pGetVolumePathNameA( test_paths
[i
].file_name
, output
, test_paths
[i
].path_len
);
806 error
= GetLastError();
807 ok(ret
== expected_ret
|| broken(ret
== broken_ret
),
808 "GetVolumePathName test %d %s unexpectedly.\n",
809 i
, test_paths
[i
].error
== NO_ERROR
? "failed" : "succeeded");
813 char path_name
[MAX_PATH
];
815 ExpandEnvironmentStringsA( test_paths
[i
].path_name
, path_name
, MAX_PATH
);
816 /* If we succeeded then make sure the path is correct */
817 success
= (strcmp( volume_path
, path_name
) == 0)
818 || broken(strcasecmp( volume_path
, path_name
) == 0) /* XP */;
819 ok(success
, "GetVolumePathName test %d unexpectedly returned path %s (expected %s).\n",
820 i
, volume_path
, path_name
);
824 /* On success Windows always returns ERROR_MORE_DATA, so only worry about failure */
825 success
= (error
== test_paths
[i
].error
|| broken(error
== test_paths
[i
].broken_error
));
826 ok(success
, "GetVolumePathName test %d unexpectedly returned error 0x%x (expected 0x%x).\n",
827 i
, error
, test_paths
[i
].error
);
830 if (test_paths
[i
].path_len
< sizeof(volume_path
))
831 ok(volume_path
[ test_paths
[i
].path_len
] == 0x11,
832 "GetVolumePathName test %d corrupted byte after end of buffer.\n", i
);
836 static void test_GetVolumePathNameW(void)
838 static WCHAR drive_c1
[] = {'C',':',0};
839 static WCHAR drive_c2
[] = {'C',':','\\',0};
840 WCHAR volume_path
[MAX_PATH
];
843 if (!pGetVolumePathNameW
)
845 win_skip("required functions not found\n");
850 volume_path
[1] = 0x11;
851 ret
= pGetVolumePathNameW( drive_c1
, volume_path
, 1 );
852 ok(!ret
, "GetVolumePathNameW test succeeded unexpectedly.\n");
853 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE
, "GetVolumePathNameW unexpectedly returned error 0x%x (expected 0x%x).\n",
854 GetLastError(), ERROR_FILENAME_EXCED_RANGE
);
855 ok(volume_path
[1] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n");
858 volume_path
[2] = 0x11;
859 ret
= pGetVolumePathNameW( drive_c1
, volume_path
, 2 );
860 ok(!ret
, "GetVolumePathNameW test succeeded unexpectedly.\n");
861 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE
, "GetVolumePathNameW unexpectedly returned error 0x%x (expected 0x%x).\n",
862 GetLastError(), ERROR_FILENAME_EXCED_RANGE
);
863 ok(volume_path
[2] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n");
866 volume_path
[3] = 0x11;
867 ret
= pGetVolumePathNameW( drive_c1
, volume_path
, 3 );
868 ok(ret
|| broken(!ret
) /* win2k */, "GetVolumePathNameW test failed unexpectedly.\n");
869 ok(memcmp(volume_path
, drive_c1
, sizeof(drive_c1
)) == 0
870 || broken(volume_path
[0] == 0) /* win2k */,
871 "GetVolumePathNameW unexpectedly returned wrong path.\n");
872 ok(volume_path
[3] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n");
875 volume_path
[4] = 0x11;
876 ret
= pGetVolumePathNameW( drive_c1
, volume_path
, 4 );
877 ok(ret
, "GetVolumePathNameW test failed unexpectedly.\n");
878 ok(memcmp(volume_path
, drive_c2
, sizeof(drive_c2
)) == 0, "GetVolumePathNameW unexpectedly returned wrong path.\n");
879 ok(volume_path
[4] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n");
882 static void test_GetVolumePathNamesForVolumeNameA(void)
885 char volume
[MAX_PATH
], buffer
[MAX_PATH
];
888 if (!pGetVolumePathNamesForVolumeNameA
|| !pGetVolumeNameForVolumeMountPointA
)
890 win_skip("required functions not found\n");
894 ret
= pGetVolumeNameForVolumeMountPointA( "c:\\", volume
, sizeof(volume
) );
895 ok(ret
, "failed to get volume name %u\n", GetLastError());
896 trace("c:\\ -> %s\n", volume
);
898 SetLastError( 0xdeadbeef );
899 ret
= pGetVolumePathNamesForVolumeNameA( NULL
, NULL
, 0, NULL
);
900 error
= GetLastError();
901 ok(!ret
, "expected failure\n");
902 ok(error
== ERROR_INVALID_NAME
, "expected ERROR_INVALID_NAME got %u\n", error
);
904 SetLastError( 0xdeadbeef );
905 ret
= pGetVolumePathNamesForVolumeNameA( "", NULL
, 0, NULL
);
906 error
= GetLastError();
907 ok(!ret
, "expected failure\n");
908 ok(error
== ERROR_INVALID_NAME
, "expected ERROR_INVALID_NAME got %u\n", error
);
910 SetLastError( 0xdeadbeef );
911 ret
= pGetVolumePathNamesForVolumeNameA( volume
, NULL
, 0, NULL
);
912 error
= GetLastError();
913 ok(!ret
, "expected failure\n");
914 ok(error
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA got %u\n", error
);
916 SetLastError( 0xdeadbeef );
917 ret
= pGetVolumePathNamesForVolumeNameA( volume
, buffer
, 0, NULL
);
918 error
= GetLastError();
919 ok(!ret
, "expected failure\n");
920 ok(error
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA got %u\n", error
);
922 memset( buffer
, 0xff, sizeof(buffer
) );
923 ret
= pGetVolumePathNamesForVolumeNameA( volume
, buffer
, sizeof(buffer
), NULL
);
924 ok(ret
, "failed to get path names %u\n", GetLastError());
925 ok(!strcmp( "C:\\", buffer
), "expected \"\\C:\" got \"%s\"\n", buffer
);
926 ok(!buffer
[4], "expected double null-terminated buffer\n");
929 SetLastError( 0xdeadbeef );
930 ret
= pGetVolumePathNamesForVolumeNameA( NULL
, NULL
, 0, &len
);
931 error
= GetLastError();
932 ok(!ret
, "expected failure\n");
933 ok(error
== ERROR_INVALID_NAME
, "expected ERROR_INVALID_NAME got %u\n", error
);
936 SetLastError( 0xdeadbeef );
937 ret
= pGetVolumePathNamesForVolumeNameA( NULL
, NULL
, sizeof(buffer
), &len
);
938 error
= GetLastError();
939 ok(!ret
, "expected failure\n");
940 ok(error
== ERROR_INVALID_NAME
, "expected ERROR_INVALID_NAME got %u\n", error
);
943 SetLastError( 0xdeadbeef );
944 ret
= pGetVolumePathNamesForVolumeNameA( NULL
, buffer
, sizeof(buffer
), &len
);
945 error
= GetLastError();
946 ok(!ret
, "expected failure\n");
947 ok(error
== ERROR_INVALID_NAME
, "expected ERROR_INVALID_NAME got %u\n", error
);
950 SetLastError( 0xdeadbeef );
951 ret
= pGetVolumePathNamesForVolumeNameA( NULL
, buffer
, sizeof(buffer
), &len
);
952 error
= GetLastError();
953 ok(!ret
, "expected failure\n");
954 ok(error
== ERROR_INVALID_NAME
, "expected ERROR_INVALID_NAME got %u\n", error
);
957 memset( buffer
, 0xff, sizeof(buffer
) );
958 ret
= pGetVolumePathNamesForVolumeNameA( volume
, buffer
, sizeof(buffer
), &len
);
959 ok(ret
, "failed to get path names %u\n", GetLastError());
960 ok(len
== 5 || broken(len
== 2), "expected 5 got %u\n", len
);
961 ok(!strcmp( "C:\\", buffer
), "expected \"\\C:\" got \"%s\"\n", buffer
);
962 ok(!buffer
[4], "expected double null-terminated buffer\n");
965 static void test_GetVolumePathNamesForVolumeNameW(void)
967 static const WCHAR empty
[] = {0};
968 static const WCHAR drive_c
[] = {'c',':','\\',0};
969 static const WCHAR volume_null
[] = {'\\','\\','?','\\','V','o','l','u','m','e',
970 '{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0','0',
971 '-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',0};
973 WCHAR volume
[MAX_PATH
], buffer
[MAX_PATH
];
976 if (!pGetVolumePathNamesForVolumeNameW
|| !pGetVolumeNameForVolumeMountPointW
)
978 win_skip("required functions not found\n");
982 ret
= pGetVolumeNameForVolumeMountPointW( drive_c
, volume
, sizeof(volume
)/sizeof(volume
[0]) );
983 ok(ret
, "failed to get volume name %u\n", GetLastError());
985 SetLastError( 0xdeadbeef );
986 ret
= pGetVolumePathNamesForVolumeNameW( empty
, NULL
, 0, NULL
);
987 error
= GetLastError();
988 ok(!ret
, "expected failure\n");
989 ok(error
== ERROR_INVALID_NAME
, "expected ERROR_INVALID_NAME got %u\n", error
);
991 SetLastError( 0xdeadbeef );
992 ret
= pGetVolumePathNamesForVolumeNameW( volume
, NULL
, 0, NULL
);
993 error
= GetLastError();
994 ok(!ret
, "expected failure\n");
995 ok(error
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA got %u\n", error
);
997 SetLastError( 0xdeadbeef );
998 ret
= pGetVolumePathNamesForVolumeNameW( volume
, buffer
, 0, NULL
);
999 error
= GetLastError();
1000 ok(!ret
, "expected failure\n");
1001 ok(error
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA got %u\n", error
);
1003 if (0) { /* crash */
1004 ret
= pGetVolumePathNamesForVolumeNameW( volume
, NULL
, sizeof(buffer
), NULL
);
1005 ok(ret
, "failed to get path names %u\n", GetLastError());
1008 ret
= pGetVolumePathNamesForVolumeNameW( volume
, buffer
, sizeof(buffer
), NULL
);
1009 ok(ret
, "failed to get path names %u\n", GetLastError());
1012 memset( buffer
, 0xff, sizeof(buffer
) );
1013 ret
= pGetVolumePathNamesForVolumeNameW( volume
, buffer
, sizeof(buffer
), &len
);
1014 ok(ret
, "failed to get path names %u\n", GetLastError());
1015 ok(len
== 5, "expected 5 got %u\n", len
);
1016 ok(!buffer
[4], "expected double null-terminated buffer\n");
1020 volume
[lstrlenW( volume
) - 1] = 0;
1021 SetLastError( 0xdeadbeef );
1022 ret
= pGetVolumePathNamesForVolumeNameW( volume
, buffer
, sizeof(buffer
), &len
);
1023 error
= GetLastError();
1024 ok(!ret
, "expected failure\n");
1025 ok(error
== ERROR_INVALID_NAME
, "expected ERROR_INVALID_NAME got %u\n", error
);
1030 SetLastError( 0xdeadbeef );
1031 ret
= pGetVolumePathNamesForVolumeNameW( volume
, buffer
, sizeof(buffer
), &len
);
1032 error
= GetLastError();
1033 ok(!ret
, "expected failure\n");
1034 todo_wine
ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
1037 lstrcpyW( volume
, volume_null
);
1038 SetLastError( 0xdeadbeef );
1039 ret
= pGetVolumePathNamesForVolumeNameW( volume
, buffer
, sizeof(buffer
), &len
);
1040 error
= GetLastError();
1041 ok(!ret
, "expected failure\n");
1042 ok(error
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND got %u\n", error
);
1045 static void test_dvd_read_structure(HANDLE handle
)
1050 DVD_READ_STRUCTURE dvdReadStructure
;
1051 DVD_LAYER_DESCRIPTOR dvdLayerDescriptor
;
1052 struct COMPLETE_DVD_LAYER_DESCRIPTOR completeDvdLayerDescriptor
;
1053 DVD_COPYRIGHT_DESCRIPTOR dvdCopyrightDescriptor
;
1054 struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR completeDvdManufacturerDescriptor
;
1056 dvdReadStructure
.BlockByteOffset
.QuadPart
= 0;
1057 dvdReadStructure
.SessionId
= 0;
1058 dvdReadStructure
.LayerNumber
= 0;
1061 /* DvdPhysicalDescriptor */
1062 dvdReadStructure
.Format
= 0;
1064 SetLastError(0xdeadbeef);
1066 /* Test whether this ioctl is supported */
1067 ret
= DeviceIoControl(handle
, IOCTL_DVD_READ_STRUCTURE
, &dvdReadStructure
, sizeof(DVD_READ_STRUCTURE
),
1068 &completeDvdLayerDescriptor
, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR
), &nbBytes
, NULL
);
1072 skip("IOCTL_DVD_READ_STRUCTURE not supported: %u\n", GetLastError());
1076 /* Confirm there is always a header before the actual data */
1077 ok( completeDvdLayerDescriptor
.Header
.Length
== 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdLayerDescriptor
.Header
.Length
);
1078 ok( completeDvdLayerDescriptor
.Header
.Reserved
[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdLayerDescriptor
.Header
.Reserved
[0]);
1079 ok( completeDvdLayerDescriptor
.Header
.Reserved
[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdLayerDescriptor
.Header
.Reserved
[1]);
1081 /* TODO: Also check completeDvdLayerDescriptor.Descriptor content (via IOCTL_SCSI_PASS_THROUGH_DIRECT ?) */
1083 /* Insufficient output buffer */
1084 for(i
=0; i
<sizeof(DVD_DESCRIPTOR_HEADER
); i
++)
1086 SetLastError(0xdeadbeef);
1088 ret
= DeviceIoControl(handle
, IOCTL_DVD_READ_STRUCTURE
, &dvdReadStructure
, sizeof(DVD_READ_STRUCTURE
),
1089 &completeDvdLayerDescriptor
, i
, &nbBytes
, NULL
);
1090 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,"IOCTL_DVD_READ_STRUCTURE should fail with small buffer\n");
1093 SetLastError(0xdeadbeef);
1095 /* On newer version, an output buffer of sizeof(DVD_READ_STRUCTURE) size fails.
1096 I think this is to force developers to realize that there is a header before the actual content */
1097 ret
= DeviceIoControl(handle
, IOCTL_DVD_READ_STRUCTURE
, &dvdReadStructure
, sizeof(DVD_READ_STRUCTURE
),
1098 &dvdLayerDescriptor
, sizeof(DVD_LAYER_DESCRIPTOR
), &nbBytes
, NULL
);
1099 ok( (!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
) || broken(ret
) /* < Win7 */,
1100 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
1102 SetLastError(0xdeadbeef);
1104 ret
= DeviceIoControl(handle
, IOCTL_DVD_READ_STRUCTURE
, NULL
, sizeof(DVD_READ_STRUCTURE
),
1105 &completeDvdLayerDescriptor
, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR
), &nbBytes
, NULL
);
1106 ok( (!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
),
1107 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
1109 /* Test wrong input parameters */
1110 for(i
=0; i
<sizeof(DVD_READ_STRUCTURE
); i
++)
1112 SetLastError(0xdeadbeef);
1114 ret
= DeviceIoControl(handle
, IOCTL_DVD_READ_STRUCTURE
, &dvdReadStructure
, i
,
1115 &completeDvdLayerDescriptor
, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR
), &nbBytes
, NULL
);
1116 ok( (!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
),
1117 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
1121 /* DvdCopyrightDescriptor */
1122 dvdReadStructure
.Format
= 1;
1124 SetLastError(0xdeadbeef);
1126 /* Strangely, with NULL lpOutBuffer, last error is insufficient buffer, not invalid parameter as we could expect */
1127 ret
= DeviceIoControl(handle
, IOCTL_DVD_READ_STRUCTURE
, &dvdReadStructure
, sizeof(DVD_READ_STRUCTURE
),
1128 NULL
, sizeof(DVD_COPYRIGHT_DESCRIPTOR
), &nbBytes
, NULL
);
1129 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret
, GetLastError());
1131 for(i
=0; i
<sizeof(DVD_COPYRIGHT_DESCRIPTOR
); i
++)
1133 SetLastError(0xdeadbeef);
1135 ret
= DeviceIoControl(handle
, IOCTL_DVD_READ_STRUCTURE
, &dvdReadStructure
, sizeof(DVD_READ_STRUCTURE
),
1136 &dvdCopyrightDescriptor
, i
, &nbBytes
, NULL
);
1137 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret
, GetLastError());
1141 /* DvdManufacturerDescriptor */
1142 dvdReadStructure
.Format
= 4;
1144 SetLastError(0xdeadbeef);
1146 ret
= DeviceIoControl(handle
, IOCTL_DVD_READ_STRUCTURE
, &dvdReadStructure
, sizeof(DVD_READ_STRUCTURE
),
1147 &completeDvdManufacturerDescriptor
, sizeof(DVD_MANUFACTURER_DESCRIPTOR
), &nbBytes
, NULL
);
1148 ok(ret
|| broken(GetLastError() == ERROR_NOT_READY
),
1149 "IOCTL_DVD_READ_STRUCTURE (DvdManufacturerDescriptor) failed, last error = %u\n", GetLastError());
1153 /* Confirm there is always a header before the actual data */
1154 ok( completeDvdManufacturerDescriptor
.Header
.Length
== 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdManufacturerDescriptor
.Header
.Length
);
1155 ok( completeDvdManufacturerDescriptor
.Header
.Reserved
[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdManufacturerDescriptor
.Header
.Reserved
[0]);
1156 ok( completeDvdManufacturerDescriptor
.Header
.Reserved
[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdManufacturerDescriptor
.Header
.Reserved
[1]);
1158 SetLastError(0xdeadbeef);
1160 /* Basic parameter check */
1161 ret
= DeviceIoControl(handle
, IOCTL_DVD_READ_STRUCTURE
, &dvdReadStructure
, sizeof(DVD_READ_STRUCTURE
),
1162 NULL
, sizeof(DVD_MANUFACTURER_DESCRIPTOR
), &nbBytes
, NULL
);
1163 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret
, GetLastError());
1166 static void test_cdrom_ioctl(void)
1168 char drive_letter
, drive_path
[] = "A:\\", drive_full_path
[] = "\\\\.\\A:";
1172 bitmask
= GetLogicalDrives();
1175 trace("GetLogicalDrives failed : %u\n", GetLastError());
1179 for(drive_letter
='A'; drive_letter
<='Z'; drive_letter
++)
1181 if(!(bitmask
& (1 << (drive_letter
-'A') )))
1184 drive_path
[0] = drive_letter
;
1185 if(GetDriveTypeA(drive_path
) != DRIVE_CDROM
)
1187 trace("Skipping %c:, not a CDROM drive.\n", drive_letter
);
1191 trace("Testing with %c:\n", drive_letter
);
1193 drive_full_path
[4] = drive_letter
;
1194 handle
= CreateFileA(drive_full_path
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0);
1195 if(handle
== INVALID_HANDLE_VALUE
)
1197 trace("Failed to open the device : %u\n", GetLastError());
1201 /* Add your tests here */
1202 test_dvd_read_structure(handle
);
1204 CloseHandle(handle
);
1211 hdll
= GetModuleHandleA("kernel32.dll");
1212 pGetVolumeNameForVolumeMountPointA
= (void *) GetProcAddress(hdll
, "GetVolumeNameForVolumeMountPointA");
1213 pGetVolumeNameForVolumeMountPointW
= (void *) GetProcAddress(hdll
, "GetVolumeNameForVolumeMountPointW");
1214 pFindFirstVolumeA
= (void *) GetProcAddress(hdll
, "FindFirstVolumeA");
1215 pFindNextVolumeA
= (void *) GetProcAddress(hdll
, "FindNextVolumeA");
1216 pFindVolumeClose
= (void *) GetProcAddress(hdll
, "FindVolumeClose");
1217 pGetLogicalDriveStringsA
= (void *) GetProcAddress(hdll
, "GetLogicalDriveStringsA");
1218 pGetLogicalDriveStringsW
= (void *) GetProcAddress(hdll
, "GetLogicalDriveStringsW");
1219 pGetVolumeInformationA
= (void *) GetProcAddress(hdll
, "GetVolumeInformationA");
1220 pGetVolumePathNameA
= (void *) GetProcAddress(hdll
, "GetVolumePathNameA");
1221 pGetVolumePathNameW
= (void *) GetProcAddress(hdll
, "GetVolumePathNameW");
1222 pGetVolumePathNamesForVolumeNameA
= (void *) GetProcAddress(hdll
, "GetVolumePathNamesForVolumeNameA");
1223 pGetVolumePathNamesForVolumeNameW
= (void *) GetProcAddress(hdll
, "GetVolumePathNamesForVolumeNameW");
1225 test_query_dos_deviceA();
1226 test_define_dos_deviceA();
1227 test_FindFirstVolume();
1228 test_GetVolumePathNameA();
1229 test_GetVolumePathNameW();
1230 test_GetVolumeNameForVolumeMountPointA();
1231 test_GetVolumeNameForVolumeMountPointW();
1232 test_GetLogicalDriveStringsA();
1233 test_GetLogicalDriveStringsW();
1234 test_GetVolumeInformationA();
1236 test_disk_extents();
1237 test_GetVolumePathNamesForVolumeNameA();
1238 test_GetVolumePathNamesForVolumeNameW();