- Timestamp:
- Aug 28, 2020 10:12:25 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/VMDK.cpp
r85945 r85946 3764 3764 #ifdef RT_OS_WINDOWS 3765 3765 /** 3766 * Transform the physical drive device name into the one for the given partition.3766 * Construct the device name for the given partition number. 3767 3767 */ 3768 3768 static int vmdkRawDescWinMakePartitionName(PVMDKIMAGE pImage, const char *pszRawDrive, RTFILE hRawDrive, uint32_t idxPartition, 3769 3769 char **ppszRawPartition) 3770 3770 { 3771 # if 13772 /*3773 * Ask the drive handle for its device number rather than mess about extracting3774 * it from the path (discovered this later when doing the path verification).3775 */3776 3771 int rc = VINF_SUCCESS; 3777 3772 DWORD cbReturned = 0; … … 3786 3781 pImage->pszFilename, pszRawDrive, GetLastError()); 3787 3782 return rc; 3788 3789 # else3790 /*3791 * First variant is \\.\PhysicalDriveX -> \\.\HarddiskXPartition{idxPartition}3792 *3793 * Find the start of the digits and validate name prefix before using the digit3794 * 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 do3800 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 parse3814 * 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) == 03823 && 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 else3846 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 # endif3851 3783 } 3852 3784 #endif /* RT_OS_WINDOWS */
Note:
See TracChangeset
for help on using the changeset viewer.