xref: /netbsd-src/share/man/man9/kprintf.9 (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1.\"     $NetBSD: kprintf.9,v 1.29 2010/02/17 22:04:14 cnst Exp $
2.\"
3.\" Copyright (c) 1998, 2002, 2007 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 September 4, 2009
31.Dt KPRINTF 9
32.Os
33.Sh NAME
34.Nm printf ,
35.Nm snprintf ,
36.Nm vprintf ,
37.Nm vsnprintf ,
38.Nm uprintf ,
39.Nm ttyprintf ,
40.Nm tprintf ,
41.Nm aprint
42.Nd kernel formatted output conversion
43.Sh SYNOPSIS
44.In sys/systm.h
45.Ft void
46.Fn "printf" "const char *format" "..."
47.Ft void
48.Fn "printf_nolog" "const char *format" "..."
49.Ft int
50.Fn "snprintf" "char *buf" "size_t size" "const char *format" "..."
51.In machine/stdarg.h
52.Ft void
53.Fn "vprintf" "const char *format" "va_list ap"
54.Ft int
55.Fn "vsnprintf" "char *buf" "size_t size" "const char *format" "va_list ap"
56.Ft void
57.Fn "uprintf" "const char *format" "..."
58.Ft void
59.Fn "ttyprintf" "struct tty *tty" "const char *format" "..."
60.In sys/tprintf.h
61.Ft tpr_t
62.Fn "tprintf_open" "struct proc *p"
63.Ft void
64.Fn "tprintf" "tpr_t tpr" "const char *format" "..."
65.Ft void
66.Fn "tprintf_close" "tpr_t tpr"
67.Ft void
68.Fn "aprint_normal" "const char *format" "..."
69.Ft void
70.Fn "aprint_naive" "const char *format" "..."
71.Ft void
72.Fn "aprint_verbose" "const char *format" "..."
73.Ft void
74.Fn "aprint_debug" "const char *format" "..."
75.Ft void
76.Fn "aprint_error" "const char *format" "..."
77.Ft void
78.Fn "aprint_normal_dev" "device_t" "const char *format" "..."
79.Ft void
80.Fn "aprint_naive_dev" "device_t" "const char *format" "..."
81.Ft void
82.Fn "aprint_verbose_dev" "device_t" "const char *format" "..."
83.Ft void
84.Fn "aprint_debug_dev" "device_t" "const char *format" "..."
85.Ft void
86.Fn "aprint_error_dev" "device_t" "const char *format" "..."
87.Ft void
88.Fn "aprint_normal_ifnet" "struct ifnet *" "const char *format" "..."
89.Ft void
90.Fn "aprint_naive_ifnet" "struct ifnet *" "const char *format" "..."
91.Ft void
92.Fn "aprint_verbose_ifnet" "struct ifnet *" "const char *format" "..."
93.Ft void
94.Fn "aprint_debug_ifnet" "struct ifnet *" "const char *format" "..."
95.Ft void
96.Fn "aprint_error_ifnet" "struct ifnet *" "const char *format" "..."
97.Ft int
98.Fn "aprint_get_error_count" "void"
99.Sh DESCRIPTION
100The
101.Fn printf
102family of functions allows the kernel to send formatted messages to various
103output devices.
104The functions
105.Fn printf
106and
107.Fn vprintf
108send formatted strings to the system console.
109The
110.Fn printf_nolog
111function is identical to
112.Fn printf ,
113except it does not send the data to the system log.
114The functions
115.Fn snprintf
116and
117.Fn vsnprintf
118write output to a string buffer.
119These four functions work similarly to their user space counterparts,
120and are not described in detail here.
121.Pp
122The functions
123.Fn uprintf
124and
125.Fn ttyprintf
126send formatted strings to the current process's controlling tty and a specific
127tty, respectively.
128.Pp
129The
130.Fn tprintf
131function sends formatted strings to a process's controlling tty,
132via a handle of type tpr_t.
133This allows multiple write operations to the tty with a guarantee that the
134tty will be valid across calls.
135A handle is acquired by calling
136.Fn tprintf_open
137with the target process as an argument.
138This handle must be closed with a matching call to
139.Fn tprintf_close .
140.Pp
141The functions
142.Fn aprint_normal ,
143.Fn aprint_naive ,
144.Fn aprint_verbose ,
145.Fn aprint_debug ,
146and
147.Fn aprint_error
148are intended to be used to print
149.Xr autoconf 9
150messages.
151Their verbosity depends on flags set in the
152.Va boothowto
153variable, through options passed during bootstrap; see
154.Xr boothowto 9
155and
156.Sx Interactive mode
157in
158.Xr boot 8 :
159.Bl -tag -width AB_VERBOSE
160.It Dv AB_SILENT
161silent mode, enabled by
162.Ic boot
163.Fl z .
164.It Dv AB_QUIET
165quiet mode, enabled by
166.Ic boot
167.Fl q .
168.It Dv AB_VERBOSE
169verbose mode, enabled by
170.Ic boot
171.Fl v .
172.It Dv AB_DEBUG
173debug mode, enabled by
174.Ic boot
175.Fl x .
176.El
177.Pp
178The
179.Fn aprint_*
180functions have the following behaviour, based on the above
181mentioned flags:
182.Bl -tag -width Xaprint_verboseXXX
183.It Fn aprint_normal
184Sends to the console unless
185.Dv AB_QUIET
186is set.
187Always sends to the log.
188.It Fn aprint_naive
189Sends to the console only if
190.Dv AB_QUIET
191is set.
192Never sends to the log.
193.It Fn aprint_verbose
194Sends to the console only if
195.Dv AB_VERBOSE
196is set.
197Always sends to the log.
198.It Fn aprint_debug
199Sends to the console and the log only if
200.Dv AB_DEBUG
201is set.
202.It Fn aprint_error
203Like
204.Fn aprint_normal ,
205but also keeps track of the number of times called.
206This allows a subsystem to report the number of errors that occurred
207during a quiet or silent initialization phase.
208.El
209.Pp
210For the
211.Fn aprint_*
212functions there are two additional families of functions with the
213suffixes
214.Dv _dev
215and
216.Dv _ifnet
217which work like their counterparts without the suffixes, except that
218they take a
219.Ft device_t
220and
221.Ft struct ifnet * ,
222respectively, as first argument,
223and prefix the log message with the
224corresponding device or interface name.
225.Pp
226The
227.Fn aprint_get_error_count
228function reports the number of errors and resets the counter to 0.
229.Pp
230If
231.Dv AB_SILENT
232is set, none of the autoconfiguration message printing routines send output
233to the console.
234The
235.Dv AB_VERBOSE
236and
237.Dv AB_DEBUG
238flags override
239.Dv AB_SILENT .
240.Sh RETURN VALUES
241The
242.Fn snprintf
243and
244.Fn vsnprintf
245functions return the number of characters placed in the buffer
246.Fa buf .
247This is different to the user-space functions of the same name.
248.Pp
249The
250.Fn tprintf_open
251function returns
252.Dv NULL
253if no terminal handle could be acquired.
254.Sh SEE ALSO
255.Xr printf 1 ,
256.Xr printf 3 ,
257.Xr snprintb 3 ,
258.Xr boot 8 ,
259.Xr autoconf 9 ,
260.Xr boothowto 9
261.Sh CODE REFERENCES
262.Pa sys/kern/subr_prf.c
263.Sh HISTORY
264The
265.Fn sprintf
266and
267.Fn vsprintf
268unsized string formatting functions are supported for compatibility only,
269and are not documented here.
270New code should use the size-limited
271.Fn snprintf
272and
273.Fn vsnprintf
274functions instead.
275.Pp
276In
277.Nx 1.5
278and earlier,
279.Fn printf
280supported more format strings than the user space
281.Fn printf .
282These nonstandard format strings are no longer supported.
283For the functionality provided by the former
284.Li %b
285format string, see
286.Xr snprintb 3 .
287.Pp
288The
289.Fn aprint_normal ,
290.Fn aprint_naive ,
291.Fn aprint_verbose ,
292and
293.Fn aprint_debug
294functions first appeared in
295.Bsx .
296.Sh BUGS
297The
298.Fn uprintf
299and
300.Fn ttyprintf
301functions should be used sparingly, if at all.
302Where multiple lines of output are required to reach a process's
303controlling terminal,
304.Fn tprintf
305is preferred.
306