Don't forget to swap the superblock on after read
authorRobert Pengelly <robertapengelly@hotmail.com>
Sun, 31 Aug 2025 19:28:20 +0000 (20:28 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sun, 31 Aug 2025 19:28:20 +0000 (20:28 +0100)
common.c
common.h
e2cp.c
e2md.c

index 560f16e4423a82131aedb946602ca4078c522971..23228123a39110a6c66f916b503f3b3d9d8f70d5 100644 (file)
--- a/common.c
+++ b/common.c
@@ -52,7 +52,7 @@ static void swap32_byte_array (unsigned char *arr, unsigned long n) {
 
 }
 
-static void swap_sb (struct superblock *sb) {
+void swap_sb (struct superblock *sb) {
 
     swap32 (sb->s_inodes_count);
     swap32 (sb->s_blocks_count);
index d39c2ff447e68b6a8fbccf47ce0a5e277fd37052..9dd806c057fb65f0924bfe7d4ebda53946c4089c 100644 (file)
--- a/common.h
+++ b/common.h
@@ -220,7 +220,9 @@ struct directory *new_dir (struct filesystem *fs, unsigned long dnod, const char
 struct directory *shrink_dir (struct dirwalker *dw, unsigned long nod, const char *name, unsigned short nlen);
 
 char *dir_name (struct dirwalker *dw);
+
 void init_bw (struct blockwalker *bw);
+void swap_sb (struct superblock *sb);
 
 void extend_inode_blk (struct filesystem *fs, struct inode_pos *ipos, unsigned char *b, signed long amount);
 void finish_fs (struct filesystem *fs);
diff --git a/e2cp.c b/e2cp.c
index a2abcf733ad354e314acac2d0b274a02e762e53c..eaa6d45c2c7dc56dc4151f46ae80a8cfd54faaa1 100644 (file)
--- a/e2cp.c
+++ b/e2cp.c
@@ -797,6 +797,10 @@ int main (int argc, char **argv) {
     
     }
     
+    if (bigendian) {
+               swap_sb (&sup);
+    }
+    
     if (sup.s_magic[0] != (EXT2_SUPER_MAGIC & 0xff) || sup.s_magic[1] != ((EXT2_SUPER_MAGIC >> 8) & 0xff)) {
     
         report_at (program_name, 0, REPORT_ERROR, "'%s' has a unsupported file system", outfile);
diff --git a/e2md.c b/e2md.c
index 763567b71f5fdb34dc573be33d762af2ae3d9763..eb8e35419a2c70e78c6c3d57c40c63839af5d452 100644 (file)
--- a/e2md.c
+++ b/e2md.c
@@ -396,6 +396,10 @@ int main (int argc, char **argv) {
     
     }
     
+    if (bigendian) {
+               swap_sb (&sup);
+    }
+    
     if (sup.s_magic[0] != (EXT2_SUPER_MAGIC & 0xff) || sup.s_magic[1] != ((EXT2_SUPER_MAGIC >> 8) & 0xff)) {
     
         report_at (program_name, 0, REPORT_ERROR, "'%s' has a unsupported file system", outfile);