xref: /netbsd-src/share/man/man9/kprintf.9 (revision 46f5119e40af2e51998f686b2fdcc76b5488f7f3)
1.\"     $NetBSD: kprintf.9,v 1.30 2011/01/21 17:51:19 dyoung Exp $
2.\"
3.\" Copyright (c) 1998, 2002, 2007, 2011 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jeremy Cooper and by Jason R. Thorpe.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd January 21, 2011
31.Dt KPRINTF 9
32.Os
33.Sh NAME
34.Nm device_printf ,
35.Nm printf ,
36.Nm snprintf ,
37.Nm vprintf ,
38.Nm vsnprintf ,
39.Nm uprintf ,
40.Nm ttyprintf ,
41.Nm tprintf ,
42.Nm aprint
43.Nd kernel formatted output conversion
44.Sh SYNOPSIS
45.In sys/systm.h
46.Ft void
47.Fn "device_printf" "device_t" "const char *format" "..."
48.Ft void
49.Fn "printf" "const char *format" "..."
50.Ft void
51.Fn "printf_nolog" "const char *format" "..."
52.Ft int
53.Fn "snprintf" "char *buf" "size_t size" "const char *format" "..."
54.In machine/stdarg.h
55.Ft void
56.Fn "vprintf" "const char *format" "va_list ap"
57.Ft int
58.Fn "vsnprintf" "char *buf" "size_t size" "const char *format" "va_list ap"
59.Ft void
60.Fn "uprintf" "const char *format" "..."
61.Ft void
62.Fn "ttyprintf" "struct tty *tty" "const char *format" "..."
63.In sys/tprintf.h
64.Ft tpr_t
65.Fn "tprintf_open" "struct proc *p"
66.Ft void
67.Fn "tprintf" "tpr_t tpr" "const char *format" "..."
68.Ft void
69.Fn "tprintf_close" "tpr_t tpr"
70.Ft void
71.Fn "aprint_normal" "const char *format" "..."
72.Ft void
73.Fn "aprint_naive" "const char *format" "..."
74.Ft void
75.Fn "aprint_verbose" "const char *format" "..."
76.Ft void
77.Fn "aprint_debug" "const char *format" "..."
78.Ft void
79.Fn "aprint_error" "const char *format" "..."
80.Ft void
81.Fn "aprint_normal_dev" "device_t" "const char *format" "..."
82.Ft void
83.Fn "aprint_naive_dev" "device_t" "const char *format" "..."
84.Ft void
85.Fn "aprint_verbose_dev" "device_t" "const char *format" "..."
86.Ft void
87.Fn "aprint_debug_dev" "device_t" "const char *format" "..."
88.Ft void
89.Fn "aprint_error_dev" "device_t" "const char *format" "..."
90.Ft void
91.Fn "aprint_normal_ifnet" "struct ifnet *" "const char *format" "..."
92.Ft void
93.Fn "aprint_naive_ifnet" "struct ifnet *" "const char *format" "..."
94.Ft void
95.Fn "aprint_verbose_ifnet" "struct ifnet *" "const char *format" "..."
96.Ft void
97.Fn "aprint_debug_ifnet" "struct ifnet *" "const char *format" "..."
98.Ft void
99.Fn "aprint_error_ifnet" "struct ifnet *" "const char *format" "..."
100.Ft int
101.Fn "aprint_get_error_count" "void"
102.Sh DESCRIPTION
103The
104.Fn printf
105family of functions allows the kernel to send formatted messages to various
106output devices.
107The functions
108.Fn printf
109and
110.Fn vprintf
111send formatted strings to the system console.
112The
113.Fn device_printf
114function is identical to
115.Fn printf ,
116except that it prefixes the log message with the corresponding
117device name.
118The
119.Fn printf_nolog
120function is identical to
121.Fn printf ,
122except it does not send the data to the system log.
123The functions
124.Fn snprintf
125and
126.Fn vsnprintf
127write output to a string buffer.
128These four functions work similarly to their user space counterparts,
129and are not described in detail here.
130.Pp
131The functions
132.Fn uprintf
133and
134.Fn ttyprintf
135send formatted strings to the current process's controlling tty and a specific
136tty, respectively.
137.Pp
138The
139.Fn tprintf
140function sends formatted strings to a process's controlling tty,
141via a handle of type tpr_t.
142This allows multiple write operations to the tty with a guarantee that the
143tty will be valid across calls.
144A handle is acquired by calling
145.Fn tprintf_open
146with the target process as an argument.
147This handle must be closed with a matching call to
148.Fn tprintf_close .
149.Pp
150The functions
151.Fn aprint_normal ,
152.Fn aprint_naive ,
153.Fn aprint_verbose ,
154.Fn aprint_debug ,
155and
156.Fn aprint_error
157are intended to be used to print
158.Xr autoconf 9
159messages.
160Their verbosity depends on flags set in the
161.Va boothowto
162variable, through options passed during bootstrap; see
163.Xr boothowto 9
164and
165.Sx Interactive mode
166in
167.Xr boot 8 :
168.Bl -tag -width AB_VERBOSE
169.It Dv AB_SILENT
170silent mode, enabled by
171.Ic boot
172.Fl z .
173.It Dv AB_QUIET
174quiet mode, enabled by
175.Ic boot
176.Fl q .
177.It Dv AB_VERBOSE
178verbose mode, enabled by
179.Ic boot
180.Fl v .
181.It Dv AB_DEBUG
182debug mode, enabled by
183.Ic boot
184.Fl x .
185.El
186.Pp
187The
188.Fn aprint_*
189functions have the following behaviour, based on the above
190mentioned flags:
191.Bl -tag -width Xaprint_verboseXXX
192.It Fn aprint_normal
193Sends to the console unless
194.Dv AB_QUIET
195is set.
196Always sends to the log.
197.It Fn aprint_naive
198Sends to the console only if
199.Dv AB_QUIET
200is set.
201Never sends to the log.
202.It Fn aprint_verbose
203Sends to the console only if
204.Dv AB_VERBOSE
205is set.
206Always sends to the log.
207.It Fn aprint_debug
208Sends to the console and the log only if
209.Dv AB_DEBUG
210is set.
211.It Fn aprint_error
212Like
213.Fn aprint_normal ,
214but also keeps track of the number of times called.
215This allows a subsystem to report the number of errors that occurred
216during a quiet or silent initialization phase.
217.El
218.Pp
219For the
220.Fn aprint_*
221functions there are two additional families of functions with the
222suffixes
223.Dv _dev
224and
225.Dv _ifnet
226which work like their counterparts without the suffixes, except that
227they take a
228.Ft device_t
229and
230.Ft struct ifnet * ,
231respectively, as first argument,
232and prefix the log message with the
233corresponding device or interface name.
234.Pp
235The
236.Fn aprint_get_error_count
237function reports the number of errors and resets the counter to 0.
238.Pp
239If
240.Dv AB_SILENT
241is set, none of the autoconfiguration message printing routines send output
242to the console.
243The
244.Dv AB_VERBOSE
245and
246.Dv AB_DEBUG
247flags override
248.Dv AB_SILENT .
249.Sh RETURN VALUES
250The
251.Fn snprintf
252and
253.Fn vsnprintf
254functions return the number of characters placed in the buffer
255.Fa buf .
256This is different to the user-space functions of the same name.
257.Pp
258The
259.Fn tprintf_open
260function returns
261.Dv NULL
262if no terminal handle could be acquired.
263.Sh SEE ALSO
264.Xr printf 1 ,
265.Xr printf 3 ,
266.Xr snprintb 3 ,
267.Xr boot 8 ,
268.Xr autoconf 9 ,
269.Xr boothowto 9
270.Sh CODE REFERENCES
271.Pa sys/kern/subr_prf.c
272.Sh HISTORY
273The
274.Fn sprintf
275and
276.Fn vsprintf
277unsized string formatting functions are supported for compatibility only,
278and are not documented here.
279New code should use the size-limited
280.Fn snprintf
281and
282.Fn vsnprintf
283functions instead.
284.Pp
285In
286.Nx 1.5
287and earlier,
288.Fn printf
289supported more format strings than the user space
290.Fn printf .
291These nonstandard format strings are no longer supported.
292For the functionality provided by the former
293.Li %b
294format string, see
295.Xr snprintb 3 .
296.Pp
297The
298.Fn aprint_normal ,
299.Fn aprint_naive ,
300.Fn aprint_verbose ,
301and
302.Fn aprint_debug
303functions first appeared in
304.Bsx .
305.Sh BUGS
306The
307.Fn uprintf
308and
309.Fn ttyprintf
310functions should be used sparingly, if at all.
311Where multiple lines of output are required to reach a process's
312controlling terminal,
313.Fn tprintf
314is preferred.
315