[Ocfs2-tools-commits] zab commits r1018 - in
branches/endian-safe/libocfs2: . include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Thu Aug 4 15:00:18 CDT 2005
Author: zab
Date: 2005-08-04 15:00:14 -0500 (Thu, 04 Aug 2005)
New Revision: 1018
Modified:
branches/endian-safe/libocfs2/alloc.c
branches/endian-safe/libocfs2/bitops.c
branches/endian-safe/libocfs2/chain.c
branches/endian-safe/libocfs2/dirblock.c
branches/endian-safe/libocfs2/extents.c
branches/endian-safe/libocfs2/include/bitops.h
branches/endian-safe/libocfs2/include/byteorder.h
branches/endian-safe/libocfs2/include/ocfs2.h
branches/endian-safe/libocfs2/inode.c
branches/endian-safe/libocfs2/inode_scan.c
branches/endian-safe/libocfs2/mkjournal.c
branches/endian-safe/libocfs2/openfs.c
Log:
first pass at making libocfs2 endian-safe
o operate natively in memory, swap on read/write
o add read_inodes helper so that scan_inode can read/swap in bulk
o use the endian-neutral byte-granular bitmap implementation on all cpus
Modified: branches/endian-safe/libocfs2/alloc.c
===================================================================
--- branches/endian-safe/libocfs2/alloc.c 2005-08-04 19:55:16 UTC (rev 1017)
+++ branches/endian-safe/libocfs2/alloc.c 2005-08-04 20:00:14 UTC (rev 1018)
@@ -163,7 +163,7 @@
if (flags & OCFS2_DEALLOC_FL) {
tl_recs = ocfs2_truncate_recs_per_inode(fs->fs_blocksize);
- di->id2.i_dealloc.tl_count = cpu_to_le16(tl_recs);
+ di->id2.i_dealloc.tl_count = tl_recs;
return ;
}
Modified: branches/endian-safe/libocfs2/bitops.c
===================================================================
--- branches/endian-safe/libocfs2/bitops.c 2005-08-04 19:55:16 UTC (rev 1017)
+++ branches/endian-safe/libocfs2/bitops.c 2005-08-04 20:00:14 UTC (rev 1018)
@@ -27,19 +27,12 @@
*/
#include <stdio.h>
+#include <strings.h>
#include <sys/types.h>
#include "bitops.h"
/*
- * XXX: We're not endian safe at all, and have just hacked in big endian
- * bitops for the arches we want to test on (ppc32 and s390x userland).
- * Post-1.0, we have to revisit this.
- */
-
-#ifndef _OCFS2_HAVE_ASM_BITOPS_
-
-/*
* For the benefit of those who are trying to port Linux to another
* architecture, here are some C-language equivalents. You should
* recode these in the native assmebly language, if at all possible.
@@ -49,29 +42,8 @@
* systems, as well as non-32 bit systems.
*/
-#if defined(__powerpc__)
int ocfs2_set_bit(int nr,void * addr)
{
- unsigned long mask = 1 << (nr & 0x1f);
- unsigned long *p = ((unsigned long *)addr) + (nr >> 5);
- unsigned long old = *p;
-
- *p = old | mask;
- return (old & mask) != 0;
-}
-#elif defined(__s390x__)
-int ocfs2_set_bit(int nr,void * addr)
-{
- unsigned long mask = 1UL << (nr & 0x3f);
- unsigned long *p = ((unsigned long *)addr) + (nr >> 6);
- unsigned long old = *p;
-
- *p = old | mask;
- return (old & mask) != 0;
-}
-#else
-int ocfs2_set_bit(int nr,void * addr)
-{
int mask, retval;
unsigned char *ADDR = (unsigned char *) addr;
@@ -81,31 +53,9 @@
*ADDR |= mask;
return retval;
}
-#endif
-#if defined(__powerpc__)
int ocfs2_clear_bit(int nr, void * addr)
{
- unsigned long mask = 1 << (nr & 0x1f);
- unsigned long *p = ((unsigned long *)addr) + (nr >> 5);
- unsigned long old = *p;
-
- *p = old & ~mask;
- return (old & mask) != 0;
-}
-#elif defined(__s390x__)
-int ocfs2_clear_bit(int nr, void * addr)
-{
- unsigned long mask = 1UL << (nr & 0x3f);
- unsigned long *p = ((unsigned long *)addr) + (nr >> 6);
- unsigned long old = *p;
-
- *p = old & ~mask;
- return (old & mask) != 0;
-}
-#else
-int ocfs2_clear_bit(int nr, void * addr)
-{
int mask, retval;
unsigned char *ADDR = (unsigned char *) addr;
@@ -115,25 +65,9 @@
*ADDR &= ~mask;
return retval;
}
-#endif
-#if defined(__powerpc__)
int ocfs2_test_bit(int nr, const void * addr)
{
- const unsigned int *p = (const unsigned int *) addr;
-
- return ((p[nr >> 5] >> (nr & 0x1f)) & 1) != 0;
-}
-#elif defined(__s390x__)
-int ocfs2_test_bit(int nr, const void * addr)
-{
- const unsigned long *p = (const unsigned long *) addr;
-
- return ((p[nr >> 6] >> (nr & 0x3f)) & 1UL) != 0;
-}
-#else
-int ocfs2_test_bit(int nr, const void * addr)
-{
int mask;
const unsigned char *ADDR = (const unsigned char *) addr;
@@ -141,112 +75,7 @@
mask = 1 << (nr & 0x07);
return ((mask & *ADDR) != 0);
}
-#endif
-#endif /* !_OCFS2_HAVE_ASM_BITOPS_ */
-
-#if !defined(_OCFS2_HAVE_ASM_FINDBIT_)
-#include <strings.h>
-
-#if defined(__powerpc__)
-static inline int __ilog2(unsigned long x)
-{
- int lz;
-
- asm ("cntlzw %0,%1" : "=r" (lz) : "r" (x));
- return 31 - lz;
-}
-
-static inline int ffz(unsigned int x)
-{
- if ((x = ~x) == 0)
- return 32;
- return __ilog2(x & -x);
-}
-
-static inline int __ffs(unsigned long x)
-{
- return __ilog2(x & -x);
-}
-#elif defined(__s390x__)
-
-static const char _zb_findmap[] = {
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,
- 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,8
-};
-
-static const char _sb_findmap[] = {
- 8,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
- 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0
-};
-
-static inline int ffz(unsigned long word)
-{
- int bit = 0;
-
- if ((word & 0xffffffff) == 0xffffffff) {
- word >>= 32;
- bit += 32;
- }
- if ((word & 0xffff) == 0xffff) {
- word >>= 16;
- bit += 16;
- }
- if ((word & 0xff) == 0xff) {
- word >>= 8;
- bit += 8;
- }
- return bit + _zb_findmap[word & 0xff];
-}
-
-static inline int __ffs(unsigned long word)
-{
- int bit = 0;
-
- if ((word & 0xffffffff) == 0) {
- word >>= 32;
- bit += 32;
- }
- if ((word & 0xffff) == 0) {
- word >>= 16;
- bit += 16;
- }
- if ((word & 0xff) == 0) {
- word >>= 8;
- bit += 8;
- }
- return bit + _sb_findmap[word & 0xff];
-}
-#endif
-
int ocfs2_find_first_bit_set(void *addr, int size)
{
return ocfs2_find_next_bit_set(addr, size, 0);
@@ -257,85 +86,8 @@
return ocfs2_find_next_bit_clear(addr, size, 0);
}
-#if defined(__powerpc__)
int ocfs2_find_next_bit_set(void *addr, int size, int offset)
{
- unsigned int *p = ((unsigned int *) addr) + (offset >> 5);
- unsigned int result = offset & ~31UL;
- unsigned int tmp;
-
- if (offset >= size)
- return size;
- size -= result;
- offset &= 31UL;
- if (offset) {
- tmp = *p++;
- tmp &= ~0UL << offset;
- if (size < 32)
- goto found_first;
- if (tmp)
- goto found_middle;
- size -= 32;
- result += 32;
- }
- while (size >= 32) {
- if ((tmp = *p++) != 0)
- goto found_middle;
- result += 32;
- size -= 32;
- }
- if (!size)
- return result;
- tmp = *p;
-
-found_first:
- tmp &= ~0UL >> (32 - size);
- if (tmp == 0UL) /* Are any bits set? */
- return result + size; /* Nope. */
-found_middle:
- return result + __ffs(tmp);
-}
-#elif defined(__s390x__)
-int ocfs2_find_next_bit_set(void *addr, int size, int offset)
-{
- unsigned long *p = ((unsigned long *) addr) + (offset >> 6);
- unsigned long result = offset & ~63UL;
- unsigned long tmp;
-
- if (offset >= size)
- return size;
- size -= result;
- offset &= 63UL;
- if (offset) {
- tmp = *p++;
- tmp &= ~0UL << offset;
- if (size < 64)
- goto found_first;
- if (tmp)
- goto found_middle;
- size -= 64;
- result += 64;
- }
- while (size & ~63UL) {
- if ((tmp = *p++) != 0)
- goto found_middle;
- result += 64;
- size -= 64;
- }
- if (!size)
- return result;
- tmp = *p;
-
-found_first:
- tmp &= ~0UL >> (64 - size);
- if (tmp == 0UL) /* Are any bits set? */
- return result + size; /* Nope. */
-found_middle:
- return result + __ffs(tmp);
-}
-#else
-int ocfs2_find_next_bit_set(void *addr, int size, int offset)
-{
unsigned char * p;
int set = 0, d0;
unsigned int bit = offset & 7, res = 0;
@@ -371,85 +123,9 @@
return (res + d0 - 1);
}
-#endif
-#if defined(__powerpc__)
int ocfs2_find_next_bit_clear(void *addr, int size, int offset)
{
- unsigned int * p = ((unsigned int *) addr) + (offset >> 5);
- unsigned int result = offset & ~31UL;
- unsigned int tmp;
-
- if (offset >= size)
- return size;
- size -= result;
- offset &= 31UL;
- if (offset) {
- tmp = *p++;
- tmp |= ~0UL >> (32-offset);
- if (size < 32)
- goto found_first;
- if (tmp != ~0U)
- goto found_middle;
- size -= 32;
- result += 32;
- }
- while (size >= 32) {
- if ((tmp = *p++) != ~0U)
- goto found_middle;
- result += 32;
- size -= 32;
- }
- if (!size)
- return result;
- tmp = *p;
-found_first:
- tmp |= ~0UL << size;
- if (tmp == ~0UL) /* Are any bits zero? */
- return result + size; /* Nope. */
-found_middle:
- return result + ffz(tmp);
-}
-#elif defined(__s390x__)
-int ocfs2_find_next_bit_clear(void *addr, int size, int offset)
-{
- unsigned long * p = ((unsigned long *) addr) + (offset >> 6);
- unsigned long result = offset & ~63UL;
- unsigned long tmp;
-
- if (offset >= size)
- return size;
- size -= result;
- offset &= 63UL;
- if (offset) {
- tmp = *p++;
- tmp |= ~0UL >> (64-offset);
- if (size < 64)
- goto found_first;
- if (~tmp)
- goto found_middle;
- size -= 64;
- result += 64;
- }
- while (size & ~63UL) {
- if (~(tmp = *p++))
- goto found_middle;
- result += 64;
- size -= 64;
- }
- if (!size)
- return result;
- tmp = *p;
-found_first:
- tmp |= ~0UL << size;
- if (tmp == ~0UL) /* Are any bits zero? */
- return result + size; /* Nope. */
-found_middle:
- return result + ffz(tmp);
-}
-#else
-int ocfs2_find_next_bit_clear(void *addr, int size, int offset)
-{
unsigned char * p;
int set = 0, d0;
unsigned int bit = offset & 7, res = 0;
@@ -484,11 +160,7 @@
return (res + d0 - 1);
}
-#endif
-#endif
-
-
#ifdef DEBUG_EXE
#include <stdio.h>
#include <stdlib.h>
Modified: branches/endian-safe/libocfs2/chain.c
===================================================================
--- branches/endian-safe/libocfs2/chain.c 2005-08-04 19:55:16 UTC (rev 1017)
+++ branches/endian-safe/libocfs2/chain.c 2005-08-04 20:00:14 UTC (rev 1018)
@@ -29,14 +29,19 @@
#include "ocfs2.h"
-static void ocfs2_group_desc_to_cpu(ocfs2_group_desc *gd)
+static void ocfs2_swap_group_desc(ocfs2_group_desc *gd)
{
- gd->bg_generation = le32_to_cpu(gd->bg_generation);
-}
+ if (cpu_is_little_endian)
+ return;
-static void ocfs2_group_desc_to_le(ocfs2_group_desc *gd)
-{
- gd->bg_generation = cpu_to_le32(gd->bg_generation);
+ gd->bg_size = bswap_16(gd->bg_size);
+ gd->bg_bits = bswap_16(gd->bg_bits);
+ gd->bg_free_bits_count = bswap_16(gd->bg_free_bits_count);
+ gd->bg_chain = bswap_16(gd->bg_chain);
+ gd->bg_generation = bswap_32(gd->bg_generation);
+ gd->bg_next_group = bswap_64(gd->bg_next_group);
+ gd->bg_parent_dinode = bswap_64(gd->bg_parent_dinode);
+ gd->bg_blkno = bswap_64(gd->bg_blkno);
}
errcode_t ocfs2_read_group_desc(ocfs2_filesys *fs, uint64_t blkno,
@@ -68,7 +73,7 @@
memcpy(gd_buf, blk, fs->fs_blocksize);
gd = (ocfs2_group_desc *)gd_buf;
- ocfs2_group_desc_to_cpu(gd);
+ ocfs2_swap_group_desc(gd);
ret = 0;
out:
@@ -98,7 +103,7 @@
memcpy(blk, gd_buf, fs->fs_blocksize);
gd = (ocfs2_group_desc *)blk;
- ocfs2_group_desc_to_le(gd);
+ ocfs2_swap_group_desc(gd);
ret = io_write_block(fs->fs_io, blkno, 1, blk);
if (ret)
Modified: branches/endian-safe/libocfs2/dirblock.c
===================================================================
--- branches/endian-safe/libocfs2/dirblock.c 2005-08-04 19:55:16 UTC (rev 1017)
+++ branches/endian-safe/libocfs2/dirblock.c 2005-08-04 20:00:14 UTC (rev 1018)
@@ -32,7 +32,15 @@
#include "ocfs2.h"
+static void ocfs2_swap_dir_entry(struct ocfs2_dir_entry *dirent)
+{
+ if (cpu_is_little_endian)
+ return;
+ dirent->inode = bswap_64(dirent->inode);
+ dirent->rec_len = bswap_64(dirent->rec_len);
+}
+
errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs, uint64_t block,
void *buf)
{
@@ -50,8 +58,7 @@
while (p < end-12) {
dirent = (struct ocfs2_dir_entry *) p;
- dirent->inode = le64_to_cpu(dirent->inode);
- dirent->rec_len = le16_to_cpu(dirent->rec_len);
+ ocfs2_swap_dir_entry(dirent);
name_len = dirent->name_len;
rec_len = dirent->rec_len;
@@ -95,8 +102,7 @@
p += dirent->rec_len;
- dirent->inode = cpu_to_le64(dirent->inode);
- dirent->rec_len = cpu_to_le16(dirent->rec_len);
+ ocfs2_swap_dir_entry(dirent);
}
retval = io_write_block(fs->fs_io, block, 1, buf);
Modified: branches/endian-safe/libocfs2/extents.c
===================================================================
--- branches/endian-safe/libocfs2/extents.c 2005-08-04 19:55:16 UTC (rev 1017)
+++ branches/endian-safe/libocfs2/extents.c 2005-08-04 20:00:14 UTC (rev 1018)
@@ -34,18 +34,38 @@
#include "ocfs2.h"
-static void ocfs2_swap_extent_block_to_cpu(ocfs2_extent_block *eb)
+void ocfs2_swap_extent_list(ocfs2_extent_list *el)
{
- eb->h_blkno = le64_to_cpu(eb->h_blkno);
- eb->h_suballoc_slot = le16_to_cpu(eb->h_suballoc_slot);
- eb->h_suballoc_bit = le16_to_cpu(eb->h_suballoc_bit);
+ uint16_t i;
+
+ if (cpu_is_little_endian)
+ return;
+
+ 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);
+
+ for(i = 0; i < el->l_next_free_rec; i++) {
+ ocfs2_extent_rec *rec = &el->l_recs[i];
+
+ rec->e_cpos = bswap_32(rec->e_cpos);
+ rec->e_clusters = bswap_32(rec->e_clusters);
+ rec->e_blkno = bswap_64(rec->e_blkno);
+ }
}
-static void ocfs2_swap_extent_block_to_le(ocfs2_extent_block *eb)
+static void ocfs2_swap_extent_block(ocfs2_extent_block *eb)
{
- eb->h_blkno = cpu_to_le64(eb->h_blkno);
- eb->h_suballoc_slot = cpu_to_le16(eb->h_suballoc_slot);
- eb->h_suballoc_bit = cpu_to_le16(eb->h_suballoc_bit);
+ ocfs2_swap_extent_list(&eb->h_list);
+
+ if (cpu_is_little_endian)
+ return;
+
+ 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);
+ eb->h_blkno = bswap_64(eb->h_blkno);
+ eb->h_next_leaf_blk = bswap_64(eb->h_next_leaf_blk);
}
errcode_t ocfs2_read_extent_block_nocheck(ocfs2_filesys *fs, uint64_t blkno,
@@ -78,7 +98,7 @@
memcpy(eb_buf, blk, fs->fs_blocksize);
eb = (ocfs2_extent_block *) eb_buf;
- ocfs2_swap_extent_block_to_cpu(eb);
+ ocfs2_swap_extent_block(eb);
out:
ocfs2_free(&blk);
@@ -121,7 +141,7 @@
memcpy(blk, eb_buf, fs->fs_blocksize);
eb = (ocfs2_extent_block *) blk;
- ocfs2_swap_extent_block_to_le(eb);
+ ocfs2_swap_extent_block(eb);
ret = io_write_block(fs->fs_io, blkno, 1, blk);
if (ret)
Modified: branches/endian-safe/libocfs2/include/bitops.h
===================================================================
--- branches/endian-safe/libocfs2/include/bitops.h 2005-08-04 19:55:16 UTC (rev 1017)
+++ branches/endian-safe/libocfs2/include/bitops.h 2005-08-04 20:00:14 UTC (rev 1018)
@@ -3,8 +3,7 @@
*
* bitops.h
*
- * Bitmap frobbing routines for the OCFS2 userspace library. These
- * are the inlined versions.
+ * Bitmap frobbing routines for the OCFS2 userspace library.
*
* Copyright (C) 2004 Oracle. All rights reserved.
*
@@ -26,251 +25,18 @@
*
* This code is a port of e2fsprogs/lib/ext2fs/bitops.h
* Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
- *
- * i386 bitops operations taken from <asm/bitops.h>, Copyright 1992,
- * Linus Torvalds.
*/
+#ifndef _BITOPS_H
+#define _BITOPS_H
-
-/*
- * OCFS2 bitmap manipulation routines.
- */
-
-#if ((defined __GNUC__) && \
- (defined(__i386__) || defined(__i486__) || defined(__i586__)))
-
-#define _OCFS2_HAVE_ASM_BITOPS_
-
-/*
- * These are done by inline assembly for speed reasons.....
- *
- * All bitoperations return 0 if the bit was cleared before the
- * operation and != 0 if it was not. Bit 0 is the LSB of addr; bit 32
- * is the LSB of (addr+1).
- */
-
-/*
- * Some hacks to defeat gcc over-optimizations..
- */
-struct __dummy_h { unsigned long a[100]; };
-#define OCFS2_ADDR (*(struct __dummy_h *) addr)
-#define OCFS2_CONST_ADDR (*(const struct __dummy_h *) addr)
-
-static inline int ocfs2_set_bit(int nr, void * addr)
-{
- int oldbit;
-
- __asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0"
- :"=r" (oldbit),"=m" (OCFS2_ADDR)
- :"r" (nr));
- return oldbit;
-}
-
-static inline int ocfs2_clear_bit(int nr, void * addr)
-{
- int oldbit;
-
- __asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0"
- :"=r" (oldbit),"=m" (OCFS2_ADDR)
- :"r" (nr));
- return oldbit;
-}
-
-static inline int ocfs2_test_bit(int nr, const void * addr)
-{
- int oldbit;
-
- __asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0"
- :"=r" (oldbit)
- :"m" (OCFS2_CONST_ADDR),"r" (nr));
- return oldbit;
-}
-
-#if 0
-#define _OCFS2_HAVE_ASM_FINDBIT_
-
-_INLINE_ int ext2fs_find_first_bit_set(void * addr, unsigned size)
-{
- int d0, d1, d2;
- int res;
-
- if (!size)
- return 0;
- /* This looks at memory. Mark it volatile to tell gcc not to move it around */
- __asm__ __volatile__(
- "cld\n\t"
- "xorl %%eax,%%eax\n\t"
- "xorl %%edx,%%edx\n\t"
- "repe; scasl\n\t"
- "je 1f\n\t"
- "movl -4(%%edi),%%eax\n\t"
- "subl $4,%%edi\n\t"
- "bsfl %%eax,%%edx\n"
- "1:\tsubl %%esi,%%edi\n\t"
- "shll $3,%%edi\n\t"
- "addl %%edi,%%edx"
- :"=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
- :"1" ((size + 31) >> 5), "2" (addr), "S" (addr));
- return res;
-}
-
-_INLINE_ int ext2fs_find_next_bit_set (void * addr, int size, int offset)
-{
- unsigned long * p = ((unsigned long *) addr) + (offset >> 5);
- int set = 0, bit = offset & 31, res;
-
- if (bit) {
- /*
- * Look for zero in first byte
- */
- __asm__("bsfl %1,%0\n\t"
- "jne 1f\n\t"
- "movl $32, %0\n"
- "1:"
- : "=r" (set)
- : "r" (*p >> bit));
- if (set < (32 - bit))
- return set + offset;
- set = 32 - bit;
- p++;
- }
- /*
- * No bit found yet, search remaining full bytes for a bit
- */
- res = ext2fs_find_first_bit_set(p, size - 32 * (p - (unsigned long *) addr));
- return (offset + set + res);
-}
-#endif
-
-#undef OCFS2_ADDR
-
-#endif /* i386 */
-
-#ifdef __mc68000__
-
-#define _OCFS2_HAVE_ASM_BITOPS_
-
-static inline int ocfs2_set_bit(int nr,void * addr)
-{
- char retval;
-
- __asm__ __volatile__ ("bfset %2@{%1:#1}; sne %0"
- : "=d" (retval) : "d" (nr^7), "a" (addr));
-
- return retval;
-}
-
-static inline int ocfs2_clear_bit(int nr, void * addr)
-{
- char retval;
-
- __asm__ __volatile__ ("bfclr %2@{%1:#1}; sne %0"
- : "=d" (retval) : "d" (nr^7), "a" (addr));
-
- return retval;
-}
-
-static inline int ocfs2_test_bit(int nr, const void * addr)
-{
- char retval;
-
- __asm__ __volatile__ ("bftst %2@{%1:#1}; sne %0"
- : "=d" (retval) : "d" (nr^7), "a" (addr));
-
- return retval;
-}
-
-#endif /* __mc68000__ */
-
-#ifdef __sparc__
-
-#define _OCFS2_HAVE_ASM_BITOPS_
-
-/*
- * Do the bitops so that we are compatible with the standard i386
- * convention.
- */
-
-static inline int ocfs2_set_bit(int nr,void * addr)
-{
-#if 1
- int mask;
- unsigned char *ADDR = (unsigned char *) addr;
-
- ADDR += nr >> 3;
- mask = 1 << (nr & 0x07);
- __asm__ __volatile__("ldub [%0], %%g6\n\t"
- "or %%g6, %2, %%g5\n\t"
- "stb %%g5, [%0]\n\t"
- "and %%g6, %2, %0\n"
- : "=&r" (ADDR)
- : "0" (ADDR), "r" (mask)
- : "g5", "g6");
- return (int) ADDR;
-#else
- int mask, retval;
- unsigned char *ADDR = (unsigned char *) addr;
-
- ADDR += nr >> 3;
- mask = 1 << (nr & 0x07);
- retval = (mask & *ADDR) != 0;
- *ADDR |= mask;
- return retval;
-#endif
-}
-
-static inline int ocfs2_clear_bit(int nr, void * addr)
-{
-#if 1
- int mask;
- unsigned char *ADDR = (unsigned char *) addr;
-
- ADDR += nr >> 3;
- mask = 1 << (nr & 0x07);
- __asm__ __volatile__("ldub [%0], %%g6\n\t"
- "andn %%g6, %2, %%g5\n\t"
- "stb %%g5, [%0]\n\t"
- "and %%g6, %2, %0\n"
- : "=&r" (ADDR)
- : "0" (ADDR), "r" (mask)
- : "g5", "g6");
- return (int) ADDR;
-
-#else
- int mask, retval;
- unsigned char *ADDR = (unsigned char *) addr;
-
- ADDR += nr >> 3;
- mask = 1 << (nr & 0x07);
- retval = (mask & *ADDR) != 0;
- *ADDR &= ~mask;
- return retval;
-#endif
-}
-
-static inline int ocfs2_test_bit(int nr, const void * addr)
-{
- int mask;
- const unsigned char *ADDR = (const unsigned char *) addr;
-
- ADDR += nr >> 3;
- mask = 1 << (nr & 0x07);
- return ((mask & *ADDR) != 0);
-}
-
-#endif /* __sparc__ */
-
-#ifndef _OCFS2_HAVE_ASM_BITOPS_
extern int ocfs2_set_bit(int nr,void * addr);
extern int ocfs2_clear_bit(int nr, void * addr);
extern int ocfs2_test_bit(int nr, const void * addr);
-#endif
-#if !defined(_OCFS2_HAVE_ASM_FINDBIT_)
extern int ocfs2_find_first_bit_set(void *addr, int size);
extern int ocfs2_find_first_bit_clear(void *addr, int size);
extern int ocfs2_find_next_bit_set(void *addr, int size, int offset);
extern int ocfs2_find_next_bit_clear(void *addr, int size, int offset);
-#endif
+#endif
Modified: branches/endian-safe/libocfs2/include/byteorder.h
===================================================================
--- branches/endian-safe/libocfs2/include/byteorder.h 2005-08-04 19:55:16 UTC (rev 1017)
+++ branches/endian-safe/libocfs2/include/byteorder.h 2005-08-04 20:00:14 UTC (rev 1018)
@@ -33,13 +33,13 @@
#include <stdint.h>
/*
- * All OCFS2 on-disk values are in little endian, except for the
- * autoconfig areas and the journal areas. The journal code has the
- * right bits for itself, and the autoconfig areas use htonl(), so
- * they are OK.
+ * All OCFS2 on-disk values are in little endian, except for jbd's journal
+ * fields which it takes care of itself.
*/
#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
@@ -77,6 +77,8 @@
# define be64_to_cpu(x) ((uint64_t)bswap_64(x))
# 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
Modified: branches/endian-safe/libocfs2/include/ocfs2.h
===================================================================
--- branches/endian-safe/libocfs2/include/ocfs2.h 2005-08-04 19:55:16 UTC (rev 1017)
+++ branches/endian-safe/libocfs2/include/ocfs2.h 2005-08-04 20:00:14 UTC (rev 1018)
@@ -253,10 +253,10 @@
errcode_t ocfs2_close(ocfs2_filesys *fs);
void ocfs2_freefs(ocfs2_filesys *fs);
-void ocfs2_swap_inode_to_cpu(ocfs2_dinode *di);
-void ocfs2_swap_inode_to_le(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,
+ char *block_buffers);
errcode_t ocfs2_write_inode(ocfs2_filesys *fs, uint64_t blkno,
char *inode_buf);
errcode_t ocfs2_check_directory(ocfs2_filesys *fs, uint64_t dir);
@@ -268,6 +268,7 @@
errcode_t ocfs2_free_cached_inode(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode);
+void ocfs2_swap_extent_list(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-04 19:55:16 UTC (rev 1017)
+++ branches/endian-safe/libocfs2/inode.c 2005-08-04 20:00:14 UTC (rev 1018)
@@ -62,45 +62,108 @@
return ret;
}
-
-/* FIXME swap rest of inode as kernel is updated */
-void ocfs2_swap_inode_to_cpu(ocfs2_dinode *di)
+static void ocfs2_swap_inode(ocfs2_dinode *di)
{
- di->i_generation = le32_to_cpu(di->i_generation);
- di->i_suballoc_slot = le16_to_cpu(di->i_suballoc_slot);
- di->i_suballoc_bit = le16_to_cpu(di->i_suballoc_bit);
- di->i_fs_generation = le32_to_cpu(di->i_fs_generation);
+ if (cpu_is_little_endian)
+ return;
+ 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);
+ di->i_clusters = bswap_32(di->i_clusters);
+ di->i_uid = bswap_32(di->i_uid);
+ di->i_gid = bswap_32(di->i_gid);
+ di->i_size = bswap_64(di->i_size);
+ di->i_mode = bswap_16(di->i_mode);
+ di->i_links_count = bswap_16(di->i_links_count);
+ di->i_flags = bswap_32(di->i_flags);
+ di->i_atime = bswap_64(di->i_atime);
+ di->i_ctime = bswap_64(di->i_ctime);
+ di->i_mtime = bswap_64(di->i_mtime);
+ di->i_dtime = bswap_64(di->i_dtime);
+ di->i_blkno = bswap_64(di->i_blkno);
+ di->i_last_eb_blk = bswap_64(di->i_last_eb_blk);
+ di->i_fs_generation = bswap_32(di->i_fs_generation);
+ 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 (S_ISCHR(di->i_mode) || S_ISBLK(di->i_mode))
- di->id1.dev1.i_rdev = le64_to_cpu(di->id1.dev1.i_rdev);
- else if (di->i_flags & OCFS2_JOURNAL_FL)
- di->id1.journal1.ij_flags =
- le32_to_cpu(di->id1.journal1.ij_flags);
+ di->id1.dev1.i_rdev = bswap_64(di->id1.dev1.i_rdev);
else if (di->i_flags & OCFS2_BITMAP_FL) {
- di->id1.bitmap1.i_total =
- le32_to_cpu(di->id1.bitmap1.i_total);
- di->id1.bitmap1.i_used =
- le32_to_cpu(di->id1.bitmap1.i_used);
- }
-}
+ di->id1.bitmap1.i_used = bswap_32(di->id1.bitmap1.i_used);
+ di->id1.bitmap1.i_total = bswap_32(di->id1.bitmap1.i_total);
+ } else if (di->i_flags & OCFS2_JOURNAL_FL)
+ di->id1.journal1.ij_flags = bswap_32(di->id1.journal1.ij_flags);
-void ocfs2_swap_inode_to_le(ocfs2_dinode *di)
-{
- di->i_generation = cpu_to_le32(di->i_generation);
- di->i_suballoc_slot = cpu_to_le16(di->i_suballoc_slot);
- di->i_suballoc_bit = cpu_to_le16(di->i_suballoc_bit);
- di->i_fs_generation = cpu_to_le32(di->i_fs_generation);
+ /* we need to be careful to swap the union member that is in use.
+ * first the ones that are explicitly marked with flags.. */
+ if (di->i_flags & OCFS2_SUPER_BLOCK_FL) {
+ ocfs2_super_block *sb = &di->id2.i_super;
- if (S_ISCHR(di->i_mode) || S_ISBLK(di->i_mode))
- di->id1.dev1.i_rdev = cpu_to_le64(di->id1.dev1.i_rdev);
- else if (di->i_flags & OCFS2_JOURNAL_FL)
- di->id1.journal1.ij_flags =
- cpu_to_le32(di->id1.journal1.ij_flags);
- else if (di->i_flags & OCFS2_BITMAP_FL) {
- di->id1.bitmap1.i_total =
- cpu_to_le32(di->id1.bitmap1.i_total);
- di->id1.bitmap1.i_used =
- cpu_to_le32(di->id1.bitmap1.i_used);
+ sb->s_major_rev_level = bswap_16(sb->s_major_rev_level);
+ sb->s_minor_rev_level = bswap_16(sb->s_minor_rev_level);
+ sb->s_mnt_count = bswap_16(sb->s_mnt_count);
+ sb->s_max_mnt_count = bswap_16(sb->s_max_mnt_count);
+ sb->s_state = bswap_16(sb->s_state);
+ sb->s_errors = bswap_16(sb->s_errors);
+ sb->s_checkinterval = bswap_32(sb->s_checkinterval);
+ sb->s_lastcheck = bswap_64(sb->s_lastcheck);
+ sb->s_creator_os = bswap_32(sb->s_creator_os);
+ sb->s_feature_compat = bswap_32(sb->s_feature_compat);
+ sb->s_feature_ro_compat = bswap_32(sb->s_feature_ro_compat);
+ sb->s_feature_incompat = bswap_32(sb->s_feature_incompat);
+ sb->s_root_blkno = bswap_64(sb->s_root_blkno);
+ sb->s_system_dir_blkno = bswap_64(sb->s_system_dir_blkno);
+ sb->s_blocksize_bits = bswap_32(sb->s_blocksize_bits);
+ sb->s_clustersize_bits = bswap_32(sb->s_clustersize_bits);
+ sb->s_max_slots = bswap_16(sb->s_max_slots);
+ sb->s_first_cluster_group = bswap_64(sb->s_first_cluster_group);
+
+ } else if (di->i_flags & OCFS2_LOCAL_ALLOC_FL) {
+ ocfs2_local_alloc *la = &di->id2.i_lab;
+
+ la->la_bm_off = bswap_32(la->la_bm_off);
+ la->la_size = bswap_16(la->la_size);
+
+ } else if (di->i_flags & OCFS2_CHAIN_FL) {
+ ocfs2_chain_list *cl = &di->id2.i_chain;
+ uint16_t 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);
+
+ 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;
+
+ tl->tl_count = bswap_16(tl->tl_count);
+ tl->tl_used = bswap_16(tl->tl_used);
+
+ 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);
+ }
+ } 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);
}
}
@@ -133,7 +196,7 @@
memcpy(inode_buf, blk, fs->fs_blocksize);
di = (ocfs2_dinode *) inode_buf;
- ocfs2_swap_inode_to_cpu(di);
+ ocfs2_swap_inode(di);
ret = 0;
out:
@@ -142,6 +205,33 @@
return ret;
}
+/* block_buffers must have been allocated with malloc_blocks so that its
+ * aligned */
+errcode_t ocfs2_read_inodes(ocfs2_filesys *fs, uint64_t blkno, int num_blocks,
+ char *block_buffers)
+{
+ ocfs2_dinode *di;
+ int i, ret;
+
+ ret = io_read_block(fs->fs_io, blkno, num_blocks, block_buffers);
+ if (ret)
+ goto out;
+
+ for (i = 0; i < num_blocks; i++) {
+ di = (ocfs2_dinode *)(block_buffers + (i * fs->fs_blocksize));
+
+ if (memcmp(di->i_signature, OCFS2_INODE_SIGNATURE,
+ strlen(OCFS2_INODE_SIGNATURE))) {
+ ret = OCFS2_ET_BAD_INODE_MAGIC;
+ goto out;
+ }
+
+ ocfs2_swap_inode(di);
+ }
+out:
+ return ret;
+}
+
errcode_t ocfs2_write_inode(ocfs2_filesys *fs, uint64_t blkno,
char *inode_buf)
{
@@ -163,7 +253,7 @@
memcpy(blk, inode_buf, fs->fs_blocksize);
di = (ocfs2_dinode *)blk;
- ocfs2_swap_inode_to_le(di);
+ ocfs2_swap_inode(di);
ret = io_write_block(fs->fs_io, blkno, 1, blk);
if (ret)
Modified: branches/endian-safe/libocfs2/inode_scan.c
===================================================================
--- branches/endian-safe/libocfs2/inode_scan.c 2005-08-04 19:55:16 UTC (rev 1017)
+++ branches/endian-safe/libocfs2/inode_scan.c 2005-08-04 20:00:14 UTC (rev 1018)
@@ -86,8 +86,8 @@
if (!scan->cur_blkno)
abort();
- ret = io_read_block(scan->fs->fs_io, scan->cur_blkno, 1,
- (char *)scan->cur_desc);
+ ret = ocfs2_read_group_desc(scan->fs, scan->cur_blkno,
+ (char *)scan->cur_desc);
if (ret)
return (ret);
@@ -175,10 +175,8 @@
if (num_blocks > scan->buffer_blocks)
num_blocks = scan->buffer_blocks;
- ret = io_read_block(scan->fs->fs_io,
- scan->cur_blkno,
- num_blocks,
- scan->group_buffer);
+ ret = ocfs2_read_inodes(scan->fs, scan->cur_blkno, num_blocks,
+ scan->group_buffer);
if (ret)
return ret;
@@ -239,7 +237,7 @@
return ret;
}
- /* FIXME: Should swap the inode */
+ /* ocfs2_read_inodes() swapped these for us alread */
memcpy(inode, scan->cur_block, scan->fs->fs_blocksize);
scan->cur_block += scan->fs->fs_blocksize;
Modified: branches/endian-safe/libocfs2/mkjournal.c
===================================================================
--- branches/endian-safe/libocfs2/mkjournal.c 2005-08-04 19:55:16 UTC (rev 1017)
+++ branches/endian-safe/libocfs2/mkjournal.c 2005-08-04 20:00:14 UTC (rev 1018)
@@ -38,7 +38,30 @@
#undef be32_to_cpu
#include "jfs_user.h"
+static void ocfs2_swap_journal_superblock(journal_superblock_t *jsb)
+{
+ if (cpu_is_big_endian)
+ return;
+ jsb->s_header.h_magic = bswap_32(jsb->s_header.h_magic);
+ jsb->s_header.h_blocktype = bswap_32(jsb->s_header.h_blocktype);
+ jsb->s_header.h_sequence = bswap_32(jsb->s_header.h_sequence);
+
+ jsb->s_blocksize = bswap_32(jsb->s_blocksize);
+ jsb->s_maxlen = bswap_32(jsb->s_maxlen);
+ jsb->s_first = bswap_32(jsb->s_first);
+ jsb->s_sequence = bswap_32(jsb->s_sequence);
+ jsb->s_start = bswap_32(jsb->s_start);
+ jsb->s_errno = bswap_32(jsb->s_errno);
+ jsb->s_feature_compat = bswap_32(jsb->s_feature_compat);
+ jsb->s_feature_incompat = bswap_32(jsb->s_feature_incompat);
+ jsb->s_feature_ro_compat = bswap_32(jsb->s_feature_ro_compat);
+ jsb->s_nr_users = bswap_32(jsb->s_nr_users);
+ jsb->s_dynsuper = bswap_32(jsb->s_dynsuper);
+ jsb->s_max_transaction = bswap_32(jsb->s_max_transaction);
+ jsb->s_max_trans_data = bswap_32(jsb->s_max_trans_data);
+}
+
/*
* The code to init a journal superblock is also in
* mkfs.ocfs2/mkfs.c:replacement_journal_create().
@@ -56,21 +79,21 @@
return OCFS2_ET_JOURNAL_TOO_SMALL;
memset(buf, 0, buflen);
- jsb->s_header.h_magic = htonl(JFS_MAGIC_NUMBER);
- jsb->s_header.h_blocktype = htonl(JFS_SUPERBLOCK_V2);
+ jsb->s_header.h_magic = JFS_MAGIC_NUMBER;
+ jsb->s_header.h_blocktype = JFS_SUPERBLOCK_V2;
- jsb->s_blocksize = cpu_to_be32(fs->fs_blocksize);
- jsb->s_maxlen = cpu_to_be32(jrnl_size_in_blks);
+ jsb->s_blocksize = fs->fs_blocksize;
+ jsb->s_maxlen = jrnl_size_in_blks;
if (fs->fs_blocksize == 512)
- jsb->s_first = htonl(2);
+ jsb->s_first = 2;
else
- jsb->s_first = htonl(1);
+ jsb->s_first = 1;
- jsb->s_start = htonl(1);
- jsb->s_sequence = htonl(1);
- jsb->s_errno = htonl(0);
- jsb->s_nr_users = htonl(1);
+ jsb->s_start = 1;
+ jsb->s_sequence = 1;
+ jsb->s_errno = 0;
+ jsb->s_nr_users = 1;
memcpy(jsb->s_uuid, OCFS2_RAW_SB(fs->fs_super)->s_uuid,
sizeof(jsb->s_uuid));
@@ -107,9 +130,9 @@
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
jsb->s_nr_users = 0;
if (fs->blocksize == 1024)
- jsb->s_first = htonl(3);
+ jsb->s_first = 3;
else
- jsb->s_first = htonl(2);
+ jsb->s_first = 2;
}
#endif
@@ -149,18 +172,8 @@
}
memcpy(jsb_buf, blk, fs->fs_blocksize);
+ ocfs2_swap_journal_superblock(jsb);
- /* XXX incomplete */
- jsb->s_header.h_magic = be32_to_cpu(disk->s_header.h_magic);
- jsb->s_header.h_blocktype = be32_to_cpu(disk->s_header.h_blocktype);
-
- jsb->s_blocksize = be32_to_cpu(disk->s_blocksize);
- jsb->s_maxlen = be32_to_cpu(disk->s_maxlen);
- jsb->s_first = be32_to_cpu(disk->s_first);
- jsb->s_start = be32_to_cpu(disk->s_start);
- jsb->s_sequence = be32_to_cpu(disk->s_sequence);
- jsb->s_errno = be32_to_cpu(disk->s_errno);
-
ret = 0;
out:
ocfs2_free(&blk);
@@ -190,18 +203,8 @@
jsb = (journal_superblock_t *)jsb_buf;
memcpy(blk, jsb_buf, fs->fs_blocksize);
+ ocfs2_swap_journal_superblock(disk);
- /* XXX incomplete */
- disk->s_header.h_magic = cpu_to_be32(jsb->s_header.h_magic);
- disk->s_header.h_blocktype = cpu_to_be32(jsb->s_header.h_blocktype);
-
- disk->s_blocksize = cpu_to_be32(jsb->s_blocksize);
- disk->s_maxlen = cpu_to_be32(jsb->s_maxlen);
- disk->s_first = cpu_to_be32(jsb->s_first);
- disk->s_start = cpu_to_be32(jsb->s_start);
- disk->s_sequence = cpu_to_be32(jsb->s_sequence);
- disk->s_errno = cpu_to_be32(jsb->s_errno);
-
ret = io_write_block(fs->fs_io, blkno, 1, blk);
if (ret)
goto out;
Modified: branches/endian-safe/libocfs2/openfs.c
===================================================================
--- branches/endian-safe/libocfs2/openfs.c 2005-08-04 19:55:16 UTC (rev 1017)
+++ branches/endian-safe/libocfs2/openfs.c 2005-08-04 20:00:14 UTC (rev 1018)
@@ -71,58 +71,6 @@
return ret;
}
-static void ocfs2_swap_super_to_cpu(ocfs2_dinode *di)
-{
- ocfs2_super_block *sb;
-
- ocfs2_swap_inode_to_cpu(di);
-
- sb = &di->id2.i_super;
- sb->s_major_rev_level = le16_to_cpu(sb->s_major_rev_level);
- sb->s_minor_rev_level = le16_to_cpu(sb->s_minor_rev_level);
- sb->s_mnt_count = le16_to_cpu(sb->s_mnt_count);
- sb->s_max_mnt_count = le16_to_cpu(sb->s_max_mnt_count);
- sb->s_state = le16_to_cpu(sb->s_state);
- sb->s_checkinterval = le32_to_cpu(sb->s_checkinterval);
- sb->s_lastcheck = le64_to_cpu(sb->s_lastcheck);
- sb->s_creator_os = le32_to_cpu(sb->s_creator_os);
- sb->s_feature_compat = le32_to_cpu(sb->s_feature_compat);
- sb->s_feature_ro_compat = le32_to_cpu(sb->s_feature_ro_compat);
- sb->s_feature_incompat = le32_to_cpu(sb->s_feature_incompat);
- sb->s_root_blkno = le64_to_cpu(sb->s_root_blkno);
- sb->s_system_dir_blkno = le64_to_cpu(sb->s_system_dir_blkno);
- sb->s_blocksize_bits = le32_to_cpu(sb->s_blocksize_bits);
- sb->s_clustersize_bits = le32_to_cpu(sb->s_clustersize_bits);
- sb->s_max_slots = le16_to_cpu(sb->s_max_slots);
- sb->s_first_cluster_group = le64_to_cpu(sb->s_first_cluster_group);
-}
-
-static void ocfs2_swap_super_to_le(ocfs2_dinode *di)
-{
- ocfs2_super_block *sb;
-
- ocfs2_swap_inode_to_le(di);
-
- sb = &di->id2.i_super;
- sb->s_major_rev_level = cpu_to_le16(sb->s_major_rev_level);
- sb->s_minor_rev_level = cpu_to_le16(sb->s_minor_rev_level);
- sb->s_mnt_count = cpu_to_le16(sb->s_mnt_count);
- sb->s_max_mnt_count = cpu_to_le16(sb->s_max_mnt_count);
- sb->s_state = cpu_to_le16(sb->s_state);
- sb->s_checkinterval = cpu_to_le32(sb->s_checkinterval);
- sb->s_lastcheck = cpu_to_le64(sb->s_lastcheck);
- sb->s_creator_os = cpu_to_le32(sb->s_creator_os);
- sb->s_feature_compat = cpu_to_le32(sb->s_feature_compat);
- sb->s_feature_ro_compat = cpu_to_le32(sb->s_feature_ro_compat);
- sb->s_feature_incompat = cpu_to_le32(sb->s_feature_incompat);
- sb->s_root_blkno = cpu_to_le64(sb->s_root_blkno);
- sb->s_system_dir_blkno = cpu_to_le64(sb->s_system_dir_blkno);
- sb->s_blocksize_bits = cpu_to_le32(sb->s_blocksize_bits);
- sb->s_clustersize_bits = cpu_to_le32(sb->s_clustersize_bits);
- sb->s_max_slots = cpu_to_le16(sb->s_max_slots);
- sb->s_first_cluster_group = cpu_to_le64(sb->s_first_cluster_group);
-}
-
static errcode_t ocfs2_read_super(ocfs2_filesys *fs, int superblock)
{
errcode_t ret;
@@ -133,7 +81,7 @@
if (ret)
return ret;
- ret = io_read_block(fs->fs_io, superblock, 1, blk);
+ ret = ocfs2_read_inode(fs, superblock, blk);
if (ret)
goto out_blk;
di = (ocfs2_dinode *)blk;
@@ -143,8 +91,6 @@
strlen(OCFS2_SUPER_BLOCK_SIGNATURE)))
goto out_blk;
- ocfs2_swap_super_to_cpu(di);
-
fs->fs_super = di;
return 0;
@@ -172,9 +118,7 @@
strlen(OCFS2_SUPER_BLOCK_SIGNATURE)))
goto out_blk;
- ocfs2_swap_super_to_le(di);
- ret = io_write_block(fs->fs_io, OCFS2_SUPER_BLOCK_BLKNO, 1, blk);
- ocfs2_swap_super_to_cpu(di);
+ ret = ocfs2_write_inode(fs, OCFS2_SUPER_BLOCK_BLKNO, blk);
if (ret)
goto out_blk;
More information about the Ocfs2-tools-commits
mailing list