[U-Boot] [PATCH] fat: fix unaligned errors

Remy Bohmer linux at bohmer.net
Fri Jan 2 10:32:39 CET 2009


Hello Mike,

2009/1/2 Mike Frysinger <vapier at gentoo.org>:
> From: Bryan Wu <bryan.wu at analog.com>
> A couple of buffers in the fat code are declared as an array of bytes.  But
> it is then cast up to a structure with 16bit and 32bit members.  Since GCC
> assumes structure alignment here, we have to force the buffers to be
> aligned according to the structure usage.

Just curious (because before the Christmas holidays I was also
debugging some FAT problems, and maybe this is related)
What problem/symptoms does this patch fix? How did the bug show itself?

Kind Regards,

Remy

>
> Signed-off-by: Bryan Wu <bryan.wu at analog.com>
> Signed-off-by: Mike Frysinger <vapier at gentoo.org>
> ---
>  fs/fat/fat.c |   19 +++++++++++++++----
>  1 files changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index a9dde7d..06736d9 100644
> --- a/fs/fat/fat.c
> +++ b/fs/fat/fat.c
> @@ -429,12 +429,16 @@ slot2str(dir_slot *slotptr, char *l_name, int *idx)
>
>
>  /*
> + * We need align this buffer to 16bit, cause it will be cast up to
> + * a dir_slot structure
> + */
> +__u8 get_vfatname_block[MAX_CLUSTSIZE] __attribute__ ((aligned(sizeof(__u16))));
> +/*
>  * Extract the full long filename starting at 'retdent' (which is really
>  * a slot) into 'l_name'. If successful also copy the real directory entry
>  * into 'retdent'
>  * Return 0 on success, -1 otherwise.
>  */
> -__u8    get_vfatname_block[MAX_CLUSTSIZE];
>  static int
>  get_vfatname(fsdata *mydata, int curclust, __u8 *cluster,
>             dir_entry *retdent, char *l_name)
> @@ -517,10 +521,14 @@ mkcksum(const char *str)
>
>
>  /*
> + * We need align this buffer to 32bit, cause it will be cast up to
> + * a dir_entry structure
> + */
> +__u8 get_dentfromdir_block[MAX_CLUSTSIZE] __attribute__ ((aligned(sizeof(__u32))));
> +/*
>  * Get the directory entry associated with 'filename' from the directory
>  * starting at 'startsect'
>  */
> -__u8 get_dentfromdir_block[MAX_CLUSTSIZE];
>  static dir_entry *get_dentfromdir (fsdata * mydata, int startsect,
>                                   char *filename, dir_entry * retdent,
>                                   int dols)
> @@ -725,8 +733,11 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize)
>        return -1;
>  }
>
> -
> -__u8 do_fat_read_block[MAX_CLUSTSIZE];  /* Block buffer */
> +/*
> + * We need align this buffer to 32bit, cause it will be cast up to
> + * a dir_entry structure
> + */
> +__u8 do_fat_read_block[MAX_CLUSTSIZE] __attribute__ ((aligned(sizeof(__u32))));
>  long
>  do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
>             int dols)
> --
> 1.6.0.6
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
>


More information about the U-Boot mailing list