shithub: lwext4

Download patch

ref: 3617716d33737c103e81870132c28a699170752e
parent: 69140168fc01b4bddb8bee96e9e34a238898b2c4
author: gkostka <kostka.grzegorz@gmail.com>
date: Tue Nov 17 17:16:20 EST 2015

Improve bg init in mkfs

--- a/lwext4/ext4_mkfs.c
+++ b/lwext4/ext4_mkfs.c
@@ -157,7 +157,7 @@
 			aux_info->blocks_per_dind * aux_info->blocks_per_dind;
 
 	aux_info->bg_desc_blocks =
-		DIV_ROUND_UP(aux_info->groups * sizeof(struct ext4_bgroup),
+		DIV_ROUND_UP(aux_info->groups * info->dsc_size,
 			info->block_size);
 
 	aux_info->default_i_flags = EXT4_INODE_FLAG_NOATIME;
@@ -306,7 +306,7 @@
 		uint32_t blk_off = 0;
 
 		bg_free_blk = info->blocks_per_group -
-			(aux_info->inode_table_blocks + aux_info->bg_desc_blocks);
+				aux_info->inode_table_blocks;
 
 		bg_free_blk -= 2;
 		blk_off += aux_info->bg_desc_blocks;
@@ -315,8 +315,7 @@
 			bg_start_block++;
 			blk_off += info->bg_desc_reserve_blocks;
 			bg_free_blk -= info->bg_desc_reserve_blocks + 1;
-		} else {
-			bg_free_blk++;
+			bg_free_blk -= aux_info->bg_desc_blocks;
 		}
 
 		ext4_bg_set_block_bitmap(&aux_info->bg_desc[i], aux_info->sb,
@@ -357,7 +356,7 @@
 	struct ext4_block b;
 	for (i = 0; i < aux_info->groups; i++) {
 		uint64_t bg_start_block = aux_info->first_data_block +
-			aux_info->first_data_block + i * info->blocks_per_group;
+			+ i * info->blocks_per_group;
 		uint32_t blk_off = 0;
 
 		blk_off += aux_info->bg_desc_blocks;
@@ -378,7 +377,8 @@
 			if (r != EOK)
 				return r;
 
-			while (dsc_pos + dsc_size < block_size) {
+			dsc_pos = 0;
+			while (dsc_pos + dsc_size <= block_size) {
 				memcpy(b.data + dsc_pos,
 				       &aux_info->bg_desc[dsc_id],
 				       dsc_size);