[Ocfs2-tools-devel] [patch 10/11] Modify debugfs.ocfs2 for sparse files.take 2

tao.ma at oracle.com tao.ma at oracle.com
Wed Aug 22 17:08:24 PDT 2007


This vesion has included Mark's modification of printing empty extent records. 
Index: quilt.ocfs2-tools/debugfs.ocfs2/commands.c
===================================================================
--- quilt.ocfs2-tools.orig/debugfs.ocfs2/commands.c	2007-08-21 06:38:06.000000000 -0400
+++ quilt.ocfs2-tools/debugfs.ocfs2/commands.c	2007-08-22 05:51:42.000000000 -0400
@@ -426,21 +426,34 @@ static errcode_t find_block_offset(ocfs2
 	errcode_t ret = 0;
 	char *buf = NULL;
 	int i;
-	uint32_t clstoff;
+	uint32_t clstoff, clusters;
 	uint32_t tmp;
 
 	clstoff = ocfs2_blocks_to_clusters(fs, blkoff);
 
 	for (i = 0; i < el->l_next_free_rec; ++i) {
 		rec = &(el->l_recs[i]);
+		clusters = ocfs2_rec_clusters(el->l_tree_depth, rec);
 
-		/* TODO Fix to handle sparse trees */
-		if (clstoff >= (rec->e_cpos + rec->e_clusters))
+		/*
+		 * For a sparse file, we may find an empty record.
+		 * Just skip it.
+		 */
+		if (!clusters)
+			continue;
+
+		if (clstoff >= (rec->e_cpos + clusters))
 			continue;
 
 		if (!el->l_tree_depth) {
-			tmp = blkoff - ocfs2_clusters_to_blocks(fs, clstoff);
-			dump_logical_blkno(out, rec->e_blkno + tmp);
+			if (clstoff < rec->e_cpos) {
+				dump_logical_blkno(out, 0);
+			} else {
+				tmp = blkoff -
+					ocfs2_clusters_to_blocks(fs,
+								 rec->e_cpos);
+				dump_logical_blkno(out, rec->e_blkno + tmp);
+			}
 			goto bail;
 		}
 
@@ -482,11 +495,23 @@ static errcode_t traverse_extents (ocfs2
 	errcode_t ret = 0;
 	char *buf = NULL;
 	int i;
+	uint32_t clusters;
 
 	dump_extent_list (out, el);
 
 	for (i = 0; i < el->l_next_free_rec; ++i) {
 		rec = &(el->l_recs[i]);
+		clusters = ocfs2_rec_clusters(el->l_tree_depth, rec);
+
+		/*
+		 * In a unsuccessful insertion, we may shift a tree
+		 * add a new branch for it and do no insertion. So we
+		 * may meet a extent block which have
+		 * clusters == 0, this should only be happen
+		 * in the last extent rec. */
+		if (!clusters && i == el->l_next_free_rec - 1)
+			break;
+
 		if (el->l_tree_depth) {
 			ret = ocfs2_malloc_block(gbls.fs->fs_io, &buf);
 			if (ret)
Index: quilt.ocfs2-tools/debugfs.ocfs2/dump.c
===================================================================
--- quilt.ocfs2-tools.orig/debugfs.ocfs2/dump.c	2007-08-21 06:38:06.000000000 -0400
+++ quilt.ocfs2-tools/debugfs.ocfs2/dump.c	2007-08-22 05:51:42.000000000 -0400
@@ -296,6 +296,7 @@ void dump_extent_list (FILE *out, struct
 {
 	struct ocfs2_extent_rec *rec;
 	int i;
+	uint32_t clusters;
 
 	fprintf(out, "\tTree Depth: %u   Count: %u   Next Free Rec: %u\n",
 		ext->l_tree_depth, ext->l_count, ext->l_next_free_rec);
@@ -303,12 +304,25 @@ void dump_extent_list (FILE *out, struct
 	if (!ext->l_next_free_rec)
 		goto bail;
 
-	fprintf(out, "\t## %-11s   %-12s   %-s\n", "Offset", "Clusters", "Block#");
+	if (ext->l_tree_depth)
+		fprintf(out, "\t## %-11s   %-12s   %-s\n", "Offset",
+			"Clusters", "Block#");
+	else
+		fprintf(out, "\t## %-11s   %-12s   %-13s   %s\n", "Offset",
+			"Clusters", "Block#", "Flags");
 
 	for (i = 0; i < ext->l_next_free_rec; ++i) {
 		rec = &(ext->l_recs[i]);
-		fprintf(out, "\t%-2d %-11u   %-12u   %"PRIu64"\n",
-		       	i, rec->e_cpos, rec->e_clusters, rec->e_blkno);
+		clusters = ocfs2_rec_clusters(ext->l_tree_depth, rec);
+
+		if (ext->l_tree_depth)
+			fprintf(out, "\t%-2d %-11u   %-12u   %"PRIu64"\n",
+				i, rec->e_cpos, clusters, rec->e_blkno);
+		else
+			fprintf(out,
+				"\t%-2d %-11u   %-12u   %-13"PRIu64"   0x%x\n",
+				i, rec->e_cpos, clusters, rec->e_blkno,
+				rec->e_flags);
 	}
 
 bail:
Index: quilt.ocfs2-tools/debugfs.ocfs2/find_block_inode.c
===================================================================
--- quilt.ocfs2-tools.orig/debugfs.ocfs2/find_block_inode.c	2007-08-21 06:38:06.000000000 -0400
+++ quilt.ocfs2-tools/debugfs.ocfs2/find_block_inode.c	2007-08-22 05:51:42.000000000 -0400
@@ -49,6 +49,7 @@ static errcode_t lookup_regular(ocfs2_fi
 	int i;
 	int j;
 	uint64_t numblks;
+	uint32_t clusters;
 
 	if (*found >= count)
 		return 0;
@@ -63,6 +64,15 @@ static errcode_t lookup_regular(ocfs2_fi
 
 	for (i = 0; i < el->l_next_free_rec; ++i) {
 		rec = &(el->l_recs[i]);
+		clusters = ocfs2_rec_clusters(el->l_tree_depth, rec);
+
+		/*
+		 * For a sparse file, we may find an empty record.
+		 * Just skip it.
+		 */
+		if (!clusters)
+			continue;
+
 		if (el->l_tree_depth) {
 			ret = ocfs2_read_extent_block(fs, rec->e_blkno, buf);
 			if (ret) {
@@ -91,7 +101,7 @@ static errcode_t lookup_regular(ocfs2_fi
 			if (ba[j].status != STATUS_UNKNOWN)
 				continue;
 
-			numblks = ocfs2_clusters_to_blocks(fs, rec->e_clusters);
+			numblks = ocfs2_clusters_to_blocks(fs, clusters);
 
 			if (ba[j].blkno >= rec->e_blkno &&
 			    ba[j].blkno < rec->e_blkno + numblks) {

-- 



More information about the Ocfs2-tools-devel mailing list