File gfs2_edit_display_block_allocation_on_rgrps_and_bitmaps.patch of Package cluster

commit 3b0691b0cbead65ed91c9cf3e2d9cd833b9471ad
Author: Bob Peterson <bob@krishna.(none)>
Date:   Tue Oct 5 04:51:52 2010 -0500

    gfs2_edit: display block allocation on rgrps and bitmaps
    
    This patch displays the bit settings for bits as you walk your
    cursor through gfs2 bitmaps.
    
    rhbz#634623

diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 1fd9e77..d900c93 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -1090,7 +1090,7 @@ int display_block_type(int from_restore)
 			break;
 		case GFS2_METATYPE_RB:   /* 3 */
 			print_gfs2("(rsrc grp bitblk)");
-			struct_len = 512;
+			struct_len = sizeof(struct gfs2_meta_header);
 			break;
 		case GFS2_METATYPE_DI:   /* 4 */
 			print_gfs2("(disk inode)");
@@ -1158,8 +1158,11 @@ int display_block_type(int from_restore)
 		rgd = gfs2_blk2rgrpd(&sbd, block);
 		if (rgd) {
 			gfs2_rgrp_read(&sbd, rgd);
-			type = gfs2_get_bitmap(&sbd, block, rgd);
-			gfs2_rgrp_relse(rgd);
+			if ((*(bh->b_data + 7) == GFS2_METATYPE_RG) ||
+			    (*(bh->b_data + 7) == GFS2_METATYPE_RB))
+				type = 4;
+			else
+				type = gfs2_get_bitmap(&sbd, block, rgd);
 		} else
 			type = 4;
 		screen_chunk_size = ((termlines - 4) * 16) >> 8 << 8;
@@ -1171,7 +1174,60 @@ int display_block_type(int from_restore)
 			   sbd.bsize / screen_chunk_size + 1 : sbd.bsize /
 			   screen_chunk_size, allocdesc[gfs1][type]);
 		/*eol(9);*/
-	}
+		if ((*(bh->b_data + 7) == GFS2_METATYPE_RG)) {
+			int ptroffset = edit_row[dmode] * 16 + edit_col[dmode];
+
+			if (ptroffset >= struct_len || pgnum) {
+				int blknum, b, btype;
+
+				blknum = pgnum * screen_chunk_size;
+				blknum += (ptroffset - struct_len);
+				blknum *= 4;
+				blknum += rgd->ri.ri_data0;
+
+				print_gfs2(" blk ");
+				for (b = blknum; b < blknum + 4; b++) {
+					btype = gfs2_get_bitmap(&sbd, b, rgd);
+					print_gfs2("0x%x-%s  ", b,
+						   allocdesc[gfs1][btype]);
+				}
+			}
+		} else if ((*(bh->b_data + 7) == GFS2_METATYPE_RB)) {
+			int ptroffset = edit_row[dmode] * 16 + edit_col[dmode];
+
+			if (ptroffset >= struct_len || pgnum) {
+				int blknum, b, btype, rb_number;
+
+				rb_number = block - rgd->ri.ri_addr;
+				blknum = 0;
+				/* count the number of bytes representing
+				   blocks prior to the displayed screen. */
+				for (b = 0; b < rb_number; b++) {
+					struct_len = (b ?
+					      sizeof(struct gfs2_meta_header) :
+					      sizeof(struct gfs2_rgrp));
+					blknum += (sbd.bsize - struct_len);
+				}
+				struct_len = sizeof(struct gfs2_meta_header);
+				/* add the number of bytes on this screen */
+				blknum += (ptroffset - struct_len);
+				/* factor in the page number */
+				blknum += pgnum * screen_chunk_size;
+				/* convert bytes to blocks */
+				blknum *= GFS2_NBBY;
+				/* add the starting offset for this rgrp */
+				blknum += rgd->ri.ri_data0;
+				print_gfs2(" blk ");
+				for (b = blknum; b < blknum + 4; b++) {
+					btype = gfs2_get_bitmap(&sbd, b, rgd);
+					print_gfs2("0x%x-%s  ", b,
+						   allocdesc[gfs1][btype]);
+				}
+			}
+		}
+		if (rgd)
+			gfs2_rgrp_relse(rgd);
+ 	}
 	if (block == sbd.sd_sb.sb_root_dir.no_addr)
 		print_gfs2("--------------- Root directory ------------------");
 	else if (!gfs1 && block == sbd.sd_sb.sb_master_dir.no_addr)
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index d442633..d37ed1b 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -104,12 +104,18 @@ struct rgrp_list *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, uint64_t blk)
 		ri = &prev_rgd->ri;
 		if (ri->ri_data0 <= blk && blk < ri->ri_data0 + ri->ri_data)
 			return prev_rgd;
+		if (blk >= ri->ri_addr && blk < ri->ri_addr + ri->ri_length)
+			return prev_rgd;
 	}
 
 	for (tmp = sdp->rglist.next; tmp != &sdp->rglist; tmp = tmp->next) {
 		rgd = osi_list_entry(tmp, struct rgrp_list, list);
 		ri = &rgd->ri;
 
+		if (blk >= ri->ri_addr && blk < ri->ri_addr + ri->ri_length) {
+			prev_rgd = rgd;
+			return rgd;
+		}
 		if (ri->ri_data0 <= blk && blk < ri->ri_data0 + ri->ri_data) {
 			prev_rgd = rgd;
 			return rgd;