* NAME: reuse() * DESCRIPTION: free a bucket for reuse, flushing if necessary */
| 392 | * DESCRIPTION: free a bucket for reuse, flushing if necessary |
| 393 | */ |
| 394 | static |
| 395 | int reuse(bcache *cache, bucket *b, unsigned long bnum) |
| 396 | { |
| 397 | bucket *chain[HFS_BLOCKBUFSZ], *bptr; |
| 398 | int i; |
| 399 | |
| 400 | # ifdef DEBUG |
| 401 | if (INUSE(b)) |
| 402 | fprintf(stderr, "BLOCK: CACHE reusing bucket containing " |
| 403 | "vol 0x%lx block %lu:%u\n", |
| 404 | (unsigned long) cache->vol, b->bnum, b->count); |
| 405 | # endif |
| 406 | |
| 407 | if (INUSE(b) && DIRTY(b)) |
| 408 | { |
| 409 | /* flush most recently unused buckets */ |
| 410 | |
| 411 | for (bptr = b, i = 0; i < HFS_BLOCKBUFSZ; ++i) |
| 412 | { |
| 413 | chain[i] = bptr; |
| 414 | bptr = bptr->cprev; |
| 415 | } |
| 416 | |
| 417 | if (flushbuckets(cache->vol, chain, HFS_BLOCKBUFSZ) == -1) |
| 418 | goto fail; |
| 419 | } |
| 420 | |
| 421 | b->flags &= ~HFS_BUCKET_INUSE; |
| 422 | b->count = 1; |
| 423 | b->bnum = bnum; |
| 424 | |
| 425 | return 0; |
| 426 | |
| 427 | fail: |
| 428 | return -1; |
| 429 | } |
| 430 | |
| 431 | /* |
| 432 | * NAME: cplace() |