fd52a2a927487ed0458eb251502cd1d1616a2e12
[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 if (!pGetVolumePathNamesForVolumeNameW || !pGetVolumeNameForVolumeMountPointW)
769 {
770 win_skip("required functions not found\n");
771 return;
772 }
773
774 ret = pGetVolumeNameForVolumeMountPointW( drive_c, volume, sizeof(volume)/sizeof(volume[0]) );
775 ok(ret, "failed to get volume name %u\n", GetLastError());
776
777 SetLastError( 0xdeadbeef );
778 ret = pGetVolumePathNamesForVolumeNameW( empty, NULL, 0, NULL );
779 error = GetLastError();
780 ok(!ret, "expected failure\n");
781 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
782
783 SetLastError( 0xdeadbeef );
784 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, 0, NULL );
785 error = GetLastError();
786 ok(!ret, "expected failure\n");
787 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
788
789 SetLastError( 0xdeadbeef );
790 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, 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 if (0) { /* crash */
796 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, sizeof(buffer), NULL );
797 ok(ret, "failed to get path names %u\n", GetLastError());
798 }
799
800 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), NULL );
801 ok(ret, "failed to get path names %u\n", GetLastError());
802
803 len = 0;
804 memset( buffer, 0xff, sizeof(buffer) );
805 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
806 ok(ret, "failed to get path names %u\n", GetLastError());
807 ok(len == 5, "expected 5 got %u\n", len);
808 ok(!buffer[4], "expected double null-terminated buffer\n");
809
810 len = 0;
811 volume[1] = '?';
812 volume[lstrlenW( volume ) - 1] = 0;
813 SetLastError( 0xdeadbeef );
814 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
815 error = GetLastError();
816 ok(!ret, "expected failure\n");
817 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
818
819 len = 0;
820 volume[0] = '\\';
821 volume[1] = 0;
822 SetLastError( 0xdeadbeef );
823 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
824 error = GetLastError();
825 ok(!ret, "expected failure\n");
826 todo_wine ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
827
828 len = 0;
829 lstrcpyW( volume, volume_null );
830 SetLastError( 0xdeadbeef );
831 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
832 error = GetLastError();
833 ok(!ret, "expected failure\n");
834 ok(error == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND got %u\n", error);
835 }
836
837 static void test_dvd_read_structure(HANDLE handle)
838 {
839 int i;
840 DWORD nbBytes;
841 BOOL ret;
842 DVD_READ_STRUCTURE dvdReadStructure;
843 DVD_LAYER_DESCRIPTOR dvdLayerDescriptor;
844 struct COMPLETE_DVD_LAYER_DESCRIPTOR completeDvdLayerDescriptor;
845 DVD_COPYRIGHT_DESCRIPTOR dvdCopyrightDescriptor;
846 struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR completeDvdManufacturerDescriptor;
847
848 dvdReadStructure.BlockByteOffset.QuadPart = 0;
849 dvdReadStructure.SessionId = 0;
850 dvdReadStructure.LayerNumber = 0;
851
852
853 /* DvdPhysicalDescriptor */
854 dvdReadStructure.Format = 0;
855
856 SetLastError(0xdeadbeef);
857
858 /* Test whether this ioctl is supported */
859 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
860 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
861
862 if(!ret)
863 {
864 skip("IOCTL_DVD_READ_STRUCTURE not supported: %u\n", GetLastError());
865 return;
866 }
867
868 /* Confirm there is always a header before the actual data */
869 ok( completeDvdLayerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdLayerDescriptor.Header.Length);
870 ok( completeDvdLayerDescriptor.Header.Reserved[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[0]);
871 ok( completeDvdLayerDescriptor.Header.Reserved[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[1]);
872
873 /* TODO: Also check completeDvdLayerDescriptor.Descriptor content (via IOCTL_SCSI_PASS_THROUGH_DIRECT ?) */
874
875 /* Insufficient output buffer */
876 for(i=0; i<sizeof(DVD_DESCRIPTOR_HEADER); i++)
877 {
878 SetLastError(0xdeadbeef);
879
880 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
881 &completeDvdLayerDescriptor, i, &nbBytes, NULL);
882 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,"IOCTL_DVD_READ_STRUCTURE should fail with small buffer\n");
883 }
884
885 SetLastError(0xdeadbeef);
886
887 /* On newer version, an output buffer of sizeof(DVD_READ_STRUCTURE) size fails.
888 I think this is to force developers to realize that there is a header before the actual content */
889 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
890 &dvdLayerDescriptor, sizeof(DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
891 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER) || broken(ret) /* < Win7 */,
892 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
893
894 SetLastError(0xdeadbeef);
895
896 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, NULL, sizeof(DVD_READ_STRUCTURE),
897 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
898 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER),
899 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
900
901 /* Test wrong input parameters */
902 for(i=0; i<sizeof(DVD_READ_STRUCTURE); i++)
903 {
904 SetLastError(0xdeadbeef);
905
906 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, i,
907 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
908 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER),
909 "IOCTL_DVD_READ_STRUCTURE should have failed\n");
910 }
911
912
913 /* DvdCopyrightDescriptor */
914 dvdReadStructure.Format = 1;
915
916 SetLastError(0xdeadbeef);
917
918 /* Strangely, with NULL lpOutBuffer, last error is insufficient buffer, not invalid parameter as we could expect */
919 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
920 NULL, sizeof(DVD_COPYRIGHT_DESCRIPTOR), &nbBytes, NULL);
921 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret, GetLastError());
922
923 for(i=0; i<sizeof(DVD_COPYRIGHT_DESCRIPTOR); i++)
924 {
925 SetLastError(0xdeadbeef);
926
927 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
928 &dvdCopyrightDescriptor, i, &nbBytes, NULL);
929 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret, GetLastError());
930 }
931
932
933 /* DvdManufacturerDescriptor */
934 dvdReadStructure.Format = 4;
935
936 SetLastError(0xdeadbeef);
937
938 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
939 &completeDvdManufacturerDescriptor, sizeof(DVD_MANUFACTURER_DESCRIPTOR), &nbBytes, NULL);
940 ok(ret || broken(GetLastError() == ERROR_NOT_READY),
941 "IOCTL_DVD_READ_STRUCTURE (DvdManufacturerDescriptor) failed, last error = %u\n", GetLastError());
942 if(!ret)
943 return;
944
945 /* Confirm there is always a header before the actual data */
946 ok( completeDvdManufacturerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdManufacturerDescriptor.Header.Length);
947 ok( completeDvdManufacturerDescriptor.Header.Reserved[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdManufacturerDescriptor.Header.Reserved[0]);
948 ok( completeDvdManufacturerDescriptor.Header.Reserved[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdManufacturerDescriptor.Header.Reserved[1]);
949
950 SetLastError(0xdeadbeef);
951
952 /* Basic parameter check */
953 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
954 NULL, sizeof(DVD_MANUFACTURER_DESCRIPTOR), &nbBytes, NULL);
955 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret, GetLastError());
956 }
957
958 static void test_cdrom_ioctl(void)
959 {
960 char drive_letter, drive_path[] = "A:\\", drive_full_path[] = "\\\\.\\A:";
961 DWORD bitmask;
962 HANDLE handle;
963
964 bitmask = GetLogicalDrives();
965 if(!bitmask)
966 {
967 trace("GetLogicalDrives failed : %u\n", GetLastError());
968 return;
969 }
970
971 for(drive_letter='A'; drive_letter<='Z'; drive_letter++)
972 {
973 if(!(bitmask & (1 << (drive_letter-'A') )))
974 continue;
975
976 drive_path[0] = drive_letter;
977 if(GetDriveTypeA(drive_path) != DRIVE_CDROM)
978 {
979 trace("Skipping %c:, not a CDROM drive.\n", drive_letter);
980 continue;
981 }
982
983 trace("Testing with %c:\n", drive_letter);
984
985 drive_full_path[4] = drive_letter;
986 handle = CreateFileA(drive_full_path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
987 if(handle == INVALID_HANDLE_VALUE)
988 {
989 trace("Failed to open the device : %u\n", GetLastError());
990 continue;
991 }
992
993 /* Add your tests here */
994 test_dvd_read_structure(handle);
995
996 CloseHandle(handle);
997 }
998
999 }
1000
1001 START_TEST(volume)
1002 {
1003 hdll = GetModuleHandleA("kernel32.dll");
1004 pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointA");
1005 pGetVolumeNameForVolumeMountPointW = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointW");
1006 pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
1007 pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
1008 pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
1009 pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
1010 pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
1011 pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
1012 pGetVolumePathNameA = (void *) GetProcAddress(hdll, "GetVolumePathNameA");
1013 pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA");
1014 pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW");
1015
1016 test_query_dos_deviceA();
1017 test_define_dos_deviceA();
1018 test_FindFirstVolume();
1019 test_GetVolumePathNameA();
1020 test_GetVolumeNameForVolumeMountPointA();
1021 test_GetVolumeNameForVolumeMountPointW();
1022 test_GetLogicalDriveStringsA();
1023 test_GetLogicalDriveStringsW();
1024 test_GetVolumeInformationA();
1025 test_enum_vols();
1026 test_disk_extents();
1027 test_GetVolumePathNamesForVolumeNameA();
1028 test_GetVolumePathNamesForVolumeNameW();
1029 test_cdrom_ioctl();
1030 }