VirtualBox

Ignore:
Timestamp:
Apr 19, 2017 7:29:36 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114658
Message:

IPRT: More FAT fun (couldn't stop myself).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp

    r66601 r66615  
    8080        AssertPtr((a_pSetOps)->pfnSetOwner); \
    8181        Assert((a_pSetOps)->uEndMarker == RTVFSOBJSETOPS_VERSION); \
     82    } while (0)
     83
     84/** Asserts that the VFS directory vtable is valid. */
     85#define RTVFSDIR_ASSERT_OPS(pDirOps, a_enmType) \
     86    do { \
     87        RTVFSOBJ_ASSERT_OPS(&(pDirOps)->Obj, a_enmType); \
     88        RTVFSOBJSET_ASSERT_OPS(&(pDirOps)->ObjSet, RT_OFFSETOF(RTVFSDIROPS, Obj) - RT_OFFSETOF(RTVFSDIROPS, ObjSet)); \
     89        Assert((pDirOps)->uVersion == RTVFSDIROPS_VERSION); \
     90        Assert(!(pDirOps)->fReserved); \
     91        AssertPtr((pDirOps)->pfnTraversalOpen); \
     92        AssertPtr((pDirOps)->pfnOpenFile); \
     93        AssertPtr((pDirOps)->pfnOpenDir); \
     94        AssertPtr((pDirOps)->pfnCreateDir); \
     95        AssertPtr((pDirOps)->pfnOpenSymlink); \
     96        AssertPtr((pDirOps)->pfnCreateSymlink); \
     97        AssertPtr((pDirOps)->pfnUnlinkEntry); \
     98        AssertPtr((pDirOps)->pfnRewindDir); \
     99        AssertPtr((pDirOps)->pfnReadDir); \
     100        Assert((pDirOps)->uEndMarker == RTVFSDIROPS_VERSION); \
    82101    } while (0)
    83102
     
    16341653    AssertReturn(pVfsOps->uVersion   == RTVFSOPS_VERSION, VERR_VERSION_MISMATCH);
    16351654    AssertReturn(pVfsOps->uEndMarker == RTVFSOPS_VERSION, VERR_VERSION_MISMATCH);
     1655    RTVFSOBJ_ASSERT_OPS(&pVfsOps->Obj, RTVFSOBJTYPE_VFS);
    16361656    Assert(cbInstance > 0);
    16371657    AssertPtr(ppvInstance);
     
    16471667        return VERR_NO_MEMORY;
    16481668
    1649     int rc = rtVfsObjInitNewObject(&pThis->Base, NULL, hVfs, hLock,
     1669    int rc = rtVfsObjInitNewObject(&pThis->Base, &pVfsOps->Obj, hVfs, hLock,
    16501670                                   (char *)pThis + RT_ALIGN_Z(sizeof(*pThis), RTVFS_INST_ALIGNMENT));
    16511671    if (RT_FAILURE(rc))
     
    16601680    *phVfs       = pThis;
    16611681    *ppvInstance = pThis->Base.pvThis;
     1682
    16621683    return VINF_SUCCESS;
    16631684}
     
    18321853 *
    18331854 */
     1855
     1856
     1857RTDECL(int) RTVfsNewDir(PCRTVFSDIROPS pDirOps, size_t cbInstance, uint32_t fFlags, RTVFS hVfs, RTVFSLOCK hLock,
     1858                        PRTVFSDIR phVfsDir, void **ppvInstance)
     1859{
     1860    /*
     1861     * Validate the input, be extra strict in strict builds.
     1862     */
     1863    AssertPtr(pDirOps);
     1864    AssertReturn(pDirOps->uVersion   == RTVFSDIROPS_VERSION, VERR_VERSION_MISMATCH);
     1865    AssertReturn(pDirOps->uEndMarker == RTVFSDIROPS_VERSION, VERR_VERSION_MISMATCH);
     1866    Assert(!pDirOps->fReserved);
     1867    RTVFSDIR_ASSERT_OPS(pDirOps, RTVFSOBJTYPE_DIR);
     1868    Assert(cbInstance > 0);
     1869    AssertReturn(!fFlags, VERR_INVALID_FLAGS);
     1870    AssertPtr(ppvInstance);
     1871    AssertPtr(phVfsDir);
     1872    RTVFS_ASSERT_VALID_HANDLE_OR_NIL_RETURN(hVfs, VERR_INVALID_HANDLE);
     1873
     1874    /*
     1875     * Allocate the handle + instance data.
     1876     */
     1877    size_t const cbThis = RT_ALIGN_Z(sizeof(RTVFSDIRINTERNAL), RTVFS_INST_ALIGNMENT)
     1878                        + RT_ALIGN_Z(cbInstance, RTVFS_INST_ALIGNMENT);
     1879    RTVFSDIRINTERNAL *pThis = (RTVFSDIRINTERNAL *)RTMemAllocZ(cbThis);
     1880    if (!pThis)
     1881        return VERR_NO_MEMORY;
     1882
     1883    int rc = rtVfsObjInitNewObject(&pThis->Base, &pDirOps->Obj, hVfs, hLock,
     1884                                   (char *)pThis + RT_ALIGN_Z(sizeof(*pThis), RTVFS_INST_ALIGNMENT));
     1885    if (RT_FAILURE(rc))
     1886    {
     1887        RTMemFree(pThis);
     1888        return rc;
     1889    }
     1890
     1891    pThis->uMagic       = RTVFSDIR_MAGIC;
     1892    pThis->fReserved    = 0;
     1893    pThis->pOps         = pDirOps;
     1894
     1895    *phVfsDir    = pThis;
     1896    *ppvInstance = pThis->Base.pvThis;
     1897    return VINF_SUCCESS;
     1898}
     1899
    18341900
    18351901RTDECL(uint32_t) RTVfsDirRetain(RTVFSDIR hVfsDir)
     
    28012867
    28022868
     2869RTDECL(int) RTVfsFileSgRead(RTVFSFILE hVfsFile, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     2870{
     2871    AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER);
     2872    if (pcbRead)
     2873        *pcbRead = 0;
     2874    RTVFSFILEINTERNAL *pThis = hVfsFile;
     2875    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     2876    AssertReturn(pThis->uMagic == RTVFSFILE_MAGIC, VERR_INVALID_HANDLE);
     2877
     2878    return RTVfsIoStrmSgRead(&pThis->Stream, off, pSgBuf, fBlocking, pcbRead);
     2879}
     2880
     2881
     2882RTDECL(int) RTVfsFileSgWrite(RTVFSFILE hVfsFile, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     2883{
     2884    AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER);
     2885    if (pcbWritten)
     2886        *pcbWritten = 0;
     2887    RTVFSFILEINTERNAL *pThis = hVfsFile;
     2888    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     2889    AssertReturn(pThis->uMagic == RTVFSFILE_MAGIC, VERR_INVALID_HANDLE);
     2890
     2891    return RTVfsIoStrmSgWrite(&pThis->Stream, off, pSgBuf, fBlocking, pcbWritten);
     2892}
     2893
     2894
    28032895RTDECL(int) RTVfsFileFlush(RTVFSFILE hVfsFile)
    28042896{
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