[Ocfs2-tools-devel] [PATCH 04/44] libocfs2: Add ocfs2_write_refcount_block()
Tao Ma
tao.ma at oracle.com
Mon Dec 28 01:00:49 PST 2009
From: Joel Becker <joel.becker at oracle.com>
The corresponding write function.
Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
include/ocfs2/ocfs2.h | 6 +++++
libocfs2/refcount.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 68c1dd9..18c55cc 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -386,12 +386,18 @@ errcode_t ocfs2_write_extent_block(ocfs2_filesys *fs, uint64_t blkno,
char *eb_buf);
void ocfs2_swap_refcount_list_to_cpu(ocfs2_filesys *fs, void *obj,
struct ocfs2_refcount_list *rl);
+void ocfs2_swap_refcount_list_from_cpu(ocfs2_filesys *fs, void *obj,
+ struct ocfs2_refcount_list *rl);
void ocfs2_swap_refcount_block_to_cpu(ocfs2_filesys *fs,
struct ocfs2_refcount_block *rb);
+void ocfs2_swap_refcount_block_from_cpu(ocfs2_filesys *fs,
+ struct ocfs2_refcount_block *rb);
errcode_t ocfs2_read_refcount_block(ocfs2_filesys *fs, uint64_t blkno,
char *eb_buf);
errcode_t ocfs2_read_refcount_block_nocheck(ocfs2_filesys *fs, uint64_t blkno,
char *eb_buf);
+errcode_t ocfs2_write_refcount_block(ocfs2_filesys *fs, uint64_t blkno,
+ char *rb_buf);
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 1a82e6e..af8c3ea 100644
--- a/libocfs2/refcount.c
+++ b/libocfs2/refcount.c
@@ -52,6 +52,16 @@ static void ocfs2_swap_refcount_list_secondary(ocfs2_filesys *fs, void *obj,
}
}
+void ocfs2_swap_refcount_list_from_cpu(ocfs2_filesys *fs, void *obj,
+ struct ocfs2_refcount_list *rl)
+{
+ if (cpu_is_little_endian)
+ return;
+
+ ocfs2_swap_refcount_list_secondary(fs, obj, rl);
+ ocfs2_swap_refcount_list_primary(rl);
+}
+
void ocfs2_swap_refcount_list_to_cpu(ocfs2_filesys *fs, void *obj,
struct ocfs2_refcount_list *rl)
{
@@ -77,6 +87,19 @@ static void ocfs2_swap_refcount_block_header(struct ocfs2_refcount_block *rb)
rb->rf_cpos = bswap_32(rb->rf_cpos);
}
+void ocfs2_swap_refcount_block_from_cpu(ocfs2_filesys *fs,
+ struct ocfs2_refcount_block *rb)
+{
+ if (cpu_is_little_endian)
+ return;
+
+ if (rb->rf_flags & OCFS2_REFCOUNT_TREE_FL)
+ ocfs2_swap_extent_list_from_cpu(fs, rb, &rb->rf_list);
+ else
+ ocfs2_swap_refcount_list_from_cpu(fs, rb, &rb->rf_records);
+ ocfs2_swap_refcount_block_header(rb);
+}
+
void ocfs2_swap_refcount_block_to_cpu(ocfs2_filesys *fs,
struct ocfs2_refcount_block *rb)
{
@@ -147,3 +170,40 @@ errcode_t ocfs2_read_refcount_block(ocfs2_filesys *fs, uint64_t blkno,
return ret;
}
+
+errcode_t ocfs2_write_refcount_block(ocfs2_filesys *fs, uint64_t blkno,
+ char *rb_buf)
+{
+ errcode_t ret;
+ char *blk;
+ struct ocfs2_refcount_block *rb;
+
+ if (!(fs->fs_flags & OCFS2_FLAG_RW))
+ return OCFS2_ET_RO_FILESYS;
+
+ if ((blkno < OCFS2_SUPER_BLOCK_BLKNO) ||
+ (blkno > fs->fs_blocks))
+ return OCFS2_ET_BAD_BLKNO;
+
+ ret = ocfs2_malloc_block(fs->fs_io, &blk);
+ if (ret)
+ return ret;
+
+ memcpy(blk, rb_buf, fs->fs_blocksize);
+
+ rb = (struct ocfs2_refcount_block *)blk;
+ ocfs2_swap_refcount_block_from_cpu(fs, rb);
+
+ ocfs2_compute_meta_ecc(fs, blk, &rb->rf_check);
+ ret = io_write_block(fs->fs_io, blkno, 1, blk);
+ if (ret)
+ goto out;
+
+ fs->fs_flags |= OCFS2_FLAG_CHANGED;
+ ret = 0;
+
+out:
+ ocfs2_free(&blk);
+
+ return ret;
+}
--
1.5.5
More information about the Ocfs2-tools-devel
mailing list