VirtualBox

Changeset 97367 in vbox for trunk/src/VBox/Storage


Ignore:
Timestamp:
Nov 1, 2022 10:38:05 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
154365
Message:

Backed out r154357,r154358,r154360,r154361,r154364 because it still doesn't build, old files weren't renamed or removed, and the changes for bugref:10180 and bugref:4787 got mixed up, making it difficult to selectively revert the latter one only.

File:
1 edited

Legend:

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

    r97360 r97367  
    105105    { "viso",           VDTYPE_OPTICAL_DISC },
    106106    { NULL,             VDTYPE_INVALID      }
    107 };
    108 
    109 /** NULL-terminated array of configuration option. */
    110 static const VDCONFIGINFO s_aVisoConfigInfo[] =
    111 {
    112     /* Options for VMDK raw disks */
    113     { "UnattendedInstall",     NULL,    VDCFGVALUETYPE_STRING,  VD_CFGKEY_EXPERT },
    114     /* End of options list */
    115     { NULL,                    NULL,    VDCFGVALUETYPE_INTEGER, 0 }
    116107};
    117108
     
    524515}
    525516
    526 /**
    527  * Scans the VISO file and removes all references to files
    528  * which are in the same folder as the VISO and
    529  * whose names begin with "Unattended-".
    530  *
    531  * @return VBox status code.
    532  *
    533  * @param pThis Pointer to VISO backend data.
    534  */
    535 static int deleteReferences(PVISOIMAGE pThis)
    536 {
    537     /*
    538      * Open the file and read it into memory.
    539      */
    540     PVDIOSTORAGE pStorage = NULL;
    541     int vrc = vdIfIoIntFileOpen(pThis->pIfIo, pThis->pszFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE, &pStorage);
    542     if (RT_FAILURE(vrc))
    543     {
    544         LogRel(("VISO: Unable to open file '%s': %Rrc\n", pThis->pszFilename, vrc));
    545         return vrc;
    546     }
    547 
    548     LogRel(("VISO: Handling file '%s' references\n", pThis->pszFilename));
    549 
    550     /*
    551      * Read the file into memory.
    552      */
    553     uint64_t cbFile = 0;
    554     vrc = vdIfIoIntFileGetSize(pThis->pIfIo, pStorage, &cbFile);
    555     if (RT_SUCCESS(vrc))
    556     {
    557         if (cbFile <= VISO_MAX_FILE_SIZE)
    558         {
    559             char *pszContent = (char *)RTMemTmpAlloc(cbFile + 1);
    560             if (pszContent)
    561             {
    562                 vrc = vdIfIoIntFileReadSync(pThis->pIfIo, pStorage, 0 /*off*/, pszContent, (size_t)cbFile);
    563                 if (RT_SUCCESS(vrc))
    564                 {
    565                     /*
    566                      * Check the file marker.
    567                      * Ignore leading blanks.
    568                      */
    569                     pszContent[(size_t)cbFile] = '\0';
    570 
    571                     char *pszReadDst = pszContent;
    572                     while (RT_C_IS_SPACE(*pszReadDst))
    573                         pszReadDst++;
    574                     if (strncmp(pszReadDst, RT_STR_TUPLE("--iprt-iso-maker-file-marker")) == 0)
    575                     {
    576                         vrc = visoParseUuid(pszReadDst, &pThis->Uuid);
    577                         if (RT_SUCCESS(vrc))
    578                         {
    579                             /*
    580                              * Make sure it's valid UTF-8 before letting
    581                              */
    582                             vrc = RTStrValidateEncodingEx(pszContent, cbFile + 1,
    583                                                           RTSTR_VALIDATE_ENCODING_EXACT_LENGTH
    584                                                           | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);
    585                             if (RT_SUCCESS(vrc))
    586                             {
    587                                 /*
    588                                  * Convert it into an argument vector.
    589                                  * Free the content afterwards to reduce memory pressure.
    590                                  */
    591                                 uint32_t fGetOpt = strncmp(pszReadDst, RT_STR_TUPLE("--iprt-iso-maker-file-marker-ms")) != 0
    592                                                  ? RTGETOPTARGV_CNV_QUOTE_BOURNE_SH : RTGETOPTARGV_CNV_QUOTE_MS_CRT;
    593                                 fGetOpt |= RTGETOPTARGV_CNV_MODIFY_INPUT;
    594                                 char **papszArgs;
    595                                 int    cArgs;
    596                                 vrc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszContent, fGetOpt, NULL);
    597 
    598                                 if (RT_SUCCESS(vrc))
    599                                 {
    600                                     for (int i = 0; i < cArgs; ++i)
    601                                     {
    602                                         char *pszArg = papszArgs[i];
    603                                         char *pszOffset = strrchr(pszArg, '=');
    604                                         if (pszOffset != NULL)
    605                                             pszArg = pszOffset + 1;
    606 
    607                                         /* if it isn't option */
    608                                         if (pszArg[0] != '-')
    609                                         {
    610                                             char *pszPath = RTPathAbsExDup(pThis->pszCwd, pszArg, 0);
    611                                             if (RTStrStartsWith((const char *)pszPath, pThis->pszCwd))
    612                                             {
    613                                                 char *pszFileName = RTPathFilename(pszPath);
    614                                                 if (   pszFileName != NULL
    615                                                     && RTStrStartsWith((const char *)pszFileName, "Unattended-"))
    616                                                 {
    617                                                     vrc = RTFileDelete(pszPath);
    618                                                     if (RT_SUCCESS(vrc))
    619                                                         LogRel(("VISO: file '%s' deleted\n", pszPath));
    620                                                     else
    621                                                         LogRel(("VISO: Failed to delete the file '%s' (%Rrc)\n", pszPath, vrc));
    622                                                     vrc = VINF_SUCCESS;
    623                                                 }
    624                                             }
    625                                             RTStrFree(pszPath);
    626                                         }
    627                                     }
    628                                     RTGetOptArgvFreeEx(papszArgs, fGetOpt);
    629                                     papszArgs = NULL;
    630                                 }
    631                                 else
    632                                     vdIfError(pThis->pIfError, vrc, RT_SRC_POS, "VISO: RTGetOptArgvFromString failed: %Rrc", vrc);
    633                             }
    634                             else
    635                                 vdIfError(pThis->pIfError, vrc, RT_SRC_POS, "VISO: Invalid file encoding");
    636                         }
    637                         else
    638                             vdIfError(pThis->pIfError, vrc, RT_SRC_POS, "VISO: Parsing UUID failed: %Rrc", vrc);
    639                     }
    640                     else
    641                         vrc = VERR_VD_GEN_INVALID_HEADER;
    642                 }
    643                 else
    644                     vdIfError(pThis->pIfError, vrc, RT_SRC_POS, "VISO: Reading file failed: %Rrc", vrc);
    645 
    646                 RTMemTmpFree(pszContent);
    647             }
    648             else
    649                 vrc = VERR_NO_TMP_MEMORY;
    650         }
    651         else
    652         {
    653             LogRel(("visoOpen: VERR_VD_INVALID_SIZE - cbFile=%#RX64 cbMaxFile=%#RX64\n",
    654                     cbFile, (uint64_t)VISO_MAX_FILE_SIZE));
    655             vrc = VERR_VD_INVALID_SIZE;
    656         }
    657     }
    658 
    659     if (RT_FAILURE(vrc))
    660         LogRel(("VISO: Handling of file '%s' failed with %Rrc\n", pThis->pszFilename, vrc));
    661 
    662     vdIfIoIntFileClose(pThis->pIfIo, pStorage);
    663     return vrc;
    664 }
    665 
    666 /**
    667 * @interface_method_impl{VDIMAGEBACKEND,pfnClose}
     517
     518/**
     519 * @interface_method_impl{VDIMAGEBACKEND,pfnClose}
    668520 */
    669521static DECLCALLBACK(int) visoClose(void *pBackendData, bool fDelete)
     
    675527    {
    676528        if (fDelete)
    677         {
    678             PVDINTERFACECONFIG pImgCfg = VDIfConfigGet(&pThis->pIfIo->Core);
    679 
    680             bool fUnattendedInstall = false;
    681             int vrc = VDCFGQueryBool(pImgCfg, "UnattendedInstall", &fUnattendedInstall);
    682 
    683             /*
    684             * The VISO created by unattended installer, so delete all generated files
    685             * included in the VISO. the file is considered generated if it is located
    686             * in the same folder as VISO and its name begins with "Unattended-"
    687             */
    688             if (RT_SUCCESS(vrc) && fUnattendedInstall)
    689                 deleteReferences(pThis);
    690529            vdIfIoIntFileDelete(pThis->pIfIo, pThis->pszFilename);
    691         }
    692530
    693531        if (pThis->hIsoFile != NIL_RTVFSFILE)
     
    1031869    g_aVBoXIsoMakerFileExtensions,
    1032870    /* paConfigInfo */
    1033     s_aVisoConfigInfo,
     871    NULL,
    1034872    /* pfnProbe */
    1035873    visoProbe,
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