Changeset 8397 for trunk/src/kernel32/disk.cpp
- Timestamp:
- May 9, 2002, 3:55:35 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/disk.cpp
r8392 r8397 1 /* $Id: disk.cpp,v 1.3 4 2002-05-08 15:02:58sandervl Exp $ */1 /* $Id: disk.cpp,v 1.35 2002-05-09 13:55:33 sandervl Exp $ */ 2 2 3 3 /* … … 17 17 18 18 #include <os2win.h> 19 #include <stdio.h> 19 20 #include <stdlib.h> 20 21 #include <string.h> 22 #include <versionos2.h> 21 23 #include "unicode.h" 22 24 #include "oslibdos.h" 25 #include "osliblvm.h" 23 26 #include "exceptutil.h" 24 27 #include "profile.h" 28 #include "hmdisk.h" 25 29 26 30 #define DBG_LOCALLOG DBG_disk … … 29 33 30 34 ODINDEBUGCHANNEL(KERNEL32-DISK) 35 31 36 32 37 //****************************************************************************** … … 225 230 } 226 231 else { 232 //Volume functions only available in Windows 2000 and up 233 if(VERSION_IS_WIN2000_OR_HIGHER() && !strncmp(lpszDrive, VOLUME_NAME_PREFIX, sizeof(VOLUME_NAME_PREFIX)-1)) 234 { 235 char *pszVolume; 236 int length; 237 238 //strip volume name prefix (\\\\?\\Volume\\) 239 length = strlen(lpszDrive); 240 pszVolume = (char *)alloca(length); 241 242 strcpy(pszVolume, &lpszDrive[sizeof(VOLUME_NAME_PREFIX)-1+1]); //-zero term + starting '{' 243 length -= sizeof(VOLUME_NAME_PREFIX)-1+1; 244 if(pszVolume[length-2] == '}') { 245 pszVolume[length-2] = 0; 246 rc = OSLibLVMGetDriveType(pszVolume); 247 dprintf(("KERNEL32: GetDriveType %s = %d (LVM)", lpszDrive, rc)); 248 return rc; 249 } 250 } 227 251 return DRIVE_NO_ROOT_DIR; //return value checked in NT4, SP6 (GetDriveType(""), GetDriveType("4"); 228 252 } … … 263 287 CHAR szOrgFileSystemName[256] = ""; 264 288 ULONG drive; 265 BOOL rc; 289 BOOL rc, fVolumeName = FALSE; 290 char *pszVolume; 266 291 267 292 dprintf(("GetVolumeInformationA %s", lpRootPathName)); … … 280 305 } 281 306 else { 307 //Volume functions only available in Windows 2000 and up 308 if(LOBYTE(GetVersion()) >= 5 && !strncmp(lpRootPathName, VOLUME_NAME_PREFIX, sizeof(VOLUME_NAME_PREFIX)-1)) 309 { 310 int length; 311 312 //strip volume name prefix (\\\\?\\Volume\\) 313 length = strlen(lpRootPathName); 314 pszVolume = (char *)alloca(length); 315 316 strcpy(pszVolume, &lpRootPathName[sizeof(VOLUME_NAME_PREFIX)-1]); 317 length -= sizeof(VOLUME_NAME_PREFIX)-1; 318 if(pszVolume[length-1] == '}') { 319 fVolumeName = TRUE; 320 goto proceed; 321 } 322 } 282 323 SetLastError(ERROR_INVALID_PARAMETER); 283 324 return FALSE; 284 325 } 326 proceed: 285 327 286 328 if(lpVolumeSerialNumber || lpVolumeNameBuffer) { 287 rc = OSLibDosQueryVolumeSerialAndName(drive, lpVolumeSerialNumber, lpVolumeNameBuffer, nVolumeNameSize); 329 if(fVolumeName) { 330 rc = OSLibLVMQueryVolumeSerialAndName(pszVolume, lpVolumeSerialNumber, lpVolumeNameBuffer, nVolumeNameSize); 331 } 332 else rc = OSLibDosQueryVolumeSerialAndName(drive, lpVolumeSerialNumber, lpVolumeNameBuffer, nVolumeNameSize); 288 333 if(lpVolumeSerialNumber) { 289 334 dprintf2(("Volume serial number: %x", *lpVolumeSerialNumber)); … … 299 344 nFileSystemNameSize = sizeof(tmpstring); 300 345 } 301 rc = OSLibDosQueryVolumeFS(drive, lpFileSystemNameBuffer, nFileSystemNameSize); 346 if(fVolumeName) { 347 rc = OSLibLVMQueryVolumeFS(pszVolume, lpFileSystemNameBuffer, nFileSystemNameSize); 348 } 349 else rc = OSLibDosQueryVolumeFS(drive, lpFileSystemNameBuffer, nFileSystemNameSize); 350 302 351 //save original file system name 303 352 if(rc == ERROR_SUCCESS) strcpy(szOrgFileSystemName, lpFileSystemNameBuffer); … … 435 484 } 436 485 //****************************************************************************** 486 typedef struct { 487 HANDLE hLVMVolumeControlData; 488 DWORD lastvol; 489 } VOLINFO; 437 490 //****************************************************************************** 438 491 HANDLE WIN32API FindFirstVolumeA(LPTSTR lpszVolumeName, DWORD cchBufferLength) 439 492 { 493 HANDLE hVolume; 494 VOLINFO *pVolInfo; 495 char szdrive[3]; 496 char szVolume[256]; 497 498 if(!VERSION_IS_WIN2000_OR_HIGHER()) { 499 SetLastError(ERROR_NOT_SUPPORTED); 500 return FALSE; 501 } 502 503 hVolume = GlobalAlloc(0, sizeof(VOLINFO)); 504 if(hVolume == 0) { 505 dprintf(("ERROR: FindFirstVolumeA: out of memory!!")); 506 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 507 return 0; 508 } 509 pVolInfo = (VOLINFO *)GlobalLock(hVolume); 510 pVolInfo->hLVMVolumeControlData = OSLibLVMQueryVolumeControlData(); 511 pVolInfo->lastvol = 0; 512 513 if(OSLibLVMQueryVolumeName(pVolInfo->hLVMVolumeControlData, pVolInfo->lastvol, szVolume, sizeof(szVolume)) == FALSE) { 514 SetLastError(ERROR_NO_MORE_FILES); 515 goto fail; 516 } 517 if(strlen(szVolume) + 14 + 1 > cchBufferLength) { 518 SetLastError(ERROR_INSUFFICIENT_BUFFER); 519 goto fail; 520 } 521 sprintf(lpszVolumeName, VOLUME_NAME_PREFIX"{%s}\\", szVolume); 522 dprintf(("FindFirstVolumeA returned %s", lpszVolumeName)); 523 pVolInfo->lastvol++; 524 GlobalUnlock(hVolume); 525 SetLastError(ERROR_SUCCESS); 526 return hVolume; 527 528 fail: 529 GlobalUnlock(hVolume); 530 GlobalFree(hVolume); 440 531 return 0; 441 532 } … … 444 535 HANDLE WIN32API FindFirstVolumeW(LPWSTR lpszVolumeName, DWORD cchBufferLength) 445 536 { 446 return 0; 537 LPSTR pszvolname = NULL; 538 HANDLE hVolume; 539 540 if(!VERSION_IS_WIN2000_OR_HIGHER()) { 541 SetLastError(ERROR_NOT_SUPPORTED); 542 return FALSE; 543 } 544 545 if(cchBufferLength) { 546 pszvolname = (char *)alloca(cchBufferLength); 547 } 548 hVolume = FindFirstVolumeA(pszvolname, cchBufferLength); 549 if(hVolume) { 550 int len = MultiByteToWideChar( CP_ACP, 0, pszvolname, -1, NULL, 0); 551 MultiByteToWideChar(CP_ACP, 0, pszvolname, -1, lpszVolumeName, len); 552 } 553 return hVolume; 447 554 } 448 555 //****************************************************************************** … … 451 558 DWORD cchBufferLength) 452 559 { 453 return FALSE; 560 VOLINFO *pVolInfo; 561 char szdrive[3]; 562 DWORD DeviceType; 563 char szVolume[256]; 564 565 if(!VERSION_IS_WIN2000_OR_HIGHER()) { 566 SetLastError(ERROR_NOT_SUPPORTED); 567 return FALSE; 568 } 569 570 pVolInfo = (VOLINFO *)GlobalLock(hFindVolume); 571 if(pVolInfo == NULL) { 572 SetLastError(ERROR_INVALID_PARAMETER); 573 return FALSE; 574 } 575 if(OSLibLVMQueryVolumeName(pVolInfo->hLVMVolumeControlData, pVolInfo->lastvol, 576 szVolume, sizeof(szVolume)) == FALSE) { 577 SetLastError(ERROR_NO_MORE_FILES); 578 GlobalUnlock(hFindVolume); 579 return FALSE; 580 } 581 if(strlen(szVolume) + 14 + 1 > cchBufferLength) { 582 SetLastError(ERROR_INSUFFICIENT_BUFFER); 583 GlobalUnlock(hFindVolume); 584 return FALSE; 585 } 586 sprintf(lpszVolumeName, VOLUME_NAME_PREFIX"{%s}\\", szVolume); 587 dprintf(("FindNextVolumeA returned %s", lpszVolumeName)); 588 pVolInfo->lastvol++; 589 GlobalUnlock(hFindVolume); 590 SetLastError(ERROR_SUCCESS); 591 return TRUE; 454 592 } 455 593 //****************************************************************************** … … 458 596 DWORD cchBufferLength) 459 597 { 598 LPSTR pszvolnameA = NULL; 599 BOOL ret; 600 601 if(!VERSION_IS_WIN2000_OR_HIGHER()) { 602 SetLastError(ERROR_NOT_SUPPORTED); 603 return FALSE; 604 } 605 606 if(cchBufferLength) { 607 pszvolnameA = (char *)alloca(cchBufferLength); 608 } 609 ret = FindNextVolumeA(hFindVolume, pszvolnameA, cchBufferLength); 610 if(ret) { 611 int len = MultiByteToWideChar( CP_ACP, 0, pszvolnameA, -1, NULL, 0); 612 MultiByteToWideChar(CP_ACP, 0, pszvolnameA, -1, lpszVolumeName, len); 613 } 614 return ret; 615 } 616 //****************************************************************************** 617 //****************************************************************************** 618 BOOL WIN32API FindVolumeClose(HANDLE hFindVolume) 619 { 620 VOLINFO *pVolInfo; 621 622 if(!VERSION_IS_WIN2000_OR_HIGHER()) { 623 SetLastError(ERROR_NOT_SUPPORTED); 624 return FALSE; 625 } 626 627 if(hFindVolume) { 628 pVolInfo = (VOLINFO *)GlobalLock(hFindVolume); 629 OSLibLVMFreeVolumeControlData(pVolInfo->hLVMVolumeControlData); 630 GlobalUnlock(hFindVolume); 631 GlobalFree(hFindVolume); 632 return TRUE; 633 } 460 634 return FALSE; 461 }462 //******************************************************************************463 //******************************************************************************464 BOOL WIN32API FindVolumeClose(HANDLE hFindVolume)465 {466 return TRUE;467 635 } 468 636 //****************************************************************************** … … 472 640 DWORD cchBufferLength) 473 641 { 642 if(!VERSION_IS_WIN2000_OR_HIGHER()) { 643 SetLastError(ERROR_NOT_SUPPORTED); 644 return FALSE; 645 } 646 647 SetLastError(ERROR_NO_MORE_FILES); 474 648 return 0; 475 649 } … … 480 654 DWORD cchBufferLength) 481 655 { 482 return 0; 656 LPSTR pszmountpointnameA = NULL; 657 LPSTR pszrootA = NULL; 658 HANDLE hVolume; 659 660 if(!VERSION_IS_WIN2000_OR_HIGHER()) { 661 SetLastError(ERROR_NOT_SUPPORTED); 662 return FALSE; 663 } 664 665 if(cchBufferLength) { 666 pszmountpointnameA = (char *)alloca(cchBufferLength); 667 } 668 if(lpszRootPathName) { 669 pszrootA = (char *)alloca(lstrlenW(lpszRootPathName)+1); 670 671 int len = WideCharToMultiByte( CP_ACP, 0, lpszRootPathName, -1, NULL, 0, 0, NULL); 672 WideCharToMultiByte(CP_ACP, 0, lpszRootPathName, -1, pszrootA, len, 0, NULL); 673 } 674 675 hVolume = FindFirstVolumeMountPointA(pszrootA, pszmountpointnameA, cchBufferLength); 676 if(hVolume) { 677 int len = MultiByteToWideChar( CP_ACP, 0, pszmountpointnameA, -1, NULL, 0); 678 MultiByteToWideChar(CP_ACP, 0, pszmountpointnameA, -1, lpszVolumeMountPoint, len); 679 } 680 return hVolume; 483 681 } 484 682 //****************************************************************************** … … 488 686 DWORD cchBufferLength) 489 687 { 688 if(!VERSION_IS_WIN2000_OR_HIGHER()) { 689 SetLastError(ERROR_NOT_SUPPORTED); 690 return FALSE; 691 } 692 SetLastError(ERROR_NO_MORE_FILES); 490 693 return FALSE; 491 694 } … … 496 699 DWORD cchBufferLength) 497 700 { 701 LPSTR pszmoutpointnameA = NULL; 702 BOOL ret; 703 704 if(!VERSION_IS_WIN2000_OR_HIGHER()) { 705 SetLastError(ERROR_NOT_SUPPORTED); 706 return FALSE; 707 } 708 709 if(cchBufferLength) { 710 pszmoutpointnameA = (char *)alloca(cchBufferLength); 711 } 712 ret = FindFirstVolumeA(pszmoutpointnameA, cchBufferLength); 713 if(ret) { 714 int len = MultiByteToWideChar( CP_ACP, 0, pszmoutpointnameA, -1, NULL, 0); 715 MultiByteToWideChar(CP_ACP, 0, pszmoutpointnameA, -1, lpszVolumeMountPoint, len); 716 } 717 return ret; 718 } 719 //****************************************************************************** 720 //****************************************************************************** 721 BOOL WIN32API FindVolumeMountPointClose(HANDLE hFindVolumeMountPoint) 722 { 723 if(!VERSION_IS_WIN2000_OR_HIGHER()) { 724 SetLastError(ERROR_NOT_SUPPORTED); 725 return FALSE; 726 } 727 728 if(hFindVolumeMountPoint) { 729 GlobalFree(hFindVolumeMountPoint); 730 return TRUE; 731 } 498 732 return FALSE; 499 }500 //******************************************************************************501 //******************************************************************************502 BOOL WIN32API FindVolumeMountPointClose(HANDLE hFindVolumeMountPoint)503 {504 return TRUE;505 733 } 506 734 //****************************************************************************** … … 510 738 DWORD cchBufferLength) 511 739 { 740 if(!VERSION_IS_WIN2000_OR_HIGHER()) { 741 SetLastError(ERROR_NOT_SUPPORTED); 742 return FALSE; 743 } 744 745 dprintf(("GetVolumeNameForVolumeMountPointA: %s", lpszVolumeMountPoint)); 746 if(OSLibLVMGetVolumeNameForVolumeMountPoint(lpszVolumeMountPoint, lpszVolumeName, 747 cchBufferLength) == TRUE) 748 { 749 SetLastError(ERROR_SUCCESS); 750 return TRUE; 751 } 752 SetLastError(ERROR_FILE_NOT_FOUND); 512 753 return FALSE; 513 754 } … … 518 759 DWORD cchBufferLength) 519 760 { 520 return FALSE; 521 } 522 //****************************************************************************** 523 //****************************************************************************** 761 LPSTR pszmoutpointnameA = NULL; 762 LPSTR pszvolumenameA = NULL; 763 BOOL ret; 764 int len; 765 766 if(!VERSION_IS_WIN2000_OR_HIGHER()) { 767 SetLastError(ERROR_NOT_SUPPORTED); 768 return FALSE; 769 } 770 len = WideCharToMultiByte( CP_ACP, 0, lpszVolumeMountPoint, -1, NULL, 0, 0, NULL); 771 pszmoutpointnameA = (char *)alloca(len+1); 772 WideCharToMultiByte(CP_ACP, 0, lpszVolumeMountPoint, -1, pszmoutpointnameA, len, 0, NULL); 773 774 if(cchBufferLength && lpszVolumeName) { 775 pszvolumenameA = (char *)alloca(cchBufferLength); 776 } 777 ret = GetVolumeNameForVolumeMountPointA(pszmoutpointnameA, pszvolumenameA, cchBufferLength); 778 if(ret) { 779 int len = MultiByteToWideChar( CP_ACP, 0, pszvolumenameA, -1, NULL, 0); 780 MultiByteToWideChar(CP_ACP, 0, pszvolumenameA, -1, lpszVolumeName, len); 781 } 782 return ret; 783 } 784 //****************************************************************************** 785 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.