From abbe0f9d70d2f6286e83b2168cd4f434c757a8a1 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 9 Nov 2019 01:42:59 -0500 Subject: [PATCH] e2fsck/recovery.c: sync up with kernel's use of __be32 E2fsprogs as a whole is not sparse-clean, but it does have and understand the __beXX and __leXX types from the kernel. The structure definitions in kernel-jbd.h have been updated to use the __beXX types, so that recovery.c and revoke.c are more sparse-clean. This removes a few more unneeded deltas from the kernel's recovery.c. Signed-off-by: Theodore Ts'o --- contrib/jbd2-resync.sh | 3 +-- e2fsck/recovery.c | 12 +++++----- lib/ext2fs/kernel-jbd.h | 64 ++++++++++++++++++++++++------------------------- 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/contrib/jbd2-resync.sh b/contrib/jbd2-resync.sh index 600df8d..9b3a52e 100755 --- a/contrib/jbd2-resync.sh +++ b/contrib/jbd2-resync.sh @@ -9,8 +9,7 @@ fi # 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/__be/__u/g' \ - -e 's/struct kmem_cache/lkmem_cache_t/g' \ +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 ddbb386..1496098 100644 --- a/e2fsck/recovery.c +++ b/e2fsck/recovery.c @@ -195,7 +195,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal, static int jbd2_descriptor_block_csum_verify(journal_t *j, void *buf) { struct jbd2_journal_block_tail *tail; - __u32 provided; + __be32 provided; __u32 calculated; if (!jbd2_journal_has_csum_v2or3(j)) @@ -399,7 +399,7 @@ static int calc_chksums(journal_t *journal, struct buffer_head *bh, static int jbd2_commit_block_csum_verify(journal_t *j, void *buf) { struct commit_header *h; - __u32 provided; + __be32 provided; __u32 calculated; if (!jbd2_journal_has_csum_v2or3(j)) @@ -419,7 +419,7 @@ static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag, { journal_block_tag3_t *tag3 = (journal_block_tag3_t *)tag; __u32 csum32; - __u32 seq; + __be32 seq; if (!jbd2_journal_has_csum_v2or3(j)) return 1; @@ -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) { - __u32 magic = ext2fs_cpu_to_be32(JBD2_MAGIC_NUMBER); + __be32 magic = ext2fs_cpu_to_be32(JBD2_MAGIC_NUMBER); memcpy(nbh->b_data, &magic, sizeof(magic)); } @@ -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(* ((__u32 *) (bh->b_data+offset))); + blocknr = ext2fs_be32_to_cpu(* ((__be32 *) (bh->b_data+offset))); else - blocknr = ext2fs_be64_to_cpu(* ((__u64 *) (bh->b_data+offset))); + blocknr = ext2fs_be64_to_cpu(* ((__be64 *) (bh->b_data+offset))); offset += record_len; err = jbd2_journal_set_revoke(journal, blocknr, sequence); if (err) diff --git a/lib/ext2fs/kernel-jbd.h b/lib/ext2fs/kernel-jbd.h index 650a2f7..cb1bc30 100644 --- a/lib/ext2fs/kernel-jbd.h +++ b/lib/ext2fs/kernel-jbd.h @@ -100,9 +100,9 @@ extern void * __jbd_kmalloc (char *where, size_t size, int flags, int retry); */ typedef struct journal_header_s { - __u32 h_magic; - __u32 h_blocktype; - __u32 h_sequence; + __be32 h_magic; + __be32 h_blocktype; + __be32 h_sequence; } journal_header_t; /* @@ -135,15 +135,15 @@ typedef struct journal_header_s * Checksum v1, v2, and v3 are mutually exclusive features. */ struct commit_header { - __u32 h_magic; - __u32 h_blocktype; - __u32 h_sequence; + __be32 h_magic; + __be32 h_blocktype; + __be32 h_sequence; unsigned char h_chksum_type; unsigned char h_chksum_size; unsigned char h_padding[2]; - __u32 h_chksum[JBD2_CHECKSUM_BYTES]; - __u64 h_commit_sec; - __u32 h_commit_nsec; + __be32 h_chksum[JBD2_CHECKSUM_BYTES]; + __be64 h_commit_sec; + __be32 h_commit_nsec; }; /* @@ -151,18 +151,18 @@ struct commit_header { */ typedef struct journal_block_tag3_s { - __u32 t_blocknr; /* The on-disk block number */ - __u32 t_flags; /* See below */ - __u32 t_blocknr_high; /* most-significant high 32bits. */ - __u32 t_checksum; /* crc32c(uuid+seq+block) */ + __be32 t_blocknr; /* The on-disk block number */ + __be32 t_flags; /* See below */ + __be32 t_blocknr_high; /* most-significant high 32bits. */ + __be32 t_checksum; /* crc32c(uuid+seq+block) */ } journal_block_tag3_t; typedef struct journal_block_tag_s { - __u32 t_blocknr; /* The on-disk block number */ - __u16 t_checksum; /* truncated crc32c(uuid+seq+block) */ - __u16 t_flags; /* See below */ - __u32 t_blocknr_high; /* most-significant high 32bits. */ + __be32 t_blocknr; /* The on-disk block number */ + __be16 t_checksum; /* truncated crc32c(uuid+seq+block) */ + __be16 t_flags; /* See below */ + __be32 t_blocknr_high; /* most-significant high 32bits. */ } journal_block_tag_t; /* Tail of descriptor or revoke block, for checksumming */ @@ -177,7 +177,7 @@ struct jbd2_journal_block_tail { typedef struct journal_revoke_header_s { journal_header_t r_header; - int r_count; /* Count of bytes used in the block */ + __be32 r_count; /* Count of bytes used in the block */ } jbd2_journal_revoke_header_t; /* Definitions for the journal tag flags word: */ @@ -200,14 +200,14 @@ typedef struct journal_superblock_s /* 0x000C */ /* Static information describing the journal */ - __u32 s_blocksize; /* journal device blocksize */ - __u32 s_maxlen; /* total blocks in journal file */ - __u32 s_first; /* first block of log information */ + __be32 s_blocksize; /* journal device blocksize */ + __be32 s_maxlen; /* total blocks in journal file */ + __be32 s_first; /* first block of log information */ /* 0x0018 */ /* Dynamic information describing the current state of the log */ - __u32 s_sequence; /* first commit ID expected in log */ - __u32 s_start; /* blocknr of start of log */ + __be32 s_sequence; /* first commit ID expected in log */ + __be32 s_start; /* blocknr of start of log */ /* 0x0020 */ /* Error value, as set by journal_abort(). */ @@ -215,26 +215,26 @@ typedef struct journal_superblock_s /* 0x0024 */ /* Remaining fields are only valid in a version-2 superblock */ - __u32 s_feature_compat; /* compatible feature set */ - __u32 s_feature_incompat; /* incompatible feature set */ - __u32 s_feature_ro_compat; /* readonly-compatible feature set */ + __be32 s_feature_compat; /* compatible feature set */ + __be32 s_feature_incompat; /* incompatible feature set */ + __be32 s_feature_ro_compat; /* readonly-compatible feature set */ /* 0x0030 */ __u8 s_uuid[16]; /* 128-bit uuid for journal */ /* 0x0040 */ - __u32 s_nr_users; /* Nr of filesystems sharing log */ + __be32 s_nr_users; /* Nr of filesystems sharing log */ - __u32 s_dynsuper; /* Blocknr of dynamic superblock copy*/ + __be32 s_dynsuper; /* Blocknr of dynamic superblock copy*/ /* 0x0048 */ - __u32 s_max_transaction; /* Limit of journal blocks per trans.*/ - __u32 s_max_trans_data; /* Limit of data blocks per trans. */ + __be32 s_max_transaction; /* Limit of journal blocks per trans.*/ + __be32 s_max_trans_data; /* Limit of data blocks per trans. */ /* 0x0050 */ __u8 s_checksum_type; /* checksum type */ __u8 s_padding2[3]; - __u32 s_padding[42]; - __u32 s_checksum; /* crc32c(superblock) */ + __be32 s_padding[42]; + __be32 s_checksum; /* crc32c(superblock) */ /* 0x0100 */ __u8 s_users[JBD2_USERS_SIZE]; /* ids of all fs'es sharing the log */ -- 1.8.3.1