Including <sys/disk*.h> without getting ioctl(2) defines

Marcel Moolenaar marcel at xcllnt.net
Mon Sep 26 16:06:00 UTC 2016


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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sys.diff
Type: application/octet-stream
Size: 1616 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20160926/f1ddec87/attachment.obj>


More information about the freebsd-arch mailing list