Device drivers do not usually print messages. Instead, the driver entry points should return error codes so that the application can determine how to handle the error. If the driver really needs to print a message, it can use cmn_err(9F) to do so. This is similar to the C function printf(3S), but only prints to the console, to the message buffer displayed by dmesg(1M), or both.
void cmn_err(int level, char *format, ...);
format is similar to the printf(3S) format string, with the addition of the format %b, which prints bit fields. level indicates which label will be printed, as shown in Table 3-1.
Table 3-1 cmn_err() Messages
Level |
Message |
---|---|
CE_NOTE |
NOTICE: format\n |
CE_WARN |
WARNING:format\n |
CE_CONT |
format |
CE_PANIC |
panic: format\n |
CE_PANIC has the side effect of crashing the system. This level should only be used if the system is in such an unstable state that to continue would cause more problems. It can also be used to get a system core dump when debugging.
The first character of the format string is treated specially. See cmn_err(9F) for more details.