HostImpl.cpp revision 38342f0883d4ea5c17b46c2bd44b55ea40b1dee1
7a33455519f76382026197f01d5cac3f6a98ed51vboxsync * VirtualBox COM class implementation: Host
7a33455519f76382026197f01d5cac3f6a98ed51vboxsync * Copyright (C) 2004-2013 Oracle Corporation
7a33455519f76382026197f01d5cac3f6a98ed51vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
7a33455519f76382026197f01d5cac3f6a98ed51vboxsync * available from http://www.virtualbox.org. This file is free software;
7a33455519f76382026197f01d5cac3f6a98ed51vboxsync * you can redistribute it and/or modify it under the terms of the GNU
7a33455519f76382026197f01d5cac3f6a98ed51vboxsync * General Public License (GPL) as published by the Free Software
7a33455519f76382026197f01d5cac3f6a98ed51vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
7a33455519f76382026197f01d5cac3f6a98ed51vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
7a33455519f76382026197f01d5cac3f6a98ed51vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
7a33455519f76382026197f01d5cac3f6a98ed51vboxsync// for some reason Windows burns in sdk\...\winsock.h if this isn't included first
7a33455519f76382026197f01d5cac3f6a98ed51vboxsync#endif // VBOX_WITH_USB
7a33455519f76382026197f01d5cac3f6a98ed51vboxsync#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
# include <set>
#ifdef VBOX_WITH_RESOURCE_USAGE_API
# include "PerformanceImpl.h"
#ifdef RT_OS_LINUX
# include <errno.h>
#ifdef RT_OS_SOLARIS
# include <fcntl.h>
# include <unistd.h>
# include <stropts.h>
# include <errno.h>
# include <limits.h>
# include <stdio.h>
# include <libdevinfo.h>
# ifdef VBOX_USE_LIBHAL
# include "vbox-libhal.h"
# include "solaris/DynLoadLibSolaris.h"
typedef struct SOLARISDVD
} SOLARISDVD;
#ifdef RT_OS_WINDOWS
# define _WIN32_DCOM
# include <windows.h>
# include <shellapi.h>
# define INITGUID
# include <guiddef.h>
# include <devguid.h>
# include <objbase.h>
//# include <setupapi.h>
# include <shlobj.h>
# include <cfgmgr32.h>
#ifdef RT_OS_DARWIN
#ifdef VBOX_WITH_CROGL
#ifndef RT_OS_WINDOWS
#ifdef RT_OS_SOLARIS
#ifdef VBOX_WITH_HOSTNETIF_API
# include "netif.h"
#include "VBox/com/MultiResult.h"
#include <stdio.h>
#include <algorithm>
Data()
fDVDDrivesListBuilt(false),
fFloppyDrivesListBuilt(false)
#ifdef VBOX_WITH_USB
bool fDVDDrivesListBuilt,
bool fVTSupported,
return BaseFinalConstruct();
uninit();
m = new Data();
#ifdef VBOX_WITH_USB
# if defined (RT_OS_DARWIN)
#ifdef VBOX_WITH_RESOURCE_USAGE_API
# if defined (RT_OS_DARWIN)
#if defined (RT_OS_WINDOWS)
m->fVTSupported = false;
m->fLongModeSupported = false;
m->fPAESupported = false;
m->fNestedPagingSupported = false;
m->fRecheckVTSupported = false;
if (ASMHasCpuId())
/* Note! This code is duplicated in SUPDrv.c and other places! */
#if defined(RT_OS_DARWIN) && ARCH_BITS == 32 /* darwin.x86 has some optimizations of 64-bit on 32-bit. */
int f64bitCapable = 0;
m->fVTSupported = true;
m->fVTSupported = true;
m->fNestedPagingSupported = true;
if (m->fVTSupported)
m->fNestedPagingSupported = true;
#ifdef VBOX_WITH_CROGL
m->f3DAccelerationSupported = false;
++it)
if (RT_FAILURE(r))
return S_OK;
#ifdef VBOX_WITH_RESOURCE_USAGE_API
#ifdef VBOX_WITH_USB
delete m->pUSBProxyService;
delete m->pHostPowerService;
#ifdef VBOX_WITH_USB
delete m->pHostDnsService;
m = NULL;
return rc;
return rc;
Assert(0);
return rc;
STDMETHODIMP Host::COMGETTER(NetworkInterfaces)(ComSafeArrayOut(IHostNetworkInterface*, aNetworkInterfaces))
return E_POINTER;
# ifdef VBOX_WITH_HOSTNETIF_API
if (rc)
return S_OK;
# if defined(RT_OS_DARWIN)
while (pEtherNICs)
if (SUCCEEDED(IfObj->init(Bstr(pEtherNICs->szName), Guid(pEtherNICs->Uuid), HostNetworkInterfaceType_Bridged)))
# ifndef VBOX_WITH_NETFLT
&pNc,
&lpszApp);
# ifdef VBOX_NETFLT_ONDEMAND_BIND
/* for the protocol-based approach for now we just get all miniports the MS_TCPIP protocol binds to */
# ifndef VBOX_WITH_HARDENING
if (uComponentStatus == 0)
if (sock >= 0)
return S_OK;
#ifdef VBOX_WITH_USB
# ifndef RT_OS_WINDOWS
STDMETHODIMP Host::COMGETTER(USBDeviceFilters)(ComSafeArrayOut(IHostUSBDeviceFilter*, aUSBDeviceFilters))
#ifdef VBOX_WITH_USB
return rc;
# ifndef RT_OS_WINDOWS
return S_OK;
return S_OK;
return E_NOTIMPL;
return S_OK;
return S_OK;
switch (aFeature)
case ProcessorFeature_PAE:
return setError(E_INVALIDARG, tr("The aFeature value %d (%#x) is out of range."), (int)aFeature, (int)aFeature);
if ( m->fRecheckVTSupported
m->fNestedPagingSupported = true;
switch (aFeature)
case ProcessorFeature_PAE:
AssertFailed();
return hrc;
return S_OK;
return E_FAIL;
return S_OK;
return E_FAIL;
return S_OK;
return S_OK;
return S_OK;
return S_OK;
#ifdef VBOX_WITH_CROGL
#ifdef DEBUG_misha
return hrc;
#ifdef VBOX_WITH_HOSTNETIF_API
if (RT_SUCCESS(r))
if (!*aHostNetworkInterface)
#if !defined(RT_OS_WINDOWS)
return S_OK;
return E_NOTIMPL;
#ifdef VBOX_WITH_HOSTNETIF_API
if (RT_SUCCESS(r))
return S_OK;
return E_NOTIMPL;
#ifdef VBOX_WITH_USB
return S_OK;
#ifdef VBOX_WITH_USB
clearError();
++it)
#ifdef VBOX_WITH_USB
clearError();
STDMETHODIMP Host::FindHostNetworkInterfaceByName(IN_BSTR name, IHostNetworkInterface **networkInterface)
#ifndef VBOX_WITH_HOSTNETIF_API
return E_NOTIMPL;
if (!name)
return E_INVALIDARG;
if (!networkInterface)
return E_POINTER;
return E_FAIL;
Bstr n;
if (n == name)
if (!found)
STDMETHODIMP Host::FindHostNetworkInterfaceById(IN_BSTR id, IHostNetworkInterface **networkInterface)
#ifndef VBOX_WITH_HOSTNETIF_API
return E_NOTIMPL;
return E_INVALIDARG;
if (!networkInterface)
return E_POINTER;
return E_FAIL;
Bstr g;
if (g == id)
if (!found)
#ifdef VBOX_WITH_HOSTNETIF_API
return E_FAIL;
return hr;
if (t == type)
return S_OK;
return E_NOTIMPL;
#ifdef VBOX_WITH_USB
aAddress);
return E_NOTIMPL;
#ifdef VBOX_WITH_USB
return E_NOTIMPL;
return S_OK;
STDMETHODIMP Host::COMGETTER(VideoInputDevices)(ComSafeArrayOut(IHostVideoInputDevice*, aVideoInputDevices))
return E_POINTER;
return hr;
#ifdef VBOX_WITH_USB
++it)
return rc;
#ifdef VBOX_WITH_USB
++it)
return S_OK;
bool fRefresh,
switch (mediumType)
case DeviceType_DVD:
return rc;
case DeviceType_Floppy:
return rc;
return E_INVALIDARG;
if (pfListBuilt)
if (!*pfListBuilt)
*pfListBuilt = true;
bool fFound = false;
++itNew)
fFound = true;
if (!fFound)
++itCached;
++itNew)
bool fFound = false;
++itCached)
fFound = true;
if (!fFound)
return rc;
bool fRefresh,
++it)
return S_OK;
return VBOX_E_OBJECT_NOT_FOUND;
bool fRefresh,
++it)
return S_OK;
return VBOX_E_OBJECT_NOT_FOUND;
#if defined(RT_OS_WINDOWS)
driveName[0] = *p;
delete[] hostDrives;
# ifdef VBOX_USE_LIBHAL
while (cur)
return rc;
#ifdef RT_OS_WINDOWS
driveName[0] = *p;
delete[] hostDrives;
return rc;
#ifdef VBOX_WITH_USB
return m->pUSBProxyService;
return S_OK;
++it)
return S_OK;
return m->pParent;
if (aActiveChanged)
return S_OK;
* @param pszDevLinkPath Pointer to a device path (/dev/(r)dsk/c7d1t0d0s3 etc.)
return pszFound;
return NULL;
return DI_WALK_TERMINATE;
* Check for "removable-media" or "hotpluggable" instead of "SCSI" so that we also include USB CD-ROMs.
if (DevLink)
if (!pszMinorPath)
if (pszDevLinkPath)
if (*ppDrives)
return DI_WALK_CONTINUE;
while (pDrives)
hostDVDDriveObj->init(m->pParent, DeviceType_DVD, Bstr(pDrives->szRawDiskPath), Bstr(pDrives->szDescription));
bool halSuccess = false;
if (!gLibHalCheckPresence())
if (dbusConnection != 0)
if (halContext != 0)
int numDevices;
if (halDevices != 0)
halSuccess = true;
for (int i = 0; i < numDevices; i++)
#ifdef RT_OS_SOLARIS
if (devNode != 0)
if (product == 0)
LogRel(("Host::COMGETTER(DVDDrives): failed to get property \"info.product\" for device %s. dbus error: %s (%s)\n",
if (vendor != 0)
if (product != 0)
#ifndef RT_OS_SOLARIS
LogRel(("Host::COMGETTER(DVDDrives): failed to get property \"block.device\" for device %s. dbus error: %s (%s)\n",
LogRel(("Host::COMGETTER(DVDDrives): failed to get devices with capability \"storage.cdrom\". dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(DVDDrives): failed to shutdown the libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(DVDDrives): failed to initialise libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(DVDDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
return halSuccess;
bool halSuccess = false;
if (!gLibHalCheckPresence())
if (dbusConnection != 0)
if (halContext != 0)
int numDevices;
if (halDevices != 0)
halSuccess = true;
for (int i = 0; i < numDevices; i++)
if (driveType != 0)
if (devNode != 0)
if (product == 0)
LogRel(("Host::COMGETTER(FloppyDrives): failed to get property \"info.product\" for device %s. dbus error: %s (%s)\n",
if (vendor != 0)
if (product != 0)
// LogRel(("Host::COMGETTER(FloppyDrives): failed to validate the block device %s as a floppy drive\n"));
LogRel(("Host::COMGETTER(FloppyDrives): failed to get property \"block.device\" for device %s. dbus error: %s (%s)\n",
LogRel(("Host::COMGETTER(FloppyDrives): failed to get devices with capability \"storage.cdrom\". dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(FloppyDrives): failed to shutdown the libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(FloppyDrives): failed to initialise libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(FloppyDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
return halSuccess;
#if defined(RT_OS_SOLARIS)
#ifdef RT_OS_LINUX
if (mtab)
char *mnt_type;
char *mnt_dev;
char *tmp;
if (tmp)
if (mnt_type)
if (tmp)
if (tmp)
if (mnt_dev)
if (tmp)
if (mntFile)
bool retValue = false;
if (!deviceNode)
if (isCDROM)
int fileHandle;
if (fileHandle >= 0)
#ifdef RT_OS_LINUX
retValue = true;
retValue = true;
return retValue;
#ifdef VBOX_WITH_USB
tr("Could not load the Host USB Proxy Service (VERR_FILE_NOT_FOUND). The service might not be installed on the host computer"));
tr("VirtualBox is not currently allowed to access USB devices. You can change this by adding your user to the 'vboxusers' group. Please see the user manual for a more detailed explanation"));
tr("VirtualBox is not currently allowed to access USB devices. You can change this by allowing your user to access the 'usbfs' folder and files. Please see the user manual for a more detailed explanation"));
case VINF_SUCCESS:
return S_OK;
#ifdef VBOX_WITH_HOSTNETIF_API
if (rc)
return E_FAIL;
# ifdef VBOX_WITH_RESOURCE_USAGE_API
bool fGone = true;
fGone = false;
if (fGone)
# ifdef VBOX_WITH_RESOURCE_USAGE_API
Bstr n;
else if (t == HostNetworkInterfaceType_Bridged)
# ifdef VBOX_WITH_RESOURCE_USAGE_API
return S_OK;
return E_NOTIMPL;
#ifdef VBOX_WITH_RESOURCE_USAGE_API