tech-toolchain archive

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

Re: disklabel endian issues



> On Tue, Jun 30, 2009 at 06:46:19PM +1200, Lloyd Parkes wrote:
> > Would anyone object if I added a couple of functions to sbin/disklabel/ 
> > main.c to byte swap the struct fields? The hard thing will be working  
> > out if byte swapping will be needed.

Well, before implementing such a function,
we have to consider the following two points as a design.


(1) When byteswap should be done

For crossbuild toolchain, we can deteremine both
target's endian and host's endian at compile time.
On the other hand, we don't have to consider more swapped labels.
(i.e. no need to read/write BE labels with LE target tools on any hosts)

Forthermore, there is nothing to do for readdisklabel(9) and
writedisklabel(9) done by the kernel via ioctl(2), because they
are not functional on generic build hosts.

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.


(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.

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 hope src/sys/arch/sh3/sh3/disklabel.c might help.

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

It's always annoying on implementing readdisklabel(9),
setdisklabel(9) and writedisklabel(9) in kernel,
but we should assume that valid disklabel should be
located at offset LABELOFFSET in the target endian
on a host tool.

> (But isn't this the wrong list?)

It depends?
---
Izumi Tsutsui


Home | Main Index | Thread Index | Old Index