1b3ed2321STobin C. Harding=========================================
2b3ed2321STobin C. HardingHow to get printk format specifiers right
3b3ed2321STobin C. Harding=========================================
4b3ed2321STobin C. Harding
590c165f0SRicardo Cañuelo.. _printk-specifiers:
690c165f0SRicardo Cañuelo
7b3ed2321STobin C. Harding:Author: Randy Dunlap <rdunlap@infradead.org>
8b3ed2321STobin C. Harding:Author: Andrew Murray <amurray@mpc-data.co.uk>
9b3ed2321STobin C. Harding
10b3ed2321STobin C. Harding
11b3ed2321STobin C. HardingInteger types
12b3ed2321STobin C. Harding=============
13b3ed2321STobin C. Harding
14b3ed2321STobin C. Harding::
15b3ed2321STobin C. Harding
16b3ed2321STobin C. Harding	If variable is of Type,		use printk format specifier:
17b3ed2321STobin C. Harding	------------------------------------------------------------
18*243e212fSAndy Shevchenko		signed char		%d or %hhx
19cbacb5abSJoe Perches		unsigned char		%u or %x
20*243e212fSAndy Shevchenko		char			%u or %x
2146d57a7aSAndy Shevchenko		short int		%d or %hx
22cbacb5abSJoe Perches		unsigned short int	%u or %x
23b3ed2321STobin C. Harding		int			%d or %x
24b3ed2321STobin C. Harding		unsigned int		%u or %x
25b3ed2321STobin C. Harding		long			%ld or %lx
26b3ed2321STobin C. Harding		unsigned long		%lu or %lx
27b3ed2321STobin C. Harding		long long		%lld or %llx
28b3ed2321STobin C. Harding		unsigned long long	%llu or %llx
29b3ed2321STobin C. Harding		size_t			%zu or %zx
30b3ed2321STobin C. Harding		ssize_t			%zd or %zx
3146d57a7aSAndy Shevchenko		s8			%d or %hhx
32cbacb5abSJoe Perches		u8			%u or %x
3346d57a7aSAndy Shevchenko		s16			%d or %hx
34cbacb5abSJoe Perches		u16			%u or %x
35b3ed2321STobin C. Harding		s32			%d or %x
36b3ed2321STobin C. Harding		u32			%u or %x
37b3ed2321STobin C. Harding		s64			%lld or %llx
38b3ed2321STobin C. Harding		u64			%llu or %llx
39b3ed2321STobin C. Harding
40b3ed2321STobin C. Harding
41d7c176e9SCarlos LlamasIf <type> is architecture-dependent for its size (e.g., cycles_t, tcflag_t) or
42d7c176e9SCarlos Llamasis dependent on a config option for its size (e.g., blk_status_t), use a format
43d7c176e9SCarlos Llamasspecifier of its largest possible type and explicitly cast to it.
44b3ed2321STobin C. Harding
45b3ed2321STobin C. HardingExample::
46b3ed2321STobin C. Harding
47d7c176e9SCarlos Llamas	printk("test: latency: %llu cycles\n", (unsigned long long)time);
48b3ed2321STobin C. Harding
49b3ed2321STobin C. HardingReminder: sizeof() returns type size_t.
50b3ed2321STobin C. Harding
51b3ed2321STobin C. HardingThe kernel's printf does not support %n. Floating point formats (%e, %f,
52b3ed2321STobin C. Harding%g, %a) are also not recognized, for obvious reasons. Use of any
53b3ed2321STobin C. Hardingunsupported specifier or length qualifier results in a WARN and early
54b3ed2321STobin C. Hardingreturn from vsnprintf().
55b3ed2321STobin C. Harding
56b3ed2321STobin C. HardingPointer types
57b3ed2321STobin C. Harding=============
58b3ed2321STobin C. Harding
59b3ed2321STobin C. HardingA raw pointer value may be printed with %p which will hash the address
60b3ed2321STobin C. Hardingbefore printing. The kernel also supports extended specifiers for printing
61b3ed2321STobin C. Hardingpointers of different types.
62b3ed2321STobin C. Harding
633e5903ebSPetr MladekSome of the extended specifiers print the data on the given address instead
643e5903ebSPetr Mladekof printing the address itself. In this case, the following error messages
653e5903ebSPetr Mladekmight be printed instead of the unreachable information::
663e5903ebSPetr Mladek
673e5903ebSPetr Mladek	(null)	 data on plain NULL address
683e5903ebSPetr Mladek	(efault) data on invalid address
69635720acSPetr Mladek	(einval) invalid data on a valid address
703e5903ebSPetr Mladek
71b3ed2321STobin C. HardingPlain Pointers
72b3ed2321STobin C. Harding--------------
73b3ed2321STobin C. Harding
74b3ed2321STobin C. Harding::
75b3ed2321STobin C. Harding
76b3ed2321STobin C. Harding	%p	abcdef12 or 00000000abcdef12
77b3ed2321STobin C. Harding
78b3ed2321STobin C. HardingPointers printed without a specifier extension (i.e unadorned %p) are
79b3ed2321STobin C. Hardinghashed to prevent leaking information about the kernel memory layout. This
80b3ed2321STobin C. Hardinghas the added benefit of providing a unique identifier. On 64-bit machines
81156383b1SJoel Stanleythe first 32 bits are zeroed. The kernel will print ``(ptrval)`` until it
82a48849e2SVlastimil Babkagathers enough entropy.
83a48849e2SVlastimil Babka
84a48849e2SVlastimil BabkaWhen possible, use specialised modifiers such as %pS or %pB (described below)
85a48849e2SVlastimil Babkato avoid the need of providing an unhashed address that has to be interpreted
86a48849e2SVlastimil Babkapost-hoc. If not possible, and the aim of printing the address is to provide
87a48849e2SVlastimil Babkamore information for debugging, use %p and boot the kernel with the
88a48849e2SVlastimil Babka``no_hash_pointers`` parameter during debugging, which will print all %p
89a48849e2SVlastimil Babkaaddresses unmodified. If you *really* always want the unmodified address, see
90a48849e2SVlastimil Babka%px below.
91a48849e2SVlastimil Babka
92a48849e2SVlastimil BabkaIf (and only if) you are printing addresses as a content of a virtual file in
93a48849e2SVlastimil Babkae.g. procfs or sysfs (using e.g. seq_printf(), not printk()) read by a
94a48849e2SVlastimil Babkauserspace process, use the %pK modifier described below instead of %p or %px.
95b3ed2321STobin C. Harding
9657f5677eSRasmus VillemoesError Pointers
9757f5677eSRasmus Villemoes--------------
9857f5677eSRasmus Villemoes
9957f5677eSRasmus Villemoes::
10057f5677eSRasmus Villemoes
10157f5677eSRasmus Villemoes	%pe	-ENOSPC
10257f5677eSRasmus Villemoes
10357f5677eSRasmus VillemoesFor printing error pointers (i.e. a pointer for which IS_ERR() is true)
10457f5677eSRasmus Villemoesas a symbolic error name. Error values for which no symbolic name is
10557f5677eSRasmus Villemoesknown are printed in decimal, while a non-ERR_PTR passed as the
10657f5677eSRasmus Villemoesargument to %pe gets treated as ordinary %p.
10757f5677eSRasmus Villemoes
108b3ed2321STobin C. HardingSymbols/Function Pointers
109b3ed2321STobin C. Harding-------------------------
110b3ed2321STobin C. Harding
111b3ed2321STobin C. Harding::
112b3ed2321STobin C. Harding
113ab486bc9SLinus Torvalds	%pS	versatile_init+0x0/0x110
114ab486bc9SLinus Torvalds	%ps	versatile_init
115b3ed2321STobin C. Harding	%pSR	versatile_init+0x9/0x110
116b3ed2321STobin C. Harding		(with __builtin_extract_return_addr() translation)
117b3ed2321STobin C. Harding	%pB	prev_fn_of_versatile_init+0x88/0x88
118b3ed2321STobin C. Harding
119b3ed2321STobin C. Harding
120ab486bc9SLinus TorvaldsThe ``S`` and ``s`` specifiers are used for printing a pointer in symbolic
121ab486bc9SLinus Torvaldsformat. They result in the symbol name with (S) or without (s)
122ab486bc9SLinus Torvaldsoffsets. If KALLSYMS are disabled then the symbol address is printed instead.
123b3ed2321STobin C. Harding
124b3ed2321STobin C. HardingThe ``B`` specifier results in the symbol name with offsets and should be
125b3ed2321STobin C. Hardingused when printing stack backtraces. The specifier takes into
126b3ed2321STobin C. Hardingconsideration the effect of compiler optimisations which may occur
127b3ed2321STobin C. Hardingwhen tail-calls are used and marked with the noreturn GCC attribute.
128b3ed2321STobin C. Harding
1299294523eSStephen BoydIf the pointer is within a module, the module name and optionally build ID is
1309294523eSStephen Boydprinted after the symbol name with an extra ``b`` appended to the end of the
1319294523eSStephen Boydspecifier.
1329294523eSStephen Boyd
1339294523eSStephen Boyd::
1345b42d0bfSIoana Ciornei
1359294523eSStephen Boyd	%pS	versatile_init+0x0/0x110 [module_name]
1369294523eSStephen Boyd	%pSb	versatile_init+0x0/0x110 [module_name ed5019fdf5e53be37cb1ba7899292d7e143b259e]
1379294523eSStephen Boyd	%pSRb	versatile_init+0x9/0x110 [module_name ed5019fdf5e53be37cb1ba7899292d7e143b259e]
1389294523eSStephen Boyd		(with __builtin_extract_return_addr() translation)
1399294523eSStephen Boyd	%pBb	prev_fn_of_versatile_init+0x88/0x88 [module_name ed5019fdf5e53be37cb1ba7899292d7e143b259e]
1409294523eSStephen Boyd
141b2a5212fSDaniel BorkmannProbed Pointers from BPF / tracing
142b2a5212fSDaniel Borkmann----------------------------------
143b2a5212fSDaniel Borkmann
144b2a5212fSDaniel Borkmann::
145b2a5212fSDaniel Borkmann
146b2a5212fSDaniel Borkmann	%pks	kernel string
147b2a5212fSDaniel Borkmann	%pus	user string
148b2a5212fSDaniel Borkmann
149b2a5212fSDaniel BorkmannThe ``k`` and ``u`` specifiers are used for printing prior probed memory from
150b2a5212fSDaniel Borkmanneither kernel memory (k) or user memory (u). The subsequent ``s`` specifier
151b2a5212fSDaniel Borkmannresults in printing a string. For direct use in regular vsnprintf() the (k)
152b2a5212fSDaniel Borkmannand (u) annotation is ignored, however, when used out of BPF's bpf_trace_printk(),
153b2a5212fSDaniel Borkmannfor example, it reads the memory it is pointing to without faulting.
154b2a5212fSDaniel Borkmann
155b3ed2321STobin C. HardingKernel Pointers
156b3ed2321STobin C. Harding---------------
157b3ed2321STobin C. Harding
158b3ed2321STobin C. Harding::
159b3ed2321STobin C. Harding
160b3ed2321STobin C. Harding	%pK	01234567 or 0123456789abcdef
161b3ed2321STobin C. Harding
162b3ed2321STobin C. HardingFor printing kernel pointers which should be hidden from unprivileged
163b3ed2321STobin C. Hardingusers. The behaviour of %pK depends on the kptr_restrict sysctl - see
16457043247SMauro Carvalho ChehabDocumentation/admin-guide/sysctl/kernel.rst for more details.
165b3ed2321STobin C. Harding
166a48849e2SVlastimil BabkaThis modifier is *only* intended when producing content of a file read by
167a48849e2SVlastimil Babkauserspace from e.g. procfs or sysfs, not for dmesg. Please refer to the
168a48849e2SVlastimil Babkasection about %p above for discussion about how to manage hashing pointers
169a48849e2SVlastimil Babkain printk().
170a48849e2SVlastimil Babka
171b3ed2321STobin C. HardingUnmodified Addresses
172b3ed2321STobin C. Harding--------------------
173b3ed2321STobin C. Harding
174b3ed2321STobin C. Harding::
175b3ed2321STobin C. Harding
176b3ed2321STobin C. Harding	%px	01234567 or 0123456789abcdef
177b3ed2321STobin C. Harding
178b3ed2321STobin C. HardingFor printing pointers when you *really* want to print the address. Please
179b3ed2321STobin C. Hardingconsider whether or not you are leaking sensitive information about the
180b3ed2321STobin C. Hardingkernel memory layout before printing pointers with %px. %px is functionally
181b3ed2321STobin C. Hardingequivalent to %lx (or %lu). %px is preferred because it is more uniquely
182b3ed2321STobin C. Hardinggrep'able. If in the future we need to modify the way the kernel handles
183b3ed2321STobin C. Hardingprinting pointers we will be better equipped to find the call sites.
184b3ed2321STobin C. Harding
185a48849e2SVlastimil BabkaBefore using %px, consider if using %p is sufficient together with enabling the
186a48849e2SVlastimil Babka``no_hash_pointers`` kernel parameter during debugging sessions (see the %p
187a48849e2SVlastimil Babkadescription above). One valid scenario for %px might be printing information
188a48849e2SVlastimil Babkaimmediately before a panic, which prevents any sensitive information to be
189a48849e2SVlastimil Babkaexploited anyway, and with %px there would be no need to reproduce the panic
190a48849e2SVlastimil Babkawith no_hash_pointers.
191a48849e2SVlastimil Babka
19288288ed0SMiles ChenPointer Differences
19388288ed0SMiles Chen-------------------
19488288ed0SMiles Chen
19588288ed0SMiles Chen::
19688288ed0SMiles Chen
19788288ed0SMiles Chen	%td	2560
19888288ed0SMiles Chen	%tx	a00
19988288ed0SMiles Chen
20088288ed0SMiles ChenFor printing the pointer differences, use the %t modifier for ptrdiff_t.
20188288ed0SMiles Chen
20288288ed0SMiles ChenExample::
20388288ed0SMiles Chen
20488288ed0SMiles Chen	printk("test: difference between pointers: %td\n", ptr2 - ptr1);
20588288ed0SMiles Chen
206b3ed2321STobin C. HardingStruct Resources
207b3ed2321STobin C. Harding----------------
208b3ed2321STobin C. Harding
209b3ed2321STobin C. Harding::
210b3ed2321STobin C. Harding
211b3ed2321STobin C. Harding	%pr	[mem 0x60000000-0x6fffffff flags 0x2200] or
212b3ed2321STobin C. Harding		[mem 0x0000000060000000-0x000000006fffffff flags 0x2200]
213b3ed2321STobin C. Harding	%pR	[mem 0x60000000-0x6fffffff pref] or
214b3ed2321STobin C. Harding		[mem 0x0000000060000000-0x000000006fffffff pref]
215b3ed2321STobin C. Harding
216b3ed2321STobin C. HardingFor printing struct resources. The ``R`` and ``r`` specifiers result in a
217b3ed2321STobin C. Hardingprinted resource with (R) or without (r) a decoded flags member.
218b3ed2321STobin C. Harding
219b3ed2321STobin C. HardingPassed by reference.
220b3ed2321STobin C. Harding
221b3ed2321STobin C. HardingPhysical address types phys_addr_t
222b3ed2321STobin C. Harding----------------------------------
223b3ed2321STobin C. Harding
224b3ed2321STobin C. Harding::
225b3ed2321STobin C. Harding
226b3ed2321STobin C. Harding	%pa[p]	0x01234567 or 0x0123456789abcdef
227b3ed2321STobin C. Harding
228b3ed2321STobin C. HardingFor printing a phys_addr_t type (and its derivatives, such as
229b3ed2321STobin C. Hardingresource_size_t) which can vary based on build options, regardless of the
230b3ed2321STobin C. Hardingwidth of the CPU data path.
231b3ed2321STobin C. Harding
232b3ed2321STobin C. HardingPassed by reference.
233b3ed2321STobin C. Harding
234b3ed2321STobin C. HardingDMA address types dma_addr_t
235b3ed2321STobin C. Harding----------------------------
236b3ed2321STobin C. Harding
237b3ed2321STobin C. Harding::
238b3ed2321STobin C. Harding
239b3ed2321STobin C. Harding	%pad	0x01234567 or 0x0123456789abcdef
240b3ed2321STobin C. Harding
241b3ed2321STobin C. HardingFor printing a dma_addr_t type which can vary based on build options,
242b3ed2321STobin C. Hardingregardless of the width of the CPU data path.
243b3ed2321STobin C. Harding
244b3ed2321STobin C. HardingPassed by reference.
245b3ed2321STobin C. Harding
246b3ed2321STobin C. HardingRaw buffer as an escaped string
247b3ed2321STobin C. Harding-------------------------------
248b3ed2321STobin C. Harding
249b3ed2321STobin C. Harding::
250b3ed2321STobin C. Harding
251b3ed2321STobin C. Harding	%*pE[achnops]
252b3ed2321STobin C. Harding
253b3ed2321STobin C. HardingFor printing raw buffer as an escaped string. For the following buffer::
254b3ed2321STobin C. Harding
255b3ed2321STobin C. Harding		1b 62 20 5c 43 07 22 90 0d 5d
256b3ed2321STobin C. Harding
257b3ed2321STobin C. HardingA few examples show how the conversion would be done (excluding surrounding
258b3ed2321STobin C. Hardingquotes)::
259b3ed2321STobin C. Harding
260b3ed2321STobin C. Harding		%*pE		"\eb \C\a"\220\r]"
261b3ed2321STobin C. Harding		%*pEhp		"\x1bb \C\x07"\x90\x0d]"
262b3ed2321STobin C. Harding		%*pEa		"\e\142\040\\\103\a\042\220\r\135"
263b3ed2321STobin C. Harding
264b3ed2321STobin C. HardingThe conversion rules are applied according to an optional combination
265b3ed2321STobin C. Hardingof flags (see :c:func:`string_escape_mem` kernel documentation for the
266b3ed2321STobin C. Hardingdetails):
267b3ed2321STobin C. Harding
268b3ed2321STobin C. Harding	- a - ESCAPE_ANY
269b3ed2321STobin C. Harding	- c - ESCAPE_SPECIAL
270b3ed2321STobin C. Harding	- h - ESCAPE_HEX
271b3ed2321STobin C. Harding	- n - ESCAPE_NULL
272b3ed2321STobin C. Harding	- o - ESCAPE_OCTAL
273b3ed2321STobin C. Harding	- p - ESCAPE_NP
274b3ed2321STobin C. Harding	- s - ESCAPE_SPACE
275b3ed2321STobin C. Harding
276b3ed2321STobin C. HardingBy default ESCAPE_ANY_NP is used.
277b3ed2321STobin C. Harding
278b3ed2321STobin C. HardingESCAPE_ANY_NP is the sane choice for many cases, in particularly for
279b3ed2321STobin C. Hardingprinting SSIDs.
280b3ed2321STobin C. Harding
281b3ed2321STobin C. HardingIf field width is omitted then 1 byte only will be escaped.
282b3ed2321STobin C. Harding
283b3ed2321STobin C. HardingRaw buffer as a hex string
284b3ed2321STobin C. Harding--------------------------
285b3ed2321STobin C. Harding
286b3ed2321STobin C. Harding::
287b3ed2321STobin C. Harding
288b3ed2321STobin C. Harding	%*ph	00 01 02  ...  3f
289b3ed2321STobin C. Harding	%*phC	00:01:02: ... :3f
290b3ed2321STobin C. Harding	%*phD	00-01-02- ... -3f
291b3ed2321STobin C. Harding	%*phN	000102 ... 3f
292b3ed2321STobin C. Harding
293b3ed2321STobin C. HardingFor printing small buffers (up to 64 bytes long) as a hex string with a
294b3ed2321STobin C. Hardingcertain separator. For larger buffers consider using
295b3ed2321STobin C. Harding:c:func:`print_hex_dump`.
296b3ed2321STobin C. Harding
297b3ed2321STobin C. HardingMAC/FDDI addresses
298b3ed2321STobin C. Harding------------------
299b3ed2321STobin C. Harding
300b3ed2321STobin C. Harding::
301b3ed2321STobin C. Harding
302b3ed2321STobin C. Harding	%pM	00:01:02:03:04:05
303b3ed2321STobin C. Harding	%pMR	05:04:03:02:01:00
304b3ed2321STobin C. Harding	%pMF	00-01-02-03-04-05
305b3ed2321STobin C. Harding	%pm	000102030405
306b3ed2321STobin C. Harding	%pmR	050403020100
307b3ed2321STobin C. Harding
308b3ed2321STobin C. HardingFor printing 6-byte MAC/FDDI addresses in hex notation. The ``M`` and ``m``
309b3ed2321STobin C. Hardingspecifiers result in a printed address with (M) or without (m) byte
310b3ed2321STobin C. Hardingseparators. The default byte separator is the colon (:).
311b3ed2321STobin C. Harding
312b3ed2321STobin C. HardingWhere FDDI addresses are concerned the ``F`` specifier can be used after
313b3ed2321STobin C. Hardingthe ``M`` specifier to use dash (-) separators instead of the default
314b3ed2321STobin C. Hardingseparator.
315b3ed2321STobin C. Harding
316b3ed2321STobin C. HardingFor Bluetooth addresses the ``R`` specifier shall be used after the ``M``
317b3ed2321STobin C. Hardingspecifier to use reversed byte order suitable for visual interpretation
318b3ed2321STobin C. Hardingof Bluetooth addresses which are in the little endian order.
319b3ed2321STobin C. Harding
320b3ed2321STobin C. HardingPassed by reference.
321b3ed2321STobin C. Harding
322b3ed2321STobin C. HardingIPv4 addresses
323b3ed2321STobin C. Harding--------------
324b3ed2321STobin C. Harding
325b3ed2321STobin C. Harding::
326b3ed2321STobin C. Harding
327b3ed2321STobin C. Harding	%pI4	1.2.3.4
328b3ed2321STobin C. Harding	%pi4	001.002.003.004
329b3ed2321STobin C. Harding	%p[Ii]4[hnbl]
330b3ed2321STobin C. Harding
331b3ed2321STobin C. HardingFor printing IPv4 dot-separated decimal addresses. The ``I4`` and ``i4``
332b3ed2321STobin C. Hardingspecifiers result in a printed address with (i4) or without (I4) leading
333b3ed2321STobin C. Hardingzeros.
334b3ed2321STobin C. Harding
335b3ed2321STobin C. HardingThe additional ``h``, ``n``, ``b``, and ``l`` specifiers are used to specify
336b3ed2321STobin C. Hardinghost, network, big or little endian order addresses respectively. Where
337b3ed2321STobin C. Hardingno specifier is provided the default network/big endian order is used.
338b3ed2321STobin C. Harding
339b3ed2321STobin C. HardingPassed by reference.
340b3ed2321STobin C. Harding
341b3ed2321STobin C. HardingIPv6 addresses
342b3ed2321STobin C. Harding--------------
343b3ed2321STobin C. Harding
344b3ed2321STobin C. Harding::
345b3ed2321STobin C. Harding
346b3ed2321STobin C. Harding	%pI6	0001:0002:0003:0004:0005:0006:0007:0008
347b3ed2321STobin C. Harding	%pi6	00010002000300040005000600070008
348b3ed2321STobin C. Harding	%pI6c	1:2:3:4:5:6:7:8
349b3ed2321STobin C. Harding
350b3ed2321STobin C. HardingFor printing IPv6 network-order 16-bit hex addresses. The ``I6`` and ``i6``
351b3ed2321STobin C. Hardingspecifiers result in a printed address with (I6) or without (i6)
352b3ed2321STobin C. Hardingcolon-separators. Leading zeros are always used.
353b3ed2321STobin C. Harding
354b3ed2321STobin C. HardingThe additional ``c`` specifier can be used with the ``I`` specifier to
355b3ed2321STobin C. Hardingprint a compressed IPv6 address as described by
3568eda94bdSAlexander A. Klimovhttps://tools.ietf.org/html/rfc5952
357b3ed2321STobin C. Harding
358b3ed2321STobin C. HardingPassed by reference.
359b3ed2321STobin C. Harding
360b3ed2321STobin C. HardingIPv4/IPv6 addresses (generic, with port, flowinfo, scope)
361b3ed2321STobin C. Harding---------------------------------------------------------
362b3ed2321STobin C. Harding
363b3ed2321STobin C. Harding::
364b3ed2321STobin C. Harding
365b3ed2321STobin C. Harding	%pIS	1.2.3.4		or 0001:0002:0003:0004:0005:0006:0007:0008
366b3ed2321STobin C. Harding	%piS	001.002.003.004	or 00010002000300040005000600070008
367b3ed2321STobin C. Harding	%pISc	1.2.3.4		or 1:2:3:4:5:6:7:8
368b3ed2321STobin C. Harding	%pISpc	1.2.3.4:12345	or [1:2:3:4:5:6:7:8]:12345
369b3ed2321STobin C. Harding	%p[Ii]S[pfschnbl]
370b3ed2321STobin C. Harding
371b3ed2321STobin C. HardingFor printing an IP address without the need to distinguish whether it's of
372b3ed2321STobin C. Hardingtype AF_INET or AF_INET6. A pointer to a valid struct sockaddr,
373b3ed2321STobin C. Hardingspecified through ``IS`` or ``iS``, can be passed to this format specifier.
374b3ed2321STobin C. Harding
375b3ed2321STobin C. HardingThe additional ``p``, ``f``, and ``s`` specifiers are used to specify port
376b3ed2321STobin C. Harding(IPv4, IPv6), flowinfo (IPv6) and scope (IPv6). Ports have a ``:`` prefix,
377b3ed2321STobin C. Hardingflowinfo a ``/`` and scope a ``%``, each followed by the actual value.
378b3ed2321STobin C. Harding
379b3ed2321STobin C. HardingIn case of an IPv6 address the compressed IPv6 address as described by
3808eda94bdSAlexander A. Klimovhttps://tools.ietf.org/html/rfc5952 is being used if the additional
381b3ed2321STobin C. Hardingspecifier ``c`` is given. The IPv6 address is surrounded by ``[``, ``]`` in
382b3ed2321STobin C. Hardingcase of additional specifiers ``p``, ``f`` or ``s`` as suggested by
383b3ed2321STobin C. Hardinghttps://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07
384b3ed2321STobin C. Harding
385b3ed2321STobin C. HardingIn case of IPv4 addresses, the additional ``h``, ``n``, ``b``, and ``l``
386b3ed2321STobin C. Hardingspecifiers can be used as well and are ignored in case of an IPv6
387b3ed2321STobin C. Hardingaddress.
388b3ed2321STobin C. Harding
389b3ed2321STobin C. HardingPassed by reference.
390b3ed2321STobin C. Harding
391b3ed2321STobin C. HardingFurther examples::
392b3ed2321STobin C. Harding
393b3ed2321STobin C. Harding	%pISfc		1.2.3.4		or [1:2:3:4:5:6:7:8]/123456789
394b3ed2321STobin C. Harding	%pISsc		1.2.3.4		or [1:2:3:4:5:6:7:8]%1234567890
395b3ed2321STobin C. Harding	%pISpfc		1.2.3.4:12345	or [1:2:3:4:5:6:7:8]:12345/123456789
396b3ed2321STobin C. Harding
397b3ed2321STobin C. HardingUUID/GUID addresses
398b3ed2321STobin C. Harding-------------------
399b3ed2321STobin C. Harding
400b3ed2321STobin C. Harding::
401b3ed2321STobin C. Harding
402b3ed2321STobin C. Harding	%pUb	00010203-0405-0607-0809-0a0b0c0d0e0f
403b3ed2321STobin C. Harding	%pUB	00010203-0405-0607-0809-0A0B0C0D0E0F
404b3ed2321STobin C. Harding	%pUl	03020100-0504-0706-0809-0a0b0c0e0e0f
405b3ed2321STobin C. Harding	%pUL	03020100-0504-0706-0809-0A0B0C0E0E0F
406b3ed2321STobin C. Harding
407b3ed2321STobin C. HardingFor printing 16-byte UUID/GUIDs addresses. The additional ``l``, ``L``,
408b3ed2321STobin C. Harding``b`` and ``B`` specifiers are used to specify a little endian order in
409b3ed2321STobin C. Hardinglower (l) or upper case (L) hex notation - and big endian order in lower (b)
410b3ed2321STobin C. Hardingor upper case (B) hex notation.
411b3ed2321STobin C. Harding
412b3ed2321STobin C. HardingWhere no additional specifiers are used the default big endian
413b3ed2321STobin C. Hardingorder with lower case hex notation will be printed.
414b3ed2321STobin C. Harding
415b3ed2321STobin C. HardingPassed by reference.
416b3ed2321STobin C. Harding
417b3ed2321STobin C. Hardingdentry names
418b3ed2321STobin C. Harding------------
419b3ed2321STobin C. Harding
420b3ed2321STobin C. Harding::
421b3ed2321STobin C. Harding
422b3ed2321STobin C. Harding	%pd{,2,3,4}
423b3ed2321STobin C. Harding	%pD{,2,3,4}
424b3ed2321STobin C. Harding
425b3ed2321STobin C. HardingFor printing dentry name; if we race with :c:func:`d_move`, the name might
426b3ed2321STobin C. Hardingbe a mix of old and new ones, but it won't oops.  %pd dentry is a safer
427b3ed2321STobin C. Hardingequivalent of %s dentry->d_name.name we used to use, %pd<n> prints ``n``
428b3ed2321STobin C. Hardinglast components.  %pD does the same thing for struct file.
429b3ed2321STobin C. Harding
430b3ed2321STobin C. HardingPassed by reference.
431b3ed2321STobin C. Harding
432b3ed2321STobin C. Hardingblock_device names
433b3ed2321STobin C. Harding------------------
434b3ed2321STobin C. Harding
435b3ed2321STobin C. Harding::
436b3ed2321STobin C. Harding
437b3ed2321STobin C. Harding	%pg	sda, sda1 or loop0p1
438b3ed2321STobin C. Harding
439b3ed2321STobin C. HardingFor printing name of block_device pointers.
440b3ed2321STobin C. Harding
441b3ed2321STobin C. Hardingstruct va_format
442b3ed2321STobin C. Harding----------------
443b3ed2321STobin C. Harding
444b3ed2321STobin C. Harding::
445b3ed2321STobin C. Harding
446b3ed2321STobin C. Harding	%pV
447b3ed2321STobin C. Harding
448b3ed2321STobin C. HardingFor printing struct va_format structures. These contain a format string
449b3ed2321STobin C. Hardingand va_list as follows::
450b3ed2321STobin C. Harding
451b3ed2321STobin C. Harding	struct va_format {
452b3ed2321STobin C. Harding		const char *fmt;
453b3ed2321STobin C. Harding		va_list *va;
454b3ed2321STobin C. Harding	};
455b3ed2321STobin C. Harding
456b3ed2321STobin C. HardingImplements a "recursive vsnprintf".
457b3ed2321STobin C. Harding
458b3ed2321STobin C. HardingDo not use this feature without some mechanism to verify the
459b3ed2321STobin C. Hardingcorrectness of the format string and va_list arguments.
460b3ed2321STobin C. Harding
461b3ed2321STobin C. HardingPassed by reference.
462b3ed2321STobin C. Harding
46394ac8f20SGeert UytterhoevenDevice tree nodes
46494ac8f20SGeert Uytterhoeven-----------------
465b3ed2321STobin C. Harding
466b3ed2321STobin C. Harding::
467b3ed2321STobin C. Harding
468b3ed2321STobin C. Harding	%pOF[fnpPcCF]
469b3ed2321STobin C. Harding
470b3ed2321STobin C. Harding
47194ac8f20SGeert UytterhoevenFor printing device tree node structures. Default behaviour is
472b3ed2321STobin C. Hardingequivalent to %pOFf.
473b3ed2321STobin C. Harding
474b3ed2321STobin C. Harding	- f - device node full_name
475b3ed2321STobin C. Harding	- n - device node name
476b3ed2321STobin C. Harding	- p - device node phandle
477b3ed2321STobin C. Harding	- P - device node path spec (name + @unit)
478b3ed2321STobin C. Harding	- F - device node flags
479b3ed2321STobin C. Harding	- c - major compatible string
480b3ed2321STobin C. Harding	- C - full compatible string
481b3ed2321STobin C. Harding
482b3ed2321STobin C. HardingThe separator when using multiple arguments is ':'
483b3ed2321STobin C. Harding
484b3ed2321STobin C. HardingExamples::
485b3ed2321STobin C. Harding
486b3ed2321STobin C. Harding	%pOF	/foo/bar@0			- Node full name
487b3ed2321STobin C. Harding	%pOFf	/foo/bar@0			- Same as above
488b3ed2321STobin C. Harding	%pOFfp	/foo/bar@0:10			- Node full name + phandle
489b3ed2321STobin C. Harding	%pOFfcF	/foo/bar@0:foo,device:--P-	- Node full name +
490b3ed2321STobin C. Harding	                                          major compatible string +
491b3ed2321STobin C. Harding						  node flags
492b3ed2321STobin C. Harding							D - dynamic
493b3ed2321STobin C. Harding							d - detached
494b3ed2321STobin C. Harding							P - Populated
495b3ed2321STobin C. Harding							B - Populated bus
496b3ed2321STobin C. Harding
497b3ed2321STobin C. HardingPassed by reference.
498b3ed2321STobin C. Harding
4993bd32d6aSSakari AilusFwnode handles
5003bd32d6aSSakari Ailus--------------
5013bd32d6aSSakari Ailus
5023bd32d6aSSakari Ailus::
5033bd32d6aSSakari Ailus
5043bd32d6aSSakari Ailus	%pfw[fP]
5053bd32d6aSSakari Ailus
5063bd32d6aSSakari AilusFor printing information on fwnode handles. The default is to print the full
5073bd32d6aSSakari Ailusnode name, including the path. The modifiers are functionally equivalent to
5083bd32d6aSSakari Ailus%pOF above.
5093bd32d6aSSakari Ailus
5103bd32d6aSSakari Ailus	- f - full name of the node, including the path
5113bd32d6aSSakari Ailus	- P - the name of the node including an address (if there is one)
5123bd32d6aSSakari Ailus
5133bd32d6aSSakari AilusExamples (ACPI)::
5143bd32d6aSSakari Ailus
5153bd32d6aSSakari Ailus	%pfwf	\_SB.PCI0.CIO2.port@1.endpoint@0	- Full node name
5163bd32d6aSSakari Ailus	%pfwP	endpoint@0				- Node name
5173bd32d6aSSakari Ailus
5183bd32d6aSSakari AilusExamples (OF)::
5193bd32d6aSSakari Ailus
5203bd32d6aSSakari Ailus	%pfwf	/ocp@68000000/i2c@48072000/camera@10/port/endpoint - Full name
5213bd32d6aSSakari Ailus	%pfwP	endpoint				- Node name
5223bd32d6aSSakari Ailus
5237daac5b2SAndy ShevchenkoTime and date
5247daac5b2SAndy Shevchenko-------------
5254d42c447SAndy Shevchenko
5264d42c447SAndy Shevchenko::
5274d42c447SAndy Shevchenko
5287daac5b2SAndy Shevchenko	%pt[RT]			YYYY-mm-ddTHH:MM:SS
52920bc8c1eSAndy Shevchenko	%pt[RT]s		YYYY-mm-dd HH:MM:SS
5307daac5b2SAndy Shevchenko	%pt[RT]d		YYYY-mm-dd
5317daac5b2SAndy Shevchenko	%pt[RT]t		HH:MM:SS
53220bc8c1eSAndy Shevchenko	%pt[RT][dt][r][s]
5334d42c447SAndy Shevchenko
534b7f41995SDaniel W. S. AlmeidaFor printing date and time as represented by::
535b7f41995SDaniel W. S. Almeida
5367daac5b2SAndy Shevchenko	R  struct rtc_time structure
5377daac5b2SAndy Shevchenko	T  time64_t type
538b7f41995SDaniel W. S. Almeida
5397daac5b2SAndy Shevchenkoin human readable format.
5404d42c447SAndy Shevchenko
5417daac5b2SAndy ShevchenkoBy default year will be incremented by 1900 and month by 1.
5427daac5b2SAndy ShevchenkoUse %pt[RT]r (raw) to suppress this behaviour.
5434d42c447SAndy Shevchenko
54420bc8c1eSAndy ShevchenkoThe %pt[RT]s (space) will override ISO 8601 separator by using ' ' (space)
54520bc8c1eSAndy Shevchenkoinstead of 'T' (Capital T) between date and time. It won't have any effect
54620bc8c1eSAndy Shevchenkowhen date or time is omitted.
54720bc8c1eSAndy Shevchenko
5484d42c447SAndy ShevchenkoPassed by reference.
5494d42c447SAndy Shevchenko
550b3ed2321STobin C. Hardingstruct clk
551b3ed2321STobin C. Harding----------
552b3ed2321STobin C. Harding
553b3ed2321STobin C. Harding::
554b3ed2321STobin C. Harding
555b3ed2321STobin C. Harding	%pC	pll1
556b3ed2321STobin C. Harding	%pCn	pll1
557b3ed2321STobin C. Harding
558ec12bc29SGeert UytterhoevenFor printing struct clk structures. %pC and %pCn print the name of the clock
559ec12bc29SGeert Uytterhoeven(Common Clock Framework) or a unique 32-bit ID (legacy clock framework).
560b3ed2321STobin C. Harding
561b3ed2321STobin C. HardingPassed by reference.
562b3ed2321STobin C. Harding
563b3ed2321STobin C. Hardingbitmap and its derivatives such as cpumask and nodemask
564b3ed2321STobin C. Harding-------------------------------------------------------
565b3ed2321STobin C. Harding
566b3ed2321STobin C. Harding::
567b3ed2321STobin C. Harding
568b3ed2321STobin C. Harding	%*pb	0779
569b3ed2321STobin C. Harding	%*pbl	0,3-6,8-10
570b3ed2321STobin C. Harding
571b3ed2321STobin C. HardingFor printing bitmap and its derivatives such as cpumask and nodemask,
572b3ed2321STobin C. Harding%*pb outputs the bitmap with field width as the number of bits and %*pbl
573b3ed2321STobin C. Hardingoutput the bitmap as range list with field width as the number of bits.
574b3ed2321STobin C. Harding
57504d0608bSGeert UytterhoevenThe field width is passed by value, the bitmap is passed by reference.
57604d0608bSGeert UytterhoevenHelper macros cpumask_pr_args() and nodemask_pr_args() are available to ease
57704d0608bSGeert Uytterhoevenprinting cpumask and nodemask.
578b3ed2321STobin C. Harding
579b3ed2321STobin C. HardingFlags bitfields such as page flags, page_type, gfp_flags
580b3ed2321STobin C. Harding--------------------------------------------------------
581b3ed2321STobin C. Harding
582b3ed2321STobin C. Harding::
583b3ed2321STobin C. Harding
5846a7ca80fSPetr Mladek	%pGp	0x17ffffc0002036(referenced|uptodate|lru|active|private|node=0|zone=2|lastcpupid=0x1fffff)
585b3ed2321STobin C. Harding	%pGt	0xffffff7f(buddy)
586b3ed2321STobin C. Harding	%pGg	GFP_USER|GFP_DMA32|GFP_NOWARN
587b3ed2321STobin C. Harding	%pGv	read|exec|mayread|maywrite|mayexec|denywrite
588b3ed2321STobin C. Harding
589b3ed2321STobin C. HardingFor printing flags bitfields as a collection of symbolic constants that
590b3ed2321STobin C. Hardingwould construct the value. The type of flags is given by the third
591b3ed2321STobin C. Hardingcharacter. Currently supported are:
592b3ed2321STobin C. Harding
593b3ed2321STobin C. Harding        - p - [p]age flags, expects value of type (``unsigned long *``)
594b3ed2321STobin C. Harding        - t - page [t]ype, expects value of type (``unsigned int *``)
595b3ed2321STobin C. Harding        - v - [v]ma_flags, expects value of type (``unsigned long *``)
596b3ed2321STobin C. Harding        - g - [g]fp_flags, expects value of type (``gfp_t *``)
597b3ed2321STobin C. Harding
598b3ed2321STobin C. HardingThe flag names and print order depends on the particular type.
599b3ed2321STobin C. Harding
600b3ed2321STobin C. HardingNote that this format should not be used directly in the
601b3ed2321STobin C. Harding:c:func:`TP_printk()` part of a tracepoint. Instead, use the show_*_flags()
602b3ed2321STobin C. Hardingfunctions from <trace/events/mmflags.h>.
603b3ed2321STobin C. Harding
604b3ed2321STobin C. HardingPassed by reference.
605b3ed2321STobin C. Harding
606b3ed2321STobin C. HardingNetwork device features
607b3ed2321STobin C. Harding-----------------------
608b3ed2321STobin C. Harding
609b3ed2321STobin C. Harding::
610b3ed2321STobin C. Harding
611af612e43SSakari Ailus	%pNF	0x000000000000c000
612af612e43SSakari Ailus
613af612e43SSakari AilusFor printing netdev_features_t.
614af612e43SSakari Ailus
615af612e43SSakari AilusPassed by reference.
616af612e43SSakari Ailus
617af612e43SSakari AilusV4L2 and DRM FourCC code (pixel format)
618af612e43SSakari Ailus---------------------------------------
619af612e43SSakari Ailus
620af612e43SSakari Ailus::
621af612e43SSakari Ailus
622af612e43SSakari Ailus	%p4cc
623af612e43SSakari Ailus
624af612e43SSakari AilusPrint a FourCC code used by V4L2 or DRM, including format endianness and
625af612e43SSakari Ailusits numerical value as hexadecimal.
626af612e43SSakari Ailus
627af612e43SSakari AilusPassed by reference.
628af612e43SSakari Ailus
629787983daSGary GuoExamples::
630787983daSGary Guo
631787983daSGary Guo	%p4cc	BG12 little-endian (0x32314742)
632787983daSGary Guo	%p4cc	Y10  little-endian (0x20303159)
633787983daSGary Guo	%p4cc	NV12 big-endian (0xb231564e)
634787983daSGary Guo
635787983daSGary GuoRust
636787983daSGary Guo----
637787983daSGary Guo
638787983daSGary Guo::
639b3ed2321STobin C. Harding
640b3ed2321STobin C. Harding	%pA
641b3ed2321STobin C. Harding
642b3ed2321STobin C. HardingOnly intended to be used from Rust code to format ``core::fmt::Arguments``.
643b3ed2321STobin C. HardingDo *not* use it from C.
644b3ed2321STobin C. Harding
645b3ed2321STobin C. HardingThanks
646======
647
648If you add other %p extensions, please extend <lib/test_printf.c> with
649one or more test cases, if at all feasible.
650
651Thank you for your cooperation and attention.
652