VirtualBox

Changeset 69955 in vbox


Ignore:
Timestamp:
Dec 6, 2017 12:26:37 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119457
Message:

IPRT/vfs: Made pfnSetMode, pfnSetTimes, pfnSetOwner and pfnWrite optional and fallback to VERR_WRITE_PROTECT.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/vfslowlevel.h

    r69942 r69955  
    327327     * @param   fMask               The mask indicating which bits we are
    328328     *                              changing.
     329     * @note    Optional, failing with VERR_WRITE_PROTECT if NULL.
    329330     * @sa      RTFileSetMode
    330331     */
     
    346347     * @remarks See RTFileSetTimes for restrictions and behavior imposed by the
    347348     *          host OS or underlying VFS provider.
     349     * @note    Optional, failing with VERR_WRITE_PROTECT if NULL.
    348350     * @sa      RTFileSetTimes
    349351     */
     
    360362     * @param   gid         The group ID of the new owner group.  NIL_RTGID if
    361363     *                      unchanged.
     364     * @note    Optional, failing with VERR_WRITE_PROTECT if NULL.
    362365     * @sa      RTFileSetOwner
    363366     */
     
    859862     *                      written.  This is set it 0 by the caller.  If
    860863     *                      NULL, try write it all and fail if incomplete.
     864     * @note    Optional, failing with VERR_WRITE_PROTECT if NULL.
    861865     * @sa      RTFileWrite, RTFileWriteAt.
    862866     */
  • trunk/src/VBox/Runtime/common/fs/isomaker.cpp

    r69942 r69955  
    72507250
    72517251/**
    7252  * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    7253  */
    7254 static DECLCALLBACK(int) rtFsIsoMakerOutFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    7255 {
    7256     RT_NOREF(pvThis, off, pSgBuf, fBlocking, pcbWritten);
    7257     return VERR_WRITE_PROTECT;
    7258 }
    7259 
    7260 
    7261 /**
    72627252 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnFlush}
    72637253 */
     
    72877277    RTFOFF offIgnored;
    72887278    return rtFsIsoMakerOutFile_Seek(pvThis, cb, RTFILE_SEEK_CURRENT, &offIgnored);
    7289 }
    7290 
    7291 
    7292 /**
    7293  * @interface_method_impl{RTVFSOBJSETOPS,pfnMode}
    7294  */
    7295 static DECLCALLBACK(int) rtFsIsoMakerOutFile_SetMode(void *pvThis, RTFMODE fMode, RTFMODE fMask)
    7296 {
    7297     RT_NOREF(pvThis, fMode, fMask);
    7298     return VERR_WRITE_PROTECT;
    7299 }
    7300 
    7301 
    7302 /**
    7303  * @interface_method_impl{RTVFSOBJSETOPS,pfnSetTimes}
    7304  */
    7305 static DECLCALLBACK(int) rtFsIsoMakerOutFile_SetTimes(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
    7306                                                       PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
    7307 {
    7308     RT_NOREF(pvThis, pAccessTime, pModificationTime, pChangeTime, pBirthTime);
    7309     return VERR_WRITE_PROTECT;
    7310 }
    7311 
    7312 
    7313 /**
    7314  * @interface_method_impl{RTVFSOBJSETOPS,pfnSetOwner}
    7315  */
    7316 static DECLCALLBACK(int) rtFsIsoMakerOutFile_SetOwner(void *pvThis, RTUID uid, RTGID gid)
    7317 {
    7318     RT_NOREF(pvThis, uid, gid);
    7319     return VERR_WRITE_PROTECT;
    73207279}
    73217280
     
    74027361        RTVFSIOSTREAMOPS_FEAT_NO_SG,
    74037362        rtFsIsoMakerOutFile_Read,
    7404         rtFsIsoMakerOutFile_Write,
     7363        NULL /*Write*/,
    74057364        rtFsIsoMakerOutFile_Flush,
    74067365        NULL /*PollOne*/,
     
    74157374        RTVFSOBJSETOPS_VERSION,
    74167375        RT_OFFSETOF(RTVFSFILEOPS, Stream.Obj) - RT_OFFSETOF(RTVFSFILEOPS, ObjSet),
    7417         rtFsIsoMakerOutFile_SetMode,
    7418         rtFsIsoMakerOutFile_SetTimes,
    7419         rtFsIsoMakerOutFile_SetOwner,
     7376        NULL /*SetMode*/,
     7377        NULL /*SetTimes*/,
     7378        NULL /*SetOwner*/,
    74207379        RTVFSOBJSETOPS_VERSION
    74217380    },
  • trunk/src/VBox/Runtime/common/fs/isovfs.cpp

    r69924 r69955  
    20282028
    20292029/**
    2030  * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    2031  */
    2032 static DECLCALLBACK(int) rtFsIsoFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    2033 {
    2034     RT_NOREF(pvThis, off, pSgBuf, fBlocking, pcbWritten);
    2035     return VERR_WRITE_PROTECT;
    2036 }
    2037 
    2038 
    2039 /**
    20402030 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnFlush}
    20412031 */
     
    20852075    *poffActual = pThis->offFile;
    20862076    return VINF_SUCCESS;
    2087 }
    2088 
    2089 
    2090 /**
    2091  * @interface_method_impl{RTVFSOBJSETOPS,pfnMode}
    2092  */
    2093 static DECLCALLBACK(int) rtFsIsoFile_SetMode(void *pvThis, RTFMODE fMode, RTFMODE fMask)
    2094 {
    2095     RT_NOREF(pvThis, fMode, fMask);
    2096     return VERR_WRITE_PROTECT;
    2097 }
    2098 
    2099 
    2100 /**
    2101  * @interface_method_impl{RTVFSOBJSETOPS,pfnSetTimes}
    2102  */
    2103 static DECLCALLBACK(int) rtFsIsoFile_SetTimes(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
    2104                                                  PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
    2105 {
    2106     RT_NOREF(pvThis, pAccessTime, pModificationTime, pChangeTime, pBirthTime);
    2107     return VERR_WRITE_PROTECT;
    2108 }
    2109 
    2110 
    2111 /**
    2112  * @interface_method_impl{RTVFSOBJSETOPS,pfnSetOwner}
    2113  */
    2114 static DECLCALLBACK(int) rtFsIsoFile_SetOwner(void *pvThis, RTUID uid, RTGID gid)
    2115 {
    2116     RT_NOREF(pvThis, uid, gid);
    2117     return VERR_WRITE_PROTECT;
    21182077}
    21192078
     
    21822141        RTVFSIOSTREAMOPS_FEAT_NO_SG,
    21832142        rtFsIsoFile_Read,
    2184         rtFsIsoFile_Write,
     2143        NULL /*Write*/,
    21852144        rtFsIsoFile_Flush,
    21862145        rtFsIsoFile_PollOne,
     
    21952154        RTVFSOBJSETOPS_VERSION,
    21962155        RT_OFFSETOF(RTVFSFILEOPS, Stream.Obj) - RT_OFFSETOF(RTVFSFILEOPS, ObjSet),
    2197         rtFsIsoFile_SetMode,
    2198         rtFsIsoFile_SetTimes,
    2199         rtFsIsoFile_SetOwner,
     2156        NULL /*SetMode*/,
     2157        NULL /*SetTimes*/,
     2158        NULL /*SetOwner*/,
    22002159        RTVFSOBJSETOPS_VERSION
    22012160    },
     
    28562815    PRTFSISODIROBJ pThis = (PRTFSISODIROBJ)pvThis;
    28572816    return rtFsIsoCore_QueryInfo(&pThis->pShared->Core, pObjInfo, enmAddAttr);
    2858 }
    2859 
    2860 
    2861 /**
    2862  * @interface_method_impl{RTVFSOBJSETOPS,pfnMode}
    2863  */
    2864 static DECLCALLBACK(int) rtFsIsoDir_SetMode(void *pvThis, RTFMODE fMode, RTFMODE fMask)
    2865 {
    2866     RT_NOREF(pvThis, fMode, fMask);
    2867     return VERR_WRITE_PROTECT;
    2868 }
    2869 
    2870 
    2871 /**
    2872  * @interface_method_impl{RTVFSOBJSETOPS,pfnSetTimes}
    2873  */
    2874 static DECLCALLBACK(int) rtFsIsoDir_SetTimes(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
    2875                                                  PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
    2876 {
    2877     RT_NOREF(pvThis, pAccessTime, pModificationTime, pChangeTime, pBirthTime);
    2878     return VERR_WRITE_PROTECT;
    2879 }
    2880 
    2881 
    2882 /**
    2883  * @interface_method_impl{RTVFSOBJSETOPS,pfnSetOwner}
    2884  */
    2885 static DECLCALLBACK(int) rtFsIsoDir_SetOwner(void *pvThis, RTUID uid, RTGID gid)
    2886 {
    2887     RT_NOREF(pvThis, uid, gid);
    2888     return VERR_WRITE_PROTECT;
    28892817}
    28902818
     
    35013429        RTVFSOBJSETOPS_VERSION,
    35023430        RT_OFFSETOF(RTVFSDIROPS, Obj) - RT_OFFSETOF(RTVFSDIROPS, ObjSet),
    3503         rtFsIsoDir_SetMode,
    3504         rtFsIsoDir_SetTimes,
    3505         rtFsIsoDir_SetOwner,
     3431        NULL /*SetMode*/,
     3432        NULL /*SetTimes*/,
     3433        NULL /*SetOwner*/,
    35063434        RTVFSOBJSETOPS_VERSION
    35073435    },
  • trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp

    r69942 r69955  
    8181        Assert((a_pSetOps)->uVersion == RTVFSOBJSETOPS_VERSION); \
    8282        Assert((a_pSetOps)->offObjOps == (a_offObjOps)); \
    83         AssertPtr((a_pSetOps)->pfnSetMode); \
    84         AssertPtr((a_pSetOps)->pfnSetTimes); \
    85         AssertPtr((a_pSetOps)->pfnSetOwner); \
     83        AssertPtrNull((a_pSetOps)->pfnSetMode); \
     84        AssertPtrNull((a_pSetOps)->pfnSetTimes); \
     85        AssertPtrNull((a_pSetOps)->pfnSetOwner); \
    8686        Assert((a_pSetOps)->uEndMarker == RTVFSOBJSETOPS_VERSION); \
    8787    } while (0)
     
    113113        Assert(!((pIoStreamOps)->fFeatures & ~RTVFSIOSTREAMOPS_FEAT_VALID_MASK)); \
    114114        AssertPtr((pIoStreamOps)->pfnRead); \
    115         AssertPtr((pIoStreamOps)->pfnWrite); \
     115        AssertPtrNull((pIoStreamOps)->pfnWrite); \
    116116        AssertPtr((pIoStreamOps)->pfnFlush); \
    117117        AssertPtrNull((pIoStreamOps)->pfnPollOne); \
     
    126126    do { \
    127127        RTVFSOBJ_ASSERT_OPS(&(pSymlinkOps)->Obj, a_enmType); \
    128         RTVFSOBJSET_ASSERT_OPS(&(pSymlinkOps)->ObjSet, \
    129             RT_OFFSETOF(RTVFSSYMLINKOPS, Obj) - RT_OFFSETOF(RTVFSSYMLINKOPS, ObjSet)); \
     128        RTVFSOBJSET_ASSERT_OPS(&(pSymlinkOps)->ObjSet, RT_OFFSETOF(RTVFSSYMLINKOPS, Obj) - RT_OFFSETOF(RTVFSSYMLINKOPS, ObjSet)); \
    130129        Assert((pSymlinkOps)->uVersion == RTVFSSYMLINKOPS_VERSION); \
    131130        Assert(!(pSymlinkOps)->fReserved); \
     
    13171316    AssertReturn(pObjSetOps, VERR_INVALID_FUNCTION);
    13181317
    1319     RTVfsLockAcquireWrite(pThis->hLock);
    1320     int rc = pObjSetOps->pfnSetMode(pThis->pvThis, fMode, fMask);
    1321     RTVfsLockReleaseWrite(pThis->hLock);
     1318    int rc;
     1319    if (pObjSetOps->pfnSetMode)
     1320    {
     1321        RTVfsLockAcquireWrite(pThis->hLock);
     1322        rc = pObjSetOps->pfnSetMode(pThis->pvThis, fMode, fMask);
     1323        RTVfsLockReleaseWrite(pThis->hLock);
     1324    }
     1325    else
     1326        rc = VERR_WRITE_PROTECT;
    13221327    return rc;
    13231328}
     
    13391344    AssertReturn(pObjSetOps, VERR_INVALID_FUNCTION);
    13401345
    1341     RTVfsLockAcquireWrite(pThis->hLock);
    1342     int rc = pObjSetOps->pfnSetTimes(pThis->pvThis, pAccessTime, pModificationTime, pChangeTime, pBirthTime);
    1343     RTVfsLockReleaseWrite(pThis->hLock);
     1346    int rc;
     1347    if (pObjSetOps->pfnSetTimes)
     1348    {
     1349        RTVfsLockAcquireWrite(pThis->hLock);
     1350        rc = pObjSetOps->pfnSetTimes(pThis->pvThis, pAccessTime, pModificationTime, pChangeTime, pBirthTime);
     1351        RTVfsLockReleaseWrite(pThis->hLock);
     1352    }
     1353    else
     1354        rc = VERR_WRITE_PROTECT;
    13441355    return rc;
    13451356}
     
    13551366    AssertReturn(pObjSetOps, VERR_INVALID_FUNCTION);
    13561367
    1357     RTVfsLockAcquireWrite(pThis->hLock);
    1358     int rc = pObjSetOps->pfnSetOwner(pThis->pvThis, uid, gid);
    1359     RTVfsLockReleaseWrite(pThis->hLock);
     1368    int rc;
     1369    if (pObjSetOps->pfnSetOwner)
     1370    {
     1371        RTVfsLockAcquireWrite(pThis->hLock);
     1372        rc = pObjSetOps->pfnSetOwner(pThis->pvThis, uid, gid);
     1373        RTVfsLockReleaseWrite(pThis->hLock);
     1374    }
     1375    else
     1376        rc = VERR_WRITE_PROTECT;
    13601377    return rc;
    13611378}
     
    34993516    AssertReturn(pThis->fFlags & RTFILE_O_WRITE, VERR_ACCESS_DENIED);
    35003517
    3501     RTSGSEG Seg = { (void *)pvBuf, cbToWrite };
    3502     RTSGBUF SgBuf;
    3503     RTSgBufInit(&SgBuf, &Seg, 1);
    3504 
    3505     RTVfsLockAcquireWrite(pThis->Base.hLock);
    3506     int rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbWritten);
    3507     RTVfsLockReleaseWrite(pThis->Base.hLock);
     3518    int rc;
     3519    if (pThis->pOps->pfnWrite)
     3520    {
     3521        RTSGSEG Seg = { (void *)pvBuf, cbToWrite };
     3522        RTSGBUF SgBuf;
     3523        RTSgBufInit(&SgBuf, &Seg, 1);
     3524
     3525        RTVfsLockAcquireWrite(pThis->Base.hLock);
     3526        rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbWritten);
     3527        RTVfsLockReleaseWrite(pThis->Base.hLock);
     3528    }
     3529    else
     3530        rc = VERR_WRITE_PROTECT;
    35083531    return rc;
    35093532}
     
    35223545    AssertReturn(pThis->fFlags & RTFILE_O_WRITE, VERR_ACCESS_DENIED);
    35233546
    3524     RTSGSEG Seg = { (void *)pvBuf, cbToWrite };
    3525     RTSGBUF SgBuf;
    3526     RTSgBufInit(&SgBuf, &Seg, 1);
    3527 
    3528     RTVfsLockAcquireWrite(pThis->Base.hLock);
    3529     int rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbWritten);
    3530     RTVfsLockReleaseWrite(pThis->Base.hLock);
     3547    int rc;
     3548    if (pThis->pOps->pfnWrite)
     3549    {
     3550        RTSGSEG Seg = { (void *)pvBuf, cbToWrite };
     3551        RTSGBUF SgBuf;
     3552        RTSgBufInit(&SgBuf, &Seg, 1);
     3553
     3554        RTVfsLockAcquireWrite(pThis->Base.hLock);
     3555        rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbWritten);
     3556        RTVfsLockReleaseWrite(pThis->Base.hLock);
     3557    }
     3558    else
     3559        rc = VERR_WRITE_PROTECT;
    35313560    return rc;
    35323561}
     
    35903619    AssertReturn(pThis->fFlags & RTFILE_O_WRITE, VERR_ACCESS_DENIED);
    35913620
    3592     RTVfsLockAcquireWrite(pThis->Base.hLock);
    35933621    int rc;
    3594     if (!(pThis->pOps->fFeatures & RTVFSIOSTREAMOPS_FEAT_NO_SG))
    3595         rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, off, pSgBuf, fBlocking, pcbWritten);
     3622    if (pThis->pOps->pfnWrite)
     3623    {
     3624        RTVfsLockAcquireWrite(pThis->Base.hLock);
     3625        if (!(pThis->pOps->fFeatures & RTVFSIOSTREAMOPS_FEAT_NO_SG))
     3626            rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, off, pSgBuf, fBlocking, pcbWritten);
     3627        else
     3628        {
     3629            size_t cbWritten = 0;
     3630            rc = VINF_SUCCESS;
     3631
     3632            for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
     3633            {
     3634                RTSGBUF SgBuf;
     3635                RTSgBufInit(&SgBuf, &pSgBuf->paSegs[iSeg], 1);
     3636
     3637                size_t cbWrittenSeg = 0;
     3638                rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbWritten ? &cbWrittenSeg : NULL);
     3639                if (RT_FAILURE(rc))
     3640                    break;
     3641                if (pcbWritten)
     3642                {
     3643                    cbWritten += cbWrittenSeg;
     3644                    if (cbWrittenSeg != SgBuf.paSegs[0].cbSeg)
     3645                        break;
     3646                    if (off != -1)
     3647                        off += cbWrittenSeg;
     3648                }
     3649                else if (off != -1)
     3650                    off += pSgBuf->paSegs[iSeg].cbSeg;
     3651            }
     3652
     3653            if (pcbWritten)
     3654                *pcbWritten = cbWritten;
     3655        }
     3656        RTVfsLockReleaseWrite(pThis->Base.hLock);
     3657    }
    35963658    else
    3597     {
    3598         size_t cbWritten = 0;
    3599         rc = VINF_SUCCESS;
    3600 
    3601         for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
    3602         {
    3603             RTSGBUF SgBuf;
    3604             RTSgBufInit(&SgBuf, &pSgBuf->paSegs[iSeg], 1);
    3605 
    3606             size_t cbWrittenSeg = 0;
    3607             rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbWritten ? &cbWrittenSeg : NULL);
    3608             if (RT_FAILURE(rc))
    3609                 break;
    3610             if (pcbWritten)
    3611             {
    3612                 cbWritten += cbWrittenSeg;
    3613                 if (cbWrittenSeg != SgBuf.paSegs[0].cbSeg)
    3614                     break;
    3615                 if (off != -1)
    3616                     off += cbWrittenSeg;
    3617             }
    3618             else if (off != -1)
    3619                 off += pSgBuf->paSegs[iSeg].cbSeg;
    3620         }
    3621 
    3622         if (pcbWritten)
    3623             *pcbWritten = cbWritten;
    3624     }
    3625     RTVfsLockReleaseWrite(pThis->Base.hLock);
     3659        rc = VERR_WRITE_PROTECT;
    36263660    return rc;
    36273661}
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