Changeset 2522 for branches


Ignore:
Timestamp:
Feb 5, 2006, 2:53:28 AM (20 years ago)
Author:
bird
Message:

#21: Restrict reading and writing of UnixEAs to HPFS, JFS, FAT and RAMFS.

Location:
branches/libc-0.6/src/emx
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/include/emx/io.h

    r2439 r2522  
    320320    /** Does the file system automatically zero the new space when a file is extended? */
    321321    unsigned            fZeroNewBytes : 1;
     322    /** Does the file system provide sufficient EA support for UNIX attributes? */
     323    unsigned            fUnixEAs : 1;
    322324    /** Device number of the device the filesystem resides on.
    323325     * On OS/2 the device number is derived from the driveletter. */
  • branches/libc-0.6/src/emx/src/lib/sys/b_fs.h

    r2328 r2522  
    411411
    412412/**
     413 * Gets the fs info object for the specfied path.
     414 *
     415 * @returns Pointer to info object for the path, if it got one.
     416 * @param   pszNativePath   The native path as returned by the resolver.
     417 */
     418__LIBC_PFSINFO __libc_back_fsInfoObjByPath(const char *pszNativePath);
     419
     420/**
     421 * Gets the fs info object for the specfied path, with cache.
     422 *
     423 * @returns Pointer to info object for the path, if it got one.
     424 * @param   pszNativePath   The native path as returned by the resolver.
     425 * @param   pCached         An cached fs info object reference. Can be NULL.
     426 */
     427__LIBC_PFSINFO __libc_back_fsInfoObjByPathCached(const char *pszNativePath, __LIBC_PFSINFO pCached);
     428
     429/**
    413430 * Adds a reference to an existing FS info object.
    414431 *
     
    428445void __libc_back_fsInfoObjRelease(__LIBC_PFSINFO pFsInfo);
    429446
     447/**
     448 * Checks if the path supports Unix EAs or not.
     449 *
     450 * @returns true / false.
     451 * @param   pszNativePath       The native path to check.
     452 */
     453int __libc_back_fsInfoSupportUnixEAs(const char *pszNativePath);
     454
    430455__END_DECLS
    431456
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsDirCreate.c

    r2313 r2522  
    6969     */
    7070    PEAOP2 pEaOp2 = NULL;
    71     if (__predict_true(!__libc_gfNoUnix))
     71    if (__predict_true(__libc_back_fsInfoSupportUnixEAs(szNativePath)))
    7272    {
    7373        Mode &= ~__libc_gfsUMask;
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsFileModeSetFH.c

    r2313 r2522  
    121121         * If in unix mode we'll have to update/add the MODE too.
    122122         */
    123         if (!__libc_gfNoUnix)
     123        if (    !__libc_gfNoUnix
     124            &&  pFH->pFsInfo
     125            &&  pFH->pFsInfo->fUnixEAs)
    124126        {
    125127            struct stat st = {0};
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsFileStatFH.c

    r2316 r2522  
    7171        LIBCLOG_ERROR_RETURN_INT(rc);
    7272
     73    int fUnixEAs = !__libc_gfNoUnix && pFH->pFsInfo && pFH->pFsInfo->fUnixEAs;
    7374    if (/*!pFH->pOps*/ 1)
    7475    {
     
    110111            if (__libc_gpfnDosOpenL)
    111112            {
    112                 rc = DosQueryFileInfo(fh, FIL_QUERYEASIZEL, &info, sizeof(info.fsts4L));
     113                if (fUnixEAs)
     114                    rc = DosQueryFileInfo(fh, FIL_QUERYEASIZEL, &info, sizeof(info.fsts4L));
     115                else
     116                    rc = -1;
    113117                if (rc)
    114118                {
     
    121125#endif
    122126            {
    123                 rc = DosQueryFileInfo(fh, FIL_QUERYEASIZE, &info, sizeof(info.fsts4));
     127                if (fUnixEAs)
     128                    rc = DosQueryFileInfo(fh, FIL_QUERYEASIZE, &info, sizeof(info.fsts4));
     129                else
     130                    rc = -1;
    124131                if (rc)
    125132                {
     
    175182
    176183            /* If in unix mode we'll check the EAs (if any). */
    177             if (    !__libc_gfNoUnix
     184            if (   fUnixEAs
    178185                && (fLarge ? info.fsts4L.cbList : info.fsts4.cbList) >= LIBC_UNIX_EA_MIN)
    179186                __libc_back_fsUnixAttribsGet(fh, pFH->pszNativePath, pStat);
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsNativeFileModeSet.c

    r2313 r2522  
    8989    FS_SAVE_LOAD();
    9090    int rc;
    91 #if OFF_MAX > LONG_MAX
    92     if (__libc_gpfnDosOpenL)
    93     {
    94         rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZEL, &info, sizeof(info.fsts4L));
    95         fLarge = 1;
     91    const int fUnixEAs = __libc_back_fsInfoSupportUnixEAs(pszNativePath);
     92    if (fUnixEAs)
     93    {
     94#if OFF_MAX > LONG_MAX
     95        if (__libc_gpfnDosOpenL)
     96        {
     97            rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZEL, &info, sizeof(info.fsts4L));
     98            fLarge = 1;
     99        }
     100        else
     101#endif
     102            rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &info, sizeof(info.fsts4));
     103        /* If the file is open in write mode, we cannot even get the EA size. stupid.
     104         * It'll fail with ERROR_SHARING_VIOLATION, which we handle rigth below. */
    96105    }
    97106    else
    98 #endif
    99         rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &info, sizeof(info.fsts4));
    100     /* Now, if the file is open in write mode, we cannot even get the EA size. stupid. */
     107        rc = ERROR_SHARING_VIOLATION; /* take the fallback path if we don't want EAs. */
    101108    if (rc == ERROR_SHARING_VIOLATION)
    102109    {
     
    150157     * If in unix mode we'll have to update/add the MODE too.
    151158     */
    152     if (!__libc_gfNoUnix)
     159    if (fUnixEAs)
    153160    {
    154161        struct stat st = {0};
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsNativeFileStat.c

    r2316 r2522  
    8686     */
    8787    /** @todo copy device check from the path resolver. */
     88
    8889    /*
    8990     * Get path info.
     
    9192    FS_SAVE_LOAD();
    9293    int rc;
    93 #if OFF_MAX > LONG_MAX
    94     if (__libc_gpfnDosOpenL)
    95     {
    96         rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZEL, &info, sizeof(info.fsts4L));
    97         fLarge = 1;
    98     }
    99     else
    100 #endif
    101         rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &info, sizeof(info.fsts4));
     94    const int fUnixEAs = __libc_back_fsInfoSupportUnixEAs(pszNativePath);
     95    if (fUnixEAs)
     96    {
     97#if OFF_MAX > LONG_MAX
     98        if (__libc_gpfnDosOpenL)
     99        {
     100            rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZEL, &info, sizeof(info.fsts4L));
     101            fLarge = 1;
     102        }
     103        else
     104#endif
     105            rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &info, sizeof(info.fsts4));
     106        /* If the file is open in write mode, we cannot even get the EA size. stupid.
     107         * It'll fail with ERROR_SHARING_VIOLATION, which we handle rigth below. */
     108    }
     109    else
     110        rc = ERROR_SHARING_VIOLATION; /* take the fallback path if we don't want EAs. */
     111
    102112    /* Now, if the file is open in write mode, we cannot even get the EA size. stupid. */
    103113    if (rc == ERROR_SHARING_VIOLATION)
     
    198208    /* If in unix mode we'll check the EAs (if any). */
    199209    rc = 1;
    200     if (    !__libc_gfNoUnix
     210    if (    fUnixEAs
    201211        && (fLarge ? info.fsts4L.cbList : info.fsts4.cbList) >= LIBC_UNIX_EA_MIN)
    202212        rc = __libc_back_fsUnixAttribsGet(-1, pszNativePath, pStat);
  • branches/libc-0.6/src/emx/src/lib/sys/b_ioFileOpen.c

    r2424 r2522  
    259259        Mode &= ACCESSPERMS;
    260260        Mode |= S_IFREG;
    261         if (flOpenFlags & (OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS))
     261        if (    (flOpenFlags & (OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS))
     262            &&  __libc_back_fsInfoSupportUnixEAs(szNativePath))
    262263        {
    263264            pEaOp2 = alloca(sizeof(EAOP2) + sizeof(__libc_gFsUnixAttribsCreateFEA2List));
  • branches/libc-0.6/src/emx/src/lib/sys/b_nativeSymlinkCreate.c

    r2498 r2522  
    5858    BYTE    fSymlinkEA;
    5959    BYTE    cbSymlinkName;
    60     USHORT  usSymlinkValue;
     60    USHORT  cbSymlinkValue;
    6161    CHAR    szSymlinkName[sizeof(EA_SYMLINK)];
    6262    USHORT  usSymlinkType;
     
    112112
    113113    /*
     114     * Do we have UnixEAs on this path?
     115     */
     116    if (__predict_false(!__libc_back_fsInfoSupportUnixEAs(pszNativePath)))
     117        LIBCLOG_ERROR_RETURN(-ENOTSUP, "ret -ENOTSUP - no Unix EAs on '%s'\n", pszNativePath);
     118
     119    /*
    114120     * Allocate FEA buffer.
    115121     */
     
    126132    *pFEas = __libc_gFsUnixAttribsCreateSymlinkFEA2List;
    127133    __libc_back_fsUnixAttribsInit(&pFEas->Core, pszNativePath, S_IFLNK | S_IRWXO | S_IRWXG | S_IRWXU);
    128     pFEas->Core.cbList = cchTarget + sizeof(USHORT) * 2;
    129     pFEas->cbSymlinkData = cchTarget;
     134    pFEas->Core.cbList = cchTarget + sizeof(__libc_gFsUnixAttribsCreateSymlinkFEA2List) - 1;
     135    pFEas->cbSymlinkValue += cchTarget;
     136    pFEas->cbSymlinkData  = cchTarget;
    130137    memcpy(pFEas->szSymlink, pszTarget, cchTarget);
    131138
  • branches/libc-0.6/src/emx/src/lib/sys/fs.c

    r2496 r2522  
    637637    LIBCLOG_ENTER("pszUserPath=%p:{%s} pszNativePath=%p *pfInUnixTree=%p\n",
    638638                  (void *)pszUserPath, pszUserPath, (void *)pszNativePath, (void *)pfInUnixTree);
    639     const char *pszUserPathIn = pszUserPath;
    640     char        _achBuffer[SIZEOF_ACHBUFFER + 4];
    641     char       *pachBuffer = (char *)((uintptr_t)&_achBuffer[3] & ~3);
    642     unsigned    cLoopsLeft = 8;
    643     int         fInUnixTree = __libc_gfInUnixTree;
    644     int         rcRet = 0;
    645     HDIR        hDir = HDIR_CREATE;
     639    const char     *pszUserPathIn = pszUserPath;
     640    char            _achBuffer[SIZEOF_ACHBUFFER + 4];
     641    char           *pachBuffer = (char *)((uintptr_t)&_achBuffer[3] & ~3);
     642    unsigned        cLoopsLeft = 8;
     643    int             fInUnixTree = __libc_gfInUnixTree;
     644    int             rcRet = 0;
     645    HDIR            hDir = HDIR_CREATE;
     646    __LIBC_PFSINFO  pFsInfo = NULL;
     647    int             fUnixEAs;
    646648    FS_VAR()
    647649    FS_SAVE_LOAD();
     
    889891            iRoot = psz - pszNativePath;
    890892            psz = strchr(psz, '/');
     893
     894            /* We don't do UNIX EAs on UNCs */
     895            fUnixEAs = 0;
    891896        }
    892897        else
     
    898903            pszPrev = &pszNativePath[iRoot + 1];
    899904            psz = strchr(pszPrev, '/');
     905
     906            /* Unix EAs? */
     907            pFsInfo = __libc_back_fsInfoObjByPathCached(pszNativePath, pFsInfo);
     908            LIBC_ASSERTM(pFsInfo, "%s\n", pszNativePath);
     909            fUnixEAs = pFsInfo ? pFsInfo->fUnixEAs : 0;
    900910        }
    901911        LIBC_ASSERTM(pszPrev - pszNativePath >= iRoot, "iRoot=%d  pszPrev offset %d  pszNativePath=%s\n", iRoot, pszPrev - pszNativePath, pszNativePath);
     
    975985             * This is a little bit messed up since we'll have to use wildcard for
    976986             * getting the casing resolved.
     987             *
     988             * The two find buffers are assumed to be equal down thru attrFile.
    977989             */
    978990            //LIBC_ASSERT(psz - pszNativePath == cchNativePath); - figure this one.
    979             PFILEFINDBUF4 pFindBuf = (PFILEFINDBUF4)pachBuffer;
     991            PFILEFINDBUF4 pFindBuf4 = (PFILEFINDBUF4)pachBuffer;
     992            PFILEFINDBUF3 pFindBuf3 = (PFILEFINDBUF3)pachBuffer;
    980993            ULONG cFiles = 1;
    981994            char chNext = psz[1];
     
    983996            psz[1] = '\0';
    984997            int rc = DosFindFirst((PCSZ)pszNativePath, &hDir, FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY | FILE_ARCHIVED,
    985                                   pFindBuf, SIZEOF_ACHBUFFER, &cFiles, FIL_QUERYEASIZE);
     998                                  pachBuffer, SIZEOF_ACHBUFFER, &cFiles, fUnixEAs ? FIL_QUERYEASIZE : FIL_STANDARD);
    986999            psz[0] = '\0';
    9871000            psz[1] = chNext;
    9881001            if (rc || cFiles == 0)
    9891002                hDir = HDIR_CREATE;
    990             while (!rc && cFiles == 1 && pFindBuf->cchName != psz - pszPrev)
    991                 rc = DosFindNext(hDir, pFindBuf, SIZEOF_ACHBUFFER, &cFiles);
     1003            while (!rc && cFiles == 1 && (fUnixEAs ? pFindBuf4->cchName : pFindBuf3->cchName) != psz - pszPrev)
     1004                rc = DosFindNext(hDir, pachBuffer, SIZEOF_ACHBUFFER, &cFiles);
    9921005            if (rc || cFiles == 0)
    9931006            {
     
    10021015                break;
    10031016            }
    1004             memcpy(pszPrev, pFindBuf->achName, psz - pszPrev);
    1005             int     fIsDirectory = (pFindBuf->attrFile & FILE_DIRECTORY) != 0;
     1017            memcpy(pszPrev, fUnixEAs ? pFindBuf4->achName : pFindBuf3->achName, psz - pszPrev);
     1018            int     fIsDirectory = (pFindBuf4->attrFile & FILE_DIRECTORY) != 0;
    10061019
    10071020            /*
    10081021             * Try querying the symlink EA value.
    1009              * (This operation will reuse the achBuffer overwriting the pFindBuf data!)
     1022             * (This operation will reuse the achBuffer overwriting the pFindBuf[3/4] data!)
    10101023             *
    10111024             * Yeah, we could do this in the same operation as the DosFindFirst() but
     
    10171030             * cases anyway... very nice.
    10181031             */
    1019             if (    pFindBuf->cbList > sizeof(USHORT) * 2 + 1
     1032            if (    fUnixEAs
     1033                &&   pFindBuf4->cbList > sizeof(USHORT) * 2 + 1
    10201034                &&  (   (fFlags & BACKFS_FLAGS_RESOLVE_FULL)
    10211035                     || chSlash)
    1022                 &&  !(pFindBuf->attrFile & FILE_DIRECTORY))
     1036                &&  !(pFindBuf4->attrFile & FILE_DIRECTORY))
    10231037            {
    10241038                PEAOP2  pEaOp2 = (PEAOP2)pachBuffer;
     
    11881202
    11891203    /*
    1190      * Cleanup find handle.
     1204     * Cleanup find handle and fs object.
    11911205     */
    11921206    if (hDir != HDIR_CREATE)
    11931207        DosFindClose(hDir);
     1208    if (pFsInfo)
     1209        __libc_back_fsInfoObjRelease(pFsInfo);
    11941210    FS_RESTORE();
    11951211
     
    15021518    /* init the structure */
    15031519    pFsInfo->fZeroNewBytes = 0;
     1520    pFsInfo->fUnixEAs = 0;
    15041521    pFsInfo->Dev = Dev;
    15051522    pFsInfo->szName[0] = '\0';
     
    15171534    if (    !strcmp(pFsInfo->szName, "JFS")
    15181535        ||  !strcmp(pFsInfo->szName, "HPFS")
    1519         ||  !strcmp(pFsInfo->szName, "FAT")
    1520         ||  !strcmp(pFsInfo->szName, "LAN"))
    1521         pFsInfo->fZeroNewBytes = 1;   /* RAMFS does not do this. */
    1522     LIBCLOG_MSG2("fsInfoObjUpdate: dev:%#x mp:%s fsd:%s fZeroNewBytes=%d\n",
    1523                  pFsInfo->Dev, pFsInfo->szMountpoint, pFsInfo->szName, pFsInfo->fZeroNewBytes);
     1536        ||  !strcmp(pFsInfo->szName, "FAT"))
     1537    {
     1538        pFsInfo->fZeroNewBytes  = 1;
     1539        pFsInfo->fUnixEAs       = 1;
     1540    }
     1541    else if (!strcmp(pFsInfo->szName, "LAN"))
     1542    {
     1543        /* should find a way of getting the remote fs... */
     1544        pFsInfo->fZeroNewBytes  = 1;    /* for performance reasons, assume it zeros. */
     1545        pFsInfo->fUnixEAs       = 0;
     1546    }
     1547    else if (!strcmp(pFsInfo->szName, "RAMFS"))
     1548    {
     1549        pFsInfo->fZeroNewBytes  = 0;
     1550        pFsInfo->fUnixEAs       = 1; /* but it doesn't zero */
     1551    }
     1552    /*else if (!strcmp(pFsInfo->szName, "FAT32"))
     1553    {
     1554        pFsInfo->fZeroNewBytes  = 0;
     1555        pFsInfo->fUnixEAs       = 0;
     1556    }*/
     1557    else
     1558    {
     1559        pFsInfo->fZeroNewBytes  = 0;
     1560        pFsInfo->fUnixEAs       = 0;
     1561    }
     1562
     1563    LIBCLOG_MSG2("fsInfoObjUpdate: dev:%#x mp:%s fsd:%s fZeroNewBytes=%d fUnixEAs=%d\n",
     1564                 pFsInfo->Dev, pFsInfo->szMountpoint, pFsInfo->szName, pFsInfo->fZeroNewBytes,
     1565                 pFsInfo->fUnixEAs);
    15241566    FS_RESTORE();
    15251567}
     
    15591601
    15601602
    1561 #if 0
    15621603/**
    15631604 * Gets the fs info object for the specfied path.
     
    15821623    return __libc_back_fsInfoObjByDev(Dev);
    15831624}
    1584 #endif
     1625
     1626
     1627/**
     1628 * Gets the fs info object for the specfied path, with cache.
     1629 *
     1630 * @returns Pointer to info object for the path, if it got one.
     1631 * @param   pszNativePath   The native path as returned by the resolver.
     1632 * @param   pCached         An cached fs info object reference. Can be NULL.
     1633 */
     1634__LIBC_PFSINFO __libc_back_fsInfoObjByPathCached(const char *pszNativePath, __LIBC_PFSINFO pCached)
     1635{
     1636    /*
     1637     * Calc device.
     1638     */
     1639    dev_t   Dev;
     1640    char    chDrv = *pszNativePath;
     1641    if (chDrv == '/' || chDrv == '\\')
     1642        Dev = makedev('U', 0);          /* U as in UNC */
     1643    else
     1644    {
     1645        LIBC_ASSERT(chDrv >= 'A' && chDrv <= 'Z');
     1646        Dev = makedev('V', chDrv);      /* V as in Volume */
     1647    }
     1648    if (!pCached)
     1649        return __libc_back_fsInfoObjByDev(Dev);
     1650    if (pCached->Dev == Dev)
     1651        return pCached;
     1652    __libc_back_fsInfoObjRelease(pCached);
     1653    return __libc_back_fsInfoObjByDev(Dev);
     1654}
    15851655
    15861656
     
    16171687        LIBC_ASSERT(cRefs > 1); (void)cRefs;
    16181688    }
     1689}
     1690
     1691
     1692/**
     1693 * Checks if the path supports Unix EAs or not.
     1694 *
     1695 * @returns true / false.
     1696 * @param   pszNativePath       The native path to check.
     1697 */
     1698int __libc_back_fsInfoSupportUnixEAs(const char *pszNativePath)
     1699{
     1700    if (__libc_gfNoUnix)
     1701        return 0;
     1702
     1703    __LIBC_PFSINFO pFsInfo = __libc_back_fsInfoObjByPath(pszNativePath);
     1704    const int fUnixEAs = pFsInfo && pFsInfo->fUnixEAs;
     1705    __libc_back_fsInfoObjRelease(pFsInfo);
     1706    return fUnixEAs;
    16191707}
    16201708
Note: See TracChangeset for help on using the changeset viewer.