[Tux3] [PATCH 03/10] Fix ileaf aligment

OGAWA Hirofumi hirofumi at mail.parknet.co.jp
Fri Oct 17 04:23:32 PDT 2008


Daniel Phillips <phillips at phunq.net> writes:

> On Friday 17 October 2008 03:45, OGAWA Hirofumi wrote:
>> Daniel Phillips <phillips at phunq.net> writes:
>> >> >> Good catch.  A better way to fix this is using gcc attribute packed,
>> >> >> which is done by the Tux3 macro PACKED:
>> >> >
>> >> > But, I think the result of it is aliment fault on some archs.
>> >> 
>> >> if we accessed ->ibase. Or we should use get_unaligned()?
>> >
>> > I think we do want to pad it just as you have done.  We do need to get
>> > unaligned in other code, the inode attributes specifically, and make
>> > sure that always works.  We also do an endian conversion every time we
>> > do this, so it is always going to be wrapped in a macro.  But I am not
>> > sure that the endian macros can handle unaligned accesses on all
>> > architectures.
>> 
>> I see. BTW, Linux has macros for it - get_unaligned_be*/_le*.
>
> According to this, attribute ((packed)) is supposed to imply unaligned:
>
>      http://www.ohse.de/uwe/articles/gcc-attributes.html#var-packed
>      "The `packed' attribute specifies that a variable or structure field
>      should have the smallest possible alignment--one byte for a
>      variable, and one bit for a field, unless you specify a larger
>      value with the `aligned' attribute."

It seems to mean it will does one byte alignment for a variable (unless
specify a ((aligned (x))) attribute.).  So, some archs which want to
natural alignment (e.g. 8 bytes alignment for u64) will generate
alignment fault.

E.g.  

struct ileaf {
/*0*/	u16 magic,
/*2*/	    count;
/*4*/	inum_t ibase;
/*12*/	char table[];
} __attribute__ ((packed));

inum_t should be aligned by 8 bytes on some arch (usually 64bit arch),
but packed will aligned by one byte like above.
-- 
OGAWA Hirofumi <hirofumi at mail.parknet.co.jp>

_______________________________________________
Tux3 mailing list
Tux3 at tux3.org
http://tux3.org/cgi-bin/mailman/listinfo/tux3



More information about the Tux3 mailing list