Blame SOURCES/bz1518938-gfs2_edit_Print_offsets_of_indirect_pointers.patch

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