summaryrefslogtreecommitdiff
path: root/e2fsck/swapfs.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2002-10-02 22:07:17 -0400
committerTheodore Ts'o <tytso@mit.edu>2002-10-02 22:07:17 -0400
commit8132d840c8f6b0d90ab5048d6f8529f74e1aa0b3 (patch)
treeee14b3b1993ee2e081a01ac3d4a71c0ad258eadf /e2fsck/swapfs.c
parent3432a916edad569235586b45d1a51706d4d700a7 (diff)
downloade2fsprogs-8132d840c8f6b0d90ab5048d6f8529f74e1aa0b3.tar.gz
Fix endian problems in the htree code for e2fsck and debugfs.
When byte-swapping a filesystem on a PPC architecture, byte-swap the bitmaps since the historical big-endian ext2 variant had byte-swapped bitmaps, and the ext2fs library assumes this. Otherwise the regression test suite will fail...
Diffstat (limited to 'e2fsck/swapfs.c')
-rw-r--r--e2fsck/swapfs.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/e2fsck/swapfs.c b/e2fsck/swapfs.c
index 513859b7..b59079c4 100644
--- a/e2fsck/swapfs.c
+++ b/e2fsck/swapfs.c
@@ -183,6 +183,31 @@ static void swap_inodes(e2fsck_t ctx)
e2fsck_use_inode_shortcuts(ctx, 0);
}
+#if defined(__powerpc__) && defined(EXT2FS_ENABLE_SWAPFS)
+/*
+ * On the PowerPC, the big-endian variant of the ext2 filesystem
+ * has its bitmaps stored as 32-bit words with bit 0 as the LSB
+ * of each word. Thus a bitmap with only bit 0 set would be, as
+ * a string of bytes, 00 00 00 01 00 ...
+ * To cope with this, we byte-reverse each word of a bitmap if
+ * we have a big-endian filesystem, that is, if we are *not*
+ * byte-swapping other word-sized numbers.
+ */
+#define EXT2_BIG_ENDIAN_BITMAPS
+#endif
+
+#ifdef EXT2_BIG_ENDIAN_BITMAPS
+static void ext2fs_swap_bitmap(ext2fs_generic_bitmap bmap)
+{
+ __u32 *p = (__u32 *) bmap->bitmap;
+ int n, nbytes = (bmap->end - bmap->start + 7) / 8;
+
+ for (n = nbytes / sizeof(__u32); n > 0; --n, ++p)
+ *p = ext2fs_swab32(*p);
+}
+#endif
+
+
void swap_filesys(e2fsck_t ctx)
{
ext2_filsys fs = ctx->fs;
@@ -222,6 +247,13 @@ void swap_filesys(e2fsck_t ctx)
fs->flags |= EXT2_FLAG_SWAP_BYTES;
fs->flags &= ~(EXT2_FLAG_SWAP_BYTES_READ|
EXT2_FLAG_SWAP_BYTES_WRITE);
+
+#ifdef EXT2_BIG_ENDIAN_BITMAPS
+ e2fsck_read_bitmaps(ctx);
+ ext2fs_swap_bitmap(fs->inode_map);
+ ext2fs_swap_bitmap(fs->block_map);
+ fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_IB_DIRTY;
+#endif
ext2fs_flush(fs);
#ifdef RESOURCE_TRACK