From: Robert Pengelly Date: Sun, 31 Aug 2025 19:28:20 +0000 (+0100) Subject: Don't forget to swap the superblock on after read X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=0aa14d117d01ae4eb883bdad0b66fca97e5169bd;p=e2fsprogs.git Don't forget to swap the superblock on after read --- diff --git a/common.c b/common.c index 560f16e..2322812 100644 --- 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); diff --git a/common.h b/common.h index d39c2ff..9dd806c 100644 --- 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 a2abcf7..eaa6d45 100644 --- 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 763567b..eb8e354 100644 --- 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);