Changeset 1947 for trunk


Ignore:
Timestamp:
May 2, 2005, 5:00:19 AM (20 years ago)
Author:
bird
Message:

Fixed several incorrect/incomplete resolve cases. Some causing invalid ino values.

Location:
trunk/src/emx/src/lib/sys
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/sys/b_fs.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1946 r1947  
    119119 * @{ */
    120120/** Resolves the path up to but not including the last component. */
    121 #define BACKFS_FLAGS_RESOLVE_PARENT         0
     121#define BACKFS_FLAGS_RESOLVE_PARENT             0x00
    122122/** Resolves and verfies the entire path. */
    123 #define BACKFS_FLAGS_RESOLVE_FULL           1
     123#define BACKFS_FLAGS_RESOLVE_FULL               0x01
     124/** Resolves and verfies the entire path, but don't resolve any symlink in the last component. */
     125#define BACKFS_FLAGS_RESOLVE_FULL_SYMLINK       0x02
     126/** Internal, use BACKFS_FLAGS_RESOLVE_FULL_MAYBE. */
     127#define BACKFS_FLAGS_RESOLVE_FULL_MAYBE_        0x08
    124128/** Resolves and verfies the entire path but it's ok if the last component doesn't exist. */
    125 #define BACKFS_FLAGS_RESOLVE_FULL_MAYBE     (BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_FULL_MAYBE_)
    126 /** Internal, use BACKFS_FLAGS_RESOLVE_FULL_MAYBE. */
    127 #define BACKFS_FLAGS_RESOLVE_FULL_MAYBE_    2
     129#define BACKFS_FLAGS_RESOLVE_FULL_MAYBE         (BACKFS_FLAGS_RESOLVE_FULL_MAYBE_ | BACKFS_FLAGS_RESOLVE_FULL)
     130/** Resolves and verfies the entire path but it's ok if the last component doesn't exist. */
     131#define BACKFS_FLAGS_RESOLVE_FULL_SYMLINK_MAYBE (BACKFS_FLAGS_RESOLVE_FULL_MAYBE_ | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK)
    128132/** The specified path is a directory. */
    129 #define BACKFS_FLAGS_RESOLVE_DIR            4
     133#define BACKFS_FLAGS_RESOLVE_DIR                0x10
     134/** Internal, use BACKFS_FLAGS_RESOLVE_DIR_MAYBE. */
     135#define BACKFS_FLAGS_RESOLVE_DIR_MAYBE_         0x80
    130136/** The specified path maybe a directory. */
    131 #define BACKFS_FLAGS_RESOLVE_DIR_MAYBE      (BACKFS_FLAGS_RESOLVE_DIR | BACKFS_FLAGS_RESOLVE_DIR_MAYBE_)
    132 /** Internal, use BACKFS_FLAGS_RESOLVE_DIR_MAYBE. */
    133 #define BACKFS_FLAGS_RESOLVE_DIR_MAYBE_     8
     137#define BACKFS_FLAGS_RESOLVE_DIR_MAYBE          (BACKFS_FLAGS_RESOLVE_DIR_MAYBE_ | BACKFS_FLAGS_RESOLVE_DIR)
    134138/** @} */
    135139
  • trunk/src/emx/src/lib/sys/b_fsDirRemove.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1946 r1947  
    5858     */
    5959    char szNativePath[PATH_MAX];
    60     int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_PARENT | BACKFS_FLAGS_RESOLVE_DIR, &szNativePath[0], NULL);
     60    int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR, &szNativePath[0], NULL);
    6161    if (rc)
    6262        LIBCLOG_RETURN_INT(rc);
  • trunk/src/emx/src/lib/sys/b_fsRename.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1946 r1947  
    6666     */
    6767    char szNativePathOld[PATH_MAX];
    68     int rc = __libc_back_fsResolve(pszPathOld, BACKFS_FLAGS_RESOLVE_PARENT | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, &szNativePathOld[0], NULL);
     68    int rc = __libc_back_fsResolve(pszPathOld, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, &szNativePathOld[0], NULL);
    6969    if (rc)
    7070        LIBCLOG_RETURN_INT(rc);
  • trunk/src/emx/src/lib/sys/b_fsSymlinkModeSet.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1946 r1947  
    5151     */
    5252    char szNativePath[PATH_MAX];
    53     int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_PARENT | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, NULL);
     53    int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, NULL);
    5454    if (!rc)
    5555        rc = __libc_back_fsNativeFileModeSet(szNativePath, Mode);
  • trunk/src/emx/src/lib/sys/b_fsSymlinkRead.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1946 r1947  
    5959     */
    6060    char szNativePath[PATH_MAX];
    61     int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_PARENT, &szNativePath[0], NULL);
     61    int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK, &szNativePath[0], NULL);
    6262    if (!rc)
    6363        rc = __libc_back_fsNativeSymlinkRead(szNativePath, pachBuf, cchBuf);
  • trunk/src/emx/src/lib/sys/b_fsSymlinkStat.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1946 r1947  
    5353     */
    5454    char szNativePath[PATH_MAX];
    55     int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_PARENT | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, NULL);
     55    int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, NULL);
    5656    if (!rc)
    5757        rc = __libc_back_fsNativeFileStat(szNativePath, pStat);
  • trunk/src/emx/src/lib/sys/b_fsUnlink.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1946 r1947  
    6565     */
    6666    char szNativePath[PATH_MAX];
    67     int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_PARENT | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, &szNativePath[0], NULL);
     67    int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, &szNativePath[0], NULL);
    6868    if (rc)
    6969        LIBCLOG_RETURN_INT(rc);
  • trunk/src/emx/src/lib/sys/fs.c

    • Property cvs2svn:cvs-rev changed from 1.14 to 1.15
    r1946 r1947  
    187187*******************************************************************************/
    188188static int fsResolveUnix(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree);
     189static int fsResolveOS2(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree);
    189190static uint32_t crc32str(const char *psz);
    190191static uint32_t djb2(const char *str);
     
    192193
    193194
    194 
     195#ifndef STANDALONE_TEST
    195196/**
    196197 * Init the file system stuff.
     
    365366}
    366367
     368#endif /*!STANDALONE_TEST*/
    367369
    368370/**
     
    668670    if (!__libc_gfNoUnix)
    669671        return fsResolveUnix(pszUserPath, fFlags, pszNativePath, pfInUnixTree);
    670 
    671     /* __libc_back_fsResolveOS2(): */
    672 
    673     LIBCLOG_ENTER("pszUserPath=%p:{%s} fFlags=%x pszNativePath=%p pfInUnixTree=%p\n",
    674                   (void *)pszUserPath, pszUserPath, fFlags, (void *)pszNativePath, (void *)pfInUnixTree);
    675 
    676     /*
    677      * Apply rewrite rule.
    678      */
    679     int cch = __libc_PathRewrite(pszUserPath, pszNativePath, sizeof(pszNativePath));
    680     if (cch < 0)
    681         LIBCLOG_RETURN_INT(-EINVAL);
    682     if (cch == 0)
    683     {
    684         cch = strlen(pszUserPath);
    685         if (cch >= PATH_MAX)
    686             LIBCLOG_RETURN_INT(-ENAMETOOLONG);
    687         memcpy(pszNativePath, pszUserPath, cch + 1);
    688     }
    689 
    690     /*
    691      * Convert slashes.
    692      */
    693     char *psz = strchr(pszNativePath, '/');
    694     while (psz)
    695     {
    696         *psz++ = '\\';
    697         psz = strchr(psz, '/');
    698     }
    699 
    700     /** @todo Validate the path? hopefully not necessary. */
    701 
    702     if (pfInUnixTree)
    703         *pfInUnixTree = 0;
    704 
    705     LIBCLOG_RETURN_INT(0);
     672    else
     673        return fsResolveOS2(pszUserPath, fFlags, pszNativePath, pfInUnixTree);
    706674}
    707675
     
    719687 * @param   pfInUnixTree    Where to store the result-in-unix-tree indicator. Optional.
    720688 */
    721 int fsResolveUnix(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree)
     689static int fsResolveUnix(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree)
    722690{
    723691    LIBCLOG_ENTER("pszUserPath=%p:{%s} pszNativePath=%p *pfInUnixTree=%p\n",
     
    744712            fInUnixTree = __libc_gfInUnixTree;
    745713        }
    746         else if (pszUserPath[0] && pszUserPath[1] == ':'
     714        else if (   pszUserPath[0] && pszUserPath[1] == ':'
    747715                 && (pszUserPath[2] == '/' || pszUserPath[2] == '\\'))
    748716        {
     
    898866
    899867        /*
    900          * Expand unix root.
     868         * Expand unix root or add missing drive letter.
    901869         */
    902         if (szTmp[0] == '/' && szTmp[1] != '/' && __libc_gcchUnixRoot)
    903         {
    904             iRoot = __libc_gcchUnixRoot;
    905             if (cchTmp + iRoot >= PATH_MAX)
    906             {
    907                 rcRet = -ENAMETOOLONG;
    908                 break;
    909             }
     870        if (szTmp[0] == '/' && szTmp[1] != '/')
     871        {
    910872            memcpy(pachBuffer, szTmp, cchTmp + 1);
    911             memcpy(szTmp, __libc_gszUnixRoot, iRoot);
     873            if (__libc_gcchUnixRoot)
     874            {
     875                iRoot = __libc_gcchUnixRoot;
     876                if (cchTmp + iRoot >= PATH_MAX)
     877                {
     878                    rcRet = -ENAMETOOLONG;
     879                    break;
     880                }
     881                memcpy(szTmp, __libc_gszUnixRoot, iRoot);
     882                fInUnixTree = 1;
     883            }
     884            else
     885            {
     886                iRoot = 2;
     887                ULONG   ulDisk = 0;
     888                ULONG   ul;
     889                DosQueryCurrentDisk(&ulDisk, &ul);
     890                if (cchTmp + iRoot >= PATH_MAX)
     891                {
     892                    rcRet = -ENAMETOOLONG;
     893                    break;
     894                }
     895                szTmp[0] = ulDisk + 'A' - 1;
     896                szTmp[1] = ':';
     897            }
    912898            if (cchTmp != 1 || iRoot <= 2)
    913899                memcpy(&szTmp[iRoot], pachBuffer, cchTmp + 1);
     
    915901                szTmp[iRoot] = '\0';
    916902            cchTmp += iRoot;
    917 
    918             fInUnixTree = 1;
    919903        }
    920904
     
    962946        else
    963947        {
     948            /* drive letters are always uppercase! (inode dev number req) */
     949            LIBC_ASSERT(szTmp[1] == ':');
     950            if (szTmp[0] >= 'a' && szTmp[0] <= 'z')
     951                szTmp[0] -= 'a' - 'A';
    964952            pszPrev = &szTmp[iRoot + 1];
    965953            psz = strchr(pszPrev, '/');
     
    968956        /* If only one component, we'll check if the fVerifyLast was requested. */
    969957        if (    !psz
    970             &&  (fFlags & BACKFS_FLAGS_RESOLVE_FULL)
     958            &&  (fFlags & (BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK))
    971959            &&  *pszPrev)
    972960            psz = strchr(szTmp, '\0');
     
    10141002                    else
    10151003                    {
    1016                         if (!(fFlags & BACKFS_FLAGS_RESOLVE_FULL))
     1004                        if (!(fFlags & (BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK)))
    10171005                        {
    10181006                            rcRet = 0;
     
    10381026             * Find the correct name and to check if it is a directory or not.
    10391027             * This'll of course also provide proper verification of the path too. :-)
     1028             *
     1029             * (This is a little bit messed up since we'll have to use wildcard for
     1030             * getting the caseing resolved.)
    10401031             */
     1032            LIBC_ASSERT(psz - szTmp == cchTmp);
    10411033            PFILEFINDBUF4 pFindBuf = (PFILEFINDBUF4)pachBuffer;
    10421034            ULONG cFiles = 1;
     1035            char chNext = psz[1];
     1036            psz[0] = '?';
     1037            psz[1] = '\0';
    10431038            int rc = DosFindFirst((PCSZ)&szTmp[0], &hDir, FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY | FILE_ARCHIVED,
    10441039                                  pFindBuf, SIZEOF_ACHBUFFER, &cFiles, FIL_QUERYEASIZE);
     1040            psz[0] = '\0';
     1041            psz[1] = chNext;
    10451042            if (rc || cFiles == 0)
    10461043            {
    1047                 LIBCLOG_MSG("DosFindFirst('%s',,,,,) -> %d resolving '%s'\n", szTmp, rc, pszUserPathIn);
     1044                hDir = HDIR_CREATE;
     1045            }
     1046            while (!rc && cFiles == 1 && pFindBuf->cchName != psz - pszPrev)
     1047                rc = DosFindNext(hDir, pFindBuf, SIZEOF_ACHBUFFER, &cFiles);
     1048            if (rc || cFiles == 0)
     1049            {
     1050                LIBCLOG_MSG("DosFindFirst/Next('%s',,,,,) -> %d resolving '%s'\n", szTmp, rc, pszUserPathIn);
    10481051                if ((fFlags & BACKFS_FLAGS_RESOLVE_FULL_MAYBE_) && !chSlash)
     1052                {
     1053                    *psz = chSlash;
    10491054                    rcRet = 0;
     1055                }
    10501056                else
    10511057                    rcRet = rc == ERROR_FILE_NOT_FOUND && chSlash ? -ENOENT : -__libc_native2errno(rc);
    1052                 hDir = HDIR_CREATE;
    10531058                break;
    10541059            }
     
    10571062
    10581063            /*
    1059              * Try querying the symlink EA value.
     1064             * Try querying the symlink EA value
    10601065             * (This operation will reuse the achBuffer overwriting the pFindBuf data!)
    10611066             *
     
    10651070             * is rather clumsily laid out. So, I decided not to try my luck on it.
    10661071             */
    1067             if (pFindBuf->cbList > sizeof(USHORT) * 2 + 1)
     1072            if (    pFindBuf->cbList > sizeof(USHORT) * 2 + 1
     1073                &&  (   (fFlags & BACKFS_FLAGS_RESOLVE_FULL)
     1074                     || chSlash))
    10681075            {
    10691076                EAOP2   EaOp;
     
    11631170                            else
    11641171                            {
    1165                                 if (!(fFlags & BACKFS_FLAGS_RESOLVE_FULL))
     1172                                if (!(fFlags & (BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK)))
    11661173                                {
    11671174                                    rcRet = 0;
     
    12011208                if (!*psz)
    12021209                {
    1203                     if (!(fFlags & BACKFS_FLAGS_RESOLVE_FULL))
     1210                    if (!(fFlags & (BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK)))
    12041211                    {
    12051212                        rcRet = 0;
     
    12441251    pszUserPathIn = pszUserPathIn;
    12451252}
     1253
     1254
     1255/**
     1256 * Resolves and verifies the user path to a native path.
     1257 *
     1258 * @returns 0 on success.
     1259 * @returns -1 and errno on failure.
     1260 * @param   pszUserPath     The user path.
     1261 * @parm    fFlags          Flags controlling the operation of the function.
     1262 *                          See the BACKFS_FLAGS_* defines.
     1263 * @param   pszNativePath   Where to store the native path. This buffer is at
     1264 *                          least PATH_MAX bytes big.
     1265 * @param   pfInUnixTree    Where to store the result-in-unix-tree indicator. Optional.
     1266 */
     1267static int fsResolveOS2(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree)
     1268{
     1269    LIBCLOG_ENTER("pszUserPath=%p:{%s} fFlags=%x pszNativePath=%p pfInUnixTree=%p\n",
     1270                  (void *)pszUserPath, pszUserPath, fFlags, (void *)pszNativePath, (void *)pfInUnixTree);
     1271
     1272    /*
     1273     * Apply rewrite rule.
     1274     */
     1275    int cch = __libc_PathRewrite(pszUserPath, pszNativePath, sizeof(pszNativePath));
     1276    if (cch < 0)
     1277        LIBCLOG_RETURN_INT(-EINVAL);
     1278    if (cch == 0)
     1279    {
     1280        cch = strlen(pszUserPath);
     1281        if (cch >= PATH_MAX)
     1282            LIBCLOG_RETURN_INT(-ENAMETOOLONG);
     1283        memcpy(pszNativePath, pszUserPath, cch + 1);
     1284    }
     1285
     1286    /*
     1287     * Convert slashes.
     1288     */
     1289    char *psz = strchr(pszNativePath, '/');
     1290    while (psz)
     1291    {
     1292        *psz++ = '\\';
     1293        psz = strchr(psz, '/');
     1294    }
     1295
     1296    /** @todo Validate the path? hopefully not necessary. */
     1297
     1298    if (pfInUnixTree)
     1299        *pfInUnixTree = 0;
     1300
     1301    LIBCLOG_RETURN_INT(0);
     1302}
     1303
     1304
    12461305
    12471306
Note: See TracChangeset for help on using the changeset viewer.