[Ocfs2-tools-devel] [PATCH 38/44] libocfs2: Add ocfs2_change_refcount.

Tao Ma tao.ma at oracle.com
Mon Dec 28 01:01:23 PST 2009


In fsck.ocfs2, sometimes we need to change some clusters'
refcount in the refcount tree. So this patch adds
the function ocfs2_change_refcount.
Please note that this function can only be used to change
some part of a refcount_rec.

Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
 include/ocfs2/ocfs2.h |    3 +++
 libocfs2/refcount.c   |   40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index c1954bb..2f24edd 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -436,6 +436,9 @@ errcode_t ocfs2_refcount_tree_get_rec(ocfs2_filesys *fs,
 				      uint32_t *num_clusters);
 errcode_t ocfs2_refcount_punch_hole(ocfs2_filesys *fs, uint64_t rf_blkno,
 				    uint64_t p_start, uint32_t len);
+errcode_t ocfs2_change_refcount(ocfs2_filesys *fs, uint64_t rf_blkno,
+				uint64_t p_start, uint32_t len,
+				uint32_t refcount);
 errcode_t ocfs2_swap_dir_entries_from_cpu(void *buf, uint64_t bytes);
 errcode_t ocfs2_swap_dir_entries_to_cpu(void *buf, uint64_t bytes);
 void ocfs2_swap_dir_trailer(struct ocfs2_dir_block_trailer *trailer);
diff --git a/libocfs2/refcount.c b/libocfs2/refcount.c
index 4ea010a..1a27631 100644
--- a/libocfs2/refcount.c
+++ b/libocfs2/refcount.c
@@ -1940,6 +1940,46 @@ out:
 	return ret;
 }
 
+errcode_t ocfs2_change_refcount(ocfs2_filesys *fs, uint64_t rf_blkno,
+				uint64_t p_start, uint32_t len,
+				uint32_t refcount)
+{
+	errcode_t ret;
+	char *root_buf = NULL, *buf = NULL;
+	struct ocfs2_refcount_rec rec;
+	int index;
+
+	ret = ocfs2_malloc_block(fs->fs_io, &root_buf);
+	if (ret)
+		goto out;
+
+	ret = ocfs2_malloc_block(fs->fs_io, &buf);
+	if (ret)
+		goto out;
+
+	ret = ocfs2_read_refcount_block(fs, rf_blkno, root_buf);
+	if (ret)
+		goto out;
+
+	ret = ocfs2_get_refcount_rec(fs, root_buf, p_start,
+				     len, &rec, &index, buf);
+	assert(rec.r_refcount != refcount &&
+	       rec.r_cpos <= p_start &&
+	       rec.r_cpos + rec.r_clusters >= p_start + len);
+
+	rec.r_cpos = p_start;
+	rec.r_clusters = len;
+	rec.r_refcount = refcount;
+	ret = ocfs2_split_refcount_rec(fs, root_buf, buf,
+				       &rec, index, 1);
+out:
+	if (root_buf)
+		ocfs2_free(&root_buf);
+	if (buf)
+		ocfs2_free(&buf);
+	return ret;
+}
+
 struct xattr_value_obj {
 	errcode_t errcode;
 	uint64_t p_cpos;
-- 
1.5.5




More information about the Ocfs2-tools-devel mailing list