VirtualBox

Changeset 87209 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 11, 2021 10:09:09 AM (4 years ago)
Author:
vboxsync
Message:

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

File:
1 edited

Legend:

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

    r87055 r87209  
    6262#include <errno.h>
    6363#endif
     64#ifdef RT_OS_DARWIN
     65# include <sys/stat.h>
     66# include <sys/disk.h>
     67# include <errno.h>
     68/* The following structure and IOCTLs are defined in znu bsd/sys/disk.h but
     69   inside KERNEL ifdefs and thus stripped from the SDK edition of the header.
     70   While we could try include the header from the Kernel.framework, it's a lot
     71   easier to just add the structure and 4 defines here. */
     72typedef struct
     73{
     74    uint64_t offset;
     75    uint64_t length;
     76    uint8_t  reserved0128[12];
     77    dev_t    dev;
     78} dk_physical_extent_t;
     79# define DKIOCGETBASE               _IOR( 'd', 73, uint64_t)
     80# define DKIOCLOCKPHYSICALEXTENTS   _IO(  'd', 81)
     81# define DKIOCGETPHYSICALEXTENT     _IOWR('d', 82, dk_physical_extent_t)
     82# define DKIOCUNLOCKPHYSICALEXTENTS _IO(  'd', 83)
     83#endif /* RT_OS_DARWIN */
    6484#include "VDBackends.h"
    6585
     
    37623782                           pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, cbSize, pPartDesc->cbData);
    37633783    }
     3784
     3785#elif defined(RT_OS_DARWIN)
     3786    /* Stat the drive get its device number. */
     3787    struct stat StDrive;
     3788    if (fstat((int)RTFileToNative(hRawDrive), &StDrive) != 0)
     3789        rc = vdIfError(pImage->pIfError, RTErrConvertFromErrno(errno), RT_SRC_POS,
     3790                       N_("VMDK: Image path: '%s'. fstat failed on '%s' (errno=%d)"), pImage->pszFilename, pszRawDrive, errno);
     3791    else
     3792    {
     3793        if (ioctl(RTFileToNative(hRawPart), DKIOCLOCKPHYSICALEXTENTS, NULL) == -1)
     3794            rc = vdIfError(pImage->pIfError, RTErrConvertFromErrno(errno), RT_SRC_POS,
     3795                           N_("VMDK: Image path: '%s'. Partition #%u number ('%s') verification failed on '%s': Unable to lock the partition (errno=%d)"),
     3796                           pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, errno);
     3797        else
     3798        {
     3799            uint32_t cbBlockSize = 0;
     3800            uint64_t cbOffset = 0;
     3801            uint64_t cbSize = 0;
     3802            if (ioctl(RTFileToNative(hRawPart), DKIOCGETBLOCKSIZE, (caddr_t)&cbBlockSize) == -1)
     3803                rc = vdIfError(pImage->pIfError, RTErrConvertFromErrno(errno), RT_SRC_POS,
     3804                               N_("VMDK: Image path: '%s'. Partition #%u number ('%s') verification failed on '%s': Unable to obtain the sector size of the partition (errno=%d)"),
     3805                               pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, errno);
     3806            else if (ioctl(RTFileToNative(hRawPart), DKIOCGETBASE, (caddr_t)&cbOffset) == -1)
     3807                rc = vdIfError(pImage->pIfError, RTErrConvertFromErrno(errno), RT_SRC_POS,
     3808                               N_("VMDK: Image path: '%s'. Partition #%u number ('%s') verification failed on '%s': Unable to obtain the start offset of the partition (errno=%d)"),
     3809                               pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, errno);
     3810            else if (ioctl(RTFileToNative(hRawPart), DKIOCGETBLOCKCOUNT, (caddr_t)&cbSize) == -1)
     3811                rc = vdIfError(pImage->pIfError, RTErrConvertFromErrno(errno), RT_SRC_POS,
     3812                               N_("VMDK: Image path: '%s'. Partition #%u number ('%s') verification failed on '%s': Unable to obtain the size of the partition (errno=%d)"),
     3813                               pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, errno);
     3814            else
     3815            {
     3816                cbSize *= (uint64_t)cbBlockSize;
     3817                dk_physical_extent_t dkPartExtent = {0};
     3818                dkPartExtent.offset = 0;
     3819                dkPartExtent.length = cbSize;
     3820                if (ioctl(RTFileToNative(hRawPart), DKIOCGETPHYSICALEXTENT, (caddr_t)&dkPartExtent) == -1)
     3821                    rc = vdIfError(pImage->pIfError, RTErrConvertFromErrno(errno), RT_SRC_POS,
     3822                                   N_("VMDK: Image path: '%s'. Partition #%u number ('%s') verification failed on '%s': Unable to obtain partition info (errno=%d)"),
     3823                                   pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, errno);
     3824                else
     3825                {
     3826                    if (dkPartExtent.dev != StDrive.st_rdev)
     3827                        rc = vdIfError(pImage->pIfError, VERR_MISMATCH, RT_SRC_POS,
     3828                                       N_("VMDK: Image path: '%s'. Partition #%u path ('%s') verification failed on '%s': Drive does not contain the partition"),
     3829                                       pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive);
     3830                    else if (cbOffset != pPartDesc->offStartInVDisk)
     3831                        rc = vdIfError(pImage->pIfError, VERR_MISMATCH, RT_SRC_POS,
     3832                                       N_("VMDK: Image path: '%s'. Partition #%u path ('%s') verification failed on '%s': Start offset %RU64, expected %RU64"),
     3833                                       pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, cbOffset, pPartDesc->offStartInVDisk);
     3834                    else if (cbSize != pPartDesc->cbData)
     3835                        rc = vdIfError(pImage->pIfError, VERR_MISMATCH, RT_SRC_POS,
     3836                                       N_("VMDK: Image path: '%s'. Partition #%u path ('%s') verification failed on '%s': Size %RU64, expected %RU64"),
     3837                                       pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, cbSize, pPartDesc->cbData);
     3838                }
     3839            }
     3840
     3841            if (ioctl(RTFileToNative(hRawPart), DKIOCUNLOCKPHYSICALEXTENTS, NULL) == -1)
     3842            {
     3843                int rc2 = vdIfError(pImage->pIfError, RTErrConvertFromErrno(errno), RT_SRC_POS,
     3844                                    N_("VMDK: Image path: '%s'. Partition #%u number ('%s') verification failed on '%s': Unable to unlock the partition (errno=%d)"),
     3845                                    pImage->pszFilename, idxPartition, pPartDesc->pszRawDevice, pszRawDrive, errno);
     3846                if (RT_SUCCESS(rc))
     3847                    rc = rc2;
     3848            }
     3849        }
     3850    }
     3851
    37643852#else
    37653853    RT_NOREF(hVol); /* PORTME */
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