Discussion:
Including <sys/disk*.h> without getting ioctl(2) defines
Marcel Moolenaar
2016-09-26 16:05:51 UTC
Permalink
Background:
In order for a select set of FreeBSD utilities to compile on non-FreeBSD (specifically macOS and Linux) as build tools, we need some portability tweaks.

Problem:
mkimg(1) includes disk partitioning headers like <sys/disklabel.h>, <sys/diskmbr.h> and <sys/diskpc98.h> and those headers themselves include <sys/ioccom.h> for ioctl(2) definitions. The <sys/ioccom.h> header does not typically exist on the host we’re being, causing build failures.

Proposal:
What I like is to be able to use FreeBSD’s headers, but not pull in FreeBSD-specifics like ioctl(2) definitions.

Solutions:
1. Split off the definitions relating to the partitioning into a separate header (e.g. <sys/bsdlabel.h>) and keep the FreeBSD-centric definitions (e.g. for ioctl(2)) in the original header (e.g. <sys/disklabel.h>. The original header will include the new header so that there’s no change to applications that include the original header. Portable tools like mkimg can include the new split-off header to get just the structure definitions and defines.

2. Expect portable utilities to define a pre-processor macro (e.g. PORTABLE_DEFINITIONS_ONLY) and make FreeBSD-specific definitions conditional upon the *absence* of the preprocessor macro.

3. (Ab)use _POSIX_SOURCE to achieve the same as point 2.

4. Get rid of the utilities that still use the ioctl(2) interface and fix ports that do the same.

5. Others?

Notes:
1. Attached a hack to allow mkimg(1) to use FreeBSD’s headers for partitioning schemes. It shows what exactly the problem is without suggesting a solution. It’s a minimal change for a reason and not to be discussed as if it was a solution.

2. mkimg(1) is one example. Other utilities include makefs, mtree, etc. Please consider an approach that serves as a good precedence for other utilities if and when a similar situation is encountered.
John Baldwin
2016-09-26 16:47:12 UTC
Permalink
Post by Marcel Moolenaar
In order for a select set of FreeBSD utilities to compile on non-FreeBSD (specifically macOS and Linux) as build tools, we need some portability tweaks.
mkimg(1) includes disk partitioning headers like <sys/disklabel.h>, <sys/diskmbr.h> and <sys/diskpc98.h> and those headers themselves include <sys/ioccom.h> for ioctl(2) definitions. The <sys/ioccom.h> header does not typically exist on the host we’re being, causing build failures.
What I like is to be able to use FreeBSD’s headers, but not pull in FreeBSD-specifics like ioctl(2) definitions.
1. Split off the definitions relating to the partitioning into a separate header (e.g. <sys/bsdlabel.h>) and keep the FreeBSD-centric definitions (e.g. for ioctl(2)) in the original header (e.g. <sys/disklabel.h>. The original header will include the new header so that there’s no change to applications that include the original header. Portable tools like mkimg can include the new split-off header to get just the structure definitions and defines.
I think this. It is similar to the 'fooreg.h' vs 'foovar.h' split in some
drivers with fooreg.h generally being a standalone, portable header and
foovar.h defining FreeBSD-specific structures (softc, etc.).

I'd even be inclined to use some kind of sensible namespace for the header
names like <disk/mbr.h>, <disk/pc98.h>, <disk/bsd.h>, <disk/gpt.h>, etc.
While you are at it, please have these split out headers avoid conflicting
names unlike diskmbr.h and diskpc98.h. (We can use compat #define's in
diskmbr.h and diskpc98.h if needed to provide API compat.)
--
John Baldwin
Poul-Henning Kamp
2016-09-26 21:32:55 UTC
Permalink
--------
Post by Marcel Moolenaar
4. Get rid of the utilities that still use the ioctl(2) interface
and fix ports that do the same.
That would be the most say way: Forward.
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
***@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
Loading...