Changeset 1002 for branches/client-3.0
- Timestamp:
- Dec 30, 2016, 5:22:31 AM (9 years ago)
- Location:
- branches/client-3.0/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/client-3.0/src/dircache.c
r998 r1002 1 /* 2 Directory caching code for Netdrive plugins. 3 Copyright (C) netlabs.org 2010-2016 4 */ 5 1 6 #include <stdio.h> 2 7 #include <stdlib.h> … … 5 10 #include <time.h> 6 11 7 #define NDPL_LARGEFILES 8 #define INCL_LONGLONG 9 #include <ndextpl2.h> 10 11 #include "smbwrp.h" 12 13 extern PLUGINHELPERTABLE2L *ph; 12 #include "dircache.h" 13 14 PLUGINHELPERTABLE2L *ph; 14 15 15 16 /* 16 * Static helpers.17 * An entry holds file name and a pointer to custom data 17 18 */ 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 19 typedef struct DirectoryCacheEntryData 20 { 21 const char fname[PATH_MAX]; 22 const void* customData; 23 } DirectoryCacheEntryData; 71 24 72 25 /* … … 78 31 struct DirectoryCacheEntry *pPrev; 79 32 80 struct DirectoryCache *pdc; 81 82 smbwrp_fileinfo *aInfos; 33 DirectoryCacheEntryData *aInfos; 83 34 int cInfos; 84 35 int cInfosAllocated; … … 97 48 DirectoryCacheEntry *pEntriesTail; 98 49 int cEntries; 99 100 50 int fEnabled; 101 51 unsigned long ulExpirationTime; 102 52 int cMaxEntries; 53 // resource handle, used only for per-share logging 54 void* resource; 55 // callback called to release data structures 56 PFNFREEDIRENTRY release; 57 103 58 } DirectoryCache; 104 59 … … 107 62 CacheOk = 1 108 63 }; 109 110 111 static int dceCreate (DirectoryCacheEntry **ppdce, DirectoryCache *pdc, const char *path, int cFiles) 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) 112 121 { 113 122 DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)malloc(sizeof(DirectoryCacheEntry)); … … 118 127 } 119 128 120 pdce->aInfos = (smbwrp_fileinfo *)malloc(cFiles * sizeof (smbwrp_fileinfo)); 129 pdce->aInfos = (DirectoryCacheEntryData *) 130 malloc(cFiles * sizeof (DirectoryCacheEntryData)); 121 131 if (!pdce->aInfos) 122 132 { … … 128 138 pdce->ulHash = computehash (path); 129 139 pdce->ulLastUpdateTime = 0; 130 pdce->pdc = pdc;131 140 pdce->fInvalid = 0; 132 141 … … 143 152 } 144 153 145 static void dceDelete (DirectoryCacheEntry *pdce) 146 { 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 */ 147 170 free(pdce->aInfos); 148 171 free(pdce->pszPath); … … 155 178 } 156 179 157 static void dceWriteEntry (DirectoryCacheEntry *pdce, const smbwrp_fileinfo *finfo) 180 static void dceWriteEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce, 181 const char *fname, const void *finfo) 158 182 { 159 183 if (pdce->cInfos >= pdce->cInfosAllocated) … … 162 186 int cNewAllocated = pdce->cInfosAllocated + pdce->cInfosAllocated / 2 + 1; 163 187 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); 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); 168 193 if (pNewInfos) 169 194 { … … 179 204 } 180 205 181 pdce->aInfos[pdce->cInfos] = *finfo; 206 // store entry name and custom data 207 strcpy( (char*)pdce->aInfos[pdce->cInfos].fname, fname); 208 pdce->aInfos[pdce->cInfos].customData = finfo; 182 209 pdce->cInfos++; 183 210 } 184 211 185 static void dceAdjust (DirectoryCache Entry *pdce)212 static void dceAdjust (DirectoryCache *pdc, DirectoryCacheEntry *pdce) 186 213 { 187 214 /* If the entry has too many preallocated info structures, adjust the memory allocation */ … … 193 220 int cNewAllocated = pdce->cInfos + cFree / 2; 194 221 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); 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); 199 227 if (pNewInfos) 200 228 { … … 209 237 } 210 238 211 static int dcePathEqualsTo (DirectoryCache Entry *pdce, const char *path)212 { 213 debuglocal( 9, "dcePathEqualTo: [%s] [%s]\n", path, pdce->pszPath);239 static int dcePathEqualsTo (DirectoryCache *pdc, DirectoryCacheEntry *pdce, const char *path) 240 { 241 debuglocal(pdc->resource, 9, "dcePathEqualTo: [%s] [%s]\n", path, pdce->pszPath); 214 242 return ph->fsphStrICmp (path, pdce->pszPath) == 0; 215 243 } … … 225 253 } 226 254 227 static struct DirectoryCacheEntry *dcFindDirCache ( structDirectoryCache *pdc, const char *path, int fPrefix)255 static struct DirectoryCacheEntry *dcFindDirCache (DirectoryCache *pdc, const char *path, int fPrefix) 228 256 { 229 257 unsigned long hash = computehash (path); … … 231 259 DirectoryCacheEntry *iter = pdc->pEntriesHead; 232 260 233 debuglocal(9, "findDirCache: [%s]\n", path); 261 debuglocal(pdc->resource, 9, "dcFindDirCache: [%s]\n", path); 262 debuglocal(pdc->resource, 9, "dcFindDirCache: iter [%p]\n", iter); 234 263 235 264 while (iter != NULL) 236 265 { 237 debuglocal( 9, "findDirCache: entry [%s]\n", iter->pszPath);266 debuglocal(pdc->resource, 9, "dcFindDirCache: entry [%s]\n", iter->pszPath); 238 267 if (fPrefix) 239 268 { … … 246 275 { 247 276 if ( iter->ulHash == hash 248 && dcePathEqualsTo ( iter, path)277 && dcePathEqualsTo (pdc, iter, path) 249 278 ) 250 279 { … … 255 284 } 256 285 257 debuglocal( 9, "findDirCache: %p\n", iter);286 debuglocal(pdc->resource, 9, "dcFindDirCache: %p\n", iter); 258 287 259 288 return iter; 260 289 } 261 290 262 static int dcCreate (struct DirectoryCache **ppdc )291 static int dcCreate (struct DirectoryCache **ppdc, void* pRes) 263 292 { 264 293 int rc; 265 294 266 295 DirectoryCache *pdc = (DirectoryCache *)malloc(sizeof (DirectoryCache)); 267 268 296 if (!pdc) 269 297 { … … 272 300 273 301 rc = lockCreate (&pdc->mutex); 274 275 302 if (rc != NO_ERROR) 276 303 { … … 285 312 pdc->fEnabled = 0; 286 313 pdc->ulExpirationTime = -1; 314 pdc->resource = pRes; 287 315 288 316 *ppdc = pdc; … … 294 322 { 295 323 DirectoryCacheEntry *iter = pdc->pEntriesHead; 324 debuglocal(pdc->resource, 9, "dcDelete: pdc %p, iter %p\n", pdc, iter); 296 325 297 326 while (iter != NULL) … … 299 328 DirectoryCacheEntry *next = iter->pNext; 300 329 301 dceDelete ( iter);330 dceDelete (pdc, iter); 302 331 303 332 iter = next; … … 308 337 } 309 338 310 static void dcRemoveEntry (DirectoryCacheEntry *pdce) 311 { 312 DirectoryCache *pdc = pdce->pdc; 313 339 static void dcRemoveEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce) 340 { 314 341 if (pdce->pNext) 315 342 { … … 329 356 pdc->pEntriesHead = pdce->pNext; 330 357 } 331 358 332 359 pdce->pNext = NULL; 333 360 pdce->pPrev = NULL; 334 361 335 362 pdc->cEntries--; 336 363 } 337 364 338 static void dcInsertEntry (DirectoryCacheEntry *pdce) 339 { 340 DirectoryCache *pdc = pdce->pdc; 341 365 static void dcInsertEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce) 366 { 342 367 pdce->pNext = pdc->pEntriesHead; 343 368 … … 374 399 } 375 400 376 debuglocal( 9, "ExistsInCache: [%s], %d\n", path, rc);401 debuglocal(pdc->resource, 9, "ExistsInCache: [%s], %d\n", path, rc); 377 402 } 378 403 … … 382 407 static int dcRead (DirectoryCache *pdc, const char *path, 383 408 PFNADDDIRENTRY fn, 384 filelist_state *state,409 void* plist, 385 410 int *ptotal_received, int fForceCache) 386 411 { 387 412 int i; 388 389 413 int rc = CacheFault; 390 414 391 415 if (pdc->fEnabled) 392 416 { … … 397 421 if (pdce) 398 422 { 399 debuglocal( 9, "CacheRead: entry %p found for [%s]\n", pdce, path);423 debuglocal(pdc->resource, 9, "dcRead: entry %p found for [%s]\n", pdce, path); 400 424 401 425 if (fForceCache) … … 403 427 for (i = 0; i < pdce->cInfos; i++) 404 428 { 405 fn ( "", &pdce->aInfos[i], path, state);429 fn (plist, (void*)pdce->aInfos[i].customData); 406 430 } 407 431 … … 412 436 if (dceExpired (pdce, pdc->ulExpirationTime)) 413 437 { 414 debuglocal( 9, "CacheRead: expired\n");415 dcRemoveEntry (pdc e);416 dceDelete (pdc e);438 debuglocal(pdc->resource, 9, "dcRead: expired\n"); 439 dcRemoveEntry (pdc, pdce); 440 dceDelete (pdc, pdce); 417 441 } 418 442 else 419 443 { 444 debuglocal(pdc->resource, 9, "dcRead: adding %d entries from cache\n", pdce->cInfos); 420 445 for (i = 0; i < pdce->cInfos; i++) 421 446 { 422 fn ("", &pdce->aInfos[i], path, state); 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); 423 450 } 424 451 … … 433 460 } 434 461 435 debuglocal( 9, "CacheRead: [%s], %d\n", path, rc);462 debuglocal(pdc->resource, 9, "dcRead: [%s], %d\n", path, rc); 436 463 } 437 464 … … 457 484 dceClear (pdce); 458 485 /* Remove the entry from list. It will be added again in dircache_write_end. */ 459 dcRemoveEntry (pdc e);486 dcRemoveEntry (pdc, pdce); 460 487 } 461 488 … … 465 492 } 466 493 467 debuglocal( 9, "CacheWriteBegin: %s\n", path);494 debuglocal(pdc->resource, 9, "CacheWriteBegin: %s\n", path); 468 495 } 469 496 … … 476 503 DirectoryCacheEntry *pdce; 477 504 478 debuglocal( 9, "CacheInvalidate: [%s]\n", path);505 debuglocal(pdc->resource, 9, "CacheInvalidate: [%s]\n", path); 479 506 480 507 pdce = dcFindDirCache (pdc, path, fPrefix); … … 482 509 while (pdce) 483 510 { 484 dcRemoveEntry (pdc e);485 dceDelete (pdc e);511 dcRemoveEntry (pdc, pdce); 512 dceDelete (pdc, pdce); 486 513 487 514 pdce = dcFindDirCache (pdc, path, fPrefix); … … 493 520 const char *parent, 494 521 const char *name, 495 smbwrp_fileinfo*finfo,522 void **finfo, 496 523 unsigned long *pulAge) 497 524 { … … 500 527 unsigned long hash = computehash (parent); 501 528 502 debuglocal( 9, "dcFindPath: [%s][%s]\n", parent, name);529 debuglocal(pdc->resource, 9, "dcFindPath: [%s][%s]\n", parent, name); 503 530 504 531 while (pdce != NULL) 505 532 { 506 debuglocal( 9, "dcFindPath: entry [%s]\n", pdce->pszPath);533 debuglocal(pdc->resource, 9, "dcFindPath: entry [%s]\n", pdce->pszPath); 507 534 508 535 if ( pdce->ulHash == hash 509 && dcePathEqualsTo (pdc e, parent))536 && dcePathEqualsTo (pdc, pdce, parent)) 510 537 { 511 538 /* This entry should contain the path. */ … … 515 542 if (ph->fsphStrICmp (pdce->aInfos[i].fname, name) == 0) 516 543 { 517 *finfo = pdce->aInfos[i];544 *finfo = (void*) pdce->aInfos[i].customData; 518 545 *pulAge = timesec () - pdce->ulLastUpdateTime; 519 debuglocal( 9, "dircache: FindPath %s found, age %d\n", path, *pulAge);546 debuglocal(pdc->resource, 9, "dcFindPath: FindPath %s found, age %d\n", path, *pulAge); 520 547 return 1; 521 548 } … … 526 553 } 527 554 528 debuglocal( 9, "dircache: FindPath %s not found\n", path);555 debuglocal(pdc->resource, 9, "dcFindPath: FindPath %s not found\n", path); 529 556 return 0; 530 557 } 531 558 532 static int dcCreateDirPath(char *path, int cbPath, filelist_state *state)559 static int dcCreateDirPath(char *path, int cbPath, char* dir_mask, char* fullpath) 533 560 { 534 561 /* State contains the original path passed to the plugin (fullpath) and … … 538 565 */ 539 566 int cbDir; 540 int cbMask = strlen( state->dir_mask) + 1;567 int cbMask = strlen(dir_mask) + 1; 541 568 if (cbMask > cbPath) 542 569 { … … 550 577 { 551 578 cbDir--; /* Exclude the slash. */ 552 memcpy(path, state->fullpath, cbDir);579 memcpy(path, fullpath, cbDir); 553 580 } 554 581 path[cbDir] = 0; … … 561 588 */ 562 589 563 int dircache_create(DirectoryCache **ppdc, unsigned long ulExpirationTime, int cMaxEntries) 564 { 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; 565 596 int rc; 566 597 567 debuglocal(9, "dircache_create: %u seconds, %d entries\n", ulExpirationTime, cMaxEntries); 568 569 rc = dcCreate(ppdc); 570 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); 571 604 if (rc == NO_ERROR) 572 605 { 606 (*ppdc)->release = _release; 573 607 dcEnable (*ppdc, 1, ulExpirationTime, cMaxEntries); 574 } 575 576 debuglocal(9, "dircache_create: %p, rc = %d\n", *ppdc, rc); 608 609 } 610 611 debuglocal( (*ppdc)->resource, 9, "dircache_create: %p, rc = %d\n", *ppdc, rc); 577 612 return rc; 578 613 } … … 580 615 void dircache_delete(DirectoryCache *pdc) 581 616 { 582 debuglocal( 9, "dircache_delete: %p\n", pdc);617 debuglocal(pdc->resource, 9, "dircache_delete: %p\n", pdc); 583 618 584 619 if (pdc) … … 588 623 } 589 624 590 591 int dircache_list_files(PFNADDDIRENTRY fn,592 filelist_state *state,625 int dircache_list_files(DirectoryCache *pdc, PFNADDDIRENTRY fn, 626 void* plist, 627 char* dir_mask, char* fullpath, 593 628 int *ptotal_received) 594 629 { 595 630 int rc; 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 { 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); 602 641 return 0; 603 642 } 604 643 605 debuglocal(9, "dircache_list_files [%s]\n", path); 606 644 debuglocal(pdc->resource, 9, "dircache_list_files [%s]\n", path); 607 645 if (!pdc) 608 646 { … … 612 650 lockRequest (pdc->mutex); 613 651 614 rc = dcRead (pdc, path, fn, state, ptotal_received, 0);652 rc = dcRead (pdc, path, fn, plist, ptotal_received, 0); 615 653 616 654 lockRelease (pdc->mutex); 617 655 656 debuglocal(pdc->resource, 9, "dircache_list_files rc=%d\n", (rc == CacheOk)); 618 657 return (rc == CacheOk); 619 658 } 620 659 621 void *dircache_write_begin(filelist_state *state, 660 void *dircache_write_begin(DirectoryCache *pdc, 661 char* dir_mask, char* fullpath, 622 662 int cFiles) 623 663 { 624 DirectoryCache *pdc = state->pConn->pRes->pdc;625 664 DirectoryCacheEntry *pdce = NULL; 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 { 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"); 638 672 return NULL; 639 673 } … … 645 679 /* Remove oldest entry. */ 646 680 pdce = pdc->pEntriesTail; 647 dcRemoveEntry (pdc e);648 dceDelete (pdc e);681 dcRemoveEntry (pdc, pdce); 682 dceDelete (pdc, pdce); 649 683 pdce = NULL; 650 684 } … … 654 688 lockRelease (pdc->mutex); 655 689 656 debuglocal( 9, "dircache_write_begin returning ctx %p\n", pdce);690 debuglocal(pdc->resource, 9, "dircache_write_begin returning ctx %p\n", pdce); 657 691 return (void *)pdce; 658 692 } 659 693 660 void dircache_write_entry(void *dircachectx, const smbwrp_fileinfo *finfo) 694 void dircache_write_entry(DirectoryCache *pdc, void *dircachectx, 695 const char *fname, const void *finfo) 661 696 { 662 697 DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx; 663 698 664 debuglocal( 9, "dircache_write_entry %p\n", pdce);699 debuglocal(pdc->resource, 9, "dircache_write_entry %p\n", pdce); 665 700 666 701 if (!pdce) … … 669 704 } 670 705 671 lockRequest (pdc e->pdc->mutex);672 673 dceWriteEntry (pdc e, finfo);674 675 lockRelease (pdc e->pdc->mutex);676 } 677 678 void dircache_write_end( void *dircachectx)706 lockRequest (pdc->mutex); 707 708 dceWriteEntry (pdc, pdce, fname, finfo); 709 710 lockRelease (pdc->mutex); 711 } 712 713 void dircache_write_end(DirectoryCache *pdc, void *dircachectx) 679 714 { 680 715 DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx; 681 DirectoryCache *pdc; 682 683 debuglocal(9, "dircache_write_end: pdce %p\n", pdce); 716 717 debuglocal(pdc->resource, 9, "dircache_write_end: pdce %p\n", pdce); 684 718 685 719 if (!pdce) … … 688 722 } 689 723 690 pdc = pdce->pdc;691 692 724 lockRequest (pdc->mutex); 693 725 … … 695 727 { 696 728 /* Something happened during writing to the entry. Delete it. */ 697 dceDelete (pdc e);729 dceDelete (pdc, pdce); 698 730 } 699 731 else 700 732 { 701 dceAdjust (pdc e);702 dcInsertEntry (pdc e);733 dceAdjust (pdc, pdce); 734 dcInsertEntry (pdc, pdce); 703 735 } 704 736 … … 706 738 } 707 739 708 void dircache_invalidate( const char *path,709 struct DirectoryCache *pdc,740 void dircache_invalidate(DirectoryCache *pdc, 741 const char *path, 710 742 int fParent) 711 743 { 712 debuglocal( 9, "dircache_invalidate [%s], parent %d\n", path, fParent);744 debuglocal(pdc->resource, 9, "dircache_invalidate [%s], parent %d\n", path, fParent); 713 745 714 746 if (!pdc) … … 725 757 memcpy(p, path, cb); 726 758 char *lastSlash = ph->fsphStrRChr(p, '\\'); 759 if (!lastSlash) 760 lastSlash = ph->fsphStrRChr(p, '/'); 727 761 if (lastSlash) 728 762 { … … 745 779 } 746 780 747 int dircache_find_path( structDirectoryCache *pdc,781 int dircache_find_path(DirectoryCache *pdc, 748 782 const char *path, 749 smbwrp_fileinfo*finfo,783 void **finfo, 750 784 unsigned long *pulAge) 751 785 { … … 755 789 int fFound = 0; 756 790 757 debuglocal( 9, "dircache_find_path [%s]\n", path);791 debuglocal(pdc->resource, 9, "dircache_find_path [%s]\n", path); 758 792 759 793 if (!pdc) … … 775 809 memcpy(p, path, cb); 776 810 lastSlash = ph->fsphStrRChr(p, '\\'); 811 if (!lastSlash) 812 lastSlash = ph->fsphStrRChr(p, '/'); 777 813 if (lastSlash) 778 814 { … … 788 824 lockRelease (pdc->mutex); 789 825 826 debuglocal(pdc->resource, 9, "dircache_find_path fFound %d\n", fFound); 790 827 return fFound; 791 828 } -
branches/client-3.0/src/ndpsmb.c
r1000 r1002 2218 2218 } 2219 2219 2220 #define NDPSMB_READ_MAX_SIZE (65536 - 4096)2221 //TODO simplify this code2222 2220 int APIENTRY NdpFileRead (HCONNECTION conn, NDFILEHANDLE handle, void *pBuffer, ULONG ulRead, ULONG *pulActual) 2223 2221 { … … 2225 2223 Resource *pRes = pConn->pRes; 2226 2224 int rc = 0; 2227 unsigned long done = 0; 2228 unsigned long onedone; 2229 unsigned long action; 2230 ULONG ulReadCompleted = 0; 2231 2232 ENTER(); 2233 2234 debuglocal(9,"NdpFileRead in [%p]\n", pConn); 2235 2236 do { 2237 if (pConn->file.fd < 0) 2238 { 2239 rc = ERROR_INVALID_HANDLE; 2240 break; 2241 } 2242 while (ulReadCompleted < ulRead) 2243 { 2244 ULONG ulActual; 2245 ULONG ulToRead = ulRead - ulReadCompleted; 2246 debuglocal(9,"NdpFileRead completed %d, to read %d\n", ulReadCompleted, ulToRead); 2247 if (ulToRead > NDPSMB_READ_MAX_SIZE) 2248 { 2249 ulToRead = NDPSMB_READ_MAX_SIZE; 2250 } 2251 rc = smbwrp_read(pConn->cli, &pConn->file, (char *)pBuffer + ulReadCompleted, ulToRead, &ulActual); 2252 if (ulActual == 0 || rc != NO_ERROR) 2253 { 2254 break; 2255 } 2256 ulReadCompleted += ulActual; 2257 } 2258 //*pulActual = ulRead; 2259 //DosSleep(0); 2260 2261 } while (0); 2262 2263 if (ulReadCompleted > 0) 2225 2226 ENTER(); 2227 2228 debuglocal(9,"NdpFileRead in [%p], ulRead = %d\n", pConn, ulRead); 2229 2230 ULONG ulActual; 2231 rc = smbwrp_read(pConn->cli, &pConn->file, (char *)pBuffer, ulRead, &ulActual); 2232 2233 if (ulActual > 0) 2264 2234 { 2265 2235 rc = NO_ERROR; /* Still were able to read some data. */ … … 2268 2238 if (rc == NO_ERROR) 2269 2239 { 2270 *pulActual = ul ReadCompleted;2240 *pulActual = ulActual; 2271 2241 } 2272 2242
Note:
See TracChangeset
for help on using the changeset viewer.