6 static void * tfs_read_block_bitmap(struct tfs_sb_info
*sbi
)
8 char *buf
= malloc(sbi
->s_block_size
);
10 tfs_bread(sbi
, sbi
->s_block_bitmap
, buf
);
16 * Free a block, return -1 if failed, or return 0
18 int tfs_free_block(struct tfs_sb_info
*sbi
, uint32_t block
)
20 char *bitmap
= tfs_read_block_bitmap(sbi
);
22 if (clear_bit(bitmap
, block
) == 0) {
23 printk("ERROR: trying to free an free block!\n");
28 tfs_bwrite(sbi
, sbi
->s_block_bitmap
, bitmap
);
33 int tfs_alloc_block(struct tfs_sb_info
*sbi
, uint32_t block
)
35 char *bitmap
= tfs_read_block_bitmap(sbi
);
37 /* try the target first */
38 if (test_bit(bitmap
, block
) != 0)
39 block
= find_first_zero(bitmap
, bitmap
+ sbi
->s_block_size
);
41 set_bit(bitmap
, block
);
42 tfs_bwrite(sbi
, sbi
->s_block_bitmap
, bitmap
);