Blame SOURCES/bz1518938-gfs2_edit_Print_offsets_of_indirect_pointers.patch

744fcf
commit 1a093d1233a4d5ef83d6141928f5de693f1333ee
744fcf
Author: Andrew Price <anprice@redhat.com>
744fcf
Date:   Thu Nov 30 19:00:31 2017 +0000
744fcf
744fcf
    gfs2_edit: Print offsets of indirect pointers
744fcf
    
744fcf
    When printing indirect pointers gfs2_edit doesn't keep track of the
744fcf
    location of the pointer within the indirect block and only prints an
744fcf
    index for each non-zero pointer. Instead, store the offset of each
744fcf
    non-zero pointer and print it when displaying indirect blocks, as it is
744fcf
    done in interactive mode.
744fcf
    
744fcf
    Resolves: rhbz#1518938
744fcf
    
744fcf
    Signed-off-by: Andrew Price <anprice@redhat.com>
744fcf
744fcf
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
744fcf
index e8048532..214fdba4 100644
744fcf
--- a/gfs2/edit/extended.c
744fcf
+++ b/gfs2/edit/extended.c
744fcf
@@ -51,6 +51,7 @@ static int get_height(void)
744fcf
 static int _do_indirect_extended(char *diebuf, struct iinfo *iinf, int hgt)
744fcf
 {
744fcf
 	unsigned int x, y;
744fcf
+	off_t headoff;
744fcf
 	uint64_t p;
744fcf
 	int i_blocks;
744fcf
 
744fcf
@@ -62,15 +63,14 @@ static int _do_indirect_extended(char *diebuf, struct iinfo *iinf, int hgt)
744fcf
 		iinf->ii[x].dirents = 0;
744fcf
 		memset(&iinf->ii[x].dirent, 0, sizeof(struct gfs2_dirents));
744fcf
 	}
744fcf
-	for (x = (sbd.gfs1 ? sizeof(struct gfs_indirect):
744fcf
-			  sizeof(struct gfs2_meta_header)), y = 0;
744fcf
-		 x < sbd.bsize;
744fcf
-		 x += sizeof(uint64_t), y++) {
744fcf
+	headoff = sbd.gfs1 ? sizeof(struct gfs_indirect) : sizeof(struct gfs2_meta_header);
744fcf
+	for (x = headoff, y = 0; x < sbd.bsize; x += sizeof(uint64_t), y++) {
744fcf
 		p = be64_to_cpu(*(uint64_t *)(diebuf + x));
744fcf
 		if (p) {
744fcf
 			iinf->ii[i_blocks].block = p;
744fcf
 			iinf->ii[i_blocks].mp.mp_list[hgt] = i_blocks;
744fcf
 			iinf->ii[i_blocks].is_dir = FALSE;
744fcf
+			iinf->ii[i_blocks].ptroff = (x - headoff) / sizeof(uint64_t);
744fcf
 			i_blocks++;
744fcf
 		}
744fcf
 	}
744fcf
@@ -177,7 +177,7 @@ static int display_indirect(struct iinfo *ind, int indblocks, int level,
744fcf
 			for (h = 0; h < level; h++)
744fcf
 				print_gfs2("   ");
744fcf
 		}
744fcf
-		print_gfs2("%d => ", pndx);
744fcf
+		print_gfs2("%d: 0x%"PRIx64" => ", pndx, ind->ii[pndx].ptroff);
744fcf
 		if (termlines)
744fcf
 			move(line,9);
744fcf
 		print_gfs2("0x%"PRIx64" / %"PRId64, ind->ii[pndx].block,
744fcf
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
744fcf
index 3d0f10dd..8abadd21 100644
744fcf
--- a/gfs2/edit/gfs2hex.c
744fcf
+++ b/gfs2/edit/gfs2hex.c
744fcf
@@ -255,6 +255,8 @@ void do_dinode_extended(struct gfs2_dinode *dine, struct gfs2_buffer_head *lbh)
744fcf
 				indirect->ii[indirect_blocks].mp.mp_list[0] =
744fcf
 					ptroff;
744fcf
 				indirect->ii[indirect_blocks].is_dir = FALSE;
744fcf
+				indirect->ii[indirect_blocks].ptroff =
744fcf
+				              (x - sizeof(*dine)) / sizeof(uint64_t);
744fcf
 				indirect_blocks++;
744fcf
 			}
744fcf
 			ptroff++;
744fcf
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
744fcf
index 4f7207b0..d2992d8e 100644
744fcf
--- a/gfs2/edit/hexedit.h
744fcf
+++ b/gfs2/edit/hexedit.h
744fcf
@@ -81,6 +81,7 @@ struct indirect_info {
744fcf
 	struct gfs2_leaf lf;
744fcf
 	struct metapath mp;
744fcf
 	struct gfs2_dirents dirent[64];
744fcf
+	uint64_t ptroff;
744fcf
 };
744fcf
 
744fcf
 struct iinfo {