[Ocfs2-tools-commits] zab commits r1027 - in branches/endian-safe:
libocfs2 libocfs2/include mkfs.ocfs2
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Thu Aug 4 19:43:32 CDT 2005
Author: zab
Date: 2005-08-04 19:43:29 -0500 (Thu, 04 Aug 2005)
New Revision: 1027
Modified:
branches/endian-safe/libocfs2/extents.c
branches/endian-safe/libocfs2/include/ocfs2.h
branches/endian-safe/libocfs2/inode.c
branches/endian-safe/libocfs2/openfs.c
branches/endian-safe/mkfs.ocfs2/mkfs.c
Log:
o have callers indicate the direction of their swapping so that fields can be
swapped in the right order where that matters
Modified: branches/endian-safe/libocfs2/extents.c
===================================================================
--- branches/endian-safe/libocfs2/extents.c 2005-08-05 00:33:30 UTC (rev 1026)
+++ branches/endian-safe/libocfs2/extents.c 2005-08-05 00:43:29 UTC (rev 1027)
@@ -34,13 +34,17 @@
#include "ocfs2.h"
-void ocfs2_swap_extent_list(ocfs2_extent_list *el)
+static void ocfs2_swap_extent_list_primary(ocfs2_extent_list *el)
{
+ el->l_tree_depth = bswap_16(el->l_tree_depth);
+ el->l_count = bswap_16(el->l_count);
+ el->l_next_free_rec = bswap_16(el->l_next_free_rec);
+}
+
+static void ocfs2_swap_extent_list_secondary(ocfs2_extent_list *el)
+{
uint16_t i;
- if (cpu_is_little_endian)
- return;
-
for(i = 0; i < el->l_next_free_rec; i++) {
ocfs2_extent_rec *rec = &el->l_recs[i];
@@ -48,19 +52,28 @@
rec->e_clusters = bswap_32(rec->e_clusters);
rec->e_blkno = bswap_64(rec->e_blkno);
}
-
- el->l_tree_depth = bswap_16(el->l_tree_depth);
- el->l_count = bswap_16(el->l_count);
- el->l_next_free_rec = bswap_16(el->l_next_free_rec);
}
-static void ocfs2_swap_extent_block(ocfs2_extent_block *eb)
+void ocfs2_swap_extent_list_from_cpu(ocfs2_extent_list *el)
{
- ocfs2_swap_extent_list(&eb->h_list);
+ if (cpu_is_little_endian)
+ return;
+ ocfs2_swap_extent_list_secondary(el);
+ ocfs2_swap_extent_list_primary(el);
+}
+void ocfs2_swap_extent_list_to_cpu(ocfs2_extent_list *el)
+{
if (cpu_is_little_endian)
return;
+ ocfs2_swap_extent_list_primary(el);
+ ocfs2_swap_extent_list_secondary(el);
+}
+
+static void ocfs2_swap_extent_block_header(ocfs2_extent_block *eb)
+{
+
eb->h_suballoc_slot = bswap_16(eb->h_suballoc_slot);
eb->h_suballoc_bit = bswap_16(eb->h_suballoc_bit);
eb->h_fs_generation = bswap_32(eb->h_fs_generation);
@@ -68,6 +81,23 @@
eb->h_next_leaf_blk = bswap_64(eb->h_next_leaf_blk);
}
+static void ocfs2_swap_extent_block_from_cpu(ocfs2_extent_block *eb)
+{
+ if (cpu_is_little_endian)
+ return;
+
+ ocfs2_swap_extent_block_header(eb);
+ ocfs2_swap_extent_list_from_cpu(&eb->h_list);
+}
+static void ocfs2_swap_extent_block_to_cpu(ocfs2_extent_block *eb)
+{
+ if (cpu_is_little_endian)
+ return;
+
+ ocfs2_swap_extent_block_header(eb);
+ ocfs2_swap_extent_list_to_cpu(&eb->h_list);
+}
+
errcode_t ocfs2_read_extent_block_nocheck(ocfs2_filesys *fs, uint64_t blkno,
char *eb_buf)
{
@@ -98,7 +128,7 @@
memcpy(eb_buf, blk, fs->fs_blocksize);
eb = (ocfs2_extent_block *) eb_buf;
- ocfs2_swap_extent_block(eb);
+ ocfs2_swap_extent_block_to_cpu(eb);
out:
ocfs2_free(&blk);
@@ -141,7 +171,7 @@
memcpy(blk, eb_buf, fs->fs_blocksize);
eb = (ocfs2_extent_block *) blk;
- ocfs2_swap_extent_block(eb);
+ ocfs2_swap_extent_block_from_cpu(eb);
ret = io_write_block(fs->fs_io, blkno, 1, blk);
if (ret)
Modified: branches/endian-safe/libocfs2/include/ocfs2.h
===================================================================
--- branches/endian-safe/libocfs2/include/ocfs2.h 2005-08-05 00:33:30 UTC (rev 1026)
+++ branches/endian-safe/libocfs2/include/ocfs2.h 2005-08-05 00:43:29 UTC (rev 1027)
@@ -253,7 +253,8 @@
errcode_t ocfs2_close(ocfs2_filesys *fs);
void ocfs2_freefs(ocfs2_filesys *fs);
-void ocfs2_swap_inode(ocfs2_dinode *di);
+void ocfs2_swap_inode_from_cpu(ocfs2_dinode *di);
+void ocfs2_swap_inode_to_cpu(ocfs2_dinode *di);
errcode_t ocfs2_read_inode(ocfs2_filesys *fs, uint64_t blkno,
char *inode_buf);
errcode_t ocfs2_read_inodes(ocfs2_filesys *fs, uint64_t blkno, int num_blocks,
@@ -269,7 +270,8 @@
errcode_t ocfs2_free_cached_inode(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode);
-void ocfs2_swap_extent_list(ocfs2_extent_list *el);
+void ocfs2_swap_extent_list_from_cpu(ocfs2_extent_list *el);
+void ocfs2_swap_extent_list_to_cpu(ocfs2_extent_list *el);
errcode_t ocfs2_extent_map_init(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode);
void ocfs2_extent_map_free(ocfs2_cached_inode *cinode);
Modified: branches/endian-safe/libocfs2/inode.c
===================================================================
--- branches/endian-safe/libocfs2/inode.c 2005-08-05 00:33:30 UTC (rev 1026)
+++ branches/endian-safe/libocfs2/inode.c 2005-08-05 00:43:29 UTC (rev 1027)
@@ -62,11 +62,8 @@
return ret;
}
-void ocfs2_swap_inode(ocfs2_dinode *di)
+static void ocfs2_swap_inode_secondary(ocfs2_dinode *di)
{
- if (cpu_is_little_endian)
- return;
-
if (S_ISCHR(di->i_mode) || S_ISBLK(di->i_mode))
di->id1.dev1.i_rdev = bswap_64(di->id1.dev1.i_rdev);
else if (di->i_flags & OCFS2_BITMAP_FL) {
@@ -117,11 +114,6 @@
rec->c_blkno = bswap_64(rec->c_blkno);
}
- cl->cl_cpg = bswap_16(cl->cl_cpg);
- cl->cl_bpc = bswap_16(cl->cl_bpc);
- cl->cl_count = bswap_16(cl->cl_count);
- cl->cl_next_free_rec = bswap_16(cl->cl_next_free_rec);
-
} else if (di->i_flags & OCFS2_DEALLOC_FL) {
ocfs2_truncate_log *tl = &di->id2.i_dealloc;
uint16_t i;
@@ -132,20 +124,11 @@
rec->t_start = bswap_32(rec->t_start);
rec->t_clusters = bswap_32(rec->t_clusters);
}
-
- tl->tl_count = bswap_16(tl->tl_count);
- tl->tl_used = bswap_16(tl->tl_used);
-
- } else {
- /* ok, now that we don't have any of the explicit _FL
- * bits set, we're a "regular" file that has an
- * extent_list i_list -- directories, file contents,
- * symlink targets.. unless we're a fast symlink. */
- if (!(S_ISLNK(di->i_mode) && di->i_size &&
- di->i_clusters == 0))
- ocfs2_swap_extent_list(&di->id2.i_list);
}
+}
+static void ocfs2_swap_inode_primary(ocfs2_dinode *di)
+{
di->i_generation = bswap_32(di->i_generation);
di->i_suballoc_slot = bswap_16(di->i_suballoc_slot);
di->i_suballoc_bit = bswap_16(di->i_suballoc_bit);
@@ -166,8 +149,58 @@
di->i_atime_nsec = bswap_32(di->i_atime_nsec);
di->i_ctime_nsec = bswap_32(di->i_ctime_nsec);
di->i_mtime_nsec = bswap_32(di->i_mtime_nsec);
+
+ if (di->i_flags & OCFS2_CHAIN_FL) {
+ ocfs2_chain_list *cl = &di->id2.i_chain;
+
+ cl->cl_cpg = bswap_16(cl->cl_cpg);
+ cl->cl_bpc = bswap_16(cl->cl_bpc);
+ cl->cl_count = bswap_16(cl->cl_count);
+ cl->cl_next_free_rec = bswap_16(cl->cl_next_free_rec);
+
+ } else if (di->i_flags & OCFS2_DEALLOC_FL) {
+ ocfs2_truncate_log *tl = &di->id2.i_dealloc;
+
+ tl->tl_count = bswap_16(tl->tl_count);
+ tl->tl_used = bswap_16(tl->tl_used);
+ }
}
+static int has_extents(ocfs2_dinode *di)
+{
+ /* inodes flagged with other stuff in id2 */
+ if (di->i_flags & (OCFS2_SUPER_BLOCK_FL | OCFS2_LOCAL_ALLOC_FL |
+ OCFS2_CHAIN_FL | OCFS2_DEALLOC_FL))
+ return 0;
+ /* i_flags doesn't indicate when id2 is a fast symlink */
+ if (S_ISLNK(di->i_mode) && di->i_size && di->i_clusters == 0)
+ return 0;
+
+ return 1;
+}
+
+void ocfs2_swap_inode_from_cpu(ocfs2_dinode *di)
+{
+ if (cpu_is_little_endian)
+ return;
+
+ if (has_extents(di))
+ ocfs2_swap_extent_list_from_cpu(&di->id2.i_list);
+ ocfs2_swap_inode_secondary(di);
+ ocfs2_swap_inode_primary(di);
+}
+
+void ocfs2_swap_inode_to_cpu(ocfs2_dinode *di)
+{
+ if (cpu_is_little_endian)
+ return;
+
+ ocfs2_swap_inode_primary(di);
+ ocfs2_swap_inode_secondary(di);
+ if (has_extents(di))
+ ocfs2_swap_extent_list_from_cpu(&di->id2.i_list);
+}
+
errcode_t ocfs2_read_inode(ocfs2_filesys *fs, uint64_t blkno,
char *inode_buf)
{
@@ -197,7 +230,7 @@
memcpy(inode_buf, blk, fs->fs_blocksize);
di = (ocfs2_dinode *) inode_buf;
- ocfs2_swap_inode(di);
+ ocfs2_swap_inode_to_cpu(di);
ret = 0;
out:
@@ -227,7 +260,7 @@
goto out;
}
- ocfs2_swap_inode(di);
+ ocfs2_swap_inode_to_cpu(di);
}
out:
return ret;
@@ -254,7 +287,7 @@
memcpy(blk, inode_buf, fs->fs_blocksize);
di = (ocfs2_dinode *)blk;
- ocfs2_swap_inode(di);
+ ocfs2_swap_inode_from_cpu(di);
ret = io_write_block(fs->fs_io, blkno, 1, blk);
if (ret)
Modified: branches/endian-safe/libocfs2/openfs.c
===================================================================
--- branches/endian-safe/libocfs2/openfs.c 2005-08-05 00:33:30 UTC (rev 1026)
+++ branches/endian-safe/libocfs2/openfs.c 2005-08-05 00:43:29 UTC (rev 1027)
@@ -91,7 +91,7 @@
strlen(OCFS2_SUPER_BLOCK_SIGNATURE)))
goto out_blk;
- ocfs2_swap_inode(di);
+ ocfs2_swap_inode_to_cpu(di);
fs->fs_super = di;
return 0;
Modified: branches/endian-safe/mkfs.ocfs2/mkfs.c
===================================================================
--- branches/endian-safe/mkfs.ocfs2/mkfs.c 2005-08-05 00:33:30 UTC (rev 1026)
+++ branches/endian-safe/mkfs.ocfs2/mkfs.c 2005-08-05 00:43:29 UTC (rev 1027)
@@ -1590,7 +1590,7 @@
strcpy(di->id2.i_super.s_label, s->vol_label);
memcpy(di->id2.i_super.s_uuid, s->uuid, 16);
- ocfs2_swap_inode(di);
+ ocfs2_swap_inode_from_cpu(di);
do_pwrite(s, di, s->blocksize, super_off);
free(di);
}
@@ -1733,7 +1733,7 @@
}
write_out:
- ocfs2_swap_inode(di);
+ ocfs2_swap_inode_from_cpu(di);
do_pwrite(s, di, s->blocksize, rec->fe_off);
free(di);
}
More information about the Ocfs2-tools-commits
mailing list