aboutsummaryrefslogtreecommitdiff
path: root/ext2fs/getblk.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext2fs/getblk.c')
-rw-r--r--ext2fs/getblk.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/ext2fs/getblk.c b/ext2fs/getblk.c
index 23ba6459..bde66e1c 100644
--- a/ext2fs/getblk.c
+++ b/ext2fs/getblk.c
@@ -104,7 +104,7 @@ ext2_alloc_block (struct node *node, block_t goal, int zero)
if (result && zero)
{
- char *bh = bptr (result);
+ char *bh = disk_cache_block_ref (result);
bzero (bh, block_size);
record_indir_poke (node, bh);
}
@@ -122,6 +122,8 @@ inode_getblk (struct node *node, int nr, int create, int zero,
block_t hint;
#endif
+ assert (0 <= nr && nr < EXT2_N_BLOCKS);
+
*result = node->dn->info.i_data[nr];
if (*result)
return 0;
@@ -180,14 +182,20 @@ block_getblk (struct node *node, block_t block, int nr, int create, int zero,
{
int i;
block_t goal = 0;
- block_t *bh = (block_t *)bptr (block);
+ block_t *bh = (block_t *)disk_cache_block_ref (block);
*result = bh[nr];
if (*result)
- return 0;
+ {
+ disk_cache_block_deref (bh);
+ return 0;
+ }
if (!create)
- return EINVAL;
+ {
+ disk_cache_block_deref (bh);
+ return EINVAL;
+ }
if (node->dn->info.i_next_alloc_block == new_block)
goal = node->dn->info.i_next_alloc_goal;
@@ -207,7 +215,10 @@ block_getblk (struct node *node, block_t block, int nr, int create, int zero,
*result = ext2_alloc_block (node, goal, zero);
if (!*result)
- return ENOSPC;
+ {
+ disk_cache_block_deref (bh);
+ return ENOSPC;
+ }
bh[nr] = *result;