[Ocfs2-tools-devel] [PATCH 19/20] o2image: Make it read group_desc properly.

Tao Ma tao.ma at oracle.com
Mon May 17 01:47:06 PDT 2010


Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
 include/ocfs2/ocfs2.h |    3 +++
 libocfs2/chain.c      |   27 +++++++++++++++++++++++++++
 o2image/o2image.c     |   10 ++++++----
 3 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 07ab375..42b5905 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -623,6 +623,9 @@ errcode_t ocfs2_read_group_desc(ocfs2_filesys *fs, uint64_t blkno,
 
 errcode_t ocfs2_write_group_desc(ocfs2_filesys *fs, uint64_t blkno,
 				 char *gd_buf);
+uint64_t ocfs2_get_block_from_group(ocfs2_filesys *fs,
+				    struct ocfs2_group_desc *grp,
+				    int bpc, int bit_offset);
 
 errcode_t ocfs2_chain_iterate(ocfs2_filesys *fs,
 			      uint64_t blkno,
diff --git a/libocfs2/chain.c b/libocfs2/chain.c
index fa9c16d..1111325 100644
--- a/libocfs2/chain.c
+++ b/libocfs2/chain.c
@@ -275,6 +275,33 @@ out_buf:
 	return ret;
 }
 
+uint64_t ocfs2_get_block_from_group(ocfs2_filesys *fs,
+				    struct ocfs2_group_desc *grp,
+				    int bpc, int bit_offset)
+{
+	int cpos, i;
+	struct ocfs2_extent_rec *rec;
+	int block_per_bit = ocfs2_clusters_to_blocks(fs, 1) / bpc;
+
+	if (!ocfs2_gd_is_discontig(grp))
+		return grp->bg_blkno + bit_offset * block_per_bit;
+
+	/* handle discontiguous group. */
+	cpos = bit_offset / bpc;
+	for (i = 0; i < grp->bg_list.l_next_free_rec; i++) {
+		rec = &grp->bg_list.l_recs[i];
+
+		if (rec->e_cpos <= cpos &&
+		    rec->e_cpos + rec->e_leaf_clusters > cpos)
+			break;
+	}
+
+	if (i == grp->bg_list.l_next_free_rec)
+		abort();
+
+	return rec->e_blkno + (bit_offset * block_per_bit -
+		ocfs2_clusters_to_blocks(fs, rec->e_cpos));
+}
 
 #ifdef DEBUG_EXE
 #include <stdlib.h>
diff --git a/o2image/o2image.c b/o2image/o2image.c
index dae649f..f8e72d7 100644
--- a/o2image/o2image.c
+++ b/o2image/o2image.c
@@ -62,7 +62,7 @@ static errcode_t mark_localalloc_bits(ocfs2_filesys *ofs,
 
 static errcode_t traverse_group_desc(ocfs2_filesys *ofs,
 				     struct ocfs2_group_desc *grp,
-				     int dump_type)
+				     int dump_type, int bpc)
 {
 	errcode_t ret = 0;
 	uint64_t blkno;
@@ -70,11 +70,12 @@ static errcode_t traverse_group_desc(ocfs2_filesys *ofs,
 
 	blkno = grp->bg_blkno;
 	for (i = 1; i < grp->bg_bits; i++) {
+		blkno = ocfs2_get_block_from_group(ofs, grp, bpc, i);
 		if ((dump_type == OCFS2_IMAGE_READ_INODE_YES) &&
 		    ocfs2_test_bit(i, grp->bg_bitmap))
-			ret = traverse_inode(ofs, (blkno + i));
+			ret = traverse_inode(ofs, blkno);
 		else
-			ocfs2_image_mark_bitmap(ofs, blkno + i);
+			ocfs2_image_mark_bitmap(ofs, blkno);
 	}
 	return ret;
 }
@@ -155,7 +156,8 @@ static errcode_t traverse_chains(ocfs2_filesys *ofs,
 
 			grp = (struct ocfs2_group_desc *)buf;
 			if (dump_type) {
-				ret = traverse_group_desc(ofs, grp, dump_type);
+				ret = traverse_group_desc(ofs, grp,
+						dump_type, cl->cl_bpc);
 				if (ret)
 					goto out;
 			}
-- 
1.5.5




More information about the Ocfs2-tools-devel mailing list