VirtualBox

Changeset 75407 in vbox for trunk/include


Ignore:
Timestamp:
Nov 12, 2018 8:06:57 PM (6 years ago)
Author:
vboxsync
Message:

VBoxSharedFolders,VBoxService,VBoxTray: New go at auto mounting shared folders, now also at runtime. bugref:3544

  • Added three new functions to the shared folders service:
    1. query mountpoint and everything else about a shared folder.
    2. wait for folder (mappings) config changes.
    3. cancel such waits.
  • Relaxed some of the check wrt placeholder folders so that the GUI can succesfully make changes to a folder while it is being used. The old code would end up failing if the guest was using the folder because of a (placeholder) duplicate.
  • Ran into some weird weird flag passing between service.cpp and vbsfMappingsQuery via pClient->fu32Flags. Didn't make sense to me and clashed with a new flag I added for the wait cancellation, so I changed it to use a parameter (fOnlyAutoMounts) for the purpose.
  • Pointed out that vbsfMappingsQuery is weird in a the way it doesn't return an overflow indicator, meaning that the guest library wrapper's checks for VINF_BUFFER_OVERFLOW is pointless.
  • In VBoxService I've reimplemented the automounter subservice. Only tested with a windows 7 guest so far. Highlights:
    • Use host specified mount points / drive letters.
    • Adjust to changes in mapping configuration.
    • Mappings should be global on windows guests, given that VBoxService runs under the System user (only verified on Win7).
  • One TODO is that I would like to try relocate a mapping that's not on the specified mount point once the mount point is freed up.
  • VBoxTray no longer maps shared folder on startup.
