shflhandle.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
/** @file
*
* Shared Folders:
* Handles helper functions.
*/
/*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "shflhandle.h"
#include <iprt/critsect.h>
/*
* Very basic and primitive handle management. Should be sufficient for our needs.
* Handle allocation can be rather slow, but at least lookup is fast.
*
*/
typedef struct
{
static int32_t lastHandleIndex = 0;
static RTCRITSECT lock;
int vbsfInitHandleTable()
{
{
AssertFailed();
return VERR_NO_MEMORY;
}
/* Never return handle 0 */
lastHandleIndex = 1;
return RTCritSectInit(&lock);
}
int vbsfFreeHandleTable()
{
if (pHandles)
if (RTCritSectIsInitialized(&lock))
return VINF_SUCCESS;
}
{
/* Find next free handle */
{
lastHandleIndex = 1;
}
/* Nice linear search */
{
{
break;
}
}
if(handle == SHFLHANDLE_MAX)
{
/* Try once more from the start */
{
{
break;
}
}
if(handle == SHFLHANDLE_MAX)
{ /* Out of handles */
AssertFailed();
return SHFL_HANDLE_NIL;
}
}
return handle;
}
{
{
return VINF_SUCCESS;
}
return VERR_INVALID_HANDLE;
}
{
{
}
return 0;
}
SHFLHANDLE vbsfAllocDirHandle (void)
{
if (pHandle)
{
}
return SHFL_HANDLE_NIL;
}
SHFLHANDLE vbsfAllocFileHandle (void)
{
if (pHandle)
{
}
return SHFL_HANDLE_NIL;
}
{
SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(hHandle, SHFL_HF_TYPE_DIR|SHFL_HF_TYPE_FILE);
if (pHandle)
{
}
else
AssertFailed();
return;
}