Changeset 2861 in kBuild
- Timestamp:
- Sep 1, 2016 10:42:55 PM (9 years ago)
- Location:
- trunk/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/dir-nt-bird.c
r2857 r2861 235 235 { 236 236 KMKNTOPENDIR *pDir = (KMKNTOPENDIR *)pvDir; 237 while (pDir->idxNext < pDir->pDir->cChildren) 237 KU32 const cChildren = pDir->pDir->cChildren; 238 while (pDir->idxNext < cChildren) 238 239 { 239 240 PKFSOBJ pEntry = pDir->pDir->papChildren[pDir->idxNext++]; … … 267 268 } 268 269 } 270 271 /* 272 * Fake the '.' and '..' directories because they're not part of papChildren above. 273 */ 274 if (pDir->idxNext < cChildren + 2) 275 { 276 pDir->idxNext++; 277 pDir->DirEnt.d_type = DT_DIR; 278 pDir->DirEnt.d_namlen = pDir->idxNext - cChildren; 279 pDir->DirEnt.d_reclen = offsetof(struct dirent, d_name) + pDir->DirEnt.d_namlen; 280 pDir->DirEnt.d_name[0] = '.'; 281 pDir->DirEnt.d_name[1] = '.'; 282 pDir->DirEnt.d_name[pDir->DirEnt.d_namlen] = '\0'; 283 return &pDir->DirEnt; 284 } 285 269 286 return NULL; 270 287 } … … 457 474 int stat_only_mtime(const char *pszPath, struct stat *pStat) 458 475 { 459 if (commands_started == 0) 460 { 461 KFSLOOKUPERROR enmError; 462 PKFSOBJ pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError); 463 if (pPathObj) 464 { 465 if (pPathObj->bObjType != KFSOBJ_TYPE_MISSING) 466 { 467 kHlpAssert(pPathObj->fHaveStats); /* currently always true. */ 468 pStat->st_mtime = pPathObj->Stats.st_mtime; 469 kFsCacheObjRelease(g_pFsCache, pPathObj); 470 return 0; 471 } 472 476 KFSLOOKUPERROR enmError; 477 PKFSOBJ pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError); 478 if (pPathObj) 479 { 480 if (pPathObj->bObjType != KFSOBJ_TYPE_MISSING) 481 { 482 kHlpAssert(pPathObj->fHaveStats); /* currently always true. */ 483 pStat->st_mtime = pPathObj->Stats.st_mtime; 473 484 kFsCacheObjRelease(g_pFsCache, pPathObj); 474 errno = ENOENT; 475 } 476 else 477 errno = enmError == KFSLOOKUPERROR_NOT_DIR 478 || enmError == KFSLOOKUPERROR_PATH_COMP_NOT_DIR 479 ? ENOTDIR : ENOENT; 480 return -1; 481 } 482 /** @todo implement cache refreshing. */ 483 return birdStatFollowLink(pszPath, pStat); 484 } 485 485 return 0; 486 } 487 488 kFsCacheObjRelease(g_pFsCache, pPathObj); 489 errno = ENOENT; 490 } 491 else 492 errno = enmError == KFSLOOKUPERROR_NOT_DIR 493 || enmError == KFSLOOKUPERROR_PATH_COMP_NOT_DIR 494 ? ENOTDIR : ENOENT; 495 return -1; 496 } 497 498 499 /** 500 * Invalidate missing bits of the directory cache. 501 * 502 * This is called each time a make job completes. 503 */ 504 void dir_cache_invalid_missing(void) 505 { 506 kFsCacheInvalidateMissing(g_pFsCache); 507 } 508 -
trunk/src/kmk/incdep.c
r2850 r2861 32 32 # define INCL_ERRORS 33 33 #endif 34 #ifdef KBUILD_OS_WINDOWS 35 # ifdef KMK 36 # define INCDEP_USE_KFSCACHE 37 # endif 38 #endif 34 39 35 40 #include "make.h" … … 63 68 # include <Windows.h> 64 69 # define PARSE_IN_WORKER 70 #endif 71 72 #ifdef INCDEP_USE_KFSCACHE 73 # include "nt/kFsCache.h" 74 extern PKFSCACHE g_pFsCache; /* dir-nt-bird.c for now */ 65 75 #endif 66 76 … … 146 156 struct incdep_recorded_file *recorded_file_tail; 147 157 #endif 148 158 #ifdef INCDEP_USE_KFSCACHE 159 /** Pointer to the fs cache object for this file (it exists and is a file). */ 160 PKFSOBJ pFileObj; 161 #else 149 162 char name[1]; 163 #endif 150 164 }; 151 165 … … 484 498 incdep_read_file (struct incdep *cur, struct floc *f) 485 499 { 500 #ifdef INCDEP_USE_KFSCACHE 501 size_t const cbFile = (size_t)cur->pFileObj->Stats.st_size; 502 503 assert(cur->pFileObj->fFlags); 504 cur->file_base = incdep_xmalloc (cur, cbFile + 1); 505 if (cur->file_base) 506 { 507 if (kFsCacheFileSimpleOpenReadClose (g_pFsCache, cur->pFileObj, 0, cur->file_base, cbFile)) 508 { 509 cur->file_end = cur->file_base + cbFile; 510 cur->file_base[cbFile] = '\0'; 511 return 0; 512 } 513 incdep_xfree (cur, cur->file_base); 514 } 515 error (f, "%s/%s: error reading file", cur->pFileObj->pParent->Obj.pszName, cur->pFileObj->pszName); 516 517 #else /* !INCDEP_USE_KFSCACHE */ 486 518 int fd; 487 519 struct stat st; … … 526 558 527 559 close (fd); 560 #endif /* !INCDEP_USE_KFSCACHE */ 528 561 cur->file_base = cur->file_end = NULL; 529 562 return -1; … … 541 574 542 575 incdep_xfree (cur, cur->file_base); 576 #ifdef INCDEP_USE_KFSCACHE 577 /** @todo release object ref some day... */ 578 #endif 543 579 cur->next = NULL; 544 580 free (cur); … … 890 926 891 927 if (cur->err_msg) 928 #ifdef INCDEP_USE_KFSCACHE 929 error(NILF, "%s/%s(%d): %s", cur->pFileObj->pParent->Obj.pszName, cur->pFileObj->pszName, cur->err_line_no, cur->err_msg); 930 #else 892 931 error(NILF, "%s(%d): %s", cur->name, cur->err_line_no, cur->err_msg); 932 #endif 893 933 894 934 … … 967 1007 { 968 1008 if (cur->worker_tid == -1) 1009 #ifdef INCDEP_USE_KFSCACHE 1010 error (NILF, "%s/%s(%d): %s", cur->pFileObj->pParent->Obj.pszName, cur->pFileObj->pszName, line_no, msg); 1011 #else 969 1012 error (NILF, "%s(%d): %s", cur->name, line_no, msg); 1013 #endif 970 1014 #ifdef PARSE_IN_WORKER 971 1015 else … … 1754 1798 while ((name = find_next_token (&names_iterator, &name_len)) != 0) 1755 1799 { 1800 #ifdef INCDEP_USE_KFSCACHE 1801 KFSLOOKUPERROR enmError; 1802 PKFSOBJ pFileObj = kFsCacheLookupWithLengthA (g_pFsCache, name, name_len, &enmError); 1803 if (!pFileObj) 1804 continue; 1805 if (pFileObj->bObjType != KFSOBJ_TYPE_FILE) 1806 { 1807 kFsCacheObjRelease (g_pFsCache, pFileObj); 1808 continue; 1809 } 1810 1811 cur = xmalloc (sizeof (*cur)); /* not incdep_xmalloc here */ 1812 cur->pFileObj = pFileObj; 1813 #else 1756 1814 cur = xmalloc (sizeof (*cur) + name_len); /* not incdep_xmalloc here */ 1757 cur->file_base = cur->file_end = NULL;1758 1815 memcpy (cur->name, name, name_len); 1759 1816 cur->name[name_len] = '\0'; 1817 #endif 1818 1819 cur->file_base = cur->file_end = NULL; 1760 1820 cur->worker_tid = -1; 1761 1821 #ifdef PARSE_IN_WORKER -
trunk/src/kmk/job.c
r2846 r2861 686 686 if (job_counter) 687 687 --job_counter; 688 689 # if defined(KMK) && defined(KBUILD_OS_WINDOWS) 690 /* Invalidate negative directory cache entries now that a 691 job has completed and possibly created new files that 692 was missing earlier. */ 693 extern void dir_cache_invalid_missing(void); 694 dir_cache_invalid_missing (); 695 # endif 688 696 } 689 697 else -
trunk/src/kmk/kbuild.c
r2837 r2861 29 29 * Header Files * 30 30 *******************************************************************************/ 31 #define NO_MEMCOPY_HACK 31 32 #include "make.h" 32 33 #include "filedef.h" -
trunk/src/lib/nt/kFsCache.c
r2859 r2861 160 160 161 161 /** 162 * Hashes a string. 162 * Hashes a substring. 163 * 164 * @returns 32-bit substring hash. 165 * @param pchString Pointer to the substring (not terminated). 166 * @param cchString The length of the substring. 167 */ 168 static KU32 kFsCacheStrHashN(const char *pszString, KSIZE cchString) 169 { 170 KU32 uHash = 0; 171 while (cchString-- > 0) 172 { 173 KU32 uChar = (unsigned char)*pszString++; 174 uHash = uChar + (uHash << 6) + (uHash << 16) - uHash; 175 } 176 return uHash; 177 } 178 179 180 /** 181 * Hashes a UTF-16 string. 163 182 * 164 183 * @returns The string length in wchar_t units. … … 178 197 *puHash = uHash; 179 198 return pwszString - pwszStart; 199 } 200 201 202 /** 203 * Hashes a UTF-16 substring. 204 * 205 * @returns 32-bit substring hash. 206 * @param pwcString Pointer to the substring (not terminated). 207 * @param cchString The length of the substring (in wchar_t's). 208 */ 209 static KU32 kFsCacheUtf16HashN(const wchar_t *pwcString, KSIZE cwcString) 210 { 211 KU32 uHash = 0; 212 while (cwcString-- > 0) 213 { 214 KU32 uChar = *pwcString++; 215 uHash = uChar + (uHash << 6) + (uHash << 16) - uHash; 216 } 217 return uHash; 180 218 } 181 219 … … 2351 2389 2352 2390 /** 2353 * Looks up a KFSOBJ for the given ANSI path. 2391 * Internal lookup worker that looks up a KFSOBJ for the given ANSI path with 2392 * length and hash. 2354 2393 * 2355 2394 * This will first try the hash table. If not in the hash table, the file … … 2364 2403 * NULL if not a path we care to cache. 2365 2404 * @param pCache The cache. 2366 * @param pszPath The path to lookup. 2405 * @param pchPath The path to lookup. 2406 * @param cchPath The path length. 2407 * @param uHashPath The hash of the path. 2367 2408 * @param penmError Where to return details as to why the lookup 2368 2409 * failed. 2369 2410 */ 2370 PKFSOBJ kFsCacheLookupA(PKFSCACHE pCache, const char *pszPath, KFSLOOKUPERROR *penmError) 2411 static PKFSOBJ kFsCacheLookupHashedA(PKFSCACHE pCache, const char *pchPath, KU32 cchPath, KU32 uHashPath, 2412 KFSLOOKUPERROR *penmError) 2371 2413 { 2372 2414 /* 2373 2415 * Do hash table lookup of the path. 2374 2416 */ 2375 KU32 uHashPath;2376 KU32 cchPath = (KU32)kFsCacheStrHashEx(pszPath, &uHashPath);2377 2417 KU32 idxHashTab = uHashPath % K_ELEMENTS(pCache->apAnsiPaths); 2378 2418 PKFSHASHA pHashEntry = pCache->apAnsiPaths[idxHashTab]; … … 2384 2424 if ( pHashEntry->uHashPath == uHashPath 2385 2425 && pHashEntry->cchPath == cchPath 2386 && kHlpMemComp(pHashEntry->pszPath, p szPath, cchPath) == 0)2426 && kHlpMemComp(pHashEntry->pszPath, pchPath, cchPath) == 0) 2387 2427 { 2388 2428 if ( pHashEntry->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE … … 2392 2432 pCache->cLookups++; 2393 2433 pCache->cPathHashHits++; 2394 KFSCACHE_LOG(("kFsCacheLookupA(% s) - hit %p\n", pszPath, pHashEntry->pFsObj));2434 KFSCACHE_LOG(("kFsCacheLookupA(%*.*s) - hit %p\n", cchPath, cchPath, pchPath, pHashEntry->pFsObj)); 2395 2435 *penmError = pHashEntry->enmError; 2396 2436 if (pHashEntry->pFsObj) … … 2415 2455 /* Is absolute without any '..' bits? */ 2416 2456 if ( cchPath >= 3 2417 && ( ( p szPath[1] == ':' /* Drive letter */2418 && IS_SLASH(p szPath[2])2419 && IS_ALPHA(p szPath[0]) )2420 || ( IS_SLASH(p szPath[0]) /* UNC */2421 && IS_SLASH(p szPath[1]) ) )2422 && !kFsCacheHasDotDotA(p szPath, cchPath) )2423 { 2424 pFsObj = kFsCacheLookupAbsoluteA(pCache, p szPath, cchPath, penmError);2457 && ( ( pchPath[1] == ':' /* Drive letter */ 2458 && IS_SLASH(pchPath[2]) 2459 && IS_ALPHA(pchPath[0]) ) 2460 || ( IS_SLASH(pchPath[0]) /* UNC */ 2461 && IS_SLASH(pchPath[1]) ) ) 2462 && !kFsCacheHasDotDotA(pchPath, cchPath) ) 2463 { 2464 pFsObj = kFsCacheLookupAbsoluteA(pCache, pchPath, cchPath, penmError); 2425 2465 fAbsolute = K_TRUE; 2426 2466 } 2427 2467 else 2428 2468 { 2429 pFsObj = kFsCacheLookupSlowA(pCache, p szPath, cchPath, penmError);2469 pFsObj = kFsCacheLookupSlowA(pCache, pchPath, cchPath, penmError); 2430 2470 fAbsolute = K_FALSE; 2431 2471 } … … 2434 2474 && *penmError != KFSLOOKUPERROR_PATH_TOO_LONG) 2435 2475 || *penmError == KFSLOOKUPERROR_UNSUPPORTED ) 2436 kFsCacheCreatePathHashTabEntryA(pCache, pFsObj, p szPath, cchPath, uHashPath, idxHashTab, fAbsolute, *penmError);2476 kFsCacheCreatePathHashTabEntryA(pCache, pFsObj, pchPath, cchPath, uHashPath, idxHashTab, fAbsolute, *penmError); 2437 2477 2438 2478 pCache->cLookups++; … … 2448 2488 2449 2489 /** 2450 * Looks up a KFSOBJ for the given UTF-16 path. 2490 * Internal lookup worker that looks up a KFSOBJ for the given UTF-16 path with 2491 * length and hash. 2451 2492 * 2452 2493 * This will first try the hash table. If not in the hash table, the file … … 2457 2498 * point. 2458 2499 * 2459 * @returns Reference to object corresponding to @a p szPath on success, this2500 * @returns Reference to object corresponding to @a pwcPath on success, this 2460 2501 * must be released by kFsCacheObjRelease. 2461 2502 * NULL if not a path we care to cache. 2462 2503 * @param pCache The cache. 2463 * @param pwszPath The path to lookup. 2504 * @param pwcPath The path to lookup. 2505 * @param cwcPath The length of the path (in wchar_t's). 2506 * @param uHashPath The hash of the path. 2464 2507 * @param penmError Where to return details as to why the lookup 2465 2508 * failed. 2466 2509 */ 2467 PKFSOBJ kFsCacheLookupW(PKFSCACHE pCache, const wchar_t *pwszPath, KFSLOOKUPERROR *penmError) 2510 static PKFSOBJ kFsCacheLookupHashedW(PKFSCACHE pCache, const wchar_t *pwcPath, KU32 cwcPath, KU32 uHashPath, 2511 KFSLOOKUPERROR *penmError) 2468 2512 { 2469 2513 /* 2470 2514 * Do hash table lookup of the path. 2471 2515 */ 2472 KU32 uHashPath;2473 KU32 cwcPath = (KU32)kFsCacheUtf16HashEx(pwszPath, &uHashPath);2474 2516 KU32 idxHashTab = uHashPath % K_ELEMENTS(pCache->apAnsiPaths); 2475 2517 PKFSHASHW pHashEntry = pCache->apUtf16Paths[idxHashTab]; … … 2481 2523 if ( pHashEntry->uHashPath == uHashPath 2482 2524 && pHashEntry->cwcPath == cwcPath 2483 && kHlpMemComp(pHashEntry->pwszPath, pw szPath, cwcPath) == 0)2525 && kHlpMemComp(pHashEntry->pwszPath, pwcPath, cwcPath) == 0) 2484 2526 { 2485 2527 if ( pHashEntry->uCacheGen == KFSOBJ_CACHE_GEN_IGNORE … … 2489 2531 pCache->cLookups++; 2490 2532 pCache->cPathHashHits++; 2491 KFSCACHE_LOG(("kFsCacheLookupW(% ls) - hit %p\n", pwszPath, pHashEntry->pFsObj));2533 KFSCACHE_LOG(("kFsCacheLookupW(%*.*ls) - hit %p\n", cwcPath, cwcPath, pwcPath, pHashEntry->pFsObj)); 2492 2534 *penmError = pHashEntry->enmError; 2493 2535 if (pHashEntry->pFsObj) … … 2512 2554 /* Is absolute without any '..' bits? */ 2513 2555 if ( cwcPath >= 3 2514 && ( ( pw szPath[1] == ':' /* Drive letter */2515 && IS_SLASH(pw szPath[2])2516 && IS_ALPHA(pw szPath[0]) )2517 || ( IS_SLASH(pw szPath[0]) /* UNC */2518 && IS_SLASH(pw szPath[1]) ) )2519 && !kFsCacheHasDotDotW(pw szPath, cwcPath) )2520 { 2521 pFsObj = kFsCacheLookupAbsoluteW(pCache, pw szPath, cwcPath, penmError);2556 && ( ( pwcPath[1] == ':' /* Drive letter */ 2557 && IS_SLASH(pwcPath[2]) 2558 && IS_ALPHA(pwcPath[0]) ) 2559 || ( IS_SLASH(pwcPath[0]) /* UNC */ 2560 && IS_SLASH(pwcPath[1]) ) ) 2561 && !kFsCacheHasDotDotW(pwcPath, cwcPath) ) 2562 { 2563 pFsObj = kFsCacheLookupAbsoluteW(pCache, pwcPath, cwcPath, penmError); 2522 2564 fAbsolute = K_TRUE; 2523 2565 } 2524 2566 else 2525 2567 { 2526 pFsObj = kFsCacheLookupSlowW(pCache, pw szPath, cwcPath, penmError);2568 pFsObj = kFsCacheLookupSlowW(pCache, pwcPath, cwcPath, penmError); 2527 2569 fAbsolute = K_FALSE; 2528 2570 } … … 2531 2573 && *penmError != KFSLOOKUPERROR_PATH_TOO_LONG) 2532 2574 || *penmError == KFSLOOKUPERROR_UNSUPPORTED ) 2533 kFsCacheCreatePathHashTabEntryW(pCache, pFsObj, pw szPath, cwcPath, uHashPath, idxHashTab, fAbsolute, *penmError);2575 kFsCacheCreatePathHashTabEntryW(pCache, pFsObj, pwcPath, cwcPath, uHashPath, idxHashTab, fAbsolute, *penmError); 2534 2576 2535 2577 pCache->cLookups++; … … 2541 2583 *penmError = KFSLOOKUPERROR_PATH_TOO_LONG; 2542 2584 return NULL; 2585 } 2586 2587 2588 2589 /** 2590 * Looks up a KFSOBJ for the given ANSI path. 2591 * 2592 * This will first try the hash table. If not in the hash table, the file 2593 * system cache tree is walked, missing bits filled in and finally a hash table 2594 * entry is created. 2595 * 2596 * Only drive letter paths are cachable. We don't do any UNC paths at this 2597 * point. 2598 * 2599 * @returns Reference to object corresponding to @a pszPath on success, this 2600 * must be released by kFsCacheObjRelease. 2601 * NULL if not a path we care to cache. 2602 * @param pCache The cache. 2603 * @param pszPath The path to lookup. 2604 * @param penmError Where to return details as to why the lookup 2605 * failed. 2606 */ 2607 PKFSOBJ kFsCacheLookupA(PKFSCACHE pCache, const char *pszPath, KFSLOOKUPERROR *penmError) 2608 { 2609 KU32 uHashPath; 2610 KU32 cchPath = (KU32)kFsCacheStrHashEx(pszPath, &uHashPath); 2611 return kFsCacheLookupHashedA(pCache, pszPath, cchPath, uHashPath, penmError); 2612 } 2613 2614 2615 /** 2616 * Looks up a KFSOBJ for the given UTF-16 path. 2617 * 2618 * This will first try the hash table. If not in the hash table, the file 2619 * system cache tree is walked, missing bits filled in and finally a hash table 2620 * entry is created. 2621 * 2622 * Only drive letter paths are cachable. We don't do any UNC paths at this 2623 * point. 2624 * 2625 * @returns Reference to object corresponding to @a pwszPath on success, this 2626 * must be released by kFsCacheObjRelease. 2627 * NULL if not a path we care to cache. 2628 * @param pCache The cache. 2629 * @param pwszPath The path to lookup. 2630 * @param penmError Where to return details as to why the lookup 2631 * failed. 2632 */ 2633 PKFSOBJ kFsCacheLookupW(PKFSCACHE pCache, const wchar_t *pwszPath, KFSLOOKUPERROR *penmError) 2634 { 2635 KU32 uHashPath; 2636 KU32 cwcPath = (KU32)kFsCacheUtf16HashEx(pwszPath, &uHashPath); 2637 return kFsCacheLookupHashedW(pCache, pwszPath, cwcPath, uHashPath, penmError); 2638 } 2639 2640 2641 /** 2642 * Looks up a KFSOBJ for the given ANSI path. 2643 * 2644 * This will first try the hash table. If not in the hash table, the file 2645 * system cache tree is walked, missing bits filled in and finally a hash table 2646 * entry is created. 2647 * 2648 * Only drive letter paths are cachable. We don't do any UNC paths at this 2649 * point. 2650 * 2651 * @returns Reference to object corresponding to @a pchPath on success, this 2652 * must be released by kFsCacheObjRelease. 2653 * NULL if not a path we care to cache. 2654 * @param pCache The cache. 2655 * @param pchPath The path to lookup (does not need to be nul 2656 * terminated). 2657 * @param cchPath The path length. 2658 * @param penmError Where to return details as to why the lookup 2659 * failed. 2660 */ 2661 PKFSOBJ kFsCacheLookupWithLengthA(PKFSCACHE pCache, const char *pchPath, KSIZE cchPath, KFSLOOKUPERROR *penmError) 2662 { 2663 return kFsCacheLookupHashedA(pCache, pchPath, (KU32)cchPath, kFsCacheStrHashN(pchPath, cchPath), penmError); 2664 } 2665 2666 2667 /** 2668 * Looks up a KFSOBJ for the given UTF-16 path. 2669 * 2670 * This will first try the hash table. If not in the hash table, the file 2671 * system cache tree is walked, missing bits filled in and finally a hash table 2672 * entry is created. 2673 * 2674 * Only drive letter paths are cachable. We don't do any UNC paths at this 2675 * point. 2676 * 2677 * @returns Reference to object corresponding to @a pwchPath on success, this 2678 * must be released by kFsCacheObjRelease. 2679 * NULL if not a path we care to cache. 2680 * @param pCache The cache. 2681 * @param pwcPath The path to lookup (does not need to be nul 2682 * terminated). 2683 * @param cwcPath The path length (in wchar_t's). 2684 * @param penmError Where to return details as to why the lookup 2685 * failed. 2686 */ 2687 PKFSOBJ kFsCacheLookupWithLengthW(PKFSCACHE pCache, const wchar_t *pwcPath, KSIZE cwcPath, KFSLOOKUPERROR *penmError) 2688 { 2689 return kFsCacheLookupHashedW(pCache, pwcPath, (KU32)cwcPath, kFsCacheUtf16HashN(pwcPath, cwcPath), penmError); 2543 2690 } 2544 2691 … … 3005 3152 3006 3153 #endif /* KFSCACHE_CFG_SHORT_NAMES */ 3154 3155 3156 3157 /** 3158 * Read the specified bits from the files into the given buffer, simple version. 3159 * 3160 * @returns K_TRUE on success (all requested bytes read), 3161 * K_FALSE on any kind of failure. 3162 * 3163 * @param pCache The cache. 3164 * @param pFileObj The file object. 3165 * @param offStart Where to start reading. 3166 * @param pvBuf Where to store what we read. 3167 * @param cbToRead How much to read (exact). 3168 */ 3169 KBOOL kFsCacheFileSimpleOpenReadClose(PKFSCACHE pCache, PKFSOBJ pFileObj, KU64 offStart, void *pvBuf, KSIZE cbToRead) 3170 { 3171 /* 3172 * Open the file relative to the parent directory. 3173 */ 3174 MY_NTSTATUS rcNt; 3175 HANDLE hFile; 3176 MY_IO_STATUS_BLOCK Ios; 3177 MY_OBJECT_ATTRIBUTES ObjAttr; 3178 MY_UNICODE_STRING UniStr; 3179 3180 kHlpAssertReturn(pFileObj->bObjType == KFSOBJ_TYPE_FILE, K_FALSE); 3181 kHlpAssert(pFileObj->pParent); 3182 kHlpAssertReturn(pFileObj->pParent->hDir != INVALID_HANDLE_VALUE, K_FALSE); 3183 kHlpAssertReturn(offStart == 0, K_FALSE); /** @todo when needed */ 3184 3185 Ios.Information = -1; 3186 Ios.u.Status = -1; 3187 3188 UniStr.Buffer = (wchar_t *)pFileObj->pwszName; 3189 UniStr.Length = (USHORT)(pFileObj->cwcName * sizeof(wchar_t)); 3190 UniStr.MaximumLength = UniStr.Length + sizeof(wchar_t); 3191 3192 MyInitializeObjectAttributes(&ObjAttr, &UniStr, OBJ_CASE_INSENSITIVE, pFileObj->pParent->hDir, NULL /*pSecAttr*/); 3193 3194 rcNt = g_pfnNtCreateFile(&hFile, 3195 GENERIC_READ | SYNCHRONIZE, 3196 &ObjAttr, 3197 &Ios, 3198 NULL, /*cbFileInitialAlloc */ 3199 FILE_ATTRIBUTE_NORMAL, 3200 FILE_SHARE_READ, 3201 FILE_OPEN, 3202 FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, 3203 NULL, /*pEaBuffer*/ 3204 0); /*cbEaBuffer*/ 3205 if (MY_NT_SUCCESS(rcNt)) 3206 { 3207 LARGE_INTEGER offFile; 3208 offFile.QuadPart = offStart; 3209 3210 Ios.Information = -1; 3211 Ios.u.Status = -1; 3212 rcNt = g_pfnNtReadFile(hFile, NULL /*hEvent*/, NULL /*pfnApcComplete*/, NULL /*pvApcCtx*/, &Ios, 3213 pvBuf, (KU32)cbToRead, !offStart ? &offFile : NULL, NULL /*puKey*/); 3214 if (MY_NT_SUCCESS(rcNt)) 3215 rcNt = Ios.u.Status; 3216 if (MY_NT_SUCCESS(rcNt)) 3217 { 3218 if (Ios.Information == cbToRead) 3219 { 3220 g_pfnNtClose(hFile); 3221 return K_TRUE; 3222 } 3223 KFSCACHE_LOG(("Error reading %#x bytes from '%ls': Information=%p\n", pFileObj->pwszName, Ios.Information)); 3224 } 3225 else 3226 KFSCACHE_LOG(("Error reading %#x bytes from '%ls': %#x\n", pFileObj->pwszName, rcNt)); 3227 g_pfnNtClose(hFile); 3228 } 3229 else 3230 KFSCACHE_LOG(("Error opening '%ls' for caching: %#x\n", pFileObj->pwszName, rcNt)); 3231 return K_FALSE; 3232 } 3007 3233 3008 3234 -
trunk/src/lib/nt/kFsCache.h
r2859 r2861 436 436 PKFSOBJ kFsCacheLookupRelativeToDirW(PKFSCACHE pCache, PKFSDIR pParent, const wchar_t *pwszPath, KU32 cwcPath, 437 437 KFSLOOKUPERROR *penmError); 438 PKFSOBJ kFsCacheLookupWithLengthA(PKFSCACHE pCache, const char *pchPath, KSIZE cchPath, KFSLOOKUPERROR *penmError); 439 PKFSOBJ kFsCacheLookupWithLengthW(PKFSCACHE pCache, const wchar_t *pwcPath, KSIZE cwcPath, KFSLOOKUPERROR *penmError); 438 440 PKFSOBJ kFsCacheLookupNoMissingA(PKFSCACHE pCache, const char *pszPath, KFSLOOKUPERROR *penmError); 439 441 PKFSOBJ kFsCacheLookupNoMissingW(PKFSCACHE pCache, const wchar_t *pwszPath, KFSLOOKUPERROR *penmError); … … 449 451 KBOOL kFsCacheObjGetFullShortPathW(PKFSOBJ pObj, wchar_t *pwszPath, KSIZE cwcPath, wchar_t wcSlash); 450 452 453 KBOOL kFsCacheFileSimpleOpenReadClose(PKFSCACHE pCache, PKFSOBJ pFileObj, KU64 offStart, void *pvBuf, KSIZE cbToRead); 454 451 455 PKFSCACHE kFsCacheCreate(KU32 fFlags); 452 456 void kFsCacheDestroy(PKFSCACHE); -
trunk/src/lib/nt/nthlpcore.c
r2859 r2861 46 46 PLARGE_INTEGER, ULONG, ULONG, ULONG, ULONG, PVOID, ULONG); 47 47 MY_NTSTATUS (WINAPI *g_pfnNtDeleteFile)(MY_OBJECT_ATTRIBUTES *); 48 MY_NTSTATUS (WINAPI *g_pfnNtReadFile)(HANDLE hFile, HANDLE hEvent, MY_IO_APC_ROUTINE *pfnApc, PVOID pvApcCtx, 49 MY_IO_STATUS_BLOCK *, PVOID pvBuf, ULONG cbToRead, PLARGE_INTEGER poffFile, 50 PULONG puKey); 48 51 MY_NTSTATUS (WINAPI *g_pfnNtQueryInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *, PVOID, LONG, MY_FILE_INFORMATION_CLASS); 49 52 MY_NTSTATUS (WINAPI *g_pfnNtQueryVolumeInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *, PVOID, LONG, MY_FS_INFORMATION_CLASS); … … 69 72 { (FARPROC *)&g_pfnNtCreateFile, "NtCreateFile" }, 70 73 { (FARPROC *)&g_pfnNtDeleteFile, "NtDeleteFile" }, 74 { (FARPROC *)&g_pfnNtReadFile, "NtReadFile" }, 71 75 { (FARPROC *)&g_pfnNtQueryInformationFile, "NtQueryInformationFile" }, 72 76 { (FARPROC *)&g_pfnNtQueryVolumeInformationFile, "NtQueryVolumeInformationFile" }, -
trunk/src/lib/nt/ntstuff.h
r2859 r2861 424 424 PLARGE_INTEGER, ULONG, ULONG, ULONG, ULONG, PVOID, ULONG); 425 425 extern MY_NTSTATUS (WINAPI * g_pfnNtDeleteFile)(MY_OBJECT_ATTRIBUTES *); 426 extern MY_NTSTATUS (WINAPI * g_pfnNtReadFile)(HANDLE hFile, HANDLE hEvent, MY_IO_APC_ROUTINE *pfnApc, PVOID pvApcCtx, 427 MY_IO_STATUS_BLOCK *, PVOID pvBuf, ULONG cbToRead, PLARGE_INTEGER poffFile, 428 PULONG puKey); 426 429 extern MY_NTSTATUS (WINAPI * g_pfnNtQueryInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *, 427 430 PVOID, LONG, MY_FILE_INFORMATION_CLASS);
Note:
See TracChangeset
for help on using the changeset viewer.