Changeset 975
- Timestamp:
- Aug 26, 2016, 6:57:36 PM (9 years ago)
- Location:
- trunk/client/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/client/src/dircache.c
r969 r975 79 79 } 80 80 81 pdce->aInfos = (smbwrp_fileinfo *)malloc(cFiles * sizeof (smbwrp_fileinfo)); 81 pdce->aInfos = (DirectoryCacheEntryData *) 82 malloc(cFiles * sizeof (DirectoryCacheEntryData)); 82 83 if (!pdce->aInfos) 83 84 { … … 103 104 } 104 105 105 static void dceDelete (DirectoryCacheEntry *pdce) 106 { 106 static void dceDelete (DirectoryCache *pdc, DirectoryCacheEntry *pdce) 107 { 108 int i; 109 110 debuglocal(pdc->resource, 9, "dceDelete: pdc %p, pdce %p\n", pdc, pdce); 111 112 /* use plugin callback to deallocate memory stored into aInfos */ 113 if (pdc->release) 114 for (i = 0; i < pdce->cInfos; i++) 115 { 116 debuglocal(pdc->resource, 9, "dceDelete: #%d->%s->%p\n", 117 i, pdce->aInfos[i].fname, pdce->aInfos[i].customData); 118 pdc->release( (void*)pdce->aInfos[i].customData); 119 } 120 121 /* now free dce local data */ 107 122 free(pdce->aInfos); 108 123 free(pdce->pszPath); … … 115 130 } 116 131 117 static void dceWriteEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce, const smbwrp_fileinfo *finfo) 132 static void dceWriteEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce, 133 const char *fname, const void *finfo) 118 134 { 119 135 if (pdce->cInfos >= pdce->cInfosAllocated) … … 122 138 int cNewAllocated = pdce->cInfosAllocated + pdce->cInfosAllocated / 2 + 1; 123 139 124 smbwrp_fileinfo *pNewInfos = (smbwrp_fileinfo *)realloc(pdce->aInfos, 125 cNewAllocated * sizeof (smbwrp_fileinfo)); 140 DirectoryCacheEntryData *pNewInfos = (DirectoryCacheEntryData *) 141 realloc(pdce->aInfos, cNewAllocated * 142 sizeof (DirectoryCacheEntryData)); 126 143 127 144 debuglocal(pdc->resource, 9, "dceWriteEntry: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated); … … 139 156 } 140 157 141 pdce->aInfos[pdce->cInfos] = *finfo; 158 // store entry name and custom data 159 strcpy( (char*)pdce->aInfos[pdce->cInfos].fname, fname); 160 pdce->aInfos[pdce->cInfos].customData = finfo; 142 161 pdce->cInfos++; 143 162 } … … 153 172 int cNewAllocated = pdce->cInfos + cFree / 2; 154 173 155 smbwrp_fileinfo *pNewInfos = (smbwrp_fileinfo *)realloc(pdce->aInfos, 156 cNewAllocated * sizeof (smbwrp_fileinfo)); 174 DirectoryCacheEntryData *pNewInfos = (DirectoryCacheEntryData *) 175 realloc(pdce->aInfos, 176 cNewAllocated * sizeof (DirectoryCacheEntryData)); 157 177 158 178 debuglocal(pdc->resource, 9, "dceAdjust: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated); … … 191 211 DirectoryCacheEntry *iter = pdc->pEntriesHead; 192 212 193 debuglocal(pdc->resource, 9, "findDirCache: [%s]\n", path); 213 debuglocal(pdc->resource, 9, "dcFindDirCache: [%s]\n", path); 214 debuglocal(pdc->resource, 9, "dcFindDirCache: iter [%p]\n", iter); 194 215 195 216 while (iter != NULL) 196 217 { 197 debuglocal(pdc->resource, 9, " findDirCache: entry [%s]\n", iter->pszPath);218 debuglocal(pdc->resource, 9, "dcFindDirCache: entry [%s]\n", iter->pszPath); 198 219 if (fPrefix) 199 220 { … … 215 236 } 216 237 217 debuglocal(pdc->resource, 9, " findDirCache: %p\n", iter);238 debuglocal(pdc->resource, 9, "dcFindDirCache: %p\n", iter); 218 239 219 240 return iter; … … 253 274 { 254 275 DirectoryCacheEntry *iter = pdc->pEntriesHead; 276 debuglocal(pdc->resource, 9, "dcDelete: pdc %p, iter %p\n", pdc, iter); 255 277 256 278 while (iter != NULL) … … 258 280 DirectoryCacheEntry *next = iter->pNext; 259 281 260 dceDelete ( iter);282 dceDelete (pdc, iter); 261 283 262 284 iter = next; … … 357 379 for (i = 0; i < pdce->cInfos; i++) 358 380 { 359 fn ( "", &pdce->aInfos[i], path, plist);381 fn (plist, (void*)pdce->aInfos[i].customData); 360 382 } 361 383 … … 368 390 debuglocal(pdc->resource, 9, "dcRead: expired\n"); 369 391 dcRemoveEntry (pdc, pdce); 370 dceDelete (pdc e);392 dceDelete (pdc, pdce); 371 393 } 372 394 else 373 395 { 396 debuglocal(pdc->resource, 9, "dcRead: adding %d entries from cache\n", pdce->cInfos); 374 397 for (i = 0; i < pdce->cInfos; i++) 375 398 { 376 fn ("", &pdce->aInfos[i], path, plist); 399 debuglocal(pdc->resource, 9, "dcRead: #%d->%s->%p\n", 400 i, pdce->aInfos[i].fname, pdce->aInfos[i].customData); 401 fn (plist, (void*)pdce->aInfos[i].customData); 377 402 } 378 403 … … 437 462 { 438 463 dcRemoveEntry (pdc, pdce); 439 dceDelete (pdc e);464 dceDelete (pdc, pdce); 440 465 441 466 pdce = dcFindDirCache (pdc, path, fPrefix); … … 447 472 const char *parent, 448 473 const char *name, 449 smbwrp_fileinfo*finfo,474 void **finfo, 450 475 unsigned long *pulAge) 451 476 { … … 469 494 if (ph->fsphStrICmp (pdce->aInfos[i].fname, name) == 0) 470 495 { 471 *finfo = pdce->aInfos[i];496 *finfo = (void*) pdce->aInfos[i].customData; 472 497 *pulAge = timesec () - pdce->ulLastUpdateTime; 473 debuglocal(pdc->resource, 9, "d ircache: FindPath %s found, age %d\n", path, *pulAge);498 debuglocal(pdc->resource, 9, "dcFindPath: FindPath %s found, age %d\n", path, *pulAge); 474 499 return 1; 475 500 } … … 480 505 } 481 506 482 debuglocal(pdc->resource, 9, "d ircache: FindPath %s not found\n", path);507 debuglocal(pdc->resource, 9, "dcFindPath: FindPath %s not found\n", path); 483 508 return 0; 484 509 } … … 516 541 517 542 int dircache_create( DirectoryCache **ppdc, void* pRes, 518 int cachetimeout, int cachedepth )543 int cachetimeout, int cachedepth, PFNFREEDIRENTRY _release) 519 544 { 520 545 unsigned long ulExpirationTime = cachetimeout; … … 527 552 if (rc == NO_ERROR) 528 553 { 554 (*ppdc)->release = _release; 529 555 dcEnable (*ppdc, 1, ulExpirationTime, cMaxEntries); 530 556 … … 554 580 int cbPath = strlen(fullpath) + 1; 555 581 char *path = (char*) alloca(cbPath); 582 debuglocal(pdc->resource, 9, "dircache_list_files pdc %p, dir_mask [%s], fullpath [%s]\n", 583 pdc, dir_mask, fullpath); 584 556 585 if (!dcCreateDirPath(path, cbPath, dir_mask, fullpath)) 557 586 { 587 debuglocal(pdc->resource, 9, "dircache_list_files pdc %p, dcCreateDirPath failed\n", 588 pdc); 558 589 return 0; 559 590 } … … 571 602 lockRelease (pdc->mutex); 572 603 604 debuglocal(pdc->resource, 9, "dircache_list_files rc=%d\n", (rc == CacheOk)); 573 605 return (rc == CacheOk); 574 606 } … … 579 611 { 580 612 DirectoryCacheEntry *pdce = NULL; 613 debuglocal(pdc->resource, 9, "dircache_write_begin pdc %p path [%s]\n", pdc, fullpath); 581 614 582 615 int cbPath = strlen(fullpath) + 1; … … 584 617 if (!dcCreateDirPath(path, cbPath, dir_mask, fullpath)) 585 618 { 586 return NULL; 587 } 588 589 debuglocal(pdc->resource, 9, "dircache_write_begin pdc %p path [%s]\n", pdc, path); 590 591 if (!pdc) 592 { 619 debuglocal(pdc->resource, 9, "dircache_write_begin dcCreateDirPath failed\n"); 593 620 return NULL; 594 621 } … … 601 628 pdce = pdc->pEntriesTail; 602 629 dcRemoveEntry (pdc, pdce); 603 dceDelete (pdc e);630 dceDelete (pdc, pdce); 604 631 pdce = NULL; 605 632 } … … 614 641 615 642 void dircache_write_entry(DirectoryCache *pdc, void *dircachectx, 616 const smbwrp_fileinfo*finfo)643 const char *fname, const void *finfo) 617 644 { 618 645 DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx; … … 627 654 lockRequest (pdc->mutex); 628 655 629 dceWriteEntry (pdc, pdce, f info);656 dceWriteEntry (pdc, pdce, fname, finfo); 630 657 631 658 lockRelease (pdc->mutex); … … 648 675 { 649 676 /* Something happened during writing to the entry. Delete it. */ 650 dceDelete (pdc e);677 dceDelete (pdc, pdce); 651 678 } 652 679 else … … 702 729 int dircache_find_path(DirectoryCache *pdc, 703 730 const char *path, 704 smbwrp_fileinfo*finfo,731 void **finfo, 705 732 unsigned long *pulAge) 706 733 { … … 745 772 lockRelease (pdc->mutex); 746 773 774 debuglocal(pdc->resource, 9, "dircache_find_path fFound %d\n", fFound); 747 775 return fFound; 748 776 } -
trunk/client/src/dircache.h
r969 r975 13 13 #include <ndextpl2.h> 14 14 15 // 16 // enable if not defined in your plugin 17 // 18 // dircache code uses only the fname field to scan the directory listing. 19 // other fields are just passed to FNADD callback as are. 20 // 21 #if 0 22 typedef struct smbwrp_fileinfo 15 16 /* callback for fsphAddFile32L */ 17 typedef void FNADDDIRENTRY(void *plist, void *finfo); 18 typedef FNADDDIRENTRY *PFNADDDIRENTRY; 19 20 /* callback for releasing memory */ 21 typedef void FNFREEDIRENTRY(void *finfo); 22 typedef FNFREEDIRENTRY *PFNFREEDIRENTRY; 23 24 25 /* 26 * An entry holds file name and a pointer to custom data 27 */ 28 typedef struct DirectoryCacheEntryData 23 29 { 24 unsigned long long size; 25 unsigned long mtime; 26 unsigned type; 27 char fname[PATH_MAX]; 28 } smbwrp_fileinfo; 29 #else 30 31 // define as forward reference here 32 typedef struct smbwrp_fileinfo smbwrp_fileinfo; 33 34 #endif 30 const char fname[PATH_MAX]; 31 const void* customData; 32 } DirectoryCacheEntryData; 35 33 36 34 /* … … 42 40 struct DirectoryCacheEntry *pPrev; 43 41 44 smbwrp_fileinfo*aInfos;42 DirectoryCacheEntryData *aInfos; 45 43 int cInfos; 46 44 int cInfosAllocated; … … 64 62 // resource handle, used only for per-share logging 65 63 void* resource; 64 // callback called to release data structures 65 PFNFREEDIRENTRY release; 66 66 67 } DirectoryCache; 67 68 … … 73 74 74 75 /* Directory cache helpers. */ 75 int dircache_create(DirectoryCache **ppdc, void* pRes, int cachetimeout, int cachedepth); 76 int dircache_create(DirectoryCache **ppdc, void* pRes, int cachetimeout, int cachedepth, 77 PFNFREEDIRENTRY fn); 76 78 void dircache_delete(DirectoryCache *pdc); 77 78 /* callback for fsphAddFile32L */79 typedef void FNADDDIRENTRY(const char *mnt, smbwrp_fileinfo *finfo,80 const char *mask, void *state);81 typedef FNADDDIRENTRY *PFNADDDIRENTRY;82 79 83 80 /* directory cache scanning */ … … 88 85 int dircache_find_path(DirectoryCache *pdc, 89 86 const char *path, 90 smbwrp_fileinfo*finfo,87 void **finfo, 91 88 unsigned long *pulAge); 92 89 … … 96 93 int cFiles); 97 94 void dircache_write_entry(DirectoryCache *pdc, void *dircachectx, 98 const smbwrp_fileinfo*finfo);95 const char *fname, const void *finfo); 99 96 void dircache_write_end(DirectoryCache *pdc, void *dircachectx); 100 97
Note:
See TracChangeset
for help on using the changeset viewer.