VirtualBox

Changeset 87050 in vbox


Ignore:
Timestamp:
Dec 8, 2020 12:51:48 PM (4 years ago)
Author:
vboxsync
Message:

Main: bugref:9224: Added device and partition paths checks for Solaris

Location:
trunk/src/VBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Makefile.kmk

    r87002 r87050  
    103103 VBoxDDU_LIBS.freebsd    += \
    104104        geom
     105 VBoxDDU_LIBS.solaris    += \
     106    efi
    105107 if defined(VBOX_WITH_USB) && "$(intersects $(KBUILD_TARGET_ARCH),$(VBOX_SUPPORTED_HOST_ARCHS))" != ""
    106108  VBoxDDU_LIBS           += \
  • trunk/src/VBox/Storage/VMDK.cpp

    r87002 r87050  
    5656#include <sys/stat.h>
    5757#include <stdlib.h>
     58#endif
     59#ifdef RT_OS_SOLARIS
     60#include <sys/dkio.h>
     61#include <sys/vtoc.h>
     62#include <sys/efi_partition.h>
     63#include <unistd.h>
     64#include <errno.h>
    5865#endif
    5966
     
    39533960        /* else: We've got nothing to work on, so only do content comparison. */
    39543961    }
     3962   
    39553963#elif defined(RT_OS_FREEBSD)
    39563964    char szDriveDevName[256];
     
    40144022                           N_("VMDK: Image path: '%s'. geom_gettree failed: %d"), pImage->pszFilename, err);
    40154023    }
     4024   
     4025#elif defined(RT_OS_SOLARIS)
     4026    RT_NOREF(hVol);
     4027   
     4028    dk_cinfo dkiDriveInfo;
     4029    dk_cinfo dkiPartInfo;
     4030    if (ioctl(RTFileToNative(hRawDrive), DKIOCINFO, (caddr_t)&dkiDriveInfo) == -1)
     4031        rc = vdIfError(pImage->pIfError, RTErrConvertFromErrno(errno), RT_SRC_POS,
     4032                       N_("VMDK: Image path: '%s'. DKIOCINFO failed on '%s': %d"), pImage->pszFilename, pszRawDrive, errno);
     4033    else if (ioctl(RTFileToNative(hRawPart), DKIOCINFO, (caddr_t)&dkiPartInfo) == -1)
     4034        rc = vdIfError(pImage->pIfError, RTErrConvertFromErrno(errno), RT_SRC_POS,
     4035                       N_("VMDK: Image path: '%s'. DKIOCINFO failed on '%s': %d"), pImage->pszFilename, pszRawDrive, errno);
     4036    else if (  dkiDriveInfo.dki_ctype != dkiPartInfo.dki_ctype
     4037            || dkiDriveInfo.dki_cnum  != dkiPartInfo.dki_cnum
     4038            || dkiDriveInfo.dki_addr  != dkiPartInfo.dki_addr
     4039            || dkiDriveInfo.dki_unit  != dkiPartInfo.dki_unit
     4040            || dkiDriveInfo.dki_slave != dkiPartInfo.dki_slave)
     4041        rc = vdIfError(pImage->pIfError, VERR_MISMATCH, RT_SRC_POS,
     4042                       N_("VMDK: Image path: '%s'. Partition #%u path ('%s') verification failed on '%s' (%#x != %#x || %#x != %#x || %#x != %#x || %#x != %#x || %#x != %#x)"),
     4043                       pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive,
     4044                       dkiDriveInfo.dki_ctype, dkiPartInfo.dki_ctype, dkiDriveInfo.dki_cnum, dkiPartInfo.dki_cnum,
     4045                       dkiDriveInfo.dki_addr, dkiPartInfo.dki_addr, dkiDriveInfo.dki_unit, dkiPartInfo.dki_unit,
     4046                       dkiDriveInfo.dki_slave, dkiPartInfo.dki_slave);
     4047    else
     4048    {
     4049        uint64_t cbOffset = 0;
     4050        uint64_t cbSize = 0;
     4051        dk_gpt *pEfi = NULL;
     4052        int idxEfiPart = efi_alloc_and_read(RTFileToNative(hRawPart), &pEfi);
     4053        if (idxEfiPart >= 0)
     4054        {
     4055            if ((uint32_t)dkiPartInfo.dki_partition + 1 == idxPartition)
     4056            {
     4057                cbOffset = pEfi->efi_parts[idxEfiPart].p_start * pEfi->efi_lbasize;
     4058                cbSize   = pEfi->efi_parts[idxEfiPart].p_size  * pEfi->efi_lbasize;
     4059            }
     4060            else
     4061                rc = vdIfError(pImage->pIfError, VERR_MISMATCH, RT_SRC_POS,
     4062                               N_("VMDK: Image path: '%s'. Partition #%u number ('%s') verification failed on '%s' (%#x != %#x)"),
     4063                               pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive,
     4064                               idxPartition, (uint32_t)dkiPartInfo.dki_partition + 1);
     4065            efi_free(pEfi);
     4066        }
     4067        else
     4068        {
     4069            /*
     4070             * Manual says the efi_alloc_and_read returns VT_EINVAL if no EFI partition table found.
     4071             * Actually, the function returns any error, e.g. VT_ERROR. Thus, we are not sure, is it
     4072             * real error or just no EFI table found. Therefore, let's try to obtain partition info
     4073             * using another way. If there is an error, it returns errno which will be handled below.
     4074             */
     4075               
     4076            uint32_t numPartition = (uint32_t)dkiPartInfo.dki_partition;
     4077            if (numPartition > NDKMAP)
     4078                numPartition -= NDKMAP;
     4079            if (numPartition != idxPartition)
     4080                rc = vdIfError(pImage->pIfError, VERR_MISMATCH, RT_SRC_POS,
     4081                               N_("VMDK: Image path: '%s'. Partition #%u number ('%s') verification failed on '%s' (%#x != %#x)"),
     4082                               pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive,
     4083                               idxPartition, numPartition);
     4084            else
     4085            {
     4086                dk_minfo_ext mediaInfo;
     4087                if (ioctl(RTFileToNative(hRawPart), DKIOCGMEDIAINFOEXT, (caddr_t)&mediaInfo) == -1)
     4088                    rc = vdIfError(pImage->pIfError, RTErrConvertFromErrno(errno), RT_SRC_POS,
     4089                                   N_("VMDK: Image path: '%s'. Partition #%u number ('%s') verification failed on '%s'. Can not obtain partition info: %d"),
     4090                                   pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, errno);
     4091                else
     4092                {
     4093                    extpart_info extPartInfo;
     4094                    if (ioctl(RTFileToNative(hRawPart), DKIOCEXTPARTINFO, (caddr_t)&extPartInfo) != -1)
     4095                    {
     4096                        cbOffset = (uint64_t)extPartInfo.p_start * mediaInfo.dki_lbsize;
     4097                        cbSize   = (uint64_t)extPartInfo.p_length * mediaInfo.dki_lbsize;
     4098                    }
     4099                    else
     4100                        rc = vdIfError(pImage->pIfError, RTErrConvertFromErrno(errno), RT_SRC_POS,
     4101                                       N_("VMDK: Image path: '%s'. Partition #%u number ('%s') verification failed on '%s'. Can not obtain partition info: %d"),
     4102                                       pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, errno);
     4103                }
     4104            }
     4105        }
     4106        if (RT_SUCCESS(rc) && cbOffset != pPartDesc->offStartInVDisk)
     4107            rc = vdIfError(pImage->pIfError, VERR_MISMATCH, RT_SRC_POS,
     4108                           N_("VMDK: Image path: '%s'. Partition #%u path ('%s') verification failed on '%s': Start offset %RI64, expected %RU64"),
     4109                           pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, cbOffset, pPartDesc->offStartInVDisk);
     4110
     4111        if (RT_SUCCESS(rc) && cbSize != pPartDesc->cbData)
     4112            rc = vdIfError(pImage->pIfError, VERR_MISMATCH, RT_SRC_POS,
     4113                           N_("VMDK: Image path: '%s'. Partition #%u path ('%s') verification failed on '%s': Size %RI64, expected %RU64"),
     4114                           pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, cbSize, pPartDesc->cbData);
     4115    }
     4116   
    40164117#else
    40174118    RT_NOREF(hVol); /* PORTME */
     
    42364337                rc = vmdkRawDescWinMakePartitionName(pImage, pszRawDrive, hRawDrive, idxPartition, &paPartDescs[i].pszRawDevice);
    42374338                AssertRCReturn(rc, rc);
     4339#elif defined(RT_OS_SOLARIS)
     4340                if (pRawDesc->enmPartitioningType == VDISKPARTTYPE_MBR)
     4341                {
     4342                    /*
     4343                     * MBR partitions have device nodes in form /dev/(r)dsk/cXtYdZpK
     4344                     * where X is the controller,
     4345                     *       Y is target (SCSI device number),
     4346                     *       Z is disk number,
     4347                     *       K is partition number,
     4348                     *         where p0 is the whole disk
     4349                     *               p1-pN are the partitions of the disk
     4350                     */
     4351                    const char *pszRawDrivePath = pszRawDrive;
     4352                    char szDrivePath[RTPATH_MAX];
     4353                    size_t cbRawDrive = strlen(pszRawDrive);
     4354                    if (  cbRawDrive > 1 && strcmp(&pszRawDrive[cbRawDrive - 2], "p0") == 0)
     4355                    {
     4356                        memcpy(szDrivePath, pszRawDrive, cbRawDrive - 2);
     4357                        szDrivePath[cbRawDrive - 2] = '\0';
     4358                        pszRawDrivePath = szDrivePath;
     4359                    }
     4360                    RTStrAPrintf(&paPartDescs[i].pszRawDevice, "%sp%u", pszRawDrivePath, idxPartition);
     4361                }
     4362                else /* GPT */
     4363                {
     4364                    /*
     4365                     * GPT partitions have device nodes in form /dev/(r)dsk/cXtYdZsK
     4366                     * where X is the controller,
     4367                     *       Y is target (SCSI device number),
     4368                     *       Z is disk number,
     4369                     *       K is partition number, zero based. Can be only from 0 to 6.
     4370                     *         Thus, only partitions numbered 0 through 6 have device nodes.
     4371                     */
     4372                    if (idxPartition > 7)
     4373                        return vdIfError(pImage->pIfError, VERR_INVALID_PARAMETER, RT_SRC_POS,
     4374                                         N_("VMDK: Image path: '%s'. the partition #%u on '%s' has no device node and can not be specified with 'Relative' property"),
     4375                                         pImage->pszFilename, idxPartition, pszRawDrive);
     4376                    RTStrAPrintf(&paPartDescs[i].pszRawDevice, "%ss%u", pszRawDrive, idxPartition - 1);
     4377                }
    42384378#else
    42394379                AssertFailedReturn(VERR_INTERNAL_ERROR_4); /* The option parsing code should have prevented this - PORTME */
     
    46404780                             N_("VMDK: Image path: '%s'. The 'Relative' option is not supported for whole-drive configurations, only when selecting partitions"),
    46414781                             pImage->pszFilename);
    4642 #if !defined(RT_OS_DARWIN) && !defined(RT_OS_LINUX) && !defined(RT_OS_FREEBSD) && !defined(RT_OS_WINDOWS) /* PORTME */
     4782#if !defined(RT_OS_DARWIN) && !defined(RT_OS_LINUX) && !defined(RT_OS_FREEBSD) && !defined(RT_OS_WINDOWS) && !defined(RT_OS_SOLARIS) /* PORTME */
    46434783        if (*pfRelative == true)
    46444784            return vdIfError(pImage->pIfError, VERR_INVALID_PARAMETER, RT_SRC_POS,
  • trunk/src/VBox/Storage/testcase/Makefile.kmk

    r87002 r87050  
    159159  vbox-img_SDKS.win = VBOX_NTDLL
    160160 else ifeq ($(KBUILD_TARGET),solaris)
    161   vbox-img_LIBS += kstat
     161  vbox-img_LIBS += kstat efi
    162162  ifdef SDK_VBOX_LIBXML2_LIBS
    163163   vbox-img_LIBS += xml2
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