Blame SOURCES/bz1518938-gfs2_edit_Print_offsets_of_indirect_pointers.patch

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