Changeset 2858 for trunk/src/lib/nt


Ignore:
Timestamp:
Sep 1, 2016, 5:12:24 PM (9 years ago)
Author:
bird
Message:

updates

Location:
trunk/src/lib/nt
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/nt/kFsCache.c

    r2857 r2858  
    22202220 *
    22212221 * @returns Reference to object corresponding to @a pszPath on success, this
    2222  *          must be released by kwFsCacheRelease.
     2222 *          must be released by kFsCacheObjRelease.
    22232223 *          NULL if not a path we care to cache.
    22242224 * @param   pCache              The cache.
     
    22462246            {
    22472247                if (   pHashEntry->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE
    2248                     || pHashEntry->uCacheGen == pCache->uGeneration
     2248                    || pHashEntry->uCacheGen == (pHashEntry->pFsObj ? pCache->uGeneration : pCache->uGenerationMissing)
    22492249                    || (pHashEntry = kFsCacheRefreshPathA(pCache, pHashEntry, idxHashTab)) )
    22502250                {
     
    23102310 *
    23112311 * @returns Reference to object corresponding to @a pszPath on success, this
    2312  *          must be released by kwFsCacheRelease.
     2312 *          must be released by kFsCacheObjRelease.
    23132313 *          NULL if not a path we care to cache.
    23142314 * @param   pCache              The cache.
     
    23362336            {
    23372337                if (   pHashEntry->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE
    2338                     || pHashEntry->uCacheGen == pCache->uGeneration
     2338                    || pHashEntry->uCacheGen == (pHashEntry->pFsObj ? pCache->uGeneration : pCache->uGenerationMissing)
    23392339                    || (pHashEntry = kFsCacheRefreshPathW(pCache, pHashEntry, idxHashTab)) )
    23402340                {
     
    23902390
    23912391/**
     2392 * Wrapper around kFsCacheLookupA that drops KFSOBJ_TYPE_MISSING and returns
     2393 * KFSLOOKUPERROR_NOT_FOUND instead.
     2394 *
     2395 * @returns Reference to object corresponding to @a pszPath on success, this
     2396 *          must be released by kFsCacheObjRelease.
     2397 *          NULL if not a path we care to cache.
     2398 * @param   pCache              The cache.
     2399 * @param   pszPath             The path to lookup.
     2400 * @param   penmError           Where to return details as to why the lookup
     2401 *                              failed.
     2402 */
     2403PKFSOBJ kFsCacheLookupNoMissingA(PKFSCACHE pCache, const char *pszPath, KFSLOOKUPERROR *penmError)
     2404{
     2405    PKFSOBJ pObj = kFsCacheLookupA(pCache, pszPath, penmError);
     2406    if (pObj)
     2407    {
     2408        if (pObj->bObjType != KFSOBJ_TYPE_MISSING)
     2409            return pObj;
     2410
     2411        kFsCacheObjRelease(pCache, pObj);
     2412        *penmError = KFSLOOKUPERROR_NOT_FOUND;
     2413    }
     2414    return NULL;
     2415}
     2416
     2417
     2418/**
     2419 * Wrapper around kFsCacheLookupW that drops KFSOBJ_TYPE_MISSING and returns
     2420 * KFSLOOKUPERROR_NOT_FOUND instead.
     2421 *
     2422 * @returns Reference to object corresponding to @a pszPath on success, this
     2423 *          must be released by kFsCacheObjRelease.
     2424 *          NULL if not a path we care to cache.
     2425 * @param   pCache              The cache.
     2426 * @param   pwszPath            The path to lookup.
     2427 * @param   penmError           Where to return details as to why the lookup
     2428 *                              failed.
     2429 */
     2430PKFSOBJ kFsCacheLookupNoMissingW(PKFSCACHE pCache, const wchar_t *pwszPath, KFSLOOKUPERROR *penmError)
     2431{
     2432    PKFSOBJ pObj = kFsCacheLookupW(pCache, pwszPath, penmError);
     2433    if (pObj)
     2434    {
     2435        if (pObj->bObjType != KFSOBJ_TYPE_MISSING)
     2436            return pObj;
     2437
     2438        kFsCacheObjRelease(pCache, pObj);
     2439        *penmError = KFSLOOKUPERROR_NOT_FOUND;
     2440    }
     2441    return NULL;
     2442}
     2443
     2444
     2445/**
    23922446 * Destroys a cache object which has a zero reference count.
    23932447 *
     
    24892543KU32 kFsCacheObjRelease(PKFSCACHE pCache, PKFSOBJ pObj)
    24902544{
    2491     KU32 cRefs;
    2492     kHlpAssert(pCache->u32Magic == KFSCACHE_MAGIC);
    2493     kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC);
    2494 
    2495     cRefs = --pObj->cRefs;
    2496     if (cRefs)
    2497         return cRefs;
    2498     return kFsCacheObjDestroy(pCache, pObj);
     2545    if (pObj)
     2546    {
     2547        KU32 cRefs;
     2548        kHlpAssert(pCache->u32Magic == KFSCACHE_MAGIC);
     2549        kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC);
     2550
     2551        cRefs = --pObj->cRefs;
     2552        if (cRefs)
     2553            return cRefs;
     2554        return kFsCacheObjDestroy(pCache, pObj);
     2555    }
     2556    return 0;
    24992557}
    25002558
     
    25722630    return NULL;
    25732631}
     2632
     2633
     2634/**
     2635 * Gets the full path to @a pObj, ANSI version.
     2636 *
     2637 * @returns K_TRUE on success, K_FALSE on buffer overflow (nothing stored).
     2638 * @param   pObj                The object to get the full path to.
     2639 * @param   pszPath             Where to return the path
     2640 * @param   cbPath              The size of the output buffer.
     2641 * @param   chSlash             The slash to use.
     2642 */
     2643KBOOL kFsCacheObjGetFullPathA(PKFSOBJ pObj, char *pszPath, KSIZE cbPath, char chSlash)
     2644{
     2645    KSIZE off = pObj->cchParent;
     2646    kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC);
     2647    if (off > 0)
     2648    {
     2649        KSIZE offEnd = off + pObj->cchName;
     2650        if (offEnd < cbPath)
     2651        {
     2652            PKFSDIR pAncestor;
     2653
     2654            pszPath[off + pObj->cchName] = '\0';
     2655            memcpy(&pszPath[off], pObj->pszName, pObj->cchName);
     2656
     2657            for (pAncestor = pObj->pParent; off > 0; pAncestor = pAncestor->Obj.pParent)
     2658            {
     2659                kHlpAssert(off > 1);
     2660                kHlpAssert(pAncestor != NULL);
     2661                kHlpAssert(pAncestor->Obj.cchName > 0);
     2662                pszPath[--off] = chSlash;
     2663                off -= pAncestor->Obj.cchName;
     2664                kHlpAssert(pAncestor->Obj.cchParent == off);
     2665                memcpy(&pszPath[off], pAncestor->Obj.pszName, pAncestor->Obj.cchName);
     2666            }
     2667            return K_TRUE;
     2668        }
     2669    }
     2670    else
     2671    {
     2672        KBOOL const fDriveLetter = pObj->cchName == 2 && pObj->pszName[2] == ':';
     2673        off = pObj->cchName;
     2674        if (off + fDriveLetter < cbPath)
     2675        {
     2676            memcpy(pszPath, pObj->pszName, off);
     2677            if (fDriveLetter)
     2678                pszPath[off++] = chSlash;
     2679            pszPath[off] = '\0';
     2680            return K_TRUE;
     2681        }
     2682    }
     2683
     2684    return K_FALSE;
     2685}
     2686
     2687
     2688/**
     2689 * Gets the full path to @a pObj, UTF-16 version.
     2690 *
     2691 * @returns K_TRUE on success, K_FALSE on buffer overflow (nothing stored).
     2692 * @param   pObj                The object to get the full path to.
     2693 * @param   pszPath             Where to return the path
     2694 * @param   cbPath              The size of the output buffer.
     2695 * @param   wcSlash             The slash to use.
     2696 */
     2697KBOOL kFsCacheObjGetFullPathW(PKFSOBJ pObj, wchar_t *pwszPath, KSIZE cwcPath, wchar_t wcSlash)
     2698{
     2699    KSIZE off = pObj->cwcParent;
     2700    kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC);
     2701    if (off > 0)
     2702    {
     2703        KSIZE offEnd = off + pObj->cwcName;
     2704        if (offEnd < cwcPath)
     2705        {
     2706            PKFSDIR pAncestor;
     2707
     2708            pwszPath[off + pObj->cwcName] = '\0';
     2709            memcpy(&pwszPath[off], pObj->pwszName, pObj->cwcName * sizeof(wchar_t));
     2710
     2711            for (pAncestor = pObj->pParent; off > 0; pAncestor = pAncestor->Obj.pParent)
     2712            {
     2713                kHlpAssert(off > 1);
     2714                kHlpAssert(pAncestor != NULL);
     2715                kHlpAssert(pAncestor->Obj.cwcName > 0);
     2716                pwszPath[--off] = wcSlash;
     2717                off -= pAncestor->Obj.cwcName;
     2718                kHlpAssert(pAncestor->Obj.cwcParent == off);
     2719                memcpy(&pwszPath[off], pAncestor->Obj.pwszName, pAncestor->Obj.cwcName * sizeof(wchar_t));
     2720            }
     2721            return K_TRUE;
     2722        }
     2723    }
     2724    else
     2725    {
     2726        KBOOL const fDriveLetter = pObj->cchName == 2 && pObj->pszName[2] == ':';
     2727        off = pObj->cwcName;
     2728        if (off + fDriveLetter < cwcPath)
     2729        {
     2730            memcpy(pwszPath, pObj->pwszName, off * sizeof(wchar_t));
     2731            if (fDriveLetter)
     2732                pwszPath[off++] = wcSlash;
     2733            pwszPath[off] = '\0';
     2734            return K_TRUE;
     2735        }
     2736    }
     2737
     2738    return K_FALSE;
     2739}
     2740
     2741
     2742#ifdef KFSCACHE_CFG_SHORT_NAMES
     2743
     2744/**
     2745 * Gets the full short path to @a pObj, ANSI version.
     2746 *
     2747 * @returns K_TRUE on success, K_FALSE on buffer overflow (nothing stored).
     2748 * @param   pObj                The object to get the full path to.
     2749 * @param   pszPath             Where to return the path
     2750 * @param   cbPath              The size of the output buffer.
     2751 * @param   chSlash             The slash to use.
     2752 */
     2753KBOOL kFsCacheObjGetFullShortPathA(PKFSOBJ pObj, char *pszPath, KSIZE cbPath, char chSlash)
     2754{
     2755    KSIZE off = pObj->cchShortParent;
     2756    kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC);
     2757    if (off > 0)
     2758    {
     2759        KSIZE offEnd = off + pObj->cchShortName;
     2760        if (offEnd < cbPath)
     2761        {
     2762            PKFSDIR pAncestor;
     2763
     2764            pszPath[off + pObj->cchShortName] = '\0';
     2765            memcpy(&pszPath[off], pObj->pszShortName, pObj->cchShortName);
     2766
     2767            for (pAncestor = pObj->pParent; off > 0; pAncestor = pAncestor->Obj.pParent)
     2768            {
     2769                kHlpAssert(off > 1);
     2770                kHlpAssert(pAncestor != NULL);
     2771                kHlpAssert(pAncestor->Obj.cchShortName > 0);
     2772                pszPath[--off] = chSlash;
     2773                off -= pAncestor->Obj.cchShortName;
     2774                kHlpAssert(pAncestor->Obj.cchShortParent == off);
     2775                memcpy(&pszPath[off], pAncestor->Obj.pszShortName, pAncestor->Obj.cchShortName);
     2776            }
     2777            return K_TRUE;
     2778        }
     2779    }
     2780    else
     2781    {
     2782        KBOOL const fDriveLetter = pObj->cchShortName == 2 && pObj->pszShortName[2] == ':';
     2783        off = pObj->cchShortName;
     2784        if (off + fDriveLetter < cbPath)
     2785        {
     2786            memcpy(pszPath, pObj->pszShortName, off);
     2787            if (fDriveLetter)
     2788                pszPath[off++] = chSlash;
     2789            pszPath[off] = '\0';
     2790            return K_TRUE;
     2791        }
     2792    }
     2793
     2794    return K_FALSE;
     2795}
     2796
     2797
     2798/**
     2799 * Gets the full short path to @a pObj, UTF-16 version.
     2800 *
     2801 * @returns K_TRUE on success, K_FALSE on buffer overflow (nothing stored).
     2802 * @param   pObj                The object to get the full path to.
     2803 * @param   pszPath             Where to return the path
     2804 * @param   cbPath              The size of the output buffer.
     2805 * @param   wcSlash             The slash to use.
     2806 */
     2807KBOOL kFsCacheObjGetFullShortPathW(PKFSOBJ pObj, wchar_t *pwszPath, KSIZE cwcPath, wchar_t wcSlash)
     2808{
     2809    KSIZE off = pObj->cwcShortParent;
     2810    kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC);
     2811    if (off > 0)
     2812    {
     2813        KSIZE offEnd = off + pObj->cwcShortName;
     2814        if (offEnd < cwcPath)
     2815        {
     2816            PKFSDIR pAncestor;
     2817
     2818            pwszPath[off + pObj->cwcShortName] = '\0';
     2819            memcpy(&pwszPath[off], pObj->pwszShortName, pObj->cwcShortName * sizeof(wchar_t));
     2820
     2821            for (pAncestor = pObj->pParent; off > 0; pAncestor = pAncestor->Obj.pParent)
     2822            {
     2823                kHlpAssert(off > 1);
     2824                kHlpAssert(pAncestor != NULL);
     2825                kHlpAssert(pAncestor->Obj.cwcShortName > 0);
     2826                pwszPath[--off] = wcSlash;
     2827                off -= pAncestor->Obj.cwcShortName;
     2828                kHlpAssert(pAncestor->Obj.cwcShortParent == off);
     2829                memcpy(&pwszPath[off], pAncestor->Obj.pwszShortName, pAncestor->Obj.cwcShortName * sizeof(wchar_t));
     2830            }
     2831            return K_TRUE;
     2832        }
     2833    }
     2834    else
     2835    {
     2836        KBOOL const fDriveLetter = pObj->cchShortName == 2 && pObj->pszShortName[2] == ':';
     2837        off = pObj->cwcShortName;
     2838        if (off + fDriveLetter < cwcPath)
     2839        {
     2840            memcpy(pwszPath, pObj->pwszShortName, off * sizeof(wchar_t));
     2841            if (fDriveLetter)
     2842                pwszPath[off++] = wcSlash;
     2843            pwszPath[off] = '\0';
     2844            return K_TRUE;
     2845        }
     2846    }
     2847
     2848    return K_FALSE;
     2849}
     2850
     2851#endif /* KFSCACHE_CFG_SHORT_NAMES */
    25742852
    25752853
     
    26212899            pCache->fFlags          = fFlags;
    26222900            pCache->uGeneration     = 1;
     2901            pCache->uGenerationMissing = KU32_MAX / 2;
    26232902            pCache->cObjects        = 1;
    26242903            pCache->cbObjects       = sizeof(pCache->RootDir) + pCache->RootDir.cHashTab * sizeof(pCache->RootDir.paHashTab[0]);
  • trunk/src/lib/nt/kFsCache.h

    r2857 r2858  
    427427PKFSOBJ     kFsCacheLookupRelativeToDirW(PKFSCACHE pCache, PKFSDIR pParent, const wchar_t *pwszPath, KU32 cwcPath,
    428428                                         KFSLOOKUPERROR *penmError);
     429PKFSOBJ     kFsCacheLookupNoMissingA(PKFSCACHE pCache, const char *pszPath, KFSLOOKUPERROR *penmError);
     430PKFSOBJ     kFsCacheLookupNoMissingW(PKFSCACHE pCache, const wchar_t *pwszPath, KFSLOOKUPERROR *penmError);
     431
    429432
    430433KU32        kFsCacheObjRelease(PKFSCACHE pCache, PKFSOBJ pObj);
    431434KU32        kFsCacheObjRetain(PKFSOBJ pObj);
    432 PKFSUSERDATA kFsCacheObjAddUserData(PKFSCACHE pCache, PKFSOBJ pPathObj, KUPTR uKey, KSIZE cbUserData);
    433 PKFSUSERDATA kFsCacheObjGetUserData(PKFSCACHE pCache, PKFSOBJ pPathObj, KUPTR uKey);
     435PKFSUSERDATA kFsCacheObjAddUserData(PKFSCACHE pCache, PKFSOBJ pObj, KUPTR uKey, KSIZE cbUserData);
     436PKFSUSERDATA kFsCacheObjGetUserData(PKFSCACHE pCache, PKFSOBJ pObj, KUPTR uKey);
     437KBOOL       kFsCacheObjGetFullPathA(PKFSOBJ pObj, char *pszPath, KSIZE cbPath, char chSlash);
     438KBOOL       kFsCacheObjGetFullPathW(PKFSOBJ pObj, wchar_t *pwszPath, KSIZE cwcPath, wchar_t wcSlash);
     439KBOOL       kFsCacheObjGetFullShortPathA(PKFSOBJ pObj, char *pszPath, KSIZE cbPath, char chSlash);
     440KBOOL       kFsCacheObjGetFullShortPathW(PKFSOBJ pObj, wchar_t *pwszPath, KSIZE cwcPath, wchar_t wcSlash);
    434441
    435442PKFSCACHE   kFsCacheCreate(KU32 fFlags);
  • trunk/src/lib/nt/ntstat.c

    r2851 r2858  
    208208    pStat->st_uid           = 0;
    209209    pStat->st_gid           = 0;
    210     pStat->st_padding1[0]   = 0;
    211     pStat->st_padding1[1]   = 0;
    212     pStat->st_padding1[2]   = 0;
     210    pStat->st_padding1      = 0;
     211    pStat->st_attribs       = pBuf->FileAttributes;
    213212    pStat->st_blksize       = 65536;
    214213    pStat->st_blocks        = (pBuf->AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1)
     
    241240    pStat->st_uid           = 0;
    242241    pStat->st_gid           = 0;
    243     pStat->st_padding1[0]   = 0;
    244     pStat->st_padding1[1]   = 0;
    245     pStat->st_padding1[2]   = 0;
     242    pStat->st_padding1      = 0;
     243    pStat->st_attribs       = pBuf->FileAttributes;
    246244    pStat->st_blksize       = 65536;
    247245    pStat->st_blocks        = (pBuf->AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1)
     
    274272    pStat->st_uid           = 0;
    275273    pStat->st_gid           = 0;
    276     pStat->st_padding1[0]   = 0;
    277     pStat->st_padding1[1]   = 0;
    278     pStat->st_padding1[2]   = 0;
     274    pStat->st_padding1      = 0;
     275    pStat->st_attribs       = pBuf->FileAttributes;
    279276    pStat->st_blksize       = 65536;
    280277    pStat->st_blocks        = (pBuf->AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1)
     
    314311            pStat->st_uid           = 0;
    315312            pStat->st_gid           = 0;
    316             pStat->st_padding1[0]   = 0;
    317             pStat->st_padding1[1]   = 0;
    318             pStat->st_padding1[2]   = 0;
     313            pStat->st_padding1      = 0;
     314            pStat->st_attribs       = pAll->StandardInformation.FileAttributes;
    319315            pStat->st_blksize       = 65536;
    320316            pStat->st_blocks        = (pAll->StandardInformation.AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1)
     
    389385        pStat->st_uid           = 0;
    390386        pStat->st_gid           = 0;
    391         pStat->st_padding1[0]   = 0;
    392         pStat->st_padding1[1]   = 0;
    393         pStat->st_padding1[2]   = 0;
     387        pStat->st_padding1      = 0;
     388        pStat->st_attribs       = BasicInfo.FileAttributes;
    394389        pStat->st_blksize       = 65536;
    395390        pStat->st_blocks        = (StdInfo.AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1)
     
    608603                pStat->st_uid               = 0;
    609604                pStat->st_gid               = 0;
    610                 pStat->st_padding1[0]       = 0;
    611                 pStat->st_padding1[1]       = 0;
    612                 pStat->st_padding1[2]       = 0;
     605                pStat->st_padding1          = 0;
     606                pStat->st_attribs           = fFileType == FILE_TYPE_PIPE ? FILE_ATTRIBUTE_NORMAL : FILE_ATTRIBUTE_DEVICE;
    613607                pStat->st_blksize           = 512;
    614608                pStat->st_blocks            = 0;
  • trunk/src/lib/nt/ntstat.h

    r2856 r2858  
    6363    __int16             st_uid;
    6464    __int16             st_gid;
    65     unsigned __int16    st_padding1[3];
     65    unsigned __int16    st_padding1;
     66    unsigned __int32    st_attribs;
    6667    unsigned __int32    st_blksize;
    6768    __int64             st_blocks;
  • trunk/src/lib/nt/ntstuff.h

    r2852 r2858  
    3636#define WIN32_NO_STATUS
    3737#include <Windows.h>
     38#include <winternl.h>
    3839#undef WIN32_NO_STATUS
    3940#include <ntstatus.h>
Note: See TracChangeset for help on using the changeset viewer.