VirtualBox

Changeset 69818 in vbox


Ignore:
Timestamp:
Nov 23, 2017 7:44:07 PM (7 years ago)
Author:
vboxsync
Message:

IPRT/VFS: Got rid of the pfnTraversalOpen method.

Location:
trunk
Files:
8 edited

Legend:

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

    r69105 r69818  
    6565 * @{ */
    6666/** Last component: Work on the link. */
    67 #define RTPATH_F_ON_LINK          RT_BIT_32(0)
     67#define RTPATH_F_ON_LINK            RT_BIT_32(0)
    6868/** Last component: Follow if link. */
    69 #define RTPATH_F_FOLLOW_LINK      RT_BIT_32(1)
     69#define RTPATH_F_FOLLOW_LINK        RT_BIT_32(1)
    7070/** Don't allow symbolic links as part of the path.
    7171 * @remarks this flag is currently not implemented and will be ignored. */
    72 #define RTPATH_F_NO_SYMLINKS      RT_BIT_32(2)
     72#define RTPATH_F_NO_SYMLINKS        RT_BIT_32(2)
     73/** Current RTPATH_F_XXX flag mask. */
     74#define RTPATH_F_MASK               UINT32_C(0x00000007)
    7375/** @} */
    7476
  • trunk/include/iprt/vfs.h

    r69817 r69818  
    183183/** Socket (RTFS_TYPE_SOCKET). */
    184184#define RTVFSOBJ_F_OPEN_SOCKET              RT_BIT_32(14)
     185/** Mounted VFS. */
     186#define RTVFSOBJ_F_OPEN_MOUNT               RT_BIT_32(15)
    185187/** Mask object types we wish to open. */
    186 #define RTVFSOBJ_F_OPEN_MASK                UINT32_C(0x00003f00)
     188#define RTVFSOBJ_F_OPEN_MASK                UINT32_C(0x0000ff00)
    187189/** Any kind of object that translates to RTVFSOBJTYPE_FILE. */
    188 #define RTVFSOBJ_F_OPEN_ANY_FILE            (RTVFSOBJ_F_FILE | RTVFSOBJ_F_DEV_BLOCK)
     190#define RTVFSOBJ_F_OPEN_ANY_FILE            (RTVFSOBJ_F_OPEN_FILE | RTVFSOBJ_F_OPEN_DEV_BLOCK)
    189191/** Any kind of object that translates to RTVFSOBJTYPE_IOS or
    190192 *  RTVFSOBJTYPE_FILE. */
    191 #define RTVFSOBJ_F_OPEN_ANY_IO_STREAM       (RTVFSOBJ_F_ANY_FILE | RTVFSOBJ_F_DEV_BLOCK | RTVFSOBJ_F_FIFO | RTVFSOBJ_F_SOCKET)
     193#define RTVFSOBJ_F_OPEN_ANY_IO_STREAM       (  RTVFSOBJ_F_ANY_OPEN_FILE | RTVFSOBJ_F_DEV_OPEN_BLOCK \
     194                                             | RTVFSOBJ_F_OPEN_FIFO     | RTVFSOBJ_F_OPEN_SOCKET)
    192195/** Any kind of object. */
    193196#define RTVFSOBJ_F_OPEN_ANY                 RTVFSOBJ_F_OPEN_MASK
     
    208211#define RTVFSOBJ_F_TRAVERSAL                RT_BIT_32(31)
    209212/** Valid mask for external callers. */
    210 #define RTVFSOBJ_F_VALID_MASK               UINT32_C(0x00003f00)
     213#define RTVFSOBJ_F_VALID_MASK               UINT32_C(0x0007ff00)
    211214/** @} */
    212215
  • trunk/include/iprt/vfslowlevel.h

    r69813 r69818  
    562562    DECLCALLBACKMEMBER(int, pfnOpen)(void *pvThis, const char *pszEntry, uint64_t fOpenFile,
    563563                                     uint32_t fObjFlags, PRTVFSOBJ phVfsObj);
    564 
    565     /**
    566      * Opens a directory entry for traversal purposes.
    567      *
    568      * Method which sole purpose is helping the path traversal.  Only one of
    569      * the three output variables will be set, the others will left untouched
    570      * (caller sets them to NIL).
    571      *
    572      * @returns IPRT status code.
    573      * @retval  VERR_PATH_NOT_FOUND if @a pszEntry was not found.
    574      * @retval  VERR_NOT_A_DIRECTORY if @a pszEntry isn't a directory or symlink.
    575      * @param   pvThis          The implementation specific directory data.
    576      * @param   pszEntry        The name of the directory entry to remove.
    577      * @param   phVfsDir        If not NULL and it is a directory, open it and
    578      *                          return the handle here.
    579      * @param   phVfsSymlink    If not NULL and it is a symbolic link, open it
    580      *                          and return the handle here.
    581      * @param   phVfsMounted    If not NULL and it is a mounted VFS directory,
    582      *                          reference it and return the handle here.
    583      * @todo    Should com dir, symlinks and mount points using some common
    584      *          ancestor "class".
    585      * @note    Will be replaced by pfnOpenObj.
    586      */
    587     DECLCALLBACKMEMBER(int, pfnTraversalOpen)(void *pvThis, const char *pszEntry, PRTVFSDIR phVfsDir,
    588                                               PRTVFSSYMLINK phVfsSymlink, PRTVFS phVfsMounted);
    589564
    590565    /**
  • trunk/src/VBox/Runtime/common/dvm/dvmvfs.cpp

    r69813 r69818  
    648648
    649649
    650 /**
    651  * @interface_method_impl{RTVFSOBJOPS,pfnTraversalOpen}
    652  */
    653 static DECLCALLBACK(int) rtDvmVfsDir_TraversalOpen(void *pvThis, const char *pszEntry, PRTVFSDIR phVfsDir,
    654                                                   PRTVFSSYMLINK phVfsSymlink, PRTVFS phVfsMounted)
    655 {
    656     RT_NOREF(pvThis, pszEntry);
    657 
    658     /* We don't do any subdirs. */
    659     if (phVfsSymlink)
    660         *phVfsSymlink = NIL_RTVFSSYMLINK;
    661     if (phVfsMounted)
    662         *phVfsMounted = NIL_RTVFS;
    663     if (phVfsDir)
    664         *phVfsDir = NIL_RTVFSDIR;
    665     return VERR_PATH_NOT_FOUND;
    666 }
    667 
    668 
    669650static int rtDvmVfsDir_FindEntry(PRTDVMVFSDIR pThis, const char *pszEntry, PRTDVMVOLUME phVolume)
    670651{
     
    1014995    },
    1015996    rtDvmVfsDir_Open,
    1016     rtDvmVfsDir_TraversalOpen,
    1017997    rtDvmVfsDir_OpenFile,
    1018998    rtDvmVfsDir_OpenDir,
  • trunk/src/VBox/Runtime/common/fs/fatvfs.cpp

    r69814 r69818  
    39993999
    40004000/**
    4001  * @interface_method_impl{RTVFSOBJOPS,pfnTraversalOpen}
    4002  */
    4003 static DECLCALLBACK(int) rtFsFatDir_TraversalOpen(void *pvThis, const char *pszEntry, PRTVFSDIR phVfsDir,
    4004                                                   PRTVFSSYMLINK phVfsSymlink, PRTVFS phVfsMounted)
    4005 {
    4006     /*
    4007      * FAT doesn't do symbolic links and mounting file systems within others
    4008      * haven't been implemented yet, I think, so only care if a directory is
    4009      * asked for.
    4010      */
    4011     int rc;
    4012     if (phVfsSymlink)
    4013         *phVfsSymlink = NIL_RTVFSSYMLINK;
    4014     if (phVfsMounted)
    4015         *phVfsMounted = NIL_RTVFS;
    4016     if (phVfsDir)
    4017     {
    4018         *phVfsDir = NIL_RTVFSDIR;
    4019 
    4020         PRTFSFATDIR     pThis   = (PRTFSFATDIR)pvThis;
    4021         PRTFSFATDIRSHRD pShared = pThis->pShared;
    4022         uint32_t        offEntryInDir;
    4023         bool            fLong;
    4024         FATDIRENTRY     DirEntry;
    4025         rc = rtFsFatDirShrd_FindEntry(pShared, pszEntry, &offEntryInDir, &fLong, &DirEntry);
    4026         if (RT_SUCCESS(rc))
    4027         {
    4028             switch (DirEntry.fAttrib & (FAT_ATTR_DIRECTORY | FAT_ATTR_VOLUME))
    4029             {
    4030                 case FAT_ATTR_DIRECTORY:
    4031                 {
    4032                     rc = rtFsFatDir_New(pShared->Core.pVol, pShared, &DirEntry, offEntryInDir,
    4033                                         RTFSFAT_GET_CLUSTER(&DirEntry, pShared->Core.pVol), UINT64_MAX /*offDisk*/,
    4034                                         DirEntry.cbFile, phVfsDir);
    4035                     break;
    4036                 }
    4037                 case 0:
    4038                     rc = VERR_NOT_A_DIRECTORY;
    4039                     break;
    4040                 default:
    4041                     rc = VERR_PATH_NOT_FOUND;
    4042                     break;
    4043             }
    4044         }
    4045         else if (rc == VERR_FILE_NOT_FOUND)
    4046             rc = VERR_PATH_NOT_FOUND;
    4047     }
    4048     else
    4049         rc = VERR_PATH_NOT_FOUND;
    4050     LogFlow(("rtFsFatDir_TraversalOpen: %s -> %Rrc\n", pszEntry, rc));
    4051     return rc;
    4052 }
    4053 
    4054 
    4055 /**
    40564001 * @interface_method_impl{RTVFSDIROPS,pfnOpen}
    40574002 */
     
    47784723    },
    47794724    rtFsFatDir_Open,
    4780     rtFsFatDir_TraversalOpen,
    47814725    rtFsFatDir_OpenFile,
    47824726    rtFsFatDir_OpenDir,
  • trunk/src/VBox/Runtime/common/fs/isovfs.cpp

    r69813 r69818  
    28902890
    28912891/**
    2892  * @interface_method_impl{RTVFSOBJOPS,pfnTraversalOpen}
    2893  */
    2894 static DECLCALLBACK(int) rtFsIsoDir_TraversalOpen(void *pvThis, const char *pszEntry, PRTVFSDIR phVfsDir,
    2895                                                   PRTVFSSYMLINK phVfsSymlink, PRTVFS phVfsMounted)
    2896 {
    2897     /*
    2898      * We may have symbolic links if rock ridge is being used, though currently
    2899      * we won't have nested mounts.
    2900      */
    2901     int rc;
    2902     if (phVfsMounted)
    2903         *phVfsMounted = NIL_RTVFS;
    2904     if (phVfsDir || phVfsSymlink)
    2905     {
    2906         if (phVfsSymlink)
    2907             *phVfsSymlink = NIL_RTVFSSYMLINK;
    2908         if (phVfsDir)
    2909             *phVfsDir = NIL_RTVFSDIR;
    2910 
    2911         PRTFSISODIROBJ      pThis = (PRTFSISODIROBJ)pvThis;
    2912         PRTFSISODIRSHRD     pShared = pThis->pShared;
    2913         if (pShared->Core.pVol->enmType != RTFSISOVOLTYPE_UDF)
    2914         {
    2915             /*
    2916              * ISO 9660
    2917              */
    2918             PCISO9660DIRREC     pDirRec;
    2919             uint64_t            offDirRec;
    2920             uint32_t            cDirRecs;
    2921             RTFMODE             fMode;
    2922             uint32_t            uVersion;
    2923             rc = rtFsIsoDir_FindEntry9660(pShared, pszEntry, &offDirRec, &pDirRec, &cDirRecs, &fMode, &uVersion);
    2924             Log2(("rtFsIsoDir_TraversalOpen: FindEntry9660(,%s,) -> %Rrc\n", pszEntry, rc));
    2925             if (RT_SUCCESS(rc))
    2926             {
    2927                 switch (fMode & RTFS_TYPE_MASK)
    2928                 {
    2929                     case RTFS_TYPE_DIRECTORY:
    2930                         if (phVfsDir)
    2931                             rc = rtFsIsoDir_New9660(pShared->Core.pVol, pShared, pDirRec, cDirRecs, offDirRec, phVfsDir);
    2932                         else
    2933                             rc = VERR_NOT_SYMLINK;
    2934                         break;
    2935 
    2936                     case RTFS_TYPE_SYMLINK:
    2937                         rc = VERR_NOT_IMPLEMENTED;
    2938                         break;
    2939                     case RTFS_TYPE_FILE:
    2940                     case RTFS_TYPE_DEV_BLOCK:
    2941                     case RTFS_TYPE_DEV_CHAR:
    2942                     case RTFS_TYPE_FIFO:
    2943                     case RTFS_TYPE_SOCKET:
    2944                         rc = VERR_NOT_A_DIRECTORY;
    2945                         break;
    2946                     default:
    2947                     case RTFS_TYPE_WHITEOUT:
    2948                         rc = VERR_PATH_NOT_FOUND;
    2949                         break;
    2950                 }
    2951             }
    2952             else if (rc == VERR_FILE_NOT_FOUND)
    2953                 rc = VERR_PATH_NOT_FOUND;
    2954         }
    2955         else
    2956         {
    2957             /*
    2958              * UDF
    2959              */
    2960             PCUDFFILEIDDESC pFid;
    2961             rc = rtFsIsoDir_FindEntryUdf(pShared, pszEntry, &pFid);
    2962             Log2(("rtFsIsoDir_TraversalOpen: FindEntryUdf(,%s,) -> %Rrc\n", pszEntry, rc));
    2963             if (RT_SUCCESS(rc))
    2964             {
    2965                 if (!(pFid->fFlags & UDF_FILE_FLAGS_DELETED))
    2966                 {
    2967                     if (pFid->fFlags & UDF_FILE_FLAGS_DIRECTORY)
    2968                     {
    2969                         if (phVfsDir)
    2970                             rc = rtFsIsoDir_NewUdf(pShared->Core.pVol, pShared, pFid, phVfsDir);
    2971                         else
    2972                             rc = VERR_NOT_SYMLINK;
    2973                     }
    2974                     else if (phVfsSymlink)
    2975                     {
    2976                         /** @todo symlink support */
    2977                         rc = VERR_NOT_A_DIRECTORY;
    2978                     }
    2979                     else
    2980                         rc = VERR_NOT_A_DIRECTORY;
    2981                 }
    2982                 /* We treat UDF_FILE_FLAGS_DELETED like RTFS_TYPE_WHITEOUT for now. */
    2983                 else
    2984                     rc = VERR_PATH_NOT_FOUND;
    2985             }
    2986         }
    2987     }
    2988     else
    2989         rc = VERR_PATH_NOT_FOUND;
    2990     return rc;
    2991 }
    2992 
    2993 
    2994 /**
    29952892 * @interface_method_impl{RTVFSDIROPS,pfnOpen}
    29962893 */
     
    37943691    },
    37953692    rtFsIsoDir_Open,
    3796     rtFsIsoDir_TraversalOpen,
    37973693    rtFsIsoDir_OpenFile,
    37983694    rtFsIsoDir_OpenDir,
  • trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp

    r69816 r69818  
    9292        Assert((pDirOps)->uVersion == RTVFSDIROPS_VERSION); \
    9393        Assert(!(pDirOps)->fReserved); \
    94         AssertPtr((pDirOps)->pfnTraversalOpen); \
    95         AssertPtr((pDirOps)->pfnOpenFile); \
    96         AssertPtr((pDirOps)->pfnOpenDir); \
    97         AssertPtr((pDirOps)->pfnCreateDir); \
    98         AssertPtr((pDirOps)->pfnOpenSymlink); \
     94        AssertPtr((pDirOps)->pfnOpen); \
     95        AssertPtrNull((pDirOps)->pfnOpenFile); \
     96        AssertPtrNull((pDirOps)->pfnOpenDir); \
     97        AssertPtrNull((pDirOps)->pfnCreateDir); \
     98        AssertPtrNull((pDirOps)->pfnOpenSymlink); \
    9999        AssertPtr((pDirOps)->pfnCreateSymlink); \
    100100        AssertPtr((pDirOps)->pfnUnlinkEntry); \
     
    16971697        RTVFSSYMLINK    hSymlink = NIL_RTVFSSYMLINK;
    16981698        RTVFS           hVfsMnt  = NIL_RTVFS;
     1699        RTVFSOBJ        hVfsObj  = NIL_RTVFSOBJ;
    16991700        if (fFinal)
    17001701        {
    17011702            RTVfsLockAcquireRead(pCurDir->Base.hLock);
    1702             rc = pCurDir->pOps->pfnTraversalOpen(pCurDir->Base.pvThis, pszEntry, NULL, &hSymlink, NULL);
     1703            rc = pCurDir->pOps->pfnOpen(pCurDir->Base.pvThis, pszEntry,
     1704                                        RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE,
     1705                                        RTVFSOBJ_F_OPEN_SYMLINK | RTVFSOBJ_F_CREATE_NOTHING
     1706                                        | RTVFSOBJ_F_TRAVERSAL | RTPATH_F_ON_LINK,
     1707                                        &hVfsObj);
    17031708            RTVfsLockReleaseRead(pCurDir->Base.hLock);
    17041709            *pszEntryEnd = '\0';
    1705             if (   rc == VERR_PATH_NOT_FOUND
    1706                 || rc == VERR_FILE_NOT_FOUND
    1707                 || rc == VERR_NOT_A_DIRECTORY
    1708                 || rc == VERR_NOT_SYMLINK)
    1709                 rc = VINF_SUCCESS;
    17101710            if (RT_FAILURE(rc))
     1711            {
     1712                if (   rc == VERR_PATH_NOT_FOUND
     1713                    || rc == VERR_FILE_NOT_FOUND
     1714                    || rc == VERR_IS_A_DIRECTORY
     1715                    || rc == VERR_IS_A_FILE
     1716                    || rc == VERR_IS_A_FIFO
     1717                    || rc == VERR_IS_A_SOCKET
     1718                    || rc == VERR_IS_A_CHAR_DEVICE
     1719                    || rc == VERR_IS_A_BLOCK_DEVICE
     1720                    || rc == VERR_NOT_SYMLINK)
     1721                {
     1722                    *ppVfsParentDir = pCurDir;
     1723                    return VINF_SUCCESS;
     1724                }
    17111725                break;
    1712 
    1713             if (hSymlink == NIL_RTVFSSYMLINK)
    1714             {
    1715                 *ppVfsParentDir = pCurDir;
    1716                 return VINF_SUCCESS;
    17171726            }
     1727            hSymlink = RTVfsObjToSymlink(hVfsObj);
     1728            Assert(hSymlink != NIL_RTVFSSYMLINK);
    17181729        }
    17191730        else
    17201731        {
    17211732            RTVfsLockAcquireRead(pCurDir->Base.hLock);
    1722             rc = pCurDir->pOps->pfnTraversalOpen(pCurDir->Base.pvThis, pszEntry, &hDir, &hSymlink, &hVfsMnt);
     1733            rc = pCurDir->pOps->pfnOpen(pCurDir->Base.pvThis, pszEntry,
     1734                                        RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE,
     1735                                        RTVFSOBJ_F_OPEN_DIRECTORY   | RTVFSOBJ_F_OPEN_SYMLINK | RTVFSOBJ_F_OPEN_MOUNT
     1736                                        | RTVFSOBJ_F_CREATE_NOTHING | RTVFSOBJ_F_TRAVERSAL    | RTPATH_F_ON_LINK,
     1737                                        &hVfsObj);
    17231738            RTVfsLockReleaseRead(pCurDir->Base.hLock);
    17241739            *pszEntryEnd = '/';
    17251740            if (RT_FAILURE(rc))
    1726                 break;
    1727 
    1728             if (   hDir     == NIL_RTVFSDIR
    1729                 && hSymlink == NIL_RTVFSSYMLINK
    1730                 && hVfsMnt  == NIL_RTVFS)
    17311741            {
    1732                 rc = VERR_NOT_A_DIRECTORY;
     1742                if (rc == VERR_FILE_NOT_FOUND)
     1743                    rc = VERR_PATH_NOT_FOUND;
    17331744                break;
    17341745            }
     1746            hDir     = RTVfsObjToDir(hVfsObj);
     1747            hSymlink = RTVfsObjToSymlink(hVfsObj);
     1748            hVfsMnt  = RTVfsObjToVfs(hVfsObj);
    17351749        }
    17361750        Assert(   (hDir != NIL_RTVFSDIR && hSymlink == NIL_RTVFSSYMLINK && hVfsMnt == NIL_RTVFS)
    17371751               || (hDir == NIL_RTVFSDIR && hSymlink != NIL_RTVFSSYMLINK && hVfsMnt == NIL_RTVFS)
    17381752               || (hDir == NIL_RTVFSDIR && hSymlink == NIL_RTVFSSYMLINK && hVfsMnt != NIL_RTVFS));
     1753        RTVfsObjRelease(hVfsObj);
    17391754
    17401755        if (hDir != NIL_RTVFSDIR)
     
    26132628    if (RT_SUCCESS(rc))
    26142629    {
    2615         if (   !pPath->fDirSlash
    2616             && pPath->cComponents > 0)
     2630        if (pPath->cComponents > 0)
    26172631        {
    26182632            /*
     
    26212635             */
    26222636            RTVFSDIRINTERNAL *pVfsParentDir;
    2623             rc = rtVfsDirTraverseToParent(pThis, pPath, RTPATH_F_FOLLOW_LINK, &pVfsParentDir);
     2637            rc = rtVfsDirTraverseToParent(pThis, pPath,
     2638                                          (fOpen & RTFILE_O_NO_SYMLINKS ? RTPATH_F_NO_SYMLINKS : 0) | RTPATH_F_FOLLOW_LINK,
     2639                                          &pVfsParentDir);
    26242640            if (RT_SUCCESS(rc))
    26252641            {
    26262642                const char *pszEntryName = &pPath->szPath[pPath->aoffComponents[pPath->cComponents - 1]];
    26272643
    2628                 /** @todo there is a symlink creation race here. */
    2629                 RTVfsLockAcquireWrite(pVfsParentDir->Base.hLock);
    2630                 rc = pVfsParentDir->pOps->pfnOpenFile(pVfsParentDir->Base.pvThis, pszEntryName, fOpen, phVfsFile);
    2631                 RTVfsLockReleaseWrite(pVfsParentDir->Base.hLock);
    2632 
    2633                 RTVfsDirRelease(pVfsParentDir);
     2644                if (   pVfsParentDir->pOps->pfnOpenFile == NULL
     2645                    || pPath->fDirSlash)
     2646                {
     2647                    RTVFSOBJ hVfsObj;
     2648                    RTVfsLockAcquireWrite(pVfsParentDir->Base.hLock);
     2649                    rc = pVfsParentDir->pOps->pfnOpen(pVfsParentDir->Base.pvThis, pszEntryName, fOpen,
     2650                                                      RTVFSOBJ_F_OPEN_ANY_FILE | RTVFSOBJ_F_CREATE_FILE
     2651                                                      | RTPATH_F_FOLLOW_LINK, &hVfsObj);
     2652                    RTVfsLockReleaseWrite(pVfsParentDir->Base.hLock);
     2653                    if (RT_SUCCESS(rc))
     2654                    {
     2655                        if (RTVfsObjGetType(hVfsObj) != RTVFSOBJTYPE_SYMLINK)
     2656                            *phVfsFile = RTVfsObjToFile(hVfsObj);
     2657                        else
     2658                        {
     2659                            /** @todo parse symbolic links. */
     2660                            AssertFailed();
     2661                            rc = VERR_NOT_IMPLEMENTED;
     2662                        }
     2663                        RTVfsObjRelease(hVfsObj);
     2664                    }
     2665                }
     2666                else
     2667                {
     2668                    /** @todo there is a symlink creation race here. */
     2669                    RTVfsLockAcquireWrite(pVfsParentDir->Base.hLock);
     2670                    rc = pVfsParentDir->pOps->pfnOpenFile(pVfsParentDir->Base.pvThis, pszEntryName, fOpen, phVfsFile);
     2671                    RTVfsLockReleaseWrite(pVfsParentDir->Base.hLock);
     2672                }
    26342673
    26352674                if (RT_SUCCESS(rc))
     
    26382677                    Assert((*phVfsFile)->uMagic == RTVFSFILE_MAGIC);
    26392678                }
     2679
     2680                RTVfsDirRelease(pVfsParentDir);
    26402681            }
    26412682        }
     
    26822723
    26832724    /*
    2684      * Parse the relative path.
     2725     * Parse the relative path.  If it ends with a directory slash or it boils
     2726     * down to an empty path (i.e. re-opening hVfsDir), adjust the flags to only
     2727     * open/create directories.
    26852728     */
    26862729    PRTVFSPARSEDPATH pPath;
     
    26902733        if (   pPath->fDirSlash
    26912734            || pPath->cComponents == 0)
     2735        {
    26922736            fObjFlags &= ~RTVFSOBJ_F_OPEN_ANY | RTVFSOBJ_F_OPEN_DIRECTORY;
    2693 
     2737            if ((fObjFlags & RTVFSOBJ_F_CREATE_MASK) != RTVFSOBJ_F_CREATE_DIRECTORY)
     2738                fObjFlags = (fObjFlags & ~RTVFSOBJ_F_CREATE_MASK) | RTVFSOBJ_F_CREATE_NOTHING;
     2739        }
     2740
     2741        /*
     2742         * Tranverse the path, resolving the parent node, not checking for
     2743         * symbolic links in the final element.
     2744         */
     2745        const char       *pszEntryName;
     2746        RTVFSDIRINTERNAL *pVfsParentDir;
    26942747        if (pPath->cComponents > 0)
    26952748        {
     2749            rc = rtVfsDirTraverseToParent(pThis, pPath, fObjFlags & RTPATH_F_MASK, &pVfsParentDir);
     2750            pszEntryName = &pPath->szPath[pPath->aoffComponents[pPath->cComponents - 1]];
     2751        }
     2752        else
     2753        {
     2754            RTVfsDirRetain(pThis);
     2755            pVfsParentDir = pThis;
     2756            pszEntryName  = ".";
     2757        }
     2758        if (RT_SUCCESS(rc))
     2759        {
    26962760            /*
    2697              * Tranverse the path, resolving the parent node, not
    2698              * checking for symbolic links in the final element.
     2761             * Do the opening.
    26992762             */
    2700             RTVFSDIRINTERNAL *pVfsParentDir;
    2701             rc = rtVfsDirTraverseToParent(pThis, pPath, RTPATH_F_ON_LINK, &pVfsParentDir);
    2702             if (RT_SUCCESS(rc))
     2763            RTVfsLockAcquireWrite(pVfsParentDir->Base.hLock);
     2764            rc = pVfsParentDir->pOps->pfnOpen(pVfsParentDir->Base.pvThis, pszEntryName, fFileOpen, fObjFlags, phVfsObj);
     2765            RTVfsLockReleaseWrite(pVfsParentDir->Base.hLock);
     2766
     2767            if (   (fObjFlags & RTPATH_F_FOLLOW_LINK)
     2768                && RTVfsObjGetType(*phVfsObj) == RTVFSOBJTYPE_SYMLINK)
    27032769            {
    2704                 const char *pszEntryName = &pPath->szPath[pPath->aoffComponents[pPath->cComponents - 1]];
    2705 
    2706                 /*
    2707                  * If we've got a trailing directory slash, use pfnOpenDir
    2708                  * instead of pfnOpenObj.
    2709                  */
    2710                 if (pPath->fDirSlash)
    2711                 {
    2712                     RTVFSDIR hVfsSubDir;
    2713                     RTVfsLockAcquireWrite(pVfsParentDir->Base.hLock);
    2714                     rc = pVfsParentDir->pOps->pfnOpenDir(pVfsParentDir->Base.pvThis, pszEntryName,
    2715                                                          0 /** @todo fFlags*/, &hVfsSubDir);
    2716                     RTVfsLockReleaseWrite(pVfsParentDir->Base.hLock);
    2717                     if (RT_SUCCESS(rc))
    2718                     {
    2719                         *phVfsObj = RTVfsObjFromDir(hVfsSubDir);
    2720                         RTVfsDirRelease(hVfsSubDir);
    2721                         AssertStmt(*phVfsObj != NIL_RTVFSOBJ, rc = VERR_INTERNAL_ERROR_3);
    2722                     }
    2723                 }
    2724                 else
    2725                 {
    2726                     RTVfsLockAcquireWrite(pVfsParentDir->Base.hLock);
    2727                     rc = pVfsParentDir->pOps->pfnOpen(pVfsParentDir->Base.pvThis, pszEntryName, fFileOpen, fObjFlags, phVfsObj);
    2728                     RTVfsLockReleaseWrite(pVfsParentDir->Base.hLock);
    2729                 }
    2730                 RTVfsDirRelease(pVfsParentDir);
     2770                /** @todo implement following symbolic links. */
     2771                AssertFailed();
     2772                RTVfsObjRelease(*phVfsObj);
     2773                *phVfsObj = NIL_RTVFSOBJ;
     2774                rc = VERR_NOT_IMPLEMENTED;
    27312775            }
    2732         }
    2733         /*
    2734          * The path boils down to '.', call pfnOpenDir on pThis with '.' as input.
    2735          * The caller may wish for a new directory instance to enumerate the entries
    2736          * in parallel or some such thing.
    2737          */
    2738         else
    2739         {
    2740             RTVFSDIR hVfsSubDir;
    2741             RTVfsLockAcquireWrite(pThis->Base.hLock);
    2742             rc = pThis->pOps->pfnOpenDir(pThis->Base.pvThis, ".", 0 /** @todo fFlags*/, &hVfsSubDir);
    2743             RTVfsLockReleaseWrite(pThis->Base.hLock);
    2744             if (RT_SUCCESS(rc))
    2745             {
    2746                 *phVfsObj = RTVfsObjFromDir(hVfsSubDir);
    2747                 RTVfsDirRelease(hVfsSubDir);
    2748                 AssertStmt(*phVfsObj != NIL_RTVFSOBJ, rc = VERR_INTERNAL_ERROR_3);
    2749             }
    2750         }
    2751 
     2776
     2777            RTVfsDirRelease(pVfsParentDir);
     2778        }
    27522779        RTVfsParsePathFree(pPath);
    27532780    }
  • trunk/src/VBox/Runtime/common/vfs/vfsstddir.cpp

    r69813 r69818  
    251251
    252252
    253 
    254 /**
    255  * @interface_method_impl{RTVFSDIROPS,pfnTraversalOpen}
    256  */
    257 static DECLCALLBACK(int) rtVfsStdDir_TraversalOpen(void *pvThis, const char *pszEntry, PRTVFSDIR phVfsDir,
    258                                                    PRTVFSSYMLINK phVfsSymlink, PRTVFS phVfsMounted)
    259 {
    260     /* No union mounting or mount points here (yet). */
    261     if (phVfsMounted)
    262         *phVfsMounted = NIL_RTVFS;
    263 
    264     int rc;
    265     if (phVfsDir || phVfsSymlink)
    266     {
    267         if (phVfsDir)
    268             *phVfsDir = NIL_RTVFSDIR;
    269         if (phVfsSymlink)
    270             *phVfsSymlink = NIL_RTVFSSYMLINK;
    271 
    272         RTFSOBJINFO ObjInfo;
    273         rc = rtVfsStdDir_QueryEntryInfo(pvThis, pszEntry, &ObjInfo, RTFSOBJATTRADD_NOTHING);
    274         if (RT_SUCCESS(rc))
    275         {
    276             switch (ObjInfo.Attr.fMode & RTFS_TYPE_MASK)
    277             {
    278                 case RTFS_TYPE_DIRECTORY:
    279                     if (phVfsDir)
    280                         rc = rtVfsStdDir_OpenDir(pvThis, pszEntry, 0, phVfsDir);
    281                     else
    282                         rc = VERR_NOT_SYMLINK;
    283                     break;
    284 
    285                 case RTFS_TYPE_SYMLINK:
    286                     if (phVfsSymlink)
    287                         rc = rtVfsStdDir_OpenSymlink(pvThis, pszEntry, phVfsSymlink);
    288                     else
    289                         rc = VERR_NOT_A_DIRECTORY;
    290                     break;
    291 
    292                 default:
    293                     rc = phVfsDir ? VERR_NOT_A_DIRECTORY : VERR_NOT_SYMLINK;
    294                     break;
    295             }
    296         }
    297     }
    298     else
    299         rc = VERR_PATH_NOT_FOUND;
    300 
    301     LogFlow(("rtVfsStdDir_TraversalOpen: %s -> %Rrc\n", pszEntry, rc));
    302     return rc;
    303 }
    304 
    305 
    306 /**
    307  * @interface_method_impl{RTVFSDIROPS,pfnOpenObj}
    308  */
    309 static DECLCALLBACK(int) rtVfsStdDir_OpenObj(void *pvThis, const char *pszEntry, uint64_t fOpen,
    310                                              uint32_t fFlags, PRTVFSOBJ phVfsObj)
     253/**
     254 * @interface_method_impl{RTVFSDIROPS,pfnOpen}
     255 */
     256static DECLCALLBACK(int) rtVfsStdDir_Open(void *pvThis, const char *pszEntry, uint64_t fFileOpen,
     257                                          uint32_t fVfsFlags, PRTVFSOBJ phVfsObj)
    311258{
    312259    PRTVFSSTDDIR pThis = (PRTVFSSTDDIR)pvThis;
     
    323270        {
    324271            case RTFS_TYPE_DIRECTORY:
    325                 if (!(fFlags & RTVFSOBJ_F_OPEN_DIRECTORY))
     272                if (!(fVfsFlags & RTVFSOBJ_F_OPEN_DIRECTORY))
    326273                {
    327                     if (   (fOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_OPEN
    328                         || (fOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_OPEN_CREATE
    329                         || (fOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_CREATE_REPLACE)
     274                    if (   (fFileOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_OPEN
     275                        || (fFileOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_OPEN_CREATE
     276                        || (fFileOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_CREATE_REPLACE)
    330277                    {
    331278                        RTDIR hSubDir;
    332                         rc = RTDirRelDirOpenFiltered(pThis->hDir, pszEntry, RTDIRFILTER_NONE, fFlags, &hSubDir);
     279                        rc = RTDirRelDirOpenFiltered(pThis->hDir, pszEntry, RTDIRFILTER_NONE, fVfsFlags, &hSubDir);
    333280                        if (RT_SUCCESS(rc))
    334281                        {
     
    339286                                *phVfsObj = RTVfsObjFromDir(hVfsDir);
    340287                                RTVfsDirRelease(hVfsDir);
    341                                 AssertStmt(*phVfsObj == NIL_RTVFSOBJ, rc = VERR_INTERNAL_ERROR_3);
     288                                AssertStmt(*phVfsObj != NIL_RTVFSOBJ, rc = VERR_INTERNAL_ERROR_3);
    342289                            }
    343290                            else
     
    360307                {
    361308                    case RTFS_TYPE_FILE:
    362                         rc = fFlags & RTVFSOBJ_F_OPEN_FILE      ? VINF_SUCCESS : VERR_IS_A_FILE;
     309                        rc = fVfsFlags & RTVFSOBJ_F_OPEN_FILE      ? VINF_SUCCESS : VERR_IS_A_FILE;
    363310                        break;
    364311                    case RTFS_TYPE_DEV_BLOCK:
    365                         rc = fFlags & RTVFSOBJ_F_OPEN_DEV_BLOCK ? VINF_SUCCESS : VERR_IS_A_BLOCK_DEVICE;
     312                        rc = fVfsFlags & RTVFSOBJ_F_OPEN_DEV_BLOCK ? VINF_SUCCESS : VERR_IS_A_BLOCK_DEVICE;
    366313                        break;
    367314                    case RTFS_TYPE_DEV_CHAR:
    368                         rc = fFlags & RTVFSOBJ_F_OPEN_DEV_CHAR  ? VINF_SUCCESS : VERR_IS_A_CHAR_DEVICE;
     315                        rc = fVfsFlags & RTVFSOBJ_F_OPEN_DEV_CHAR  ? VINF_SUCCESS : VERR_IS_A_CHAR_DEVICE;
    369316                        break;
    370317                    /** @todo These two types should not result in files, but pure I/O streams.
    371318                     *        possibly char device too.  */
    372319                    case RTFS_TYPE_FIFO:
    373                         rc = fFlags & RTVFSOBJ_F_OPEN_FIFO      ? VINF_SUCCESS : VERR_IS_A_FIFO;
     320                        rc = fVfsFlags & RTVFSOBJ_F_OPEN_FIFO      ? VINF_SUCCESS : VERR_IS_A_FIFO;
    374321                        break;
    375322                    case RTFS_TYPE_SOCKET:
    376                         rc = fFlags & RTVFSOBJ_F_OPEN_SOCKET    ? VINF_SUCCESS : VERR_IS_A_SOCKET;
     323                        rc = fVfsFlags & RTVFSOBJ_F_OPEN_SOCKET    ? VINF_SUCCESS : VERR_IS_A_SOCKET;
    377324                        break;
    378325                    default:
     
    382329                if (RT_SUCCESS(rc))
    383330                {
    384                     if (   (fOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_OPEN
    385                         || (fOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_OPEN_CREATE
    386                         || (fOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_CREATE_REPLACE)
     331                    if (   (fFileOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_OPEN
     332                        || (fFileOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_OPEN_CREATE
     333                        || (fFileOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_CREATE_REPLACE)
    387334                    {
    388335                        RTFILE hFile;
    389                         rc = RTDirRelFileOpen(pThis->hDir, pszEntry, fOpen, &hFile);
     336                        rc = RTDirRelFileOpen(pThis->hDir, pszEntry, fFileOpen, &hFile);
    390337                        if (RT_SUCCESS(rc))
    391338                        {
    392339                            RTVFSFILE hVfsFile;
    393                             rc = RTVfsFileFromRTFile(hFile, fOpen, false /*fLeaveOpen*/, &hVfsFile);
     340                            rc = RTVfsFileFromRTFile(hFile, fFileOpen, false /*fLeaveOpen*/, &hVfsFile);
    394341                            if (RT_SUCCESS(rc))
    395342                            {
    396343                                *phVfsObj = RTVfsObjFromFile(hVfsFile);
    397344                                RTVfsFileRelease(hVfsFile);
    398                                 AssertStmt(*phVfsObj == NIL_RTVFSOBJ, rc = VERR_INTERNAL_ERROR_3);
     345                                AssertStmt(*phVfsObj != NIL_RTVFSOBJ, rc = VERR_INTERNAL_ERROR_3);
    399346                            }
    400347                            else
     
    408355
    409356            case RTFS_TYPE_SYMLINK:
    410                 if (fFlags & RTVFSOBJ_F_OPEN_SYMLINK)
     357                if (fVfsFlags & RTVFSOBJ_F_OPEN_SYMLINK)
    411358                {
    412359                    uint32_t cRefs = RTVfsDirRetain(pThis->hSelf);
     
    448395         * Consider file or directory creation.
    449396         */
    450         if (   (   (fOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_CREATE
    451                 || (fOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_OPEN_CREATE
    452                 || (fOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_CREATE_REPLACE)
    453             && (fFlags & RTVFSOBJ_F_CREATE_MASK) != RTVFSOBJ_F_CREATE_NOTHING)
     397        if (   (   (fFileOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_CREATE
     398                || (fFileOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_OPEN_CREATE
     399                || (fFileOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_CREATE_REPLACE)
     400            && (fVfsFlags & RTVFSOBJ_F_CREATE_MASK) != RTVFSOBJ_F_CREATE_NOTHING)
    454401        {
    455402
    456             if ((fFlags & RTVFSOBJ_F_CREATE_MASK) == RTVFSOBJ_F_CREATE_FILE)
     403            if ((fVfsFlags & RTVFSOBJ_F_CREATE_MASK) == RTVFSOBJ_F_CREATE_FILE)
    457404            {
    458405                RTFILE hFile;
    459                 rc = RTDirRelFileOpen(pThis->hDir, pszEntry, fOpen, &hFile);
     406                rc = RTDirRelFileOpen(pThis->hDir, pszEntry, fFileOpen, &hFile);
    460407                if (RT_SUCCESS(rc))
    461408                {
    462409                    RTVFSFILE hVfsFile;
    463                     rc = RTVfsFileFromRTFile(hFile, fOpen, false /*fLeaveOpen*/, &hVfsFile);
     410                    rc = RTVfsFileFromRTFile(hFile, fFileOpen, false /*fLeaveOpen*/, &hVfsFile);
    464411                    if (RT_SUCCESS(rc))
    465412                    {
    466413                        *phVfsObj = RTVfsObjFromFile(hVfsFile);
    467414                        RTVfsFileRelease(hVfsFile);
    468                         AssertStmt(*phVfsObj == NIL_RTVFSOBJ, rc = VERR_INTERNAL_ERROR_3);
     415                        AssertStmt(*phVfsObj != NIL_RTVFSOBJ, rc = VERR_INTERNAL_ERROR_3);
    469416                    }
    470417                    else
     
    472419                }
    473420            }
    474             else if ((fFlags & RTVFSOBJ_F_CREATE_MASK) == RTVFSOBJ_F_CREATE_DIRECTORY)
     421            else if ((fVfsFlags & RTVFSOBJ_F_CREATE_MASK) == RTVFSOBJ_F_CREATE_DIRECTORY)
    475422            {
    476423                RTDIR hSubDir;
    477                 rc = RTDirRelDirCreate(pThis->hDir, pszEntry, (fOpen & RTFILE_O_CREATE_MODE_MASK) >> RTFILE_O_CREATE_MODE_SHIFT,
    478                                        0 /* fFlags */, &hSubDir);
     424                rc = RTDirRelDirCreate(pThis->hDir, pszEntry, (fFileOpen & RTFILE_O_CREATE_MODE_MASK) >> RTFILE_O_CREATE_MODE_SHIFT,
     425                                       0 /* fVfsFlags */, &hSubDir);
    479426                if (RT_SUCCESS(rc))
    480427                {
     
    720667        RTVFSOBJSETOPS_VERSION
    721668    },
    722     rtVfsStdDir_OpenObj,
    723     rtVfsStdDir_TraversalOpen,
     669    rtVfsStdDir_Open,
    724670    rtVfsStdDir_OpenFile,
    725671    rtVfsStdDir_OpenDir,
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