VirtualBox

Changeset 1740 in vbox


Ignore:
Timestamp:
Mar 27, 2007 4:21:40 PM (18 years ago)
Author:
vboxsync
Message:

Support raw disk images (the code is almost identical to raw disk
access). Currently only for Linux host.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DrvHostRawDisk.cpp

    • Property svn:eol-style set to native
    • Property svn:keywords set to Author Date Id Revision
    r1717 r1740  
    4343#include <errno.h>
    4444#include <sys/ioctl.h>
     45#include <sys/types.h>
     46#include <sys/stat.h>
     47#include <unistd.h>
    4548#include <linux/hdreg.h>
    4649#include <linux/fs.h>
     
    341344                pThis->cHeads = DriveGeo.TracksPerCylinder;
    342345                pThis->cSectors = DriveGeo.SectorsPerTrack;
    343                 pThis->enmTranslation = PDMBIOSTRANSLATION_NONE;
    344346                if (!pThis->cbSize)
    345347                {
     
    359361            rc = RTErrConvertFromWin32(GetLastError());
    360362#elif defined(__LINUX__)
    361         struct hd_geometry DriveGeo;
    362         if (!ioctl(pThis->HostDiskFile, HDIO_GETGEO, &DriveGeo))
     363        struct stat DevStat;
     364        if (!fstat(pThis->HostDiskFile, &DevStat) && S_ISBLK(DevStat.st_mode))
    363365        {
    364             pThis->cCylinders = DriveGeo.cylinders;
    365             pThis->cHeads = DriveGeo.heads;
    366             pThis->cSectors = DriveGeo.sectors;
    367             pThis->enmTranslation = PDMBIOSTRANSLATION_NONE;
    368             if (!pThis->cbSize)
     366            struct hd_geometry DriveGeo;
     367            if (!ioctl(pThis->HostDiskFile, HDIO_GETGEO, &DriveGeo))
    369368            {
    370                 long cBlocks;
    371                 if (!ioctl(pThis->HostDiskFile, BLKGETSIZE, &cBlocks))
    372                     pThis->cbSize = (uint64_t)cBlocks * 512;
    373                 else
    374                     rc = RTErrConvertFromErrno(errno);
     369                pThis->cCylinders = DriveGeo.cylinders;
     370                pThis->cHeads = DriveGeo.heads;
     371                pThis->cSectors = DriveGeo.sectors;
     372                if (!pThis->cbSize)
     373                {
     374                    long cBlocks;
     375                    if (!ioctl(pThis->HostDiskFile, BLKGETSIZE, &cBlocks))
     376                        pThis->cbSize = (uint64_t)cBlocks * 512;
     377                    else
     378                        rc = RTErrConvertFromErrno(errno);
     379                }
    375380            }
     381            else
     382                rc = RTErrConvertFromErrno(errno);
    376383        }
    377         else
    378             rc = RTErrConvertFromErrno(errno);
    379384#else
    380385        /** @todo add further host OS geometry detection mechanisms. */
     
    382387        rc = VERR_NOT_IMPLEMENTED;
    383388#endif
     389        /* Do geometry cleanup common to all host operating systems.
     390         * Very important, as Windows guests are very sensitive to odd
     391         * PCHS settings, and for big disks they consider anything
     392         * except the standard mapping as odd. */
     393        if (pThis->cCylinders != 0)
     394        {
     395            if (pThis->cSectors == 63 && pThis->cCylinders >= 1024)
     396            {
     397                /* For big disks, use dummy PCHS values and let the BIOS
     398                 * select an appropriate LCHS mapping. */
     399                pThis->cCylinders = pThis->cbSize / 512 / 63 / 16;
     400                pThis->cHeads = 16;
     401                pThis->cSectors = 63;
     402                pThis->enmTranslation = PDMBIOSTRANSLATION_LBA;
     403            }
     404            else
     405                pThis->enmTranslation = PDMBIOSTRANSLATION_NONE;
     406        }
    384407    }
    385408
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