VirtualBox

Changeset 85946 in vbox for trunk


Ignore:
Timestamp:
Aug 28, 2020 10:12:25 PM (4 years ago)
Author:
vboxsync
Message:

Storage/VMDK: Removed unnecessary code from vmdkRawDescWinMakePartitionName. bugref:9224

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/VMDK.cpp

    r85945 r85946  
    37643764#ifdef RT_OS_WINDOWS
    37653765/**
    3766  * Transform the physical drive device name into the one for the given partition.
     3766 * Construct the device name for the given partition number.
    37673767 */
    37683768static int vmdkRawDescWinMakePartitionName(PVMDKIMAGE pImage, const char *pszRawDrive, RTFILE hRawDrive, uint32_t idxPartition,
    37693769                                           char **ppszRawPartition)
    37703770{
    3771 # if 1
    3772     /*
    3773      * Ask the drive handle for its device number rather than mess about extracting
    3774      * it from the path (discovered this later when doing the path verification).
    3775      */
    37763771    int                   rc         = VINF_SUCCESS;
    37773772    DWORD                 cbReturned = 0;
     
    37863781                       pImage->pszFilename, pszRawDrive, GetLastError());
    37873782    return rc;
    3788 
    3789 # else
    3790     /*
    3791      * First variant is \\.\PhysicalDriveX -> \\.\HarddiskXPartition{idxPartition}
    3792      *
    3793      * Find the start of the digits and validate name prefix before using the digit
    3794      * portition to construct the partition device node name.
    3795      */
    3796     size_t offDigits = strlen(pszRawDrive);
    3797     if (offDigits > 0 && RT_C_IS_DIGIT(pszRawDrive[offDigits - 1]))
    3798     {
    3799         do
    3800             offDigits--;
    3801         while (offDigits > 0 && RT_C_IS_DIGIT(pszRawDrive[offDigits - 1]));
    3802         static const char s_szBaseName[] = "PhysicalDrive";
    3803         if (   offDigits > sizeof(s_szBaseName)
    3804             && RTPATH_IS_SLASH(pszRawDrive[offDigits - sizeof(s_szBaseName)])
    3805             && RTStrNICmp(&pszRawDrive[offDigits - sizeof(s_szBaseName) + 1], RT_STR_TUPLE(s_szBaseName)) == 0)
    3806         {
    3807             RTStrAPrintf(ppszRawPartition, "\\\\.\\Harddisk%sPartition%u", &pszRawDrive[offDigits], idxPartition);
    3808             return VINF_SUCCESS;
    3809         }
    3810     }
    3811 
    3812     /*
    3813      * Query the name.  We should then get "\Device\HarddiskX\DRy" back and we can parse
    3814      * the X out of that and use it to construct the \\.\HarddiskXPartition{idxPartition}.
    3815      */
    3816     UNICODE_STRING NtName;
    3817     int rc = RTNtPathFromHandle(&NtName, (HANDLE)RTFileToNative(hRawDrive), 0 /*cwcExtra*/);
    3818     if (RT_SUCCESS(rc))
    3819     {
    3820         Log(("RTNtPathFromHandle: pszRawDrive=%s; NtName=%ls\n", pszRawDrive, NtName.Buffer));
    3821         static const char s_szBaseName[] = "\\Device\\Harddisk";
    3822         if (   RTUtf16NCmpAscii(NtName.Buffer, s_szBaseName, sizeof(s_szBaseName) - 1) == 0
    3823             && RTUniCpIsDecDigit(NtName.Buffer[sizeof(s_szBaseName) - 1])) /* A bit HACKY as words in UTF-16 != codepoint. */
    3824         {
    3825             offDigits = sizeof(s_szBaseName) - 1;
    3826             size_t offEndDigits = offDigits + 1;
    3827             while (RTUniCpIsDecDigit(NtName.Buffer[offEndDigits]))
    3828                 offEndDigits++;
    3829             if (   NtName.Buffer[offEndDigits] == '\\'
    3830                 && NtName.Buffer[offEndDigits + 1] == 'D'
    3831                 && NtName.Buffer[offEndDigits + 2] == 'R'
    3832                 && RTUniCpIsDecDigit(NtName.Buffer[offEndDigits + 3]))
    3833             {
    3834                 RTStrAPrintf(ppszRawPartition, "\\\\.\\Harddisk%.*lsPartition%u",
    3835                              offEndDigits - offDigits, &NtName.Buffer[offDigits], idxPartition);
    3836                 RTNtPathFree(&NtName, NULL);
    3837                 return VINF_SUCCESS;
    3838             }
    3839         }
    3840         rc = vdIfError(pImage->pIfError, VERR_INVALID_PARAMETER, RT_SRC_POS,
    3841                        N_("VMDK: Image path: '%s'. Do not know how to translate '%s' ('%ls') into a name for partition #%u"),
    3842                        pImage->pszFilename, pszRawDrive, NtName.Buffer, idxPartition);
    3843         RTNtPathFree(&NtName, NULL);
    3844     }
    3845     else
    3846         rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS,
    3847                        N_("VMDK: Image path: '%s'. Failed to get the NT path for '%s' and therefore unable to determin path to partition #%u (%Rrc)"),
    3848                        pImage->pszFilename, pszRawDrive, idxPartition, rc);
    3849     return rc;
    3850 # endif
    38513783}
    38523784#endif /* RT_OS_WINDOWS */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette