Changeset 960 for trunk/client/src/dircache.c
- Timestamp:
- Aug 16, 2016, 5:41:49 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/client/src/dircache.c
r958 r960 109 109 110 110 111 static int dceCreate (DirectoryCacheEntry **ppdce, DirectoryCache *pdc, const char *path, int cFiles)111 static int dceCreate (DirectoryCacheEntry **ppdce, Resource *pRes, const char *path, int cFiles) 112 112 { 113 113 DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)malloc(sizeof(DirectoryCacheEntry)); … … 128 128 pdce->ulHash = computehash (path); 129 129 pdce->ulLastUpdateTime = 0; 130 pdce->pdc = p dc;130 pdce->pdc = pRes->pdc; 131 131 pdce->fInvalid = 0; 132 132 … … 155 155 } 156 156 157 static void dceWriteEntry ( DirectoryCacheEntry *pdce, const smbwrp_fileinfo *finfo)157 static void dceWriteEntry (Resource *pRes, DirectoryCacheEntry *pdce, const smbwrp_fileinfo *finfo) 158 158 { 159 159 if (pdce->cInfos >= pdce->cInfosAllocated) … … 165 165 cNewAllocated * sizeof (smbwrp_fileinfo)); 166 166 167 debuglocal( 9, "dceWriteEntry: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated);167 debuglocal(pRes, 9, "dceWriteEntry: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated); 168 168 if (pNewInfos) 169 169 { … … 183 183 } 184 184 185 static void dceAdjust ( DirectoryCacheEntry *pdce)185 static void dceAdjust (Resource *pRes, DirectoryCacheEntry *pdce) 186 186 { 187 187 /* If the entry has too many preallocated info structures, adjust the memory allocation */ … … 196 196 cNewAllocated * sizeof (smbwrp_fileinfo)); 197 197 198 debuglocal( 9, "dceAdjust: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated);198 debuglocal(pRes, 9, "dceAdjust: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated); 199 199 if (pNewInfos) 200 200 { … … 209 209 } 210 210 211 static int dcePathEqualsTo ( DirectoryCacheEntry *pdce, const char *path)212 { 213 debuglocal( 9, "dcePathEqualTo: [%s] [%s]\n", path, pdce->pszPath);211 static int dcePathEqualsTo (Resource *pRes, DirectoryCacheEntry *pdce, const char *path) 212 { 213 debuglocal(pRes, 9, "dcePathEqualTo: [%s] [%s]\n", path, pdce->pszPath); 214 214 return ph->fsphStrICmp (path, pdce->pszPath) == 0; 215 215 } … … 225 225 } 226 226 227 static struct DirectoryCacheEntry *dcFindDirCache ( struct DirectoryCache *pdc, const char *path, int fPrefix)227 static struct DirectoryCacheEntry *dcFindDirCache (Resource *pRes, const char *path, int fPrefix) 228 228 { 229 229 unsigned long hash = computehash (path); 230 230 231 DirectoryCacheEntry *iter = p dc->pEntriesHead;232 233 debuglocal( 9, "findDirCache: [%s]\n", path);231 DirectoryCacheEntry *iter = pRes->pdc->pEntriesHead; 232 233 debuglocal(pRes, 9, "findDirCache: [%s]\n", path); 234 234 235 235 while (iter != NULL) 236 236 { 237 debuglocal( 9, "findDirCache: entry [%s]\n", iter->pszPath);237 debuglocal(pRes, 9, "findDirCache: entry [%s]\n", iter->pszPath); 238 238 if (fPrefix) 239 239 { … … 246 246 { 247 247 if ( iter->ulHash == hash 248 && dcePathEqualsTo ( iter, path)248 && dcePathEqualsTo (pRes, iter, path) 249 249 ) 250 250 { … … 255 255 } 256 256 257 debuglocal( 9, "findDirCache: %p\n", iter);257 debuglocal(pRes, 9, "findDirCache: %p\n", iter); 258 258 259 259 return iter; … … 363 363 }; 364 364 365 static int dcExistsInCache ( DirectoryCache *pdc, const char *path)365 static int dcExistsInCache (Resource *pRes, const char *path) 366 366 { 367 367 int rc = CacheFault; 368 368 369 if (p dc->fEnabled)370 { 371 if (dcFindDirCache (p dc, path, 0) != NULL)369 if (pRes->pdc->fEnabled) 370 { 371 if (dcFindDirCache (pRes, path, 0) != NULL) 372 372 { 373 373 rc = CacheOk; 374 374 } 375 375 376 debuglocal( 9, "ExistsInCache: [%s], %d\n", path, rc);376 debuglocal(pRes, 9, "ExistsInCache: [%s], %d\n", path, rc); 377 377 } 378 378 … … 380 380 } 381 381 382 static int dcRead ( DirectoryCache *pdc, const char *path,382 static int dcRead (Resource *pRes, const char *path, 383 383 PFNADDDIRENTRY fn, 384 384 filelist_state *state, … … 387 387 int i; 388 388 389 DirectoryCache *pdc = pRes->pdc; 389 390 int rc = CacheFault; 390 391 … … 393 394 DirectoryCacheEntry *pdce; 394 395 395 pdce = dcFindDirCache (p dc, path, 0);396 pdce = dcFindDirCache (pRes, path, 0); 396 397 397 398 if (pdce) 398 399 { 399 debuglocal( 9, "CacheRead: entry %p found for [%s]\n", pdce, path);400 debuglocal(pRes, 9, "CacheRead: entry %p found for [%s]\n", pdce, path); 400 401 401 402 if (fForceCache) … … 412 413 if (dceExpired (pdce, pdc->ulExpirationTime)) 413 414 { 414 debuglocal( 9, "CacheRead: expired\n");415 debuglocal(pRes, 9, "CacheRead: expired\n"); 415 416 dcRemoveEntry (pdce); 416 417 dceDelete (pdce); … … 433 434 } 434 435 435 debuglocal( 9, "CacheRead: [%s], %d\n", path, rc);436 debuglocal(pRes, 9, "CacheRead: [%s], %d\n", path, rc); 436 437 } 437 438 … … 439 440 } 440 441 441 static DirectoryCacheEntry *dcWriteBegin ( DirectoryCache *pdc, const char *path, int cFiles)442 static DirectoryCacheEntry *dcWriteBegin (Resource *pRes, const char *path, int cFiles) 442 443 { 443 444 DirectoryCacheEntry *pdce = NULL; 444 445 445 if (p dc->fEnabled)446 { 447 pdce = dcFindDirCache (p dc, path, 0);446 if (pRes->pdc->fEnabled) 447 { 448 pdce = dcFindDirCache (pRes, path, 0); 448 449 449 450 if (!pdce) 450 451 { 451 452 /* Does not exist in the cache yet. */ 452 dceCreate (&pdce, p dc, path, cFiles);453 dceCreate (&pdce, pRes, path, cFiles); 453 454 } 454 455 else … … 465 466 } 466 467 467 debuglocal( 9, "CacheWriteBegin: %s\n", path);468 debuglocal(pRes, 9, "CacheWriteBegin: %s\n", path); 468 469 } 469 470 … … 472 473 473 474 474 static void dcInvalidate ( DirectoryCache *pdc, const char *path, int fPrefix)475 static void dcInvalidate (Resource *pRes, const char *path, int fPrefix) 475 476 { 476 477 DirectoryCacheEntry *pdce; 477 478 478 debuglocal( 9, "CacheInvalidate: [%s]\n", path);479 480 pdce = dcFindDirCache (p dc, path, fPrefix);479 debuglocal(pRes, 9, "CacheInvalidate: [%s]\n", path); 480 481 pdce = dcFindDirCache (pRes, path, fPrefix); 481 482 482 483 while (pdce) … … 485 486 dceDelete (pdce); 486 487 487 pdce = dcFindDirCache (p dc, path, fPrefix);488 } 489 } 490 491 static int dcFindPath ( DirectoryCache *pdc,488 pdce = dcFindDirCache (pRes, path, fPrefix); 489 } 490 } 491 492 static int dcFindPath (Resource *pRes, DirectoryCache *pdc, 492 493 const char *path, 493 494 const char *parent, … … 500 501 unsigned long hash = computehash (parent); 501 502 502 debuglocal( 9, "dcFindPath: [%s][%s]\n", parent, name);503 debuglocal(pRes, 9, "dcFindPath: [%s][%s]\n", parent, name); 503 504 504 505 while (pdce != NULL) 505 506 { 506 debuglocal( 9, "dcFindPath: entry [%s]\n", pdce->pszPath);507 debuglocal(pRes, 9, "dcFindPath: entry [%s]\n", pdce->pszPath); 507 508 508 509 if ( pdce->ulHash == hash 509 && dcePathEqualsTo (p dce, parent))510 && dcePathEqualsTo (pRes, pdce, parent)) 510 511 { 511 512 /* This entry should contain the path. */ … … 517 518 *finfo = pdce->aInfos[i]; 518 519 *pulAge = timesec () - pdce->ulLastUpdateTime; 519 debuglocal( 9, "dircache: FindPath %s found, age %d\n", path, *pulAge);520 debuglocal(pRes, 9, "dircache: FindPath %s found, age %d\n", path, *pulAge); 520 521 return 1; 521 522 } … … 526 527 } 527 528 528 debuglocal( 9, "dircache: FindPath %s not found\n", path);529 debuglocal(pRes, 9, "dircache: FindPath %s not found\n", path); 529 530 return 0; 530 531 } … … 561 562 */ 562 563 563 int dircache_create(DirectoryCache **ppdc, unsigned long ulExpirationTime, int cMaxEntries) 564 { 564 int dircache_create(Resource *pRes) 565 { 566 struct DirectoryCache **ppdc = &pRes->pdc; 567 unsigned long ulExpirationTime = pRes->cachetimeout; 568 int cMaxEntries = pRes->cachedepth; 565 569 int rc; 566 570 567 debuglocal( 9, "dircache_create: %u seconds, %d entries\n", ulExpirationTime, cMaxEntries);571 debuglocal(pRes, 9, "dircache_create: %u seconds, %d entries\n", ulExpirationTime, cMaxEntries); 568 572 569 573 rc = dcCreate(ppdc); … … 574 578 } 575 579 576 debuglocal( 9, "dircache_create: %p, rc = %d\n", *ppdc, rc);580 debuglocal(pRes, 9, "dircache_create: %p, rc = %d\n", *ppdc, rc); 577 581 return rc; 578 582 } 579 583 580 void dircache_delete(DirectoryCache *pdc) 581 { 582 debuglocal(9, "dircache_delete: %p\n", pdc); 584 void dircache_delete(Resource *pRes) 585 { 586 DirectoryCache *pdc = pRes->pdc; 587 debuglocal(pRes, 9, "dircache_delete: %p\n", pdc); 583 588 584 589 if (pdc) … … 603 608 } 604 609 605 debuglocal( 9, "dircache_list_files [%s]\n", path);610 debuglocal(state->pConn->pRes, 9, "dircache_list_files [%s]\n", path); 606 611 607 612 if (!pdc) … … 612 617 lockRequest (pdc->mutex); 613 618 614 rc = dcRead ( pdc, path, fn, state, ptotal_received, 0);619 rc = dcRead (state->pConn->pRes, path, fn, state, ptotal_received, 0); 615 620 616 621 lockRelease (pdc->mutex); … … 632 637 } 633 638 634 debuglocal( 9, "dircache_write_begin pdc %p path [%s]\n", pdc, path);639 debuglocal(state->pConn->pRes, 9, "dircache_write_begin pdc %p path [%s]\n", pdc, path); 635 640 636 641 if (!pdc) … … 650 655 } 651 656 652 pdce = dcWriteBegin ( pdc, path, cFiles);657 pdce = dcWriteBegin (state->pConn->pRes, path, cFiles); 653 658 654 659 lockRelease (pdc->mutex); 655 660 656 debuglocal( 9, "dircache_write_begin returning ctx %p\n", pdce);661 debuglocal(state->pConn->pRes, 9, "dircache_write_begin returning ctx %p\n", pdce); 657 662 return (void *)pdce; 658 663 } 659 664 660 void dircache_write_entry( void *dircachectx, const smbwrp_fileinfo *finfo)665 void dircache_write_entry(Resource *pRes, void *dircachectx, const smbwrp_fileinfo *finfo) 661 666 { 662 667 DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx; 663 668 664 debuglocal( 9, "dircache_write_entry %p\n", pdce);669 debuglocal(pRes, 9, "dircache_write_entry %p\n", pdce); 665 670 666 671 if (!pdce) … … 671 676 lockRequest (pdce->pdc->mutex); 672 677 673 dceWriteEntry (p dce, finfo);678 dceWriteEntry (pRes, pdce, finfo); 674 679 675 680 lockRelease (pdce->pdc->mutex); 676 681 } 677 682 678 void dircache_write_end( void *dircachectx)683 void dircache_write_end(Resource *pRes, void *dircachectx) 679 684 { 680 685 DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx; 681 686 DirectoryCache *pdc; 682 687 683 debuglocal( 9, "dircache_write_end: pdce %p\n", pdce);688 debuglocal(pRes, 9, "dircache_write_end: pdce %p\n", pdce); 684 689 685 690 if (!pdce) … … 699 704 else 700 705 { 701 dceAdjust (p dce);706 dceAdjust (pRes, pdce); 702 707 dcInsertEntry (pdce); 703 708 } … … 707 712 708 713 void dircache_invalidate(const char *path, 709 struct DirectoryCache *pdc,714 Resource *pRes, 710 715 int fParent) 711 716 { 712 debuglocal(9, "dircache_invalidate [%s], parent %d\n", path, fParent); 717 struct DirectoryCache *pdc = pRes->pdc; 718 debuglocal(pRes, 9, "dircache_invalidate [%s], parent %d\n", path, fParent); 713 719 714 720 if (!pdc) … … 728 734 { 729 735 *lastSlash = 0; 730 dcInvalidate (p dc, p, 0);736 dcInvalidate (pRes, p, 0); 731 737 } 732 738 else 733 739 { 734 dcInvalidate (p dc, "", 0);740 dcInvalidate (pRes, "", 0); 735 741 } 736 742 } 737 743 else 738 744 { 739 dcInvalidate (p dc, path, 0);745 dcInvalidate (pRes, path, 0); 740 746 } 741 747 … … 745 751 } 746 752 747 int dircache_find_path( struct DirectoryCache *pdc,753 int dircache_find_path(Resource *pRes, 748 754 const char *path, 749 755 smbwrp_fileinfo *finfo, 750 756 unsigned long *pulAge) 751 757 { 758 struct DirectoryCache *pdc = pRes->pdc; 752 759 int cb; 753 760 char *p; … … 755 762 int fFound = 0; 756 763 757 debuglocal( 9, "dircache_find_path [%s]\n", path);764 debuglocal(pRes, 9, "dircache_find_path [%s]\n", path); 758 765 759 766 if (!pdc) … … 778 785 { 779 786 *lastSlash = 0; 780 fFound = dcFindPath (p dc, path, p, lastSlash + 1, finfo, pulAge);787 fFound = dcFindPath (pRes, pdc, path, p, lastSlash + 1, finfo, pulAge); 781 788 } 782 789 else 783 790 { 784 791 /* Find in the root directory. p is the name. */ 785 fFound = dcFindPath (p dc, path, "", p, finfo, pulAge);792 fFound = dcFindPath (pRes, pdc, path, "", p, finfo, pulAge); 786 793 } 787 794
Note:
See TracChangeset
for help on using the changeset viewer.