ext4: fix endianess problems in ext4 write support
All fields were accessed directly instead of using the proper byte swap
functions. Thus, ext4 write support was only usable on little-endian
architectures. Fix this.
Signed-off-by: Michael Walle <michael@walle.cc>
diff --git a/fs/ext4/ext4_journal.c b/fs/ext4/ext4_journal.c
index 3f61335..cf14049 100644
--- a/fs/ext4/ext4_journal.c
+++ b/fs/ext4/ext4_journal.c
@@ -151,7 +151,7 @@
* journal_buffer -- Buffer containing meta data
* blknr -- Block number on disk of the meta data buffer
*/
-int ext4fs_log_journal(char *journal_buffer, long int blknr)
+int ext4fs_log_journal(char *journal_buffer, uint32_t blknr)
{
struct ext_filesystem *fs = get_fs();
short i;
@@ -183,7 +183,7 @@
* metadata_buffer -- Buffer containing meta data
* blknr -- Block number on disk of the meta data buffer
*/
-int ext4fs_put_metadata(char *metadata_buffer, long int blknr)
+int ext4fs_put_metadata(char *metadata_buffer, uint32_t blknr)
{
struct ext_filesystem *fs = get_fs();
if (!metadata_buffer) {
@@ -215,7 +215,7 @@
printf("total bytes %d\n", max);
while (offset < max) {
- blocknr = be32_to_cpu(*((long int *)(revk_blk + offset)));
+ blocknr = be32_to_cpu(*((__be32 *)(revk_blk + offset)));
printf("revoke blknr is %ld\n", blocknr);
offset += 4;
}
@@ -302,7 +302,7 @@
max = be32_to_cpu(header->r_count);
while (offset < max) {
- blocknr = be32_to_cpu(*((long int *)
+ blocknr = be32_to_cpu(*((__be32 *)
(revk_blk + offset)));
if (blocknr == blknr)
goto found;
@@ -420,7 +420,7 @@
temp_buff);
jsb = (struct journal_superblock_t *) temp_buff;
- if (fs->sb->feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) {
+ if (le32_to_cpu(fs->sb->feature_incompat) & EXT3_FEATURE_INCOMPAT_RECOVER) {
if (recovery_flag == RECOVER)
printf("Recovery required\n");
} else {
@@ -517,11 +517,14 @@
end:
if (recovery_flag == RECOVER) {
+ uint32_t new_feature_incompat;
jsb->s_start = cpu_to_be32(1);
jsb->s_sequence = cpu_to_be32(be32_to_cpu(jsb->s_sequence) + 1);
/* get the superblock */
ext4_read_superblock((char *)fs->sb);
- fs->sb->feature_incompat |= EXT3_FEATURE_INCOMPAT_RECOVER;
+ new_feature_incompat = le32_to_cpu(fs->sb->feature_incompat);
+ new_feature_incompat |= EXT3_FEATURE_INCOMPAT_RECOVER;
+ fs->sb->feature_incompat = cpu_to_le32(new_feature_incompat);
/* Update the super block */
put_ext4((uint64_t) (SUPERBLOCK_SIZE),