[Ocfs2-tools-devel] [PATCH 4/6] libocfs2: add ocfs2_xattr_get_clusters

Tiger Yang tiger.yang at oracle.com
Wed Jul 29 00:02:05 PDT 2009


This function use to get starting cluster number
from a specified offset in an xattr tree or value tree.

Signed-off-by: Tiger Yang <tiger.yang at oracle.com>
---
 include/ocfs2/ocfs2.h |    7 +++++
 libocfs2/extent_map.c |   63 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index d1514db..a0bec71 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -1166,5 +1166,12 @@ errcode_t ocfs2_extent_iterate_xattr(ocfs2_filesys *fs,
 				     int *changed);
 errcode_t ocfs2_delete_xattr_block(ocfs2_filesys *fs, uint64_t blkno);
 errcode_t ocfs2_new_xattr_block(ocfs2_filesys *fs, uint64_t *blkno);
+errcode_t ocfs2_xattr_get_clusters(ocfs2_cached_inode *cinode,
+				   uint32_t v_cluster,
+				   uint32_t *p_cluster,
+				   uint32_t *num_clusters,
+				   struct ocfs2_extent_list *el,
+				   uint64_t el_blkno,
+				   char *el_blk);
 
 #endif  /* _FILESYS_H */
diff --git a/libocfs2/extent_map.c b/libocfs2/extent_map.c
index 7e5f8fe..52149d0 100644
--- a/libocfs2/extent_map.c
+++ b/libocfs2/extent_map.c
@@ -207,6 +207,69 @@ out:
 	return ret;
 }
 
+errcode_t ocfs2_xattr_get_clusters(ocfs2_cached_inode *cinode,
+				   uint32_t v_cluster,
+				   uint32_t *p_cluster,
+				   uint32_t *num_clusters,
+				   struct ocfs2_extent_list *el,
+				   uint64_t el_blkno,
+				   char *el_blk)
+{
+	int i;
+	uint16_t flags = 0;
+	errcode_t ret =  0;
+	ocfs2_filesys *fs = cinode->ci_fs;
+	struct ocfs2_extent_block *eb;
+	struct ocfs2_extent_rec *rec;
+	char *eb_buf = NULL;
+	uint32_t coff;
+
+	if (el->l_tree_depth) {
+		ret = ocfs2_xattr_find_leaf(fs, el, el_blkno, el_blk,
+					    v_cluster, &eb_buf);
+		if (ret)
+			goto out;
+
+		eb = (struct ocfs2_extent_block *)eb_buf;
+		el = &eb->h_list;
+
+		if (el->l_tree_depth) {
+			ret = OCFS2_ET_CORRUPT_EXTENT_BLOCK;
+			goto out;
+		}
+	}
+
+	i = ocfs2_search_extent_list(el, v_cluster);
+	if (i == -1) {
+		ret = -1;
+		goto out;
+	} else {
+		rec = &el->l_recs[i];
+
+		assert(v_cluster >= rec->e_cpos);
+
+		if (!rec->e_blkno) {
+			ret = OCFS2_ET_BAD_BLKNO;
+			goto out;
+		}
+
+		coff = v_cluster - rec->e_cpos;
+
+		*p_cluster = ocfs2_blocks_to_clusters(fs, rec->e_blkno);
+		*p_cluster = *p_cluster + coff;
+
+		if (num_clusters)
+			*num_clusters = ocfs2_rec_clusters(el->l_tree_depth,
+							   rec) - coff;
+
+		flags = rec->e_flags;
+	}
+out:
+	if (eb_buf)
+		ocfs2_free(&eb_buf);
+	return ret;
+}
+
 errcode_t ocfs2_extent_map_get_blocks(ocfs2_cached_inode *cinode,
 				      uint64_t v_blkno, int count,
 				      uint64_t *p_blkno, uint64_t *ret_count,
-- 
1.5.4.1




More information about the Ocfs2-tools-devel mailing list