tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: disklabel endian issues




On 30/06/2009, at 11:47 PM, Izumi Tsutsui wrote:

(1) When byteswap should be done

For crossbuild toolchain, we can deteremine both
target's endian and host's endian at compile time.

That's a good point.

So, struct disklabel in target's endian is required only in buffers
to read from/write to a target regular file specified by `-F' option,
i.e. byteswap ops should be done only on copying disklabel between
the buffer and struct disklabel for the host to calculate parameters.

Is this right?  If so, there is no hard thing there.

Right. The actual byte swapping shouldn't be too hard.

(2) How byteswap should be done

First, the struct disklabel contains some data in char arrays,
and those members must not be swapped in the byteswap functions.

All the members that need swapping are uint16 and uint32, so that it really is just a lot of typing.

Second, we have to consider how d_checksum member should be handled.
d_checksum is calculated by XOR in uint16_t, but as noted above
not all even/odd bytes are swapped, so d_checksum must be
(re)calculated after all other non-char members are properly swapped,
and no more swap is needed for a recalculated sum.

I remembered the checksum this morning. Since it's only an XOR, we might not need to recalculate the checksum. I'm pretty sure XOR is associative and commutative.

I hope src/sys/arch/sh3/sh3/disklabel.c might help.

I'll check it out.


martin%duskware.de@localhost wrote:
And where to find/store the label ;-}

The disklabel program is built as a target specific binary, so I'm assuming that someone else has taken care of this. I also assumed that someone else had taken care of the byte swapping, so ...

(But isn't this the wrong list?)

It depends?

There isn't a tech-tools for hosted tools issues, and the toolchain is the largest hosted tool.

Cheers,
Lloyd


Home | Main Index | Thread Index | Old Index