changed get_cached_block() to no longer use a reference argument

modified to panic when an invalid block is requested (to find fs errors)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16537 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marcus Overhagen 2006-02-27 18:03:42 +00:00
parent 9b5a183539
commit 89d76e508d

View File

@ -489,6 +489,9 @@ put_cached_block(block_cache *cache, cached_block *block)
static void static void
put_cached_block(block_cache *cache, off_t blockNumber) put_cached_block(block_cache *cache, off_t blockNumber)
{ {
if (blockNumber < 0 || blockNumber >= cache->max_blocks)
panic("put_cached_block: invalid block number %lld (max %lld)", blockNumber, cache->max_blocks - 1);
cached_block *block = (cached_block *)hash_lookup(cache->hash, &blockNumber); cached_block *block = (cached_block *)hash_lookup(cache->hash, &blockNumber);
if (block != NULL) if (block != NULL)
put_cached_block(cache, block); put_cached_block(cache, block);
@ -496,10 +499,13 @@ put_cached_block(block_cache *cache, off_t blockNumber)
static cached_block * static cached_block *
get_cached_block(block_cache *cache, off_t blockNumber, bool &allocated, bool readBlock = true) get_cached_block(block_cache *cache, off_t blockNumber, bool *allocated, bool readBlock = true)
{ {
if (blockNumber < 0 || blockNumber >= cache->max_blocks)
panic("get_cached_block: invalid block number %lld (max %lld)", blockNumber, cache->max_blocks - 1);
cached_block *block = (cached_block *)hash_lookup(cache->hash, &blockNumber); cached_block *block = (cached_block *)hash_lookup(cache->hash, &blockNumber);
allocated = false; *allocated = false;
if (block == NULL) { if (block == NULL) {
// read block into cache // read block into cache
@ -507,7 +513,7 @@ get_cached_block(block_cache *cache, off_t blockNumber, bool &allocated, bool re
if (block == NULL) if (block == NULL)
return NULL; return NULL;
allocated = true; *allocated = true;
} else { } else {
/* /*
if (block->ref_count == 0 && block->current_data != NULL) { if (block->ref_count == 0 && block->current_data != NULL) {
@ -521,12 +527,12 @@ get_cached_block(block_cache *cache, off_t blockNumber, bool &allocated, bool re
if (block->current_data == NULL) if (block->current_data == NULL)
return NULL; return NULL;
allocated = true; *allocated = true;
} }
*/ */
} }
if (allocated && readBlock) { if (*allocated && readBlock) {
int32 blockSize = cache->block_size; int32 blockSize = cache->block_size;
if (read_pos(cache->fd, blockNumber * blockSize, block->current_data, blockSize) < blockSize) { if (read_pos(cache->fd, blockNumber * blockSize, block->current_data, blockSize) < blockSize) {
@ -562,8 +568,11 @@ get_writable_cached_block(block_cache *cache, off_t blockNumber, off_t base, off
{ {
TRACE(("get_writable_cached_block(blockNumber = %Ld, transaction = %ld)\n", blockNumber, transactionID)); TRACE(("get_writable_cached_block(blockNumber = %Ld, transaction = %ld)\n", blockNumber, transactionID));
if (blockNumber < 0 || blockNumber >= cache->max_blocks)
panic("get_writable_cached_block: invalid block number %lld (max %lld)", blockNumber, cache->max_blocks - 1);
bool allocated; bool allocated;
cached_block *block = get_cached_block(cache, blockNumber, allocated, !cleared); cached_block *block = get_cached_block(cache, blockNumber, &allocated, !cleared);
if (block == NULL) if (block == NULL)
return NULL; return NULL;
@ -1205,7 +1214,7 @@ block_cache_get_etc(void *_cache, off_t blockNumber, off_t base, off_t length)
BenaphoreLocker locker(&cache->lock); BenaphoreLocker locker(&cache->lock);
bool allocated; bool allocated;
cached_block *block = get_cached_block(cache, blockNumber, allocated); cached_block *block = get_cached_block(cache, blockNumber, &allocated);
if (block == NULL) if (block == NULL)
return NULL; return NULL;