[NTDLL_APITEST] Disable NtContinue test when runtime checks are enabled
[reactos.git] / rostests / winetests / kernel32 / volume.c
1 /*
2 * Unit test suite for volume functions
3 *
4 * Copyright 2006 Stefan Leichter
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "wine/test.h"
22 #include "winbase.h"
23 #include "winioctl.h"
24 #include <stdio.h>
25 #include "wine/ddk/ntddcdvd.h"
26
27 #include <pshpack1.h>
28 struct COMPLETE_DVD_LAYER_DESCRIPTOR
29 {
30 DVD_DESCRIPTOR_HEADER Header;
31 DVD_LAYER_DESCRIPTOR Descriptor;
32 UCHAR Padding;
33 };
34 #include <poppack.h>
35 C_ASSERT(sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR) == 22);
36
37 #include <pshpack1.h>
38 struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR
39 {
40 DVD_DESCRIPTOR_HEADER Header;
41 DVD_MANUFACTURER_DESCRIPTOR Descriptor;
42 UCHAR Padding;
43 };
44 #include <poppack.h>
45 C_ASSERT(sizeof(struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR) == 2053);
46
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 *pGetVolumePathNamesForVolumeNameA)(LPCSTR, LPSTR, DWORD, LPDWORD);
58 static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameW)(LPCWSTR, LPWSTR, DWORD, LPDWORD);
59
60 /* ############################### */
61
62 static void test_query_dos_deviceA(void)
63 {
64 char drivestr[] = "a:";
65 char *p, *buffer, buffer2[2000];
66 DWORD ret, ret2, buflen=32768;
67 BOOL found = FALSE;
68
69 /* callers must guess the buffer size */
70 SetLastError(0xdeadbeef);
71 ret = QueryDosDeviceA( NULL, NULL, 0 );
72 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
73 "QueryDosDeviceA(no buffer): returned %u, le=%u\n", ret, GetLastError());
74
75 buffer = HeapAlloc( GetProcessHeap(), 0, buflen );
76 SetLastError(0xdeadbeef);
77 ret = QueryDosDeviceA( NULL, buffer, buflen );
78 ok((ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER),
79 "QueryDosDeviceA failed to return list, last error %u\n", GetLastError());
80
81 if (ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
82 p = buffer;
83 for (;;) {
84 if (!strlen(p)) break;
85 ret2 = QueryDosDeviceA( p, buffer2, sizeof(buffer2) );
86 ok(ret2, "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", p, GetLastError());
87 p += strlen(p) + 1;
88 if (ret <= (p-buffer)) break;
89 }
90 }
91
92 for (;drivestr[0] <= 'z'; drivestr[0]++) {
93 /* Older W2K fails with ERROR_INSUFFICIENT_BUFFER when buflen is > 32767 */
94 ret = QueryDosDeviceA( drivestr, buffer, buflen - 1);
95 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
96 "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", drivestr, GetLastError());
97 if(ret) {
98 for (p = buffer; *p; p++) *p = toupper(*p);
99 if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE;
100 }
101 }
102 ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
103 HeapFree( GetProcessHeap(), 0, buffer );
104 }
105
106 static void test_define_dos_deviceA(void)
107 {
108 char drivestr[3];
109 char buf[MAX_PATH];
110 DWORD ret;
111
112 /* Find an unused drive letter */
113 drivestr[1] = ':';
114 drivestr[2] = 0;
115 for (drivestr[0] = 'a'; drivestr[0] <= 'z'; drivestr[0]++) {
116 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf));
117 if (!ret) break;
118 }
119 if (drivestr[0] > 'z') {
120 skip("can't test creating a dos drive, none available\n");
121 return;
122 }
123
124 /* Map it to point to the current directory */
125 ret = GetCurrentDirectoryA(sizeof(buf), buf);
126 ok(ret, "GetCurrentDir\n");
127
128 ret = DefineDosDeviceA(0, drivestr, buf);
129 todo_wine
130 ok(ret, "Could not make drive %s point to %s!\n", drivestr, buf);
131
132 if (!ret) {
133 skip("can't test removing fake drive\n");
134 } else {
135 ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL);
136 ok(ret, "Could not remove fake drive %s!\n", drivestr);
137 }
138 }
139
140 static void test_FindFirstVolume(void)
141 {
142 char volume[51];
143 HANDLE handle;
144
145 /* not present before w2k */
146 if (!pFindFirstVolumeA) {
147 win_skip("FindFirstVolumeA not found\n");
148 return;
149 }
150
151 handle = pFindFirstVolumeA( volume, 0 );
152 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
153 ok( GetLastError() == ERROR_MORE_DATA || /* XP */
154 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Vista */
155 "wrong error %u\n", GetLastError() );
156 handle = pFindFirstVolumeA( volume, 49 );
157 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
158 ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE, "wrong error %u\n", GetLastError() );
159 handle = pFindFirstVolumeA( volume, 51 );
160 ok( handle != INVALID_HANDLE_VALUE, "failed err %u\n", GetLastError() );
161 if (handle != INVALID_HANDLE_VALUE)
162 {
163 do
164 {
165 ok( strlen(volume) == 49, "bad volume name %s\n", volume );
166 ok( !memcmp( volume, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume );
167 ok( !memcmp( volume + 47, "}\\", 2 ), "bad volume name %s\n", volume );
168 } while (pFindNextVolumeA( handle, volume, MAX_PATH ));
169 ok( GetLastError() == ERROR_NO_MORE_FILES, "wrong error %u\n", GetLastError() );
170 pFindVolumeClose( handle );
171 }
172 }
173
174 static void test_GetVolumeNameForVolumeMountPointA(void)
175 {
176 BOOL ret;
177 char volume[MAX_PATH], path[] = "c:\\";
178 DWORD len = sizeof(volume), reti;
179 char temp_path[MAX_PATH];
180
181 /* not present before w2k */
182 if (!pGetVolumeNameForVolumeMountPointA) {
183 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
184 return;
185 }
186
187 reti = GetTempPathA(MAX_PATH, temp_path);
188 ok(reti != 0, "GetTempPathA error %d\n", GetLastError());
189 ok(reti < MAX_PATH, "temp path should fit into MAX_PATH\n");
190
191 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 0);
192 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
193 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
194 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
195 "wrong error, last=%d\n", GetLastError());
196
197 if (0) { /* these crash on XP */
198 ret = pGetVolumeNameForVolumeMountPointA(path, NULL, len);
199 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
200
201 ret = pGetVolumeNameForVolumeMountPointA(NULL, volume, len);
202 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
203 }
204
205 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
206 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
207 ok(!strncmp( volume, "\\\\?\\Volume{", 11),
208 "GetVolumeNameForVolumeMountPointA failed to return valid string <%s>\n",
209 volume);
210
211 /* test with too small buffer */
212 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 10);
213 ok(ret == FALSE && GetLastError() == ERROR_FILENAME_EXCED_RANGE,
214 "GetVolumeNameForVolumeMountPointA failed, wrong error returned, was %d, should be ERROR_FILENAME_EXCED_RANGE\n",
215 GetLastError());
216
217 /* Try on an arbitrary directory */
218 /* On FAT filesystems it seems that GetLastError() is set to
219 ERROR_INVALID_FUNCTION. */
220 ret = pGetVolumeNameForVolumeMountPointA(temp_path, volume, len);
221 ok(ret == FALSE && (GetLastError() == ERROR_NOT_A_REPARSE_POINT ||
222 GetLastError() == ERROR_INVALID_FUNCTION),
223 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
224 temp_path, GetLastError());
225
226 /* Try on a nonexistent dos drive */
227 path[2] = 0;
228 for (;path[0] <= 'z'; path[0]++) {
229 ret = QueryDosDeviceA( path, volume, len);
230 if(!ret) break;
231 }
232 if (path[0] <= 'z')
233 {
234 path[2] = '\\';
235 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
236 ok(ret == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND,
237 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
238 path, GetLastError());
239
240 /* Try without trailing \ and on a nonexistent dos drive */
241 path[2] = 0;
242 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
243 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
244 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
245 path, GetLastError());
246 }
247 }
248
249 static void test_GetVolumeNameForVolumeMountPointW(void)
250 {
251 BOOL ret;
252 WCHAR volume[MAX_PATH], path[] = {'c',':','\\',0};
253 DWORD len = sizeof(volume) / sizeof(WCHAR);
254
255 /* not present before w2k */
256 if (!pGetVolumeNameForVolumeMountPointW) {
257 win_skip("GetVolumeNameForVolumeMountPointW not found\n");
258 return;
259 }
260
261 ret = pGetVolumeNameForVolumeMountPointW(path, volume, 0);
262 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
263 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
264 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
265 "wrong error, last=%d\n", GetLastError());
266
267 if (0) { /* these crash on XP */
268 ret = pGetVolumeNameForVolumeMountPointW(path, NULL, len);
269 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
270
271 ret = pGetVolumeNameForVolumeMountPointW(NULL, volume, len);
272 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
273 }
274
275 ret = pGetVolumeNameForVolumeMountPointW(path, volume, len);
276 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n");
277 }
278
279 static void test_GetLogicalDriveStringsA(void)
280 {
281 UINT size, size2;
282 char *buf, *ptr;
283
284 ok( pGetLogicalDriveStringsA != NULL, "GetLogicalDriveStringsA not available\n");
285 if(!pGetLogicalDriveStringsA) {
286 return;
287 }
288
289 size = pGetLogicalDriveStringsA(0, NULL);
290 ok(size%4 == 1, "size = %d\n", size);
291
292 buf = HeapAlloc(GetProcessHeap(), 0, size);
293
294 *buf = 0;
295 size2 = pGetLogicalDriveStringsA(2, buf);
296 ok(size2 == size, "size2 = %d\n", size2);
297 ok(!*buf, "buf changed\n");
298
299 size2 = pGetLogicalDriveStringsA(size, buf);
300 ok(size2 == size-1, "size2 = %d\n", size2);
301
302 for(ptr = buf; ptr < buf+size2; ptr += 4) {
303 ok(('A' <= *ptr && *ptr <= 'Z'), "device name '%c' is not uppercase\n", *ptr);
304 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
305 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
306 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
307 }
308 ok(!*ptr, "buf[size2] is not nullbyte\n");
309
310 HeapFree(GetProcessHeap(), 0, buf);
311 }
312
313 static void test_GetLogicalDriveStringsW(void)
314 {
315 UINT size, size2;
316 WCHAR *buf, *ptr;
317
318 ok( pGetLogicalDriveStringsW != NULL, "GetLogicalDriveStringsW not available\n");
319 if(!pGetLogicalDriveStringsW) {
320 return;
321 }
322
323 SetLastError(0xdeadbeef);
324 size = pGetLogicalDriveStringsW(0, NULL);
325 if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
326 win_skip("GetLogicalDriveStringsW not implemented\n");
327 return;
328 }
329 ok(size%4 == 1, "size = %d\n", size);
330
331 buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
332
333 *buf = 0;
334 size2 = pGetLogicalDriveStringsW(2, buf);
335 ok(size2 == size, "size2 = %d\n", size2);
336 ok(!*buf, "buf changed\n");
337
338 size2 = pGetLogicalDriveStringsW(size, buf);
339 ok(size2 == size-1, "size2 = %d\n", size2);
340
341 for(ptr = buf; ptr < buf+size2; ptr += 4) {
342 ok('A' <= *ptr && *ptr <= 'Z', "device name '%c' is not uppercase\n", *ptr);
343 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
344 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
345 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
346 }
347 ok(!*ptr, "buf[size2] is not nullbyte\n");
348
349 HeapFree(GetProcessHeap(), 0, buf);
350 }
351
352 static void test_GetVolumeInformationA(void)
353 {
354 BOOL ret;
355 UINT result;
356 char Root_Colon[]="C:";
357 char Root_Slash[]="C:\\";
358 char Root_UNC[]="\\\\?\\C:\\";
359 char volume[MAX_PATH+1];
360 DWORD vol_name_size=MAX_PATH+1, vol_serial_num=-1, max_comp_len=0, fs_flags=0, fs_name_len=MAX_PATH+1;
361 char vol_name_buf[MAX_PATH+1], fs_name_buf[MAX_PATH+1];
362 char windowsdir[MAX_PATH+10];
363 char currentdir[MAX_PATH+1];
364
365 ok( pGetVolumeInformationA != NULL, "GetVolumeInformationA not found\n");
366 if(!pGetVolumeInformationA) {
367 return;
368 }
369
370 /* get windows drive letter and update strings for testing */
371 result = GetWindowsDirectoryA(windowsdir, sizeof(windowsdir));
372 ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
373 ok(result != 0, "GetWindowsDirectory: error %d\n", GetLastError());
374 Root_Colon[0] = windowsdir[0];
375 Root_Slash[0] = windowsdir[0];
376 Root_UNC[4] = windowsdir[0];
377
378 result = GetCurrentDirectoryA(MAX_PATH, currentdir);
379 ok(result, "GetCurrentDirectory: error %d\n", GetLastError());
380 /* Note that GetCurrentDir yields no trailing slash for subdirs */
381
382 /* check for NO error on no trailing \ when current dir is root dir */
383 ret = SetCurrentDirectoryA(Root_Slash);
384 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
385 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
386 NULL, NULL, fs_name_buf, fs_name_len);
387 ok(ret, "GetVolumeInformationA root failed, last error %u\n", GetLastError());
388
389 /* check for error on no trailing \ when current dir is subdir (windows) of queried drive */
390 ret = SetCurrentDirectoryA(windowsdir);
391 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
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 /* reset current directory */
399 ret = SetCurrentDirectoryA(currentdir);
400 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
401
402 if (toupper(currentdir[0]) == toupper(windowsdir[0])) {
403 skip("Please re-run from another device than %c:\n", windowsdir[0]);
404 /* FIXME: Use GetLogicalDrives to find another device to avoid this skip. */
405 } else {
406 char Root_Env[]="=C:"; /* where MS maintains the per volume directory */
407 Root_Env[1] = windowsdir[0];
408
409 /* C:\windows becomes the current directory on drive C: */
410 /* Note that paths to subdirs are stored without trailing slash, like what GetCurrentDir yields. */
411 ret = SetEnvironmentVariableA(Root_Env, windowsdir);
412 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
413
414 ret = SetCurrentDirectoryA(windowsdir);
415 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
416 ret = SetCurrentDirectoryA(currentdir);
417 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
418
419 /* windows dir is current on the root drive, call fails */
420 SetLastError(0xdeadbeef);
421 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
422 NULL, NULL, fs_name_buf, fs_name_len);
423 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
424 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
425
426 /* Try normal drive letter with trailing \ */
427 ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size, NULL,
428 NULL, NULL, fs_name_buf, fs_name_len);
429 ok(ret, "GetVolumeInformationA with \\ failed, last error %u\n", GetLastError());
430
431 ret = SetCurrentDirectoryA(Root_Slash);
432 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
433 ret = SetCurrentDirectoryA(currentdir);
434 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
435
436 /* windows dir is STILL CURRENT on root drive; the call fails as before, */
437 /* proving that SetCurrentDir did not remember the other drive's directory */
438 SetLastError(0xdeadbeef);
439 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
440 NULL, NULL, fs_name_buf, fs_name_len);
441 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
442 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
443
444 /* Now C:\ becomes the current directory on drive C: */
445 ret = SetEnvironmentVariableA(Root_Env, Root_Slash); /* set =C:=C:\ */
446 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
447
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());
452
453 /* again, SetCurrentDirectory on another drive does not matter */
454 ret = SetCurrentDirectoryA(Root_Slash);
455 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
456 ret = SetCurrentDirectoryA(currentdir);
457 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
458
459 /* \ is current on root drive, call succeeds */
460 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
461 NULL, NULL, fs_name_buf, fs_name_len);
462 ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
463 }
464
465 /* try null root directory to return "root of the current directory" */
466 ret = pGetVolumeInformationA(NULL, vol_name_buf, vol_name_size, NULL,
467 NULL, NULL, fs_name_buf, fs_name_len);
468 ok(ret, "GetVolumeInformationA failed on null root dir, last error %u\n", GetLastError());
469
470 /* Try normal drive letter with trailing \ */
471 ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size,
472 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
473 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Slash, GetLastError());
474
475 /* try again with drive letter and the "disable parsing" prefix */
476 SetLastError(0xdeadbeef);
477 ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
478 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
479 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
480
481 /* try again with device name space */
482 Root_UNC[2] = '.';
483 SetLastError(0xdeadbeef);
484 ret = pGetVolumeInformationA(Root_UNC, 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 did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
487
488 /* try again with a directory off the root - should generate error */
489 if (windowsdir[strlen(windowsdir)-1] != '\\') strcat(windowsdir, "\\");
490 SetLastError(0xdeadbeef);
491 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
492 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
493 ok(!ret && (GetLastError()==ERROR_DIR_NOT_ROOT),
494 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
495 /* A subdir with trailing \ yields DIR_NOT_ROOT instead of INVALID_NAME */
496 if (windowsdir[strlen(windowsdir)-1] == '\\') windowsdir[strlen(windowsdir)-1] = 0;
497 SetLastError(0xdeadbeef);
498 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
499 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
500 ok(!ret && (GetLastError()==ERROR_INVALID_NAME),
501 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
502
503 if (!pGetVolumeNameForVolumeMountPointA) {
504 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
505 return;
506 }
507 /* get the unique volume name for the windows drive */
508 ret = pGetVolumeNameForVolumeMountPointA(Root_Slash, volume, MAX_PATH);
509 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
510
511 /* try again with unique volume name */
512 ret = pGetVolumeInformationA(volume, vol_name_buf, vol_name_size,
513 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
514 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", volume, GetLastError());
515 }
516
517 /* Test to check that unique volume name from windows dir mount point */
518 /* matches at least one of the unique volume names returned from the */
519 /* FindFirstVolumeA/FindNextVolumeA list. */
520 static void test_enum_vols(void)
521 {
522 DWORD ret;
523 HANDLE hFind = INVALID_HANDLE_VALUE;
524 char Volume_1[MAX_PATH] = {0};
525 char Volume_2[MAX_PATH] = {0};
526 char path[] = "c:\\";
527 BOOL found = FALSE;
528 char windowsdir[MAX_PATH];
529
530 if (!pGetVolumeNameForVolumeMountPointA) {
531 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
532 return;
533 }
534
535 /*get windows drive letter and update strings for testing */
536 ret = GetWindowsDirectoryA( windowsdir, sizeof(windowsdir) );
537 ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
538 ok(ret != 0, "GetWindowsDirecory: error %d\n", GetLastError());
539 path[0] = windowsdir[0];
540
541 /* get the unique volume name for the windows drive */
542 ret = pGetVolumeNameForVolumeMountPointA( path, Volume_1, MAX_PATH );
543 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
544 ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1);
545
546 /* get first unique volume name of list */
547 hFind = pFindFirstVolumeA( Volume_2, MAX_PATH );
548 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstVolume failed, err=%u\n",
549 GetLastError());
550 /* ReactOS */
551 if (hFind != INVALID_HANDLE_VALUE) {
552 do
553 {
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)
557 {
558 found = TRUE;
559 break;
560 }
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 );
564 }
565 }
566
567 static void test_disk_extents(void)
568 {
569 BOOL ret;
570 DWORD size;
571 HANDLE handle;
572 static DWORD data[16];
573
574 handle = CreateFileA( "\\\\.\\c:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
575 if (handle == INVALID_HANDLE_VALUE)
576 {
577 win_skip("can't open c: drive %u\n", GetLastError());
578 return;
579 }
580 size = 0;
581 ret = DeviceIoControl( handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, &data,
582 sizeof(data), &data, sizeof(data), &size, NULL );
583 if (!ret && GetLastError() == ERROR_INVALID_FUNCTION)
584 {
585 win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
586 CloseHandle( handle );
587 return;
588 }
589 ok(ret, "DeviceIoControl failed %u\n", GetLastError());
590 ok(size == 32, "expected 32, got %u\n", size);
591 CloseHandle( handle );
592 }
593
594 static void test_GetVolumePathNameA(void)
595 {
596 BOOL ret;
597 char volume[MAX_PATH];
598 char expected[] = "C:\\", pathC1[] = "C:\\", pathC2[] = "C::";
599 DWORD error;
600
601 if (!pGetVolumePathNameA)
602 {
603 win_skip("required functions not found\n");
604 return;
605 }
606
607 SetLastError( 0xdeadbeef );
608 ret = pGetVolumePathNameA(NULL, NULL, 0);
609 error = GetLastError();
610 ok(!ret, "expected failure\n");
611 ok(error == ERROR_INVALID_PARAMETER
612 || broken( error == 0xdeadbeef) /* <=XP */,
613 "expected ERROR_INVALID_PARAMETER got %u\n", error);
614
615 SetLastError( 0xdeadbeef );
616 ret = pGetVolumePathNameA("", NULL, 0);
617 error = GetLastError();
618 ok(!ret, "expected failure\n");
619 ok(error == ERROR_INVALID_PARAMETER
620 || broken( error == 0xdeadbeef) /* <=XP */,
621 "expected ERROR_INVALID_PARAMETER got %u\n", error);
622
623 SetLastError( 0xdeadbeef );
624 ret = pGetVolumePathNameA(pathC1, NULL, 0);
625 error = GetLastError();
626 ok(!ret, "expected failure\n");
627 ok(error == ERROR_INVALID_PARAMETER
628 || broken(error == ERROR_FILENAME_EXCED_RANGE) /* <=XP */,
629 "expected ERROR_INVALID_PARAMETER got %u\n", error);
630
631 SetLastError( 0xdeadbeef );
632 ret = pGetVolumePathNameA(pathC1, volume, 0);
633 error = GetLastError();
634 ok(!ret, "expected failure\n");
635 ok(error == ERROR_INVALID_PARAMETER
636 || broken(error == ERROR_FILENAME_EXCED_RANGE ) /* <=XP */,
637 "expected ERROR_INVALID_PARAMETER got %u\n", error);
638
639 SetLastError( 0xdeadbeef );
640 ret = pGetVolumePathNameA(pathC1, volume, 1);
641 error = GetLastError();
642 ok(!ret, "expected failure\n");
643 ok(error == ERROR_FILENAME_EXCED_RANGE, "expected ERROR_FILENAME_EXCED_RANGE got %u\n", error);
644
645 volume[0] = '\0';
646 ret = pGetVolumePathNameA(pathC1, volume, sizeof(volume));
647 ok(ret, "expected success\n");
648 ok(!strcmp(expected, volume), "expected name '%s', returned '%s'\n", pathC1, volume);
649
650 pathC1[0] = tolower(pathC1[0]);
651 volume[0] = '\0';
652 ret = pGetVolumePathNameA(pathC1, volume, sizeof(volume));
653 ok(ret, "expected success\n");
654 todo_wine
655 ok(!strcmp(expected, volume) || broken(!strcasecmp(expected, volume)) /* <=XP */,
656 "expected name '%s', returned '%s'\n", expected, volume);
657
658 volume[0] = '\0';
659 ret = pGetVolumePathNameA(pathC2, volume, sizeof(volume));
660 todo_wine
661 ok(ret, "expected success\n");
662 todo_wine
663 ok(!strcmp(expected, volume), "expected name '%s', returned '%s'\n", expected, volume);
664
665 /* test an invalid path */
666 SetLastError( 0xdeadbeef );
667 ret = pGetVolumePathNameA("\\\\$$$", volume, 1);
668 error = GetLastError();
669 ok(!ret, "expected failure\n");
670 ok(error == ERROR_INVALID_NAME || broken(ERROR_FILENAME_EXCED_RANGE) /* <=2000 */,
671 "expected ERROR_INVALID_NAME got %u\n", error);
672 }
673
674 static void test_GetVolumePathNamesForVolumeNameA(void)
675 {
676 BOOL ret;
677 char volume[MAX_PATH], buffer[MAX_PATH];
678 DWORD len, error;
679
680 if (!pGetVolumePathNamesForVolumeNameA || !pGetVolumeNameForVolumeMountPointA)
681 {
682 win_skip("required functions not found\n");
683 return;
684 }
685
686 ret = pGetVolumeNameForVolumeMountPointA( "c:\\", volume, sizeof(volume) );
687 ok(ret, "failed to get volume name %u\n", GetLastError());
688 trace("c:\\ -> %s\n", volume);
689
690 SetLastError( 0xdeadbeef );
691 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, NULL );
692 error = GetLastError();
693 ok(!ret, "expected failure\n");
694 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
695
696 SetLastError( 0xdeadbeef );
697 ret = pGetVolumePathNamesForVolumeNameA( "", NULL, 0, NULL );
698 error = GetLastError();
699 ok(!ret, "expected failure\n");
700 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
701
702 SetLastError( 0xdeadbeef );
703 ret = pGetVolumePathNamesForVolumeNameA( volume, NULL, 0, NULL );
704 error = GetLastError();
705 ok(!ret, "expected failure\n");
706 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
707
708 SetLastError( 0xdeadbeef );
709 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, 0, NULL );
710 error = GetLastError();
711 ok(!ret, "expected failure\n");
712 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
713
714 memset( buffer, 0xff, sizeof(buffer) );
715 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), NULL );
716 ok(ret, "failed to get path names %u\n", GetLastError());
717 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
718 ok(!buffer[4], "expected double null-terminated buffer\n");
719
720 len = 0;
721 SetLastError( 0xdeadbeef );
722 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, &len );
723 error = GetLastError();
724 ok(!ret, "expected failure\n");
725 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
726
727 len = 0;
728 SetLastError( 0xdeadbeef );
729 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, sizeof(buffer), &len );
730 error = GetLastError();
731 ok(!ret, "expected failure\n");
732 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
733
734 len = 0;
735 SetLastError( 0xdeadbeef );
736 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
737 error = GetLastError();
738 ok(!ret, "expected failure\n");
739 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
740
741 len = 0;
742 SetLastError( 0xdeadbeef );
743 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
744 error = GetLastError();
745 ok(!ret, "expected failure\n");
746 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
747
748 len = 0;
749 memset( buffer, 0xff, sizeof(buffer) );
750 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), &len );
751 ok(ret, "failed to get path names %u\n", GetLastError());
752 ok(len == 5 || broken(len == 2), "expected 5 got %u\n", len);
753 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
754 ok(!buffer[4], "expected double null-terminated buffer\n");
755 }
756
757 static void test_GetVolumePathNamesForVolumeNameW(void)
758 {
759 static const WCHAR empty[] = {0};
760 static const WCHAR drive_c[] = {'c',':','\\',0};
761 static const WCHAR volume_null[] = {'\\','\\','?','\\','V','o','l','u','m','e',
762 '{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0','0',
763 '-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',0};
764 BOOL ret;
765 WCHAR volume[MAX_PATH], buffer[MAX_PATH];
766 DWORD len, error;
767
768 #ifdef __REACTOS__
769 /* due to failing all calls to GetVolumeNameForVolumeMountPointW, this
770 * buffer never gets initialized and could cause a buffer overflow later */
771 volume[0] = 0;
772 #endif /* __REACTOS__ */
773
774 if (!pGetVolumePathNamesForVolumeNameW || !pGetVolumeNameForVolumeMountPointW)
775 {
776 win_skip("required functions not found\n");
777 return;
778 }
779
780 ret = pGetVolumeNameForVolumeMountPointW( drive_c, volume, sizeof(volume)/sizeof(volume[0]) );
781 ok(ret, "failed to get volume name %u\n", GetLastError());
782
783 SetLastError( 0xdeadbeef );
784 ret = pGetVolumePathNamesForVolumeNameW( empty, NULL, 0, NULL );
785 error = GetLastError();
786 ok(!ret, "expected failure\n");
787 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
788
789 SetLastError( 0xdeadbeef );
790 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, 0, NULL );
791 error = GetLastError();
792 ok(!ret, "expected failure\n");
793 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
794
795 SetLastError( 0xdeadbeef );
796 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, 0, NULL );
797 error = GetLastError();
798 ok(!ret, "expected failure\n");
799 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
800
801 if (0) { /* crash */
802 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, sizeof(buffer), NULL );
803 ok(ret, "failed to get path names %u\n", GetLastError());
804 }
805
806 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), NULL );
807 ok(ret, "failed to get path names %u\n", GetLastError());
808
809 len = 0;
810 memset( buffer, 0xff, sizeof(buffer) );
811 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
812 ok(ret, "failed to get path names %u\n", GetLastError());
813 ok(len == 5, "expected 5 got %u\n", len);
814 ok(!buffer[4], "expected double null-terminated buffer\n");
815
816 len = 0;
817 volume[1] = '?';
818 volume[lstrlenW( volume ) - 1] = 0;
819 SetLastError( 0xdeadbeef );
820 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
821 error = GetLastError();
822 ok(!ret, "expected failure\n");
823 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
824
825 len = 0;
826 volume[0] = '\\';
827 volume[1] = 0;
828 SetLastError( 0xdeadbeef );
829 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
830 error = GetLastError();
831 ok(!ret, "expected failure\n");
832 todo_wine ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
833
834 len = 0;
835 lstrcpyW( volume, volume_null );
836 SetLastError( 0xdeadbeef );
837 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
838 error = GetLastError();
839 ok(!ret, "expected failure\n");
840 ok(error == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND got %u\n", error);
841 }
842
843 static void test_dvd_read_structure(HANDLE handle)
844 {
845 int i;
846 DWORD nbBytes;
847 BOOL ret;
848 DVD_READ_STRUCTURE dvdReadStructure;
849 DVD_LAYER_DESCRIPTOR dvdLayerDescriptor;
850 struct COMPLETE_DVD_LAYER_DESCRIPTOR completeDvdLayerDescriptor;
851 DVD_COPYRIGHT_DESCRIPTOR dvdCopyrightDescriptor;
852 struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR completeDvdManufacturerDescriptor;
853
854 dvdReadStructure.BlockByteOffset.QuadPart = 0;
855 dvdReadStructure.SessionId = 0;
856 dvdReadStructure.LayerNumber = 0;
857
858
859 /* DvdPhysicalDescriptor */
860 dvdReadStructure.Format = 0;
861
862 SetLastError(0xdeadbeef);
863
864 /* Test whether this ioctl is supported */
865 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
866 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
867
868 if(!ret)
869 {
870 skip("IOCTL_DVD_READ_STRUCTURE not supported: %u\n", GetLastError());
871 return;
872 }
873
874 /* Confirm there is always a header before the actual data */
875 ok( completeDvdLayerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdLayerDescriptor.Header.Length);
876 ok( completeDvdLayerDescriptor.Header.Reserved[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[0]);
877 ok( completeDvdLayerDescriptor.Header.Reserved[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[1]);
878
879 /* TODO: Also check completeDvdLayerDescriptor.Descriptor content (via IOCTL_SCSI_PASS_THROUGH_DIRECT ?) */
880
881 /* Insufficient output buffer */
882 for(i=0; i<sizeof(DVD_DESCRIPTOR_HEADER); i++)
883 {
884 SetLastError(0xdeadbeef);
885
886 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
887 &completeDvdLayerDescriptor, i, &nbBytes, NULL);
888 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,"IOCTL_DVD_READ_STRUCTURE should fail with small buffer\n");
889 }
890
891 SetLastError(0xdeadbeef);
892
893 /* On newer version, an output buffer of sizeof(DVD_READ_STRUCTURE) size fails.
894 I think this is to force developers to realize that there is a header before the actual content */
895 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
896 &dvdLayerDescriptor, sizeof(DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
897 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER) || broken(ret) /* < Win7 */,
898 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
899
900 SetLastError(0xdeadbeef);
901
902 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, NULL, sizeof(DVD_READ_STRUCTURE),
903 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
904 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER),
905 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
906
907 /* Test wrong input parameters */
908 for(i=0; i<sizeof(DVD_READ_STRUCTURE); i++)
909 {
910 SetLastError(0xdeadbeef);
911
912 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, i,
913 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
914 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER),
915 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
916 }
917
918
919 /* DvdCopyrightDescriptor */
920 dvdReadStructure.Format = 1;
921
922 SetLastError(0xdeadbeef);
923
924 /* Strangely, with NULL lpOutBuffer, last error is insufficient buffer, not invalid parameter as we could expect */
925 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
926 NULL, sizeof(DVD_COPYRIGHT_DESCRIPTOR), &nbBytes, NULL);
927 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret, GetLastError());
928
929 for(i=0; i<sizeof(DVD_COPYRIGHT_DESCRIPTOR); i++)
930 {
931 SetLastError(0xdeadbeef);
932
933 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
934 &dvdCopyrightDescriptor, i, &nbBytes, NULL);
935 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret, GetLastError());
936 }
937
938
939 /* DvdManufacturerDescriptor */
940 dvdReadStructure.Format = 4;
941
942 SetLastError(0xdeadbeef);
943
944 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
945 &completeDvdManufacturerDescriptor, sizeof(DVD_MANUFACTURER_DESCRIPTOR), &nbBytes, NULL);
946 ok(ret || broken(GetLastError() == ERROR_NOT_READY),
947 "IOCTL_DVD_READ_STRUCTURE (DvdManufacturerDescriptor) failed, last error = %u\n", GetLastError());
948 if(!ret)
949 return;
950
951 /* Confirm there is always a header before the actual data */
952 ok( completeDvdManufacturerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdManufacturerDescriptor.Header.Length);
953 ok( completeDvdManufacturerDescriptor.Header.Reserved[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdManufacturerDescriptor.Header.Reserved[0]);
954 ok( completeDvdManufacturerDescriptor.Header.Reserved[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdManufacturerDescriptor.Header.Reserved[1]);
955
956 SetLastError(0xdeadbeef);
957
958 /* Basic parameter check */
959 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
960 NULL, sizeof(DVD_MANUFACTURER_DESCRIPTOR), &nbBytes, NULL);
961 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret, GetLastError());
962 }
963
964 static void test_cdrom_ioctl(void)
965 {
966 char drive_letter, drive_path[] = "A:\\", drive_full_path[] = "\\\\.\\A:";
967 DWORD bitmask;
968 HANDLE handle;
969
970 bitmask = GetLogicalDrives();
971 if(!bitmask)
972 {
973 trace("GetLogicalDrives failed : %u\n", GetLastError());
974 return;
975 }
976
977 for(drive_letter='A'; drive_letter<='Z'; drive_letter++)
978 {
979 if(!(bitmask & (1 << (drive_letter-'A') )))
980 continue;
981
982 drive_path[0] = drive_letter;
983 if(GetDriveTypeA(drive_path) != DRIVE_CDROM)
984 {
985 trace("Skipping %c:, not a CDROM drive.\n", drive_letter);
986 continue;
987 }
988
989 trace("Testing with %c:\n", drive_letter);
990
991 drive_full_path[4] = drive_letter;
992 handle = CreateFileA(drive_full_path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
993 if(handle == INVALID_HANDLE_VALUE)
994 {
995 trace("Failed to open the device : %u\n", GetLastError());
996 continue;
997 }
998
999 /* Add your tests here */
1000 test_dvd_read_structure(handle);
1001
1002 CloseHandle(handle);
1003 }
1004
1005 }
1006
1007 START_TEST(volume)
1008 {
1009 hdll = GetModuleHandleA("kernel32.dll");
1010 pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointA");
1011 pGetVolumeNameForVolumeMountPointW = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointW");
1012 pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
1013 pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
1014 pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
1015 pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
1016 pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
1017 pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
1018 pGetVolumePathNameA = (void *) GetProcAddress(hdll, "GetVolumePathNameA");
1019 pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA");
1020 pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW");
1021
1022 test_query_dos_deviceA();
1023 test_define_dos_deviceA();
1024 test_FindFirstVolume();
1025 test_GetVolumePathNameA();
1026 test_GetVolumeNameForVolumeMountPointA();
1027 test_GetVolumeNameForVolumeMountPointW();
1028 test_GetLogicalDriveStringsA();
1029 test_GetLogicalDriveStringsW();
1030 test_GetVolumeInformationA();
1031 test_enum_vols();
1032 test_disk_extents();
1033 test_GetVolumePathNamesForVolumeNameA();
1034 test_GetVolumePathNamesForVolumeNameW();
1035 test_cdrom_ioctl();
1036 }