VirtualBox

Changeset 47817 in vbox


Ignore:
Timestamp:
Aug 16, 2013 3:30:15 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
88078
Message:

GuestCtrl: Update for IGuestFile; some renaming.

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/HostServices/GuestControlSvc.h

    r47697 r47817  
    710710    /** UInt32: Context ID. */
    711711    HGCMFunctionParameter context;
    712     /** String: File to open. */
     712    /** File to open. */
    713713    HGCMFunctionParameter filename;
    714     /** String: Open mode. */
     714    /** Open mode. */
    715715    HGCMFunctionParameter openmode;
    716     /** String: Disposition. */
     716    /** Disposition mode. */
    717717    HGCMFunctionParameter disposition;
     718    /** Sharing mode. */
     719    HGCMFunctionParameter sharing;
    718720    /** UInt32: Creation mode. */
    719721    HGCMFunctionParameter creationmode;
  • trunk/include/VBox/VBoxGuestLib.h

    r47697 r47817  
    626626VBGLR3DECL(int) VbglR3GuestCtrlProcGetWaitFor(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puPID, uint32_t *puWaitFlags, uint32_t *puTimeoutMS);
    627627/* Guest native file handling. */
    628 VBGLR3DECL(int) VbglR3GuestCtrlFileGetOpen(PVBGLR3GUESTCTRLCMDCTX pCtx, char *pszFileName, uint32_t cbFileName, char *pszOpenMode, uint32_t cbOpenMode, char *pszDisposition, uint32_t cbDisposition, uint32_t *puCreationMode, uint64_t *puOffset);
     628VBGLR3DECL(int) VbglR3GuestCtrlFileGetOpen(PVBGLR3GUESTCTRLCMDCTX pCtx, char *pszFileName, uint32_t cbFileName, char *pszOpenMode, uint32_t cbOpenMode, char *pszDisposition, uint32_t cbDisposition, char *pszSharing, uint32_t cbSharing, uint32_t *puCreationMode, uint64_t *puOffset);
    629629VBGLR3DECL(int) VbglR3GuestCtrlFileGetClose(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle);
    630630VBGLR3DECL(int) VbglR3GuestCtrlFileGetRead(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle, uint32_t *puToRead);
     
    637637VBGLR3DECL(int) VbglR3GuestCtrlFileCbOpen(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint32_t uFileHandle);
    638638VBGLR3DECL(int) VbglR3GuestCtrlFileCbClose(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc);
     639VBGLR3DECL(int) VbglR3GuestCtrlFileCbError(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc);
    639640VBGLR3DECL(int) VbglR3GuestCtrlFileCbRead(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, void *pvData, uint32_t cbData);
    640641VBGLR3DECL(int) VbglR3GuestCtrlFileCbWrite(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint32_t uWritten);
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestCtrl.cpp

    r47695 r47817  
    532532 ** @todo Docs!
    533533 */
    534 VBGLR3DECL(int) VbglR3GuestCtrlProcGetInput(PVBGLR3GUESTCTRLCMDCTX pCtx,
     534VBGLR3DECL(int) VbglR3GuestCtrlProcGetInput(PVBGLR3GUESTCTRLCMDCTX  pCtx,
    535535                                            uint32_t  *puPID,       uint32_t *puFlags,
    536536                                            void      *pvData,      uint32_t  cbData,
     
    579579
    580580VBGLR3DECL(int) VbglR3GuestCtrlFileGetOpen(PVBGLR3GUESTCTRLCMDCTX      pCtx,
    581                                            char     *pszFileName,       uint32_t cbFileName,
    582                                            char     *pszOpenMode,       uint32_t cbOpenMode,
    583                                            char     *pszDisposition,    uint32_t cbDisposition,
     581                                           char     *pszFileName,      uint32_t cbFileName,
     582                                           char     *pszAccess,        uint32_t cbAccess,
     583                                           char     *pszDisposition,   uint32_t cbDisposition,
     584                                           char     *pszSharing,       uint32_t cbSharing,
    584585                                           uint32_t *puCreationMode,
    585586                                           uint64_t *puOffset)
    586587{
    587588    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
    588     AssertReturn(pCtx->uNumParms == 6, VERR_INVALID_PARAMETER);
     589    AssertReturn(pCtx->uNumParms == 7, VERR_INVALID_PARAMETER);
    589590
    590591    AssertPtrReturn(pszFileName, VERR_INVALID_POINTER);
    591592    AssertReturn(cbFileName, VERR_INVALID_PARAMETER);
    592     AssertPtrReturn(pszOpenMode, VERR_INVALID_POINTER);
    593     AssertReturn(cbOpenMode, VERR_INVALID_PARAMETER);
     593    AssertPtrReturn(pszAccess, VERR_INVALID_POINTER);
     594    AssertReturn(cbAccess, VERR_INVALID_PARAMETER);
    594595    AssertPtrReturn(pszDisposition, VERR_INVALID_POINTER);
    595596    AssertReturn(cbDisposition, VERR_INVALID_PARAMETER);
     597    AssertPtrReturn(pszSharing, VERR_INVALID_POINTER);
     598    AssertReturn(cbSharing, VERR_INVALID_PARAMETER);
    596599    AssertPtrReturn(puCreationMode, VERR_INVALID_POINTER);
    597600    AssertPtrReturn(puOffset, VERR_INVALID_POINTER);
     
    606609    VbglHGCMParmUInt32Set(&Msg.context, 0);
    607610    VbglHGCMParmPtrSet(&Msg.filename, pszFileName, cbFileName);
    608     VbglHGCMParmPtrSet(&Msg.openmode, pszOpenMode, cbOpenMode);
     611    VbglHGCMParmPtrSet(&Msg.openmode, pszAccess, cbAccess);
    609612    VbglHGCMParmPtrSet(&Msg.disposition, pszDisposition, cbDisposition);
     613    VbglHGCMParmPtrSet(&Msg.sharing, pszSharing, cbSharing);
    610614    VbglHGCMParmUInt32Set(&Msg.creationmode, 0);
    611615    VbglHGCMParmUInt64Set(&Msg.offset, 0);
     
    10381042
    10391043
     1044VBGLR3DECL(int) VbglR3GuestCtrlFileCbError(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc)
     1045{
     1046    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
     1047
     1048    HGCMReplyFileNotify Msg;
     1049
     1050    Msg.hdr.result      = VERR_WRONG_ORDER;
     1051    Msg.hdr.u32ClientID = pCtx->uClientID;
     1052    Msg.hdr.u32Function = GUEST_FILE_NOTIFY;
     1053    Msg.hdr.cParms      = 3;
     1054
     1055    VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
     1056    VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_ERROR);
     1057    VbglHGCMParmUInt32Set(&Msg.rc, uRc);
     1058
     1059    int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     1060    if (RT_SUCCESS(rc))
     1061    {
     1062        int rc2 = Msg.hdr.result;
     1063        if (RT_FAILURE(rc2))
     1064            rc = rc2;
     1065    }
     1066    return rc;
     1067}
     1068
     1069
    10401070VBGLR3DECL(int) VbglR3GuestCtrlFileCbRead(PVBGLR3GUESTCTRLCMDCTX pCtx,
    10411071                                          uint32_t uRc,
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.cpp

    r47721 r47817  
    225225        if (RT_SUCCESS(rc))
    226226        {
    227 #ifdef DEBUG
    228             VBoxServiceVerbose(3, "Msg=%RU32 (%RU32 parms) retrieved\n", uMsg, cParms);
    229 #endif
     227            VBoxServiceVerbose(4, "Msg=%RU32 (%RU32 parms) retrieved\n", uMsg, cParms);
     228
    230229            /* Set number of parameters for current host context. */
    231230            ctxHost.uNumParms = cParms;
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp

    r47695 r47817  
    103103
    104104
     105/** @todo No locking done yet! */
    105106static PVBOXSERVICECTRLFILE gstcntlSessionFileGetLocked(const PVBOXSERVICECTRLSESSION pSession,
    106107                                                        uint32_t uHandle)
     
    127128
    128129    char szFile[RTPATH_MAX];
    129     char szOpenMode[64];
     130    char szAccess[64];
    130131    char szDisposition[64];
     132    char szSharing[64];
    131133    uint32_t uCreationMode = 0;
    132134    uint64_t uOffset = 0;
    133 
    134135    uint32_t uHandle = 0;
     136
    135137    int rc = VbglR3GuestCtrlFileGetOpen(pHostCtx,
    136138                                        /* File to open. */
    137139                                        szFile, sizeof(szFile),
    138140                                        /* Open mode. */
    139                                         szOpenMode, sizeof(szOpenMode),
     141                                        szAccess, sizeof(szAccess),
    140142                                        /* Disposition. */
    141143                                        szDisposition, sizeof(szDisposition),
     144                                        /* Sharing. */
     145                                        szSharing, sizeof(szSharing),
    142146                                        /* Creation mode. */
    143147                                        &uCreationMode,
    144148                                        /* Offset. */
    145149                                        &uOffset);
     150#ifdef DEBUG
     151    VBoxServiceVerbose(4, "[File %s]: szAccess=%s, szDisposition=%s, szSharing=%s, rc=%Rrc\n",
     152                       szFile, szAccess, szDisposition, szSharing, rc);
     153#endif
    146154    if (RT_SUCCESS(rc))
    147155    {
     
    149157        if (pFile)
    150158        {
    151             if (!RTStrPrintf(pFile->szName, sizeof(pFile->szName), "%s", szFile))
    152                 rc = VERR_BUFFER_OVERFLOW;
     159            if (!strlen(szFile))
     160                rc = VERR_INVALID_PARAMETER;
     161
     162            if (   RT_SUCCESS(rc)
     163                && !RTStrPrintf(pFile->szName, sizeof(pFile->szName), "%s", szFile))
     164                rc = VERR_NO_MEMORY;
    153165
    154166            if (RT_SUCCESS(rc))
    155167            {
    156                 uint64_t fFlags = RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE; /** @todo Modes! */
    157                 rc = RTFileOpen(&pFile->hFile, pFile->szName, fFlags);
     168                uint64_t fFlags;
     169                rc = RTFileModeToFlagsEx(szAccess, szDisposition,
     170                                         NULL /* pszSharing, not used yet */, &fFlags);
     171                VBoxServiceVerbose(4, "[File %s]: Opening flags=0x%x, rc=%Rrc\n", pFile->szName, fFlags, rc);
     172                if (RT_SUCCESS(rc))
     173                    rc = RTFileOpen(&pFile->hFile, pFile->szName, fFlags);
    158174                if (   RT_SUCCESS(rc)
    159175                    && uOffset)
     
    165181                                           pFile->szName, uOffset, rc);
    166182                }
    167                 else
     183                else if (RT_FAILURE(rc))
    168184                    VBoxServiceVerbose(3, "[File %s]: Opening failed; rc=%Rrc\n",
    169185                                       pFile->szName, rc);
     
    196212    }
    197213
     214#ifdef DEBUG
     215    VBoxServiceVerbose(4, "Opening file \"%s\" (open mode=\"%s\", disposition=\"%s\", creation mode=0x%x returned rc=%Rrc\n",
     216                       szFile, szAccess, szDisposition, uCreationMode, rc);
     217#endif
    198218    return rc;
    199219}
     
    206226    AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
    207227
    208     uint32_t uHandle;
    209 
     228    PVBOXSERVICECTRLFILE pFile = NULL;
     229
     230    uint32_t uHandle = 0;
    210231    int rc = VbglR3GuestCtrlFileGetClose(pHostCtx, &uHandle /* File handle to close */);
    211232    if (RT_SUCCESS(rc))
    212233    {
    213         PVBOXSERVICECTRLFILE pFile = gstcntlSessionFileGetLocked(pSession, uHandle);
     234        pFile = gstcntlSessionFileGetLocked(pSession, uHandle);
    214235        if (pFile)
    215236        {
     
    227248    }
    228249
     250#ifdef DEBUG
     251    VBoxServiceVerbose(4, "Closing file \"%s\" (handle=%RU32) returned rc=%Rrc\n",
     252                       pFile ? pFile->szName : "<Not found>", uHandle, rc);
     253#endif
    229254    return rc;
    230255}
     
    238263    AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
    239264
    240     uint32_t uHandle;
     265    PVBOXSERVICECTRLFILE pFile = NULL;
     266
     267    uint32_t uHandle = 0;
    241268    uint32_t cbToRead;
    242 
    243269    int rc = VbglR3GuestCtrlFileGetRead(pHostCtx, &uHandle, &cbToRead);
    244270    if (RT_SUCCESS(rc))
     
    279305            rc = rc2;
    280306    }
     307
     308#ifdef DEBUG
     309    VBoxServiceVerbose(4, "Reading file \"%s\" (handle=%RU32) returned rc=%Rrc\n",
     310                       pFile ? pFile->szName : "<Not found>", uHandle, rc);
     311#endif
    281312    return rc;
    282313}
     
    290321    AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
    291322
    292     uint32_t uHandle;
     323    PVBOXSERVICECTRLFILE pFile = NULL;
     324
     325    uint32_t uHandle = 0;
    293326    uint32_t cbToRead; int64_t iOffset;
    294327
    295328    int rc = VbglR3GuestCtrlFileGetReadAt(pHostCtx,
    296                                           &uHandle, &cbToRead, (uint64_t*)&iOffset);
     329                                          &uHandle, &cbToRead, (uint64_t *)&iOffset);
    297330    if (RT_SUCCESS(rc))
    298331    {
     
    300333        size_t cbRead = 0;
    301334
    302         PVBOXSERVICECTRLFILE pFile = gstcntlSessionFileGetLocked(pSession, uHandle);
     335        pFile = gstcntlSessionFileGetLocked(pSession, uHandle);
    303336        if (pFile)
    304337        {
     
    332365            rc = rc2;
    333366    }
     367
     368#ifdef DEBUG
     369    VBoxServiceVerbose(4, "Reading file \"%s\" at offset (handle=%RU32) returned rc=%Rrc\n",
     370                       pFile ? pFile->szName : "<Not found>", uHandle, rc);
     371#endif
    334372    return rc;
    335373}
     
    345383    AssertPtrReturn(cbScratchBuf, VERR_INVALID_PARAMETER);
    346384
    347     uint32_t uHandle;
     385    PVBOXSERVICECTRLFILE pFile = NULL;
     386
     387    uint32_t uHandle = 0;
    348388    uint32_t cbToWrite;
    349389
     
    354394    {
    355395        size_t cbWritten = 0;
    356         PVBOXSERVICECTRLFILE pFile = gstcntlSessionFileGetLocked(pSession, uHandle);
     396        pFile = gstcntlSessionFileGetLocked(pSession, uHandle);
    357397        if (pFile)
    358398        {
     
    369409            rc = rc2;
    370410    }
     411
     412#ifdef DEBUG
     413    VBoxServiceVerbose(4, "Writing file \"%s\" (handle=%RU32) returned rc=%Rrc\n",
     414                       pFile ? pFile->szName : "<Not found>", uHandle, rc);
     415#endif
    371416    return rc;
    372417}
     
    382427    AssertPtrReturn(cbScratchBuf, VERR_INVALID_PARAMETER);
    383428
    384     uint32_t uHandle;
     429    PVBOXSERVICECTRLFILE pFile = NULL;
     430
     431    uint32_t uHandle = 0;
    385432    uint32_t cbToWrite; int64_t iOffset;
    386433
    387434    int rc = VbglR3GuestCtrlFileGetWriteAt(pHostCtx, &uHandle,
    388435                                           pvScratchBuf, cbScratchBuf,
    389                                            &cbToWrite, (uint64_t*)&iOffset);
     436                                           &cbToWrite, (uint64_t *)&iOffset);
    390437    if (RT_SUCCESS(rc))
    391438    {
     
    407454            rc = rc2;
    408455    }
     456
     457#ifdef DEBUG
     458    VBoxServiceVerbose(4, "Writing file \"%s\" at offset (handle=%RU32) returned rc=%Rrc\n",
     459                       pFile ? pFile->szName : "<Not found>", uHandle, rc);
     460#endif
    409461    return rc;
    410462}
     
    417469    AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
    418470
    419     uint32_t uHandle;
     471    PVBOXSERVICECTRLFILE pFile = NULL;
     472
     473    uint32_t uHandle = 0;
    420474    uint32_t uSeekMethod;
    421475    uint64_t uOffset; /* Will be converted to int64_t. */
     
    427481    if (RT_SUCCESS(rc))
    428482    {
    429         PVBOXSERVICECTRLFILE pFile = gstcntlSessionFileGetLocked(pSession, uHandle);
     483        pFile = gstcntlSessionFileGetLocked(pSession, uHandle);
    430484        if (pFile)
    431485        {
     
    464518            rc = rc2;
    465519    }
     520
     521#ifdef DEBUG
     522    VBoxServiceVerbose(4, "Seeking file \"%s\" (handle=%RU32) returned rc=%Rrc\n",
     523                       pFile ? pFile->szName : "<Not found>", uHandle, rc);
     524#endif
    466525    return rc;
    467526}
     
    474533    AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
    475534
    476     uint32_t uHandle;
     535    PVBOXSERVICECTRLFILE pFile = NULL;
     536
     537    uint32_t uHandle = 0;
    477538    uint64_t uOffsetActual = 0;
    478539
     
    480541    if (RT_SUCCESS(rc))
    481542    {
    482         PVBOXSERVICECTRLFILE pFile = gstcntlSessionFileGetLocked(pSession, uHandle);
     543        pFile = gstcntlSessionFileGetLocked(pSession, uHandle);
    483544        if (pFile)
    484545        {
     
    495556            rc = rc2;
    496557    }
     558
     559#ifdef DEBUG
     560    VBoxServiceVerbose(4, "Telling file \"%s\" (handle=%RU32) returned rc=%Rrc\n",
     561                       pFile ? pFile->szName : "<Not found>", uHandle, rc);
     562#endif
    497563    return rc;
    498564}
     
    659725        {
    660726            fPendingClose = true;
    661 #ifdef DEBUG_andy
     727#ifdef DEBUG
    662728            VBoxServiceVerbose(4, "Got last process input block for PID=%RU32 (%RU32 bytes) ...\n",
    663729                               uPID, cbSize);
     
    679745    }
    680746
    681 
    682 #ifdef DEBUG_andy
     747#ifdef DEBUG
    683748    VBoxServiceVerbose(4, "Setting input for PID=%RU32 resulted in rc=%Rrc\n",
    684749                       uPID, rc);
     
    905970            break;
    906971    }
     972
     973    if (RT_FAILURE(rc))
     974        VBoxServiceError("Error while handling message (uMsg=%RU32, cParms=%RU32), rc=%Rrc\n",
     975                         uMsg, pHostCtx->uNumParms, rc);
    907976
    908977    return rc;
     
    11691238            if (RT_SUCCESS(rc))
    11701239            {
    1171 #ifdef DEBUG
    1172                 VBoxServiceVerbose(3, "Msg=%RU32 (%RU32 parms) retrieved\n", uMsg, cParms);
    1173 #endif
     1240                VBoxServiceVerbose(4, "Msg=%RU32 (%RU32 parms) retrieved\n", uMsg, cParms);
     1241
    11741242                /* Set number of parameters for current host context. */
    11751243                ctxHost.uNumParms = cParms;
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r47804 r47817  
    1013810138  <interface
    1013910139    name="IGuestSession" extends="$unknown"
    10140     uuid="1afeabbd-0c0b-458c-8026-04464892ae12"
     10140    uuid="5b28703c-07b6-4fcb-afba-ac199b309752"
    1014110141    wsmap="managed"
    1014210142    >
     
    1062510625      <param name="disposition" type="wstring" dir="in">
    1062610626        <desc>The file disposition.</desc>
     10627      </param>
     10628      <param name="creationMode" type="unsigned long" dir="in">
     10629        <desc>The file creation mode.</desc>
     10630      </param>
     10631      <param name="file" type="IGuestFile" dir="return">
     10632        <desc><link to="IGuestFile"/> object representing the opened file.</desc>
     10633      </param>
     10634    </method>
     10635
     10636    <method name="fileOpenEx">
     10637      <desc>
     10638        Opens a file and creates a <link to="IGuestFile"/> object that
     10639        can be used for further operations, extended version.
     10640
     10641        <result name="VBOX_E_OBJECT_NOT_FOUND">
     10642          File to open was not found.
     10643        </result>
     10644        <result name="VBOX_E_IPRT_ERROR">
     10645          Error while opening the file.
     10646        </result>
     10647      </desc>
     10648      <param name="path" type="wstring" dir="in">
     10649        <desc>Full path to file to open.</desc>
     10650      </param>
     10651      <param name="openMode" type="wstring" dir="in">
     10652        <desc>The file open mode.</desc>
     10653      </param>
     10654      <param name="disposition" type="wstring" dir="in">
     10655        <desc>The file disposition.</desc>
     10656      </param>
     10657      <param name="sharingMode" type="wstring" dir="in">
     10658        <desc>The file sharing mode on the guest.</desc>
    1062710659      </param>
    1062810660      <param name="creationMode" type="unsigned long" dir="in">
     
    2090920941    </attribute>
    2091020942    <!-- Note: No events for reads/writes for performance reasons.
    20911                See dedidcated events IGuestFileReadEvent and
     20943               See dedicated events IGuestFileReadEvent and
    2091220944               IGuestFileWriteEvent. -->
    2091320945
  • trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h

    r47627 r47817  
    116116    /** The file's disposition mode. */
    117117    Utf8Str                 mDisposition;
     118    /** The file's sharing mode.
     119     **@todo Not implemented yet.*/
     120    Utf8Str                 mSharingMode;
    118121    /** Octal creation mode. */
    119122    uint32_t                mCreationMode;
    120123    /** The initial offset on open. */
    121     int64_t                 mInitialOffset;
     124    uint64_t                mInitialOffset;
    122125};
    123126
  • trunk/src/VBox/Main/include/GuestFileImpl.h

    r45780 r47817  
    8282    int             callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
    8383    int             closeFile(int *pGuestRc);
    84     static uint32_t getDispositionFromString(const Utf8Str &strDisposition);
    8584    EventSource    *getEventSource(void) { return mEventSource; }
    86     static uint32_t getOpenModeFromString(const Utf8Str &strOpenMode);
    8785    static Utf8Str  guestErrorToString(int guestRc);
    8886    int             onFileNotify(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
    8987    int             onGuestDisconnected(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
    90     int             openFile(int *pGuestRc);
     88    int             openFile(uint32_t uTimeoutMS, int *pGuestRc);
    9189    int             readData(uint32_t uSize, uint32_t uTimeoutMS, void* pvData, uint32_t cbData, uint32_t* pcbRead);
    9290    int             readDataAt(uint64_t uOffset, uint32_t uSize, uint32_t uTimeoutMS, void* pvData, size_t cbData, size_t* pcbRead);
     
    9694    int             waitForOffsetChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, uint64_t *puOffset);
    9795    int             waitForRead(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, void *pvData, size_t cbData, uint32_t *pcbRead);
    98     int             waitForStatusChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, FileStatus_T *pFileStatus);
     96    int             waitForStatusChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, FileStatus_T *pFileStatus, int *pGuestRc);
    9997    int             waitForWrite(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, uint32_t *pcbWritten);
    10098    int             writeData(uint32_t uTimeoutMS, void *pvData, uint32_t cbData, uint32_t *pcbWritten);
     
    104102private:
    105103
    106     /** The internal console object. */
    107     Console                *mConsole;
    108     /** The associate session this file belongs to. */
    109     GuestSession           *mSession;
    110104    /** This can safely be used without holding any locks.
    111105     * An AutoCaller suffices to prevent it being destroy while in use and
     
    123117        /** The current file status. */
    124118        FileStatus_T            mStatus;
     119        /** The last returned process status
     120         *  returned from the guest side. */
     121        int                     mLastError;
    125122        /** The file's current offset. */
    126123        uint64_t                mOffCurrent;
  • trunk/src/VBox/Main/include/GuestProcessImpl.h

    r47627 r47817  
    128128        /** The last returned process status
    129129         *  returned from the guest side. */
    130         int                      mRC;
     130        int                      mLastError;
    131131    } mData;
    132132};
  • trunk/src/VBox/Main/include/GuestSessionImpl.h

    r47469 r47817  
    303303    STDMETHOD(FileExists)(IN_BSTR aPath, BOOL *aExists);
    304304    STDMETHOD(FileRemove)(IN_BSTR aPath);
    305     STDMETHOD(FileOpen)(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile);
     305    STDMETHOD(FileOpen)(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, IGuestFile **aFile);
     306    STDMETHOD(FileOpenEx)(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, IN_BSTR aSharingMode, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile);
    306307    STDMETHOD(FileQueryInfo)(IN_BSTR aPath, IGuestFsObjInfo **aInfo);
    307308    STDMETHOD(FileQuerySize)(IN_BSTR aPath, LONG64 *aSize);
  • trunk/src/VBox/Main/src-client/GuestFileImpl.cpp

    r47469 r47817  
    153153    if (RT_SUCCESS(vrc))
    154154    {
    155         mData.mID = 0;
     155        mSession = pSession;
     156
     157        mData.mID = uFileID;
    156158        mData.mInitialSize = 0;
    157159        mData.mStatus = FileStatus_Undefined;
     160        mData.mOpenInfo = openInfo;
    158161
    159162        unconst(mEventSource).createObject();
     
    273276    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    274277
    275     *aDisposition = getDispositionFromString(mData.mOpenInfo.mDisposition);
     278    uint32_t uDisposition = 0;
     279    /** @todo Fix me! */
     280    *aDisposition = uDisposition;
    276281
    277282    return S_OK;
     
    363368    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    364369
    365     *aOpenMode = getOpenModeFromString(mData.mOpenInfo.mOpenMode);
     370    uint32_t uOpenMode = 0;
     371    /** @todo Fix me! */
     372    *aOpenMode = uOpenMode;
    366373
    367374    return S_OK;
     
    398405    AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
    399406
    400     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    401 
    402407    int vrc;
    403408    switch (pCbCtx->uFunction)
     
    454459    if (RT_SUCCESS(vrc))
    455460        vrc = waitForStatusChange(pEvent, 30 * 1000 /* Timeout in ms */,
    456                                   NULL /* FileStatus */);
     461                                  NULL /* FileStatus */, pGuestRc);
    457462    unregisterWaitEvent(pEvent);
    458463
    459464    LogFlowFuncLeaveRC(vrc);
    460465    return vrc;
    461 }
    462 
    463 /* static */
    464 uint32_t GuestFile::getDispositionFromString(const Utf8Str &strDisposition)
    465 {
    466     return 0; /** @todo Implement me! */
    467 }
    468 
    469 /* static */
    470 uint32_t GuestFile::getOpenModeFromString(const Utf8Str &strOpenMode)
    471 {
    472     uint32_t uOpenMode = 0;
    473 
    474     const char *pc = strOpenMode.c_str();
    475     while (*pc != '\0')
    476     {
    477         switch (*pc++)
    478         {
    479             case 'r':
    480                 uOpenMode |= RTFILE_O_READ;
    481                 break;
    482 
    483             case 'w':
    484                 uOpenMode |= RTFILE_O_WRITE;
    485                 break;
    486 
    487             default:
    488                 /* Silently skip unknown values. */
    489                 break;
    490         }
    491     }
    492 
    493     return uOpenMode;
    494466}
    495467
     
    543515    AssertPtrReturn(pSvcCbData, VERR_INVALID_POINTER);
    544516
     517    LogFlowThisFuncEnter();
     518
    545519    if (pSvcCbData->mParms < 3)
    546520        return VERR_INVALID_PARAMETER;
     
    548522    int vrc = VINF_SUCCESS;
    549523
    550     int idx = 0; /* Current parameter index. */
     524    int idx = 1; /* Current parameter index. */
    551525    CALLBACKDATA_FILE_NOTIFY dataCb;
    552526    /* pSvcCb->mpaParms[0] always contains the context ID. */
     
    554528    pSvcCbData->mpaParms[idx++].getUInt32(&dataCb.rc);
    555529
     530    FileStatus_T fileStatus = FileStatus_Undefined;
    556531    int guestRc = (int)dataCb.rc; /* uint32_t vs. int. */
    557532
     533    LogFlowFunc(("uType=%RU32, guestRc=%Rrc\n",
     534                 dataCb.uType, guestRc));
     535
     536    if (RT_FAILURE(guestRc))
     537    {
     538        int rc2 = setFileStatus(FileStatus_Error, guestRc);
     539        AssertRC(rc2);
     540
     541        return VINF_SUCCESS; /* Report to the guest. */
     542    }
     543
    558544    switch (dataCb.uType)
    559545    {
    560546        case GUEST_FILE_NOTIFYTYPE_ERROR:
    561547        {
    562             AssertMsg(mData.mStatus != FileStatus_Error, ("File status already set to error\n"));
    563 
    564548            int rc2 = setFileStatus(FileStatus_Error, guestRc);
    565549            AssertRC(rc2);
     
    573557                pSvcCbData->mpaParms[idx++].getUInt32(&dataCb.u.open.uHandle);
    574558
    575                 AssertMsg(mData.mID == 0, ("File ID already set to %RU32\n", mData.mID));
    576                 mData.mID = dataCb.u.open.uHandle;
    577                 AssertMsg(mData.mID == VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCbCtx->uContextID),
    578                           ("File ID %RU32 does not match context ID %RU32\n", mData.mID,
    579                            VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCbCtx->uContextID)));
     559                {
     560                    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     561                    AssertMsg(mData.mID == VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCbCtx->uContextID),
     562                              ("File ID %RU32 does not match context ID %RU32\n", mData.mID,
     563                               VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCbCtx->uContextID)));
     564                }
    580565
    581566                /* Set the process status. */
     
    599584
    600585        case GUEST_FILE_NOTIFYTYPE_READ:
     586        {
    601587            if (pSvcCbData->mParms == 4)
    602588            {
     
    606592                if (cbRead)
    607593                {
     594                    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     595
    608596                    mData.mOffCurrent += cbRead;
     597
     598                    alock.release();
    609599
    610600                    com::SafeArray<BYTE> data((size_t)cbRead);
    611601                    data.initFrom((BYTE*)dataCb.u.read.pvData, cbRead);
     602
    612603                    fireGuestFileReadEvent(mEventSource, mSession, this, mData.mOffCurrent,
    613604                                           cbRead, ComSafeArrayAsInParam(data));
     
    617608                vrc = VERR_NOT_SUPPORTED;
    618609            break;
     610        }
    619611
    620612        case GUEST_FILE_NOTIFYTYPE_WRITE:
     613        {
    621614            if (pSvcCbData->mParms == 4)
    622615            {
    623616                pSvcCbData->mpaParms[idx++].getUInt32(&dataCb.u.write.cbWritten);
    624617
     618                AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     619
    625620                mData.mOffCurrent += dataCb.u.write.cbWritten;
     621                uint64_t uOffCurrent = mData.mOffCurrent;
     622
     623                alock.release();
    626624
    627625                if (dataCb.u.write.cbWritten)
    628                     fireGuestFileWriteEvent(mEventSource, mSession, this, mData.mOffCurrent,
     626                    fireGuestFileWriteEvent(mEventSource, mSession, this, uOffCurrent,
    629627                                            dataCb.u.write.cbWritten);
    630628            }
     
    632630                vrc = VERR_NOT_SUPPORTED;
    633631            break;
     632        }
    634633
    635634        case GUEST_FILE_NOTIFYTYPE_SEEK:
     635        {
    636636            if (pSvcCbData->mParms == 4)
    637637            {
    638638                pSvcCbData->mpaParms[idx++].getUInt64(&dataCb.u.seek.uOffActual);
    639639
     640                AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     641
    640642                mData.mOffCurrent = dataCb.u.seek.uOffActual;
     643                uint64_t uOffCurrent = mData.mOffCurrent;
     644
     645                alock.release();
    641646
    642647                if (dataCb.u.seek.uOffActual)
    643648                    fireGuestFileOffsetChangedEvent(mEventSource, mSession, this,
    644                                                     mData.mOffCurrent, 0 /* Processed */);
     649                                                    uOffCurrent, 0 /* Processed */);
    645650            }
    646651            else
    647652                vrc = VERR_NOT_SUPPORTED;
    648653            break;
     654        }
    649655
    650656        case GUEST_FILE_NOTIFYTYPE_TELL:
     657        {
    651658            if (pSvcCbData->mParms == 4)
    652659            {
    653660                pSvcCbData->mpaParms[idx++].getUInt64(&dataCb.u.tell.uOffActual);
    654661
     662                AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     663
    655664                if (mData.mOffCurrent != dataCb.u.tell.uOffActual)
    656665                {
    657666                    mData.mOffCurrent = dataCb.u.tell.uOffActual;
     667                    uint64_t uOffCurrent = mData.mOffCurrent;
     668
     669                    alock.release();
    658670
    659671                    fireGuestFileOffsetChangedEvent(mEventSource, mSession, this,
    660                                                     mData.mOffCurrent, 0 /* Processed */);
     672                                                    uOffCurrent, 0 /* Processed */);
    661673                }
    662674            }
     
    664676                vrc = VERR_NOT_SUPPORTED;
    665677            break;
     678        }
    666679
    667680        default:
     
    670683    }
    671684
    672     LogFlowThisFunc(("strName=%s, uType=%RU32, guestRc=%Rrc\n",
    673                      mData.mOpenInfo.mFileName.c_str(), dataCb.uType, dataCb.rc));
    674 
    675     if (RT_SUCCESS(vrc))
    676     {
    677         /* Nothing to do here yet. */
    678     }
    679     else if (vrc == VERR_NOT_SUPPORTED)
    680     {
    681         /* Also let the callback know. */
    682         guestRc = VERR_NOT_SUPPORTED;
    683     }
     685    LogFlowThisFunc(("uType=%RU32, guestRc=%Rrc\n",
     686                     dataCb.uType, dataCb.rc));
    684687
    685688    LogFlowFuncLeaveRC(vrc);
     
    692695    AssertPtrReturn(pSvcCbData, VERR_INVALID_POINTER);
    693696
    694     LogFlowThisFunc(("strFile=%s\n",
    695                      mData.mOpenInfo.mFileName.c_str()));
    696 
    697697    int vrc = setFileStatus(FileStatus_Down, VINF_SUCCESS);
    698698
     
    701701}
    702702
    703 int GuestFile::openFile(int *pGuestRc)
    704 {
    705     LogFlowThisFunc(("strFile=%s, strOpenMode=%s, strDisposition=%s, uCreationMode=%RU32\n",
     703int GuestFile::openFile(uint32_t uTimeoutMS, int *pGuestRc)
     704{
     705    LogFlowThisFuncEnter();
     706
     707    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     708
     709    LogFlowThisFunc(("strFile=%s, strOpenMode=%s, strDisposition=%s, uCreationMode=%RU32, uOffset=%RU64\n",
    706710                     mData.mOpenInfo.mFileName.c_str(), mData.mOpenInfo.mOpenMode.c_str(),
    707                      mData.mOpenInfo.mDisposition.c_str(), mData.mOpenInfo.mCreationMode));
     711                     mData.mOpenInfo.mDisposition.c_str(), mData.mOpenInfo.mCreationMode, mData.mOpenInfo.mInitialOffset));
    708712    int vrc;
    709713
     
    734738    paParms[i++].setPointer((void*)mData.mOpenInfo.mDisposition.c_str(),
    735739                            (ULONG)mData.mOpenInfo.mDisposition.length() + 1);
     740    paParms[i++].setPointer((void*)mData.mOpenInfo.mSharingMode.c_str(),
     741                            (ULONG)mData.mOpenInfo.mSharingMode.length() + 1);
    736742    paParms[i++].setUInt32(mData.mOpenInfo.mCreationMode);
    737743    paParms[i++].setUInt64(mData.mOpenInfo.mInitialOffset);
    738744
     745    alock.release(); /* Drop read lock before sending. */
     746
    739747    vrc = sendCommand(HOST_FILE_OPEN, i, paParms);
    740748    if (RT_SUCCESS(vrc))
    741         vrc = waitForStatusChange(pEvent, 30 * 1000 /* Timeout in ms */,
    742                                   NULL /* FileStatus */);
     749        vrc = waitForStatusChange(pEvent, uTimeoutMS,
     750                                  NULL /* FileStatus */, pGuestRc);
    743751
    744752    unregisterWaitEvent(pEvent);
     
    903911}
    904912
    905 /* Does not do locking; caller is responsible for that! */
    906913int GuestFile::setFileStatus(FileStatus_T fileStatus, int fileRc)
    907914{
     915    LogFlowThisFuncEnter();
     916
     917    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     918
    908919    LogFlowThisFunc(("oldStatus=%ld, newStatus=%ld, fileRc=%Rrc\n",
    909920                     mData.mStatus, fileStatus, fileRc));
     
    920931    if (mData.mStatus != fileStatus)
    921932    {
    922         mData.mStatus = fileStatus;
     933        mData.mStatus    = fileStatus;
     934        mData.mLastError = fileRc;
    923935
    924936        ComObjPtr<VirtualBoxErrorInfo> errorInfo;
     
    927939        if (RT_FAILURE(fileRc))
    928940        {
    929             int rc2 = errorInfo->initEx(VBOX_E_IPRT_ERROR, fileRc,
    930                                         COM_IIDOF(IGuestFile), getComponentName(),
    931                                         guestErrorToString(fileRc));
    932             AssertRC(rc2);
    933         }
     941            hr = errorInfo->initEx(VBOX_E_IPRT_ERROR, fileRc,
     942                                   COM_IIDOF(IGuestFile), getComponentName(),
     943                                   guestErrorToString(fileRc));
     944            ComAssertComRC(hr);
     945        }
     946
     947        /* Copy over necessary data before releasing lock again. */
     948        FileStatus_T fileStatus = mData.mStatus;
     949
     950        alock.release(); /* Release lock before firing off event. */
    934951
    935952        fireGuestFileStateChangedEvent(mEventSource, mSession,
    936                                        this, mData.mStatus, errorInfo);
     953                                       this, fileStatus, errorInfo);
    937954    }
    938955
     
    10131030}
    10141031
    1015 int GuestFile::waitForStatusChange(GuestWaitEvent *pEvent,
    1016                                    uint32_t uTimeoutMS, FileStatus_T *pFileStatus)
     1032int GuestFile::waitForStatusChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS,
     1033                                   FileStatus_T *pFileStatus, int *pGuestRc)
    10171034{
    10181035    AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
     1036    /* pFileStatus is optional. */
    10191037
    10201038    VBoxEventType_T evtType;
     
    10281046        Assert(!pFileEvent.isNull());
    10291047
    1030         HRESULT hr = pFileEvent->COMGETTER(Status)(pFileStatus);
     1048        HRESULT hr;
     1049        if (pFileStatus)
     1050        {
     1051            hr = pFileEvent->COMGETTER(Status)(pFileStatus);
     1052            ComAssertComRC(hr);
     1053        }
     1054
     1055        ComPtr<IVirtualBoxErrorInfo> errorInfo;
     1056        hr = pFileEvent->COMGETTER(Error)(errorInfo.asOutParam());
    10311057        ComAssertComRC(hr);
     1058
     1059        LONG lGuestRc;
     1060        hr = errorInfo->COMGETTER(ResultDetail)(&lGuestRc);
     1061        ComAssertComRC(hr);
     1062
     1063        LogFlowThisFunc(("resultDetail=%RI32 (rc=%Rrc)\n",
     1064                         lGuestRc, lGuestRc));
     1065
     1066        if (RT_FAILURE((int)lGuestRc))
     1067            vrc = VERR_GSTCTL_GUEST_ERROR;
     1068
     1069        if (pGuestRc)
     1070            *pGuestRc = (int)lGuestRc;
    10321071    }
    10331072
     
    11971236        rc = rc2;
    11981237
    1199     /*
    1200      * Release autocaller before calling uninit.
    1201      */
    1202     autoCaller.release();
    1203 
    1204     uninit();
    1205 
    1206     LogFlowFuncLeaveRC(rc);
    12071238    if (RT_FAILURE(rc))
    12081239    {
     
    12141245    }
    12151246
     1247    LogFlowThisFunc(("Returning rc=%Rrc\n", rc));
    12161248    return S_OK;
    12171249#endif /* VBOX_WITH_GUEST_CONTROL */
  • trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp

    r47630 r47817  
    239239        mData.mExitCode = 0;
    240240        mData.mPID = 0;
    241         mData.mRC = VINF_SUCCESS;
     241        mData.mLastError = VINF_SUCCESS;
    242242        mData.mStatus = ProcessStatus_Undefined;
    243243        /* Everything else will be set by the actual starting routine. */
     
    967967        /* Do not allow overwriting an already set error. If this happens
    968968         * this means we forgot some error checking/locking somewhere. */
    969         AssertMsg(RT_SUCCESS(mData.mRC), ("Guest rc already set (to %Rrc)\n", mData.mRC));
     969        AssertMsg(RT_SUCCESS(mData.mLastError), ("Guest rc already set (to %Rrc)\n", mData.mLastError));
    970970    }
    971971    else
     
    976976    if (mData.mStatus != procStatus) /* Was there a process status change? */
    977977    {
    978         mData.mStatus = procStatus;
    979         mData.mRC    = procRc;
     978        mData.mStatus    = procStatus;
     979        mData.mLastError = procRc;
    980980
    981981        ComObjPtr<VirtualBoxErrorInfo> errorInfo;
    982982        HRESULT hr = errorInfo.createObject();
    983983        ComAssertComRC(hr);
    984         if (RT_FAILURE(mData.mRC))
    985         {
    986             int rc2 = errorInfo->initEx(VBOX_E_IPRT_ERROR, mData.mRC,
    987                                         COM_IIDOF(IGuestProcess), getComponentName(),
    988                                         guestErrorToString(mData.mRC));
    989             AssertRC(rc2);
     984        if (RT_FAILURE(mData.mLastError))
     985        {
     986            hr = errorInfo->initEx(VBOX_E_IPRT_ERROR, mData.mLastError,
     987                                   COM_IIDOF(IGuestProcess), getComponentName(),
     988                                   guestErrorToString(mData.mLastError));
     989            ComAssertComRC(hr);
    990990        }
    991991
    992992        /* Copy over necessary data before releasing lock again. */
    993993        uint32_t uPID =  mData.mPID;
    994         ProcessStatus_T uStatus = mData.mStatus;
     994        ProcessStatus_T procStatus = mData.mStatus;
    995995        /** @todo Also handle mSession? */
    996996
     
    998998
    999999        fireGuestProcessStateChangedEvent(mEventSource, mSession, this,
    1000                                           uPID, uStatus, errorInfo);
     1000                                          uPID, procStatus, errorInfo);
    10011001#if 0
    10021002        /*
     
    14081408
    14091409    LogFlowThisFunc(("fWaitFlags=0x%x, uTimeoutMS=%RU32, procStatus=%RU32, procRc=%Rrc, pGuestRc=%p\n",
    1410                      fWaitFlags, uTimeoutMS, mData.mStatus, mData.mRC, pGuestRc));
     1410                     fWaitFlags, uTimeoutMS, mData.mStatus, mData.mLastError, pGuestRc));
    14111411
    14121412    /* Did some error occur before? Then skip waiting and return. */
     
    14141414    {
    14151415        waitResult = ProcessWaitResult_Error;
    1416         AssertMsg(RT_FAILURE(mData.mRC), ("No error rc (%Rrc) set when guest process indicated an error\n", mData.mRC));
     1416        AssertMsg(RT_FAILURE(mData.mLastError), ("No error rc (%Rrc) set when guest process indicated an error\n", mData.mLastError));
    14171417        if (pGuestRc)
    1418             *pGuestRc = mData.mRC; /* Return last set error. */
     1418            *pGuestRc = mData.mLastError; /* Return last set error. */
    14191419        return VERR_GSTCTL_GUEST_ERROR;
    14201420    }
     
    14271427    {
    14281428        if (pGuestRc)
    1429             *pGuestRc = mData.mRC; /* Return last set error (if any). */
    1430         return RT_SUCCESS(mData.mRC) ? VINF_SUCCESS : VERR_GSTCTL_GUEST_ERROR;
     1429            *pGuestRc = mData.mLastError; /* Return last set error (if any). */
     1430        return RT_SUCCESS(mData.mLastError) ? VINF_SUCCESS : VERR_GSTCTL_GUEST_ERROR;
    14311431    }
    14321432
  • trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp

    r47781 r47817  
    10051005                             Utf8Str(strName).c_str(), mData.mSession.mID, mData.mFiles.size() - 1, mData.mNumObjects - 1));
    10061006
    1007             itFiles->second->Release();
     1007            pFile->cancelWaitEvents();
     1008            pFile->Release();
    10081009
    10091010            mData.mFiles.erase(itFiles);
     
    10541055int GuestSession::fileOpenInternal(const GuestFileOpenInfo &openInfo, ComObjPtr<GuestFile> &pFile, int *pGuestRc)
    10551056{
    1056     LogFlowThisFunc(("strPath=%s, strOpenMode=%s, strDisposition=%s, uCreationMode=%x, iOffset=%RI64\n",
     1057    LogFlowThisFunc(("strPath=%s, strOpenMode=%s, strDisposition=%s, uCreationMode=%x, uOffset=%RU64\n",
    10571058                     openInfo.mFileName.c_str(), openInfo.mOpenMode.c_str(), openInfo.mDisposition.c_str(),
    10581059                     openInfo.mCreationMode, openInfo.mInitialOffset));
     
    11111112        return rc;
    11121113
    1113     int guestRc;
    1114     rc = pFile->openFile(&guestRc);
     1114    /*
     1115     * Since this is a synchronous guest call we have to
     1116     * register the file object first, releasing the session's
     1117     * lock and then proceed with the actual opening command
     1118     * -- otherwise the file's opening callback would hang
     1119     * because the session's lock still is in place.
     1120     */
     1121    try
     1122    {
     1123        /* Add the created file to our vector. */
     1124        mData.mFiles[uNewFileID] = pFile;
     1125        mData.mNumObjects++;
     1126        Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
     1127
     1128        LogFlowFunc(("Added new guest file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n",
     1129                     openInfo.mFileName.c_str(), mData.mSession.mID, mData.mFiles.size(), mData.mNumObjects));
     1130
     1131        alock.release(); /* Release lock before firing off event. */
     1132
     1133        fireGuestFileRegisteredEvent(mEventSource, this, pFile,
     1134                                     true /* Registered */);
     1135    }
     1136    catch (std::bad_alloc &)
     1137    {
     1138        rc = VERR_NO_MEMORY;
     1139    }
     1140
    11151141    if (RT_SUCCESS(rc))
    11161142    {
    1117         try
    1118         {
    1119             /* Add the created file to our vector. */
    1120             mData.mFiles[uNewFileID] = pFile;
    1121             mData.mNumObjects++;
    1122             Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
    1123 
    1124             LogFlowFunc(("Added new guest file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n",
    1125                          openInfo.mFileName.c_str(), mData.mSession.mID, mData.mFiles.size(), mData.mNumObjects));
    1126 
    1127             alock.release(); /* Release lock before firing off event. */
    1128 
    1129             fireGuestFileRegisteredEvent(mEventSource, this, pFile,
    1130                                          true /* Registered */);
    1131             if (pGuestRc)
    1132                 *pGuestRc = guestRc;
    1133         }
    1134         catch (std::bad_alloc &)
    1135         {
    1136             rc = VERR_NO_MEMORY;
     1143        int guestRc;
     1144        rc = pFile->openFile(30 * 1000 /* 30s timeout */, &guestRc);
     1145        if (   rc == VERR_GSTCTL_GUEST_ERROR
     1146            && pGuestRc)
     1147        {
     1148            *pGuestRc = guestRc;
    11371149        }
    11381150    }
     
    27282740}
    27292741
    2730 STDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile)
     2742STDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, IGuestFile **aFile)
     2743{
     2744#ifndef VBOX_WITH_GUEST_CONTROL
     2745    ReturnComNotImplemented();
     2746#else
     2747    LogFlowThisFuncEnter();
     2748
     2749    Bstr strSharingMode = ""; /* Sharing mode is ignored. */
     2750
     2751    return FileOpenEx(aPath, aOpenMode, aDisposition, strSharingMode.raw(), aCreationMode,
     2752                      0 /* aOffset */, aFile);
     2753#endif /* VBOX_WITH_GUEST_CONTROL */
     2754}
     2755
     2756STDMETHODIMP GuestSession::FileOpenEx(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, IN_BSTR aSharingMode,
     2757                                      ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile)
    27312758{
    27322759#ifndef VBOX_WITH_GUEST_CONTROL
     
    27412768    if (RT_UNLIKELY((aDisposition) == NULL || *(aDisposition) == '\0'))
    27422769        return setError(E_INVALIDARG, tr("No disposition mode specified"));
     2770    /* aSharingMode is optional. */
    27432771
    27442772    CheckComArgOutPointerValid(aFile);
     
    27502778    if (FAILED(hr))
    27512779        return hr;
    2752 
    2753     /** @todo Validate open mode. */
    2754     /** @todo Validate disposition mode. */
    27552780
    27562781    /** @todo Validate creation mode. */
     
    27612786    openInfo.mOpenMode = Utf8Str(aOpenMode);
    27622787    openInfo.mDisposition = Utf8Str(aDisposition);
     2788    openInfo.mSharingMode = Utf8Str(aSharingMode);
    27632789    openInfo.mCreationMode = aCreationMode;
    27642790    openInfo.mInitialOffset = aOffset;
    27652791
     2792    uint64_t uFlagsIgnored;
     2793    int vrc = RTFileModeToFlagsEx(openInfo.mOpenMode.c_str(),
     2794                                  openInfo.mDisposition.c_str(),
     2795                                  openInfo.mSharingMode.c_str(),
     2796                                  &uFlagsIgnored);
     2797    if (RT_FAILURE(vrc))
     2798        return setError(E_INVALIDARG, tr("Invalid open mode / disposition / sharing mode specified"));
     2799
    27662800    ComObjPtr <GuestFile> pFile; int guestRc;
    2767     int vrc = fileOpenInternal(openInfo, pFile, &guestRc);
     2801    vrc = fileOpenInternal(openInfo, pFile, &guestRc);
    27682802    if (RT_SUCCESS(vrc))
    27692803    {
Note: See TracChangeset for help on using the changeset viewer.

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