[Ocfs2-tools-commits] zab commits r1028 - in branches/endian-safe: libocfs2 libocfs2/include mkfs.ocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Fri Aug 5 14:30:38 CDT 2005


Author: zab
Date: 2005-08-05 14:30:35 -0500 (Fri, 05 Aug 2005)
New Revision: 1028

Modified:
   branches/endian-safe/libocfs2/dirblock.c
   branches/endian-safe/libocfs2/include/byteorder.h
   branches/endian-safe/libocfs2/include/ocfs2.h
   branches/endian-safe/libocfs2/inode.c
   branches/endian-safe/mkfs.ocfs2/mkfs.c
Log:
get mkfs working on big-endian

o one more try and getting the swapping order right in inodes
o swap extent lists *to* cpu when swapping the inode to cpu
o micro-simplify the cpu_is macros so joel can stop giggling
o get swaping order right in dirents, and swap rec_len as 16 instead of 64
o be sure to swap all directory entries, not just those that have names



Modified: branches/endian-safe/libocfs2/dirblock.c
===================================================================
--- branches/endian-safe/libocfs2/dirblock.c	2005-08-05 00:43:29 UTC (rev 1027)
+++ branches/endian-safe/libocfs2/dirblock.c	2005-08-05 19:30:35 UTC (rev 1028)
@@ -38,10 +38,11 @@
 		return;
 
 	dirent->inode = bswap_64(dirent->inode);
-	dirent->rec_len = bswap_64(dirent->rec_len);
+	dirent->rec_len = bswap_16(dirent->rec_len);
 }
 
-errcode_t ocfs2_swap_dir_entries(void *buf, uint64_t bytes)
+static errcode_t ocfs2_swap_dir_entries_direction(void *buf, uint64_t bytes,
+						  int to_cpu)
 {
 	char		*p, *end;
 	struct ocfs2_dir_entry *dirent;
@@ -53,16 +54,19 @@
 	while (p < end-12) {
 		dirent = (struct ocfs2_dir_entry *) p;
 
-		ocfs2_swap_dir_entry(dirent);
+		if (to_cpu)
+			ocfs2_swap_dir_entry(dirent);
 		name_len = dirent->name_len;
 		rec_len = dirent->rec_len;
+		if (!to_cpu)
+			ocfs2_swap_dir_entry(dirent);
 
 		if ((rec_len < 12) || (rec_len % 4)) {
 			rec_len = 12;
 			retval = OCFS2_ET_DIR_CORRUPTED;
 		}
 
-		if (((name_len & 0xFF) + 12) > dirent->rec_len)
+		if (((name_len & 0xFF) + 12) > rec_len)
 			retval = OCFS2_ET_DIR_CORRUPTED;
 
 		p += rec_len;
@@ -70,6 +74,15 @@
 	return retval;
 }
 
+errcode_t ocfs2_swap_dir_entries_from_cpu(void *buf, uint64_t bytes)
+{
+	return ocfs2_swap_dir_entries_direction(buf, bytes, 0);
+}
+errcode_t ocfs2_swap_dir_entries_to_cpu(void *buf, uint64_t bytes)
+{
+	return ocfs2_swap_dir_entries_direction(buf, bytes, 1);
+}
+
 errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs, uint64_t block,
                                void *buf)
 {
@@ -79,7 +92,7 @@
 	if (retval)
 		return retval;
 
-	return ocfs2_swap_dir_entries(buf, fs->fs_blocksize);
+	return ocfs2_swap_dir_entries_to_cpu(buf, fs->fs_blocksize);
 }
 
 errcode_t ocfs2_write_dir_block(ocfs2_filesys *fs, uint64_t block,
@@ -94,7 +107,7 @@
 
 	memcpy(buf, inbuf, fs->fs_blocksize);
 
-	retval = ocfs2_swap_dir_entries(buf, fs->fs_blocksize);
+	retval = ocfs2_swap_dir_entries_from_cpu(buf, fs->fs_blocksize);
 	if (retval)
 		goto out;
 	

Modified: branches/endian-safe/libocfs2/include/byteorder.h
===================================================================
--- branches/endian-safe/libocfs2/include/byteorder.h	2005-08-05 00:43:29 UTC (rev 1027)
+++ branches/endian-safe/libocfs2/include/byteorder.h	2005-08-05 19:30:35 UTC (rev 1028)
@@ -39,7 +39,6 @@
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 #define cpu_is_little_endian	1
-#define cpu_is_big_endian	0
 # ifndef cpu_to_le16
 #  define cpu_to_le16(x) ((uint16_t)(x))
 # endif
@@ -78,7 +77,6 @@
 # endif
 #elif __BYTE_ORDER == __BIG_ENDIAN
 #define cpu_is_little_endian	0
-#define cpu_is_big_endian	1
 # ifndef cpu_to_le16
 #  define cpu_to_le16(x) ((uint16_t)bswap_16(x))
 # endif
@@ -119,4 +117,6 @@
 # error Invalid byte order __BYTE_ORDER
 #endif  /* __BYTE_ORDER */
 
+#define cpu_is_big_endian	(!cpu_is_little_endian)
+
 #endif  /* _BYTEORDER_H */

Modified: branches/endian-safe/libocfs2/include/ocfs2.h
===================================================================
--- branches/endian-safe/libocfs2/include/ocfs2.h	2005-08-05 00:43:29 UTC (rev 1027)
+++ branches/endian-safe/libocfs2/include/ocfs2.h	2005-08-05 19:30:35 UTC (rev 1028)
@@ -354,7 +354,8 @@
 						void *priv_data),
 				    void *priv_data);
 
