VirtualBox

Changeset 106868 in vbox for trunk/src/VBox/GuestHost


Ignore:
Timestamp:
Nov 7, 2024 9:30:45 AM (2 months ago)
Author:
vboxsync
Message:

Windows driver installation: Reduced number of INF file opening/closing sequences by passing the INF handle instead of the file name to callback functions. bugref:10762

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/installation/VBoxWinDrvInst.cpp

    r106867 r106868  
    118118
    119119/** Function pointer for a general try INF section callback. */
    120 typedef int (*PFNVBOXWINDRVINST_TRYINFSECTION_CALLBACK)(PCRTUTF16 pwszInfPathAbs, PCRTUTF16 pwszSection, void *pvCtx);
     120typedef int (*PFNVBOXWINDRVINST_TRYINFSECTION_CALLBACK)(HINF hInf, PCRTUTF16 pwszSection, void *pvCtx);
    121121
    122122
     
    704704    /** Pointer to driver installer instance. */
    705705    PVBOXWINDRVINSTINTERNAL pThis;
    706     /** Weak pointer to INF file being handled. */
    707     PCRTUTF16               pwszInfFile;
    708706    /** Weak pointer to INF section being handled. */
    709707    PCRTUTF16               pwszSection;
     
    781779 * @returns VBox status code.
    782780 * @param   pCtx                Windows driver installer context.
    783  * @param   pwszInfPathAbs      Absolute path of INF file to use for [un]installation.
     781 * @param   hInf                Handle of INF file.
    784782 * @param   pwszSection         Section to invoke for [un]installation.
    785783 *                              If NULL, the "DefaultInstall" / "DefaultUninstall" section will be tried.
    786784 * @param   pfnCallback         Callback to invoke for each found section.
    787785 */
    788 static int vboxWinDrvTryInfSection(PVBOXWINDRVINSTINTERNAL pCtx, PCRTUTF16 pwszInfPathAbs, PCRTUTF16 pwszSection,
    789                                    PFNVBOXWINDRVINST_TRYINFSECTION_CALLBACK pfnCallback)
     786static int vboxWinDrvTryInfSectionEx(PVBOXWINDRVINSTINTERNAL pCtx, HINF hInf, PCRTUTF16 pwszSection,
     787                                     PFNVBOXWINDRVINST_TRYINFSECTION_CALLBACK pfnCallback)
    790788{
    791789    if (pwszSection)
     
    810808    };
    811809
    812     int rc = VINF_SUCCESS; /* Shut up MSVC. */
     810    int rc = VERR_NOT_FOUND;
    813811
    814812    for (size_t i = 0; i < RT_ELEMENTS(apwszTryInstallSections); i++)
     
    826824            AssertRCBreak(rc);
    827825
    828             rc = pfnCallback(pwszInfPathAbs, wszTrySection, pCtx /* pvCtx */);
     826            rc = pfnCallback(hInf, wszTrySection, pCtx /* pvCtx */);
    829827            if (RT_SUCCESS(rc))
    830828                break;
     
    854852
    855853/**
     854 * Generic function to for probing a list of well-known sections for [un]installation.
     855 *
     856 * Due to the nature of INF files this function tries different combinations of decorations (e.g. SectionName[.NTAMD64|.X86])
     857 * and invokes the given callback for the first found section.
     858 *
     859 * @returns VBox status code.
     860 * @param   pCtx                Windows driver installer context.
     861 * @param   pwszInfPathAbs      Absolute path of INF file to use for [un]installation.
     862 * @param   pwszSection         Section to invoke for [un]installation.
     863 *                              If NULL, the "DefaultInstall" / "DefaultUninstall" section will be tried.
     864 * @param   pfnCallback         Callback to invoke for each found section.
     865 */
     866static int vboxWinDrvTryInfSection(PVBOXWINDRVINSTINTERNAL pCtx, PCRTUTF16 pwszInfPathAbs, PCRTUTF16 pwszSection,
     867                                   PFNVBOXWINDRVINST_TRYINFSECTION_CALLBACK pfnCallback)
     868{
     869    HINF hInf;
     870    int rc = VBoxWinDrvInfOpen(pwszInfPathAbs, &hInf);
     871    if (RT_FAILURE(rc))
     872    {
     873        vboxWinDrvInstLogError(pCtx, "Unable to open INF file: %Rrc\n", rc);
     874        return rc;
     875    }
     876    vboxWinDrvInstLogVerbose(pCtx, 1, "INF file \"%ls\" opened", pwszInfPathAbs);
     877
     878    rc = vboxWinDrvTryInfSectionEx(pCtx, hInf, pwszSection, pfnCallback);
     879
     880    VBoxWinDrvInfClose(hInf);
     881    vboxWinDrvInstLogVerbose(pCtx, 1, "INF file \"%ls\" closed", pwszInfPathAbs);
     882
     883    return rc;
     884}
     885
     886/**
    856887 * Uninstalls a section of a given INF file.
    857888 *
     
    859890 * @retval  VERR_NOT_FOUND if the given section has not been found.
    860891 * @param   pCtx                Windows driver installer context.
    861  * @param   pwszInfFile         INF file to execute.
     892 * @param   hInf                Handle of INF file.
    862893 * @param   pwszSection         Section within INF file to uninstall.
    863894 *                              Can have a platform decoration (e.g. "Foobar.NTx86").
    864895 */
    865 static int vboxWinDrvUninstallInfSectionEx(PVBOXWINDRVINSTINTERNAL pCtx, PCRTUTF16 pwszInfFile, PCRTUTF16 pwszSection)
    866 {
    867     AssertPtrReturn(pwszInfFile, VERR_INVALID_POINTER);
     896static int vboxWinDrvUninstallInfSectionEx(PVBOXWINDRVINSTINTERNAL pCtx, HINF hInf, PCRTUTF16 pwszSection)
     897{
    868898    AssertPtrReturn(pwszSection, VERR_INVALID_POINTER);
    869899
     900    int rc = VINF_SUCCESS;
     901
    870902    vboxWinDrvInstLogInfo(pCtx, "Uninstalling INF section \"%ls\" ...", pwszSection);
    871 
    872     HINF hInf;
    873     int rc = VBoxWinDrvInfOpen(pwszInfFile, &hInf);
    874     if (RT_FAILURE(rc))
    875     {
    876         if (rc == VERR_FILE_NOT_FOUND)
    877             vboxWinDrvInstLogVerbose(pCtx, 1, "INF file not found anymore, skipping");
    878         else
    879             vboxWinDrvInstLogError(pCtx, "Unable to open INF file: %Rrc", rc);
    880         return rc;
    881     }
    882 
    883     vboxWinDrvInstLogVerbose(pCtx, 1, "INF file \"%ls\" successfully opened", pwszInfFile);
    884903
    885904    /*
     
    926945    }
    927946
    928     VBoxWinDrvInfClose(hInf);
    929 
    930     vboxWinDrvInstLogVerbose(pCtx, 1, "INF file \"%ls\" closed", pwszInfFile);
    931 
    932947    return rc;
    933948}
     
    939954 * @retval  VERR_NOT_FOUND if the given section has not been found.
    940955 * @param   pCtx                Windows driver installer context.
    941  * @param   pwszInfFile         INF file to execute.
     956 * @param   hInf                Handle of INF file.
    942957 * @param   pwszSection         Section within INF file to install.
    943958 *                              Can have a platform decoration (e.g. "Foobar.NTx86").
    944959 */
    945 static int vboxWinDrvInstallInfSectionEx(PVBOXWINDRVINSTINTERNAL pCtx, PCRTUTF16 pwszInfFile, PCRTUTF16 pwszSection)
    946 {
    947     AssertPtrReturn(pwszInfFile, VERR_INVALID_POINTER);
     960static int vboxWinDrvInstallInfSectionEx(PVBOXWINDRVINSTINTERNAL pCtx, HINF hInf, PCRTUTF16 pwszSection)
     961{
    948962    AssertPtrReturn(pwszSection, VERR_INVALID_POINTER);
    949963
     964    int rc = VINF_SUCCESS;
     965
    950966    vboxWinDrvInstLogInfo(pCtx, "Installing INF section \"%ls\" ...", pwszSection);
    951 
    952     HINF hInf;
    953     int rc = VBoxWinDrvInfOpen(pwszInfFile, &hInf);
    954     if (RT_FAILURE(rc))
    955     {
    956         vboxWinDrvInstLogError(pCtx, "Unable to open INF file: %Rrc\n", rc);
    957         return rc;
    958     }
    959 
    960     vboxWinDrvInstLogVerbose(pCtx, 1, "INF file \"%ls\" successfully opened", pwszInfFile);
    961967
    962968    VBOXDRVINSTINFCALLBACKCTX CallbackCtx;
    963969    RT_ZERO(CallbackCtx);
    964970    CallbackCtx.pThis = pCtx;
    965     CallbackCtx.pwszInfFile = pwszInfFile;
    966971    CallbackCtx.pwszSection = pwszSection;
    967972    CallbackCtx.pvSetupContext = SetupInitDefaultQueueCallback(NULL);
     
    10391044    }
    10401045
    1041     VBoxWinDrvInfClose(hInf);
    1042 
    1043     vboxWinDrvInstLogVerbose(pCtx, 1, "INF file \"%ls\" closed", pwszInfFile);
    1044 
    10451046    return rc;
    10461047}
     
    10611062                 || pParms->enmMode == VBOXWINDRVINSTMODE_UNINSTALL_INFSECTION, VERR_INVALID_PARAMETER);
    10621063
    1063     return vboxWinDrvInstallInfSectionEx(pCtx, pParms->pwszInfFile, pParms->u.ExecuteInf.pwszSection);
     1064    HINF hInf;
     1065    int rc = VBoxWinDrvInfOpen(pParms->pwszInfFile, &hInf);
     1066    if (RT_FAILURE(rc))
     1067    {
     1068        vboxWinDrvInstLogError(pCtx, "Unable to open INF file: %Rrc\n", rc);
     1069        return rc;
     1070    }
     1071
     1072    vboxWinDrvInstLogVerbose(pCtx, 1, "INF file \"%ls\" opened", pParms->pwszInfFile);
     1073
     1074    rc = vboxWinDrvInstallInfSectionEx(pCtx, hInf, pParms->u.ExecuteInf.pwszSection);
     1075
     1076    VBoxWinDrvInfClose(hInf);
     1077    vboxWinDrvInstLogVerbose(pCtx, 1, "INF file \"%ls\" closed", pParms->pwszInfFile);
     1078
     1079    return rc;
    10641080}
    10651081
     
    10681084 *
    10691085 * @returns VBox status code.
    1070  * @param   pwszInfPathAbs      Absolute path of INF file to use.
     1086 * @param   hInf                Handle of INF file to use.
    10711087 * @param   pwszSection         Section to invoke.
    10721088 * @param   pvCtx               User-supplied pointer. Usually PVBOXWINDRVINSTINTERNAL.
    10731089 */
    1074 DECLCALLBACK(int) vboxWinDrvInstallTryInfSectionCallback(PCRTUTF16 pwszInfPathAbs, PCRTUTF16 pwszSection, void *pvCtx)
     1090DECLCALLBACK(int) vboxWinDrvInstallTryInfSectionCallback(HINF hInf, PCRTUTF16 pwszSection, void *pvCtx)
    10751091{
    10761092    PVBOXWINDRVINSTINTERNAL pCtx = (PVBOXWINDRVINSTINTERNAL)pvCtx;
    10771093
    1078     return vboxWinDrvInstallInfSectionEx(pCtx, pwszInfPathAbs, pwszSection);
     1094    return vboxWinDrvInstallInfSectionEx(pCtx, hInf, pwszSection);
    10791095}
    10801096
     
    14171433 *
    14181434 * @returns VBox status code.
    1419  * @param   pwszInfPathAbs      Absolute path of INF file to use.
     1435 * @param   hInf                Handle to INF file.
    14201436 * @param   pwszSection         Section to invoke.
    14211437 * @param   pvCtx               User-supplied pointer. Usually PVBOXWINDRVINSTINTERNAL.
    14221438 */
    1423 DECLCALLBACK(int) vboxWinDrvUninstallTryInfSectionCallback(PCRTUTF16 pwszInfPathAbs, PCRTUTF16 pwszSection, void *pvCtx)
     1439DECLCALLBACK(int) vboxWinDrvUninstallTryInfSectionCallback(HINF hInf, PCRTUTF16 pwszSection, void *pvCtx)
    14241440{
    14251441    PVBOXWINDRVINSTINTERNAL pCtx = (PVBOXWINDRVINSTINTERNAL)pvCtx;
    14261442
    1427     return vboxWinDrvUninstallInfSectionEx(pCtx, pwszInfPathAbs, pwszSection);
     1443    return vboxWinDrvUninstallInfSectionEx(pCtx, hInf, pwszSection);
    14281444}
    14291445
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