[Ocfs2-tools-devel] [PATCH 1/6] libocfs2: Add ocfs2_test_clusters.v4
Tao Ma
tao.ma at oracle.com
Tue Oct 7 00:28:59 PDT 2008
Add ocfs2_test_clusters in libocfs2 which test the allocation
status of clusters in the global_bitmap.
Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
include/ocfs2/ocfs2.h | 5 +++++
libocfs2/alloc.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index fbc3146..8bc6666 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -507,6 +507,11 @@ errcode_t ocfs2_new_clusters(ocfs2_filesys *fs,
errcode_t ocfs2_free_clusters(ocfs2_filesys *fs,
uint32_t len,
uint64_t start_blkno);
+errcode_t ocfs2_test_clusters(ocfs2_filesys *fs,
+ uint32_t len,
+ uint64_t start_blkno,
+ int test,
+ int *matches);
errcode_t ocfs2_lookup(ocfs2_filesys *fs, uint64_t dir, const char *name,
int namelen, char *buf, uint64_t *inode);
diff --git a/libocfs2/alloc.c b/libocfs2/alloc.c
index 03b3091..22aa452 100644
--- a/libocfs2/alloc.c
+++ b/libocfs2/alloc.c
@@ -513,6 +513,48 @@ out:
return ret;
}
+/*
+ * Test whether clusters have the specified value in the bitmap.
+ * test: expected value
+ * matches: 1 if all bits match test, else 0
+ */
+errcode_t ocfs2_test_clusters(ocfs2_filesys *fs,
+ uint32_t len,
+ uint64_t start_blkno,
+ int test,
+ int *matches)
+{
+ errcode_t ret;
+ uint32_t start_cluster;
+ int set = 0;
+
+ *matches = 0;
+
+ if (!len)
+ return 0;
+
+ ret = ocfs2_load_allocator(fs, GLOBAL_BITMAP_SYSTEM_INODE,
+ 0, &fs->fs_cluster_alloc);
+ if (ret)
+ goto out;
+
+ start_cluster = ocfs2_blocks_to_clusters(fs, start_blkno);
+
+ while (len) {
+ ret = ocfs2_bitmap_test(fs->fs_cluster_alloc->ci_chains,
+ start_cluster, &set);
+ if (ret || set != test)
+ goto out;
+
+ len--;
+ start_cluster++;
+ }
+
+ *matches = 1;
+out:
+ return ret;
+}
+
#ifdef DEBUG_EXE
#include <stdio.h>
--
1.5.4.GIT
More information about the Ocfs2-tools-devel
mailing list