[Ocfs2-tools-devel] [PATCH 21/44] libocfs2: add ocfs2_xattr_get_clusters
Tao Ma
tao.ma at oracle.com
Mon Dec 28 01:01:06 PST 2009
From: Tiger Yang <tiger.yang at oracle.com>
This function use to get the starting cluster number
of a specified offset in an xattr extent tree.
Signed-off-by: Tiger Yang <tiger.yang at oracle.com>
---
include/ocfs2/ocfs2.h | 8 ++++++
libocfs2/extent_map.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 7960aab..6b718e4 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -354,6 +354,14 @@ errcode_t ocfs2_get_clusters(ocfs2_cached_inode *cinode,
uint32_t *p_cluster,
uint32_t *num_clusters,
uint16_t *extent_flags);
+errcode_t ocfs2_xattr_get_clusters(ocfs2_filesys *fs,
+ struct ocfs2_extent_list *el,
+ uint64_t el_blkno,
+ char *el_blk,
+ uint32_t v_cluster,
+ uint32_t *p_cluster,
+ uint32_t *num_clusters,
+ uint16_t *extent_flags);
int ocfs2_find_leaf(ocfs2_filesys *fs, struct ocfs2_dinode *di,
uint32_t cpos, char **leaf_buf);
int ocfs2_search_extent_list(struct ocfs2_extent_list *el, uint32_t v_cluster);
diff --git a/libocfs2/extent_map.c b/libocfs2/extent_map.c
index 7e5f8fe..00beb6e 100644
--- a/libocfs2/extent_map.c
+++ b/libocfs2/extent_map.c
@@ -207,6 +207,68 @@ out:
return ret;
}
+errcode_t ocfs2_xattr_get_clusters(ocfs2_filesys *fs,
+ struct ocfs2_extent_list *el,
+ uint64_t el_blkno,
+ char *el_blk,
+ uint32_t v_cluster,
+ uint32_t *p_cluster,
+ uint32_t *num_clusters,
+ uint16_t *extent_flags)
+{
+ int i;
+ errcode_t ret = 0;
+ struct ocfs2_extent_block *eb;
+ struct ocfs2_extent_rec *rec;
+ char *eb_buf = NULL;
+ uint32_t coff;
+
+ if (el->l_tree_depth) {
+ ret = ocfs2_tree_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;
+ if (extent_flags)
+ *extent_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.5
More information about the Ocfs2-tools-devel
mailing list