VirtualBox

Changeset 78467 in vbox


Ignore:
Timestamp:
May 11, 2019 1:04:24 AM (6 years ago)
Author:
vboxsync
Message:

SharedFoldersSvc: Adding an alternative remove function that also closes the handle so that windows guests can combine two host calls and speed up deletion. bugref:9172

Location:
trunk
Files:
4 edited

Legend:

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

    r77858 r78467  
    148148 * @since VBox 6.0.6  */
    149149#define SHFL_FN_COPY_FILE_PART      (27)
     150/** Close handle to (optional) and remove object by path.
     151 * This function is tailored for Windows guests.
     152 * @since VBox 6.0.8  */
     153#define SHFL_FN_CLOSE_AND_REMOVE    (28)
    150154/** The last function number. */
    151 #define SHFL_FN_LAST                SHFL_FN_COPY_FILE_PART
     155#define SHFL_FN_LAST                SHFL_FN_CLOSE_AND_REMOVE
    152156/** @} */
    153157
     
    17801784
    17811785
     1786/** @name SHFL_FN_CLOSE_AND_REMOVE
     1787 * Extends SHFL_FN_REMOVE with a 4th handle parameter that can be nil.
     1788 * @{
     1789 */
     1790/** SHFL_FN_CLOSE_AND_REMOVE parameters. */
     1791typedef struct VBoxSFParmCloseAndRemove
     1792#ifdef __cplusplus
     1793    : public VBoxSFParmRemove
     1794#endif
     1795{
     1796#ifndef __cplusplus
     1797    VBoxSFParmRemove      Core;
     1798#endif
     1799    /** value64, in: SHFLHANDLE to the object to be removed & close, optional. */
     1800    HGCMFunctionParameter u64Handle;
     1801} VBoxSFParmCloseAndRemove;
     1802/** Number of parameters */
     1803#define SHFL_CPARMS_CLOSE_AND_REMOVE    (4)
     1804AssertCompileSize(VBoxSFParmCloseAndRemove, SHFL_CPARMS_CLOSE_AND_REMOVE * sizeof(HGCMFunctionParameter));
     1805/** @} */
     1806
     1807
    17821808/** @name SHFL_FN_RENAME
    17831809 * @{
  • trunk/src/VBox/HostServices/SharedFolders/VBoxSharedFoldersSvc.cpp

    r77852 r78467  
    8686static STAMPROFILE g_StatRemove;
    8787static STAMPROFILE g_StatRemoveFail;
     88static STAMPROFILE g_StatCloseAndRemove;
     89static STAMPROFILE g_StatCloseAndRemoveFail;
    8890static STAMPROFILE g_StatRename;
    8991static STAMPROFILE g_StatRenameFail;
     
    12141216
    12151217            /* Verify parameter count and types. */
    1216             if (cParms != SHFL_CPARMS_REMOVE)
    1217             {
    1218                 rc = VERR_INVALID_PARAMETER;
    1219             }
    1220             else if (   paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT   /* root */
    1221                      || paParms[1].type != VBOX_HGCM_SVC_PARM_PTR   /* path */
    1222                      || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* flags */
    1223                     )
    1224             {
    1225                 rc = VERR_INVALID_PARAMETER;
    1226             }
    1227             else
    1228             {
    1229                 /* Fetch parameters. */
    1230                 SHFLROOT  root          = (SHFLROOT)paParms[0].u.uint32;
    1231                 SHFLSTRING *pPath       = (SHFLSTRING *)paParms[1].u.pointer.addr;
    1232                 uint32_t cbPath         = paParms[1].u.pointer.size;
    1233                 uint32_t flags          = paParms[2].u.uint32;
    1234 
    1235                 /* Verify parameters values. */
    1236                 if (!ShflStringIsValidIn(pPath, cbPath, RT_BOOL(pClient->fu32Flags & SHFL_CF_UTF8)))
    1237                 {
    1238                     rc = VERR_INVALID_PARAMETER;
    1239                 }
    1240                 else
    1241                 {
    1242                     /* Execute the function. */
    1243                     rc = vbsfRemove (pClient, root, pPath, cbPath, flags);
    1244                     if (RT_SUCCESS(rc))
    1245                     {
    1246                         /* Update parameters.*/
    1247                         ; /* none */
    1248                     }
    1249                 }
    1250             }
     1218            ASSERT_GUEST_STMT_BREAK(cParms == SHFL_CPARMS_REMOVE, rc = VERR_WRONG_PARAMETER_COUNT);
     1219            ASSERT_GUEST_STMT_BREAK(paParms[0].type == VBOX_HGCM_SVC_PARM_32BIT, rc = VERR_WRONG_PARAMETER_TYPE); /* root */
     1220            ASSERT_GUEST_STMT_BREAK(paParms[1].type == VBOX_HGCM_SVC_PARM_PTR,   rc = VERR_WRONG_PARAMETER_TYPE); /* path */
     1221            PCSHFLSTRING pStrPath = (PCSHFLSTRING)paParms[1].u.pointer.addr;
     1222            ASSERT_GUEST_STMT_BREAK(ShflStringIsValidIn(pStrPath, paParms[1].u.pointer.size,
     1223                                                        RT_BOOL(pClient->fu32Flags & SHFL_CF_UTF8)),
     1224                                    rc = VERR_INVALID_PARAMETER);
     1225            ASSERT_GUEST_STMT_BREAK(paParms[2].type == VBOX_HGCM_SVC_PARM_32BIT, rc = VERR_WRONG_PARAMETER_TYPE); /* flags */
     1226            uint32_t const fFlags = paParms[2].u.uint32;
     1227            ASSERT_GUEST_STMT_BREAK(!(fFlags & ~(SHFL_REMOVE_FILE | SHFL_REMOVE_DIR | SHFL_REMOVE_SYMLINK)),
     1228                                    rc = VERR_INVALID_FLAGS);
     1229
     1230            /* Execute the function. */
     1231            rc = vbsfRemove(pClient, paParms[0].u.uint32, pStrPath, paParms[1].u.pointer.size, fFlags, SHFL_HANDLE_NIL);
     1232            break;
     1233        }
     1234
     1235        case SHFL_FN_CLOSE_AND_REMOVE:
     1236        {
     1237            pStat     = &g_StatCloseAndRemove;
     1238            pStatFail = &g_StatCloseAndRemoveFail;
     1239            Log(("SharedFolders host service: svcCall: SHFL_FN_CLOSE_AND_REMOVE\n"));
     1240
     1241            /* Verify parameter count and types. */
     1242            ASSERT_GUEST_STMT_BREAK(cParms == SHFL_CPARMS_CLOSE_AND_REMOVE, rc = VERR_WRONG_PARAMETER_COUNT);
     1243            ASSERT_GUEST_STMT_BREAK(paParms[0].type == VBOX_HGCM_SVC_PARM_32BIT, rc = VERR_WRONG_PARAMETER_TYPE); /* root */
     1244            ASSERT_GUEST_STMT_BREAK(paParms[1].type == VBOX_HGCM_SVC_PARM_PTR,   rc = VERR_WRONG_PARAMETER_TYPE); /* path */
     1245            PCSHFLSTRING pStrPath = (PCSHFLSTRING)paParms[1].u.pointer.addr;
     1246            ASSERT_GUEST_STMT_BREAK(ShflStringIsValidIn(pStrPath, paParms[1].u.pointer.size,
     1247                                                        RT_BOOL(pClient->fu32Flags & SHFL_CF_UTF8)),
     1248                                    rc = VERR_INVALID_PARAMETER);
     1249            ASSERT_GUEST_STMT_BREAK(paParms[2].type == VBOX_HGCM_SVC_PARM_32BIT, rc = VERR_WRONG_PARAMETER_TYPE); /* flags */
     1250            uint32_t const fFlags = paParms[2].u.uint32;
     1251            ASSERT_GUEST_STMT_BREAK(!(fFlags & ~(SHFL_REMOVE_FILE | SHFL_REMOVE_DIR | SHFL_REMOVE_SYMLINK)),
     1252                                    rc = VERR_INVALID_FLAGS);
     1253            SHFLHANDLE const hToClose = paParms[3].u.uint64;
     1254            ASSERT_GUEST_STMT_BREAK(hToClose != SHFL_HANDLE_ROOT, rc = VERR_INVALID_HANDLE);
     1255
     1256            /* Execute the function. */
     1257            rc = vbsfRemove(pClient, paParms[0].u.uint32, pStrPath, paParms[1].u.pointer.size, fFlags, hToClose);
    12511258            break;
    12521259        }
     
    18601867             HGCMSvcHlpStamRegister(g_pHelpers, &g_StatRemove,                    STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "SHFL_FN_REMOVE successes",                  "/HGCM/VBoxSharedFolders/FnRemove");
    18611868             HGCMSvcHlpStamRegister(g_pHelpers, &g_StatRemoveFail,                STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "SHFL_FN_REMOVE failures",                   "/HGCM/VBoxSharedFolders/FnRemoveFail");
     1869             HGCMSvcHlpStamRegister(g_pHelpers, &g_StatCloseAndRemove,            STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "SHFL_FN_CLOSE_AND_REMOVE successes",        "/HGCM/VBoxSharedFolders/FnCloseAndRemove");
     1870             HGCMSvcHlpStamRegister(g_pHelpers, &g_StatCloseAndRemoveFail,        STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "SHFL_FN_CLOSE_AND_REMOVE failures",         "/HGCM/VBoxSharedFolders/FnCloseAndRemoveFail");
    18621871             HGCMSvcHlpStamRegister(g_pHelpers, &g_StatRename,                    STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "SHFL_FN_RENAME successes",                  "/HGCM/VBoxSharedFolders/FnRename");
    18631872             HGCMSvcHlpStamRegister(g_pHelpers, &g_StatRenameFail,                STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "SHFL_FN_RENAME failures",                   "/HGCM/VBoxSharedFolders/FnRenameFail");
  • trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp

    r77861 r78467  
    21812181}
    21822182#endif
    2183 int vbsfRemove(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath, uint32_t cbPath, uint32_t flags)
    2184 {
     2183int vbsfRemove(SHFLCLIENTDATA *pClient, SHFLROOT root, PCSHFLSTRING pPath, uint32_t cbPath, uint32_t flags, SHFLHANDLE hToClose)
     2184{
     2185
     2186    /* Validate input */
     2187    Assert(pPath);
     2188    AssertReturn(pPath->u16Size > 0, VERR_INVALID_PARAMETER);
     2189
     2190    /*
     2191     * Close the handle if specified.
     2192     */
    21852193    int rc = VINF_SUCCESS;
    2186 
    2187     /* Validate input */
    2188     if (   flags & ~(SHFL_REMOVE_FILE|SHFL_REMOVE_DIR|SHFL_REMOVE_SYMLINK)
    2189         || cbPath == 0
    2190         || pPath == 0)
    2191     {
    2192         AssertFailed();
    2193         return VERR_INVALID_PARAMETER;
    2194     }
    2195 
    2196     /* Build a host full path for the given path
    2197      * and convert ucs2 to utf8 if necessary.
    2198      */
    2199     char *pszFullPath = NULL;
    2200 
    2201     rc = vbsfBuildFullPath(pClient, root, pPath, cbPath, &pszFullPath, NULL);
     2194    if (hToClose != SHFL_HANDLE_NIL)
     2195        rc = vbsfClose(pClient, root, hToClose);
    22022196    if (RT_SUCCESS(rc))
    22032197    {
    2204         /* is the guest allowed to write to this share? */
    2205         bool fWritable;
    2206         rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);
    2207         if (RT_FAILURE(rc) || !fWritable)
    2208             rc = VERR_WRITE_PROTECT;
    2209 
     2198        /*
     2199         * Build a host full path for the given path and convert ucs2 to utf8 if necessary.
     2200         */
     2201        char *pszFullPath = NULL;
     2202        rc = vbsfBuildFullPath(pClient, root, pPath, cbPath, &pszFullPath, NULL);
    22102203        if (RT_SUCCESS(rc))
    22112204        {
    2212             if (flags & SHFL_REMOVE_SYMLINK)
    2213                 rc = RTSymlinkDelete(pszFullPath, 0);
    2214             else if (flags & SHFL_REMOVE_FILE)
    2215                 rc = RTFileDelete(pszFullPath);
     2205            /*
     2206             * Is the guest allowed to write to this share?
     2207             */
     2208            bool fWritable;
     2209            rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);
     2210            if (RT_SUCCESS(rc) && fWritable)
     2211            {
     2212                /*
     2213                 * Do the removal/deletion according to the type flags.
     2214                 */
     2215                if (flags & SHFL_REMOVE_SYMLINK)
     2216                    rc = RTSymlinkDelete(pszFullPath, 0);
     2217                else if (flags & SHFL_REMOVE_FILE)
     2218                    rc = RTFileDelete(pszFullPath);
     2219                else
     2220                    rc = RTDirRemove(pszFullPath);
     2221            }
    22162222            else
    2217                 rc = RTDirRemove(pszFullPath);
    2218         }
    2219 
    2220 #ifndef DEBUG_dmik
    2221         // VERR_ACCESS_DENIED for example?
    2222         // Assert(rc == VINF_SUCCESS || rc == VERR_DIR_NOT_EMPTY);
    2223 #endif
    2224         /* free the path string */
    2225         vbsfFreeFullPath(pszFullPath);
     2223                rc = VERR_WRITE_PROTECT;
     2224
     2225            /* free the path string */
     2226            vbsfFreeFullPath(pszFullPath);
     2227        }
    22262228    }
    22272229    return rc;
  • trunk/src/VBox/HostServices/SharedFolders/vbsf.h

    r77848 r78467  
    4040int vbsfLock(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint64_t length, uint32_t flags);
    4141int vbsfUnlock(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint64_t length, uint32_t flags);
    42 int vbsfRemove(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath, uint32_t cbPath, uint32_t flags);
     42int vbsfRemove(SHFLCLIENTDATA *pClient, SHFLROOT root, PCSHFLSTRING pPath, uint32_t cbPath, uint32_t flags, SHFLHANDLE hToClose);
    4343int vbsfRename(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pSrc, SHFLSTRING *pDest, uint32_t flags);
    4444int vbsfCopyFile(SHFLCLIENTDATA *pClient, SHFLROOT idRootSrc, PCSHFLSTRING pStrPathSrc,
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