Subject: multiple inclusion protection for kernel files
To: None <tech-kern@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: tech-kern
Date: 12/03/2005 16:59:35
Hello,

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.

My understanding of the current rules for include files [kernel] are:

1. For files that get installed in /usr/include:
   All the code in the include file is bracketed by:

   #ifndef _[<DIR>_...]<FILENAME>_H_
   #define _[<DIR>_...]<FILENAME>_H_
   .... code ....
   #endif /* _[<DIR>_...]<FILENAME>_H_ */

   The DIR portion is the dirname portion of the path capitalized, and with
   `/' substituted by `_'. The path is the install path of the file not the
   source path. For example:

   src/sys/fs/cd9660/iso.h gets installed in /usr/include/isofs/cd9660/iso.h
   so the file should be protected by:

   #ifndef _ISOFS_CD9660_ISO_H_
   #define _ISOFS_CD9660_ISO_H_
   #endif /* _ISOFS_CD9660_ISO_H_ */

   Files that should not be protected against multiple inclusion should mention
   this prominently as a comment immediately after the copyright notice.

2. Header files that are not installed are not protected for multiple inclusion
   but they are protected against use in the userland by:

   #ifndef _KERNEL
   #error not supposed to be exposed to userland.
   #endif /* _KERNEL */

   The rationale is that we don't want to include these files multiple times
   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. there
   are files that are used by userland programs and not being installed, and
   most files don't have the #error protection.

Comments?

christos