-errcode_t ocfs2_swap_dir_entries(void *buf, uint64_t bytes);
+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);
 errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs, uint64_t block,
 			       void *buf);
 errcode_t ocfs2_write_dir_block(ocfs2_filesys *fs, uint64_t block,

Modified: branches/endian-safe/libocfs2/inode.c
===================================================================
--- branches/endian-safe/libocfs2/inode.c	2005-08-05 00:43:29 UTC (rev 1027)
+++ branches/endian-safe/libocfs2/inode.c	2005-08-05 19:30:35 UTC (rev 1028)
@@ -62,8 +62,36 @@
 	return ret;
 }
 
-static void ocfs2_swap_inode_secondary(ocfs2_dinode *di)
+static void ocfs2_swap_inode_third(ocfs2_dinode *di)
 {
+
+	if (di->i_flags & OCFS2_CHAIN_FL) {
+		ocfs2_chain_list *cl = &di->id2.i_chain;
+		uint16_t i;
+
+		for (i = 0; i < cl->cl_next_free_rec; i++) {
+			ocfs2_chain_rec *rec = &cl->cl_recs[i];
+
+			rec->c_free  = bswap_32(rec->c_free);
+			rec->c_total = bswap_32(rec->c_total);
+			rec->c_blkno = bswap_64(rec->c_blkno);
+		}
+
+	} else if (di->i_flags & OCFS2_DEALLOC_FL) {
+		ocfs2_truncate_log *tl = &di->id2.i_dealloc;
+		uint16_t i;
+
+		for(i = 0; i < tl->tl_count; i++) {
+			ocfs2_truncate_rec *rec = &tl->tl_recs[i];
+
+			rec->t_start    = bswap_32(rec->t_start);
+			rec->t_clusters = bswap_32(rec->t_clusters);
+		}
+	}
+}
+
+static void ocfs2_swap_inode_second(ocfs2_dinode *di)
+{
 	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) {
@@ -104,30 +132,21 @@
 
 	} else if (di->i_flags & OCFS2_CHAIN_FL) {
 		ocfs2_chain_list *cl = &di->id2.i_chain;
-		uint16_t i;
 
-		for (i = 0; i < cl->cl_next_free_rec; i++) {
-			ocfs2_chain_rec *rec = &cl->cl_recs[i];
+		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);
 
-			rec->c_free  = bswap_32(rec->c_free);
-			rec->c_total = bswap_32(rec->c_total);
-			rec->c_blkno = bswap_64(rec->c_blkno);
-		}
-
 	} else if (di->i_flags & OCFS2_DEALLOC_FL) {
 		ocfs2_truncate_log *tl = &di->id2.i_dealloc;
-		uint16_t i;
 
-		for(i = 0; i < tl->tl_count; i++) {
-			ocfs2_truncate_rec *rec = &tl->tl_recs[i];
-
-			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);
 	}
 }
 
-static void ocfs2_swap_inode_primary(ocfs2_dinode *di)
+static void ocfs2_swap_inode_first(ocfs2_dinode *di)
 {
 	di->i_generation    = bswap_32(di->i_generation);
 	di->i_suballoc_slot = bswap_16(di->i_suballoc_slot);
@@ -149,21 +168,6 @@
 	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)
@@ -186,8 +190,9 @@
 
 	if (has_extents(di))
 		ocfs2_swap_extent_list_from_cpu(&di->id2.i_list);
-	ocfs2_swap_inode_secondary(di);
-	ocfs2_swap_inode_primary(di);
+	ocfs2_swap_inode_third(di);
+	ocfs2_swap_inode_second(di);
+	ocfs2_swap_inode_first(di);
 }
 
 void ocfs2_swap_inode_to_cpu(ocfs2_dinode *di)
@@ -195,10 +200,11 @@
 	if (cpu_is_little_endian)
 		return;
 
-	ocfs2_swap_inode_primary(di);
-	ocfs2_swap_inode_secondary(di);
+	ocfs2_swap_inode_first(di);
+	ocfs2_swap_inode_second(di);
+	ocfs2_swap_inode_third(di);
 	if (has_extents(di))
-		ocfs2_swap_extent_list_from_cpu(&di->id2.i_list);
+		ocfs2_swap_extent_list_to_cpu(&di->id2.i_list);
 }
 
 errcode_t ocfs2_read_inode(ocfs2_filesys *fs, uint64_t blkno,

Modified: branches/endian-safe/mkfs.ocfs2/mkfs.c
===================================================================
--- branches/endian-safe/mkfs.ocfs2/mkfs.c	2005-08-05 00:43:29 UTC (rev 1027)
+++ branches/endian-safe/mkfs.ocfs2/mkfs.c	2005-08-05 19:30:35 UTC (rev 1028)
@@ -1796,10 +1796,12 @@
 write_directory_data(State *s, DirData *dir)
 {
 	if (dir->buf)
-		ocfs2_swap_dir_entries(dir->buf, dir->last_off);
+		ocfs2_swap_dir_entries_from_cpu(dir->buf,
+						dir->record->file_size);
 	write_metadata(s, dir->record, dir->buf);
 	if (dir->buf)
-		ocfs2_swap_dir_entries(dir->buf, dir->last_off);
+		ocfs2_swap_dir_entries_to_cpu(dir->buf,
+					      dir->record->file_size);
 }
 
 static void



More information about the Ocfs2-tools-commits mailing list