VirtualBox

Changeset 80512 in vbox


Ignore:
Timestamp:
Aug 30, 2019 11:40:05 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133013
Message:

vboximg-mounter: Don't hardcode the sector size but use VDGetSectorSize() to query it from the disk image

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ImageMounter/vboximg-mount/vboximg-mount.cpp

    r80511 r80512  
    9191
    9292#define VBOX_EXTPACK                "Oracle VM VirtualBox Extension Pack"
    93 #define GPT_PTABLE_SIZE             32 * BLOCKSIZE   /** Max size we to read for GPT partition table */
     93#define GPT_PTABLE_SIZE             32 * 512         /** Max size we to read for GPT partition table */
    9494#define MBR_PARTITIONS_MAX          4                /** Fixed number of partitions in Master Boot Record */
    9595#define BASENAME_MAX                256              /** Maximum name for the basename of a path (for RTStrNLen()*/
    9696#define VBOXIMG_PARTITION_MAX       256              /** How much storage to allocate to store partition info */
    9797#define PARTITION_NAME_MAX          72               /** Maximum partition name size (accomodates GPT partition name) */
    98 #define BLOCKSIZE                   512              /** Commonly used disk block size */
    9998#define DOS_BOOT_RECORD_SIGNATURE   0xaa55           /** MBR and EBR (partition table) signature [EOT boundary] */
    10099#define NULL_BOOT_RECORD_SIGNATURE  0x0000           /** MBR or EBR null signature value */
    101100#define MAX_UUID_LEN                256              /** Max length of a UUID */
    102 #define LBA(n)                      (n * BLOCKSIZE)
    103 #define VD_SECTOR_SIZE              512              /** Virtual disk sector/blocksize */
    104 #define VD_SECTOR_MASK              (VD_SECTOR_SIZE - 1)    /** Masks off a blocks worth of data */
    105 #define VD_SECTOR_OUT_OF_BOUNDS_MASK  (~UINT64_C(VD_SECTOR_MASK))         /** Masks the overflow of a blocks worth of data */
     101#define LBA(n)                      (n * g_cbSector)
    106102#define VERBOSE                     g_vboximgOpts.fVerbose
    107 #define IS_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100)
    108103
    109104#define PARTTYPE_IS_NULL(parType) ((uint8_t)parType == 0x00)
     
    121116
    122117static RTVFSFILE             g_hVfsFileDisk;        /** Disk as VFS file handle. */
    123 static char                 *g_pszDiskUuid;          /** UUID of image (if known, otherwise NULL) */
     118static uint32_t              g_cbSector;            /** Disk sector size. */
     119static char                 *g_pszDiskUuid;         /** UUID of image (if known, otherwise NULL) */
    124120static off_t                 g_vDiskOffset;         /** Biases r/w from start of VD */
    125121static off_t                 g_vDiskSize;           /** Limits r/w length for VD */
     
    642638
    643639        ppi->idxPartition = idxPartition;
    644         ppi->offPartition = (off_t) pMbrPartitionEntry->partitionLba * BLOCKSIZE;
    645         ppi->cbPartition  = (off_t) pMbrPartitionEntry->partitionBlkCnt * BLOCKSIZE;
     640        ppi->offPartition = (off_t) pMbrPartitionEntry->partitionLba * g_cbSector;
     641        ppi->cbPartition  = (off_t) pMbrPartitionEntry->partitionBlkCnt * g_cbSector;
    646642        ppi->fBootable    = pMbrPartitionEntry->bootIndicator == 0x80;
    647643        ppi->partitionType.legacy = pMbrPartitionEntry->type;
     
    689685            if (!pEntry->firstLba)
    690686                break;
    691             ppi->offPartition = pEntry->firstLba * BLOCKSIZE;
    692             ppi->cbPartition = (pEntry->lastLba - pEntry->firstLba) * BLOCKSIZE;
     687            ppi->offPartition = pEntry->firstLba * g_cbSector;
     688            ppi->cbPartition = (pEntry->lastLba - pEntry->firstLba) * g_cbSector;
    693689            ppi->fBootable = pEntry->attrFlags & (1 << GPT_LEGACY_BIOS_BOOTABLE);
    694690            ppi->partitionType.gptGuidTypeSpecifier = pEntry->partitionTypeGuid;
     
    708704        uint32_t firstEbrLba
    709705            = g_aParsedPartitionInfo[idxEbrPartitionInMbr].partitionEntry.mbrEntry.partitionLba;
    710         off_t    firstEbrOffset   = (off_t)firstEbrLba * BLOCKSIZE;
     706        off_t    firstEbrOffset   = (off_t)firstEbrLba * g_cbSector;
    711707        off_t    chainedEbrOffset = 0;
    712708
     
    738734            PARTITIONINFO *ppi = &g_aParsedPartitionInfo[idxPartition];
    739735            ppi->idxPartition         = idxPartition;
    740             ppi->offPartition         = currentEbrOffset + (off_t)pEbrPartitionEntry->partitionLba * BLOCKSIZE;
    741             ppi->cbPartition          = (off_t)pEbrPartitionEntry->partitionBlkCnt * BLOCKSIZE;
     736            ppi->offPartition         = currentEbrOffset + (off_t)pEbrPartitionEntry->partitionLba * g_cbSector;
     737            ppi->cbPartition          = (off_t)pEbrPartitionEntry->partitionBlkCnt * g_cbSector;
    742738            ppi->fBootable            = pEbrPartitionEntry->bootIndicator == 0x80;
    743739            ppi->partitionType.legacy = pEbrPartitionEntry->type;
     
    751747                return RTMsgErrorExitFailure("Logical partition chain broken");
    752748
    753             chainedEbrOffset = ebr.chainingPartitionEntry.partitionLba * BLOCKSIZE;
     749            chainedEbrOffset = ebr.chainingPartitionEntry.partitionLba * g_cbSector;
    754750        }
    755751    }
     
    825821            if (colBoot)
    826822                tbl.setCell(row, colBoot,   ppi->fBootable ? '*' : ' ');
    827             tbl.setCell(row, colStart,      ppi->offPartition / BLOCKSIZE);
    828             tbl.setCell(row, colSectors,    ppi->cbPartition / BLOCKSIZE);
     823            tbl.setCell(row, colStart,      ppi->offPartition / g_cbSector);
     824            tbl.setCell(row, colSectors,    ppi->cbPartition / g_cbSector);
    829825            tbl.setCell(row, colSize,       vboximgScaledSize(ppi->cbPartition));
    830826            tbl.setCell(row, colOffset,     ppi->offPartition);
     
    875871            tbl.setCell(row, colPartition,  g_pszBaseImageName, idxPartition);
    876872            tbl.setCell(row, colBoot,       p->fBootable ? '*' : ' ');
    877             tbl.setCell(row, colStart,      p->offPartition / BLOCKSIZE);
    878             tbl.setCell(row, colSectors,    p->cbPartition / BLOCKSIZE);
     873            tbl.setCell(row, colStart,      p->offPartition / g_cbSector);
     874            tbl.setCell(row, colSectors,    p->cbPartition / g_cbSector);
    879875            tbl.setCell(row, colSize,       vboximgScaledSize(p->cbPartition));
    880876            tbl.setCell(row, colOffset,     p->offPartition);
     
    12321228
    12331229        rc = VDOpen(pVDisk,
    1234                     CSTR(pszFormat),
     1230                    pszFormat,
    12351231                    CSTR(pCurMedium->pImagePath),
    12361232                    pCurMedium->fWriteable,
     
    12561252    if (RT_FAILURE(rc))
    12571253        return RTMsgErrorExitFailure("Error querying disk image size from VFS wrapper\n");
     1254
     1255    g_cbSector = VDGetSectorSize(pVDisk, VD_LAST_IMAGE);
    12581256
    12591257    if (g_vboximgOpts.fList)
     
    13181316                     if (VERBOSE)
    13191317                        RTPrintf("\nPartition %d specified. Only sectors %llu to %llu of disk will be accessible\n",
    1320                             g_vboximgOpts.idxPartition, g_vDiskOffset / BLOCKSIZE, g_vDiskSize / BLOCKSIZE);
     1318                            g_vboximgOpts.idxPartition, g_vDiskOffset / g_cbSector, g_vDiskSize / g_cbSector);
    13211319                }
    13221320            }
     
    13301328
    13311329            if (VERBOSE)
    1332                 RTPrintf("Setting r/w bias (offset) to user requested value for sector %llu\n", g_vDiskOffset / BLOCKSIZE);
     1330                RTPrintf("Setting r/w bias (offset) to user requested value for sector %llu\n", g_vDiskOffset / g_cbSector);
    13331331
    13341332            g_vDiskOffset = g_vboximgOpts.offset;
     
    13391337
    13401338            if (VERBOSE)
    1341                 RTPrintf("Setting r/w size limit to user requested value %llu\n", g_vDiskSize / BLOCKSIZE);
     1339                RTPrintf("Setting r/w size limit to user requested value %llu\n", g_vDiskSize / g_cbSector);
    13421340
    13431341            g_vDiskSize = g_vboximgOpts.size;
Note: See TracChangeset for help on using the changeset viewer.

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