[Ocfs2-tools-devel] [PATCH] Fix directory entry handling in big endian archs

Sunil Mushran sunil.mushran at oracle.com
Fri Dec 9 13:28:58 PST 2011


Thanks. I'll check it in.

On 12/08/2011 05:40 PM, Goldwyn Rodrigues wrote:
> dir_trailer_func() and ocfs2_dx_dir_search() reads the dir blocks directly
> instead of using ocfs2_read_dir_block(). It does not swap the directory
> entries before using. Fix.
>
> Also, use the correct function for swapping some of directory structure
> variables.
>
> Signed-off-by: Goldwyn Rodrigues<rgoldwyn at suse.de>
> Signed-off-by: Mark Fasheh<mfasheh at suse.com>
> ---
> diff --git a/libocfs2/dir_indexed.c b/libocfs2/dir_indexed.c
> index 12a5620..cdea72d 100644
> --- a/libocfs2/dir_indexed.c
> +++ b/libocfs2/dir_indexed.c
> @@ -186,6 +186,7 @@ static int dir_trailer_func(ocfs2_filesys *fs,
>   		ret = OCFS2_EXTENT_ERROR;
>   		goto out;
>   	}
> +	ocfs2_swap_dir_entries_to_cpu(blk, fs->fs_blocksize);
>
>   	err = ocfs2_check_dir_trailer_space(fs, di, blkno, blk);
>   	if (err) {
> @@ -1454,6 +1455,7 @@ errcode_t ocfs2_dx_dir_search(ocfs2_filesys *fs,
>   		ret = ocfs2_read_blocks(fs, dx_entry->dx_dirent_blk, 1, dir_buf);
>   		if (ret)
>   			goto out;
> +		ocfs2_swap_dir_entries_to_cpu(dir_buf, fs->fs_blocksize);
>
>   		found = ocfs2_search_dirblock(fs, dir_buf, name, namelen,
>   						fs->fs_blocksize,&dir_ent);
> diff --git a/libocfs2/dirblock.c b/libocfs2/dirblock.c
> index bc60a26..52ac78f 100644
> --- a/libocfs2/dirblock.c
> +++ b/libocfs2/dirblock.c
> @@ -137,7 +137,6 @@ static errcode_t
> ocfs2_swap_dir_entries_direction(void *buf, uint64_t bytes,
>
>   		if (((name_len&  0xFF) + 12)>  rec_len)
>   			retval = OCFS2_ET_DIR_CORRUPTED;
> -
>   		p += rec_len;
>   	}
>   	return retval;
> @@ -158,7 +157,7 @@ void ocfs2_swap_dir_trailer(struct
> ocfs2_dir_block_trailer *trailer)
>   		return;
>
>   	trailer->db_compat_inode = bswap_64(trailer->db_compat_inode);
> -	trailer->db_compat_rec_len = bswap_64(trailer->db_compat_rec_len);
> +	trailer->db_compat_rec_len = bswap_16(trailer->db_compat_rec_len);
>   	trailer->db_blkno = bswap_64(trailer->db_blkno);
>   	trailer->db_parent_dinode = bswap_64(trailer->db_parent_dinode);
>   	trailer->db_free_rec_len = bswap_16(trailer->db_free_rec_len);
> @@ -192,7 +191,7 @@ errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs,
> struct ocfs2_dinode *di,
>   	}
>
>   	retval = ocfs2_swap_dir_entries_to_cpu(buf, end);
> -	if (!retval)
> +	if (retval)
>   		goto out;
>
>   	if (trailer)
> @@ -392,7 +391,7 @@ void ocfs2_swap_dx_leaf_to_cpu(struct
> ocfs2_dx_leaf *dx_leaf)
>   	if (cpu_is_little_endian)
>   		return;
>   	dx_leaf->dl_blkno = bswap_64(dx_leaf->dl_blkno);
> -	dx_leaf->dl_fs_generation = bswap_64(dx_leaf->dl_fs_generation);
> +	dx_leaf->dl_fs_generation = bswap_32(dx_leaf->dl_fs_generation);
>   	ocfs2_swap_dx_entry_list_to_cpu(&dx_leaf->dl_list);
>   }
>
> @@ -401,7 +400,7 @@ void ocfs2_swap_dx_leaf_from_cpu(struct
> ocfs2_dx_leaf *dx_leaf)
>   	if (cpu_is_little_endian)
>   		return;
>   	dx_leaf->dl_blkno = bswap_64(dx_leaf->dl_blkno);
> -	dx_leaf->dl_fs_generation = bswap_64(dx_leaf->dl_fs_generation);
> +	dx_leaf->dl_fs_generation = bswap_32(dx_leaf->dl_fs_generation);
>   	ocfs2_swap_dx_entry_list_from_cpu(&dx_leaf->dl_list);
>   }




More information about the Ocfs2-tools-devel mailing list