VirtualBox

Changeset 79287 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jun 22, 2019 12:05:44 AM (6 years ago)
Author:
vboxsync
Message:

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

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r79216 r79287  
    2367223672      </desc>
    2367323673    </const>
     23674    <const name="OnGuestFileSizeChanged" value="103">
     23675      <desc>
     23676        See <link to="IGuestFileSizeChangedEvent">IGuestFileSizeChangedEvent</link>.
     23677      </desc>
     23678    </const>
    2367423679    <!-- End event marker -->
    2367523680    <!-- @todo rename to 'End' as it is exclusive (we use 'last' to be inclusive). -->
    23676     <const name="Last" value="103">
     23681    <const name="Last" value="104">
    2367723682      <desc>
    2367823683        Must be last event, used for iterations and structures relying on numerical event values.
     
    2495324958    >
    2495424959    <desc>
    24955       Notification when a guest file changed its current offset.
     24960      Notification when a guest file changed its current offset via <link to="IFile::seek" />.
    2495624961    </desc>
    2495724962
    2495824963    <attribute name="midlDoesNotLikeEmptyInterfaces" readonly="yes" type="boolean"/>
    2495924964  </interface>
     24965
     24966  <interface
     24967    name="IGuestFileSizeChangedEvent" extends="IGuestFileEvent"
     24968    uuid="d78374e9-486e-472f-481b-969746af2480"
     24969    wsmap="managed" autogen="VBoxEvent" id="OnGuestFileSizeChanged"
     24970    >
     24971    <desc>
     24972      Notification when a guest file changed its size via <link to="IFile::setSize" />.
     24973    </desc>
     24974
     24975    <attribute name="newSize" readonly="yes" type="long long"/>
     24976  </interface>
     24977
    2496024978
    2496124979  <interface
  • trunk/src/VBox/Main/src-client/GuestFileImpl.cpp

    r79285 r79287  
    4141#include <VBox/com/array.h>
    4242#include <VBox/com/listeners.h>
     43#include <VBox/AssertGuest.h>
    4344
    4445
     
    584585        }
    585586
     587        case GUEST_FILE_NOTIFYTYPE_SET_SIZE:
     588            ASSERT_GUEST_MSG_STMT_BREAK(pSvcCbData->mParms == 4, ("mParms=%u\n", pSvcCbData->mParms),
     589                                        rc = VERR_WRONG_PARAMETER_COUNT);
     590            ASSERT_GUEST_MSG_STMT_BREAK(pSvcCbData->mpaParms[idx].type == VBOX_HGCM_SVC_PARM_64BIT,
     591                                        ("type=%u\n", pSvcCbData->mpaParms[idx].type),
     592                                        rc = VERR_WRONG_PARAMETER_TYPE);
     593            dataCb.u.SetSize.cbSize = pSvcCbData->mpaParms[idx].u.uint64;
     594            Log3ThisFunc(("cbSize=%RU64\n", dataCb.u.SetSize.cbSize));
     595
     596            fireGuestFileSizeChangedEvent(mEventSource, mSession, this, dataCb.u.SetSize.cbSize);
     597            rc = VINF_SUCCESS;
     598            break;
     599
    586600        default:
    587601            break;
     
    15181532HRESULT GuestFile::setSize(LONG64 aSize)
    15191533{
    1520     RT_NOREF(aSize);
    1521     ReturnComNotImplemented();
     1534    LogFlowThisFuncEnter();
     1535
     1536    /*
     1537     * Validate.
     1538     */
     1539    if (aSize < 0)
     1540        return setError(E_INVALIDARG, tr("The size (%RI64) cannot be a negative value"), aSize);
     1541
     1542    /*
     1543     * Register event callbacks.
     1544     */
     1545    int             vrc;
     1546    GuestWaitEvent *pWaitEvent = NULL;
     1547    GuestEventTypes lstEventTypes;
     1548    try
     1549    {
     1550        lstEventTypes.push_back(VBoxEventType_OnGuestFileStateChanged);
     1551        lstEventTypes.push_back(VBoxEventType_OnGuestFileSizeChanged);
     1552    }
     1553    catch (std::bad_alloc &)
     1554    {
     1555        return E_OUTOFMEMORY;
     1556    }
     1557
     1558    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     1559
     1560    vrc = registerWaitEvent(lstEventTypes, &pWaitEvent);
     1561    if (RT_SUCCESS(vrc))
     1562    {
     1563        /*
     1564         * Send of the HGCM message.
     1565         */
     1566        VBOXHGCMSVCPARM aParms[3];
     1567        HGCMSvcSetU32(&aParms[0], pWaitEvent->ContextID());
     1568        HGCMSvcSetU32(&aParms[1], mObjectID /* File handle */);
     1569        HGCMSvcSetU64(&aParms[2], aSize);
     1570
     1571        alock.release(); /* Drop write lock before sending. */
     1572
     1573        vrc = sendMessage(HOST_MSG_FILE_SET_SIZE, RT_ELEMENTS(aParms), aParms);
     1574        if (RT_SUCCESS(vrc))
     1575        {
     1576            /*
     1577             * Wait for the event.
     1578             */
     1579            VBoxEventType_T enmEvtType;
     1580            ComPtr<IEvent>  pIEvent;
     1581            vrc = waitForEvent(pWaitEvent, RT_MS_1MIN / 2, &enmEvtType, pIEvent.asOutParam());
     1582            if (RT_SUCCESS(vrc))
     1583            {
     1584                if (enmEvtType == VBoxEventType_OnGuestFileSizeChanged)
     1585                    vrc = VINF_SUCCESS;
     1586                else
     1587                    vrc = VWRN_GSTCTL_OBJECTSTATE_CHANGED;
     1588            }
     1589            if (RT_FAILURE(vrc) && pWaitEvent->HasGuestError()) /* Return guest rc if available. */
     1590                vrc = pWaitEvent->GetGuestError();
     1591        }
     1592
     1593        /*
     1594         * Unregister the wait event and deal with error reporting if needed.
     1595         */
     1596        unregisterWaitEvent(pWaitEvent);
     1597    }
     1598    HRESULT hrc;
     1599    if (RT_SUCCESS(vrc))
     1600        hrc = S_OK;
     1601    else
     1602        hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrc, tr("Setting the file size of '%s' to %RU64 (%#RX64) bytes failed: %Rrc"),
     1603                           mData.mOpenInfo.mFilename.c_str(), aSize, aSize, vrc);
     1604    LogFlowFuncLeaveRC(vrc);
     1605    return hrc;
    15221606}
    15231607
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