Skip to contentSkip to conversation

ext4: Rename block group descriptor table from gd to bgd

PATCH New Simon Glass 2 participants 2 messages Oct 3, 2012 – Oct 4, 2012 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ext4: Rename block group descriptor table from gd to bgd

On x86 machines gd is unfortunately a #define, so we should avoid using gd for anything. This patch changes uses of gd to bgd so that ext4fs can be used on x86.

A better fix would be to remove the #define in x86, but I'm not sure how to do that.

---
Changes in v2:
- Don't change name of ext4fs_get_bgdtable() function
- Drop warning patch, which seems to be due to a buggy compiler

 fs/ext4/ext4_common.c |   85 ++++++++++++++++++++++--------------------
 fs/ext4/ext4fs.c      |   99 +++++++++++++++++++++++++------------------------
 include/ext4fs.h      |    2 +-
 3 files changed, 95 insertions(+), 91 deletions(-)
fs/ext4/ext4_common.c +44 -41
index 3deffd5..d6d55b9 100644
@@ -314,7 +314,7 @@ int ext4fs_checksum_update(unsigned int i)
 	struct ext_filesystem *fs = get_fs();
 	__u16 crc = 0;
 
-	desc = (struct ext2_block_group *)&fs->gd[i];
+	desc = (struct ext2_block_group *)&fs->bgd[i];
 	if (fs->sb->feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
 		int offset = offsetof(struct ext2_block_group, bg_checksum);
 
@@ -874,17 +874,17 @@ long int ext4fs_get_new_blk_no(void)
 	char *zero_buffer = zalloc(fs->blksz);
 	if (!journal_buffer || !zero_buffer)
 		goto fail;
-	struct ext2_block_group *gd = (struct ext2_block_group *)fs->gdtable;
+	struct ext2_block_group *bgd = (struct ext2_block_group *)fs->gdtable;
 
 	if (fs->first_pass_bbmap == 0) {
 		for (i = 0; i < fs->no_blkgrp; i++) {
-			if (gd[i].free_blocks) {
-				if (gd[i].bg_flags & EXT4_BG_BLOCK_UNINIT) {
-					put_ext4(((uint64_t) (gd[i].block_id *
+			if (bgd[i].free_blocks) {
+				if (bgd[i].bg_flags & EXT4_BG_BLOCK_UNINIT) {
+					put_ext4(((uint64_t) (bgd[i].block_id *
 							      fs->blksz)),
 						 zero_buffer, fs->blksz);
-					gd[i].bg_flags =
-					    gd[i].
+					bgd[i].bg_flags =
+					    bgd[i].
 					    bg_flags & ~EXT4_BG_BLOCK_UNINIT;
 					memcpy(fs->blk_bmaps[i], zero_buffer,
 					       fs->blksz);
@@ -897,16 +897,16 @@ long int ext4fs_get_new_blk_no(void)
 				fs->curr_blkno = fs->curr_blkno +
 						(i * fs->blksz * 8);
 				fs->first_pass_bbmap++;
-				gd[i].free_blocks--;
+				bgd[i].free_blocks--;
 				fs->sb->free_blocks--;
-				status = ext4fs_devread(gd[i].block_id *
+				status = ext4fs_devread(bgd[i].block_id *
 							fs->sect_perblk, 0,
 							fs->blksz,
 							journal_buffer);
 				if (status == 0)
 					goto fail;
 				if (ext4fs_log_journal(journal_buffer,
-							gd[i].block_id))
+							bgd[i].block_id))
 					goto fail;
 				goto success;
 			} else {
@@ -935,19 +935,19 @@ restart:
 		if (bg_idx >= fs->no_blkgrp)
 			goto fail;
 
-		if (gd[bg_idx].free_blocks == 0) {
+		if (bgd[bg_idx].free_blocks == 0) {
 			debug("block group %u is full. Skipping\n", bg_idx);
 			fs->curr_blkno = fs->curr_blkno + blk_per_grp;
 			fs->curr_blkno--;
 			goto restart;
 		}
 
-		if (gd[bg_idx].bg_flags & EXT4_BG_BLOCK_UNINIT) {
+		if (bgd[bg_idx].bg_flags & EXT4_BG_BLOCK_UNINIT) {
 			memset(zero_buffer, '\0', fs->blksz);
-			put_ext4(((uint64_t) (gd[bg_idx].block_id * fs->blksz)),
-				 zero_buffer, fs->blksz);
+			put_ext4(((uint64_t) (bgd[bg_idx].block_id *
+					fs->blksz)), zero_buffer, fs->blksz);
 			memcpy(fs->blk_bmaps[bg_idx], zero_buffer, fs->blksz);
-			gd[bg_idx].bg_flags = gd[bg_idx].bg_flags &
+			bgd[bg_idx].bg_flags = bgd[bg_idx].bg_flags &
 						~EXT4_BG_BLOCK_UNINIT;
 		}
 
@@ -961,18 +961,18 @@ restart:
 		/* journal backup */
 		if (prev_bg_bitmap_index != bg_idx) {
 			memset(journal_buffer, '\0', fs->blksz);
-			status = ext4fs_devread(gd[bg_idx].block_id
+			status = ext4fs_devread(bgd[bg_idx].block_id
 						* fs->sect_perblk,
 						0, fs->blksz, journal_buffer);
 			if (status == 0)
 				goto fail;
 			if (ext4fs_log_journal(journal_buffer,
-						gd[bg_idx].block_id))
+						bgd[bg_idx].block_id))
 				goto fail;
 
 			prev_bg_bitmap_index = bg_idx;
 		}
-		gd[bg_idx].free_blocks--;
+		bgd[bg_idx].free_blocks--;
 		fs->sb->free_blocks--;
 		goto success;
 	}
@@ -1000,19 +1000,21 @@ int ext4fs_get_new_inode_no(void)
 	char *zero_buffer = zalloc(fs->blksz);
 	if (!journal_buffer || !zero_buffer)
 		goto fail;
-	struct ext2_block_group *gd = (struct ext2_block_group *)fs->gdtable;
+	struct ext2_block_group *bgd = (struct ext2_block_group *)fs->gdtable;
 
 	if (fs->first_pass_ibmap == 0) {
 		for (i = 0; i < fs->no_blkgrp; i++) {
-			if (gd[i].free_inodes) {
-				if (gd[i].bg_itable_unused != gd[i].free_inodes)
-					gd[i].bg_itable_unused =
-						gd[i].free_inodes;
-				if (gd[i].bg_flags & EXT4_BG_INODE_UNINIT) {
+			if (bgd[i].free_inodes) {
+				if (bgd[i].bg_itable_unused !=
+						bgd[i].free_inodes)
+					bgd[i].bg_itable_unused =
+						bgd[i].free_inodes;
+				if (bgd[i].bg_flags & EXT4_BG_INODE_UNINIT) {
 					put_ext4(((uint64_t)
-						  (gd[i].inode_id * fs->blksz)),
+						  (bgd[i].inode_id *
+							fs->blksz)),
 						 zero_buffer, fs->blksz);
-					gd[i].bg_flags = gd[i].bg_flags &
+					bgd[i].bg_flags = bgd[i].bg_flags &
 							~EXT4_BG_INODE_UNINIT;
 					memcpy(fs->inode_bmaps[i],
 					       zero_buffer, fs->blksz);
@@ -1025,17 +1027,17 @@ int ext4fs_get_new_inode_no(void)
 				fs->curr_inode_no = fs->curr_inode_no +
 							(i * inodes_per_grp);
 				fs->first_pass_ibmap++;
-				gd[i].free_inodes--;
-				gd[i].bg_itable_unused--;
+				bgd[i].free_inodes--;
+				bgd[i].bg_itable_unused--;
 				fs->sb->free_inodes--;
-				status = ext4fs_devread(gd[i].inode_id *
+				status = ext4fs_devread(bgd[i].inode_id *
 							fs->sect_perblk, 0,
 							fs->blksz,
 							journal_buffer);
 				if (status == 0)
 					goto fail;
 				if (ext4fs_log_journal(journal_buffer,
-							gd[i].inode_id))
+							bgd[i].inode_id))
 					goto fail;
 				goto success;
 			} else
@@ -1047,13 +1049,13 @@ restart:
 		fs->curr_inode_no++;
 		/* get the blockbitmap index respective to blockno */
 		ibmap_idx = fs->curr_inode_no / inodes_per_grp;
-		if (gd[ibmap_idx].bg_flags & EXT4_BG_INODE_UNINIT) {
+		if (bgd[ibmap_idx].bg_flags & EXT4_BG_INODE_UNINIT) {
 			memset(zero_buffer, '\0', fs->blksz);
-			put_ext4(((uint64_t) (gd[ibmap_idx].inode_id *
+			put_ext4(((uint64_t) (bgd[ibmap_idx].inode_id *
 					      fs->blksz)), zero_buffer,
 				 fs->blksz);
-			gd[ibmap_idx].bg_flags =
-			    gd[ibmap_idx].bg_flags & ~EXT4_BG_INODE_UNINIT;
+			bgd[ibmap_idx].bg_flags =
+			    bgd[ibmap_idx].bg_flags & ~EXT4_BG_INODE_UNINIT;
 			memcpy(fs->inode_bmaps[ibmap_idx], zero_buffer,
 				fs->blksz);
 		}
@@ -1069,21 +1071,22 @@ restart:
 		/* journal backup */
 		if (prev_inode_bitmap_index != ibmap_idx) {
 			memset(journal_buffer, '\0', fs->blksz);
-			status = ext4fs_devread(gd[ibmap_idx].inode_id
+			status = ext4fs_devread(bgd[ibmap_idx].inode_id
 						* fs->sect_perblk,
 						0, fs->blksz, journal_buffer);
 			if (status == 0)
 				goto fail;
 			if (ext4fs_log_journal(journal_buffer,
-						gd[ibmap_idx].inode_id))
+						bgd[ibmap_idx].inode_id))
 				goto fail;
 			prev_inode_bitmap_index = ibmap_idx;
 		}
-		if (gd[ibmap_idx].bg_itable_unused != gd[ibmap_idx].free_inodes)
-			gd[ibmap_idx].bg_itable_unused =
-					gd[ibmap_idx].free_inodes;
-		gd[ibmap_idx].free_inodes--;
-		gd[ibmap_idx].bg_itable_unused--;
+		if (bgd[ibmap_idx].bg_itable_unused !=
+				bgd[ibmap_idx].free_inodes)
+			bgd[ibmap_idx].bg_itable_unused =
+					bgd[ibmap_idx].free_inodes;
+		bgd[ibmap_idx].free_inodes--;
+		bgd[ibmap_idx].bg_itable_unused--;
 		fs->sb->free_inodes--;
 		goto success;
 	}
fs/ext4/ext4fs.c +50 -49

342 lines not on this page · raw message

include/ext4fs.h +1 -1
index b6eedde..23298fc 100644
@@ -94,7 +94,7 @@ struct ext_filesystem {
 	/* Superblock */
 	struct ext2_sblock *sb;
 	/* Block group descritpor table */
-	struct ext2_block_group *gd;
+	struct ext2_block_group *bgd;
 	char *gdtable;
 
 	/* Block Bitmap Related */
Signature · 1 line
1.7.7.3
#1 lore raw

PATCH v2 1/1 ext4: Rename block group descriptor table from gd to bgd

Quoted 8 lines · Simon Glass

On x86 machines gd is unfortunately a #define, so we should avoid using gd for anything. This patch changes uses of gd to bgd so that ext4fs can be used on x86.

A better fix would be to remove the #define in x86, but I'm not sure how to do that.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20121003/25c74e1f/attachment.pgp>