Reactos
at master 1926 lines 84 kB view raw
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 <stdio.h> 22#include "ntstatus.h" 23#define WIN32_NO_STATUS 24#include "windef.h" 25#include "winbase.h" 26#include "winioctl.h" 27#include "ntddstor.h" 28#include "winternl.h" 29#include "ddk/ntddcdvd.h" 30#include "ddk/mountmgr.h" 31#include "wine/test.h" 32 33#include <pshpack1.h> 34struct COMPLETE_DVD_LAYER_DESCRIPTOR 35{ 36 DVD_DESCRIPTOR_HEADER Header; 37 DVD_LAYER_DESCRIPTOR Descriptor; 38 UCHAR Padding; 39}; 40#include <poppack.h> 41C_ASSERT(sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR) == 22); 42 43#include <pshpack1.h> 44struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR 45{ 46 DVD_DESCRIPTOR_HEADER Header; 47 DVD_MANUFACTURER_DESCRIPTOR Descriptor; 48 UCHAR Padding; 49}; 50#include <poppack.h> 51C_ASSERT(sizeof(struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR) == 2053); 52 53static HINSTANCE hdll; 54static HANDLE (WINAPI *pFindFirstVolumeA)(LPSTR,DWORD); 55static BOOL (WINAPI *pFindNextVolumeA)(HANDLE,LPSTR,DWORD); 56static BOOL (WINAPI *pFindVolumeClose)(HANDLE); 57static UINT (WINAPI *pGetLogicalDriveStringsA)(UINT,LPSTR); 58static UINT (WINAPI *pGetLogicalDriveStringsW)(UINT,LPWSTR); 59static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameA)(LPCSTR, LPSTR, DWORD, LPDWORD); 60static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameW)(LPCWSTR, LPWSTR, DWORD, LPDWORD); 61static BOOL (WINAPI *pCreateSymbolicLinkA)(const char *, const char *, DWORD); 62static BOOL (WINAPI *pGetVolumeInformationByHandleW)(HANDLE, WCHAR *, DWORD, DWORD *, DWORD *, DWORD *, WCHAR *, DWORD); 63 64/* ############################### */ 65 66static void test_query_dos_deviceA(void) 67{ 68 char drivestr[] = "a:"; 69 char *p, *buffer, buffer2[2000]; 70 DWORD ret, ret2, buflen=32768; 71 BOOL found = FALSE; 72 73 /* callers must guess the buffer size */ 74 SetLastError(0xdeadbeef); 75 ret = QueryDosDeviceA( NULL, NULL, 0 ); 76 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, 77 "QueryDosDeviceA(no buffer): returned %lu, le=%lu\n", ret, GetLastError()); 78 79 buffer = HeapAlloc( GetProcessHeap(), 0, buflen ); 80 SetLastError(0xdeadbeef); 81 ret = QueryDosDeviceA( NULL, buffer, buflen ); 82 ok((ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER), 83 "QueryDosDeviceA failed to return list, last error %lu\n", GetLastError()); 84 85 if (ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER) { 86 p = buffer; 87 for (;;) { 88 if (!*p) break; 89 ret2 = QueryDosDeviceA( p, buffer2, sizeof(buffer2) ); 90 /* Win10+ exposes the security device which requires extra privileges to be queried. So skip it */ 91 ok(ret2 || broken( !strcmp( p, "MSSECFLTSYS" ) && GetLastError() == ERROR_ACCESS_DENIED ), 92 "QueryDosDeviceA failed to return current mapping for %s, last error %lu\n", p, GetLastError()); 93 p += strlen(p) + 1; 94 if (ret <= (p-buffer)) break; 95 } 96 } 97 98 for (;drivestr[0] <= 'z'; drivestr[0]++) { 99 /* Older W2K fails with ERROR_INSUFFICIENT_BUFFER when buflen is > 32767 */ 100 ret = QueryDosDeviceA( drivestr, buffer, buflen - 1); 101 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND, 102 "QueryDosDeviceA failed to return current mapping for %s, last error %lu\n", drivestr, GetLastError()); 103 if(ret) { 104 for (p = buffer; *p; p++) *p = toupper(*p); 105 if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE; 106 } 107 } 108 ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n"); 109 HeapFree( GetProcessHeap(), 0, buffer ); 110} 111 112static void test_dos_devices(void) 113{ 114 char buf[MAX_PATH], buf2[400]; 115 char drivestr[3]; 116 HANDLE file; 117 BOOL ret; 118#ifdef __REACTOS__ 119 char root_path[MAX_PATH], buf3[MAX_PATH]; 120 121 GetWindowsDirectoryA(root_path, sizeof(root_path)); 122#endif 123 124 /* Find an unused drive letter */ 125 drivestr[1] = ':'; 126 drivestr[2] = 0; 127 for (drivestr[0] = 'a'; drivestr[0] <= 'z'; drivestr[0]++) { 128 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf)); 129 if (!ret) break; 130 } 131 if (drivestr[0] > 'z') { 132 skip("can't test creating a dos drive, none available\n"); 133 return; 134 } 135 136#ifdef __REACTOS__ 137 sprintf(buf3, "%s/", root_path); 138 for (char *p = buf3; *p; p++) { 139 if (*p == '\\') *p = '/'; // Replace backslashes with forward slashes 140 else if (p != buf3) *p = (char)tolower((unsigned char)*p); // Lowercase everything except the first character 141 } 142 ret = DefineDosDeviceA( 0, drivestr, buf3 ); 143#else 144 ret = DefineDosDeviceA( 0, drivestr, "C:/windows/" ); 145#endif 146 ok(ret, "failed to define drive %s, error %lu\n", drivestr, GetLastError()); 147 148 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf) ); 149 ok(ret, "failed to query drive %s, error %lu\n", drivestr, GetLastError()); 150#ifdef __REACTOS__ 151 sprintf(buf3, "\\??\\%s\\", root_path); 152 for (char *p = buf3; *p; p++) { 153 if (p != (buf3 + 4)) *p = (char)tolower((unsigned char)*p); // Lowercase everything except "C:\" 154 } 155 ok(!strcmp(buf, buf3), "got path %s\n", debugstr_a(buf)); 156#else 157 ok(!strcmp(buf, "\\??\\C:\\windows\\"), "got path %s\n", debugstr_a(buf)); 158#endif 159 160 sprintf(buf, "%s/system32", drivestr); 161 file = CreateFileA( buf, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 162 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); 163 todo_wine ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError()); 164 CloseHandle( file ); 165 166 /* but it's not a volume mount point */ 167 168 sprintf(buf, "%s\\", drivestr); 169 ret = GetVolumeNameForVolumeMountPointA( buf, buf2, sizeof(buf2) ); 170 ok(!ret, "expected failure\n"); 171 todo_wine ok(GetLastError() == ERROR_INVALID_PARAMETER, "got error %lu\n", GetLastError()); 172 173 ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL); 174 ok(ret, "failed to remove drive %s, error %lu\n", drivestr, GetLastError()); 175 176 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf) ); 177 ok(!ret, "expected failure\n"); 178 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "got error %lu\n", GetLastError()); 179 180 sprintf(buf, "%s/system32", drivestr); 181 file = CreateFileA( buf, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 182 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); 183 ok(file == INVALID_HANDLE_VALUE, "expected failure\n"); 184 todo_wine ok(GetLastError() == ERROR_PATH_NOT_FOUND, "got error %lu\n", GetLastError()); 185 186 /* try with DDD_RAW_TARGET_PATH */ 187 188#ifdef __REACTOS__ 189 ret = DefineDosDeviceA( DDD_RAW_TARGET_PATH, drivestr, buf3 ); 190#else 191 ret = DefineDosDeviceA( DDD_RAW_TARGET_PATH, drivestr, "\\??\\C:\\windows\\" ); 192#endif 193 ok(ret, "failed to define drive %s, error %lu\n", drivestr, GetLastError()); 194 195 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf) ); 196 ok(ret, "failed to query drive %s, error %lu\n", drivestr, GetLastError()); 197#ifdef __REACTOS__ 198 ok(!strcmp(buf, buf3), "got path %s\n", debugstr_a(buf)); 199#else 200 ok(!strcmp(buf, "\\??\\C:\\windows\\"), "got path %s\n", debugstr_a(buf)); 201#endif 202 203 sprintf(buf, "%s/system32", drivestr); 204 file = CreateFileA( buf, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 205 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); 206 todo_wine ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError()); 207 CloseHandle( file ); 208 209 sprintf(buf, "%s\\", drivestr); 210 ret = GetVolumeNameForVolumeMountPointA( buf, buf2, sizeof(buf2) ); 211 ok(!ret, "expected failure\n"); 212 todo_wine ok(GetLastError() == ERROR_INVALID_PARAMETER, "got error %lu\n", GetLastError()); 213 214 ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL); 215 ok(ret, "failed to remove drive %s, error %lu\n", drivestr, GetLastError()); 216 217 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf) ); 218 ok(!ret, "expected failure\n"); 219 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "got error %lu\n", GetLastError()); 220} 221 222static void test_FindFirstVolume(void) 223{ 224 char volume[51]; 225 HANDLE handle; 226 227 /* not present before w2k */ 228 if (!pFindFirstVolumeA) { 229 win_skip("FindFirstVolumeA not found\n"); 230 return; 231 } 232 233 handle = pFindFirstVolumeA( volume, 0 ); 234 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" ); 235 ok( GetLastError() == ERROR_MORE_DATA || /* XP */ 236 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Vista */ 237 "wrong error %lu\n", GetLastError() ); 238 handle = pFindFirstVolumeA( volume, 49 ); 239 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" ); 240 ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE, "wrong error %lu\n", GetLastError() ); 241 handle = pFindFirstVolumeA( volume, 51 ); 242 ok( handle != INVALID_HANDLE_VALUE, "failed err %lu\n", GetLastError() ); 243 if (handle != INVALID_HANDLE_VALUE) 244 { 245 do 246 { 247 ok( strlen(volume) == 49, "bad volume name %s\n", volume ); 248 ok( !memcmp( volume, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume ); 249 ok( !memcmp( volume + 47, "}\\", 2 ), "bad volume name %s\n", volume ); 250 } while (pFindNextVolumeA( handle, volume, MAX_PATH )); 251 ok( GetLastError() == ERROR_NO_MORE_FILES, "wrong error %lu\n", GetLastError() ); 252 pFindVolumeClose( handle ); 253 } 254} 255 256static void test_GetVolumeNameForVolumeMountPointA(void) 257{ 258 BOOL ret; 259 char volume[MAX_PATH], path[] = "c:\\"; 260 DWORD len = sizeof(volume), reti; 261 char temp_path[MAX_PATH]; 262 263 reti = GetTempPathA(MAX_PATH, temp_path); 264 ok(reti != 0, "GetTempPathA error %ld\n", GetLastError()); 265 ok(reti < MAX_PATH, "temp path should fit into MAX_PATH\n"); 266 267 ret = GetVolumeNameForVolumeMountPointA(path, volume, 0); 268 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n"); 269 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE || 270 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */ 271 "wrong error, last=%ld\n", GetLastError()); 272 273 if (0) { /* these crash on XP */ 274 ret = GetVolumeNameForVolumeMountPointA(path, NULL, len); 275 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n"); 276 277 ret = GetVolumeNameForVolumeMountPointA(NULL, volume, len); 278 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n"); 279 } 280 281 ret = GetVolumeNameForVolumeMountPointA(path, volume, len); 282 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n"); 283 ok(!strncmp( volume, "\\\\?\\Volume{", 11), 284 "GetVolumeNameForVolumeMountPointA failed to return valid string <%s>\n", 285 volume); 286 287 /* test with too small buffer */ 288 ret = GetVolumeNameForVolumeMountPointA(path, volume, 10); 289 ok(ret == FALSE && GetLastError() == ERROR_FILENAME_EXCED_RANGE, 290 "GetVolumeNameForVolumeMountPointA failed, wrong error returned, was %ld, should be ERROR_FILENAME_EXCED_RANGE\n", 291 GetLastError()); 292 293 /* Try on an arbitrary directory */ 294 /* On FAT filesystems it seems that GetLastError() is set to 295 ERROR_INVALID_FUNCTION. */ 296 ret = GetVolumeNameForVolumeMountPointA(temp_path, volume, len); 297 ok(ret == FALSE && (GetLastError() == ERROR_NOT_A_REPARSE_POINT || 298 GetLastError() == ERROR_INVALID_FUNCTION), 299 "GetVolumeNameForVolumeMountPointA failed on %s, last=%ld\n", 300 temp_path, GetLastError()); 301 302 /* Try on a nonexistent dos drive */ 303 path[2] = 0; 304 for (;path[0] <= 'z'; path[0]++) { 305 ret = QueryDosDeviceA( path, volume, len); 306 if(!ret) break; 307 } 308 if (path[0] <= 'z') 309 { 310 path[2] = '\\'; 311 ret = GetVolumeNameForVolumeMountPointA(path, volume, len); 312 ok(ret == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND, 313 "GetVolumeNameForVolumeMountPointA failed on %s, last=%ld\n", 314 path, GetLastError()); 315 316 /* Try without trailing \ and on a nonexistent dos drive */ 317 path[2] = 0; 318 ret = GetVolumeNameForVolumeMountPointA(path, volume, len); 319 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME, 320 "GetVolumeNameForVolumeMountPointA failed on %s, last=%ld\n", 321 path, GetLastError()); 322 } 323} 324 325static void test_GetVolumeNameForVolumeMountPointW(void) 326{ 327 BOOL ret; 328 WCHAR volume[MAX_PATH], path[] = {'c',':','\\',0}; 329 DWORD len = ARRAY_SIZE(volume); 330 331 ret = GetVolumeNameForVolumeMountPointW(path, volume, 0); 332 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n"); 333 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE || 334 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */ 335 "wrong error, last=%ld\n", GetLastError()); 336 337 if (0) { /* these crash on XP */ 338 ret = GetVolumeNameForVolumeMountPointW(path, NULL, len); 339 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n"); 340 341 ret = GetVolumeNameForVolumeMountPointW(NULL, volume, len); 342 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n"); 343 } 344 345 ret = GetVolumeNameForVolumeMountPointW(path, volume, len); 346 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n"); 347} 348 349static void test_GetLogicalDriveStringsA(void) 350{ 351 UINT size, size2; 352 char *buf, *ptr; 353 354 ok( pGetLogicalDriveStringsA != NULL, "GetLogicalDriveStringsA not available\n"); 355 if(!pGetLogicalDriveStringsA) { 356 return; 357 } 358 359 size = pGetLogicalDriveStringsA(0, NULL); 360 ok(size%4 == 1, "size = %d\n", size); 361 362 buf = HeapAlloc(GetProcessHeap(), 0, size); 363 364 *buf = 0; 365 size2 = pGetLogicalDriveStringsA(2, buf); 366 ok(size2 == size, "size2 = %d\n", size2); 367 ok(!*buf, "buf changed\n"); 368 369 size2 = pGetLogicalDriveStringsA(size, buf); 370 ok(size2 == size-1, "size2 = %d\n", size2); 371 372 for(ptr = buf; ptr < buf+size2; ptr += 4) { 373 ok(('A' <= *ptr && *ptr <= 'Z'), "device name '%c' is not uppercase\n", *ptr); 374 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]); 375 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]); 376 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]); 377 } 378 ok(!*ptr, "buf[size2] is not nullbyte\n"); 379 380 HeapFree(GetProcessHeap(), 0, buf); 381} 382 383static void test_GetLogicalDriveStringsW(void) 384{ 385 UINT size, size2; 386 WCHAR *buf, *ptr; 387 388 ok( pGetLogicalDriveStringsW != NULL, "GetLogicalDriveStringsW not available\n"); 389 if(!pGetLogicalDriveStringsW) { 390 return; 391 } 392 393 SetLastError(0xdeadbeef); 394 size = pGetLogicalDriveStringsW(0, NULL); 395 if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { 396 win_skip("GetLogicalDriveStringsW not implemented\n"); 397 return; 398 } 399 ok(size%4 == 1, "size = %d\n", size); 400 401 buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR)); 402 403 *buf = 0; 404 size2 = pGetLogicalDriveStringsW(2, buf); 405 ok(size2 == size, "size2 = %d\n", size2); 406 ok(!*buf, "buf changed\n"); 407 408 size2 = pGetLogicalDriveStringsW(size, buf); 409 ok(size2 == size-1, "size2 = %d\n", size2); 410 411 for(ptr = buf; ptr < buf+size2; ptr += 4) { 412 ok('A' <= *ptr && *ptr <= 'Z', "device name '%c' is not uppercase\n", *ptr); 413 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]); 414 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]); 415 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]); 416 } 417 ok(!*ptr, "buf[size2] is not nullbyte\n"); 418 419 HeapFree(GetProcessHeap(), 0, buf); 420} 421 422static void test_GetVolumeInformationA(void) 423{ 424 BOOL ret; 425 UINT result; 426 char Root_Colon[]="C:"; 427 char Root_Slash[]="C:\\"; 428 char Root_UNC[]="\\\\?\\C:\\"; 429 char volume[MAX_PATH+1]; 430 DWORD vol_name_size=MAX_PATH+1, vol_serial_num=-1, max_comp_len=0, fs_flags=0, fs_name_len=MAX_PATH+1; 431 char vol_name_buf[MAX_PATH+1], fs_name_buf[MAX_PATH+1]; 432 char windowsdir[MAX_PATH+10]; 433 char currentdir[MAX_PATH+1]; 434 435 /* get windows drive letter and update strings for testing */ 436 result = GetWindowsDirectoryA(windowsdir, sizeof(windowsdir)); 437 ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n"); 438 ok(result != 0, "GetWindowsDirectory: error %ld\n", GetLastError()); 439 Root_Colon[0] = windowsdir[0]; 440 Root_Slash[0] = windowsdir[0]; 441 Root_UNC[4] = windowsdir[0]; 442 443 result = GetCurrentDirectoryA(MAX_PATH, currentdir); 444 ok(result, "GetCurrentDirectory: error %ld\n", GetLastError()); 445 /* Note that GetCurrentDir yields no trailing slash for subdirs */ 446 447 /* check for NO error on no trailing \ when current dir is root dir */ 448 ret = SetCurrentDirectoryA(Root_Slash); 449 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError()); 450 ret = GetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL, 451 NULL, NULL, fs_name_buf, fs_name_len); 452 ok(ret, "GetVolumeInformationA root failed, last error %lu\n", GetLastError()); 453 454 /* check for error on no trailing \ when current dir is subdir (windows) of queried drive */ 455 ret = SetCurrentDirectoryA(windowsdir); 456 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError()); 457 SetLastError(0xdeadbeef); 458 ret = GetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL, 459 NULL, NULL, fs_name_buf, fs_name_len); 460 ok(!ret && (GetLastError() == ERROR_INVALID_NAME), 461 "GetVolumeInformationA did%s fail, last error %lu\n", ret ? " not":"", GetLastError()); 462 463 /* reset current directory */ 464 ret = SetCurrentDirectoryA(currentdir); 465 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError()); 466 467 if (toupper(currentdir[0]) == toupper(windowsdir[0])) { 468 skip("Please re-run from another device than %c:\n", windowsdir[0]); 469 /* FIXME: Use GetLogicalDrives to find another device to avoid this skip. */ 470 } else { 471 char Root_Env[]="=C:"; /* where MS maintains the per volume directory */ 472 Root_Env[1] = windowsdir[0]; 473 474 /* C:\windows becomes the current directory on drive C: */ 475 /* Note that paths to subdirs are stored without trailing slash, like what GetCurrentDir yields. */ 476 ret = SetEnvironmentVariableA(Root_Env, windowsdir); 477 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env); 478 479 ret = SetCurrentDirectoryA(windowsdir); 480 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError()); 481 ret = SetCurrentDirectoryA(currentdir); 482 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError()); 483 484 /* windows dir is current on the root drive, call fails */ 485 SetLastError(0xdeadbeef); 486 ret = GetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL, 487 NULL, NULL, fs_name_buf, fs_name_len); 488 ok(!ret && (GetLastError() == ERROR_INVALID_NAME), 489 "GetVolumeInformationA did%s fail, last error %lu\n", ret ? " not":"", GetLastError()); 490 491 /* Try normal drive letter with trailing \ */ 492 ret = GetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size, NULL, 493 NULL, NULL, fs_name_buf, fs_name_len); 494 ok(ret, "GetVolumeInformationA with \\ failed, last error %lu\n", GetLastError()); 495 496 ret = SetCurrentDirectoryA(Root_Slash); 497 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError()); 498 ret = SetCurrentDirectoryA(currentdir); 499 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError()); 500 501 /* windows dir is STILL CURRENT on root drive; the call fails as before, */ 502 /* proving that SetCurrentDir did not remember the other drive's directory */ 503 SetLastError(0xdeadbeef); 504 ret = GetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL, 505 NULL, NULL, fs_name_buf, fs_name_len); 506 ok(!ret && (GetLastError() == ERROR_INVALID_NAME), 507 "GetVolumeInformationA did%s fail, last error %lu\n", ret ? " not":"", GetLastError()); 508 509 /* Now C:\ becomes the current directory on drive C: */ 510 ret = SetEnvironmentVariableA(Root_Env, Root_Slash); /* set =C:=C:\ */ 511 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env); 512 513 /* \ is current on root drive, call succeeds */ 514 ret = GetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL, 515 NULL, NULL, fs_name_buf, fs_name_len); 516 ok(ret, "GetVolumeInformationA failed, last error %lu\n", GetLastError()); 517 518 /* again, SetCurrentDirectory on another drive does not matter */ 519 ret = SetCurrentDirectoryA(Root_Slash); 520 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError()); 521 ret = SetCurrentDirectoryA(currentdir); 522 ok(ret, "SetCurrentDirectory: error %ld\n", GetLastError()); 523 524 /* \ is current on root drive, call succeeds */ 525 ret = GetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL, 526 NULL, NULL, fs_name_buf, fs_name_len); 527 ok(ret, "GetVolumeInformationA failed, last error %lu\n", GetLastError()); 528 } 529 530 /* try null root directory to return "root of the current directory" */ 531 ret = GetVolumeInformationA(NULL, vol_name_buf, vol_name_size, NULL, 532 NULL, NULL, fs_name_buf, fs_name_len); 533 ok(ret, "GetVolumeInformationA failed on null root dir, last error %lu\n", GetLastError()); 534 535 /* Try normal drive letter with trailing \ */ 536 ret = GetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size, 537 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len); 538 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%lu\n", Root_Slash, GetLastError()); 539 540 /* try again with drive letter and the "disable parsing" prefix */ 541 SetLastError(0xdeadbeef); 542 ret = GetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size, 543 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len); 544 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%lu\n", ret ? " not":"", Root_UNC, GetLastError()); 545 546 /* try again with device name space */ 547 Root_UNC[2] = '.'; 548 SetLastError(0xdeadbeef); 549 ret = GetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size, 550 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len); 551 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%lu\n", ret ? " not":"", Root_UNC, GetLastError()); 552 553 /* try again with a directory off the root - should generate error */ 554 if (windowsdir[strlen(windowsdir)-1] != '\\') strcat(windowsdir, "\\"); 555 SetLastError(0xdeadbeef); 556 ret = GetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size, 557 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len); 558 ok(!ret && (GetLastError()==ERROR_DIR_NOT_ROOT), 559 "GetVolumeInformationA did%s fail, root=%s, last error=%lu\n", ret ? " not":"", windowsdir, GetLastError()); 560 /* A subdir with trailing \ yields DIR_NOT_ROOT instead of INVALID_NAME */ 561 if (windowsdir[strlen(windowsdir)-1] == '\\') windowsdir[strlen(windowsdir)-1] = 0; 562 SetLastError(0xdeadbeef); 563 ret = GetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size, 564 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len); 565 ok(!ret && (GetLastError()==ERROR_INVALID_NAME), 566 "GetVolumeInformationA did%s fail, root=%s, last error=%lu\n", ret ? " not":"", windowsdir, GetLastError()); 567 568 /* get the unique volume name for the windows drive */ 569 ret = GetVolumeNameForVolumeMountPointA(Root_Slash, volume, MAX_PATH); 570 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n"); 571 572 /* try again with unique volume name */ 573 ret = GetVolumeInformationA(volume, vol_name_buf, vol_name_size, 574 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len); 575 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%lu\n", volume, GetLastError()); 576} 577 578/* Test to check that unique volume name from windows dir mount point */ 579/* matches at least one of the unique volume names returned from the */ 580/* FindFirstVolumeA/FindNextVolumeA list. */ 581static void test_enum_vols(void) 582{ 583 DWORD ret; 584 HANDLE hFind = INVALID_HANDLE_VALUE; 585 char Volume_1[MAX_PATH] = {0}; 586 char Volume_2[MAX_PATH] = {0}; 587 char path[] = "c:\\"; 588 BOOL found = FALSE; 589 char windowsdir[MAX_PATH]; 590 591 /*get windows drive letter and update strings for testing */ 592 ret = GetWindowsDirectoryA( windowsdir, sizeof(windowsdir) ); 593 ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n"); 594 ok(ret != 0, "GetWindowsDirectory: error %ld\n", GetLastError()); 595 path[0] = windowsdir[0]; 596 597 /* get the unique volume name for the windows drive */ 598 ret = GetVolumeNameForVolumeMountPointA( path, Volume_1, MAX_PATH ); 599 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n"); 600 ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1); 601 602 /* get first unique volume name of list */ 603 hFind = pFindFirstVolumeA( Volume_2, MAX_PATH ); 604 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstVolume failed, err=%lu\n", 605 GetLastError()); 606 607 do 608 { 609 /* validate correct length of unique volume name */ 610 ok(strlen(Volume_2) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1); 611 if (memcmp(Volume_1, Volume_2, 49) == 0) 612 { 613 found = TRUE; 614 break; 615 } 616 } while (pFindNextVolumeA( hFind, Volume_2, MAX_PATH )); 617 ok(found, "volume name %s not found by Find[First/Next]Volume\n", Volume_1); 618 pFindVolumeClose( hFind ); 619} 620 621static void test_disk_extents(void) 622{ 623 BOOL ret; 624 DWORD size; 625 HANDLE handle; 626 static DWORD data[16]; 627 628 handle = CreateFileA( "\\\\.\\c:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 ); 629 if (handle == INVALID_HANDLE_VALUE) 630 { 631 win_skip("can't open c: drive %lu\n", GetLastError()); 632 return; 633 } 634 size = 0; 635 ret = DeviceIoControl( handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, &data, 636 sizeof(data), &data, sizeof(data), &size, NULL ); 637 if (!ret && GetLastError() == ERROR_INVALID_FUNCTION) 638 { 639 win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n"); 640 CloseHandle( handle ); 641 return; 642 } 643 ok(ret, "DeviceIoControl failed %lu\n", GetLastError()); 644 ok(size == 32, "expected 32, got %lu\n", size); 645 CloseHandle( handle ); 646} 647 648static void test_disk_query_property(void) 649{ 650 STORAGE_PROPERTY_QUERY query = {0}; 651 STORAGE_DESCRIPTOR_HEADER header = {0}; 652 STORAGE_DEVICE_DESCRIPTOR descriptor = {0}; 653 DEVICE_SEEK_PENALTY_DESCRIPTOR seek_pen = {0}; 654 HANDLE handle; 655 DWORD error; 656 DWORD size; 657 BOOL ret; 658 659 handle = CreateFileA("\\\\.\\PhysicalDrive0", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 660 0, 0); 661 if (handle == INVALID_HANDLE_VALUE) 662 { 663 win_skip("can't open \\\\.\\PhysicalDrive0 %#lx\n", GetLastError()); 664 return; 665 } 666 667 query.PropertyId = StorageDeviceProperty; 668 query.QueryType = PropertyStandardQuery; 669 670 SetLastError(0xdeadbeef); 671 ret = DeviceIoControl(handle, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), &header, sizeof(header), &size, 672 NULL); 673 error = GetLastError(); 674 ok(ret, "expect ret %#x, got %#x\n", TRUE, ret); 675 ok(error == 0xdeadbeef, "expect err %#x, got err %#lx\n", 0xdeadbeef, error); 676 ok(size == sizeof(header), "got size %ld\n", size); 677 ok(header.Version == sizeof(descriptor), "got header.Version %ld\n", header.Version); 678 ok(header.Size >= sizeof(descriptor), "got header.Size %ld\n", header.Size); 679 680 SetLastError(0xdeadbeef); 681 ret = DeviceIoControl(handle, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), &descriptor, sizeof(descriptor), 682 &size, NULL); 683 error = GetLastError(); 684 ok(ret, "expect ret %#x, got %#x\n", TRUE, ret); 685 ok(error == 0xdeadbeef, "expect err %#x, got err %#lx\n", 0xdeadbeef, error); 686 ok(size == sizeof(descriptor), "got size %ld\n", size); 687 ok(descriptor.Version == sizeof(descriptor), "got descriptor.Version %ld\n", descriptor.Version); 688 ok(descriptor.Size >= sizeof(descriptor), "got descriptor.Size %ld\n", descriptor.Size); 689 690 691 query.PropertyId = StorageDeviceSeekPenaltyProperty; 692 query.QueryType = PropertyStandardQuery; 693 SetLastError(0xdeadbeef); 694 ret = DeviceIoControl(handle, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), &header, sizeof(header), &size, 695 NULL); 696 error = GetLastError(); 697 if (!ret && error == ERROR_INVALID_FUNCTION) 698 { 699 win_skip( "StorageDeviceSeekPenaltyProperty is not supported.\n" ); /* Win7 */ 700 } 701 else 702 { 703#ifdef __REACTOS__ 704 if (GetNTVersion() >= _WIN32_WINNT_VISTA) { 705#endif 706 ok(ret, "expect ret %#x, got %#x\n", TRUE, ret); 707 ok(error == 0xdeadbeef, "expect err %#x, got err %#lx\n", 0xdeadbeef, error); 708 ok(size == sizeof(header), "got size %ld\n", size); 709 ok(header.Version == sizeof(seek_pen), "got header.Version %ld\n", header.Version); 710 ok(header.Size == sizeof(seek_pen), "got header.Size %ld\n", header.Size); 711 712 memset(&seek_pen, 0xcc, sizeof(seek_pen)); 713 ret = DeviceIoControl(handle, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), &seek_pen, sizeof(seek_pen), 714 &size, NULL); 715 error = GetLastError(); 716 ok(ret || (error == ERROR_INVALID_FUNCTION /* Win8 VMs */ || (error == ERROR_GEN_FAILURE /* VMs */)), 717 "got ret %d, error %#lx\n", ret, error); 718 if (ret) 719 { 720 ok(size == sizeof(seek_pen), "got size %ld\n", size); 721 ok(seek_pen.Version == sizeof(seek_pen), "got %ld\n", seek_pen.Version); 722 ok(seek_pen.Size == sizeof(seek_pen), "got %ld\n", seek_pen.Size); 723 ok(seek_pen.IncursSeekPenalty == TRUE || seek_pen.IncursSeekPenalty == FALSE, "got %d.\n", seek_pen.IncursSeekPenalty); 724 } 725#ifdef __REACTOS__ 726 } 727#endif 728 } 729 730 CloseHandle(handle); 731} 732 733static void test_GetVolumePathNameA(void) 734{ 735 char volume_path[MAX_PATH], cwd[MAX_PATH], expect_path[MAX_PATH]; 736 struct { 737 const char *file_name; 738 const char *path_name; 739 DWORD path_len; 740 DWORD error; 741 DWORD broken_error; 742 } test_paths[] = { 743 { /* test 0: NULL parameters, 0 output length */ 744 NULL, NULL, 0, 745 ERROR_INVALID_PARAMETER, 0xdeadbeef /* winxp */ 746 }, 747 { /* empty input, NULL output, 0 output length */ 748 "", NULL, 0, 749 ERROR_INVALID_PARAMETER, 0xdeadbeef /* winxp */ 750 }, 751 { /* valid input, NULL output, 0 output length */ 752 "C:\\", NULL, 0, 753 ERROR_INVALID_PARAMETER, ERROR_FILENAME_EXCED_RANGE /* winxp */ 754 }, 755 { /* valid input, valid output, 0 output length */ 756 "C:\\", "C:\\", 0, 757 ERROR_INVALID_PARAMETER, ERROR_FILENAME_EXCED_RANGE /* winxp */ 758 }, 759 { /* valid input, valid output, 1 output length */ 760 "C:\\", "C:\\", 1, 761 ERROR_FILENAME_EXCED_RANGE, NO_ERROR 762 }, 763 { /* test 5: valid input, valid output, valid output length */ 764 "C:\\", "C:\\", sizeof(volume_path), 765 NO_ERROR, NO_ERROR 766 }, 767 { /* lowercase input, uppercase output, valid output length */ 768 "c:\\", "C:\\", sizeof(volume_path), 769 NO_ERROR, NO_ERROR 770 }, 771 { /* really bogus input, valid output, 1 output length */ 772 "\\\\$$$", "C:\\", 1, 773 ERROR_INVALID_NAME, ERROR_FILENAME_EXCED_RANGE 774 }, 775 { /* a reasonable DOS path that is guaranteed to exist */ 776 "C:\\windows\\system32", "C:\\", sizeof(volume_path), 777 NO_ERROR, NO_ERROR 778 }, 779 { /* a reasonable DOS path that shouldn't exist */ 780 "C:\\windows\\system32\\AnInvalidFolder", "C:\\", sizeof(volume_path), 781 NO_ERROR, NO_ERROR 782 }, 783 { /* test 10: a reasonable NT-converted DOS path that shouldn't exist */ 784 "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:\\", sizeof(volume_path), 785 NO_ERROR, NO_ERROR 786 }, 787 { /* an unreasonable NT-converted DOS path */ 788 "\\\\?\\InvalidDrive:\\AnInvalidFolder", "\\\\?\\InvalidDrive:\\" /* win2k, winxp */, 789 sizeof(volume_path), 790 ERROR_INVALID_NAME, NO_ERROR 791 }, 792 { /* an unreasonable NT volume path */ 793 "\\\\?\\Volume{00000000-00-0000-0000-000000000000}\\AnInvalidFolder", 794 "\\\\?\\Volume{00000000-00-0000-0000-000000000000}\\" /* win2k, winxp */, 795 sizeof(volume_path), 796 ERROR_INVALID_NAME, NO_ERROR 797 }, 798 { /* an unreasonable NT-ish path */ 799 "\\\\ReallyBogus\\InvalidDrive:\\AnInvalidFolder", 800 "\\\\ReallyBogus\\InvalidDrive:\\" /* win2k, winxp */, sizeof(volume_path), 801 ERROR_INVALID_NAME, NO_ERROR 802 }, 803 { 804 "M::", "C:\\", 4, 805 ERROR_FILE_NOT_FOUND, ERROR_MORE_DATA 806 }, 807 { /* test 15 */ 808 "C:", "C:", 2, 809 ERROR_FILENAME_EXCED_RANGE, NO_ERROR 810 }, 811 { 812 "C:", "C:", 3, 813 NO_ERROR, ERROR_FILENAME_EXCED_RANGE 814 }, 815 { 816 "C:\\", "C:", 2, 817 ERROR_FILENAME_EXCED_RANGE, NO_ERROR 818 }, 819 { 820 "C:\\", "C:", 3, 821 NO_ERROR, ERROR_FILENAME_EXCED_RANGE 822 }, 823 { 824 "C::", "C:", 2, 825 ERROR_FILENAME_EXCED_RANGE, NO_ERROR 826 }, 827 { /* test 20 */ 828 "C::", "C:", 3, 829 NO_ERROR, ERROR_FILENAME_EXCED_RANGE 830 }, 831 { 832 "C:\\windows\\system32\\AnInvalidFolder", "C:", 3, 833 NO_ERROR, ERROR_FILENAME_EXCED_RANGE 834 }, 835 { 836 "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:", 3, 837 ERROR_FILENAME_EXCED_RANGE, NO_ERROR 838 }, 839 { 840 "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:", 6, 841 ERROR_FILENAME_EXCED_RANGE, NO_ERROR 842 }, 843 { 844 "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:", 7, 845 NO_ERROR, ERROR_FILENAME_EXCED_RANGE 846 }, 847 { /* test 25 */ 848 "\\\\?\\c:\\AnInvalidFolder", "\\\\?\\c:", 7, 849 NO_ERROR, ERROR_FILENAME_EXCED_RANGE 850 }, 851 { 852 "C:/", "C:\\", 4, 853 NO_ERROR, ERROR_MORE_DATA 854 }, 855 { 856 "M:/", "", 4, 857 ERROR_FILE_NOT_FOUND, ERROR_MORE_DATA 858 }, 859 { 860 "?:ABC:DEF:\\AnInvalidFolder", "?:\\" /* win2k, winxp */, sizeof(volume_path), 861 ERROR_FILE_NOT_FOUND, NO_ERROR 862 }, 863 { 864 "s:omefile", "S:\\" /* win2k, winxp */, sizeof(volume_path), 865 ERROR_FILE_NOT_FOUND, NO_ERROR 866 }, 867 { /* test 30: a reasonable forward slash path that is guaranteed to exist */ 868 "C:/windows/system32", "C:\\", sizeof(volume_path), 869 NO_ERROR, NO_ERROR 870 }, 871 }; 872 873 static const char *relative_tests[] = 874 { 875 "InvalidDrive:\\AnInvalidFolder", 876 "relative/path", 877 "somefile:def", 878 }; 879 880 static const char *global_prefix_tests[] = 881 { 882 "\\??\\CdRom0", 883 "\\??\\ReallyBogus", 884 "\\??\\C:\\NonExistent", 885 "\\??\\M:\\NonExistent", 886 }; 887 888 BOOL ret, success; 889 DWORD error; 890 UINT i; 891 892#ifdef __REACTOS__ 893 char sysroot[MAX_PATH]; 894 char patched[MAX_PATH]; 895 896 /* Get the real system root and lowercase everything other than "C:\""*/ 897 GetWindowsDirectoryA(sysroot, sizeof(sysroot)); 898 for (char *p = sysroot; *p; p++) 899 if (p != sysroot) *p = (char)tolower((unsigned char)*p);; 900 901 /* Patch test 8: "C:\\windows\\system32" */ 902 sprintf(patched, "%s\\system32", sysroot); 903 test_paths[8].file_name = _strdup(patched); 904 905 /* Patch test 9: "C:\\windows\\system32\\AnInvalidFolder" */ 906 sprintf(patched, "%s\\system32\\AnInvalidFolder", sysroot); 907 test_paths[9].file_name = _strdup(patched); 908 909 /* Patch test 30: "C:/windows/system32" (forward slashes) */ 910 sprintf(patched, "%s/system32", sysroot); 911 for (char *p = patched; *p; p++) 912 if (*p == '\\') *p = '/'; 913 test_paths[30].file_name = _strdup(patched); 914#endif 915 916 for (i=0; i<ARRAY_SIZE(test_paths); i++) 917 { 918 BOOL broken_ret = test_paths[i].broken_error == NO_ERROR; 919 char *output = (test_paths[i].path_name != NULL ? volume_path : NULL); 920 BOOL expected_ret = test_paths[i].error == NO_ERROR; 921 922 volume_path[0] = 0; 923 if (test_paths[i].path_len < sizeof(volume_path)) 924 volume_path[ test_paths[i].path_len ] = 0x11; 925 926 SetLastError( 0xdeadbeef ); 927 ret = GetVolumePathNameA( test_paths[i].file_name, output, test_paths[i].path_len ); 928 error = GetLastError(); 929 ok(ret == expected_ret || broken(ret == broken_ret), 930 "GetVolumePathName test %d %s unexpectedly.\n", 931 i, test_paths[i].error == NO_ERROR ? "failed" : "succeeded"); 932 933 if (ret) 934 { 935 ok(!strcmp( volume_path, test_paths[i].path_name ) 936 || broken(!strcasecmp( volume_path, test_paths[i].path_name )), /* XP */ 937 "GetVolumePathName test %d unexpectedly returned path %s (expected %s).\n", 938 i, volume_path, test_paths[i].path_name); 939 } 940 else 941 { 942 /* On success Windows always returns ERROR_MORE_DATA, so only worry about failure */ 943 success = (error == test_paths[i].error || broken(error == test_paths[i].broken_error)); 944 ok(success, "GetVolumePathName test %d unexpectedly returned error 0x%lx (expected 0x%lx).\n", 945 i, error, test_paths[i].error); 946 } 947 948 if (test_paths[i].path_len < sizeof(volume_path)) 949 ok(volume_path[ test_paths[i].path_len ] == 0x11, 950 "GetVolumePathName test %d corrupted byte after end of buffer.\n", i); 951 } 952 953 ret = GetCurrentDirectoryA( sizeof(cwd), cwd ); 954 ok(ret, "Failed to obtain the current working directory, error %lu.\n", GetLastError()); 955 ret = GetVolumePathNameA( cwd, expect_path, sizeof(expect_path) ); 956 ok(ret, "Failed to obtain the current volume path, error %lu.\n", GetLastError()); 957 958 for (i = 0; i < ARRAY_SIZE(relative_tests); i++) 959 { 960 ret = GetVolumePathNameA( relative_tests[i], volume_path, sizeof(volume_path) ); 961 ok(ret, "GetVolumePathName(%s) failed unexpectedly, error %lu.\n", 962 debugstr_a( relative_tests[i] ), GetLastError()); 963 ok(!strcmp( volume_path, expect_path ), "%s: expected %s, got %s.\n", 964 debugstr_a( relative_tests[i] ), debugstr_a( expect_path ), debugstr_a( volume_path )); 965 } 966 967 cwd[3] = 0; 968 for (i = 0; i < ARRAY_SIZE(global_prefix_tests); i++) 969 { 970 ret = GetVolumePathNameA( global_prefix_tests[i], volume_path, sizeof(volume_path) ); 971 ok(ret, "GetVolumePathName(%s) failed unexpectedly, error %lu.\n", 972 debugstr_a( global_prefix_tests[i] ), GetLastError()); 973 ok(!strcmp( volume_path, cwd ), "%s: expected %s, got %s.\n", 974 debugstr_a( global_prefix_tests[i] ), debugstr_a( cwd ), debugstr_a( volume_path )); 975 } 976 977 ret = GetVolumePathNameA( "C:.", expect_path, sizeof(expect_path) ); 978 ok(ret, "Failed to obtain the volume path, error %lu.\n", GetLastError()); 979 980 SetLastError( 0xdeadbeef ); 981 ret = GetVolumePathNameA( "C::", volume_path, 1 ); 982 ok(!ret, "Expected failure.\n"); 983 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE, "Got error %lu.\n", GetLastError()); 984 985 ret = GetVolumePathNameA( "C::", volume_path, sizeof(volume_path) ); 986 ok(ret, "Failed to obtain the volume path, error %lu.\n", GetLastError()); 987 ok(!strcmp(volume_path, expect_path), "Expected %s, got %s.\n", 988 debugstr_a( expect_path ), debugstr_a( volume_path )); 989 990 ret = GetVolumePathNameA( "C:ABC:DEF:\\AnInvalidFolder", volume_path, sizeof(volume_path) ); 991 ok(ret, "Failed to obtain the volume path, error %lu.\n", GetLastError()); 992 ok(!strcmp(volume_path, expect_path), "Expected %s, got %s.\n", 993 debugstr_a( expect_path ), debugstr_a( volume_path )); 994#ifdef __REACTOS__ 995 /* Free patched strings */ 996 free((void*)test_paths[8].file_name); 997 free((void*)test_paths[9].file_name); 998 free((void*)test_paths[30].file_name); 999#endif 1000} 1001 1002static void test_GetVolumePathNameW(void) 1003{ 1004 WCHAR volume_path[MAX_PATH]; 1005 BOOL ret; 1006 1007 volume_path[0] = 0; 1008 volume_path[1] = 0x11; 1009 ret = GetVolumePathNameW( L"C:\\", volume_path, 1 ); 1010 ok(!ret, "GetVolumePathNameW test succeeded unexpectedly.\n"); 1011 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE, "GetVolumePathNameW unexpectedly returned error 0x%lx (expected 0x%x).\n", 1012 GetLastError(), ERROR_FILENAME_EXCED_RANGE); 1013 ok(volume_path[1] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n"); 1014 1015 volume_path[0] = 0; 1016 volume_path[2] = 0x11; 1017 ret = GetVolumePathNameW( L"C:\\", volume_path, 2 ); 1018 ok(!ret, "GetVolumePathNameW test succeeded unexpectedly.\n"); 1019 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE, "GetVolumePathNameW unexpectedly returned error 0x%lx (expected 0x%x).\n", 1020 GetLastError(), ERROR_FILENAME_EXCED_RANGE); 1021 ok(volume_path[2] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n"); 1022 1023 volume_path[0] = 0; 1024 volume_path[3] = 0x11; 1025 ret = GetVolumePathNameW( L"C:\\", volume_path, 3 ); 1026 ok(ret || broken(!ret) /* win2k */, "GetVolumePathNameW test failed unexpectedly.\n"); 1027 ok(!memcmp(volume_path, L"C:\\", 3) || broken(!volume_path[0]) /* XP */, 1028 "Got wrong path %s.\n", debugstr_w(volume_path)); 1029 ok(volume_path[3] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n"); 1030 1031 volume_path[0] = 0; 1032 volume_path[4] = 0x11; 1033 ret = GetVolumePathNameW( L"C:\\", volume_path, 4 ); 1034 ok(ret, "GetVolumePathNameW test failed unexpectedly.\n"); 1035 ok(!wcscmp(volume_path, L"C:\\"), "Got wrong path %s.\n", debugstr_w(volume_path)); 1036 ok(volume_path[4] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n"); 1037} 1038 1039static void test_GetVolumePathNamesForVolumeNameA(void) 1040{ 1041 BOOL ret; 1042 char volume[MAX_PATH], buffer[MAX_PATH]; 1043 DWORD len, error; 1044 1045 if (!pGetVolumePathNamesForVolumeNameA) 1046 { 1047 win_skip("required functions not found\n"); 1048 return; 1049 } 1050 1051 ret = GetVolumeNameForVolumeMountPointA( "c:\\", volume, sizeof(volume) ); 1052 ok(ret, "failed to get volume name %lu\n", GetLastError()); 1053 trace("c:\\ -> %s\n", volume); 1054 1055 SetLastError( 0xdeadbeef ); 1056 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, NULL ); 1057 error = GetLastError(); 1058 ok(!ret, "expected failure\n"); 1059 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error); 1060 1061 SetLastError( 0xdeadbeef ); 1062 ret = pGetVolumePathNamesForVolumeNameA( "", NULL, 0, NULL ); 1063 error = GetLastError(); 1064 ok(!ret, "expected failure\n"); 1065 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error); 1066 1067 SetLastError( 0xdeadbeef ); 1068 ret = pGetVolumePathNamesForVolumeNameA( volume, NULL, 0, NULL ); 1069 error = GetLastError(); 1070 ok(!ret, "expected failure\n"); 1071 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %lu\n", error); 1072 1073 SetLastError( 0xdeadbeef ); 1074 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, 0, NULL ); 1075 error = GetLastError(); 1076 ok(!ret, "expected failure\n"); 1077 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %lu\n", error); 1078 1079 memset( buffer, 0xff, sizeof(buffer) ); 1080 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), NULL ); 1081 ok(ret, "failed to get path names %lu\n", GetLastError()); 1082 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer); 1083 ok(!buffer[4], "expected double null-terminated buffer\n"); 1084 1085 len = 0; 1086 SetLastError( 0xdeadbeef ); 1087 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, &len ); 1088 error = GetLastError(); 1089 ok(!ret, "expected failure\n"); 1090 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error); 1091 1092 len = 0; 1093 SetLastError( 0xdeadbeef ); 1094 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, sizeof(buffer), &len ); 1095 error = GetLastError(); 1096 ok(!ret, "expected failure\n"); 1097 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error); 1098 1099 len = 0; 1100 SetLastError( 0xdeadbeef ); 1101 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len ); 1102 error = GetLastError(); 1103 ok(!ret, "expected failure\n"); 1104 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error); 1105 1106 len = 0; 1107 SetLastError( 0xdeadbeef ); 1108 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len ); 1109 error = GetLastError(); 1110 ok(!ret, "expected failure\n"); 1111 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error); 1112 1113 len = 0; 1114 memset( buffer, 0xff, sizeof(buffer) ); 1115 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), &len ); 1116 ok(ret, "failed to get path names %lu\n", GetLastError()); 1117 ok(len == 5 || broken(len == 2), "expected 5 got %lu\n", len); 1118 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer); 1119 ok(!buffer[4], "expected double null-terminated buffer\n"); 1120} 1121 1122static void test_GetVolumePathNamesForVolumeNameW(void) 1123{ 1124 static const WCHAR empty[] = {0}; 1125 static const WCHAR drive_c[] = {'c',':','\\',0}; 1126 static const WCHAR volume_null[] = {'\\','\\','?','\\','V','o','l','u','m','e', 1127 '{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0','0', 1128 '-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',0}; 1129 BOOL ret; 1130 WCHAR volume[MAX_PATH], buffer[MAX_PATH]; 1131 DWORD len, error; 1132 1133 if (!pGetVolumePathNamesForVolumeNameW) 1134 { 1135 win_skip("required functions not found\n"); 1136 return; 1137 } 1138 1139 ret = GetVolumeNameForVolumeMountPointW( drive_c, volume, ARRAY_SIZE(volume) ); 1140 ok(ret, "failed to get volume name %lu\n", GetLastError()); 1141 1142 SetLastError( 0xdeadbeef ); 1143 ret = pGetVolumePathNamesForVolumeNameW( empty, NULL, 0, NULL ); 1144 error = GetLastError(); 1145 ok(!ret, "expected failure\n"); 1146 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error); 1147 1148 SetLastError( 0xdeadbeef ); 1149 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, 0, NULL ); 1150 error = GetLastError(); 1151 ok(!ret, "expected failure\n"); 1152 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %lu\n", error); 1153 1154 SetLastError( 0xdeadbeef ); 1155 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, 0, NULL ); 1156 error = GetLastError(); 1157 ok(!ret, "expected failure\n"); 1158 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %lu\n", error); 1159 1160 if (0) { /* crash */ 1161 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, ARRAY_SIZE(buffer), NULL ); 1162 ok(ret, "failed to get path names %lu\n", GetLastError()); 1163 } 1164 1165 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, ARRAY_SIZE(buffer), NULL ); 1166 ok(ret, "failed to get path names %lu\n", GetLastError()); 1167 1168 len = 0; 1169 memset( buffer, 0xff, sizeof(buffer) ); 1170 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, ARRAY_SIZE(buffer), &len ); 1171 ok(ret, "failed to get path names %lu\n", GetLastError()); 1172 ok(len == 5, "expected 5 got %lu\n", len); 1173 ok(!buffer[4], "expected double null-terminated buffer\n"); 1174 1175 len = 0; 1176 volume[1] = '?'; 1177 volume[lstrlenW( volume ) - 1] = 0; 1178 SetLastError( 0xdeadbeef ); 1179 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, ARRAY_SIZE(buffer), &len ); 1180 error = GetLastError(); 1181 ok(!ret, "expected failure\n"); 1182 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %lu\n", error); 1183 1184 len = 0; 1185 volume[0] = '\\'; 1186 volume[1] = 0; 1187 SetLastError( 0xdeadbeef ); 1188 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, ARRAY_SIZE(buffer), &len ); 1189 error = GetLastError(); 1190 ok(!ret, "expected failure\n"); 1191 todo_wine ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %lu\n", error); 1192 1193 len = 0; 1194 lstrcpyW( volume, volume_null ); 1195 SetLastError( 0xdeadbeef ); 1196 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, ARRAY_SIZE(buffer), &len ); 1197 error = GetLastError(); 1198 ok(!ret, "expected failure\n"); 1199 ok(error == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND got %lu\n", error); 1200} 1201 1202static void test_dvd_read_structure(HANDLE handle) 1203{ 1204 int i; 1205 DWORD nbBytes; 1206 BOOL ret; 1207 DVD_READ_STRUCTURE dvdReadStructure; 1208 DVD_LAYER_DESCRIPTOR dvdLayerDescriptor; 1209 struct COMPLETE_DVD_LAYER_DESCRIPTOR completeDvdLayerDescriptor; 1210 DVD_COPYRIGHT_DESCRIPTOR dvdCopyrightDescriptor; 1211 struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR completeDvdManufacturerDescriptor; 1212 1213 dvdReadStructure.BlockByteOffset.QuadPart = 0; 1214 dvdReadStructure.SessionId = 0; 1215 dvdReadStructure.LayerNumber = 0; 1216 1217 1218 /* DvdPhysicalDescriptor */ 1219 dvdReadStructure.Format = 0; 1220 1221 SetLastError(0xdeadbeef); 1222 1223 /* Test whether this ioctl is supported */ 1224 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE), 1225 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL); 1226 1227 if(!ret) 1228 { 1229 skip("IOCTL_DVD_READ_STRUCTURE not supported: %lu\n", GetLastError()); 1230 return; 1231 } 1232 1233 /* Confirm there is always a header before the actual data */ 1234 ok( completeDvdLayerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdLayerDescriptor.Header.Length); 1235 ok( completeDvdLayerDescriptor.Header.Reserved[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[0]); 1236 ok( completeDvdLayerDescriptor.Header.Reserved[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[1]); 1237 1238 /* TODO: Also check completeDvdLayerDescriptor.Descriptor content (via IOCTL_SCSI_PASS_THROUGH_DIRECT ?) */ 1239 1240 /* Insufficient output buffer */ 1241 for(i=0; i<sizeof(DVD_DESCRIPTOR_HEADER); i++) 1242 { 1243 SetLastError(0xdeadbeef); 1244 1245 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE), 1246 &completeDvdLayerDescriptor, i, &nbBytes, NULL); 1247 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,"IOCTL_DVD_READ_STRUCTURE should fail with small buffer\n"); 1248 } 1249 1250 SetLastError(0xdeadbeef); 1251 1252 /* On newer version, an output buffer of sizeof(DVD_READ_STRUCTURE) size fails. 1253 I think this is to force developers to realize that there is a header before the actual content */ 1254 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE), 1255 &dvdLayerDescriptor, sizeof(DVD_LAYER_DESCRIPTOR), &nbBytes, NULL); 1256 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER) || broken(ret) /* < Win7 */, 1257 "IOCTL_DVD_READ_STRUCTURE should have failed\n"); 1258 1259 SetLastError(0xdeadbeef); 1260 1261 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, NULL, sizeof(DVD_READ_STRUCTURE), 1262 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL); 1263 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER), 1264 "IOCTL_DVD_READ_STRUCTURE should have failed\n"); 1265 1266 /* Test wrong input parameters */ 1267 for(i=0; i<sizeof(DVD_READ_STRUCTURE); i++) 1268 { 1269 SetLastError(0xdeadbeef); 1270 1271 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, i, 1272 &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL); 1273 ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER), 1274 "IOCTL_DVD_READ_STRUCTURE should have failed\n"); 1275 } 1276 1277 1278 /* DvdCopyrightDescriptor */ 1279 dvdReadStructure.Format = 1; 1280 1281 SetLastError(0xdeadbeef); 1282 1283 /* Strangely, with NULL lpOutBuffer, last error is insufficient buffer, not invalid parameter as we could expect */ 1284 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE), 1285 NULL, sizeof(DVD_COPYRIGHT_DESCRIPTOR), &nbBytes, NULL); 1286 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %lu\n", ret, GetLastError()); 1287 1288 for(i=0; i<sizeof(DVD_COPYRIGHT_DESCRIPTOR); i++) 1289 { 1290 SetLastError(0xdeadbeef); 1291 1292 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE), 1293 &dvdCopyrightDescriptor, i, &nbBytes, NULL); 1294 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %lu\n", ret, GetLastError()); 1295 } 1296 1297 1298 /* DvdManufacturerDescriptor */ 1299 dvdReadStructure.Format = 4; 1300 1301 SetLastError(0xdeadbeef); 1302 1303 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE), 1304 &completeDvdManufacturerDescriptor, sizeof(DVD_MANUFACTURER_DESCRIPTOR), &nbBytes, NULL); 1305 ok(ret || broken(GetLastError() == ERROR_NOT_READY), 1306 "IOCTL_DVD_READ_STRUCTURE (DvdManufacturerDescriptor) failed, last error = %lu\n", GetLastError()); 1307 if(!ret) 1308 return; 1309 1310 /* Confirm there is always a header before the actual data */ 1311 ok( completeDvdManufacturerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdManufacturerDescriptor.Header.Length); 1312 ok( completeDvdManufacturerDescriptor.Header.Reserved[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdManufacturerDescriptor.Header.Reserved[0]); 1313 ok( completeDvdManufacturerDescriptor.Header.Reserved[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdManufacturerDescriptor.Header.Reserved[1]); 1314 1315 SetLastError(0xdeadbeef); 1316 1317 /* Basic parameter check */ 1318 ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE), 1319 NULL, sizeof(DVD_MANUFACTURER_DESCRIPTOR), &nbBytes, NULL); 1320 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %lu\n", ret, GetLastError()); 1321} 1322 1323static void test_cdrom_ioctl(void) 1324{ 1325 char drive_letter, drive_path[] = "A:\\", drive_full_path[] = "\\\\.\\A:"; 1326 DWORD bitmask; 1327 HANDLE handle; 1328 1329 bitmask = GetLogicalDrives(); 1330 if(!bitmask) 1331 { 1332 trace("GetLogicalDrives failed : %lu\n", GetLastError()); 1333 return; 1334 } 1335 1336 for(drive_letter='A'; drive_letter<='Z'; drive_letter++) 1337 { 1338 if(!(bitmask & (1 << (drive_letter-'A') ))) 1339 continue; 1340 1341 drive_path[0] = drive_letter; 1342 if(GetDriveTypeA(drive_path) != DRIVE_CDROM) 1343 { 1344 trace("Skipping %c:, not a CDROM drive.\n", drive_letter); 1345 continue; 1346 } 1347 1348 trace("Testing with %c:\n", drive_letter); 1349 1350 drive_full_path[4] = drive_letter; 1351 handle = CreateFileA(drive_full_path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0); 1352 if(handle == INVALID_HANDLE_VALUE) 1353 { 1354 trace("Failed to open the device : %lu\n", GetLastError()); 1355 continue; 1356 } 1357 1358 /* Add your tests here */ 1359 test_dvd_read_structure(handle); 1360 1361 CloseHandle(handle); 1362 } 1363 1364} 1365 1366static void test_mounted_folder(void) 1367{ 1368 char name_buffer[200], path[MAX_PATH], volume_name[100], *p; 1369 FILE_NAME_INFORMATION *name = (FILE_NAME_INFORMATION *)name_buffer; 1370 FILE_ATTRIBUTE_TAG_INFO info; 1371 IO_STATUS_BLOCK io; 1372 BOOL ret, got_path; 1373 NTSTATUS status; 1374 HANDLE file; 1375 DWORD size; 1376#ifdef __REACTOS__ 1377 int i = 0; 1378 char sysroot[MAX_PATH] = {0}, buf[MAX_PATH] = {0}; 1379 WCHAR buf2[MAX_PATH] = {0}; 1380 1381 GetWindowsDirectoryA(sysroot, sizeof(sysroot)); 1382 for (char *p = sysroot; *p; p++) { 1383 // Lowercase everything except "C:\" 1384 if (p != sysroot) *p = (char)tolower((unsigned char)*p); 1385 } 1386#endif 1387 1388 file = CreateFileA( "C:\\", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 1389 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL ); 1390 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError()); 1391 1392 status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileAttributeTagInformation ); 1393 ok(!status, "got status %#lx\n", status); 1394 ok(!(info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) 1395 && (info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY), "got attributes %#lx\n", info.FileAttributes); 1396 ok(!info.ReparseTag, "got reparse tag %#lx\n", info.ReparseTag); 1397 1398 CloseHandle( file ); 1399 1400 file = CreateFileA( "C:\\", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 1401 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); 1402 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError()); 1403 1404 status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileAttributeTagInformation ); 1405 ok(!status, "got status %#lx\n", status); 1406 ok(!(info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) 1407 && (info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY), "got attributes %#lx\n", info.FileAttributes); 1408 ok(!info.ReparseTag, "got reparse tag %#lx\n", info.ReparseTag); 1409 1410 CloseHandle( file ); 1411 1412 ret = GetFileAttributesA( "C:\\" ); 1413 ok(!(ret & FILE_ATTRIBUTE_REPARSE_POINT) && (ret & FILE_ATTRIBUTE_DIRECTORY), "got attributes %#x\n", ret); 1414 1415 ret = CreateDirectoryA("C:\\winetest_mnt", NULL); 1416 if (!ret && GetLastError() == ERROR_ACCESS_DENIED) 1417 { 1418 skip("Not enough permissions to create a folder in the C: drive.\n"); 1419 return; 1420 } 1421 ok(ret, "got error %lu\n", GetLastError()); 1422 1423 ret = GetVolumeNameForVolumeMountPointA( "C:\\", volume_name, sizeof(volume_name) ); 1424 ok(ret, "got error %lu\n", GetLastError()); 1425 1426 ret = SetVolumeMountPointA( "C:\\winetest_mnt\\", volume_name ); 1427 if (!ret) 1428 { 1429 skip("Not enough permissions to create a mounted folder.\n"); 1430 RemoveDirectoryA( "C:\\winetest_mnt" ); 1431 return; 1432 } 1433 todo_wine ok(ret, "got error %lu\n", GetLastError()); 1434 1435 file = CreateFileA( "C:\\winetest_mnt", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 1436 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL ); 1437 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError()); 1438 1439 status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileAttributeTagInformation ); 1440 ok(!status, "got status %#lx\n", status); 1441 ok((info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) 1442 && (info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY), "got attributes %#lx\n", info.FileAttributes); 1443 ok(info.ReparseTag == IO_REPARSE_TAG_MOUNT_POINT, "got reparse tag %#lx\n", info.ReparseTag); 1444 1445 status = NtQueryInformationFile( file, &io, name, sizeof(name_buffer), FileNameInformation ); 1446 ok(!status, "got status %#lx\n", status); 1447 ok(name->FileNameLength == wcslen(L"\\winetest_mnt") * sizeof(WCHAR), "got length %lu\n", name->FileNameLength); 1448 ok(!wcsnicmp(name->FileName, L"\\winetest_mnt", wcslen(L"\\winetest_mnt")), "got name %s\n", 1449 debugstr_wn(name->FileName, name->FileNameLength / sizeof(WCHAR))); 1450 1451 CloseHandle( file ); 1452 1453 file = CreateFileA( "C:\\winetest_mnt", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 1454 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); 1455 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError()); 1456 1457 status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileAttributeTagInformation ); 1458 ok(!status, "got status %#lx\n", status); 1459 ok(!(info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) 1460 && (info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY), "got attributes %#lx\n", info.FileAttributes); 1461 ok(!info.ReparseTag, "got reparse tag %#lx\n", info.ReparseTag); 1462 1463 status = NtQueryInformationFile( file, &io, name, sizeof(name_buffer), FileNameInformation ); 1464 ok(!status, "got status %#lx\n", status); 1465 ok(name->FileNameLength == wcslen(L"\\") * sizeof(WCHAR), "got length %lu\n", name->FileNameLength); 1466 ok(!wcsnicmp(name->FileName, L"\\", wcslen(L"\\")), "got name %s\n", 1467 debugstr_wn(name->FileName, name->FileNameLength / sizeof(WCHAR))); 1468 1469 CloseHandle( file ); 1470 1471 ret = GetFileAttributesA( "C:\\winetest_mnt" ); 1472 ok(ret != INVALID_FILE_ATTRIBUTES, "got error %lu\n", GetLastError()); 1473 ok((ret & FILE_ATTRIBUTE_REPARSE_POINT) && (ret & FILE_ATTRIBUTE_DIRECTORY), "got attributes %#x\n", ret); 1474 1475#ifdef __REACTOS__ 1476 sprintf(buf, "C:\\winetest_mnt\\%s", sysroot + 3); 1477 file = CreateFileA( buf, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, 1478 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); 1479#else 1480 file = CreateFileA( "C:\\winetest_mnt\\windows", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, 1481 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); 1482#endif 1483 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError()); 1484 1485 status = NtQueryInformationFile( file, &io, name, sizeof(name_buffer), FileNameInformation ); 1486 ok(!status, "got status %#lx\n", status); 1487#ifdef __REACTOS__ 1488 /* Copy \windows (or \reactos) to buf2. */ 1489 while ((buf2[i] = (WCHAR)(unsigned char)sysroot[i+2]) != 0) i++; 1490 ok(name->FileNameLength == wcslen(buf2) * sizeof(WCHAR), "got length %lu\n", name->FileNameLength); 1491 ok(!wcsnicmp(name->FileName, buf2, wcslen(buf2)), "got name %s\n", 1492 debugstr_wn(name->FileName, name->FileNameLength / sizeof(WCHAR))); 1493#else 1494 ok(name->FileNameLength == wcslen(L"\\windows") * sizeof(WCHAR), "got length %lu\n", name->FileNameLength); 1495 ok(!wcsnicmp(name->FileName, L"\\windows", wcslen(L"\\windows")), "got name %s\n", 1496 debugstr_wn(name->FileName, name->FileNameLength / sizeof(WCHAR))); 1497#endif 1498 1499 CloseHandle( file ); 1500 1501 ret = GetVolumePathNameA( "C:\\winetest_mnt", path, sizeof(path) ); 1502 ok(ret, "got error %lu\n", GetLastError()); 1503 ok(!strcmp(path, "C:\\winetest_mnt\\"), "got %s\n", debugstr_a(path)); 1504 SetLastError(0xdeadbeef); 1505 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_mnt", path, sizeof(path) ); 1506 ok(!ret, "expected failure\n"); 1507 ok(GetLastError() == ERROR_INVALID_NAME, "wrong error %lu\n", GetLastError()); 1508 SetLastError(0xdeadbeef); 1509 ret = GetVolumeInformationA( "C:\\winetest_mnt", NULL, 0, NULL, NULL, NULL, NULL, 0 ); 1510 ok(!ret, "expected failure\n"); 1511 ok(GetLastError() == ERROR_INVALID_NAME, "wrong error %lu\n", GetLastError()); 1512 1513 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_mnt\\", path, sizeof(path) ); 1514 ok(ret, "got error %lu\n", GetLastError()); 1515 ok(!strcmp(path, volume_name), "expected %s, got %s\n", debugstr_a(volume_name), debugstr_a(path)); 1516 ret = GetVolumeInformationA( "C:\\winetest_mnt\\", NULL, 0, NULL, NULL, NULL, NULL, 0 ); 1517 ok(ret, "got error %lu\n", GetLastError()); 1518 1519#ifdef __REACTOS__ 1520 ret = GetVolumePathNameA( buf, path, sizeof(path) ); 1521#else 1522 ret = GetVolumePathNameA( "C:\\winetest_mnt\\windows", path, sizeof(path) ); 1523#endif 1524 ok(ret, "got error %lu\n", GetLastError()); 1525 ok(!strcmp(path, "C:\\winetest_mnt\\"), "got %s\n", debugstr_a(path)); 1526 SetLastError(0xdeadbeef); 1527#ifdef __REACTOS__ 1528 strcat(buf, "\\"); 1529 ret = GetVolumeNameForVolumeMountPointA( buf, path, sizeof(path) ); 1530#else 1531 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_mnt\\windows\\", path, sizeof(path) ); 1532#endif 1533 ok(!ret, "expected failure\n"); 1534 ok(GetLastError() == ERROR_NOT_A_REPARSE_POINT, "wrong error %lu\n", GetLastError()); 1535 SetLastError(0xdeadbeef); 1536#ifdef __REACTOS__ 1537 ret = GetVolumeInformationA( buf, NULL, 0, NULL, NULL, NULL, NULL, 0 ); 1538#else 1539 ret = GetVolumeInformationA( "C:\\winetest_mnt\\windows\\", NULL, 0, NULL, NULL, NULL, NULL, 0 ); 1540#endif 1541 ok(!ret, "expected failure\n"); 1542 ok(GetLastError() == ERROR_DIR_NOT_ROOT, "wrong error %lu\n", GetLastError()); 1543 1544 ret = GetVolumePathNameA( "C:\\winetest_mnt\\nonexistent\\", path, sizeof(path) ); 1545 ok(ret, "got error %lu\n", GetLastError()); 1546 ok(!strcmp(path, "C:\\winetest_mnt\\"), "got %s\n", debugstr_a(path)); 1547 SetLastError(0xdeadbeef); 1548 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_mnt\\nonexistent\\", path, sizeof(path) ); 1549 ok(!ret, "expected failure\n"); 1550 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %lu\n", GetLastError()); 1551 SetLastError(0xdeadbeef); 1552 ret = GetVolumeInformationA( "C:\\winetest_mnt\\nonexistent\\", NULL, 0, NULL, NULL, NULL, NULL, 0 ); 1553 ok(!ret, "expected failure\n"); 1554 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %lu\n", GetLastError()); 1555 1556 ret = GetVolumePathNameA( "C:\\winetest_mnt\\winetest_mnt", path, sizeof(path) ); 1557 ok(ret, "got error %lu\n", GetLastError()); 1558 ok(!strcmp(path, "C:\\winetest_mnt\\winetest_mnt\\"), "got %s\n", debugstr_a(path)); 1559 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_mnt\\winetest_mnt\\", path, sizeof(path) ); 1560 ok(ret, "got error %lu\n", GetLastError()); 1561 ok(!strcmp(path, volume_name), "expected %s, got %s\n", debugstr_a(volume_name), debugstr_a(path)); 1562 ret = GetVolumeInformationA( "C:\\winetest_mnt\\winetest_mnt\\", NULL, 0, NULL, NULL, NULL, NULL, 0 ); 1563 ok(ret, "got error %lu\n", GetLastError()); 1564 1565 ret = GetVolumePathNameA( "C:/winetest_mnt/../winetest_mnt/.", path, sizeof(path) ); 1566 ok(ret, "got error %lu\n", GetLastError()); 1567 ok(!strcmp(path, "C:\\winetest_mnt\\"), "got %s\n", debugstr_a(path)); 1568 ret = GetVolumeNameForVolumeMountPointA( "C:/winetest_mnt/../winetest_mnt/.\\", path, sizeof(path) ); 1569 ok(ret, "got error %lu\n", GetLastError()); 1570 ok(!strcmp(path, volume_name), "expected %s, got %s\n", debugstr_a(volume_name), debugstr_a(path)); 1571 ret = GetVolumeInformationA( "C:/winetest_mnt/../winetest_mnt/.\\", NULL, 0, NULL, NULL, NULL, NULL, 0 ); 1572 ok(ret, "got error %lu\n", GetLastError()); 1573 1574 ret = GetVolumePathNamesForVolumeNameA( volume_name, path, sizeof(path), &size ); 1575 ok(ret, "got error %lu\n", GetLastError()); 1576 got_path = FALSE; 1577 for (p = path; *p; p += strlen(p) + 1) 1578 { 1579 if (!strcmp( p, "C:\\winetest_mnt\\" )) 1580 got_path = TRUE; 1581 ok(strcmp( p, "C:\\winetest_mnt\\winetest_mnt\\" ), "GetVolumePathNamesForVolumeName() should not recurse\n"); 1582 } 1583 ok(got_path, "mount point was not enumerated\n"); 1584 1585 /* test interaction with symbolic links */ 1586 1587 if (pCreateSymbolicLinkA) 1588 { 1589 ret = pCreateSymbolicLinkA( "C:\\winetest_link", "C:\\winetest_mnt\\", SYMBOLIC_LINK_FLAG_DIRECTORY ); 1590 ok(ret, "got error %lu\n", GetLastError()); 1591 1592 ret = GetVolumePathNameA( "C:\\winetest_link\\", path, sizeof(path) ); 1593 ok(ret, "got error %lu\n", GetLastError()); 1594 ok(!strcmp(path, "C:\\"), "got %s\n", path); 1595 SetLastError(0xdeadbeef); 1596 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_link\\", path, sizeof(path) ); 1597 ok(!ret, "expected failure\n"); 1598 ok(GetLastError() == ERROR_INVALID_PARAMETER 1599 || broken(GetLastError() == ERROR_SUCCESS) /* 2008 */, "wrong error %lu\n", GetLastError()); 1600 ret = GetVolumeInformationA( "C:\\winetest_link\\", NULL, 0, NULL, NULL, NULL, NULL, 0 ); 1601 ok(ret, "got error %lu\n", GetLastError()); 1602 1603#ifdef __REACTOS__ 1604 sprintf(buf, "C:\\winetest_link\\%s", sysroot + 3); 1605 ret = GetVolumePathNameA( buf, path, sizeof(path) ); 1606#else 1607 ret = GetVolumePathNameA( "C:\\winetest_link\\windows\\", path, sizeof(path) ); 1608#endif 1609 ok(ret, "got error %lu\n", GetLastError()); 1610 ok(!strcmp(path, "C:\\"), "got %s\n", path); 1611 SetLastError(0xdeadbeef); 1612#ifdef __REACTOS__ 1613 ret = GetVolumeNameForVolumeMountPointA( buf, path, sizeof(path) ); 1614#else 1615 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_link\\windows\\", path, sizeof(path) ); 1616#endif 1617 ok(!ret, "expected failure\n"); 1618 ok(GetLastError() == ERROR_NOT_A_REPARSE_POINT, "wrong error %lu\n", GetLastError()); 1619 SetLastError(0xdeadbeef); 1620#ifdef __REACTOS__ 1621 ret = GetVolumeInformationA( buf, NULL, 0, NULL, NULL, NULL, NULL, 0 ); 1622#else 1623 ret = GetVolumeInformationA( "C:\\winetest_link\\windows\\", NULL, 0, NULL, NULL, NULL, NULL, 0 ); 1624#endif 1625 ok(!ret, "expected failure\n"); 1626 ok(GetLastError() == ERROR_DIR_NOT_ROOT, "wrong error %lu\n", GetLastError()); 1627 1628 ret = GetVolumePathNameA( "C:\\winetest_link\\winetest_mnt", path, sizeof(path) ); 1629 ok(ret, "got error %lu\n", GetLastError()); 1630 ok(!strcmp(path, "C:\\winetest_link\\winetest_mnt\\"), "got %s\n", debugstr_a(path)); 1631 ret = GetVolumeNameForVolumeMountPointA( "C:\\winetest_link\\winetest_mnt\\", path, sizeof(path) ); 1632 ok(ret, "got error %lu\n", GetLastError()); 1633 ok(!strcmp(path, volume_name), "expected %s, got %s\n", debugstr_a(volume_name), debugstr_a(path)); 1634 ret = GetVolumeInformationA( "C:\\winetest_link\\winetest_mnt\\", NULL, 0, NULL, NULL, NULL, NULL, 0 ); 1635 ok(ret, "got error %lu\n", GetLastError()); 1636 1637 /* The following test makes it clear that when we encounter a symlink 1638 * while resolving, we resolve *every* junction in the path, i.e. both 1639 * mount points and symlinks. */ 1640#ifdef __REACTOS__ 1641 sprintf(buf, "C:\\winetest_link\\winetest_mnt\\winetest_link\\%s\\", sysroot + 3); 1642 ret = GetVolumePathNameA( buf, path, sizeof(path) ); 1643#else 1644 ret = GetVolumePathNameA( "C:\\winetest_link\\winetest_mnt\\winetest_link\\windows\\", path, sizeof(path) ); 1645#endif 1646 ok(ret, "got error %lu\n", GetLastError()); 1647 ok(!strcmp(path, "C:\\") || !strcmp(path, "C:\\winetest_link\\winetest_mnt\\") /* 2008 */, 1648 "got %s\n", debugstr_a(path)); 1649 1650#ifdef __REACTOS__ 1651 file = CreateFileA( buf, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); 1652#else 1653 file = CreateFileA( "C:\\winetest_link\\winetest_mnt\\winetest_link\\windows\\", 0, 1654 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); 1655#endif 1656 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError()); 1657 1658 status = NtQueryInformationFile( file, &io, name, sizeof(name_buffer), FileNameInformation ); 1659 ok(!status, "got status %#lx\n", status); 1660#ifdef __REACTOS__ 1661 ok(name->FileNameLength == wcslen(buf2) * sizeof(WCHAR), "got length %lu\n", name->FileNameLength); 1662 ok(!wcsnicmp(name->FileName, buf2, wcslen(buf2)), "got name %s\n", 1663 debugstr_wn(name->FileName, name->FileNameLength / sizeof(WCHAR))); 1664#else 1665 ok(name->FileNameLength == wcslen(L"\\windows") * sizeof(WCHAR), "got length %lu\n", name->FileNameLength); 1666 ok(!wcsnicmp(name->FileName, L"\\windows", wcslen(L"\\windows")), "got name %s\n", 1667 debugstr_wn(name->FileName, name->FileNameLength / sizeof(WCHAR))); 1668#endif 1669 1670 CloseHandle( file ); 1671 1672 ret = RemoveDirectoryA( "C:\\winetest_link\\" ); 1673 ok(ret, "got error %lu\n", GetLastError()); 1674 1675 /* The following cannot be automatically tested: 1676 * 1677 * Suppose C: and D: are mount points of different volumes. If C:/a is 1678 * symlinked to D:/b, GetVolumePathName("C:\\a") will return "D:\\" if 1679 * "a" is a directory, but "C:\\" if "a" is a file. 1680 * Moreover, if D: is mounted at C:/mnt, and C:/a is symlinked to 1681 * C:/mnt, GetVolumePathName("C:\\mnt\\b") will still return "D:\\". */ 1682 } 1683 1684 ret = DeleteVolumeMountPointA( "C:\\winetest_mnt\\" ); 1685 ok(ret, "got error %lu\n", GetLastError()); 1686 ret = RemoveDirectoryA( "C:\\winetest_mnt" ); 1687 ok(ret, "got error %lu\n", GetLastError()); 1688} 1689 1690static void test_GetVolumeInformationByHandle(void) 1691{ 1692 char DECLSPEC_ALIGN(8) buffer[50]; 1693 FILE_FS_ATTRIBUTE_INFORMATION *attr_info = (void *)buffer; 1694 FILE_FS_VOLUME_INFORMATION *volume_info = (void *)buffer; 1695 DWORD serial, filename_len, flags; 1696 WCHAR label[20], fsname[20]; 1697 char volume[MAX_PATH+1]; 1698 IO_STATUS_BLOCK io; 1699 HANDLE file; 1700 NTSTATUS status; 1701 BOOL ret; 1702#ifdef __REACTOS__ 1703 char sysroot[MAX_PATH]; 1704 1705 GetWindowsDirectoryA(sysroot, sizeof(sysroot)); 1706 for (char *p = sysroot; *p; p++) { 1707 if (*p == '\\') *p = '/'; // Use forward slashes 1708 else if (p != sysroot) *p = (char)tolower((unsigned char)*p); // Lowercase everything except "C:\" 1709 } 1710#endif 1711 1712#if defined(__REACTOS__) && DLL_EXPORT_VERSION >= 0x600 1713 /* FIXME: GetVolumeInformationByHandleW is a STUB on ReactOS! */ 1714 if (is_reactos() || !pGetVolumeInformationByHandleW) 1715#else 1716 if (!pGetVolumeInformationByHandleW) 1717#endif 1718 { 1719 win_skip("GetVolumeInformationByHandleW is not present.\n"); 1720 return; 1721 } 1722 1723#ifdef __REACTOS__ 1724 file = CreateFileA( sysroot, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 1725 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); 1726#else 1727 file = CreateFileA( "C:/windows", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 1728 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); 1729#endif 1730 ok(file != INVALID_HANDLE_VALUE, "failed to open file, error %lu\n", GetLastError()); 1731 1732 SetLastError(0xdeadbeef); 1733 ret = pGetVolumeInformationByHandleW( INVALID_HANDLE_VALUE, label, ARRAY_SIZE(label), &serial, 1734 &filename_len, &flags, fsname, ARRAY_SIZE(fsname) ); 1735 ok(!ret, "expected failure\n"); 1736 ok(GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError()); 1737 1738 ret = pGetVolumeInformationByHandleW( file, NULL, 0, NULL, NULL, NULL, NULL, 0 ); 1739 ok(ret, "got error %lu\n", GetLastError()); 1740 1741 ret = pGetVolumeInformationByHandleW( file, label, ARRAY_SIZE(label), &serial, 1742 &filename_len, &flags, fsname, ARRAY_SIZE(fsname) ); 1743 ok(ret, "got error %lu\n", GetLastError()); 1744 1745 memset(buffer, 0, sizeof(buffer)); 1746 status = NtQueryVolumeInformationFile( file, &io, buffer, sizeof(buffer), FileFsAttributeInformation ); 1747 ok(!status, "got status %#lx\n", status); 1748 ok(flags == attr_info->FileSystemAttributes, "expected flags %#lx, got %#lx\n", 1749 attr_info->FileSystemAttributes, flags); 1750 ok(filename_len == attr_info->MaximumComponentNameLength, "expected filename_len %lu, got %lu\n", 1751 attr_info->MaximumComponentNameLength, filename_len); 1752 ok(!wcscmp( fsname, attr_info->FileSystemName ), "expected fsname %s, got %s\n", 1753 debugstr_w( attr_info->FileSystemName ), debugstr_w( fsname )); 1754 ok(wcslen( fsname ) == attr_info->FileSystemNameLength / sizeof(WCHAR), "got %Iu\n", wcslen( fsname )); 1755 1756 SetLastError(0xdeadbeef); 1757 ret = pGetVolumeInformationByHandleW( file, NULL, 0, NULL, &filename_len, &flags, fsname, 2 ); 1758 ok(!ret, "expected failure\n"); 1759 ok(GetLastError() == ERROR_BAD_LENGTH, "got error %lu\n", GetLastError()); 1760 1761 memset(buffer, 0, sizeof(buffer)); 1762 status = NtQueryVolumeInformationFile( file, &io, buffer, sizeof(buffer), FileFsVolumeInformation ); 1763 ok(!status, "got status %#lx\n", status); 1764 ok(serial == volume_info->VolumeSerialNumber, "expected serial %08lx, got %08lx\n", 1765 volume_info->VolumeSerialNumber, serial); 1766 ok(!wcscmp( label, volume_info->VolumeLabel ), "expected label %s, got %s\n", 1767 debugstr_w( volume_info->VolumeLabel ), debugstr_w( label )); 1768 ok(wcslen( label ) == volume_info->VolumeLabelLength / sizeof(WCHAR), "got %Iu\n", wcslen( label )); 1769 1770 CloseHandle( file ); 1771 1772 /* get the unique volume name for the windows drive */ 1773 ret = GetVolumeNameForVolumeMountPointA("C:\\", volume, MAX_PATH); 1774 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n"); 1775 1776 /* try again with unique volume name */ 1777 1778 file = CreateFileA( volume, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 1779 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); 1780 ok(file != INVALID_HANDLE_VALUE, "failed to open file, error %lu\n", GetLastError()); 1781 1782 ret = pGetVolumeInformationByHandleW( file, label, ARRAY_SIZE(label), &serial, 1783 &filename_len, &flags, fsname, ARRAY_SIZE(fsname) ); 1784 ok(ret, "got error %lu\n", GetLastError()); 1785 1786 memset(buffer, 0, sizeof(buffer)); 1787 status = NtQueryVolumeInformationFile( file, &io, buffer, sizeof(buffer), FileFsVolumeInformation ); 1788 ok(!status, "got status %#lx\n", status); 1789 ok(serial == volume_info->VolumeSerialNumber, "expected serial %08lx, got %08lx\n", 1790 volume_info->VolumeSerialNumber, serial); 1791 ok(!wcscmp( label, volume_info->VolumeLabel ), "expected label %s, got %s\n", 1792 debugstr_w( volume_info->VolumeLabel ), debugstr_w( label )); 1793 ok(wcslen( label ) == volume_info->VolumeLabelLength / sizeof(WCHAR), "got %Iu\n", wcslen( label )); 1794 1795 memset(buffer, 0, sizeof(buffer)); 1796 status = NtQueryVolumeInformationFile( file, &io, buffer, sizeof(buffer), FileFsAttributeInformation ); 1797 ok(!status, "got status %#lx\n", status); 1798 ok(flags == attr_info->FileSystemAttributes, "expected flags %#lx, got %#lx\n", 1799 attr_info->FileSystemAttributes, flags); 1800 ok(filename_len == attr_info->MaximumComponentNameLength, "expected filename_len %lu, got %lu\n", 1801 attr_info->MaximumComponentNameLength, filename_len); 1802 ok(!wcscmp( fsname, attr_info->FileSystemName ), "expected fsname %s, got %s\n", 1803 debugstr_w( attr_info->FileSystemName ), debugstr_w( fsname )); 1804 ok(wcslen( fsname ) == attr_info->FileSystemNameLength / sizeof(WCHAR), "got %Iu\n", wcslen( fsname )); 1805 1806 CloseHandle( file ); 1807} 1808 1809static void test_mountmgr_query_points(void) 1810{ 1811 char input_buffer[64]; 1812 MOUNTMGR_MOUNT_POINTS *output; 1813 MOUNTMGR_MOUNT_POINT *input = (MOUNTMGR_MOUNT_POINT *)input_buffer; 1814 IO_STATUS_BLOCK io; 1815 NTSTATUS status; 1816 HANDLE file; 1817 1818 output = malloc(1024); 1819 1820 file = CreateFileW( MOUNTMGR_DOS_DEVICE_NAME, 0, 0, NULL, OPEN_EXISTING, 0, NULL ); 1821 ok(file != INVALID_HANDLE_VALUE, "failed to open mountmgr, error %lu\n", GetLastError()); 1822 1823 io.Status = 0xdeadf00d; 1824 io.Information = 0xdeadf00d; 1825 status = NtDeviceIoControlFile( file, NULL, NULL, NULL, &io, 1826 IOCTL_MOUNTMGR_QUERY_POINTS, NULL, 0, NULL, 0 ); 1827 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status); 1828 ok(io.Status == 0xdeadf00d, "got status %#lx\n", io.Status); 1829 ok(io.Information == 0xdeadf00d, "got information %#Ix\n", io.Information); 1830 1831 memset( input, 0, sizeof(*input) ); 1832 1833 io.Status = 0xdeadf00d; 1834 io.Information = 0xdeadf00d; 1835 status = NtDeviceIoControlFile( file, NULL, NULL, NULL, &io, 1836 IOCTL_MOUNTMGR_QUERY_POINTS, input, sizeof(*input) - 1, NULL, 0 ); 1837 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status); 1838 ok(io.Status == 0xdeadf00d, "got status %#lx\n", io.Status); 1839 ok(io.Information == 0xdeadf00d, "got information %#Ix\n", io.Information); 1840 1841 io.Status = 0xdeadf00d; 1842 io.Information = 0xdeadf00d; 1843 status = NtDeviceIoControlFile( file, NULL, NULL, NULL, &io, 1844 IOCTL_MOUNTMGR_QUERY_POINTS, input, sizeof(*input), NULL, 0 ); 1845 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status); 1846 ok(io.Status == 0xdeadf00d, "got status %#lx\n", io.Status); 1847 ok(io.Information == 0xdeadf00d, "got information %#Ix\n", io.Information); 1848 1849 io.Status = 0xdeadf00d; 1850 io.Information = 0xdeadf00d; 1851 memset(output, 0xcc, sizeof(*output)); 1852 status = NtDeviceIoControlFile( file, NULL, NULL, NULL, &io, 1853 IOCTL_MOUNTMGR_QUERY_POINTS, input, sizeof(*input), output, sizeof(*output) - 1 ); 1854 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status); 1855 ok(io.Status == 0xdeadf00d, "got status %#lx\n", io.Status); 1856 ok(io.Information == 0xdeadf00d, "got information %#Ix\n", io.Information); 1857 ok(output->Size == 0xcccccccc, "got size %lu\n", output->Size); 1858 ok(output->NumberOfMountPoints == 0xcccccccc, "got count %lu\n", output->NumberOfMountPoints); 1859 1860 io.Status = 0xdeadf00d; 1861 io.Information = 0xdeadf00d; 1862 memset(output, 0xcc, sizeof(*output)); 1863 status = NtDeviceIoControlFile( file, NULL, NULL, NULL, &io, 1864 IOCTL_MOUNTMGR_QUERY_POINTS, input, sizeof(*input), output, sizeof(*output) ); 1865 ok(status == STATUS_BUFFER_OVERFLOW, "got %#lx\n", status); 1866 ok(io.Status == STATUS_BUFFER_OVERFLOW, "got status %#lx\n", io.Status); 1867#ifdef __REACTOS__ 1868 todo_wine ok(io.Information == offsetof(MOUNTMGR_MOUNT_POINTS, MountPoints[0]) || broken(io.Information == sizeof(MOUNTMGR_MOUNT_POINTS)) /* WS03 */, "got information %#Ix\n", io.Information); 1869#else 1870 todo_wine ok(io.Information == offsetof(MOUNTMGR_MOUNT_POINTS, MountPoints[0]), "got information %#Ix\n", io.Information); 1871#endif 1872 ok(output->Size > offsetof(MOUNTMGR_MOUNT_POINTS, MountPoints[0]), "got size %lu\n", output->Size); 1873 todo_wine ok(output->NumberOfMountPoints && output->NumberOfMountPoints != 0xcccccccc, 1874 "got count %lu\n", output->NumberOfMountPoints); 1875 1876 output = realloc(output, output->Size); 1877 1878 io.Status = 0xdeadf00d; 1879 io.Information = 0xdeadf00d; 1880 status = NtDeviceIoControlFile( file, NULL, NULL, NULL, &io, 1881 IOCTL_MOUNTMGR_QUERY_POINTS, input, sizeof(*input), output, output->Size ); 1882 ok(!status, "got %#lx\n", status); 1883 ok(!io.Status, "got status %#lx\n", io.Status); 1884 ok(io.Information == output->Size, "got size %lu, information %#Ix\n", output->Size, io.Information); 1885 ok(output->Size > offsetof(MOUNTMGR_MOUNT_POINTS, MountPoints[0]), "got size %lu\n", output->Size); 1886 ok(output->NumberOfMountPoints && output->NumberOfMountPoints != 0xcccccccc, 1887 "got count %lu\n", output->NumberOfMountPoints); 1888 1889 CloseHandle( file ); 1890 1891 free(output); 1892} 1893 1894START_TEST(volume) 1895{ 1896 hdll = GetModuleHandleA("kernel32.dll"); 1897 pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA"); 1898 pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA"); 1899 pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose"); 1900 pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA"); 1901 pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW"); 1902 pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA"); 1903 pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW"); 1904 pCreateSymbolicLinkA = (void *) GetProcAddress(hdll, "CreateSymbolicLinkA"); 1905 pGetVolumeInformationByHandleW = (void *) GetProcAddress(hdll, "GetVolumeInformationByHandleW"); 1906 1907 test_query_dos_deviceA(); 1908 test_dos_devices(); 1909 test_FindFirstVolume(); 1910 test_GetVolumePathNameA(); 1911 test_GetVolumePathNameW(); 1912 test_GetVolumeNameForVolumeMountPointA(); 1913 test_GetVolumeNameForVolumeMountPointW(); 1914 test_GetLogicalDriveStringsA(); 1915 test_GetLogicalDriveStringsW(); 1916 test_GetVolumeInformationA(); 1917 test_enum_vols(); 1918 test_disk_extents(); 1919 test_disk_query_property(); 1920 test_GetVolumePathNamesForVolumeNameA(); 1921 test_GetVolumePathNamesForVolumeNameW(); 1922 test_cdrom_ioctl(); 1923 test_mounted_folder(); 1924 test_GetVolumeInformationByHandle(); 1925 test_mountmgr_query_points(); 1926}