Date: Tue, 29 Aug 2017 12:41:21 -0700 From: John Baldwin <jhb@freebsd.org> To: Maxim Sobolev <sobomax@sippysoft.com> Cc: Ryan Libby <rlibby@freebsd.org>, svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers <src-committers@freebsd.org> Subject: Re: svn commit: r322969 - in head: sbin/mdconfig sys/dev/md sys/sys Message-ID: <5654024.G33lbUi2LU@ralph.baldwin.cx> In-Reply-To: <CAH7qZfvGL-UgZX5VzZXB%2B6zPznA9-GvEg%2B=X2roiTSUUj5jxSA@mail.gmail.com> References: <201708281554.v7SFs8fr014268@repo.freebsd.org> <6350259.n2rmZ9RnEY@ralph.baldwin.cx> <CAH7qZfvGL-UgZX5VzZXB%2B6zPznA9-GvEg%2B=X2roiTSUUj5jxSA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday, August 29, 2017 12:18:18 PM Maxim Sobolev wrote:
> John, OK, maybe you are right and the current status quo was just an
> accident. I am curious what do you and other people think about expressing
> expected structure size and padding more explicitly instead of trying to
> accommodate for sometimes intricate play between alignment and type size
> with something like char[N]? I.e. along the following lines:
>
> #if __WORDSIZE < 64
Use #ifdef __LP64__
> #define MD_IOCTL_LEN 436
> #else
> #define MD_IOCTL_LEN 448
> #endif
>
> struct md_ioctl {
> union {
> struct _md_ioctl_payload {
> unsigned version; /* Structure layout version */
> unsigned unit; /* unit number */
> enum md_types type ; /* type of disk */
> char *file; /* pathname of file to mount */
> off_t mediasize; /* size of disk in bytes */
> unsigned sectorsize; /* sectorsize */
> unsigned options; /* options */
> u_int64_t base; /* base address */
> int fwheads; /* firmware heads */
> int fwsectors; /* firmware sectors */
> char *label; /* label of the device */
> } md;
> char raw[MD_IOCTL_LEN]; /* payload + padding for future ideas */
> };
> };
> CTASSERT(sizeof(struct md_ioctl) == MD_IOCTL_LEN);
This is not the style we use in other structures in FreeBSD. Simply making
the existing MDNPAD depend on the #ifdef would be more consistent. For a
really good example of how to handle padding, see kinfo_proc which has
separate "spare" arrays for int, long, void *, and char.
--
John Baldwin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5654024.G33lbUi2LU>
