Skip to contentSkip to conversation

pu branch: fix more direct fs->group_desc accesses

PATCH In review Eric Sandeen 2 participants 2 messages Sep 25, 2009 – Oct 5, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 pu branch: fix more direct fs->group_desc accesses

This fixes still more direct accesses to fs->group_desc fields off a normal array index (group_desc[i]). Since we have variable sized group_desc depending on the group_desc size, these all must go through accessor functions.

---

debugfs/set_fields.c +0 -0
index 7ba7782..88cf411 100644
@@ -415,7 +415,10 @@ static errcode_t parse_gd_csum(struct field_set_info *info, char *arg)
 
	if (strcmp(arg, "calc") == 0) {
		ext2fs_group_desc_csum_set(current_fs, set_bg);

- set_gd = current_fs->group_desc[set_bg];
+ memcpy(&set_gd, ext2fs_group_desc(current_fs,
+ current_fs->group_desc,
+ set_bg),

+			sizeof(set_gd));
		printf("Checksum set to 0x%04x\n",
		       ext2fs_bg_checksum(current_fs, set_bg));
		return 0;
@@ -570,10 +573,14 @@ void do_set_block_group_descriptor(int argc, char *argv[])
		return;
	}

- set_gd = current_fs->group_desc[set_bg];
+ memcpy(&set_gd, ext2fs_group_desc(current_fs,
+ current_fs->group_desc, set_bg),
+ sizeof(set_gd));

	if (ss->func(ss, argv[3]) == 0) {
-		current_fs->group_desc[set_bg] = set_gd;
+		memcpy(ext2fs_group_desc(current_fs,
+				current_fs->group_desc, set_bg),
+		       &set_gd, sizeof(set_gd));
		ext2fs_mark_super_dirty(current_fs);
	}
}
lib/ext2fs/closefs.c +0 -0
index cc3a884..a04d560 100644
@@ -303,7 +303,7 @@ errcode_t ext2fs_flush(ext2_filsys fs)
	}
#else
	super_shadow = fs->super;

- group_shadow = fs->group_desc;
+ group_shadow = ext2fs_group_desc(fs, fs->group_desc, 0);
#endif

	/*
lib/ext2fs/csum.c +0 -0
index a6661b7..b99be26 100644
@@ -204,9 +204,9 @@ int main(int argc, char **argv)
		ext2fs_block_bitmap_loc_set(fs, i, 124);
		ext2fs_inode_bitmap_loc_set(fs, i, 125);
		ext2fs_inode_table_loc_set(fs, i, 126);

- fs->group_desc[i].bg_free_blocks_count = 31119;
- fs->group_desc[i].bg_free_inodes_count = 15701;
- fs->group_desc[i].bg_used_dirs_count = 2;
+ ext2fs_bg_free_blocks_count_set(fs, i, 31119);
+ ext2fs_bg_free_inodes_count_set(fs, i, 15701);

+		ext2fs_bg_used_dirs_count_set(fs, i, 2);
		ext2fs_bg_flags_zap(fs, i);
	};

@@ -249,7 +249,7 @@ int main(int argc, char **argv)

	csum1 = ext2fs_group_desc_csum(fs, 0);
	ext2fs_bg_checksum_set(fs, 0, csum1);
	print_csum("csum_new", fs, 0);
-	fs->group_desc[0].bg_free_blocks_count = 1;
+	ext2fs_bg_free_blocks_count_set(fs, 0, 1);
	csum2 = ext2fs_group_desc_csum(fs, 0);
	print_csum("csum_blk", fs, 0);
	if (csum1 == csum2) {
misc/tune2fs.c +0 -0
index c81f625..dea3366 100644
@@ -1021,9 +1021,9 @@ static int ext2fs_is_meta_block(ext2_filsys fs, blk_t blk)
{
	dgrp_t group;
	group = ext2fs_group_of_blk(fs, blk);
-	if (fs->group_desc[group].bg_block_bitmap == blk)
+	if (ext2fs_block_bitmap_loc(fs, group) == blk)
		return 1;
-	if (fs->group_desc[group].bg_inode_bitmap == blk)
+	if (ext2fs_inode_bitmap_loc(fs, group) == blk)
		return 1;
	return 0;
}
@@ -1233,20 +1233,20 @@ static int group_desc_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
	blk_t blk, new_blk;

	for (i = 0; i < fs->group_desc_count; i++) {
-		blk = fs->group_desc[i].bg_block_bitmap;
+		blk = ext2fs_block_bitmap_loc(fs, i);
		if (ext2fs_test_block_bitmap2(bmap, blk)) {
			new_blk = translate_block(blk);
			if (!new_blk)
				continue;
-			fs->group_desc[i].bg_block_bitmap = new_blk;
+			ext2fs_block_bitmap_loc_set(fs, i, new_blk);
		}

- blk = fs->group_desc[i].bg_inode_bitmap;

+		blk = ext2fs_inode_bitmap_loc(fs, i);
		if (ext2fs_test_block_bitmap2(bmap, blk)) {
			new_blk = translate_block(blk);
			if (!new_blk)
				continue;
-			fs->group_desc[i].bg_inode_bitmap = new_blk;
+			ext2fs_inode_bitmap_loc_set(fs, i, new_blk);
		}
	}
	return 0;
resize/resize2fs.c +0 -0
index 9a70b27..0d3f05f 100644
@@ -438,7 +438,8 @@ retry:
		for (i = fs->group_desc_count;
		     i < old_fs->group_desc_count; i++) {
			free_gdp_blocks(fs, reserve_blocks,
-					&old_fs->group_desc[i]);
+					ext2fs_group_desc(old_fs,
+						old_fs->group_desc, i));
		}
		retval = 0;
		goto errout;
#1 lore raw
Quoted 6 lines · Eric Sandeen

This fixes still more direct accesses to fs->group_desc fields off a normal array index (group_desc[i]). Since we have variable sized group_desc depending on the group_desc size, these all must go through accessor functions.

Thanks, I've added it to the pu branch. (Haven't pushed it out yet though; still doing some clean up work. I'll push out a new pu branch in a day or so.)

- Ted