VirtualBox

Changeset 64987 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Dec 21, 2016 3:05:56 PM (8 years ago)
Author:
vboxsync
Message:

VBoxManage: proposal for a sanity check

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp

    r63582 r64987  
    504504    bool fModifyCompact = false;
    505505    bool fModifyResize = false;
     506    bool fModifyResizeMB = false;
    506507    bool fModifyLocation = false;
    507508    bool fModifyDescription = false;
     
    591592                cbResize = ValueUnion.u64 * _1M;
    592593                fModifyResize = true;
     594                fModifyResizeMB = true; // do sanity check!
    593595                break;
    594596
     
    670672        RTMsgError("Invalid medium reference, avoiding crash");
    671673        return RTEXITCODE_FAILURE;
     674    }
     675
     676    if (   fModifyResize
     677        && fModifyResizeMB)
     678    {
     679        // Sanity check
     680        //
     681        // In general users should know what they do but in this case users have no
     682        // alternative to VBoxManage. If happens that one wants to resize the disk
     683        // and uses --resize and does not consider that this parameter expects the
     684        // new medium size in MB not Byte. If the operation is started and then
     685        // aborted by the user, the result is most likely a medium which doesn't
     686        // work anymore.
     687        LONG64 logicalSize;
     688        pMedium->COMGETTER(LogicalSize)(&logicalSize);
     689        if (cbResize > (uint64_t)logicalSize * _1M)
     690        {
     691            RTMsgError("Error: Attempt to resize the medium from %RU64.%RU64 MB to %RU64.%RU64 MB. Use --resizebyte is this is intended!\n",
     692                    logicalSize / _1M, (logicalSize % _1M) / (_1M / 10), cbResize / _1M, (cbResize % _1M) / (_1M / 10));
     693            return RTEXITCODE_FAILURE;
     694        }
    672695    }
    673696
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