shflhandle.cpp revision efb542e50386467c7bf5e4174935c828e7d6c685
039cd2c4871a00e51af909222a34695d9cec3000vboxsync * Shared Folders:
039cd2c4871a00e51af909222a34695d9cec3000vboxsync * Handles helper functions.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
039cd2c4871a00e51af909222a34695d9cec3000vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
039cd2c4871a00e51af909222a34695d9cec3000vboxsync * available from http://www.virtualbox.org. This file is free software;
039cd2c4871a00e51af909222a34695d9cec3000vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * additional information or have any questions.
039cd2c4871a00e51af909222a34695d9cec3000vboxsync * Very basic and primitive handle management. Should be sufficient for our needs.
039cd2c4871a00e51af909222a34695d9cec3000vboxsync * Handle allocation can be rather slow, but at least lookup is fast.
039cd2c4871a00e51af909222a34695d9cec3000vboxsynctypedef struct
039cd2c4871a00e51af909222a34695d9cec3000vboxsync pHandles = (SHFLINTHANDLE *)RTMemAllocZ (sizeof (SHFLINTHANDLE) * SHFLHANDLE_MAX);
039cd2c4871a00e51af909222a34695d9cec3000vboxsync /* Never return handle 0 */
039cd2c4871a00e51af909222a34695d9cec3000vboxsyncSHFLHANDLE vbsfAllocHandle(uint32_t uType, uintptr_t pvUserData)
039cd2c4871a00e51af909222a34695d9cec3000vboxsync Assert((uType & SHFL_HF_TYPE_MASK) != 0 && pvUserData);
039cd2c4871a00e51af909222a34695d9cec3000vboxsync /* Find next free handle */
039cd2c4871a00e51af909222a34695d9cec3000vboxsync /* Nice linear search */
039cd2c4871a00e51af909222a34695d9cec3000vboxsync for(handle=lastHandleIndex;handle<SHFLHANDLE_MAX;handle++)
039cd2c4871a00e51af909222a34695d9cec3000vboxsync /* Try once more from the start */
039cd2c4871a00e51af909222a34695d9cec3000vboxsync { /* Out of handles */
039cd2c4871a00e51af909222a34695d9cec3000vboxsync pHandles[handle].uFlags = (uType & SHFL_HF_TYPE_MASK) | SHFL_HF_VALID;
039cd2c4871a00e51af909222a34695d9cec3000vboxsync if (handle < SHFLHANDLE_MAX && (pHandles[handle].uFlags & SHFL_HF_VALID))
039cd2c4871a00e51af909222a34695d9cec3000vboxsyncuintptr_t vbsfQueryHandle(SHFLHANDLE handle, uint32_t uType)
039cd2c4871a00e51af909222a34695d9cec3000vboxsync if (handle < SHFLHANDLE_MAX && (pHandles[handle].uFlags & SHFL_HF_VALID))
039cd2c4871a00e51af909222a34695d9cec3000vboxsync SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)RTMemAllocZ (sizeof (SHFLFILEHANDLE));
039cd2c4871a00e51af909222a34695d9cec3000vboxsync return vbsfAllocHandle(pHandle->Header.u32Flags, (uintptr_t)pHandle);
039cd2c4871a00e51af909222a34695d9cec3000vboxsync SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)RTMemAllocZ (sizeof (SHFLFILEHANDLE));
039cd2c4871a00e51af909222a34695d9cec3000vboxsync return vbsfAllocHandle(pHandle->Header.u32Flags, (uintptr_t)pHandle);