VirtualBox

Changeset 33948 in vbox


Ignore:
Timestamp:
Nov 10, 2010 7:36:49 PM (14 years ago)
Author:
vboxsync
Message:

vfs: more filesystem streaming code.

Location:
trunk
Files:
3 edited

Legend:

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

    r33945 r33948  
    105105/** A NIL VFS symbolic link handle. */
    106106#define NIL_RTVFSSYMLINK                ((RTVFSSYMLINK)~(uintptr_t)0)
     107
     108/**
     109 * The object type.
     110 */
     111typedef enum RTVFSOBJTYPE
     112{
     113    /** Invalid type. */
     114    RTVFSOBJTYPE_INVALID = 0,
     115    /** Pure base object.
     116     * This is returned by the filesystem stream to represent directories,
     117     * devices, fifos and similar that needs to be created. */
     118    RTVFSOBJTYPE_BASE,
     119    /** Virtual filesystem. */
     120    RTVFSOBJTYPE_VFS,
     121    /** Filesystem stream. */
     122    RTVFSOBJTYPE_FS_STREAM,
     123    /** Pure I/O stream. */
     124    RTVFSOBJTYPE_IO_STREAM,
     125    /** Directory. */
     126    RTVFSOBJTYPE_DIR,
     127    /** File. */
     128    RTVFSOBJTYPE_FILE,
     129    /** Symbolic link. */
     130    RTVFSOBJTYPE_SYMLINK,
     131    /** End of valid object types. */
     132    RTVFSOBJTYPE_END,
     133    /** Pure I/O stream. */
     134    RTVFSOBJTYPE_32BIT_HACK = 0x7fffffff
     135} RTVFSOBJTYPE;
     136/** Pointer to a VFS object type. */
     137typedef RTVFSOBJTYPE *PRTVFSOBJTYPE;
     138
     139
    107140
    108141
     
    153186RTDECL(RTVFSOBJ)        RTVfsObjFromSymlink(RTVFSSYMLINK hVfsSym);
    154187
     188/**
     189 * Query information about the object.
     190 *
     191 * @returns IPRT status code.
     192 * @param   hVfsObj         The VFS object handle.
     193 * @param   pObjInfo        Where to return the info.
     194 * @param   enmAddAttr      Which additional attributes should be retrieved.
     195 * @sa      RTFileQueryInfo, RTPathQueryInfo
     196 */
     197RTDECL(int)         RTVfsObjQueryInfo(RTVFSOBJ hVfsObj, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
     198
    155199/** @} */
     200
     201
     202/** @defgroup grp_vfs_fsstream      VFS Filesystem Stream API
     203 *
     204 * Filesystem streams are for tar, cpio and similar.  Any virtual filesystem can
     205 * be turned into a filesystem stream using RTVfsFsStrmFromVfs.
     206 *
     207 * @{
     208 */
     209
     210RTDECL(uint32_t)    RTVfsFsStrmRetain(RTVFSFSSTREAM hVfsFss);
     211RTDECL(uint32_t)    RTVfsFsStrmRelease(RTVFSFSSTREAM hVfsFss);
     212RTDECL(int)         RTVfsFsStrmQueryInfo(RTVFSFSSTREAM hVfsFss, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
     213
     214/**
     215 * Gets the next object in the stream.
     216 *
     217 * This call may affect the stream posision of a previously returned object.
     218 *
     219 * The type of object returned here typically boils down to three types:
     220 *      - I/O streams (representing files),
     221 *      - symbolic links
     222 *      - base object
     223 * The base objects represent anything not convered by the two other, i.e.
     224 * directories, device nodes, fifos, sockets and whatnot.  The details can be
     225 * queried using RTVfsObjQueryInfo.
     226 *
     227 * That said, absolutely any object except for filesystem stream objects can be
     228 * returned by this call.  Any generic code is adviced to just deal with it all.
     229 *
     230 * @returns IPRT status code.
     231 * @retval  VINF_SUCCESS if a new object was retrieved.
     232 * @retval  VERR_EOF when there are no more objects.
     233 * @param   pvThis      The implementation specific directory data.
     234 * @param   ppszName    Where to return the object name.  Must be freed by
     235 *                      calling RTStrFree.
     236 * @param   penmType    Where to return the object type.
     237 * @param   hVfsObj     Where to return the object handle (referenced).
     238 *                      This must be cast to the desired type before use.
     239 */
     240RTDECL(int)         RTVfsFsStrmNext(RTVFSFSSTREAM hVfsFss, char **ppszName, RTVFSOBJTYPE *penmType, PRTVFSOBJ phVfsObj);
     241
     242/** @}  */
    156243
    157244
     
    182269 * @{
    183270 */
     271
     272RTDECL(uint32_t)    RTVfsSymlinkRetain(RTVFSSYMLINK hVfsSym);
     273RTDECL(uint32_t)    RTVfsSymlinkRelease(RTVFSSYMLINK hVfsSym);
    184274
    185275/**
  • trunk/include/iprt/vfslowlevel.h

    r33945 r33948  
    100100#define RTVFSOPS_FEAT_ATTACH        RT_BIT_32(0)
    101101/** @}  */
    102 
    103 
    104 /**
    105  * The object type.
    106  */
    107 typedef enum RTVFSOBJTYPE
    108 {
    109     /** Invalid type. */
    110     RTVFSOBJTYPE_INVALID = 0,
    111     /** Pure base object.
    112      * This is returned by the filesystem stream to represent directories,
    113      * devices, fifos and similar that needs to be created. */
    114     RTVFSOBJTYPE_BASE,
    115     /** Virtual filesystem. */
    116     RTVFSOBJTYPE_VFS,
    117     /** Filesystem stream. */
    118     RTVFSOBJTYPE_FS_STREAM,
    119     /** Pure I/O stream. */
    120     RTVFSOBJTYPE_IO_STREAM,
    121     /** Directory. */
    122     RTVFSOBJTYPE_DIR,
    123     /** File. */
    124     RTVFSOBJTYPE_FILE,
    125     /** Symbolic link. */
    126     RTVFSOBJTYPE_SYMLINK,
    127     /** End of valid object types. */
    128     RTVFSOBJTYPE_END,
    129     /** Pure I/O stream. */
    130     RTVFSOBJTYPE_32BIT_HACK = 0x7fffffff
    131 } RTVFSOBJTYPE;
    132 /** Pointer to a VFS object type. */
    133 typedef RTVFSOBJTYPE *PRTVFSOBJTYPE;
    134102
    135103
  • trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp

    r33945 r33948  
    440440    AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, UINT32_MAX);
    441441    return rtVfsObjRelease(pThis);
     442}
     443
     444
     445RTDECL(RTVFS)           RTVfsObjToVfs(RTVFSOBJ hVfsObj)
     446{
     447    RTVFSOBJINTERNAL *pThis = hVfsObj;
     448    if (pThis != NIL_RTVFSOBJ)
     449    {
     450        AssertPtrReturn(pThis, NIL_RTVFS);
     451        AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, NIL_RTVFS);
     452
     453        if (pThis->pOps->enmType == RTVFSOBJTYPE_VFS)
     454        {
     455            rtVfsObjRetainVoid(pThis);
     456            return RT_FROM_MEMBER(pThis, RTVFSINTERNAL, Base);
     457        }
     458    }
     459    return NIL_RTVFS;
     460}
     461
     462
     463RTDECL(RTVFSFSSTREAM)   RTVfsObjToFsStream(RTVFSOBJ hVfsObj)
     464{
     465    RTVFSOBJINTERNAL *pThis = hVfsObj;
     466    if (pThis != NIL_RTVFSOBJ)
     467    {
     468        AssertPtrReturn(pThis, NIL_RTVFSFSSTREAM);
     469        AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, NIL_RTVFSFSSTREAM);
     470
     471        if (pThis->pOps->enmType == RTVFSOBJTYPE_FS_STREAM)
     472        {
     473            rtVfsObjRetainVoid(pThis);
     474            return RT_FROM_MEMBER(pThis, RTVFSFSSTREAMINTERNAL, Base);
     475        }
     476    }
     477    return NIL_RTVFSFSSTREAM;
     478}
     479
     480
     481RTDECL(RTVFSDIR)        RTVfsObjToDir(RTVFSOBJ hVfsObj)
     482{
     483    RTVFSOBJINTERNAL *pThis = hVfsObj;
     484    if (pThis != NIL_RTVFSOBJ)
     485    {
     486        AssertPtrReturn(pThis, NIL_RTVFSDIR);
     487        AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, NIL_RTVFSDIR);
     488
     489        if (pThis->pOps->enmType == RTVFSOBJTYPE_VFS)
     490        {
     491            rtVfsObjRetainVoid(pThis);
     492            return RT_FROM_MEMBER(pThis, RTVFSDIRINTERNAL, Base);
     493        }
     494    }
     495    return NIL_RTVFSDIR;
     496}
     497
     498
     499RTDECL(RTVFSIOSTREAM)   RTVfsObjToIoStream(RTVFSOBJ hVfsObj)
     500{
     501    RTVFSOBJINTERNAL *pThis = hVfsObj;
     502    if (pThis != NIL_RTVFSOBJ)
     503    {
     504        AssertPtrReturn(pThis, NIL_RTVFSIOSTREAM);
     505        AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, NIL_RTVFSIOSTREAM);
     506
     507        if (pThis->pOps->enmType == RTVFSOBJTYPE_VFS)
     508        {
     509            rtVfsObjRetainVoid(pThis);
     510            return RT_FROM_MEMBER(pThis, RTVFSIOSTREAMINTERNAL, Base);
     511        }
     512    }
     513    return NIL_RTVFSIOSTREAM;
     514}
     515
     516
     517RTDECL(RTVFSFILE)       RTVfsObjToFile(RTVFSOBJ hVfsObj)
     518{
     519    RTVFSOBJINTERNAL *pThis = hVfsObj;
     520    if (pThis != NIL_RTVFSOBJ)
     521    {
     522        AssertPtrReturn(pThis, NIL_RTVFSFILE);
     523        AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, NIL_RTVFSFILE);
     524
     525        if (pThis->pOps->enmType == RTVFSOBJTYPE_VFS)
     526        {
     527            rtVfsObjRetainVoid(pThis);
     528            return RT_FROM_MEMBER(pThis, RTVFSFILEINTERNAL, Stream.Base);
     529        }
     530    }
     531    return NIL_RTVFSFILE;
     532}
     533
     534
     535RTDECL(RTVFSSYMLINK)    RTVfsObjToSymlink(RTVFSOBJ hVfsObj)
     536{
     537    RTVFSOBJINTERNAL *pThis = hVfsObj;
     538    if (pThis != NIL_RTVFSOBJ)
     539    {
     540        AssertPtrReturn(pThis, NIL_RTVFSSYMLINK);
     541        AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, NIL_RTVFSSYMLINK);
     542
     543        if (pThis->pOps->enmType == RTVFSOBJTYPE_VFS)
     544        {
     545            rtVfsObjRetainVoid(pThis);
     546            return RT_FROM_MEMBER(pThis, RTVFSSYMLINKINTERNAL, Base);
     547        }
     548    }
     549    return NIL_RTVFSSYMLINK;
     550}
     551
     552
     553RTDECL(RTVFSOBJ)        RTVfsObjFromVfs(RTVFS hVfs)
     554{
     555    if (hVfs != NIL_RTVFS)
     556    {
     557        RTVFSOBJINTERNAL *pThis = &hVfs->Base;
     558        AssertPtrReturn(pThis, NIL_RTVFSOBJ);
     559        AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, NIL_RTVFSOBJ);
     560
     561        rtVfsObjRetainVoid(pThis);
     562        return pThis;
     563    }
     564    return NIL_RTVFSOBJ;
     565}
     566
     567
     568RTDECL(RTVFSOBJ)        RTVfsObjFromFsStream(RTVFSFSSTREAM hVfsFss)
     569{
     570    if (hVfsFss != NIL_RTVFSFSSTREAM)
     571    {
     572        RTVFSOBJINTERNAL *pThis = &hVfsFss->Base;
     573        AssertPtrReturn(pThis, NIL_RTVFSOBJ);
     574        AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, NIL_RTVFSOBJ);
     575
     576        rtVfsObjRetainVoid(pThis);
     577        return pThis;
     578    }
     579    return NIL_RTVFSOBJ;
     580}
     581
     582
     583RTDECL(RTVFSOBJ)        RTVfsObjFromDir(RTVFSDIR hVfsDir)
     584{
     585    if (hVfsDir != NIL_RTVFSDIR)
     586    {
     587        RTVFSOBJINTERNAL *pThis = &hVfsDir->Base;
     588        AssertPtrReturn(pThis, NIL_RTVFSOBJ);
     589        AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, NIL_RTVFSOBJ);
     590
     591        rtVfsObjRetainVoid(pThis);
     592        return pThis;
     593    }
     594    return NIL_RTVFSOBJ;
     595}
     596
     597
     598RTDECL(RTVFSOBJ)        RTVfsObjFromIoStream(RTVFSIOSTREAM hVfsIos)
     599{
     600    if (hVfsIos != NIL_RTVFSIOSTREAM)
     601    {
     602        RTVFSOBJINTERNAL *pThis = &hVfsIos->Base;
     603        AssertPtrReturn(pThis, NIL_RTVFSOBJ);
     604        AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, NIL_RTVFSOBJ);
     605
     606        rtVfsObjRetainVoid(pThis);
     607        return pThis;
     608    }
     609    return NIL_RTVFSOBJ;
     610}
     611
     612
     613RTDECL(RTVFSOBJ)        RTVfsObjFromFile(RTVFSFILE hVfsFile)
     614{
     615    if (hVfsFile != NIL_RTVFSFILE)
     616    {
     617        RTVFSOBJINTERNAL *pThis = &hVfsFile->Stream.Base;
     618        AssertPtrReturn(pThis, NIL_RTVFSOBJ);
     619        AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, NIL_RTVFSOBJ);
     620
     621        rtVfsObjRetainVoid(pThis);
     622        return pThis;
     623    }
     624    return NIL_RTVFSOBJ;
     625}
     626
     627
     628RTDECL(RTVFSOBJ)        RTVfsObjFromSymlink(RTVFSSYMLINK hVfsSym)
     629{
     630    if (hVfsSym != NIL_RTVFSSYMLINK)
     631    {
     632        RTVFSOBJINTERNAL *pThis = &hVfsSym->Base;
     633        AssertPtrReturn(pThis, NIL_RTVFSOBJ);
     634        AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, NIL_RTVFSOBJ);
     635
     636        rtVfsObjRetainVoid(pThis);
     637        return pThis;
     638    }
     639    return NIL_RTVFSOBJ;
     640}
     641
     642
     643
     644RTDECL(int)         RTVfsObjQueryInfo(RTVFSOBJ hVfsObj, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
     645{
     646    RTVFSOBJINTERNAL *pThis = hVfsObj;
     647    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     648    AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, VERR_INVALID_HANDLE);
     649
     650    rtVfsObjReadLock(pThis);
     651    int rc = pThis->pOps->pfnQueryInfo(pThis->pvThis, pObjInfo, enmAddAttr);
     652    rtVfsObjReadUnlock(pThis);
     653    return rc;
    442654}
    443655
     
    8611073
    8621074
     1075
     1076
     1077/*
     1078 *
     1079 *  F I L E S Y S T E M   S T R E A M
     1080 *  F I L E S Y S T E M   S T R E A M
     1081 *  F I L E S Y S T E M   S T R E A M
     1082 *
     1083 */
     1084
     1085
     1086RTDECL(int) RTVfsNewIoStream(PCRTVFSFSSTREAMOPS pFsStreamOps, size_t cbInstance, RTVFS hVfs, RTSEMRW hSemRW,
     1087                             PRTVFSFSSTREAM phVfsFss, void **ppvInstance)
     1088{
     1089    return VERR_NOT_IMPLEMENTED;
     1090}
     1091
     1092
     1093RTDECL(uint32_t)    RTVfsFsStrmRetain(RTVFSFSSTREAM hVfsFss)
     1094{
     1095    RTVFSFSSTREAMINTERNAL *pThis = hVfsFss;
     1096    AssertPtrReturn(pThis, UINT32_MAX);
     1097    AssertReturn(pThis->uMagic == RTVFSFSSTREAM_MAGIC, UINT32_MAX);
     1098    return rtVfsObjRetain(&pThis->Base);
     1099}
     1100
     1101
     1102RTDECL(uint32_t)    RTVfsFsStrmRelease(RTVFSFSSTREAM hVfsFss)
     1103{
     1104    RTVFSFSSTREAMINTERNAL *pThis = hVfsFss;
     1105    AssertPtrReturn(pThis, UINT32_MAX);
     1106    AssertReturn(pThis->uMagic == RTVFSFSSTREAM_MAGIC, UINT32_MAX);
     1107    return rtVfsObjRelease(&pThis->Base);
     1108}
     1109
     1110
     1111RTDECL(int)         RTVfsFsStrmQueryInfo(RTVFSFSSTREAM hVfsFss, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
     1112{
     1113    RTVFSFSSTREAMINTERNAL *pThis = hVfsFss;
     1114    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     1115    AssertReturn(pThis->uMagic == RTVFSFSSTREAM_MAGIC, VERR_INVALID_HANDLE);
     1116    return RTVfsObjQueryInfo(&pThis->Base, pObjInfo, enmAddAttr);
     1117}
     1118
     1119
     1120RTDECL(int)         RTVfsFsStrmNext(RTVFSFSSTREAM hVfsFss, char **ppszName, RTVFSOBJTYPE *penmType, PRTVFSOBJ phVfsObj)
     1121{
     1122    RTVFSFSSTREAMINTERNAL *pThis = hVfsFss;
     1123    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     1124    AssertReturn(pThis->uMagic == RTVFSDIR_MAGIC, VERR_INVALID_HANDLE);
     1125    AssertPtrNullReturn(ppszName, VERR_INVALID_POINTER);
     1126    if (ppszName)
     1127        *ppszName = NULL;
     1128    AssertPtrNullReturn(penmType, VERR_INVALID_POINTER);
     1129    if (penmType)
     1130        *penmType = RTVFSOBJTYPE_INVALID;
     1131    AssertPtrNullReturn(penmType, VERR_INVALID_POINTER);
     1132    if (phVfsObj)
     1133        *phVfsObj = NIL_RTVFSOBJ;
     1134
     1135    return pThis->pOps->pfnNext(pThis->Base.pvThis, ppszName, penmType, phVfsObj);
     1136}
     1137
     1138
     1139
     1140
    8631141/*
    8641142 *
     
    10261304    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    10271305    AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE);
    1028 
    1029     rtVfsObjReadLock(&pThis->Base);
    1030     int rc = pThis->pOps->Obj.pfnQueryInfo(pThis->Base.pvThis, pObjInfo, enmAddAttr);
    1031     rtVfsObjReadUnlock(&pThis->Base);
    1032     return rc;
     1306    return RTVfsObjQueryInfo(&pThis->Base, pObjInfo, enmAddAttr);
    10331307}
    10341308
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