VirtualBox

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


Ignore:
Timestamp:
Mar 23, 2023 5:08:44 PM (2 years ago)
Author:
vboxsync
Message:

Guest Control/VBoxService: A bit of cleanup for internal directory / file entry handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp

    r99120 r99147  
    141141 * Must be released via vgsvcGstCtrlSessionDirRelease().
    142142 *
    143  * @returns VBox status code.
     143 * @returns Guest directory entry on success, or NULL if not found.
    144144 * @param   pSession            Guest control session to acquire guest directory for.
    145145 * @param   uHandle             Handle of directory to acquire.
     
    175175
    176176
     177/**
     178 * Free's a guest file entry.
     179 *
     180 * @returns VBox status code.
     181 * @param   pFile               Guest file entry to free.
     182 *                              The pointer wil be invalid on success.
     183 */
    177184static int vgsvcGstCtrlSessionFileFree(PVBOXSERVICECTRLFILE pFile)
    178185{
     
    194201
    195202
    196 /** @todo No locking done yet! */
    197 static PVBOXSERVICECTRLFILE vgsvcGstCtrlSessionFileGetLocked(const PVBOXSERVICECTRLSESSION pSession, uint32_t uHandle)
     203/**
     204 * Acquires an internal guest file entry.
     205 *
     206 * Must be released via vgsvcGstCtrlSessionFileRelease().
     207 *
     208 * @returns Guest file entry on success, or NULL if not found.
     209 * @param   pSession            Guest session to use.
     210 * @param   uHandle             Handle of guest file entry to acquire.
     211 *
     212 * @note    No locking done yet.
     213 */
     214static PVBOXSERVICECTRLFILE vgsvcGstCtrlSessionFileAcquire(const PVBOXSERVICECTRLSESSION pSession, uint32_t uHandle)
    198215{
    199216    AssertPtrReturn(pSession, NULL);
     
    208225
    209226    return NULL;
     227}
     228
     229
     230/**
     231 * Releases a formerly acquired guest file.
     232 *
     233 * @param   pFile               File to release.
     234 */
     235static void vgsvcGstCtrlSessionFileRelease(PVBOXSERVICECTRLFILE pFile)
     236{
     237    RT_NOREF(pFile);
    210238}
    211239
     
    514542    if (RT_SUCCESS(rc))
    515543    {
    516         PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
     544        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileAcquire(pSession, uHandle);
    517545        if (pFile)
    518546        {
     
    568596        uint32_t offNew = 0;
    569597        size_t   cbRead = 0;
    570         PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
     598        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileAcquire(pSession, uHandle);
    571599        if (pFile)
    572600        {
     
    577605            offNew = (int64_t)RTFileTell(pFile->hFile);
    578606            VGSvcVerbose(5, "[File %s] Read %zu/%RU32 bytes, rc=%Rrc, offNew=%RI64\n", pFile->pszName, cbRead, cbToRead, rc, offNew);
     607            vgsvcGstCtrlSessionFileRelease(pFile);
    579608        }
    580609        else
     
    631660        int64_t offNew = 0;
    632661        size_t  cbRead = 0;
    633         PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
     662        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileAcquire(pSession, uHandle);
    634663        if (pFile)
    635664        {
     
    646675                offNew = (int64_t)RTFileTell(pFile->hFile);
    647676            VGSvcVerbose(5, "[File %s] Read %zu bytes @ %RU64, rc=%Rrc, offNew=%RI64\n", pFile->pszName, cbRead, offReadAt, rc, offNew);
     677            vgsvcGstCtrlSessionFileRelease(pFile);
    648678        }
    649679        else
     
    699729        int64_t offNew    = 0;
    700730        size_t  cbWritten = 0;
    701         PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
     731        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileAcquire(pSession, uHandle);
    702732        if (pFile)
    703733        {
     
    706736            VGSvcVerbose(5, "[File %s] Writing %p LB %RU32 =>  %Rrc, cbWritten=%zu, offNew=%RI64\n",
    707737                         pFile->pszName, *ppvScratchBuf, RT_MIN(cbToWrite, *pcbScratchBuf), rc, cbWritten, offNew);
     738            vgsvcGstCtrlSessionFileRelease(pFile);
    708739        }
    709740        else
     
    760791        int64_t offNew    = 0;
    761792        size_t  cbWritten = 0;
    762         PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
     793        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileAcquire(pSession, uHandle);
    763794        if (pFile)
    764795        {
     
    778809            VGSvcVerbose(5, "[File %s] Writing %p LB %RU32 @ %RU64 =>  %Rrc, cbWritten=%zu, offNew=%RI64\n",
    779810                         pFile->pszName, *ppvScratchBuf, RT_MIN(cbToWrite, *pcbScratchBuf), offWriteAt, rc, cbWritten, offNew);
     811            vgsvcGstCtrlSessionFileRelease(pFile);
    780812        }
    781813        else
     
    839871             * Locate the file and do the seek.
    840872             */
    841             PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
     873            PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileAcquire(pSession, uHandle);
    842874            if (pFile)
    843875            {
     
    845877                VGSvcVerbose(5, "[File %s]: Seeking to offSeek=%RI64, uSeekMethodIPRT=%u, rc=%Rrc\n",
    846878                             pFile->pszName, offSeek, s_abMethods[uSeekMethod], rc);
     879                vgsvcGstCtrlSessionFileRelease(pFile);
    847880            }
    848881            else
     
    894927         */
    895928        uint64_t offCurrent = 0;
    896         PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
     929        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileAcquire(pSession, uHandle);
    897930        if (pFile)
    898931        {
    899932            offCurrent = RTFileTell(pFile->hFile);
    900933            VGSvcVerbose(5, "[File %s]: Telling offCurrent=%RU64\n", pFile->pszName, offCurrent);
     934            vgsvcGstCtrlSessionFileRelease(pFile);
    901935        }
    902936        else
     
    942976         * Locate the file and ask for the current position.
    943977         */
    944         PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
     978        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileAcquire(pSession, uHandle);
    945979        if (pFile)
    946980        {
    947981            rc = RTFileSetSize(pFile->hFile, cbNew);
    948982            VGSvcVerbose(5, "[File %s]: Changing size to %RU64 (%#RX64), rc=%Rrc\n", pFile->pszName, cbNew, cbNew, rc);
     983            vgsvcGstCtrlSessionFileRelease(pFile);
    949984        }
    950985        else
     
    11111146            VGSvcVerbose(2, "[Dir %s] Closing (handle=%RU32)\n", pDir ? pDir->pszPathAbs : "<Not found>", uHandle);
    11121147            rc = vgsvcGstCtrlSessionDirFree(pDir);
    1113 
    1114             vgsvcGstCtrlSessionDirRelease(pDir);
    11151148        }
    11161149        else
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