VirtualBox

Changeset 72630 in vbox


Ignore:
Timestamp:
Jun 20, 2018 2:10:41 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
123132
Message:

Flash: Fixed initial state when file did not exist.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/DevFlash.cpp

    r72615 r72630  
    413413
    414414/** @todo this does not really belong here; workaround for EFI failing to init empty flash. */
    415 uint8_t aHdrBegin[] = {
     415static const uint8_t aHdrBegin[] = {
    416416    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    417417    0x8D, 0x2B, 0xF1, 0xFF, 0x96, 0x76, 0x8B, 0x4C, 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50,
     
    487487        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to allocate heap memory"));
    488488
    489     memset(pThis->pbFlash, 0xff, pThis->cbFlashSize);
    490     memcpy(pThis->pbFlash, aHdrBegin, sizeof(aHdrBegin));
    491 
    492489    size_t cbRead = 0;
    493490    rc = RTFileRead(pThis->hFlashFile, pThis->pbFlash, pThis->cbFlashSize, &cbRead);
    494491    if (RT_FAILURE(rc))
    495492        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to read flash file"));
    496     Log(("Read %zu bytes from file (asked for %u).", cbRead, pThis->cbFlashSize));
     493    Log(("Read %zu bytes from file (asked for %u)\n.", cbRead, pThis->cbFlashSize));
     494
     495    /* If the file didn't exist, or someone truncated it, we'll initialize
     496     * the storage with default contents.
     497     */
    497498    if (cbRead != pThis->cbFlashSize)
    498         return PDMDEV_SET_ERROR(pDevIns, VERR_READ_ERROR, N_("Failed to read flash file"));
     499    {
     500        memset(pThis->pbFlash, 0xff, pThis->cbFlashSize);
     501        memcpy(pThis->pbFlash, aHdrBegin, sizeof(aHdrBegin));
     502        LogRel(("Only read %zu bytes from flash file (asked for %u). Initializing with defaults.\n", cbRead, pThis->cbFlashSize));
     503    }
    499504
    500505    /* Reset the dynamic state.*/
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