printk-formats.txt 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. If variable is of Type, use printk format specifier:
  2. ---------------------------------------------------------
  3. int %d or %x
  4. unsigned int %u or %x
  5. long %ld or %lx
  6. unsigned long %lu or %lx
  7. long long %lld or %llx
  8. unsigned long long %llu or %llx
  9. size_t %zu or %zx
  10. ssize_t %zd or %zx
  11. s32 %d or %x
  12. u32 %u or %x
  13. s64 %lld or %llx
  14. u64 %llu or %llx
  15. If <type> is dependent on a config option for its size (e.g., sector_t,
  16. blkcnt_t) or is architecture-dependent for its size (e.g., tcflag_t), use a
  17. format specifier of its largest possible type and explicitly cast to it.
  18. Example:
  19. printk("test: sector number/total blocks: %llu/%llu\n",
  20. (unsigned long long)sector, (unsigned long long)blockcount);
  21. Reminder: sizeof() result is of type size_t.
  22. The kernel's printf does not support %n. For obvious reasons, floating
  23. point formats (%e, %f, %g, %a) are also not recognized. Use of any
  24. unsupported specifier or length qualifier results in a WARN and early
  25. return from vsnprintf.
  26. Raw pointer value SHOULD be printed with %p. The kernel supports
  27. the following extended format specifiers for pointer types:
  28. Symbols/Function Pointers:
  29. %pF versatile_init+0x0/0x110
  30. %pf versatile_init
  31. %pS versatile_init+0x0/0x110
  32. %pSR versatile_init+0x9/0x110
  33. (with __builtin_extract_return_addr() translation)
  34. %ps versatile_init
  35. %pB prev_fn_of_versatile_init+0x88/0x88
  36. For printing symbols and function pointers. The 'S' and 's' specifiers
  37. result in the symbol name with ('S') or without ('s') offsets. Where
  38. this is used on a kernel without KALLSYMS - the symbol address is
  39. printed instead.
  40. The 'B' specifier results in the symbol name with offsets and should be
  41. used when printing stack backtraces. The specifier takes into
  42. consideration the effect of compiler optimisations which may occur
  43. when tail-call's are used and marked with the noreturn GCC attribute.
  44. On ia64, ppc64 and parisc64 architectures function pointers are
  45. actually function descriptors which must first be resolved. The 'F' and
  46. 'f' specifiers perform this resolution and then provide the same
  47. functionality as the 'S' and 's' specifiers.
  48. Kernel Pointers:
  49. %pK 0x01234567 or 0x0123456789abcdef
  50. For printing kernel pointers which should be hidden from unprivileged
  51. users. The behaviour of %pK depends on the kptr_restrict sysctl - see
  52. Documentation/sysctl/kernel.txt for more details.
  53. Struct Resources:
  54. %pr [mem 0x60000000-0x6fffffff flags 0x2200] or
  55. [mem 0x0000000060000000-0x000000006fffffff flags 0x2200]
  56. %pR [mem 0x60000000-0x6fffffff pref] or
  57. [mem 0x0000000060000000-0x000000006fffffff pref]
  58. For printing struct resources. The 'R' and 'r' specifiers result in a
  59. printed resource with ('R') or without ('r') a decoded flags member.
  60. Passed by reference.
  61. Physical addresses types phys_addr_t:
  62. %pa[p] 0x01234567 or 0x0123456789abcdef
  63. For printing a phys_addr_t type (and its derivatives, such as
  64. resource_size_t) which can vary based on build options, regardless of
  65. the width of the CPU data path. Passed by reference.
  66. DMA addresses types dma_addr_t:
  67. %pad 0x01234567 or 0x0123456789abcdef
  68. For printing a dma_addr_t type which can vary based on build options,
  69. regardless of the width of the CPU data path. Passed by reference.
  70. Raw buffer as an escaped string:
  71. %*pE[achnops]
  72. For printing raw buffer as an escaped string. For the following buffer
  73. 1b 62 20 5c 43 07 22 90 0d 5d
  74. few examples show how the conversion would be done (the result string
  75. without surrounding quotes):
  76. %*pE "\eb \C\a"\220\r]"
  77. %*pEhp "\x1bb \C\x07"\x90\x0d]"
  78. %*pEa "\e\142\040\\\103\a\042\220\r\135"
  79. The conversion rules are applied according to an optional combination
  80. of flags (see string_escape_mem() kernel documentation for the
  81. details):
  82. a - ESCAPE_ANY
  83. c - ESCAPE_SPECIAL
  84. h - ESCAPE_HEX
  85. n - ESCAPE_NULL
  86. o - ESCAPE_OCTAL
  87. p - ESCAPE_NP
  88. s - ESCAPE_SPACE
  89. By default ESCAPE_ANY_NP is used.
  90. ESCAPE_ANY_NP is the sane choice for many cases, in particularly for
  91. printing SSIDs.
  92. If field width is omitted the 1 byte only will be escaped.
  93. Raw buffer as a hex string:
  94. %*ph 00 01 02 ... 3f
  95. %*phC 00:01:02: ... :3f
  96. %*phD 00-01-02- ... -3f
  97. %*phN 000102 ... 3f
  98. For printing a small buffers (up to 64 bytes long) as a hex string with
  99. certain separator. For the larger buffers consider to use
  100. print_hex_dump().
  101. MAC/FDDI addresses:
  102. %pM 00:01:02:03:04:05
  103. %pMR 05:04:03:02:01:00
  104. %pMF 00-01-02-03-04-05
  105. %pm 000102030405
  106. %pmR 050403020100
  107. For printing 6-byte MAC/FDDI addresses in hex notation. The 'M' and 'm'
  108. specifiers result in a printed address with ('M') or without ('m') byte
  109. separators. The default byte separator is the colon (':').
  110. Where FDDI addresses are concerned the 'F' specifier can be used after
  111. the 'M' specifier to use dash ('-') separators instead of the default
  112. separator.
  113. For Bluetooth addresses the 'R' specifier shall be used after the 'M'
  114. specifier to use reversed byte order suitable for visual interpretation
  115. of Bluetooth addresses which are in the little endian order.
  116. Passed by reference.
  117. IPv4 addresses:
  118. %pI4 1.2.3.4
  119. %pi4 001.002.003.004
  120. %p[Ii]4[hnbl]
  121. For printing IPv4 dot-separated decimal addresses. The 'I4' and 'i4'
  122. specifiers result in a printed address with ('i4') or without ('I4')
  123. leading zeros.
  124. The additional 'h', 'n', 'b', and 'l' specifiers are used to specify
  125. host, network, big or little endian order addresses respectively. Where
  126. no specifier is provided the default network/big endian order is used.
  127. Passed by reference.
  128. IPv6 addresses:
  129. %pI6 0001:0002:0003:0004:0005:0006:0007:0008
  130. %pi6 00010002000300040005000600070008
  131. %pI6c 1:2:3:4:5:6:7:8
  132. For printing IPv6 network-order 16-bit hex addresses. The 'I6' and 'i6'
  133. specifiers result in a printed address with ('I6') or without ('i6')
  134. colon-separators. Leading zeros are always used.
  135. The additional 'c' specifier can be used with the 'I' specifier to
  136. print a compressed IPv6 address as described by
  137. http://tools.ietf.org/html/rfc5952
  138. Passed by reference.
  139. IPv4/IPv6 addresses (generic, with port, flowinfo, scope):
  140. %pIS 1.2.3.4 or 0001:0002:0003:0004:0005:0006:0007:0008
  141. %piS 001.002.003.004 or 00010002000300040005000600070008
  142. %pISc 1.2.3.4 or 1:2:3:4:5:6:7:8
  143. %pISpc 1.2.3.4:12345 or [1:2:3:4:5:6:7:8]:12345
  144. %p[Ii]S[pfschnbl]
  145. For printing an IP address without the need to distinguish whether it's
  146. of type AF_INET or AF_INET6, a pointer to a valid 'struct sockaddr',
  147. specified through 'IS' or 'iS', can be passed to this format specifier.
  148. The additional 'p', 'f', and 's' specifiers are used to specify port
  149. (IPv4, IPv6), flowinfo (IPv6) and scope (IPv6). Ports have a ':' prefix,
  150. flowinfo a '/' and scope a '%', each followed by the actual value.
  151. In case of an IPv6 address the compressed IPv6 address as described by
  152. http://tools.ietf.org/html/rfc5952 is being used if the additional
  153. specifier 'c' is given. The IPv6 address is surrounded by '[', ']' in
  154. case of additional specifiers 'p', 'f' or 's' as suggested by
  155. https://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07
  156. In case of IPv4 addresses, the additional 'h', 'n', 'b', and 'l'
  157. specifiers can be used as well and are ignored in case of an IPv6
  158. address.
  159. Passed by reference.
  160. Further examples:
  161. %pISfc 1.2.3.4 or [1:2:3:4:5:6:7:8]/123456789
  162. %pISsc 1.2.3.4 or [1:2:3:4:5:6:7:8]%1234567890
  163. %pISpfc 1.2.3.4:12345 or [1:2:3:4:5:6:7:8]:12345/123456789
  164. UUID/GUID addresses:
  165. %pUb 00010203-0405-0607-0809-0a0b0c0d0e0f
  166. %pUB 00010203-0405-0607-0809-0A0B0C0D0E0F
  167. %pUl 03020100-0504-0706-0809-0a0b0c0e0e0f
  168. %pUL 03020100-0504-0706-0809-0A0B0C0E0E0F
  169. For printing 16-byte UUID/GUIDs addresses. The additional 'l', 'L',
  170. 'b' and 'B' specifiers are used to specify a little endian order in
  171. lower ('l') or upper case ('L') hex characters - and big endian order
  172. in lower ('b') or upper case ('B') hex characters.
  173. Where no additional specifiers are used the default big endian
  174. order with lower case hex characters will be printed.
  175. Passed by reference.
  176. dentry names:
  177. %pd{,2,3,4}
  178. %pD{,2,3,4}
  179. For printing dentry name; if we race with d_move(), the name might be
  180. a mix of old and new ones, but it won't oops. %pd dentry is a safer
  181. equivalent of %s dentry->d_name.name we used to use, %pd<n> prints
  182. n last components. %pD does the same thing for struct file.
  183. Passed by reference.
  184. struct va_format:
  185. %pV
  186. For printing struct va_format structures. These contain a format string
  187. and va_list as follows:
  188. struct va_format {
  189. const char *fmt;
  190. va_list *va;
  191. };
  192. Implements a "recursive vsnprintf".
  193. Do not use this feature without some mechanism to verify the
  194. correctness of the format string and va_list arguments.
  195. Passed by reference.
  196. struct clk:
  197. %pC pll1
  198. %pCn pll1
  199. For printing struct clk structures. '%pC' and '%pCn' print the name
  200. (Common Clock Framework) or address (legacy clock framework) of the
  201. structure.
  202. Passed by reference.
  203. bitmap and its derivatives such as cpumask and nodemask:
  204. %*pb 0779
  205. %*pbl 0,3-6,8-10
  206. For printing bitmap and its derivatives such as cpumask and nodemask,
  207. %*pb output the bitmap with field width as the number of bits and %*pbl
  208. output the bitmap as range list with field width as the number of bits.
  209. Passed by reference.
  210. Network device features:
  211. %pNF 0x000000000000c000
  212. For printing netdev_features_t.
  213. Passed by reference.
  214. Command from struct task_struct
  215. %pT ls
  216. For printing executable name excluding path from struct
  217. task_struct.
  218. Passed by reference.
  219. If you add other %p extensions, please extend lib/test_printf.c with
  220. one or more test cases, if at all feasible.
  221. Thank you for your cooperation and attention.
  222. By Randy Dunlap <rdunlap@infradead.org> and
  223. Andrew Murray <amurray@mpc-data.co.uk>