[U-Boot] [PATCH v3 3/4] ext4: fix endianess problems in ext4 write support

Michael Walle michael at walle.cc
Wed Aug 31 16:17:10 CEST 2016



Am 2016-08-29 10:46, schrieb Michael Walle:
[..snip..]

> @@ -149,10 +169,10 @@ static void delete_double_indirect_block(struct
> ext2_inode *inode)
>  	int i;
>  	short status;
>  	static int prev_bg_bmap_idx = -1;
> -	long int blknr;
> +	uint32_t blknr;
>  	int remainder;
>  	int bg_idx;
> -	unsigned int blk_per_grp = ext4fs_root->sblock.blocks_per_group;
> +	uint32_t blk_per_grp = 
> le32_to_cpu(ext4fs_root->sblock.blocks_per_group);
>  	unsigned int *di_buffer = NULL;

This has to be __le32 *di_buffer. Therefore, there are still some 
le32_to_cpu() calls missing. I'll send a new version tomorrow.
This was found by Thomas Schäfer. Thanks.

>  	unsigned int *DIB_start_addr = NULL;
>  	struct ext2_block_group *bgd = NULL;
> @@ -172,7 +192,7 @@ static void delete_double_indirect_block(struct
> ext2_inode *inode)
>  			return;
>  		}
>  		DIB_start_addr = (unsigned int *)di_buffer;
> -		blknr = inode->b.blocks.double_indir_block;
> +		blknr = le32_to_cpu(inode->b.blocks.double_indir_block);
>  		status = ext4fs_devread((lbaint_t)blknr * fs->sect_perblk, 0,
>  					fs->blksz, (char *)di_buffer);
>  		for (i = 0; i < fs->blksz / sizeof(int); i++) {
> @@ -189,12 +209,12 @@ static void delete_double_indirect_block(struct
> ext2_inode *inode)
>  			ext4fs_reset_block_bmap(*di_buffer,
>  					fs->blk_bmaps[bg_idx], bg_idx);
>  			di_buffer++;
> -			bgd[bg_idx].free_blocks++;
> -			fs->sb->free_blocks++;
> +			ext4fs_bg_free_blocks_inc(&bgd[bg_idx]);
> +			ext4fs_sb_free_blocks_inc(fs->sb);
>  			/* journal backup */
>  			if (prev_bg_bmap_idx != bg_idx) {
> -				status = ext4fs_devread((lbaint_t)
> -							bgd[bg_idx].block_id
> +				status = ext4fs_devread(
> +							(lbaint_t)le32_to_cpu(bgd[bg_idx].block_id)
>  							* fs->sect_perblk, 0,
>  							fs->blksz,
>  							journal_buffer);
> @@ -202,14 +222,14 @@ static void delete_double_indirect_block(struct
> ext2_inode *inode)
>  					goto fail;
> 
>  				if (ext4fs_log_journal(journal_buffer,
> -							bgd[bg_idx].block_id))
> +							le32_to_cpu(bgd[bg_idx].block_id)))
>  					goto fail;
>  				prev_bg_bmap_idx = bg_idx;
>  			}
>  		}
> 
>  		/* removing the parent double indirect block */
> -		blknr = inode->b.blocks.double_indir_block;
> +		blknr = le32_to_cpu(inode->b.blocks.double_indir_block);
>  		bg_idx = blknr / blk_per_grp;
>  		if (fs->blksz == 1024) {
>  			remainder = blknr % blk_per_grp;
> @@ -217,23 +237,23 @@ static void delete_double_indirect_block(struct
> ext2_inode *inode)
>  				bg_idx--;
>  		}
>  		ext4fs_reset_block_bmap(blknr, fs->blk_bmaps[bg_idx], bg_idx);
> -		bgd[bg_idx].free_blocks++;
> -		fs->sb->free_blocks++;
> +		ext4fs_bg_free_blocks_inc(&bgd[bg_idx]);
> +		ext4fs_sb_free_blocks_inc(fs->sb);
>  		/* journal backup */
>  		if (prev_bg_bmap_idx != bg_idx) {
>  			memset(journal_buffer, '\0', fs->blksz);
> -			status = ext4fs_devread((lbaint_t)bgd[bg_idx].block_id *
> +			status = ext4fs_devread((lbaint_t)le32_to_cpu(bgd[bg_idx].block_id) 
> *
>  						fs->sect_perblk, 0, fs->blksz,
>  						journal_buffer);
>  			if (status == 0)
>  				goto fail;
> 
>  			if (ext4fs_log_journal(journal_buffer,
> -						bgd[bg_idx].block_id))
> +						le32_to_cpu(bgd[bg_idx].block_id)))
>  				goto fail;
>  			prev_bg_bmap_idx = bg_idx;
>  		}
> -		debug("DIPB releasing %ld\n", blknr);
> +		debug("DIPB releasing %d\n", blknr);
>  	}
>  fail:
>  	free(DIB_start_addr);
> @@ -245,10 +265,10 @@ static void delete_triple_indirect_block(struct
> ext2_inode *inode)
>  	int i, j;
>  	short status;
>  	static int prev_bg_bmap_idx = -1;
> -	long int blknr;
> +	uint32_t blknr;
>  	int remainder;
>  	int bg_idx;
> -	unsigned int blk_per_grp = ext4fs_root->sblock.blocks_per_group;
> +	uint32_t blk_per_grp = 
> le32_to_cpu(ext4fs_root->sblock.blocks_per_group);
>  	unsigned int *tigp_buffer = NULL;
likewise

>  	unsigned int *tib_start_addr = NULL;
>  	unsigned int *tip_buffer = NULL;
likewise

[..snip..]

-michael


More information about the U-Boot mailing list