From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Subject: [PATCH 1/7] e2fsck: make recovery.c identical with kernel
Date: Thu, 19 Mar 2020 16:34:27 -0700 [thread overview]
Message-ID: <20200319233433.117144-2-harshadshirwadkar@gmail.com> (raw)
In-Reply-To: <20200319233433.117144-1-harshadshirwadkar@gmail.com>
Add endianness conversion macros identical to Kernel and fix differences
between Kernel's and e2fsprogs's recovery.c to make them identical.
Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
---
e2fsck/jfs_user.h | 9 +++++++++
e2fsck/recovery.c | 46 ++++++++++++----------------------------------
2 files changed, 21 insertions(+), 34 deletions(-)
diff --git a/e2fsck/jfs_user.h b/e2fsck/jfs_user.h
index a97fcc18..62a3e8a8 100644
--- a/e2fsck/jfs_user.h
+++ b/e2fsck/jfs_user.h
@@ -267,4 +267,13 @@ extern int jbd2_journal_set_revoke(journal_t *, unsigned long long, tid_t);
extern int jbd2_journal_test_revoke(journal_t *, unsigned long long, tid_t);
extern void jbd2_journal_clear_revoke(journal_t *);
+/* Macros for kernel compatibility */
+#define be32_to_cpu(x) ext2fs_be32_to_cpu(x)
+#define cpu_to_be32(x) ext2fs_cpu_to_be32(x)
+#define cpu_to_be16(x) ext2fs_cpu_to_be16(x)
+#define le16_to_cpu(x) ext2fs_le16_to_cpu(x)
+#define le32_to_cpu(x) ext2fs_le32_to_cpu(x)
+
+#define pr_warn(...)
+
#endif /* _JFS_USER_H */
diff --git a/e2fsck/recovery.c b/e2fsck/recovery.c
index 5df690ad..4750f9c1 100644
--- a/e2fsck/recovery.c
+++ b/e2fsck/recovery.c
@@ -121,27 +121,6 @@ failed:
#endif /* __KERNEL__ */
-static inline __u32 get_be32(__be32 *p)
-{
- unsigned char *cp = (unsigned char *) p;
- __u32 ret;
-
- ret = *cp++;
- ret = (ret << 8) + *cp++;
- ret = (ret << 8) + *cp++;
- ret = (ret << 8) + *cp++;
- return ret;
-}
-
-static inline __u16 get_be16(__be16 *p)
-{
- unsigned char *cp = (unsigned char *) p;
- __u16 ret;
-
- ret = *cp++;
- ret = (ret << 8) + *cp++;
- return ret;
-}
/*
* Read a block from the journal
@@ -201,7 +180,7 @@ static int jbd2_descriptor_block_csum_verify(journal_t *j, void *buf)
if (!jbd2_journal_has_csum_v2or3(j))
return 1;
- tail = (struct jbd2_journal_block_tail *)((char *)buf + j->j_blocksize -
+ tail = (struct jbd2_journal_block_tail *)(buf + j->j_blocksize -
sizeof(struct jbd2_journal_block_tail));
provided = tail->t_checksum;
tail->t_checksum = 0;
@@ -232,10 +211,10 @@ static int count_tags(journal_t *journal, struct buffer_head *bh)
nr++;
tagp += tag_bytes;
- if (!(get_be16(&tag->t_flags) & JBD2_FLAG_SAME_UUID))
+ if (!(tag->t_flags & cpu_to_be16(JBD2_FLAG_SAME_UUID)))
tagp += 16;
- if (get_be16(&tag->t_flags) & JBD2_FLAG_LAST_TAG)
+ if (tag->t_flags & cpu_to_be16(JBD2_FLAG_LAST_TAG))
break;
}
@@ -358,9 +337,9 @@ int jbd2_journal_skip_recovery(journal_t *journal)
static inline unsigned long long read_tag_block(journal_t *journal,
journal_block_tag_t *tag)
{
- unsigned long long block = get_be32(&tag->t_blocknr);
+ unsigned long long block = be32_to_cpu(tag->t_blocknr);
if (jbd2_has_feature_64bit(journal))
- block |= (u64)get_be32(&tag->t_blocknr_high) << 32;
+ block |= (u64)be32_to_cpu(tag->t_blocknr_high) << 32;
return block;
}
@@ -429,9 +408,9 @@ static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag,
csum32 = jbd2_chksum(j, csum32, buf, j->j_blocksize);
if (jbd2_has_feature_csum3(j))
- return get_be32(&tag3->t_checksum) == csum32;
-
- return get_be16(&tag->t_checksum) == (csum32 & 0xFFFF);
+ return tag3->t_checksum == cpu_to_be32(csum32);
+ else
+ return tag->t_checksum == cpu_to_be16(csum32);
}
static int do_one_pass(journal_t *journal,
@@ -579,7 +558,7 @@ static int do_one_pass(journal_t *journal,
unsigned long io_block;
tag = (journal_block_tag_t *) tagp;
- flags = get_be16(&tag->t_flags);
+ flags = be16_to_cpu(tag->t_flags);
io_block = next_log_block++;
wrap(journal, next_log_block);
@@ -643,9 +622,8 @@ 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 = cpu_to_be32(JBD2_MAGIC_NUMBER);
- memcpy(nbh->b_data, &magic,
- sizeof(magic));
+ *((__be32 *)nbh->b_data) =
+ cpu_to_be32(JBD2_MAGIC_NUMBER);
}
BUFFER_TRACE(nbh, "marking dirty");
@@ -833,7 +811,7 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
{
jbd2_journal_revoke_header_t *header;
int offset, max;
- unsigned csum_size = 0;
+ int csum_size = 0;
__u32 rcount;
int record_len = 4;
--
2.25.1.696.g5e7596f4ac-goog
next prev parent reply other threads:[~2020-03-19 23:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-19 23:34 [PATCH 0/7] e2fsck: fast commit recovery path e2fsck changes Harshad Shirwadkar
2020-03-19 23:34 ` Harshad Shirwadkar [this message]
2020-03-19 23:34 ` [PATCH 2/7] e2fsck: allow rewriting extents of a file Harshad Shirwadkar
2020-03-19 23:34 ` [PATCH 3/7] ext2fs: make ext2fs_calculate_summary_stats() visible Harshad Shirwadkar
2020-03-19 23:34 ` [PATCH 4/7] e2fsck/jbd2: add fast commit feature in jbd2 Harshad Shirwadkar
2020-03-19 23:34 ` [PATCH 5/7] e2fsck/jbd2: fast commit recovery changes Harshad Shirwadkar
2020-03-19 23:34 ` [PATCH 6/7] e2fsck: main fast commit replay handler Harshad Shirwadkar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200319233433.117144-2-harshadshirwadkar@gmail.com \
--to=harshadshirwadkar@gmail.com \
--cc=linux-ext4@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).