VirtualBox

Changeset 2856 in kBuild


Ignore:
Timestamp:
Sep 1, 2016 2:42:08 AM (9 years ago)
Author:
bird
Message:

updates

Location:
trunk/src
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/Makefile.kmk

    r2845 r2856  
    221221        commands.c \
    222222        default.c \
    223         dir.c \
    224223        expand.c \
    225224        file.c \
     
    242241        kbuild.c \
    243242        kbuild-object.c
     243ifeq ($(KBUILD_TARGET),win)
     244 kmk_SOURCES += dir-nt-bird.c
     245else
     246 kmk_SOURCES += dir.c
     247endif
    244248
    245249kmk_SOURCES.win = \
  • trunk/src/kmk/kmkbuiltin/kDepIDB.c

    r2413 r2856  
    4242# include <io.h>
    4343#endif
    44 #include "../../lib/k/kDefs.h"
    45 #include "../../lib/k/kTypes.h"
    46 #include "../../lib/kDep.h"
     44#include "k/kDefs.h"
     45#include "k/kTypes.h"
     46#include "kDep.h"
    4747#include "kmkbuiltin.h"
    4848
  • trunk/src/kmk/kmkbuiltin/kDepObj.c

    r2804 r2856  
    4444# include <io.h>
    4545#endif
    46 #include "../../lib/k/kDefs.h"
    47 #include "../../lib/k/kTypes.h"
    48 #include "../../lib/k/kLdrFmts/pe.h"
    49 #include "../../lib/kDep.h"
     46#include "k/kDefs.h"
     47#include "k/kTypes.h"
     48#include "k/kLdrFmts/pe.h"
     49#include "kDep.h"
    5050#include "kmkbuiltin.h"
    5151
  • trunk/src/lib/Makefile.kmk

    r2854 r2856  
    5151       nt/ntstat.c \
    5252       nt/ntunlink.c \
    53        nt/kFsCache.c
     53       nt/kFsCache.c \
     54       kStuff/kHlp/CRT/kHlpCRTString.cpp \
     55       kStuff/kHlp/CRT/kHlpCRTAlloc.cpp
    5456kUtil_SOURCES.solaris = \
    5557        restartable-syscall-wrappers.c
  • trunk/src/lib/nt/kFsCache.c

    r2855 r2856  
    652652        pCache->cbObjects += 16 * sizeof(pParent->papChildren[0]);
    653653    }
    654     pParent->papChildren[pParent->cChildren++] = pChild;
     654    pParent->papChildren[pParent->cChildren++] = kFsCacheObjRetainInternal(pChild);
    655655    return K_TRUE;
    656656}
     
    688688     * Allocate the object.
    689689     */
    690     KBOOL const fDirish = bObjType != KFSOBJ_TYPE_FILE && bObjType == KFSOBJ_TYPE_OTHER;
    691     KSIZE const cbObj   = (fDirish ? sizeof(KFSDIR) : sizeof(KFSOBJ))
    692                         + (cwcName + 1) * sizeof(wchar_t)                           + cchName + 1
     690    KBOOL const fDirish = bObjType != KFSOBJ_TYPE_FILE && bObjType != KFSOBJ_TYPE_OTHER;
     691    KSIZE const cbObj   = fDirish ? sizeof(KFSDIR) : sizeof(KFSOBJ);
     692    KSIZE const cbNames = (cwcName + 1) * sizeof(wchar_t)                           + cchName + 1
    693693#ifdef KFSCACHE_CFG_SHORT_NAMES
    694694                        + (cwcShortName > 0 ? (cwcShortName + 1) * sizeof(wchar_t)  + cchShortName + 1 : 0)
     
    698698    kHlpAssert(pCache->u32Magic == KFSCACHE_MAGIC);
    699699
    700     pObj = (PKFSOBJ)kHlpAlloc(cbObj);
     700    pObj = (PKFSOBJ)kHlpAlloc(cbObj + cbNames);
    701701    if (pObj)
    702702    {
    703         KU8 *pbExtra = (KU8 *)(pObj + 1);
    704 
    705         pCache->cbObjects += cbObj;
     703        KU8 *pbExtra = (KU8 *)pObj + cbObj;
     704
     705        pCache->cbObjects += cbObj + cbNames;
    706706        pCache->cObjects++;
    707707
     
    723723        pObj->cwcParent = pParent->Obj.cwcParent + pParent->Obj.cwcName + !!pParent->Obj.cwcName;
    724724        pObj->pwszName  = (wchar_t *)kHlpMemCopy(pbExtra, pwszName, cwcName * sizeof(wchar_t));
     725        pObj->cwcName   = cwcName;
    725726        pbExtra += cwcName * sizeof(wchar_t);
    726727        *pbExtra++ = '\0';
     
    731732        {
    732733            pObj->pwszShortName = (wchar_t *)kHlpMemCopy(pbExtra, pwszShortName, cwcShortName * sizeof(wchar_t));
     734            pObj->cwcShortName  = cwcShortName;
    733735            pbExtra += cwcShortName * sizeof(wchar_t);
    734736            *pbExtra++ = '\0';
     
    738740        {
    739741            pObj->pwszShortName = pObj->pwszName;
    740             pObj->cwcShortName  = pObj->cwcName;
     742            pObj->cwcShortName  = cwcName;
    741743        }
    742744# endif
     
    744746        pObj->cchParent = pParent->Obj.cchParent + pParent->Obj.cchName + !!pParent->Obj.cchName;
    745747        pObj->pszName   = (char *)kHlpMemCopy(pbExtra, pszName, cchName);
     748        pObj->cchName   = cchName;
    746749        pbExtra += cchName;
    747750        *pbExtra++ = '\0';
     
    751754        {
    752755            pObj->pszShortName = (char *)kHlpMemCopy(pbExtra, pszShortName, cchShortName);
     756            pObj->cchShortName = cchShortName;
    753757            pbExtra += cchShortName;
    754758            *pbExtra++ = '\0';
     
    757761        {
    758762            pObj->pszShortName = pObj->pszName;
    759             pObj->cchShortName = pObj->cchName;
     763            pObj->cchShortName = cchName;
    760764        }
    761765#endif
     
    10871091#endif
    10881092            pCur->Stats.st_dev = pDir->uDevNo;
     1093            pCur->fHaveStats   = K_TRUE;
    10891094
    10901095            /*
     
    11371142
    11381143    if (rcNt == MY_STATUS_NO_MORE_FILES)
     1144    {
     1145        /*
     1146         * Mark the directory as fully populated and up to date.
     1147         */
     1148        pDir->fPopulated = K_TRUE;
     1149        if (pDir->Obj.uCacheGen != KFSOBJ_CACHE_GEN_IGNORE)
     1150            pDir->Obj.uCacheGen = pCache->uGeneration;
    11391151        return K_TRUE;
     1152    }
     1153
    11401154    kHlpAssertMsgFailed(("%#x\n", rcNt));
    11411155    *penmError = KFSLOOKUPERROR_DIR_READ_ERROR;
     
    12661280                pDir->hDir = hDir;
    12671281
    1268                 /* Get the device number. */
    1269                 rcNt = birdQueryVolumeDeviceNumber(hDir, &uBuf.VolInfo, sizeof(uBuf), &pDir->uDevNo);
    1270                 kHlpAssertMsg(MY_NT_SUCCESS(rcNt), ("%#x\n", rcNt));
     1282                if (birdStatHandle(hDir, &pDir->Obj.Stats, pDir->Obj.pszName) == 0)
     1283                {
     1284                    pDir->Obj.fHaveStats = K_TRUE;
     1285                    pDir->uDevNo = pDir->Obj.Stats.st_dev;
     1286                }
     1287                else
     1288                {
     1289                    /* Just in case. */
     1290                    pDir->Obj.fHaveStats = K_FALSE;
     1291                    rcNt = birdQueryVolumeDeviceNumber(hDir, &uBuf.VolInfo, sizeof(uBuf), &pDir->uDevNo);
     1292                    kHlpAssertMsg(MY_NT_SUCCESS(rcNt), ("%#x\n", rcNt));
     1293                }
    12711294
    12721295                /* Get the file system. */
     
    15981621
    15991622/**
    1600  * Walk the file system tree for the given absolute path, entering it into the
    1601  * hash table.
     1623 * Walks an full path relative to the given directory, ANSI version.
    16021624 *
    16031625 * This will create any missing nodes while walking.
     
    16081630 *          NULL on lookup failure, see @a penmError for details.
    16091631 * @param   pCache              The cache.
     1632 * @param   pParent             The directory to start the lookup in.
    16101633 * @param   pszPath             The path to walk.
    16111634 * @param   cchPath             The length of the path.
     
    16131636 *                              failed.
    16141637 */
    1615 static PKFSOBJ kFsCacheLookupAbsoluteA(PKFSCACHE pCache, const char *pszPath, KU32 cchPath, KFSLOOKUPERROR *penmError)
    1616 {
    1617     PKFSDIR     pParent = &pCache->RootDir;
    1618     PKFSOBJ     pChild;
    1619     KU32        off;
    1620     KU32        cchSlashes;
    1621     KU32        offEnd;
    1622 
    1623     KFSCACHE_LOG(("kFsCacheLookupAbsoluteA(%s)\n", pszPath));
    1624 
    1625     /*
    1626      * The root "directory" needs special handling, so we keep it outside the
    1627      * main search loop. (Special: Cannot enumerate it, UNCs, ++.)
    1628      */
    1629     cchSlashes = 0;
    1630     off        = 0;
    1631     if (   pszPath[1] == ':'
    1632         && IS_ALPHA(pszPath[0]))
    1633     {
    1634         /* Drive letter. */
    1635         offEnd = 2;
    1636         kHlpAssert(IS_SLASH(pszPath[2]));
    1637         pChild = kFswCacheLookupDrive(pCache, toupper(pszPath[0]), penmError);
    1638     }
    1639     else if (   IS_SLASH(pszPath[0])
    1640              && IS_SLASH(pszPath[1]) )
    1641         pChild = kFswCacheLookupUncShareA(pCache, pszPath, &offEnd, penmError);
    1642     else
    1643     {
    1644         *penmError = KFSLOOKUPERROR_UNSUPPORTED;
    1645         return NULL;
    1646     }
    1647     if (pChild)
    1648     { /* likely */ }
    1649     else
    1650         return NULL;
    1651 
    1652     /* Count slashes trailing the root spec. */
    1653     if (offEnd < cchPath)
    1654     {
    1655         kHlpAssert(IS_SLASH(pszPath[offEnd]));
    1656         do
    1657             cchSlashes++;
    1658         while (IS_SLASH(pszPath[offEnd + cchSlashes]));
    1659     }
    1660 
    1661     /* Done already? */
    1662     if (offEnd >= cchPath)
    1663     {
    1664         if (   pChild->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE
    1665             || pChild->uCacheGen == (pChild->bObjType != KFSOBJ_TYPE_MISSING ? pCache->uGeneration : pCache->uGenerationMissing)
    1666             || kFsCacheRefreshObj(pCache, pChild, penmError))
    1667             return kFsCacheObjRetainInternal(pChild);
    1668         return NULL;
    1669     }
    1670 
    1671     /* Check that we've got a valid result and not a cached negative one. */
    1672     if (pChild->bObjType == KFSOBJ_TYPE_DIR)
    1673     { /* likely */ }
    1674     else
    1675     {
    1676         kHlpAssert(pChild->bObjType == KFSOBJ_TYPE_MISSING);
    1677         kHlpAssert(pChild->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE || pChild->uCacheGen == pCache->uGenerationMissing);
    1678         return pChild;
    1679     }
    1680 
    1681     /* Next component. */
    1682     pParent = (PKFSDIR)pChild;
    1683     off     = offEnd + cchSlashes;
    1684 
    1685 
     1638PKFSOBJ kFsCacheLookupRelativeToDirA(PKFSCACHE pCache, PKFSDIR pParent, const char *pszPath, KU32 cchPath,
     1639                                     KFSLOOKUPERROR *penmError)
     1640{
    16861641    /*
    16871642     * Walk loop.
    16881643     */
     1644    KU32 off = 0;
    16891645    for (;;)
    16901646    {
     1647        PKFSOBJ pChild;
     1648
    16911649        /*
    16921650         * Find the end of the component, counting trailing slashes.
    16931651         */
    1694         char ch;
    1695         cchSlashes = 0;
    1696         offEnd     = off + 1;
     1652        char    ch;
     1653        KU32    cchSlashes = 0;
     1654        KU32    offEnd     = off + 1;
    16971655        while ((ch = pszPath[offEnd]) != '\0')
    16981656        {
     
    17361694            {
    17371695                if (pChild)
    1738                     return pChild;
     1696                    return kFsCacheObjRetainInternal(pChild);
    17391697                *penmError = KFSLOOKUPERROR_NOT_FOUND;
    17401698            }
     
    17561714            else
    17571715                return NULL;
    1758             return pChild;
     1716            return kFsCacheObjRetainInternal(pChild);
    17591717        }
    17601718
     
    17831741
    17841742    return NULL;
    1785 }
    1786 
    1787 
    1788 /**
    1789  * Walk the file system tree for the given absolute path, UTF-16 version.
     1743
     1744}
     1745
     1746
     1747/**
     1748 * Walks an full path relative to the given directory, UTF-16 version.
    17901749 *
    17911750 * This will create any missing nodes while walking.
     
    17961755 *          NULL on lookup failure, see @a penmError for details.
    17971756 * @param   pCache              The cache.
    1798  * @param   pwszPath            The path to walk.
    1799  * @param   cwcPath             The length of the path (in wchar_t's).
     1757 * @param   pParent             The directory to start the lookup in.
     1758 * @param   pszPath             The path to walk.  No dot-dot bits allowed!
     1759 * @param   cchPath             The length of the path.
    18001760 * @param   penmError           Where to return details as to why the lookup
    18011761 *                              failed.
    18021762 */
    1803 static PKFSOBJ kFsCacheLookupAbsoluteW(PKFSCACHE pCache, const wchar_t *pwszPath, KU32 cwcPath, KFSLOOKUPERROR *penmError)
    1804 {
    1805     PKFSDIR     pParent = &pCache->RootDir;
    1806     PKFSOBJ     pChild;
    1807     KU32        off;
    1808     KU32        cwcSlashes;
    1809     KU32        offEnd;
    1810 
    1811     KFSCACHE_LOG(("kFsCacheLookupAbsoluteW(%ls)\n", pwszPath));
    1812 
    1813     /*
    1814      * The root "directory" needs special handling, so we keep it outside the
    1815      * main search loop. (Special: Cannot enumerate it, UNCs, ++.)
    1816      */
    1817     cwcSlashes = 0;
    1818     off        = 0;
    1819     if (   pwszPath[1] == ':'
    1820         && IS_ALPHA(pwszPath[0]))
    1821     {
    1822         /* Drive letter. */
    1823         offEnd = 2;
    1824         kHlpAssert(IS_SLASH(pwszPath[2]));
    1825         pChild = kFswCacheLookupDrive(pCache, toupper(pwszPath[0]), penmError);
    1826     }
    1827     else if (   IS_SLASH(pwszPath[0])
    1828              && IS_SLASH(pwszPath[1]) )
    1829         pChild = kFswCacheLookupUncShareW(pCache, pwszPath, &offEnd, penmError);
    1830     else
    1831     {
    1832         *penmError = KFSLOOKUPERROR_UNSUPPORTED;
    1833         return NULL;
    1834     }
    1835     if (pChild)
    1836     { /* likely */ }
    1837     else
    1838         return NULL;
    1839 
    1840     /* Count slashes trailing the root spec. */
    1841     if (offEnd < cwcPath)
    1842     {
    1843         kHlpAssert(IS_SLASH(pwszPath[offEnd]));
    1844         do
    1845             cwcSlashes++;
    1846         while (IS_SLASH(pwszPath[offEnd + cwcSlashes]));
    1847     }
    1848 
    1849     /* Done already? */
    1850     if (offEnd >= cwcPath)
    1851     {
    1852         if (   pChild->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE
    1853             || pChild->uCacheGen == (pChild->bObjType != KFSOBJ_TYPE_MISSING ? pCache->uGeneration : pCache->uGenerationMissing)
    1854             || kFsCacheRefreshObj(pCache, pChild, penmError))
    1855             return kFsCacheObjRetainInternal(pChild);
    1856         return NULL;
    1857     }
    1858 
    1859     /* Check that we've got a valid result and not a cached negative one. */
    1860     if (pChild->bObjType == KFSOBJ_TYPE_DIR)
    1861     { /* likely */ }
    1862     else
    1863     {
    1864         kHlpAssert(pChild->bObjType == KFSOBJ_TYPE_MISSING);
    1865         kHlpAssert(pChild->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE || pChild->uCacheGen == pCache->uGenerationMissing);
    1866         return pChild;
    1867     }
    1868 
    1869     /* Next component. */
    1870     pParent = (PKFSDIR)pChild;
    1871     off     = offEnd + cwcSlashes;
    1872 
    1873 
     1763PKFSOBJ kFsCacheLookupRelativeToDirW(PKFSCACHE pCache, PKFSDIR pParent, const wchar_t *pwszPath, KU32 cwcPath,
     1764                                     KFSLOOKUPERROR *penmError)
     1765{
    18741766    /*
    18751767     * Walk loop.
    18761768     */
     1769    KU32 off = 0;
    18771770    for (;;)
    18781771    {
     1772        PKFSOBJ pChild;
     1773
    18791774        /*
    18801775         * Find the end of the component, counting trailing slashes.
    18811776         */
    18821777        wchar_t wc;
    1883         cwcSlashes = 0;
    1884         offEnd     = off + 1;
     1778        KU32    cwcSlashes = 0;
     1779        KU32    offEnd     = off + 1;
    18851780        while ((wc = pwszPath[offEnd]) != '\0')
    18861781        {
     
    19241819            {
    19251820                if (pChild)
    1926                     return pChild;
     1821                    return kFsCacheObjRetainInternal(pChild);
    19271822                *penmError = KFSLOOKUPERROR_NOT_FOUND;
    19281823            }
     
    19441839            else
    19451840                return NULL;
    1946             return pChild;
     1841            return kFsCacheObjRetainInternal(pChild);
    19471842        }
    19481843
     
    19711866
    19721867    return NULL;
     1868
     1869}
     1870
     1871/**
     1872 * Walk the file system tree for the given absolute path, entering it into the
     1873 * hash table.
     1874 *
     1875 * This will create any missing nodes while walking.
     1876 *
     1877 * The caller will have to do the path hash table insertion of the result.
     1878 *
     1879 * @returns Pointer to the tree node corresponding to @a pszPath.
     1880 *          NULL on lookup failure, see @a penmError for details.
     1881 * @param   pCache              The cache.
     1882 * @param   pszPath             The path to walk. No dot-dot bits allowed!
     1883 * @param   cchPath             The length of the path.
     1884 * @param   penmError           Where to return details as to why the lookup
     1885 *                              failed.
     1886 */
     1887static PKFSOBJ kFsCacheLookupAbsoluteA(PKFSCACHE pCache, const char *pszPath, KU32 cchPath, KFSLOOKUPERROR *penmError)
     1888{
     1889    PKFSOBJ     pChild;
     1890    KU32        cchSlashes;
     1891    KU32        offEnd;
     1892
     1893    KFSCACHE_LOG(("kFsCacheLookupAbsoluteA(%s)\n", pszPath));
     1894
     1895    /*
     1896     * The root "directory" needs special handling, so we keep it outside the
     1897     * main search loop. (Special: Cannot enumerate it, UNCs, ++.)
     1898     */
     1899    cchSlashes = 0;
     1900    if (   pszPath[1] == ':'
     1901        && IS_ALPHA(pszPath[0]))
     1902    {
     1903        /* Drive letter. */
     1904        offEnd = 2;
     1905        kHlpAssert(IS_SLASH(pszPath[2]));
     1906        pChild = kFswCacheLookupDrive(pCache, toupper(pszPath[0]), penmError);
     1907    }
     1908    else if (   IS_SLASH(pszPath[0])
     1909             && IS_SLASH(pszPath[1]) )
     1910        pChild = kFswCacheLookupUncShareA(pCache, pszPath, &offEnd, penmError);
     1911    else
     1912    {
     1913        *penmError = KFSLOOKUPERROR_UNSUPPORTED;
     1914        return NULL;
     1915    }
     1916    if (pChild)
     1917    { /* likely */ }
     1918    else
     1919        return NULL;
     1920
     1921    /* Count slashes trailing the root spec. */
     1922    if (offEnd < cchPath)
     1923    {
     1924        kHlpAssert(IS_SLASH(pszPath[offEnd]));
     1925        do
     1926            cchSlashes++;
     1927        while (IS_SLASH(pszPath[offEnd + cchSlashes]));
     1928    }
     1929
     1930    /* Done already? */
     1931    if (offEnd >= cchPath)
     1932    {
     1933        if (   pChild->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE
     1934            || pChild->uCacheGen == (pChild->bObjType != KFSOBJ_TYPE_MISSING ? pCache->uGeneration : pCache->uGenerationMissing)
     1935            || kFsCacheRefreshObj(pCache, pChild, penmError))
     1936            return kFsCacheObjRetainInternal(pChild);
     1937        return NULL;
     1938    }
     1939
     1940    /* Check that we've got a valid result and not a cached negative one. */
     1941    if (pChild->bObjType == KFSOBJ_TYPE_DIR)
     1942    { /* likely */ }
     1943    else
     1944    {
     1945        kHlpAssert(pChild->bObjType == KFSOBJ_TYPE_MISSING);
     1946        kHlpAssert(pChild->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE || pChild->uCacheGen == pCache->uGenerationMissing);
     1947        return pChild;
     1948    }
     1949
     1950    /*
     1951     * Now that we've found a valid root directory, lookup the
     1952     * remainder of the path starting with it.
     1953     */
     1954    return kFsCacheLookupRelativeToDirA(pCache, (PKFSDIR)pChild, &pszPath[offEnd + cchSlashes],
     1955                                        cchPath - offEnd - cchSlashes, penmError);
     1956}
     1957
     1958
     1959/**
     1960 * Walk the file system tree for the given absolute path, UTF-16 version.
     1961 *
     1962 * This will create any missing nodes while walking.
     1963 *
     1964 * The caller will have to do the path hash table insertion of the result.
     1965 *
     1966 * @returns Pointer to the tree node corresponding to @a pszPath.
     1967 *          NULL on lookup failure, see @a penmError for details.
     1968 * @param   pCache              The cache.
     1969 * @param   pwszPath            The path to walk.
     1970 * @param   cwcPath             The length of the path (in wchar_t's).
     1971 * @param   penmError           Where to return details as to why the lookup
     1972 *                              failed.
     1973 */
     1974static PKFSOBJ kFsCacheLookupAbsoluteW(PKFSCACHE pCache, const wchar_t *pwszPath, KU32 cwcPath, KFSLOOKUPERROR *penmError)
     1975{
     1976    PKFSDIR     pParent = &pCache->RootDir;
     1977    PKFSOBJ     pChild;
     1978    KU32        off;
     1979    KU32        cwcSlashes;
     1980    KU32        offEnd;
     1981
     1982    KFSCACHE_LOG(("kFsCacheLookupAbsoluteW(%ls)\n", pwszPath));
     1983
     1984    /*
     1985     * The root "directory" needs special handling, so we keep it outside the
     1986     * main search loop. (Special: Cannot enumerate it, UNCs, ++.)
     1987     */
     1988    cwcSlashes = 0;
     1989    off        = 0;
     1990    if (   pwszPath[1] == ':'
     1991        && IS_ALPHA(pwszPath[0]))
     1992    {
     1993        /* Drive letter. */
     1994        offEnd = 2;
     1995        kHlpAssert(IS_SLASH(pwszPath[2]));
     1996        pChild = kFswCacheLookupDrive(pCache, toupper(pwszPath[0]), penmError);
     1997    }
     1998    else if (   IS_SLASH(pwszPath[0])
     1999             && IS_SLASH(pwszPath[1]) )
     2000        pChild = kFswCacheLookupUncShareW(pCache, pwszPath, &offEnd, penmError);
     2001    else
     2002    {
     2003        *penmError = KFSLOOKUPERROR_UNSUPPORTED;
     2004        return NULL;
     2005    }
     2006    if (pChild)
     2007    { /* likely */ }
     2008    else
     2009        return NULL;
     2010
     2011    /* Count slashes trailing the root spec. */
     2012    if (offEnd < cwcPath)
     2013    {
     2014        kHlpAssert(IS_SLASH(pwszPath[offEnd]));
     2015        do
     2016            cwcSlashes++;
     2017        while (IS_SLASH(pwszPath[offEnd + cwcSlashes]));
     2018    }
     2019
     2020    /* Done already? */
     2021    if (offEnd >= cwcPath)
     2022    {
     2023        if (   pChild->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE
     2024            || pChild->uCacheGen == (pChild->bObjType != KFSOBJ_TYPE_MISSING ? pCache->uGeneration : pCache->uGenerationMissing)
     2025            || kFsCacheRefreshObj(pCache, pChild, penmError))
     2026            return kFsCacheObjRetainInternal(pChild);
     2027        return NULL;
     2028    }
     2029
     2030    /* Check that we've got a valid result and not a cached negative one. */
     2031    if (pChild->bObjType == KFSOBJ_TYPE_DIR)
     2032    { /* likely */ }
     2033    else
     2034    {
     2035        kHlpAssert(pChild->bObjType == KFSOBJ_TYPE_MISSING);
     2036        kHlpAssert(pChild->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE || pChild->uCacheGen == pCache->uGenerationMissing);
     2037        return pChild;
     2038    }
     2039
     2040    /*
     2041     * Now that we've found a valid root directory, lookup the
     2042     * remainder of the path starting with it.
     2043     */
     2044    return kFsCacheLookupRelativeToDirW(pCache, (PKFSDIR)pChild, &pwszPath[offEnd + cwcSlashes],
     2045                                        cwcPath - offEnd - cwcSlashes, penmError);
    19732046}
    19742047
     
    23132386        PKFSUSERDATA pUserData = pObj->pUserDataHead;
    23142387        pObj->pUserDataHead = pUserData->pNext;
    2315         pUserData->pfnDestructor(pCache, pObj, pUserData);
     2388        if (pUserData->pfnDestructor)
     2389            pUserData->pfnDestructor(pCache, pObj, pUserData);
    23162390        kHlpFree(pUserData);
    23172391    }
     
    24132487    kHlpAssert(cRefs < 16384);
    24142488    return cRefs;
     2489}
     2490
     2491
     2492/**
     2493 * Associates an item of user data with the given object.
     2494 *
     2495 * If the data needs cleaning up before being free, set the
     2496 * PKFSUSERDATA::pfnDestructor member of the returned structure.
     2497 *
     2498 * @returns Pointer to the user data on success.
     2499 *          NULL if out of memory or key already in use.
     2500 *
     2501 * @param   pCache              The cache.
     2502 * @param   pObj                The object.
     2503 * @param   uKey                The user data key.
     2504 * @param   cbUserData          The size of the user data.
     2505 */
     2506PKFSUSERDATA kFsCacheObjAddUserData(PKFSCACHE pCache, PKFSOBJ pObj, KUPTR uKey, KSIZE cbUserData)
     2507{
     2508    kHlpAssert(cbUserData >= sizeof(*pNew));
     2509    if (kFsCacheObjGetUserData(pCache, pObj, uKey) == NULL)
     2510    {
     2511        PKFSUSERDATA pNew = (PKFSUSERDATA)kHlpAllocZ(cbUserData);
     2512        if (pNew)
     2513        {
     2514            pNew->uKey          = uKey;
     2515            pNew->pfnDestructor = NULL;
     2516            pNew->pNext         = pObj->pUserDataHead;
     2517            pObj->pUserDataHead = pNew;
     2518            return pNew;
     2519        }
     2520    }
     2521
     2522    return NULL;
     2523}
     2524
     2525
     2526/**
     2527 * Retrieves an item of user data associated with the given object.
     2528 *
     2529 * @returns Pointer to the associated user data if found, otherwise NULL.
     2530 * @param   pCache              The cache.
     2531 * @param   pObj                The object.
     2532 * @param   uKey                The user data key.
     2533 */
     2534PKFSUSERDATA kFsCacheObjGetUserData(PKFSCACHE pCache, PKFSOBJ pObj, KUPTR uKey)
     2535{
     2536    PKFSUSERDATA pCur;
     2537
     2538    kHlpAssert(pCache->u32Magic == KFSCACHE_MAGIC);
     2539    kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC);
     2540
     2541    for (pCur = pObj->pUserDataHead; pCur; pCur = pCur->pNext)
     2542        if (pCur->uKey == uKey)
     2543            return pCur;
     2544    return NULL;
    24152545}
    24162546
  • trunk/src/lib/nt/kFsCache.h

    r2855 r2856  
    231231
    232232    /** Handle to the directory (we generally keep it open). */
     233#ifndef DECLARE_HANDLE
     234    KUPTR               hDir;
     235#else
    233236    HANDLE              hDir;
     237#endif
    234238    /** The device number we queried/inherited when opening it. */
    235239    KU64                uDevNo;
     
    418422PKFSOBJ     kFsCacheLookupA(PKFSCACHE pCache, const char *pszPath, KFSLOOKUPERROR *penmError);
    419423PKFSOBJ     kFsCacheLookupW(PKFSCACHE pCache, const wchar_t *pwszPath, KFSLOOKUPERROR *penmError);
     424PKFSOBJ     kFsCacheLookupRelativeToDirA(PKFSCACHE pCache, PKFSDIR pParent, const char *pszPath, KU32 cchPath,
     425                                         KFSLOOKUPERROR *penmError);
     426PKFSOBJ     kFsCacheLookupRelativeToDirW(PKFSCACHE pCache, PKFSDIR pParent, const wchar_t *pwszPath, KU32 cwcPath,
     427                                         KFSLOOKUPERROR *penmError);
    420428
    421429KU32        kFsCacheObjRelease(PKFSCACHE pCache, PKFSOBJ pObj);
    422430KU32        kFsCacheObjRetain(PKFSOBJ pObj);
     431PKFSUSERDATA kFsCacheObjAddUserData(PKFSCACHE pCache, PKFSOBJ pPathObj, KUPTR uKey, KSIZE cbUserData);
     432PKFSUSERDATA kFsCacheObjGetUserData(PKFSCACHE pCache, PKFSOBJ pPathObj, KUPTR uKey);
    423433
    424434PKFSCACHE   kFsCacheCreate(KU32 fFlags);
  • trunk/src/lib/nt/ntstat.h

    r2851 r2856  
    8181int birdStatModTimeOnly(const char *pszPath, BirdTimeSpec_T *pTimeSpec, int fFollowLink);
    8282#ifdef ___nt_ntstuff_h
     83int  birdStatHandle(HANDLE hFile, BirdStat_T *pStat, const char *pszPath);
    8384void birdStatFillFromFileIdFullDirInfo(BirdStat_T *pStat, MY_FILE_ID_FULL_DIR_INFORMATION const *pBuf, const char *pszPath);
    8485void birdStatFillFromFileIdBothDirInfo(BirdStat_T *pStat, MY_FILE_ID_BOTH_DIR_INFORMATION const *pBuf, const char *pszPath);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette