- Timestamp:
- Dec 30, 2016, 9:42:50 AM (9 years ago)
- Location:
- branches/client-3.0/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/client-3.0/src/dircache.c
r1002 r1003 1 /*2 Directory caching code for Netdrive plugins.3 Copyright (C) netlabs.org 2010-20164 */5 6 1 #include <stdio.h> 7 2 #include <stdlib.h> … … 10 5 #include <time.h> 11 6 12 #include "dircache.h" 13 14 PLUGINHELPERTABLE2L *ph; 7 #define NDPL_LARGEFILES 8 #define INCL_LONGLONG 9 #include <ndextpl2.h> 10 11 #include "smbwrp.h" 12 13 extern PLUGINHELPERTABLE2L *ph; 15 14 16 15 /* 17 * An entry holds file name and a pointer to custom data16 * Static helpers. 18 17 */ 19 typedef struct DirectoryCacheEntryData 20 { 21 const char fname[PATH_MAX]; 22 const void* customData; 23 } DirectoryCacheEntryData; 18 static int lockCreate (NDMUTEX *pMutex) 19 { 20 return ph->fsphCreateMutex (pMutex); 21 } 22 23 static void lockDelete (NDMUTEX mutex) 24 { 25 ph->fsphCloseMutex (mutex); 26 } 27 28 static int lockRequest (NDMUTEX mutex) 29 { 30 return ph->fsphRequestMutex (mutex, 10000); 31 } 32 33 void lockRelease (NDMUTEX mutex) 34 { 35 ph->fsphReleaseMutex (mutex); 36 } 37 38 static ULONG Hash (const char *pData, ULONG ulLen) 39 { 40 ULONG hash = 0ul, g; 41 static ULONG ulHashModule = 30031ul; 42 43 const char *p; 44 int i; 45 for( p = pData, i = 0; i < ulLen; i++, p++ ) 46 { 47 hash = ( hash << 4 ) + (*p); 48 g = hash & 0xf0000000ul; 49 if ( g ) 50 { 51 hash ^= ( g >> 24 ); 52 hash ^= g; 53 } 54 } 55 return ( hash % ulHashModule ); 56 } 57 58 static unsigned long timesec (void) 59 { 60 ULONG ul = 0; 61 DosQuerySysInfo (QSV_TIME_LOW, QSV_TIME_LOW, &ul, sizeof (ul)); 62 return ul; 63 } 64 65 static unsigned long computehash (const char *s) 66 { 67 return s? Hash ((char *)s, strlen (s)): 0; 68 } 69 70 24 71 25 72 /* … … 31 78 struct DirectoryCacheEntry *pPrev; 32 79 33 DirectoryCacheEntryData *aInfos; 80 struct DirectoryCache *pdc; 81 82 smbwrp_fileinfo *aInfos; 34 83 int cInfos; 35 84 int cInfosAllocated; … … 48 97 DirectoryCacheEntry *pEntriesTail; 49 98 int cEntries; 99 50 100 int fEnabled; 51 101 unsigned long ulExpirationTime; 52 102 int cMaxEntries; 53 // resource handle, used only for per-share logging54 void* resource;55 // callback called to release data structures56 PFNFREEDIRENTRY release;57 58 103 } DirectoryCache; 59 104 … … 62 107 CacheOk = 1 63 108 }; 64 65 /* 66 * Static helpers. 67 */ 68 static int lockCreate (NDMUTEX *pMutex) 69 { 70 return ph->fsphCreateMutex (pMutex); 71 } 72 73 static void lockDelete (NDMUTEX mutex) 74 { 75 ph->fsphCloseMutex (mutex); 76 } 77 78 static int lockRequest (NDMUTEX mutex) 79 { 80 return ph->fsphRequestMutex (mutex, 10000); 81 } 82 83 void lockRelease (NDMUTEX mutex) 84 { 85 ph->fsphReleaseMutex (mutex); 86 } 87 88 static ULONG Hash (const char *pData, ULONG ulLen) 89 { 90 ULONG hash = 0ul, g; 91 static ULONG ulHashModule = 30031ul; 92 93 const char *p; 94 int i; 95 for( p = pData, i = 0; i < ulLen; i++, p++ ) 96 { 97 hash = ( hash << 4 ) + (*p); 98 g = hash & 0xf0000000ul; 99 if ( g ) 100 { 101 hash ^= ( g >> 24 ); 102 hash ^= g; 103 } 104 } 105 return ( hash % ulHashModule ); 106 } 107 108 static unsigned long timesec (void) 109 { 110 ULONG ul = 0; 111 DosQuerySysInfo (QSV_TIME_LOW, QSV_TIME_LOW, &ul, sizeof (ul)); 112 return ul; 113 } 114 115 static unsigned long computehash (const char *s) 116 { 117 return s? Hash ((char *)s, strlen (s)): 0; 118 } 119 120 static int dceCreate (DirectoryCacheEntry **ppdce, DirectoryCache* pdc, const char *path, int cFiles) 109 110 111 static int dceCreate (DirectoryCacheEntry **ppdce, DirectoryCache *pdc, const char *path, int cFiles) 121 112 { 122 113 DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)malloc(sizeof(DirectoryCacheEntry)); … … 127 118 } 128 119 129 pdce->aInfos = (DirectoryCacheEntryData *) 130 malloc(cFiles * sizeof (DirectoryCacheEntryData)); 120 pdce->aInfos = (smbwrp_fileinfo *)malloc(cFiles * sizeof (smbwrp_fileinfo)); 131 121 if (!pdce->aInfos) 132 122 { … … 138 128 pdce->ulHash = computehash (path); 139 129 pdce->ulLastUpdateTime = 0; 130 pdce->pdc = pdc; 140 131 pdce->fInvalid = 0; 141 132 … … 152 143 } 153 144 154 static void dceDelete (DirectoryCache *pdc, DirectoryCacheEntry *pdce) 155 { 156 int i; 157 158 debuglocal(pdc->resource, 9, "dceDelete: pdc %p, pdce %p\n", pdc, pdce); 159 160 /* use plugin callback to deallocate memory stored into aInfos */ 161 if (pdc->release) 162 for (i = 0; i < pdce->cInfos; i++) 163 { 164 debuglocal(pdc->resource, 9, "dceDelete: #%d->%s->%p\n", 165 i, pdce->aInfos[i].fname, pdce->aInfos[i].customData); 166 pdc->release( (void*)pdce->aInfos[i].customData); 167 } 168 169 /* now free dce local data */ 145 static void dceDelete (DirectoryCacheEntry *pdce) 146 { 170 147 free(pdce->aInfos); 171 148 free(pdce->pszPath); … … 178 155 } 179 156 180 static void dceWriteEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce, 181 const char *fname, const void *finfo) 157 static void dceWriteEntry (DirectoryCacheEntry *pdce, const smbwrp_fileinfo *finfo) 182 158 { 183 159 if (pdce->cInfos >= pdce->cInfosAllocated) … … 186 162 int cNewAllocated = pdce->cInfosAllocated + pdce->cInfosAllocated / 2 + 1; 187 163 188 DirectoryCacheEntryData *pNewInfos = (DirectoryCacheEntryData *) 189 realloc(pdce->aInfos, cNewAllocated * 190 sizeof (DirectoryCacheEntryData)); 191 192 debuglocal(pdc->resource, 9, "dceWriteEntry: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated); 164 smbwrp_fileinfo *pNewInfos = (smbwrp_fileinfo *)realloc(pdce->aInfos, 165 cNewAllocated * sizeof (smbwrp_fileinfo)); 166 167 debuglocal(9, "dceWriteEntry: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated); 193 168 if (pNewInfos) 194 169 { … … 204 179 } 205 180 206 // store entry name and custom data 207 strcpy( (char*)pdce->aInfos[pdce->cInfos].fname, fname); 208 pdce->aInfos[pdce->cInfos].customData = finfo; 181 pdce->aInfos[pdce->cInfos] = *finfo; 209 182 pdce->cInfos++; 210 183 } 211 184 212 static void dceAdjust (DirectoryCache *pdc, DirectoryCacheEntry *pdce)185 static void dceAdjust (DirectoryCacheEntry *pdce) 213 186 { 214 187 /* If the entry has too many preallocated info structures, adjust the memory allocation */ … … 220 193 int cNewAllocated = pdce->cInfos + cFree / 2; 221 194 222 DirectoryCacheEntryData *pNewInfos = (DirectoryCacheEntryData *) 223 realloc(pdce->aInfos, 224 cNewAllocated * sizeof (DirectoryCacheEntryData)); 225 226 debuglocal(pdc->resource, 9, "dceAdjust: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated); 195 smbwrp_fileinfo *pNewInfos = (smbwrp_fileinfo *)realloc(pdce->aInfos, 196 cNewAllocated * sizeof (smbwrp_fileinfo)); 197 198 debuglocal(9, "dceAdjust: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated); 227 199 if (pNewInfos) 228 200 { … … 237 209 } 238 210 239 static int dcePathEqualsTo (DirectoryCache *pdc, DirectoryCacheEntry *pdce, const char *path)240 { 241 debuglocal( pdc->resource,9, "dcePathEqualTo: [%s] [%s]\n", path, pdce->pszPath);211 static int dcePathEqualsTo (DirectoryCacheEntry *pdce, const char *path) 212 { 213 debuglocal(9, "dcePathEqualTo: [%s] [%s]\n", path, pdce->pszPath); 242 214 return ph->fsphStrICmp (path, pdce->pszPath) == 0; 243 215 } … … 253 225 } 254 226 255 static struct DirectoryCacheEntry *dcFindDirCache ( DirectoryCache *pdc, const char *path, int fPrefix)227 static struct DirectoryCacheEntry *dcFindDirCache (struct DirectoryCache *pdc, const char *path, int fPrefix) 256 228 { 257 229 unsigned long hash = computehash (path); … … 259 231 DirectoryCacheEntry *iter = pdc->pEntriesHead; 260 232 261 debuglocal(pdc->resource, 9, "dcFindDirCache: [%s]\n", path); 262 debuglocal(pdc->resource, 9, "dcFindDirCache: iter [%p]\n", iter); 233 debuglocal(9, "findDirCache: [%s]\n", path); 263 234 264 235 while (iter != NULL) 265 236 { 266 debuglocal( pdc->resource, 9, "dcFindDirCache: entry [%s]\n", iter->pszPath);237 debuglocal(9, "findDirCache: entry [%s]\n", iter->pszPath); 267 238 if (fPrefix) 268 239 { … … 275 246 { 276 247 if ( iter->ulHash == hash 277 && dcePathEqualsTo ( pdc,iter, path)248 && dcePathEqualsTo (iter, path) 278 249 ) 279 250 { … … 284 255 } 285 256 286 debuglocal( pdc->resource, 9, "dcFindDirCache: %p\n", iter);257 debuglocal(9, "findDirCache: %p\n", iter); 287 258 288 259 return iter; 289 260 } 290 261 291 static int dcCreate (struct DirectoryCache **ppdc , void* pRes)262 static int dcCreate (struct DirectoryCache **ppdc) 292 263 { 293 264 int rc; 294 265 295 266 DirectoryCache *pdc = (DirectoryCache *)malloc(sizeof (DirectoryCache)); 267 296 268 if (!pdc) 297 269 { … … 300 272 301 273 rc = lockCreate (&pdc->mutex); 274 302 275 if (rc != NO_ERROR) 303 276 { … … 312 285 pdc->fEnabled = 0; 313 286 pdc->ulExpirationTime = -1; 314 pdc->resource = pRes;315 287 316 288 *ppdc = pdc; … … 322 294 { 323 295 DirectoryCacheEntry *iter = pdc->pEntriesHead; 324 debuglocal(pdc->resource, 9, "dcDelete: pdc %p, iter %p\n", pdc, iter);325 296 326 297 while (iter != NULL) … … 328 299 DirectoryCacheEntry *next = iter->pNext; 329 300 330 dceDelete ( pdc,iter);301 dceDelete (iter); 331 302 332 303 iter = next; … … 337 308 } 338 309 339 static void dcRemoveEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce) 340 { 310 static void dcRemoveEntry (DirectoryCacheEntry *pdce) 311 { 312 DirectoryCache *pdc = pdce->pdc; 313 341 314 if (pdce->pNext) 342 315 { … … 356 329 pdc->pEntriesHead = pdce->pNext; 357 330 } 358 331 359 332 pdce->pNext = NULL; 360 333 pdce->pPrev = NULL; 361 334 362 335 pdc->cEntries--; 363 336 } 364 337 365 static void dcInsertEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce) 366 { 338 static void dcInsertEntry (DirectoryCacheEntry *pdce) 339 { 340 DirectoryCache *pdc = pdce->pdc; 341 367 342 pdce->pNext = pdc->pEntriesHead; 368 343 … … 399 374 } 400 375 401 debuglocal( pdc->resource,9, "ExistsInCache: [%s], %d\n", path, rc);376 debuglocal(9, "ExistsInCache: [%s], %d\n", path, rc); 402 377 } 403 378 … … 407 382 static int dcRead (DirectoryCache *pdc, const char *path, 408 383 PFNADDDIRENTRY fn, 409 void* plist,384 filelist_state *state, 410 385 int *ptotal_received, int fForceCache) 411 386 { 412 387 int i; 388 413 389 int rc = CacheFault; 414 390 415 391 if (pdc->fEnabled) 416 392 { … … 421 397 if (pdce) 422 398 { 423 debuglocal( pdc->resource, 9, "dcRead: entry %p found for [%s]\n", pdce, path);399 debuglocal(9, "CacheRead: entry %p found for [%s]\n", pdce, path); 424 400 425 401 if (fForceCache) … … 427 403 for (i = 0; i < pdce->cInfos; i++) 428 404 { 429 fn ( plist, (void*)pdce->aInfos[i].customData);405 fn ("", &pdce->aInfos[i], path, state); 430 406 } 431 407 … … 436 412 if (dceExpired (pdce, pdc->ulExpirationTime)) 437 413 { 438 debuglocal( pdc->resource, 9, "dcRead: expired\n");439 dcRemoveEntry (pdc , pdce);440 dceDelete (pdc , pdce);414 debuglocal(9, "CacheRead: expired\n"); 415 dcRemoveEntry (pdce); 416 dceDelete (pdce); 441 417 } 442 418 else 443 419 { 444 debuglocal(pdc->resource, 9, "dcRead: adding %d entries from cache\n", pdce->cInfos);445 420 for (i = 0; i < pdce->cInfos; i++) 446 421 { 447 debuglocal(pdc->resource, 9, "dcRead: #%d->%s->%p\n", 448 i, pdce->aInfos[i].fname, pdce->aInfos[i].customData); 449 fn (plist, (void*)pdce->aInfos[i].customData); 422 fn ("", &pdce->aInfos[i], path, state); 450 423 } 451 424 … … 460 433 } 461 434 462 debuglocal( pdc->resource, 9, "dcRead: [%s], %d\n", path, rc);435 debuglocal(9, "CacheRead: [%s], %d\n", path, rc); 463 436 } 464 437 … … 484 457 dceClear (pdce); 485 458 /* Remove the entry from list. It will be added again in dircache_write_end. */ 486 dcRemoveEntry (pdc , pdce);459 dcRemoveEntry (pdce); 487 460 } 488 461 … … 492 465 } 493 466 494 debuglocal( pdc->resource,9, "CacheWriteBegin: %s\n", path);467 debuglocal(9, "CacheWriteBegin: %s\n", path); 495 468 } 496 469 … … 503 476 DirectoryCacheEntry *pdce; 504 477 505 debuglocal( pdc->resource,9, "CacheInvalidate: [%s]\n", path);478 debuglocal(9, "CacheInvalidate: [%s]\n", path); 506 479 507 480 pdce = dcFindDirCache (pdc, path, fPrefix); … … 509 482 while (pdce) 510 483 { 511 dcRemoveEntry (pdc , pdce);512 dceDelete (pdc , pdce);484 dcRemoveEntry (pdce); 485 dceDelete (pdce); 513 486 514 487 pdce = dcFindDirCache (pdc, path, fPrefix); … … 520 493 const char *parent, 521 494 const char *name, 522 void **finfo,495 smbwrp_fileinfo *finfo, 523 496 unsigned long *pulAge) 524 497 { … … 527 500 unsigned long hash = computehash (parent); 528 501 529 debuglocal( pdc->resource,9, "dcFindPath: [%s][%s]\n", parent, name);502 debuglocal(9, "dcFindPath: [%s][%s]\n", parent, name); 530 503 531 504 while (pdce != NULL) 532 505 { 533 debuglocal( pdc->resource,9, "dcFindPath: entry [%s]\n", pdce->pszPath);506 debuglocal(9, "dcFindPath: entry [%s]\n", pdce->pszPath); 534 507 535 508 if ( pdce->ulHash == hash 536 && dcePathEqualsTo (pdc , pdce, parent))509 && dcePathEqualsTo (pdce, parent)) 537 510 { 538 511 /* This entry should contain the path. */ … … 542 515 if (ph->fsphStrICmp (pdce->aInfos[i].fname, name) == 0) 543 516 { 544 *finfo = (void*) pdce->aInfos[i].customData;517 *finfo = pdce->aInfos[i]; 545 518 *pulAge = timesec () - pdce->ulLastUpdateTime; 546 debuglocal( pdc->resource, 9, "dcFindPath: FindPath %s found, age %d\n", path, *pulAge);519 debuglocal(9, "dircache: FindPath %s found, age %d\n", path, *pulAge); 547 520 return 1; 548 521 } … … 553 526 } 554 527 555 debuglocal( pdc->resource, 9, "dcFindPath: FindPath %s not found\n", path);528 debuglocal(9, "dircache: FindPath %s not found\n", path); 556 529 return 0; 557 530 } 558 531 559 static int dcCreateDirPath(char *path, int cbPath, char* dir_mask, char* fullpath)532 static int dcCreateDirPath(char *path, int cbPath, filelist_state *state) 560 533 { 561 534 /* State contains the original path passed to the plugin (fullpath) and … … 565 538 */ 566 539 int cbDir; 567 int cbMask = strlen( dir_mask) + 1;540 int cbMask = strlen(state->dir_mask) + 1; 568 541 if (cbMask > cbPath) 569 542 { … … 577 550 { 578 551 cbDir--; /* Exclude the slash. */ 579 memcpy(path, fullpath, cbDir);552 memcpy(path, state->fullpath, cbDir); 580 553 } 581 554 path[cbDir] = 0; … … 588 561 */ 589 562 590 int dircache_create( DirectoryCache **ppdc, void* pRes, 591 int cachetimeout, int cachedepth, PFNFREEDIRENTRY _release, 592 PLUGINHELPERTABLE2L *_ph) 593 { 594 unsigned long ulExpirationTime = cachetimeout; 595 int cMaxEntries = cachedepth; 563 int dircache_create(DirectoryCache **ppdc, unsigned long ulExpirationTime, int cMaxEntries) 564 { 596 565 int rc; 597 566 598 debuglocal( pRes, 9, "dircache_create: %u seconds, %d entries\n", ulExpirationTime, cMaxEntries); 599 600 // save pointer to helpers 601 ph = _ph; 602 603 rc = dcCreate(ppdc, pRes); 567 debuglocal(9, "dircache_create: %u seconds, %d entries\n", ulExpirationTime, cMaxEntries); 568 569 rc = dcCreate(ppdc); 570 604 571 if (rc == NO_ERROR) 605 572 { 606 (*ppdc)->release = _release;607 573 dcEnable (*ppdc, 1, ulExpirationTime, cMaxEntries); 608 609 } 610 611 debuglocal( (*ppdc)->resource, 9, "dircache_create: %p, rc = %d\n", *ppdc, rc); 574 } 575 576 debuglocal(9, "dircache_create: %p, rc = %d\n", *ppdc, rc); 612 577 return rc; 613 578 } … … 615 580 void dircache_delete(DirectoryCache *pdc) 616 581 { 617 debuglocal( pdc->resource,9, "dircache_delete: %p\n", pdc);582 debuglocal(9, "dircache_delete: %p\n", pdc); 618 583 619 584 if (pdc) … … 623 588 } 624 589 625 int dircache_list_files(DirectoryCache *pdc, PFNADDDIRENTRY fn, 626 void* plist,627 char* dir_mask, char* fullpath,590 591 int dircache_list_files(PFNADDDIRENTRY fn, 592 filelist_state *state, 628 593 int *ptotal_received) 629 594 { 630 595 int rc; 631 632 int cbPath = strlen(fullpath) + 1; 633 char *path = (char*) alloca(cbPath); 634 debuglocal(pdc->resource, 9, "dircache_list_files pdc %p, dir_mask [%s], fullpath [%s]\n", 635 pdc, dir_mask, fullpath); 636 637 if (!dcCreateDirPath(path, cbPath, dir_mask, fullpath)) 638 { 639 debuglocal(pdc->resource, 9, "dircache_list_files pdc %p, dcCreateDirPath failed\n", 640 pdc); 596 DirectoryCache *pdc = state->pConn->pRes->pdc; 597 598 int cbPath = strlen(state->fullpath) + 1; 599 char *path = alloca(cbPath); 600 if (!dcCreateDirPath(path, cbPath, state)) 601 { 641 602 return 0; 642 603 } 643 604 644 debuglocal(pdc->resource, 9, "dircache_list_files [%s]\n", path); 605 debuglocal(9, "dircache_list_files [%s]\n", path); 606 645 607 if (!pdc) 646 608 { … … 650 612 lockRequest (pdc->mutex); 651 613 652 rc = dcRead (pdc, path, fn, plist, ptotal_received, 0);614 rc = dcRead (pdc, path, fn, state, ptotal_received, 0); 653 615 654 616 lockRelease (pdc->mutex); 655 617 656 debuglocal(pdc->resource, 9, "dircache_list_files rc=%d\n", (rc == CacheOk));657 618 return (rc == CacheOk); 658 619 } 659 620 660 void *dircache_write_begin(DirectoryCache *pdc, 661 char* dir_mask, char* fullpath, 621 void *dircache_write_begin(filelist_state *state, 662 622 int cFiles) 663 623 { 624 DirectoryCache *pdc = state->pConn->pRes->pdc; 664 625 DirectoryCacheEntry *pdce = NULL; 665 debuglocal(pdc->resource, 9, "dircache_write_begin pdc %p path [%s]\n", pdc, fullpath); 666 667 int cbPath = strlen(fullpath) + 1; 668 char *path = (char*) alloca(cbPath); 669 if (!dcCreateDirPath(path, cbPath, dir_mask, fullpath)) 670 { 671 debuglocal(pdc->resource, 9, "dircache_write_begin dcCreateDirPath failed\n"); 626 627 int cbPath = strlen(state->fullpath) + 1; 628 char *path = alloca(cbPath); 629 if (!dcCreateDirPath(path, cbPath, state)) 630 { 631 return NULL; 632 } 633 634 debuglocal(9, "dircache_write_begin pdc %p path [%s]\n", pdc, path); 635 636 if (!pdc) 637 { 672 638 return NULL; 673 639 } … … 679 645 /* Remove oldest entry. */ 680 646 pdce = pdc->pEntriesTail; 681 dcRemoveEntry (pdc , pdce);682 dceDelete (pdc , pdce);647 dcRemoveEntry (pdce); 648 dceDelete (pdce); 683 649 pdce = NULL; 684 650 } … … 688 654 lockRelease (pdc->mutex); 689 655 690 debuglocal( pdc->resource,9, "dircache_write_begin returning ctx %p\n", pdce);656 debuglocal(9, "dircache_write_begin returning ctx %p\n", pdce); 691 657 return (void *)pdce; 692 658 } 693 659 694 void dircache_write_entry(DirectoryCache *pdc, void *dircachectx, 695 const char *fname, const void *finfo) 660 void dircache_write_entry(void *dircachectx, const smbwrp_fileinfo *finfo) 696 661 { 697 662 DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx; 698 663 699 debuglocal( pdc->resource,9, "dircache_write_entry %p\n", pdce);664 debuglocal(9, "dircache_write_entry %p\n", pdce); 700 665 701 666 if (!pdce) … … 704 669 } 705 670 671 lockRequest (pdce->pdc->mutex); 672 673 dceWriteEntry (pdce, finfo); 674 675 lockRelease (pdce->pdc->mutex); 676 } 677 678 void dircache_write_end(void *dircachectx) 679 { 680 DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx; 681 DirectoryCache *pdc; 682 683 debuglocal(9, "dircache_write_end: pdce %p\n", pdce); 684 685 if (!pdce) 686 { 687 return; 688 } 689 690 pdc = pdce->pdc; 691 706 692 lockRequest (pdc->mutex); 707 693 708 dceWriteEntry (pdc, pdce, fname, finfo); 694 if (pdce->fInvalid) 695 { 696 /* Something happened during writing to the entry. Delete it. */ 697 dceDelete (pdce); 698 } 699 else 700 { 701 dceAdjust (pdce); 702 dcInsertEntry (pdce); 703 } 709 704 710 705 lockRelease (pdc->mutex); 711 706 } 712 707 713 void dircache_write_end(DirectoryCache *pdc, void *dircachectx) 714 { 715 DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx; 716 717 debuglocal(pdc->resource, 9, "dircache_write_end: pdce %p\n", pdce); 718 719 if (!pdce) 720 { 721 return; 722 } 723 724 lockRequest (pdc->mutex); 725 726 if (pdce->fInvalid) 727 { 728 /* Something happened during writing to the entry. Delete it. */ 729 dceDelete (pdc, pdce); 730 } 731 else 732 { 733 dceAdjust (pdc, pdce); 734 dcInsertEntry (pdc, pdce); 735 } 736 737 lockRelease (pdc->mutex); 738 } 739 740 void dircache_invalidate(DirectoryCache *pdc, 741 const char *path, 708 void dircache_invalidate(const char *path, 709 struct DirectoryCache *pdc, 742 710 int fParent) 743 711 { 744 debuglocal( pdc->resource,9, "dircache_invalidate [%s], parent %d\n", path, fParent);712 debuglocal(9, "dircache_invalidate [%s], parent %d\n", path, fParent); 745 713 746 714 if (!pdc) … … 757 725 memcpy(p, path, cb); 758 726 char *lastSlash = ph->fsphStrRChr(p, '\\'); 759 if (!lastSlash)760 lastSlash = ph->fsphStrRChr(p, '/');761 727 if (lastSlash) 762 728 { … … 779 745 } 780 746 781 int dircache_find_path( DirectoryCache *pdc,747 int dircache_find_path(struct DirectoryCache *pdc, 782 748 const char *path, 783 void **finfo,749 smbwrp_fileinfo *finfo, 784 750 unsigned long *pulAge) 785 751 { … … 789 755 int fFound = 0; 790 756 791 debuglocal( pdc->resource,9, "dircache_find_path [%s]\n", path);757 debuglocal(9, "dircache_find_path [%s]\n", path); 792 758 793 759 if (!pdc) … … 809 775 memcpy(p, path, cb); 810 776 lastSlash = ph->fsphStrRChr(p, '\\'); 811 if (!lastSlash)812 lastSlash = ph->fsphStrRChr(p, '/');813 777 if (lastSlash) 814 778 { … … 824 788 lockRelease (pdc->mutex); 825 789 826 debuglocal(pdc->resource, 9, "dircache_find_path fFound %d\n", fFound);827 790 return fFound; 828 791 } -
branches/client-3.0/src/smbwrp.c
r1001 r1003 957 957 smbwrp_fileinfo wrpfinfo; 958 958 959 //Init cache - don't know number of files so init with 128 960 dircachectx = dircache_write_begin(state, 128); 961 959 962 if (smbXcli_conn_has_async_calls(cli->conn)) { 960 963 /* … … 1075 1078 pathname, 1076 1079 state); 1080 // Also add the entry to the cache. 1081 dircache_write_entry(dircachectx, &wrpfinfo); 1077 1082 1078 1083 if (!NT_STATUS_IS_OK(status)) { … … 1118 1123 status = NT_STATUS_NO_SUCH_FILE; 1119 1124 } 1120 1125 dircache_write_end(dircachectx); 1121 1126 fail: 1122 1127 … … 1148 1153 smbwrp_fileinfo wrpfinfo; 1149 1154 1155 /* Try to get the listing from cache. */ 1156 if (dircache_list_files(fn, state, &num_finfo)) 1157 { 1158 /* Got from cache. */ 1159 return(num_finfo); 1160 } 1161 1150 1162 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 1151 1163 debuglocal(4,"SMB2 detected, calling list_files_smb2()\n"); 1152 1164 return list_files_smb2(cli, mask, attribute, fn, state); 1153 }1154 1155 /* Try to get the listing from cache. */1156 if (dircache_list_files(fn, state, &num_finfo))1157 {1158 /* Got from cache. */1159 return(num_finfo);1160 1165 } 1161 1166
Note:
See TracChangeset
for help on using the changeset viewer.