[Ocfs2-tools-devel] [patch 10/11] Modify debugfs.ocfs2 to be show
sparse files.
tao.ma at oracle.com
tao.ma at oracle.com
Wed Aug 15 10:56:20 PDT 2007
Mark has modified some, he will check in some patches for it soon.
===================================================================
--- test.ocfs2-tools.orig/debugfs.ocfs2/commands.c 2007-08-16 00:27:43.000000000 -0400
+++ test.ocfs2-tools/debugfs.ocfs2/commands.c 2007-08-16 00:36:28.000000000 -0400
@@ -426,21 +426,33 @@ 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 +494,22 @@ 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)
===================================================================
--- test.ocfs2-tools.orig/debugfs.ocfs2/dump.c 2007-08-16 00:27:43.000000000 -0400
+++ test.ocfs2-tools/debugfs.ocfs2/dump.c 2007-08-16 00:36:28.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);
@@ -307,8 +308,14 @@ void dump_extent_list (FILE *out, struct
for (i = 0; i < ext->l_next_free_rec; ++i) {
rec = &(ext->l_recs[i]);
+ clusters = ocfs2_rec_clusters(ext->l_tree_depth, rec);
+ /* For a sparse file, we may find an empty record.
+ * Just skip it.
+ */
+ if (!clusters)
+ continue;
fprintf(out, "\t%-2d %-11u %-12u %"PRIu64"\n",
- i, rec->e_cpos, rec->e_clusters, rec->e_blkno);
+ i, rec->e_cpos, clusters, rec->e_blkno);
}
bail:
===================================================================
--- test.ocfs2-tools.orig/debugfs.ocfs2/find_block_inode.c 2007-08-16 00:27:43.000000000 -0400
+++ test.ocfs2-tools/debugfs.ocfs2/find_block_inode.c 2007-08-16 00:36:28.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,14 @@ 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 +100,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