From 46e1286ae644df4a1340407ad945b8cc7351231b Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 9 Nov 2019 23:28:43 -0500 Subject: [PATCH] Define the beXX_to_cpu and cpu_to_beXX macros for e2fsck/{recovery.c,revoke.c} We were previously using contrib/jbd2-resync.sh to transmogrify the beXX_to_cpu and cpu_to_beXX macros to ext2fs_beXX_to_cpu and ext2fs_cpu_to_beXX. Define them in lib/ext2fs/jfs_compat.h so we can more easily keep them in sync with the kernel version of those files. Signed-off-by: Theodore Ts'o --- contrib/jbd2-resync.sh | 5 ----- e2fsck/recovery.c | 34 +++++++++++++++++----------------- e2fsck/revoke.c | 2 +- lib/ext2fs/jfs_compat.h | 12 +++++++----- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/contrib/jbd2-resync.sh b/contrib/jbd2-resync.sh index 9b3a52e..f6b3887 100755 --- a/contrib/jbd2-resync.sh +++ b/contrib/jbd2-resync.sh @@ -6,10 +6,5 @@ if [ -z "$1" -o -z "$2" ]; then fi # Transform a few things to fit the compatibility things defined in jfs_user.h. -# Use the ext2fs_ endian conversion functions because they truncate oversized -# inputs (e.g. passing a u32 to cpu_to_be16()) like the kernel versions and -# unlike the libc6 versions. exec sed -e 's/struct kmem_cache/lkmem_cache_t/g' \ - -e 's/cpu_to_be/ext2fs_cpu_to_be/g' \ - -e 's/be\([0-9][0-9]\)_to_cpu/ext2fs_be\1_to_cpu/g' \ < "$1" > "$2" diff --git a/e2fsck/recovery.c b/e2fsck/recovery.c index 1496098..5df690a 100644 --- a/e2fsck/recovery.c +++ b/e2fsck/recovery.c @@ -208,7 +208,7 @@ static int jbd2_descriptor_block_csum_verify(journal_t *j, void *buf) calculated = jbd2_chksum(j, j->j_csum_seed, buf, j->j_blocksize); tail->t_checksum = provided; - return provided == ext2fs_cpu_to_be32(calculated); + return provided == cpu_to_be32(calculated); } /* @@ -280,8 +280,8 @@ int jbd2_journal_recover(journal_t *journal) if (!sb->s_start) { jbd_debug(1, "No recovery required, last transaction %d\n", - ext2fs_be32_to_cpu(sb->s_sequence)); - journal->j_transaction_sequence = ext2fs_be32_to_cpu(sb->s_sequence) + 1; + be32_to_cpu(sb->s_sequence)); + journal->j_transaction_sequence = be32_to_cpu(sb->s_sequence) + 1; return 0; } @@ -343,7 +343,7 @@ int jbd2_journal_skip_recovery(journal_t *journal) } else { #ifdef CONFIG_JBD2_DEBUG int dropped = info.end_transaction - - ext2fs_be32_to_cpu(journal->j_superblock->s_sequence); + be32_to_cpu(journal->j_superblock->s_sequence); jbd_debug(1, "JBD2: ignoring %d transaction%s from the journal.\n", dropped, (dropped == 1) ? "" : "s"); @@ -411,7 +411,7 @@ static int jbd2_commit_block_csum_verify(journal_t *j, void *buf) calculated = jbd2_chksum(j, j->j_csum_seed, buf, j->j_blocksize); h->h_chksum[0] = provided; - return provided == ext2fs_cpu_to_be32(calculated); + return provided == cpu_to_be32(calculated); } static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag, @@ -424,7 +424,7 @@ static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag, if (!jbd2_journal_has_csum_v2or3(j)) return 1; - seq = ext2fs_cpu_to_be32(sequence); + seq = cpu_to_be32(sequence); csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&seq, sizeof(seq)); csum32 = jbd2_chksum(j, csum32, buf, j->j_blocksize); @@ -457,8 +457,8 @@ static int do_one_pass(journal_t *journal, */ sb = journal->j_superblock; - next_commit_ID = ext2fs_be32_to_cpu(sb->s_sequence); - next_log_block = ext2fs_be32_to_cpu(sb->s_start); + next_commit_ID = be32_to_cpu(sb->s_sequence); + next_log_block = be32_to_cpu(sb->s_start); first_commit_ID = next_commit_ID; if (pass == PASS_SCAN) @@ -513,13 +513,13 @@ static int do_one_pass(journal_t *journal, tmp = (journal_header_t *)bh->b_data; - if (tmp->h_magic != ext2fs_cpu_to_be32(JBD2_MAGIC_NUMBER)) { + if (tmp->h_magic != cpu_to_be32(JBD2_MAGIC_NUMBER)) { brelse(bh); break; } - blocktype = ext2fs_be32_to_cpu(tmp->h_blocktype); - sequence = ext2fs_be32_to_cpu(tmp->h_sequence); + blocktype = be32_to_cpu(tmp->h_blocktype); + sequence = be32_to_cpu(tmp->h_sequence); jbd_debug(3, "Found magic %d, sequence %d\n", blocktype, sequence); @@ -613,7 +613,7 @@ static int do_one_pass(journal_t *journal, /* Look for block corruption */ if (!jbd2_block_tag_csum_verify( journal, tag, obh->b_data, - ext2fs_be32_to_cpu(tmp->h_sequence))) { + be32_to_cpu(tmp->h_sequence))) { brelse(obh); success = -EFSBADCRC; printk(KERN_ERR "JBD2: Invalid " @@ -643,7 +643,7 @@ static int do_one_pass(journal_t *journal, memcpy(nbh->b_data, obh->b_data, journal->j_blocksize); if (flags & JBD2_FLAG_ESCAPE) { - __be32 magic = ext2fs_cpu_to_be32(JBD2_MAGIC_NUMBER); + __be32 magic = cpu_to_be32(JBD2_MAGIC_NUMBER); memcpy(nbh->b_data, &magic, sizeof(magic)); } @@ -713,7 +713,7 @@ static int do_one_pass(journal_t *journal, struct commit_header *cbh = (struct commit_header *)bh->b_data; unsigned found_chksum = - ext2fs_be32_to_cpu(cbh->h_chksum[0]); + be32_to_cpu(cbh->h_chksum[0]); chksum_err = chksum_seen = 0; @@ -839,7 +839,7 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh, header = (jbd2_journal_revoke_header_t *) bh->b_data; offset = sizeof(jbd2_journal_revoke_header_t); - rcount = ext2fs_be32_to_cpu(header->r_count); + rcount = be32_to_cpu(header->r_count); if (!jbd2_descriptor_block_csum_verify(journal, header)) return -EFSBADCRC; @@ -858,9 +858,9 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh, int err; if (record_len == 4) - blocknr = ext2fs_be32_to_cpu(* ((__be32 *) (bh->b_data+offset))); + blocknr = be32_to_cpu(* ((__be32 *) (bh->b_data+offset))); else - blocknr = ext2fs_be64_to_cpu(* ((__be64 *) (bh->b_data+offset))); + blocknr = be64_to_cpu(* ((__be64 *) (bh->b_data+offset))); offset += record_len; err = jbd2_journal_set_revoke(journal, blocknr, sequence); if (err) diff --git a/e2fsck/revoke.c b/e2fsck/revoke.c index 6406cae..b8da99b 100644 --- a/e2fsck/revoke.c +++ b/e2fsck/revoke.c @@ -648,7 +648,7 @@ static void flush_descriptor(journal_t *journal, return; header = (jbd2_journal_revoke_header_t *)descriptor->b_data; - header->r_count = ext2fs_cpu_to_be32(offset); + header->r_count = cpu_to_be32(offset); jbd2_descriptor_block_csum_set(journal, descriptor); set_buffer_jwrite(descriptor); diff --git a/lib/ext2fs/jfs_compat.h b/lib/ext2fs/jfs_compat.h index a51aebc..2bda521 100644 --- a/lib/ext2fs/jfs_compat.h +++ b/lib/ext2fs/jfs_compat.h @@ -20,10 +20,13 @@ #define REQ_OP_READ 0 #define REQ_OP_WRITE 1 -#define cpu_to_be32(n) htonl(n) -#define be32_to_cpu(n) ntohl(n) -#define cpu_to_be16(n) htons(n) -#define be16_to_cpu(n) ntohs(n) +#define cpu_to_be16(x) ext2fs_cpu_to_be16(x) +#define cpu_to_be32(x) ext2fs_cpu_to_be32(x) +#define cpu_to_be64(x) ext2fs_cpu_to_be64(x) + +#define be16_to_cpu(x) ext2fs_be16_to_cpu(x) +#define be32_to_cpu(x) ext2fs_be32_to_cpu(x) +#define be64_to_cpu(x) ext2fs_be64_to_cpu(x) typedef unsigned int tid_t; typedef struct journal_s journal_t; @@ -40,7 +43,6 @@ typedef unsigned int gfp_t; #define JBD2_BARRIER 0 typedef __u64 u64; #define put_bh(x) brelse(x) -#define be64_to_cpu(x) ext2fs_be64_to_cpu(x) static inline __u32 jbd2_chksum(journal_t *j EXT2FS_ATTR((unused)), __u32 crc, const void *address, -- 1.8.3.1