Subject: Re: multiple inclusion protection for kernel files
To: Christos Zoulas <christos@zoulas.com>
From: Rui Paulo <rpaulo@fnop.net>
List: tech-kern
Date: 12/03/2005 22:42:16
--EVcIhgQsEzAXu06J
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2005.12.03 16:59:35 -0500, Christos Zoulas wrote:
|=20
| Hello,
|=20
| I just made a short pass in sys/fs and sys/sys to fix multiple inclusion
| issues. Where many files followed the current standard, there were quite
| a few that did not.
|=20
| My understanding of the current rules for include files [kernel] are:
|=20
| 1. For files that get installed in /usr/include:
|    All the code in the include file is bracketed by:
|=20
|    #ifndef _[<DIR>_...]<FILENAME>_H_
|    #define _[<DIR>_...]<FILENAME>_H_
|    .... code ....
|    #endif /* _[<DIR>_...]<FILENAME>_H_ */
|=20
|    The DIR portion is the dirname portion of the path capitalized, and wi=
th
|    `/' substituted by `_'. The path is the install path of the file not t=
he
|    source path. For example:
|=20
|    src/sys/fs/cd9660/iso.h gets installed in /usr/include/isofs/cd9660/is=
o.h
|    so the file should be protected by:
|=20
|    #ifndef _ISOFS_CD9660_ISO_H_
|    #define _ISOFS_CD9660_ISO_H_
|    #endif /* _ISOFS_CD9660_ISO_H_ */
|=20
|    Files that should not be protected against multiple inclusion should m=
ention
|    this prominently as a comment immediately after the copyright notice.

Yes, I think this truly correct.


|=20
| 2. Header files that are not installed are not protected for multiple inc=
lusion
|    but they are protected against use in the userland by:
|=20
|    #ifndef _KERNEL
|    #error not supposed to be exposed to userland.
|    #endif /* _KERNEL */
|=20
|    The rationale is that we don't want to include these files multiple ti=
mes
|    accidentally, and we also don't want userland applications to include =
them
|    either.
|    Most of the kernel files do not follow this standard right now. I.e. t=
here
|    are files that are used by userland programs and not being installed, =
and
|    most files don't have the #error protection.

We can work together on fixing this.

		-- Rui Paulo

--EVcIhgQsEzAXu06J
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (NetBSD)

iD8DBQFDkh9IZPqyxs9FH4QRAtj5AKCf8MwweQBJG4Do6EH+PJi4iX0JmwCfbwFU
9pWWkJNstMRQas/5MQ0HCbI=
=TNCA
-----END PGP SIGNATURE-----

--EVcIhgQsEzAXu06J--