USBLib-solaris.cpp revision 59190ecd61435d19ba3515b876272aee7bd12298
/** $Id$ */
/** @file
* USBLib - Library for wrapping up the VBoxUSB functionality, Solaris flavor.
*/
/*
* Copyright (C) 2008 Oracle Corporation
*
* Oracle Corporation confidential
* All rights reserved
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
# include <errno.h>
# include <unistd.h>
# include <string.h>
# include <limits.h>
# include <strings.h>
/** -XXX- Remove this hackery eventually */
#ifdef DEBUG_ramshankar
#endif
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Logging class. */
#define USBLIBR3 "USBLibR3"
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Reference counter. */
/** VBoxUSB Device handle. */
/** List of tasks handled by the USB helper. */
typedef enum USBHELPER_OP
{
ADD_ALIAS = 0,
};
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
USBLIB_DECL(int) USBLibInit(void)
{
/*
* Already open?
* This isn't properly serialized, but we'll be fine with the current usage.
*/
if (g_cUsers)
{
return VINF_SUCCESS;
}
int rc = RTFileOpen(&File, VBOXUSB_DEVICE_NAME, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Check the USBMonitor version.
*/
if (RT_SUCCESS(rc))
{
{
g_File = NIL_RTFILE;
return rc;
}
}
else
{
g_File = NIL_RTFILE;
return rc;
}
#endif
return VINF_SUCCESS;
}
USBLIB_DECL(int) USBLibTerm(void)
{
if (!g_cUsers)
return VERR_WRONG_ORDER;
if (ASMAtomicDecU32(&g_cUsers) != 0)
return VINF_SUCCESS;
/*
* We're the last guy, close down the connection.
*/
g_File = NIL_RTFILE;
if (File == NIL_RTFILE)
return VERR_INTERNAL_ERROR;
return rc;
}
{
if (RT_SUCCESS(rc))
return NULL;
}
{
if (RT_SUCCESS(rc))
return;
}
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
return VINF_SUCCESS;
LogRel((USBLIBR3 ":USBLibGetClientInfo RTStrAPrintf failed! rc=%Rrc achClientPath=%s\n", rc, Req.achClientPath));
}
else
return rc;
}
#else
{
LogFlow((USBLIBR3 ":USBLibDeviceInstance pszDevicePath=%s pInstance=%p\n", pszDevicePath, pInstance));
if (RT_UNLIKELY(!pReq))
return VERR_NO_MEMORY;
if (RT_FAILURE(rc))
return rc;
}
#endif
#if 1
{
if (RT_UNLIKELY(!pReq))
return VERR_NO_MEMORY;
if (RT_FAILURE(rc))
return rc;
}
#else
{
}
#endif
{
}
{
}
#if 0
{
}
#endif
{
/*
* Find VBoxUSBHelper.
*/
char szDriverCtl[PATH_MAX];
if (RT_SUCCESS(rc))
{
if (!RTPathExists(szDriverCtl))
{
LogRel(("USBProxy: path %s does not exist. Failed to run USB helper %s.\n", szDriverCtl, VBOXUSB_HELPER_NAME));
return VERR_FILE_NOT_FOUND;
}
/*
* Run VBoxUSBHelper task.
*/
const char *pszArgs[5];
{
pszArgs[0] = szDriverCtl;
}
else
{
char szDriverAlias[128];
#if 0
/*
* USB vid.pid.rev driver binding alias.
*/
RTStrPrintf(szDriverAlias, sizeof(szDriverAlias), "usb%x,%x.%x", pData->idVendor, pData->idProduct, pData->bcdDevice);
#else
/*
* Path based driver binding alias.
*/
#endif
pszArgs[0] = szDriverCtl;
}
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
{
{
case 0: return VINF_SUCCESS; /* @todo later maybe ignore -4 as well (see VBoxUSBHelper return codes). */
case -1: return VERR_PERMISSION_DENIED;
case -2: return VERR_INVALID_PARAMETER;
case -3: return VERR_GENERAL_FAILURE;
default: return VERR_INTERNAL_ERROR;
}
}
else
}
else
}
else
{
/* Bad. RTProcCreate() failed! */
}
}
return rc;
}
{
if (g_File == NIL_RTFILE)
{
return VERR_FILE_NOT_FOUND;
}
if (rc < 0)
{
return RTErrConvertFromErrno(rc);
}
return rc;
}