Location:
trunk/include/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/VBoxGuestLib.h

    r74535 r75407  
    682682                                                  PVBGLR3SHAREDFOLDERMAPPING *ppaMappings, uint32_t *pcMappings);
    683683VBGLR3DECL(void)    VbglR3SharedFolderFreeMappings(PVBGLR3SHAREDFOLDERMAPPING paMappings);
    684 VBGLR3DECL(int)     VbglR3SharedFolderGetName(HGCMCLIENTID  idClient,uint32_t u32Root, char **ppszName);
    685 VBGLR3DECL(int)     VbglR3SharedFolderGetMountPrefix(char **ppszPrefix);
    686 VBGLR3DECL(int)     VbglR3SharedFolderGetMountDir(char **ppszDir);
     684VBGLR3DECL(int)     VbglR3SharedFolderGetName(HGCMCLIENTID  idClient,uint32_t u32Root, char **ppszName); /**< @todo r=bird: GET functions return the value, not a status code!*/
     685VBGLR3DECL(int)     VbglR3SharedFolderQueryFolderInfo(HGCMCLIENTID idClient, uint32_t idRoot, uint64_t fQueryFlags,
     686                                                      char **ppszName, char **ppszMountPoint,
     687                                                      uint64_t *pfFlags, uint32_t *puRootIdVersion);
     688VBGLR3DECL(int)     VbglR3SharedFolderWaitForMappingsChanges(HGCMCLIENTID idClient, uint32_t uPrevVersion, uint32_t *puCurVersion);
     689VBGLR3DECL(int)     VbglR3SharedFolderCancelMappingsChangesWaits(HGCMCLIENTID idClient);
     690
     691VBGLR3DECL(int)     VbglR3SharedFolderGetMountPrefix(char **ppszPrefix); /**< @todo r=bird: GET functions return the value, not a status code! */
     692VBGLR3DECL(int)     VbglR3SharedFolderGetMountDir(char **ppszDir);       /**< @todo r=bird: GET functions return the value, not a status code! */
    687693/** @}  */
    688694# endif /* VBOX_WITH_SHARED_FOLDERS defined */
  • trunk/include/VBox/shflsvc.h

    r75384 r75407  
    7777 * @{
    7878 */
    79 /** Query mappings changes. */
     79/** Query mappings changes.
     80 * @note Description is currently misleading, it will always return all
     81 *       current mappings with SHFL_MS_NEW status.  Only modification is the
     82 *       SHFL_MF_AUTOMOUNT flag that causes filtering out non-auto mounts. */
    8083#define SHFL_FN_QUERY_MAPPINGS      (1)
    81 /** Query mappings changes. */
     84/** Query the name of a map. */
    8285#define SHFL_FN_QUERY_MAP_NAME      (2)
    8386/** Open/create object. */
     
    118121 * @since VBox 4.0  */
    119122#define SHFL_FN_SET_SYMLINKS        (20)
     123/** Query information about a map.
     124 * @since VBox 6.0  */
     125#define SHFL_FN_QUERY_MAP_INFO      (21)
     126/** Wait for changes to the mappings.
     127 * @since VBox 6.0  */
     128#define SHFL_FN_WAIT_FOR_MAPPINGS_CHANGES       (22)
     129/** Cancel all waits for changes to the mappings for the calling client.
     130 * The wait calls will return VERR_CANCELLED.
     131 * @since VBox 6.0  */
     132#define SHFL_FN_CANCEL_MAPPINGS_CHANGES_WAITS   (23)
    120133/** @} */
    121134
     
    240253 * Helper for copying one string into another.
    241254 *
    242  * @returns pDst
    243  * @param   pDst        The destination string. Assumed to be the same size as
    244  *                      the source.
     255 * @returns IPRT status code.
     256 * @retval  VERR_BUFFER_OVERFLOW and pDst->u16Length set to source length.
     257 * @param   pDst        The destination string.
    245258 * @param   pSrc        The source string.
    246  */
    247 DECLINLINE(PSHFLSTRING) ShflStringCopy(PSHFLSTRING pDst, PCSHFLSTRING pSrc)
    248 {
     259 * @param   cbTerm      The size of the string terminator.
     260 */
     261DECLINLINE(int) ShflStringCopy(PSHFLSTRING pDst, PCSHFLSTRING pSrc, size_t cbTerm)
     262{
     263    int rc = VINF_SUCCESS;
     264    if (pDst->u16Size >= pSrc->u16Length + cbTerm)
     265    {
     266        memcpy(&pDst->String, &pSrc->String, pSrc->u16Length);
     267        switch (cbTerm)
     268        {
     269            default:
     270            case 2: pDst->String.ach[pSrc->u16Length + 1] = '\0'; RT_FALL_THROUGH();
     271            case 1: pDst->String.ach[pSrc->u16Length + 0] = '\0'; break;
     272            case 0: break;
     273        }
     274    }
     275    else
     276        rc = VERR_BUFFER_OVERFLOW;
    249277    pDst->u16Length = pSrc->u16Length;
    250     pDst->u16Size   = pSrc->u16Size;
    251     memcpy(&pDst->String, &pSrc->String, pSrc->u16Size);
    252     return pDst;
     278    return rc;
    253279}
    254280
     
    265291    PSHFLSTRING pDst = (PSHFLSTRING)RTMemAlloc(SHFLSTRING_HEADER_SIZE + pSrc->u16Size);
    266292    if (pDst)
    267         return ShflStringCopy(pDst, pSrc);
     293    {
     294        pDst->u16Length = pSrc->u16Length;
     295        pDst->u16Size   = pSrc->u16Size;
     296        memcpy(&pDst->String, &pSrc->String, pSrc->u16Size);
     297    }
    268298    return pDst;
    269299}
     
    355385    AssertMsgFailed(("rc=%Rrc cwcConversion=%#x\n", rc, cwcConversion));
    356386    return NULL;
     387}
     388
     389/**
     390 * Copies a UTF-8 string to a buffer as UTF-16.
     391 *
     392 * @returns IPRT status code.
     393 * @param   pDst        The destination buffer.
     394 * @param   pszSrc      The source string.
     395 * @param   cchSrc      The source string length, or RTSTR_MAX.
     396 */
     397DECLINLINE(int) ShflStringCopyUtf8AsUtf16(PSHFLSTRING pDst, const char *pszSrc, size_t cchSrc)
     398{
     399    int rc;
     400    size_t cwcDst = 0;
     401    if (pDst->u16Size >= sizeof(RTUTF16))
     402    {
     403        PRTUTF16 pwszDst = pDst->String.utf16;
     404        rc = RTStrToUtf16Ex(pszSrc, cchSrc, &pwszDst, pDst->u16Size / sizeof(RTUTF16), &cwcDst);
     405    }
     406    else
     407    {
     408        RTStrCalcUtf16LenEx(pszSrc, cchSrc, &cwcDst);
     409        rc = VERR_BUFFER_OVERFLOW;
     410    }
     411    pDst->u16Length = (uint16_t)(cwcDst * sizeof(RTUTF16));
     412    return rc != VERR_BUFFER_OVERFLOW || cwcDst < UINT16_MAX / sizeof(RTUTF16) ? rc : VERR_TOO_MUCH_DATA;
     413}
     414
     415/**
     416 * Copies a UTF-8 string buffer to another buffer as UTF-16
     417 *
     418 * @returns IPRT status code.
     419 * @param   pDst        The destination buffer (UTF-16).
     420 * @param   pSrc        The source buffer (UTF-8).
     421 */
     422DECLINLINE(int) ShflStringCopyUtf8BufAsUtf16(PSHFLSTRING pDst, PCSHFLSTRING pSrc)
     423{
     424    return ShflStringCopyUtf8AsUtf16(pDst, pSrc->String.ach, pSrc->u16Length);
     425}
     426
     427/**
     428 * Copies a UTF-16 string to a buffer as UTF-8
     429 *
     430 * @returns IPRT status code.
     431 * @param   pDst        The destination buffer.
     432 * @param   pwszSrc     The source string.
     433 * @param   cwcSrc      The source string length, or RTSTR_MAX.
     434 */
     435DECLINLINE(int) ShflStringCopyUtf16AsUtf8(PSHFLSTRING pDst, PCRTUTF16 pwszSrc, size_t cwcSrc)
     436{
     437    int rc;
     438    size_t cchDst = 0;
     439    if (pDst->u16Size > 0)
     440    {
     441        char *pszDst = pDst->String.ach;
     442        rc = RTUtf16ToUtf8Ex(pwszSrc, cwcSrc, &pszDst, pDst->u16Size, &cchDst);
     443    }
     444    else
     445    {
     446        RTUtf16CalcUtf8LenEx(pwszSrc, cwcSrc, &cchDst);
     447        rc = VERR_BUFFER_OVERFLOW;
     448    }
     449    pDst->u16Length = (uint16_t)cchDst;
     450    return rc != VERR_BUFFER_OVERFLOW || cchDst < UINT16_MAX ? rc : VERR_TOO_MUCH_DATA;
     451}
     452
     453/**
     454 * Copies a UTF-16 string buffer to another buffer as UTF-8
     455 *
     456 * @returns IPRT status code.
     457 * @param   pDst        The destination buffer (UTF-8).
     458 * @param   pSrc        The source buffer (UTF-16).
     459 */
     460DECLINLINE(int) ShflStringCopyUtf16BufAsUtf8(PSHFLSTRING pDst, PCSHFLSTRING pSrc)
     461{
     462    return ShflStringCopyUtf16AsUtf8(pDst, pSrc->String.utf16, pSrc->u16Length / sizeof(RTUTF16));
    357463}
    358464
     
    802908typedef struct _SHFLMAPPING
    803909{
    804     /** Mapping status. */
     910    /** Mapping status.
     911     * @note Currently always set to SHFL_MS_NEW.  */
    805912    uint32_t u32Status;
    806913    /** Root handle. */
     
    15581665
    15591666
     1667/** @name SHFL_FN_QUERY_MAP_INFO
     1668 * @{
     1669 */
     1670/** Query flag: Guest prefers drive letters as mount points. */
     1671#define SHFL_MIQF_DRIVE_LETTER      RT_BIT_64(0)
     1672/** Query flag: Guest prefers paths as mount points. */
     1673#define SHFL_MIQF_PATH              RT_BIT_64(1)
     1674
     1675/** Set if writable. */
     1676#define SHFL_MIF_WRITABLE           RT_BIT_64(0)
     1677/** Indicates that the mapping should be auto-mounted. */
     1678#define SHFL_MIF_AUTO_MOUNT         RT_BIT_64(1)
     1679/** Set if host is case insensitive. */
     1680#define SHFL_MIF_HOST_ICASE         RT_BIT_64(2)
     1681/** Set if guest is case insensitive. */
     1682#define SHFL_MIF_GUEST_ICASE        RT_BIT_64(3)
     1683/** Symbolic link creation is allowed. */
     1684#define SHFL_MIF_SYMLINK_CREATION   RT_BIT_64(4)
     1685
     1686/** Parameters structure. */
     1687typedef struct VBoxSFQueryMapInfo
     1688{
     1689    /** Common header. */
     1690    VBGLIOCHGCMCALL callInfo;
     1691    /** 32-bit, in: SHFLROOT - root handle of the mapping to query. */
     1692    HGCMFunctionParameter root;
     1693    /** pointer, in/out: SHFLSTRING buffer for the name. */
     1694    HGCMFunctionParameter name;
     1695    /** pointer, in/out: SHFLSTRING buffer for the auto mount point. */
     1696    HGCMFunctionParameter mountPoint;
     1697    /** 64-bit, in: SHFL_MIQF_XXX; out: SHFL_MIF_XXX. */
     1698    HGCMFunctionParameter flags;
     1699    /** 32-bit, out: Root ID version number - root handle reuse guard. */
     1700    HGCMFunctionParameter rootIdVersion;
     1701} VBoxSFQueryMapInfo;
     1702/** Number of parameters */
     1703#define SHFL_CPARMS_QUERY_MAP_INFO (5)
     1704/** @} */
     1705
     1706
     1707/** @name SHFL_FN_WAIT_FOR_MAPPINGS_CHANGES
     1708 *
     1709 * Returns VINF_SUCCESS on change and VINF_TRY_AGAIN when restored from saved
     1710 * state.  If the guest makes too many calls (max 64) VERR_OUT_OF_RESOURCES will
     1711 * be returned.
     1712 *
     1713 * @{
     1714 */
     1715/** Parameters structure. */
     1716typedef struct VBoxSFWaitForMappingsChanges
     1717{
     1718    /** Common header. */
     1719    VBGLIOCHGCMCALL callInfo;
     1720    /** 32-bit, in/out: The mappings configuration version.
     1721     * On input the client sets it to the last config it knows about, on return
     1722     * it holds the current version.  */
     1723    HGCMFunctionParameter version;
     1724} VBoxSFWaitForMappingsChanges;
     1725/** Number of parameters */
     1726#define SHFL_CPARMS_WAIT_FOR_MAPPINGS_CHANGES       (1)
     1727/** @} */
     1728
     1729
     1730/** @name SHFL_FN_CANCEL_MAPPINGS_CHANGES_WAITS
     1731 * @{
     1732 */
     1733/** Number of parameters */
     1734#define SHFL_CPARMS_CANCEL_MAPPINGS_CHANGES_WAITS   (0)
     1735/** @} */
     1736
    15601737
    15611738/** @name SHFL_FN_ADD_MAPPING
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette