VirtualBox

Changeset 79287 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Jun 22, 2019 12:05:44 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131488
Message:

GuestCtrlSvc,Main,VBoxService: Implemented IGuestFile::SetSize. bugref:9320

Location:
trunk/src/VBox/Additions/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibGuestCtrl.cpp

    r79252 r79287  
    12871287
    12881288/**
     1289 * Retrieves a HOST_FILE_SET_SIZE message.
     1290 */
     1291VBGLR3DECL(int) VbglR3GuestCtrlFileGetSetSize(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle, uint64_t *pcbNew)
     1292{
     1293    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
     1294
     1295    AssertReturn(pCtx->uNumParms == 3, VERR_INVALID_PARAMETER);
     1296    AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
     1297    AssertPtrReturn(pcbNew, VERR_INVALID_POINTER);
     1298
     1299    int rc;
     1300    do
     1301    {
     1302        HGCMMsgFileSetSize Msg;
     1303        VBGL_HGCM_HDR_INIT(&Msg.Hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
     1304        VbglHGCMParmUInt32Set(&Msg.id32Context, HOST_MSG_FILE_SET_SIZE);
     1305        VbglHGCMParmUInt32Set(&Msg.id32Handle, 0);
     1306        VbglHGCMParmUInt64Set(&Msg.cb64NewSize, 0);
     1307
     1308        rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
     1309        if (RT_SUCCESS(rc))
     1310        {
     1311            Msg.id32Context.GetUInt32(&pCtx->uContextID);
     1312            Msg.id32Handle.GetUInt32(puHandle);
     1313            Msg.cb64NewSize.GetUInt64(pcbNew);
     1314        }
     1315    } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
     1316    return rc;
     1317}
     1318
     1319
     1320/**
    12891321 * Retrieves a HOST_EXEC_TERMINATE message.
    12901322 */
     
    14111443
    14121444
    1413 VBGLR3DECL(int) VbglR3GuestCtrlFileCbWrite(PVBGLR3GUESTCTRLCMDCTX pCtx,
    1414                                            uint32_t uRc, uint32_t uWritten)
     1445VBGLR3DECL(int) VbglR3GuestCtrlFileCbWrite(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint32_t cbWritten)
    14151446{
    14161447    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
     
    14211452    VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_WRITE);
    14221453    VbglHGCMParmUInt32Set(&Msg.rc, uRc);
    1423     VbglHGCMParmUInt32Set(&Msg.u.write.written, uWritten);
     1454    VbglHGCMParmUInt32Set(&Msg.u.write.written, cbWritten);
    14241455
    14251456    return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.write));
     
    14271458
    14281459
    1429 VBGLR3DECL(int) VbglR3GuestCtrlFileCbSeek(PVBGLR3GUESTCTRLCMDCTX pCtx,
    1430                                           uint32_t uRc, uint64_t uOffActual)
     1460VBGLR3DECL(int) VbglR3GuestCtrlFileCbSeek(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint64_t offCurrent)
    14311461{
    14321462    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
     
    14371467    VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_SEEK);
    14381468    VbglHGCMParmUInt32Set(&Msg.rc, uRc);
    1439     VbglHGCMParmUInt64Set(&Msg.u.seek.offset, uOffActual);
     1469    VbglHGCMParmUInt64Set(&Msg.u.seek.offset, offCurrent);
    14401470
    14411471    return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.seek));
     
    14431473
    14441474
    1445 VBGLR3DECL(int) VbglR3GuestCtrlFileCbTell(PVBGLR3GUESTCTRLCMDCTX pCtx,
    1446                                           uint32_t uRc, uint64_t uOffActual)
     1475VBGLR3DECL(int) VbglR3GuestCtrlFileCbTell(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint64_t offCurrent)
    14471476{
    14481477    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
     
    14531482    VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_TELL);
    14541483    VbglHGCMParmUInt32Set(&Msg.rc, uRc);
    1455     VbglHGCMParmUInt64Set(&Msg.u.tell.offset, uOffActual);
     1484    VbglHGCMParmUInt64Set(&Msg.u.tell.offset, offCurrent);
    14561485
    14571486    return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.tell));
     1487}
     1488
     1489
     1490VBGLR3DECL(int) VbglR3GuestCtrlFileCbSetSize(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint64_t cbNew)
     1491{
     1492    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
     1493
     1494    HGCMReplyFileNotify Msg;
     1495    VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
     1496    VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
     1497    VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_SET_SIZE);
     1498    VbglHGCMParmUInt32Set(&Msg.rc, uRc);
     1499    VbglHGCMParmUInt64Set(&Msg.u.SetSize.cb64Size, cbNew);
     1500
     1501    return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.SetSize));
    14581502}
    14591503
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp

    r79261 r79287  
    316316                uint64_t fFlags;
    317317                rc = RTFileModeToFlagsEx(szAccess, szDisposition, NULL /* pszSharing, not used yet */, &fFlags);
    318                 VGSvcVerbose(4, "[File %s] Opening with fFlags=0x%x, rc=%Rrc\n", pFile->szName, fFlags, rc);
     318                VGSvcVerbose(4, "[File %s] Opening with fFlags=%#RX64 -> rc=%Rrc\n", pFile->szName, fFlags, rc);
    319319                if (RT_SUCCESS(rc))
    320320                {
     321                    fFlags |= (uCreationMode << RTFILE_O_CREATE_MODE_SHIFT) & RTFILE_O_CREATE_MODE_MASK;
    321322                    rc = RTFileOpen(&pFile->hFile, pFile->szName, fFlags);
    322323                    if (RT_SUCCESS(rc))
     
    766767
    767768
     769static int vgsvcGstCtrlSessionHandleFileSetSize(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx)
     770{
     771    AssertPtrReturn(pSession, VERR_INVALID_POINTER);
     772    AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
     773
     774    /*
     775     * Retrieve the request.
     776     */
     777    uint32_t uHandle = 0;
     778    uint64_t cbNew = 0;
     779    int rc = VbglR3GuestCtrlFileGetSetSize(pHostCtx, &uHandle, &cbNew);
     780    if (RT_SUCCESS(rc))
     781    {
     782        /*
     783         * Locate the file and ask for the current position.
     784         */
     785        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
     786        if (pFile)
     787        {
     788            rc = RTFileSetSize(pFile->hFile, cbNew);
     789            VGSvcVerbose(5, "[File %s]: Changing size to %RU64 (%#RX64), rc=%Rrc\n", pFile->szName, cbNew, cbNew, rc);
     790        }
     791        else
     792        {
     793            VGSvcError("File %u (%#x) not found!\n", uHandle, uHandle);
     794            cbNew = UINT64_MAX;
     795            rc = VERR_NOT_FOUND;
     796        }
     797
     798        /*
     799         * Report result back to host.
     800         */
     801        int rc2 = VbglR3GuestCtrlFileCbSetSize(pHostCtx, rc, cbNew);
     802        if (RT_FAILURE(rc2))
     803        {
     804            VGSvcError("Failed to report file tell status, rc=%Rrc\n", rc2);
     805            if (RT_SUCCESS(rc))
     806                rc = rc2;
     807        }
     808    }
     809    else
     810    {
     811        VGSvcError("Error fetching parameters for file tell operation: %Rrc\n", rc);
     812        VbglR3GuestCtrlMsgSkip(pHostCtx->uClientID, rc, UINT32_MAX);
     813    }
     814    return rc;
     815}
     816
     817
    768818static int vgsvcGstCtrlSessionHandlePathRename(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx)
    769819{
     
    12871337            if (fImpersonated)
    12881338                rc = vgsvcGstCtrlSessionHandleFileTell(pSession, pHostCtx);
     1339            break;
     1340
     1341        case HOST_MSG_FILE_SET_SIZE:
     1342            if (fImpersonated)
     1343                rc = vgsvcGstCtrlSessionHandleFileSetSize(pSession, pHostCtx);
    12891344            break;
    12901345
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