Changeset 2525 for branches


Ignore:
Timestamp:
Feb 5, 2006, 3:54:47 AM (20 years ago)
Author:
bird
Message:

#41: Calc st_ino and st_dev at the end of the unix attrib getter if they are not present. And added separate file mode mask getter.

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

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/ChangeLog.LIBC

    r2524 r2525  
    1212        o #25: Ensure correct address length returns from recvmsg and recvfrom.
    1313    - libc:
     14        o #41: Calc st_ino and st_dev at the end of the unix attrib getter if they
     15          are not present. And added special file mode mask getter.
    1416        o #40: Fixed double slash preventing root directories from being opened.
    1517        o #23: Fixed two incorrect EA size fields, now creating symlinks really works.
  • branches/libc-0.6/src/emx/src/lib/sys/b_fs.h

    r2522 r2525  
    332332int __libc_back_fsUnixAttribsGet(int hFile, const char *pszNativePath, struct stat *pStat);
    333333
     334/**
     335 * Reads the unix file mode EA.
     336 *
     337 * @returns 0 on success.
     338 * @returns -ENOTSUP if the file mode EA is not present or if Unix EAs isn't supported on the volume.
     339 * @returns Negative errno on failure.
     340 * @param   hFile           File handle to the fs object. If no handle handy, set to -1.
     341 * @param   pszNativePath   Native path to the fs object. If handle is give this will be ignored.
     342 * @param   pMode           Where to store the mode mask.
     343 */
     344int __libc_back_fsUnixAttribsGetMode(int hFile, const char *pszNativePath, mode_t *pMode);
    334345
    335346/**
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsFileModeSetFH.c

    r2522 r2525  
    125125            &&  pFH->pFsInfo->fUnixEAs)
    126126        {
    127             struct stat st = {0};
    128             rc = __libc_back_fsUnixAttribsGet(fh, pFH->pszNativePath, &st);
     127            mode_t CurMode;
     128            rc = __libc_back_fsUnixAttribsGetMode(fh, pFH->pszNativePath, &CurMode);
    129129            if (__predict_true(!rc))
    130130            {
    131131                /* correct the passed in Mode mask. */
    132132                Mode &= ALLPERMS; /** @todo sticky bit and set uid/gid access validation... */
    133                 Mode |= st.st_mode & ~ALLPERMS;
     133                Mode |= CurMode & ~ALLPERMS;
    134134
    135135                /* construct FEA2 stuff. */
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsNativeFileModeSet.c

    r2522 r2525  
    159159    if (fUnixEAs)
    160160    {
    161         struct stat st = {0};
    162         rc = __libc_back_fsUnixAttribsGet(-1, pszNativePath, &st);
     161        mode_t CurMode;
     162        rc = __libc_back_fsUnixAttribsGetMode(-1, pszNativePath, &CurMode);
    163163        if (__predict_true(!rc))
    164164        {
    165165            /* correct the passed in Mode mask. */
    166166            Mode &= ALLPERMS; /** @todo sticky bit and set uid/gid access validation... */
    167             Mode |= st.st_mode & ~ALLPERMS;
     167            Mode |= Mode & ~ALLPERMS;
    168168
    169169            /* construct FEA2 stuff. */
  • branches/libc-0.6/src/emx/src/lib/sys/fs.c

    r2522 r2525  
    137137    0,                         sizeof(EA_FLAGS) - 1,   EA_FLAGS
    138138#undef OFF
     139};
     140#pragma pack()
     141
     142/**
     143 * The prefilled GEA2LIST construct for querying all the mode attribute.
     144 */
     145#pragma pack(1)
     146static const struct
     147{
     148    ULONG   cbList;
     149    ULONG   oNextEntryOffset;
     150    BYTE    cbName;
     151    CHAR    szName[sizeof(EA_MODE)];
     152} gGEA2ListMode =
     153{
     154    sizeof(gGEA2ListMode),
     155    0,
     156    sizeof(EA_MODE) - 1,
     157    EA_MODE
    139158};
    140159#pragma pack()
     
    14661485    }
    14671486
     1487    /*
     1488     * Calc st_ino and st_dev if not found.
     1489     */
     1490    if ((!pStat->st_ino || !pStat->st_dev) && pszNativePath)
     1491    {
     1492        ino_t Inode;
     1493        dev_t Dev = __libc_back_fsPathCalcInodeAndDev(pszNativePath, &Inode);
     1494        if (!pStat->st_ino)
     1495            pStat->st_ino = Inode;
     1496        if (!pStat->st_dev)
     1497            pStat->st_dev = Dev;
     1498    }
     1499
    14681500    LIBCLOG_RETURN_INT(0);
     1501}
     1502
     1503
     1504/**
     1505 * Reads the unix file mode EA.
     1506 *
     1507 * @returns 0 on success.
     1508 * @returns -ENOTSUP if the file mode EA is not present or if Unix EAs isn't supported on the volume.
     1509 * @returns Negative errno on failure.
     1510 * @param   hFile           File handle to the fs object. If no handle handy, set to -1.
     1511 * @param   pszNativePath   Native path to the fs object. If handle is give this will be ignored.
     1512 * @param   pMode           Where to store the mode mask.
     1513 */
     1514int __libc_back_fsUnixAttribsGetMode(int hFile, const char *pszNativePath, mode_t *pMode)
     1515{
     1516     LIBCLOG_ENTER("hFile=%d pszNativePath=%p:{%s} pMode=%p\n", hFile, (void *)pszNativePath, pszNativePath, (void *)pMode);
     1517
     1518     /* Try come up with an accurate max estimate of a maximum result. */
     1519     char    achBuffer[sizeof(EAOP2) + sizeof(FILEFINDBUF3) + sizeof(gGEA2ListMode) + 1 * (sizeof(USHORT) * 2 + sizeof(BYTE)) + 1 * sizeof(uint32_t) + 0x30];
     1520     char   *pachBuffer = (char *)((uintptr_t)&achBuffer[3] & ~3);
     1521     PEAOP2  pEaOp2 = (PEAOP2)pachBuffer;
     1522     int     rc = -1000;
     1523
     1524     *pMode = 0;
     1525
     1526/** @todo the following query is generic! It's repeated 3 times already in this file (only the gea list and buffer size varies). */
     1527     /*
     1528      * Issue the query.
     1529      */
     1530     if (hFile >= 0)
     1531     {
     1532         pEaOp2->fpGEA2List = (PGEA2LIST)&gGEA2ListMode;
     1533         pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1);
     1534         pEaOp2->oError     = 0;
     1535         pEaOp2->fpFEA2List->cbList = sizeof(achBuffer) - 4 - sizeof(EAOP2);
     1536         rc = DosQueryFileInfo(hFile, FIL_QUERYEASFROMLIST, pEaOp2, sizeof(EAOP2));
     1537     }
     1538     if (rc && pszNativePath)
     1539     {
     1540         pEaOp2->fpGEA2List = (PGEA2LIST)&gGEA2ListMode;
     1541         pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1);
     1542         pEaOp2->oError     = 0;
     1543         pEaOp2->fpFEA2List->cbList = sizeof(achBuffer) - 4 - sizeof(EAOP2);
     1544         rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASFROMLIST, pEaOp2, sizeof(EAOP2));
     1545         if (rc == ERROR_SHARING_VIOLATION || rc == ERROR_ACCESS_DENIED || rc == ERROR_INVALID_ACCESS)
     1546         {
     1547             HDIR hDir = HDIR_CREATE;
     1548             ULONG cFiles = 1;
     1549             pEaOp2->fpGEA2List = (PGEA2LIST)&gGEA2ListMode;
     1550             pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1);
     1551             pEaOp2->oError     = 0;
     1552             pEaOp2->fpFEA2List->cbList = sizeof(achBuffer) - 4 - sizeof(EAOP2);
     1553             rc = DosFindFirst((PCSZ)pszNativePath, &hDir, 0, pEaOp2, pEaOp2->fpFEA2List->cbList + sizeof(*pEaOp2), &cFiles, FIL_QUERYEASFROMLIST);
     1554             if (!rc)
     1555             {
     1556                 DosFindClose(hDir);
     1557                 pEaOp2->fpFEA2List = (PFEA2LIST)((char *)pEaOp2 + sizeof(EAOP2) + offsetof(FILEFINDBUF3, cchName));
     1558             }
     1559         }
     1560     }
     1561     if (rc)
     1562     {
     1563         LIBC_ASSERTM(rc == ERROR_ACCESS_DENIED || rc == ERROR_SHARING_VIOLATION || rc == ERROR_EAS_NOT_SUPPORTED,
     1564                      "Bogus EAs? rc=%d oError=%ld\n", rc, pEaOp2->oError);
     1565         rc = -__libc_native2errno(rc);
     1566         LIBCLOG_ERROR_RETURN_INT(rc);
     1567     }
     1568
     1569     /*
     1570      * Parse the result.
     1571      * There is only one EA here, so this is gonna be pretty simple...
     1572      */
     1573     rc = -ENOTSUP;
     1574     PFEA2   pFea2 = &pEaOp2->fpFEA2List->list[0];
     1575     if (   pEaOp2->fpFEA2List->cbList > sizeof(*pFea2)
     1576         && pFea2->cbValue > 0
     1577         && pFea2->cbName == sizeof(EA_MODE) - 1
     1578         && !memcmp(EA_MODE, pFea2->szName, sizeof(EA_MODE) - 1)
     1579        )
     1580     {
     1581         PUSHORT pusType = (PUSHORT)&pFea2->szName[pFea2->cbName + 1];
     1582         if (   pusType[0] == EAT_BINARY
     1583             && pusType[1] == sizeof(uint32_t)
     1584             )
     1585         {
     1586             uint32_t u32 = *(uint32_t *)(pusType + 2);
     1587             *pMode = u32;
     1588             rc = 0;
     1589         }
     1590         else
     1591             LIBC_ASSERTM_FAILED("Invalid LIBC EA! '%s' type=%#x len=%#x, expected type=%#x and len=4.\n",
     1592                                 pFea2->szName, pusType[0], pusType[1], EAT_BINARY);
     1593     }
     1594
     1595     LIBCLOG_RETURN_MSG(rc, "ret %d *pMode=#%x\n", rc, *pMode);
    14691596}
    14701597
Note: See TracChangeset for help on using the changeset viewer.