VirtualBox

Changeset 23419 in vbox


Ignore:
Timestamp:
Sep 29, 2009 4:20:29 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
52987
Message:

Main/ConsoleImpl: make DVD attachments at runtime work. floppy still untested

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r23379 r23419  
    27262726    unsigned uInstance = 0;
    27272727    unsigned uLun = 0;
     2728    BOOL fHostDrive = FALSE;
    27282729    Utf8Str location;
     2730    Utf8Str format;
    27292731    BOOL fPassthrough = FALSE;
    27302732
     
    27802782        AssertComRC(rc);
    27812783        location = loc;
     2784        Bstr fmt;
     2785        rc = medium->COMGETTER(Format)(fmt.asOutParam());
     2786        AssertComRC(rc);
     2787        format = fmt;
     2788        rc = medium->COMGETTER(HostDrive)(&fHostDrive);
     2789        AssertComRC(rc);
    27822790    }
    27832791    rc = aMediumAttachment->COMGETTER(Passthrough)(&fPassthrough);
     
    27952803    PVMREQ pReq;
    27962804    int vrc = VMR3ReqCall(mpVM, VMCPUID_ANY, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
    2797                           (PFNRT)Console::changeDrive, 6,
    2798                           this, pszDevice, uInstance, uLun, location.raw(), fPassthrough);
     2805                          (PFNRT)Console::changeDrive, 8,
     2806                          this, pszDevice, uInstance, uLun, !!fHostDrive, location.raw(), format.raw(), !!fPassthrough);
    27992807
    28002808    /* leave the lock before waiting for a result (EMT will call us back!) */
     
    28352843 * @param   uInstance       The PDM device instance.
    28362844 * @param   uLun            The PDM LUN number of the drive.
    2837  * @param   eState          The new state.
    2838  * @param   peState         Pointer to the variable keeping the actual state of the drive.
    2839  *                          This will be both read and updated to eState or other appropriate state.
     2845 * @param   fHostDrive      True if this is a host drive attachment.
    28402846 * @param   pszPath         The path to the media / drive which is now being mounted / captured.
    28412847 *                          If NULL no media or drive is attached and the LUN will be configured with
    28422848 *                          the default block driver with no media. This will also be the state if
    28432849 *                          mounting / capturing the specified media / drive fails.
     2850 * @param   pszFormat       Medium format string, usually "RAW".
    28442851 * @param   fPassthrough    Enables using passthrough mode of the host DVD drive if applicable.
    28452852 *
     
    28492856 */
    28502857DECLCALLBACK(int) Console::changeDrive(Console *pThis, const char *pszDevice, unsigned uInstance, unsigned uLun,
    2851                                        const char *pszPath, bool fPassthrough)
     2858                                       bool fHostDrive, const char *pszPath, const char *pszFormat, bool fPassthrough)
    28522859{
    28532860/// @todo change this to use the same code as in ConsoleImpl2.cpp
    2854     LogFlowFunc(("pThis=%p pszDevice=%p:{%s} uInstance=%u uLun=%u pszPath=%p:{%s} fPassthrough=%d\n",
    2855                  pThis, pszDevice, pszDevice, uInstance, uLun, pszPath, pszPath, fPassthrough));
     2861    LogFlowFunc(("pThis=%p pszDevice=%p:{%s} uInstance=%u uLun=%u fHostDrive=%d pszPath=%p:{%s} pszFormat=%p:{%s} fPassthrough=%d\n",
     2862                 pThis, pszDevice, pszDevice, uInstance, uLun, fHostDrive, pszPath, pszPath, pszFormat, pszFormat, fPassthrough));
    28562863
    28572864    AssertReturn(pThis, VERR_INVALID_PARAMETER);
     
    29182925         * Unmount existing media / detach host drive.
    29192926         */
    2920         PPDMIMOUNT pIMount = NULL;
    29212927        PPDMIBASE pBase;
    29222928        rc = PDMR3QueryLun(pVM, pszDevice, uInstance, uLun, &pBase);
    29232929        if (RT_FAILURE(rc))
    29242930        {
    2925             if (rc == VERR_PDM_LUN_NOT_FOUND)
     2931            if (rc == VERR_PDM_LUN_NOT_FOUND || rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
    29262932                rc = VINF_SUCCESS;
    29272933            AssertRC(rc);
     
    29292935        else
    29302936        {
     2937            PPDMIMOUNT pIMount = NULL;
    29312938            pIMount = (PPDMIMOUNT) pBase->pfnQueryInterface(pBase, PDMINTERFACE_MOUNT);
    29322939            AssertBreakStmt(pIMount, rc = VERR_INVALID_POINTER);
     
    29382945            if (rc == VERR_PDM_MEDIA_NOT_MOUNTED)
    29392946                rc = VINF_SUCCESS;
     2947
     2948            if (RT_SUCCESS(rc))
     2949            {
     2950                rc = PDMR3DeviceDetach(pVM, pszDevice, uInstance, uLun, PDM_TACH_FLAGS_NOT_HOT_PLUG);
     2951                if (rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
     2952                    rc = VINF_SUCCESS;
     2953            }
    29402954        }
    29412955
     
    29452959            break;
    29462960        }
     2961
     2962        /** @todo this does a very thorough job. usually it's too much,
     2963         * as a simple medium change (without changing between host attachment
     2964         * and image) could be done with a lot less effort, by just using the
     2965         * pfnUnmount and pfnMount interfaces. Later. */
    29472966
    29482967        /*
     
    29562975#define RC_CHECK() do { if (RT_FAILURE(rc)) { AssertReleaseRC(rc); break; } } while (0)
    29572976
    2958         /* create a new block driver config */
    29592977        PCFGMNODE pLunL0;
     2978        PCFGMNODE pCfg;
    29602979        rc = CFGMR3InsertNodeF(pInst, &pLunL0, "LUN#%d", uLun);     RC_CHECK();
    2961         rc = CFGMR3InsertString(pLunL0, "Driver",       "Block");   RC_CHECK();
    2962         PCFGMNODE pCfg;
    2963         rc = CFGMR3InsertNode(pLunL0,   "Config",       &pCfg);     RC_CHECK();
    2964         rc = CFGMR3InsertString(pCfg,   "Type",         !strcmp(pszDevice, "i82078") ? "Floppy 1.44" : "DVD"); RC_CHECK();
    2965         rc = CFGMR3InsertInteger(pCfg,  "Mountable",    1);         RC_CHECK();
     2980
     2981        if (fHostDrive)
     2982        {
     2983            rc = CFGMR3InsertString(pLunL0, "Driver",       !strcmp(pszDevice, "i82078") ? "HostFloppy" : "HostDVD");   RC_CHECK();
     2984            rc = CFGMR3InsertNode(pLunL0,   "Config",       &pCfg);     RC_CHECK();
     2985            Assert(!pszPath && !*pszPath);
     2986            rc = CFGMR3InsertString(pCfg,   "Path",         pszPath);   RC_CHECK();
     2987            if (strcmp(pszDevice, "i82078"))
     2988            {
     2989                rc = CFGMR3InsertInteger(pCfg, "Passthrough", fPassthrough); RC_CHECK();
     2990            }
     2991        }
     2992        else
     2993        {
     2994            /* create a new block driver config */
     2995            rc = CFGMR3InsertString(pLunL0, "Driver",       "Block");   RC_CHECK();
     2996            rc = CFGMR3InsertNode(pLunL0,   "Config",       &pCfg);     RC_CHECK();
     2997            rc = CFGMR3InsertString(pCfg,   "Type",         !strcmp(pszDevice, "i82078") ? "Floppy 1.44" : "DVD"); RC_CHECK();
     2998            rc = CFGMR3InsertInteger(pCfg,  "Mountable",    1);         RC_CHECK();
     2999        }
    29663000
    29673001        /*
     
    29693003         */
    29703004        rc = PDMR3DeviceAttach(pVM, pszDevice, uInstance, uLun, PDM_TACH_FLAGS_NOT_HOT_PLUG, &pBase); RC_CHECK();
    2971         pIMount = (PPDMIMOUNT) pBase->pfnQueryInterface(pBase, PDMINTERFACE_MOUNT);
    2972         if (!pIMount)
    2973         {
    2974             AssertFailed();
    2975             return rc;
    2976         }
    2977 
    2978         /*
    2979          * If we've got an image, let's mount it.
    2980          */
    2981         if (pszPath && *pszPath)
    2982         {
    2983             rc = pIMount->pfnMount(pIMount, pszPath, strcmp(pszDevice, "i82078") ? "MediaISO" : "RawImage");
    2984         }
     3005
     3006        if (!fHostDrive && pszPath && *pszPath)
     3007        {
     3008            PCFGMNODE pLunL1;
     3009            rc = CFGMR3InsertNode(pLunL0,   "AttachedDriver", &pLunL1); RC_CHECK();
     3010            rc = CFGMR3InsertString(pLunL1, "Driver",       "VD");      RC_CHECK();
     3011            rc = CFGMR3InsertNode(pLunL1,   "Config",       &pCfg);     RC_CHECK();
     3012            rc = CFGMR3InsertString(pCfg,   "Path",         pszPath);   RC_CHECK();
     3013            rc = CFGMR3InsertString(pCfg,   "Format",       pszFormat); RC_CHECK();
     3014            if (strcmp(pszDevice, "i82078"))
     3015            {
     3016                rc = CFGMR3InsertInteger(pCfg, "ReadOnly",  1);         RC_CHECK();
     3017            }
     3018            /** @todo later pass full VDConfig information and parent images */
     3019
     3020            PPDMIMOUNT pIMount = NULL;
     3021            pIMount = (PPDMIMOUNT) pBase->pfnQueryInterface(pBase, PDMINTERFACE_MOUNT);
     3022            if (!pIMount)
     3023            {
     3024                AssertFailed();
     3025                return rc;
     3026            }
     3027
     3028LogRelFunc(("mounting new medium\n"));
     3029            rc = pIMount->pfnMount(pIMount, NULL , NULL);
     3030        }
     3031CFGMR3Dump(pInst);
    29853032
    29863033#undef RC_CHECK
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r23223 r23419  
    438438    static DECLCALLBACK(int) changeDrive (Console *pThis, const char *pszDevice,
    439439                                          unsigned uInstance, unsigned uLun,
    440                                           const char *pszPath, bool fPassthrough);
     440                                          bool fHostDrive, const char *pszPath,
     441                                          const char *pszFormat, bool fPassthrough);
    441442    const char *controllerTypeToDev(StorageControllerType_T enmCtrlType);
    442443    HRESULT convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
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