Changeset 1750


Ignore:
Timestamp:
Dec 21, 2004, 2:38:04 AM (21 years ago)
Author:
bird
Message:

Inode and Dev stuff of stat/lstat/fstat.

Location:
trunk/src/emx
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/emx/io.h

    • Property cvs2svn:cvs-rev changed from 1.13 to 1.14
    r1749 r1750  
    373373    __LIBC_PCFHOPS          pOps;
    374374
     375    /** Device number of the device containing the file.
     376     * The device number is also determined from the path, more correctly the
     377     * driveletter determins this. */
     378    dev_t                   Dev;
     379    /** Inode number of the file.
     380     * Since the inode number is usually calculated from the path we need to
     381     * determin this at handle creation time. */
     382    ino_t                   Inode;
    375383} __LIBC_FH;
    376384/** Pointer to filehandle. */
  • trunk/src/emx/src/lib/sys/__dup.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1749 r1750  
    5757                pFHNew->fFlags      = pFH->fFlags;
    5858                pFHNew->iLookAhead  = pFH->iLookAhead;
     59                pFHNew->Inode       = pFH->Inode;
     60                pFHNew->Dev         = pFH->Dev;
    5961            }
    6062            else
  • trunk/src/emx/src/lib/sys/__dup2.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1749 r1750  
    9090                pFHNew->fFlags      = pFH->fFlags;
    9191                pFHNew->iLookAhead  = pFH->iLookAhead;
     92                pFHNew->Inode       = pFH->Inode;
     93                pFHNew->Dev         = pFH->Dev;
    9294            }
    9395            else
  • trunk/src/emx/src/lib/sys/b_fs.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1749 r1750  
    3131#include <sys/syslimits.h>
    3232#include <sys/types.h>
     33#include <emx/io.h>
    3334#include <InnoTekLIBC/sharedpm.h>
    3435#include "backend.h"
     
    136137/**
    137138 * Creates the unix EAs for a new file or directory.
     139 *
    138140 * @returns 0 on success.
    139141 * @returns Negative errno on failure.
    140142 * @param   hFile           File handle to the newly created fs object. If no
    141143 *                          handle handy, set to -1.
    142  * @param   pszNativePath   Native path of the newly created fs object. If
    143  *                          handle is give this will be ignored.
     144 * @param   pszNativePath   Native path to the newly created fs object.
    144145 * @param   mode            The specified file permission mode mask.
    145  */
    146 int __libc_back_fsUnixAttribsSet(int hFile, const char *pszNativePath, mode_t mode);
     146 * @param   pDev            Where to store the dev number.
     147 * @param   pInode          Where to store the calculated inode number.
     148 */
     149int __libc_back_fsUnixAttribsSet(int hFile, const char *pszNativePath, mode_t mode, dev_t *pDev, ino_t *pInode);
    147150
    148151/**
     
    197200int __libc_back_fsNativeFileStat(const char *pszNativePath, struct stat *pStat);
    198201
     202/**
     203 * Calc the Inode and Dev based on native path.
     204 *
     205 * @returns device number and *pInode.
     206 *
     207 * @param   pszNativePath       Pointer to native path.
     208 * @param   pInode              Where to store the inode number.
     209 * @remark  This doesn't work right when in non-unix mode!
     210 */
     211dev_t __libc_back_fsPathCalcInodeAndDev(const char *pszNativePath, ino_t *pInode);
     212
    199213
    200214__END_DECLS
  • trunk/src/emx/src/lib/sys/b_fsDirCreate.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1749 r1750  
    7171    if (!rc)
    7272    {
    73         __libc_back_fsUnixAttribsSet(-1, &szNativePath[0], Mode);
     73        __libc_back_fsUnixAttribsSet(-1, &szNativePath[0], Mode, NULL, NULL);
    7474        LIBCLOG_RETURN_INT(0);
    7575    }
  • trunk/src/emx/src/lib/sys/b_fsFileStatFH.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1749 r1750  
    9393        pStat->st_uid = 0;
    9494        pStat->st_gid = 0;
    95         pStat->st_ino = _sys_ino++;
    96         if (_sys_ino == 0)
    97             _sys_ino = 1;
    98         pStat->st_dev = 0;
     95        pStat->st_ino = pFH->Inode;
     96        pStat->st_dev = pFH->Dev;
    9997        pStat->st_rdev = 0;
    10098        pStat->st_nlink = 1;
  • trunk/src/emx/src/lib/sys/b_fsNativeFileStat.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1749 r1750  
    188188    pStat->st_uid = 0;
    189189    pStat->st_gid = 0;
    190     pStat->st_ino = _sys_ino++;
    191     if (_sys_ino == 0)
    192         _sys_ino = 1;
    193     pStat->st_dev = 0;
     190    pStat->st_dev = __libc_back_fsPathCalcInodeAndDev(pszNativePath, &pStat->st_ino);
    194191    pStat->st_rdev = 0;
    195192    pStat->st_nlink = 1;
  • trunk/src/emx/src/lib/sys/b_ioFileOpen.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1749 r1750  
    174174        ULONG   fulType;
    175175        ULONG   fulDevFlags;
     176        dev_t   Dev;
     177        ino_t   Inode;
    176178
    177179        /*
     
    180182        if (   (ulAction == FILE_CREATED)
    181183            && !__libc_gfNoUnix)
    182             __libc_back_fsUnixAttribsSet(hFile, NULL, Mode);
     184            __libc_back_fsUnixAttribsSet(hFile, pszFile, Mode, &Dev, &Inode);
     185        else
     186            Dev = __libc_back_fsPathCalcInodeAndDev(szNativePath, &(*ppFH)->Inode);
     187
    183188
    184189        /*
     
    203208
    204209            /*
    205              * Register the handle.
     210             * Register the handle and calc Dev and Inode.
     211             * We calc the Dev/Inode regardless of whether it's stored in an EA or not.
    206212             */
    207213            rc = __libc_FHAllocate(hFile, fLibc, sizeof(LIBCFH), NULL, ppFH, NULL);
    208             LIBCLOG_MSG("hFile=%#lx fLibc=%#x fulType=%#lx ulAction=%lu\n",
    209                         hFile, fLibc, fulType, ulAction);
     214            if (!rc)
     215            {
     216                if (ppFH)
     217                {
     218                    (*ppFH)->Dev = Dev;
     219                    (*ppFH)->Inode = Inode;
     220                }
     221                LIBCLOG_MSG("hFile=%#lx fLibc=%#x fulType=%#lx ulAction=%lu Dev=%#x Inode=%#llx\n",
     222                            hFile, fLibc, fulType, ulAction, Dev, Inode);
     223            }
    210224        }
    211225
  • trunk/src/emx/src/lib/sys/filehandles.c

    • Property cvs2svn:cvs-rev changed from 1.16 to 1.17
    r1749 r1750  
    735735        pFH->iLookAhead = -1;
    736736        pFH->pOps       = pOps;
     737        pFH->Inode      = ++_sys_ino;
     738        if (!pFH->Inode)
     739            pFH->Inode  = ++_sys_ino;
     740        pFH->Dev        = 0;
    737741
    738742        /*
  • trunk/src/emx/src/lib/sys/fs.c

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r1749 r1750  
    187187*******************************************************************************/
    188188static int fsResolveUnix(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree);
     189static uint32_t crc32str(const char *psz);
     190static uint32_t djb2(const char *str);
     191static uint32_t sdbm(const char *str);
    189192
    190193
     
    12341237/**
    12351238 * Creates the unix EAs for a new file or directory.
     1239 *
    12361240 * @returns 0 on success.
    12371241 * @returns Negative errno on failure.
    12381242 * @param   hFile           File handle to the newly created fs object. If no
    12391243 *                          handle handy, set to -1.
    1240  * @param   pszNativePath   Native path to the newly created fs object. If
    1241  *                          handle is give this will be ignored.
     1244 * @param   pszNativePath   Native path to the newly created fs object.
    12421245 * @param   mode            The specified file permission mode mask.
     1246 * @param   pDev            Where to store the dev number.
     1247 * @param   pInode          Where to store the calculated inode number.
    12431248 */
    1244 int __libc_back_fsUnixAttribsSet(int hFile, const char *pszNativePath, mode_t mode)
    1245 {
    1246     /* later */
     1249int __libc_back_fsUnixAttribsSet(int hFile, const char *pszNativePath, mode_t mode, dev_t *pDev, ino_t *pInode)
     1250{
     1251    /*
     1252     * Calc device.
     1253     */
     1254    dev_t   Dev;
     1255    char    chDrv = *pszNativePath;
     1256    if (chDrv == '/' || chDrv == '\\')
     1257        Dev = makedev('U', 0);          /* U as in UNC */
     1258    else
     1259    {
     1260        /* ASSUMES that pszNativePath contains a driveletter! If not fix the resolver!!! */
     1261        if (chDrv >= 'a' && chDrv <= 'z')
     1262            chDrv -= 'a' - 'A';
     1263        Dev = makedev('V', chDrv);      /* V as in Volume */
     1264    }
     1265
     1266    /*
     1267     * Calc Inode number.
     1268     *
     1269     * Whether to use another hash algorithm here is a bit in the blue now
     1270     * because the stored value might be inaccessible at times.
     1271     */
     1272    const char *psz = pszNativePath;
     1273    if (psz[1] == ':')
     1274        psz += 2;
     1275    ino_t Inode = ((uint64_t)crc32str(psz) << 32) | (uint64_t)djb2(psz);
     1276
     1277    /** @todo Save unix EAs! */
     1278    if (pDev)
     1279        *pDev = Dev;
     1280    if (pInode)
     1281        *pInode = (Inode & 0xffffffff00000000ULL) | (uint64_t)sdbm(psz);
    12471282    return 0;
    12481283}
     1284
    12491285
    12501286/**
     
    13391375
    13401376
     1377/**
     1378 * Calc the Inode and Dev based on native path.
     1379 *
     1380 * @returns device number and *pInode.
     1381 *
     1382 * @param   pszNativePath       Pointer to native path.
     1383 * @param   pInode              Where to store the inode number.
     1384 * @remark  This doesn't work right when in non-unix mode!
     1385 */
     1386dev_t __libc_back_fsPathCalcInodeAndDev(const char *pszNativePath, ino_t *pInode)
     1387{
     1388    /*
     1389     * Calc device.
     1390     */
     1391    dev_t   Dev;
     1392    char    chDrv = *pszNativePath;
     1393    if (chDrv == '/' || chDrv == '\\')
     1394        Dev = makedev('U', 0);          /* U as in UNC */
     1395    else
     1396    {
     1397        /* ASSUMES that pszNativePath contains a driveletter! If not fix the resolver!!! */
     1398        if (chDrv >= 'a' && chDrv <= 'z')
     1399            chDrv -= 'a' - 'A';
     1400        Dev = makedev('V', chDrv);      /* V as in Volume */
     1401    }
     1402
     1403    /*
     1404     * Calc Inode number.
     1405     */
     1406    const char *psz = pszNativePath;
     1407    if (psz[1] == ':')
     1408        psz += 2;
     1409    *pInode = ((uint64_t)crc32str(psz) << 32) | (uint64_t)sdbm(psz);
     1410    return Dev;
     1411}
     1412
     1413
     1414/* djb2:
     1415  This algorithm (k=33) was first reported by dan bernstein many years ago in
     1416  comp.lang.c. Another version of this algorithm (now favored by bernstein) uses
     1417  xor: hash(i) = hash(i - 1) * 33 ^ str[i]; the magic of number 33 (why it
     1418  works better than many other constants, prime or not) has never been
     1419  adequately explained. */
     1420
     1421static uint32_t djb2(const char *str)
     1422{
     1423    uint32_t hash = 5381;
     1424    int c;
     1425
     1426    while ((c = *(unsigned const char *)str++))
     1427        hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     1428
     1429    return hash;
     1430}
     1431
     1432/* sdbm:
     1433   This algorithm was created for sdbm (a public-domain reimplementation of
     1434   ndbm) database library. it was found to do well in scrambling bits,
     1435   causing better distribution of the keys and fewer splits. it also happens
     1436   to be a good general hashing function with good distribution. the actual
     1437   function is hash(i) = hash(i - 1) * 65599 + str[i]; what is included below
     1438   is the faster version used in gawk. [there is even a faster, duff-device
     1439   version] the magic constant 65599 was picked out of thin air while
     1440   experimenting with different constants, and turns out to be a prime.
     1441   this is one of the algorithms used in berkeley db (see sleepycat) and
     1442   elsewhere. */
     1443static uint32_t sdbm(const char *str)
     1444{
     1445    uint32_t hash = 0;
     1446    int c;
     1447
     1448    while ((c = *(unsigned const char *)str++))
     1449        hash = c + (hash << 6) + (hash << 16) - hash;
     1450
     1451    return hash;
     1452}
     1453
     1454/*-
     1455 *  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or
     1456 *  code or tables extracted from it, as desired without restriction.
     1457 *
     1458 *  First, the polynomial itself and its table of feedback terms.  The
     1459 *  polynomial is
     1460 *  X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
     1461 *
     1462 *  Note that we take it "backwards" and put the highest-order term in
     1463 *  the lowest-order bit.  The X^32 term is "implied"; the LSB is the
     1464 *  X^31 term, etc.  The X^0 term (usually shown as "+1") results in
     1465 *  the MSB being 1
     1466 *
     1467 *  Note that the usual hardware shift register implementation, which
     1468 *  is what we're using (we're merely optimizing it by doing eight-bit
     1469 *  chunks at a time) shifts bits into the lowest-order term.  In our
     1470 *  implementation, that means shifting towards the right.  Why do we
     1471 *  do it this way?  Because the calculated CRC must be transmitted in
     1472 *  order from highest-order term to lowest-order term.  UARTs transmit
     1473 *  characters in order from LSB to MSB.  By storing the CRC this way
     1474 *  we hand it to the UART in the order low-byte to high-byte; the UART
     1475 *  sends each low-bit to hight-bit; and the result is transmission bit
     1476 *  by bit from highest- to lowest-order term without requiring any bit
     1477 *  shuffling on our part.  Reception works similarly
     1478 *
     1479 *  The feedback terms table consists of 256, 32-bit entries.  Notes
     1480 *
     1481 *      The table can be generated at runtime if desired; code to do so
     1482 *      is shown later.  It might not be obvious, but the feedback
     1483 *      terms simply represent the results of eight shift/xor opera
     1484 *      tions for all combinations of data and CRC register values
     1485 *
     1486 *      The values must be right-shifted by eight bits by the "updcrc
     1487 *      logic; the shift must be unsigned (bring in zeroes).  On some
     1488 *      hardware you could probably optimize the shift in assembler by
     1489 *      using byte-swap instructions
     1490 *      polynomial $edb88320
     1491 *
     1492 *
     1493 * CRC32 code derived from work by Gary S. Brown.
     1494 */
     1495
     1496#include <sys/cdefs.h>
     1497__FBSDID("$FreeBSD: src/sys/libkern/crc32.c,v 1.2 2003/06/11 05:23:04 obrien Exp $");
     1498
     1499#include <sys/param.h>
     1500/* #include <sys/systm.h> */
     1501
     1502static const uint32_t crc32_tab[] = {
     1503        0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
     1504        0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
     1505        0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
     1506        0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
     1507        0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
     1508        0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
     1509        0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
     1510        0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
     1511        0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
     1512        0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
     1513        0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
     1514        0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
     1515        0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
     1516        0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
     1517        0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
     1518        0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
     1519        0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
     1520        0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
     1521        0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
     1522        0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
     1523        0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
     1524        0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
     1525        0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
     1526        0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
     1527        0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
     1528        0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
     1529        0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
     1530        0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
     1531        0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
     1532        0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
     1533        0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
     1534        0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
     1535        0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
     1536        0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
     1537        0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
     1538        0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
     1539        0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
     1540        0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
     1541        0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
     1542        0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
     1543        0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
     1544        0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
     1545        0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
     1546};
     1547
     1548static uint32_t
     1549crc32str(const char *psz)
     1550{
     1551        const uint8_t *p;
     1552        uint32_t crc;
     1553
     1554        p = (const uint8_t *)psz;
     1555        crc = ~0U;
     1556
     1557        while (*p)
     1558                crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
     1559
     1560        return crc ^ ~0U;
     1561}
     1562
Note: See TracChangeset for help on using the changeset viewer.