Skip to contentSkip to conversation

Fix incorrect zone count

PATCH New Vladimir 'φ-coder/phcoder' Serbinenko 1 participant 1 message May 9, 2012 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix incorrect zone count

Hello all. It seems that the zone map, inodes, inode maps and superblock aren't included in the zone map. At least it's the impression I've got from:
Super3.s_zmap_blocks = UPPER(BLOCKS -
(1+get_nimaps()+inode_blocks()),

                         BITS_PER_BLOCK+1);

However, in another place the assumption is opposite and this leads to an attempt to write outside the allocated buffer. Attached patch fixes it.

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
disk-utils/mkfs.minix.c +6 -5
index 051cd5f..fd68fc9 100644
@@ -421,13 +432,13 @@ static void super_set_nzones(void)
 {
 	switch (fs_version) {
 	case 3:
-		Super3.s_zones = BLOCKS;
+		Super3.s_zones = BLOCKS - Super3.s_zmap_blocks - (1+get_nimaps()+inode_blocks());
 		break;
 	case 2:
-		Super.s_zones = BLOCKS;
+		Super.s_zones = BLOCKS - Super.s_zmap_blocks - (1+get_nimaps()+inode_blocks());
 		break;
 	default: /* v1 */
-		Super.s_nzones = BLOCKS;
+		Super.s_nzones = BLOCKS - Super.s_zmap_blocks - (1+get_nimaps()+inode_blocks());
 		break;
 	}
 }
@@ -497,8 +508,6 @@ static void setup_tables(void) {
 	}
 
 	super_init_maxsize();
-	super_set_nzones();
-	zones = get_nzones();
 
 	/* some magic nrs: 1 inode / 3 blocks */
 	if ( req_nr_inodes == 0 ) 
@@ -522,6 +531,9 @@ static void setup_tables(void) {
 	}
 
 	super_set_map_blocks(inodes);
+	super_set_nzones();
+
+	zones = get_nzones();
 	imaps = get_nimaps();
 	zmaps = get_nzmaps();