Re: le32_to_cpu() help...

Jakub Jelinek (jakub@redhat.com)
Tue, 2 Nov 1999 11:45:22 +0100


On Wed, Nov 03, 1999 at 02:31:09AM +0800, dony wrote:
> On Tue, 02 Nov 1999, Jes Sorensen wrote:
> > >>>>> "dony" == dony <dony.he@huawei.com.cn> writes:
> >
> > dony> Hi,
> >
> > dony> What role does le32_to_cpu() or cpu_to_le32() play in
> > dony> kernel? Why do we need these two functions? They seem to
> > dony> translate a value from big-endian to little-endian or vice
> > dony> versa, but I don't know why we need do this. Thanks.
> >
> > They translate data to little endian from big endian on big endian
> > CPUs, on little endian CPUs like the x86 they are noops. We need these
> > because some hardware and other things like file systems wants data in
> > little endian order no matter what type of system you are running on.
> >
>
> Then when do we use le32_to_cpu( ) , and when do we use cpu_to_le32( )?

The names tell it. le32_to_cpu is used for convesions from 32bit little
endian data into CPUs endianness, cpu_to_le32 is used for convesions from
CPU endianness to little endian 32bit data.
Actually, both macros do the same thing, but one should make the differences
clear to make code more readable so that anyone can quickly find out whether
some data is kept in native endianness or some particular one.

Cheers,
Jakub
___________________________________________________________________
Jakub Jelinek | jakub@redhat.com | http://sunsite.mff.cuni.cz/~jj
Linux version 2.3.18 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/