Changeset 30365 in vbox for trunk/src/VBox/Runtime/r3/win
- Timestamp:
- Jun 22, 2010 12:08:20 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 62957
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/fs-win.cpp
r30279 r30365 334 334 } 335 335 336 RTR3DECL(int) RTFsQueryType(const char *pszFsPath, uint32_t *pu32Type) 337 { 338 int rc = VINF_SUCCESS; 339 340 *pu32Type = RTFS_FS_TYPE_UNKNOWN; 341 342 HANDLE hFile = CreateFile(pszFsPath, 343 GENERIC_READ, 344 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 345 NULL, 346 OPEN_EXISTING, 347 FILE_FLAG_BACKUP_SEMANTICS, 348 NULL); 349 if (hFile != INVALID_HANDLE_VALUE) 350 { 351 char abBuf[8192]; 352 IO_STATUS_BLOCK Ios; 353 NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, 354 abBuf, sizeof(abBuf), 355 FileFsAttributeInformation); 356 if (rcNt >= 0) 357 { 358 PFILE_FS_ATTRIBUTE_INFORMATION pFsAttrInfo = (PFILE_FS_ATTRIBUTE_INFORMATION)abBuf; 359 if ( pFsAttrInfo->FileSystemName[0] == 'N' 360 && pFsAttrInfo->FileSystemName[1] == 'T' 361 && pFsAttrInfo->FileSystemName[2] == 'F' 362 && pFsAttrInfo->FileSystemName[3] == 'S' 363 && pFsAttrInfo->FileSystemName[4] == '\0') 364 *pu32Type = RTFS_FS_TYPE_NTFS; 365 else if ( pFsAttrInfo->FileSystemName[0] == 'F' 366 && pFsAttrInfo->FileSystemName[1] == 'A' 367 && pFsAttrInfo->FileSystemName[2] == 'T' 368 && ( ( pFsAttrInfo->FileSystemName[3] == '3' 369 && pFsAttrInfo->FileSystemName[4] == '2' 370 && pFsAttrInfo->FileSystemName[5] == '\0') 371 || pFsAttrInfo->FileSystemName[3] == '\0')) 372 /* This is either FAT32 or FAT12/16. IMO it doesn't make 373 * sense to distinguish more detailed because we cannot 374 * easily distinguish between these FAT types on Linux 375 * and users who put some image file on an FAT16 partition 376 * should know what they are doing. */ 377 *pu32Type = RTFS_FS_TYPE_FAT; 336 337 /** 338 * Internal helper for comparing a WCHAR string with a char string. 339 * 340 * @returns 0 if equal, -1 if @a psz1 < @a psz2, 1 if @a psz1 < @a psz2. 341 * @param pwsz1 The first string. 342 * @param psz2 The second string. 343 */ 344 static int rtFsWinCmpUtf16(WCHAR const *pwsz1, const char *psz2) 345 { 346 for (;;) 347 { 348 unsigned ch1 = *pwsz1++; 349 unsigned ch2 = (unsigned char)*psz2++; 350 if (ch1 != ch2) 351 return ch1 < ch2 ? -1 : 1; 352 if (!ch1) 353 return 0; 354 } 355 } 356 357 358 RTR3DECL(int) RTFsQueryType(const char *pszFsPath, PRTFSTYPE penmType) 359 { 360 *penmType = RTFSTYPE_UNKNOWN; 361 362 AssertPtrReturn(pszFsPath, VERR_INVALID_POINTER); 363 AssertReturn(*pszFsPath, VERR_INVALID_PARAMETER); 364 365 /* 366 * Convert the path and try open it. 367 */ 368 PRTUTF16 pwszFsPath; 369 int rc = RTStrToUtf16(pszFsPath, &pwszFsPath); 370 if (RT_SUCCESS(rc)) 371 { 372 HANDLE hFile = CreateFileW(pwszFsPath, 373 GENERIC_READ, 374 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 375 NULL, 376 OPEN_EXISTING, 377 FILE_FLAG_BACKUP_SEMANTICS, 378 NULL); 379 if (hFile != INVALID_HANDLE_VALUE) 380 { 381 /* 382 * Use the NT api directly to get the file system name. 383 */ 384 char abBuf[8192]; 385 IO_STATUS_BLOCK Ios; 386 NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, 387 abBuf, sizeof(abBuf), 388 FileFsAttributeInformation); 389 if (rcNt >= 0) 390 { 391 PFILE_FS_ATTRIBUTE_INFORMATION pFsAttrInfo = (PFILE_FS_ATTRIBUTE_INFORMATION)abBuf; 392 393 if (!rtFsWinCmpUtf16(pFsAttrInfo->FileSystemName, "NTFS")) 394 *penmType = RTFSTYPE_NTFS; 395 else if (!rtFsWinCmpUtf16(pFsAttrInfo->FileSystemName, "FAT")) 396 *penmType = RTFSTYPE_FAT; 397 else if (!rtFsWinCmpUtf16(pFsAttrInfo->FileSystemName, "FAT32")) 398 *penmType = RTFSTYPE_FAT; 399 else if (!rtFsWinCmpUtf16(pFsAttrInfo->FileSystemName, "VBoxSharedFolderFS")) 400 *penmType = RTFSTYPE_VBOXSHF; 401 } 402 else 403 rc = RTErrConvertFromNtStatus(rcNt); 404 CloseHandle(hFile); 378 405 } 379 /* else: Is RTFS_FS_UNKNOWN suffient or should we return an error? */380 CloseHandle(hFile);381 }382 406 else 407 rc = RTErrConvertFromWin32(GetLastError()); 408 RTUtf16Free(pwszFsPath); 409 } 383 410 return rc; 384 411 }
Note:
See TracChangeset
for help on using the changeset viewer.