Changeset 2858 for trunk/src/lib/nt
- Timestamp:
- Sep 1, 2016, 5:12:24 PM (9 years ago)
- Location:
- trunk/src/lib/nt
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/nt/kFsCache.c
r2857 r2858 2220 2220 * 2221 2221 * @returns Reference to object corresponding to @a pszPath on success, this 2222 * must be released by k wFsCacheRelease.2222 * must be released by kFsCacheObjRelease. 2223 2223 * NULL if not a path we care to cache. 2224 2224 * @param pCache The cache. … … 2246 2246 { 2247 2247 if ( pHashEntry->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE 2248 || pHashEntry->uCacheGen == pCache->uGeneration2248 || pHashEntry->uCacheGen == (pHashEntry->pFsObj ? pCache->uGeneration : pCache->uGenerationMissing) 2249 2249 || (pHashEntry = kFsCacheRefreshPathA(pCache, pHashEntry, idxHashTab)) ) 2250 2250 { … … 2310 2310 * 2311 2311 * @returns Reference to object corresponding to @a pszPath on success, this 2312 * must be released by k wFsCacheRelease.2312 * must be released by kFsCacheObjRelease. 2313 2313 * NULL if not a path we care to cache. 2314 2314 * @param pCache The cache. … … 2336 2336 { 2337 2337 if ( pHashEntry->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE 2338 || pHashEntry->uCacheGen == pCache->uGeneration2338 || pHashEntry->uCacheGen == (pHashEntry->pFsObj ? pCache->uGeneration : pCache->uGenerationMissing) 2339 2339 || (pHashEntry = kFsCacheRefreshPathW(pCache, pHashEntry, idxHashTab)) ) 2340 2340 { … … 2390 2390 2391 2391 /** 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 */ 2403 PKFSOBJ 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 */ 2430 PKFSOBJ 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 /** 2392 2446 * Destroys a cache object which has a zero reference count. 2393 2447 * … … 2489 2543 KU32 kFsCacheObjRelease(PKFSCACHE pCache, PKFSOBJ pObj) 2490 2544 { 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; 2499 2557 } 2500 2558 … … 2572 2630 return NULL; 2573 2631 } 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 */ 2643 KBOOL 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 */ 2697 KBOOL 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 */ 2753 KBOOL 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 */ 2807 KBOOL 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 */ 2574 2852 2575 2853 … … 2621 2899 pCache->fFlags = fFlags; 2622 2900 pCache->uGeneration = 1; 2901 pCache->uGenerationMissing = KU32_MAX / 2; 2623 2902 pCache->cObjects = 1; 2624 2903 pCache->cbObjects = sizeof(pCache->RootDir) + pCache->RootDir.cHashTab * sizeof(pCache->RootDir.paHashTab[0]); -
trunk/src/lib/nt/kFsCache.h
r2857 r2858 427 427 PKFSOBJ kFsCacheLookupRelativeToDirW(PKFSCACHE pCache, PKFSDIR pParent, const wchar_t *pwszPath, KU32 cwcPath, 428 428 KFSLOOKUPERROR *penmError); 429 PKFSOBJ kFsCacheLookupNoMissingA(PKFSCACHE pCache, const char *pszPath, KFSLOOKUPERROR *penmError); 430 PKFSOBJ kFsCacheLookupNoMissingW(PKFSCACHE pCache, const wchar_t *pwszPath, KFSLOOKUPERROR *penmError); 431 429 432 430 433 KU32 kFsCacheObjRelease(PKFSCACHE pCache, PKFSOBJ pObj); 431 434 KU32 kFsCacheObjRetain(PKFSOBJ pObj); 432 PKFSUSERDATA kFsCacheObjAddUserData(PKFSCACHE pCache, PKFSOBJ pPathObj, KUPTR uKey, KSIZE cbUserData); 433 PKFSUSERDATA kFsCacheObjGetUserData(PKFSCACHE pCache, PKFSOBJ pPathObj, KUPTR uKey); 435 PKFSUSERDATA kFsCacheObjAddUserData(PKFSCACHE pCache, PKFSOBJ pObj, KUPTR uKey, KSIZE cbUserData); 436 PKFSUSERDATA kFsCacheObjGetUserData(PKFSCACHE pCache, PKFSOBJ pObj, KUPTR uKey); 437 KBOOL kFsCacheObjGetFullPathA(PKFSOBJ pObj, char *pszPath, KSIZE cbPath, char chSlash); 438 KBOOL kFsCacheObjGetFullPathW(PKFSOBJ pObj, wchar_t *pwszPath, KSIZE cwcPath, wchar_t wcSlash); 439 KBOOL kFsCacheObjGetFullShortPathA(PKFSOBJ pObj, char *pszPath, KSIZE cbPath, char chSlash); 440 KBOOL kFsCacheObjGetFullShortPathW(PKFSOBJ pObj, wchar_t *pwszPath, KSIZE cwcPath, wchar_t wcSlash); 434 441 435 442 PKFSCACHE kFsCacheCreate(KU32 fFlags); -
trunk/src/lib/nt/ntstat.c
r2851 r2858 208 208 pStat->st_uid = 0; 209 209 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; 213 212 pStat->st_blksize = 65536; 214 213 pStat->st_blocks = (pBuf->AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1) … … 241 240 pStat->st_uid = 0; 242 241 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; 246 244 pStat->st_blksize = 65536; 247 245 pStat->st_blocks = (pBuf->AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1) … … 274 272 pStat->st_uid = 0; 275 273 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; 279 276 pStat->st_blksize = 65536; 280 277 pStat->st_blocks = (pBuf->AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1) … … 314 311 pStat->st_uid = 0; 315 312 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; 319 315 pStat->st_blksize = 65536; 320 316 pStat->st_blocks = (pAll->StandardInformation.AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1) … … 389 385 pStat->st_uid = 0; 390 386 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; 394 389 pStat->st_blksize = 65536; 395 390 pStat->st_blocks = (StdInfo.AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1) … … 608 603 pStat->st_uid = 0; 609 604 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; 613 607 pStat->st_blksize = 512; 614 608 pStat->st_blocks = 0; -
trunk/src/lib/nt/ntstat.h
r2856 r2858 63 63 __int16 st_uid; 64 64 __int16 st_gid; 65 unsigned __int16 st_padding1[3]; 65 unsigned __int16 st_padding1; 66 unsigned __int32 st_attribs; 66 67 unsigned __int32 st_blksize; 67 68 __int64 st_blocks; -
trunk/src/lib/nt/ntstuff.h
r2852 r2858 36 36 #define WIN32_NO_STATUS 37 37 #include <Windows.h> 38 #include <winternl.h> 38 39 #undef WIN32_NO_STATUS 39 40 #include <ntstatus.h>
Note:
See TracChangeset
for help on using the changeset viewer.