Subject: Re: Alignment issue in msdosfs - bpb.h
To: John Hayward <John.C.Hayward@wheaton.edu>
From: Chris G. Demetriou <cgd@sibyte.com>
List: current-users
Date: 03/21/2001 11:29:03
John.C.Hayward@wheaton.edu (John Hayward) writes:
> Dear NetBSDers,
>    I am running on a NetBSD-1.5 i386 port - the question below may
> apply to other ports.
>    I am trying to write a utility to extract some info from a msdos file
> system.  In the boot parameter block header file
> (/usr/include/msdosfs/bpb.h) we find two versions of bpb for Fat32.
> One starts out like:
> ====
> /*
>  * BPB for DOS 7.10 (FAT32).  This one has a few extensions to bpb50.
>  */
> struct bpb710 {
>         u_int16_t       bpbBytesPerSec; /* bytes per sector */
>         u_int8_t        bpbSecPerClust; /* sectors per cluster */
>         u_int16_t       bpbResSectors;  /* number of reserved sectors */
>         u_int8_t        bpbFATs;        /* number of FATs */
> ====
> The other like:
> ====
> /*
>  * BPB for DOS 7.10 (FAT32).  This one has a few extensions to bpb50.
>  */
> struct byte_bpb710 {
>         u_int8_t bpbBytesPerSec[2];     /* bytes per sector */
>         u_int8_t bpbSecPerClust;        /* sectors per cluster */
>         u_int8_t bpbResSectors[2];      /* number of reserved sectors */
>         u_int8_t bpbFATs;               /* number of FATs */

Really, the first set of structures (the non-byte_* ones should
probably be nuked).

They're just not portable, and people shouldn't be using them except
as in-memory representations of the BPBs... if the they're going to
use them only as in-memory representations, the fields should be
shuffled so that they don't waste so much space in padding.  8-)

If you really must use them, then the packed attribute (as has been
already suggested) can be used.


chris