* adfUpdateCache * */
| 439 | * |
| 440 | */ |
| 441 | RETCODE adfUpdateCache(struct Volume *vol, struct bEntryBlock *parent, |
| 442 | struct bEntryBlock *entry, BOOL entryLenChg) |
| 443 | { |
| 444 | struct bDirCacheBlock dirc; |
| 445 | SECTNUM nSect; |
| 446 | struct CacheEntry caEntry, newEntry; |
| 447 | int offset, oldOffset, n; |
| 448 | BOOL found; |
| 449 | int i, oLen, nLen; |
| 450 | int sLen; /* shift length */ |
| 451 | |
| 452 | nLen = adfEntry2CacheEntry(entry, &newEntry); |
| 453 | |
| 454 | nSect = parent->extension; |
| 455 | found = FALSE; |
| 456 | do { |
| 457 | /*printf("dirc=%ld\n",nSect);*/ |
| 458 | if (adfReadDirCBlock(vol, nSect, &dirc)!=RC_OK) |
| 459 | return RC_ERROR; |
| 460 | offset = 0; n = 0; |
| 461 | /* search entry to update with its header_key */ |
| 462 | while(n < dirc.recordsNb && !found) { |
| 463 | oldOffset = offset; |
| 464 | /* offset is updated */ |
| 465 | adfGetCacheEntry(&dirc, &offset, &caEntry); |
| 466 | oLen = offset-oldOffset; |
| 467 | sLen = oLen-nLen; |
| 468 | /*printf("olen=%d nlen=%d\n",oLen,nLen);*/ |
| 469 | found = (caEntry.header==newEntry.header); |
| 470 | if (found) { |
| 471 | if (!entryLenChg || oLen==nLen) { |
| 472 | /* same length : remplace the old values */ |
| 473 | adfPutCacheEntry(&dirc, &oldOffset, &newEntry); |
| 474 | /*if (entryLenChg) puts("oLen==nLen");*/ |
| 475 | if (adfWriteDirCBlock(vol, dirc.headerKey, &dirc)!=RC_OK) |
| 476 | return RC_ERROR; |
| 477 | } |
| 478 | else if (oLen>nLen) { |
| 479 | /*puts("oLen>nLen");*/ |
| 480 | /* the new record is shorter, write it, |
| 481 | * then shift down the following records |
| 482 | */ |
| 483 | adfPutCacheEntry(&dirc, &oldOffset, &newEntry); |
| 484 | for(i=oldOffset+nLen; i<(488-sLen); i++) |
| 485 | dirc.records[i] = dirc.records[i+sLen]; |
| 486 | /* then clear the following bytes */ |
| 487 | for(i=488-sLen; i<488; i++) |
| 488 | dirc.records[i] = (char)0; |
| 489 | |
| 490 | if (adfWriteDirCBlock(vol, dirc.headerKey, &dirc)!=RC_OK) |
| 491 | return RC_ERROR; |
| 492 | } |
| 493 | else { |
| 494 | /* the new record is larger */ |
| 495 | /*puts("oLen<nLen");*/ |
| 496 | adfDelFromCache(vol,parent,entry->headerKey); |
| 497 | adfAddInCache(vol,parent,entry); |
| 498 | /*puts("oLen<nLen end");*/ |
no test coverage detected