printk-formats.txt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. Raw pointer value SHOULD be printed with %p. The kernel supports
  12. the following extended format specifiers for pointer types:
  13. Symbols/Function Pointers:
  14. %pF versatile_init+0x0/0x110
  15. %pf versatile_init
  16. %pS versatile_init+0x0/0x110
  17. %pSR versatile_init+0x9/0x110
  18. (with __builtin_extract_return_addr() translation)
  19. %ps versatile_init
  20. %pB prev_fn_of_versatile_init+0x88/0x88
  21. For printing symbols and function pointers. The 'S' and 's' specifiers
  22. result in the symbol name with ('S') or without ('s') offsets. Where
  23. this is used on a kernel without KALLSYMS - the symbol address is
  24. printed instead.
  25. The 'B' specifier results in the symbol name with offsets and should be
  26. used when printing stack backtraces. The specifier takes into
  27. consideration the effect of compiler optimisations which may occur
  28. when tail-call's are used and marked with the noreturn GCC attribute.
  29. On ia64, ppc64 and parisc64 architectures function pointers are
  30. actually function descriptors which must first be resolved. The 'F' and
  31. 'f' specifiers perform this resolution and then provide the same
  32. functionality as the 'S' and 's' specifiers.
  33. Kernel Pointers:
  34. %pK 0x01234567 or 0x0123456789abcdef
  35. For printing kernel pointers which should be hidden from unprivileged
  36. users. The behaviour of %pK depends on the kptr_restrict sysctl - see
  37. Documentation/sysctl/kernel.txt for more details.
  38. Struct Resources:
  39. %pr [mem 0x60000000-0x6fffffff flags 0x2200] or
  40. [mem 0x0000000060000000-0x000000006fffffff flags 0x2200]
  41. %pR [mem 0x60000000-0x6fffffff pref] or
  42. [mem 0x0000000060000000-0x000000006fffffff pref]
  43. For printing struct resources. The 'R' and 'r' specifiers result in a
  44. printed resource with ('R') or without ('r') a decoded flags member.
  45. Physical addresses:
  46. %pa 0x01234567 or 0x0123456789abcdef
  47. For printing a phys_addr_t type (and its derivatives, such as
  48. resource_size_t) which can vary based on build options, regardless of
  49. the width of the CPU data path. Passed by reference.
  50. Raw buffer as a hex string:
  51. %*ph 00 01 02 ... 3f
  52. %*phC 00:01:02: ... :3f
  53. %*phD 00-01-02- ... -3f
  54. %*phN 000102 ... 3f
  55. For printing a small buffers (up to 64 bytes long) as a hex string with
  56. certain separator. For the larger buffers consider to use
  57. print_hex_dump().
  58. MAC/FDDI addresses:
  59. %pM 00:01:02:03:04:05
  60. %pMR 05:04:03:02:01:00
  61. %pMF 00-01-02-03-04-05
  62. %pm 000102030405
  63. %pmR 050403020100
  64. For printing 6-byte MAC/FDDI addresses in hex notation. The 'M' and 'm'
  65. specifiers result in a printed address with ('M') or without ('m') byte
  66. separators. The default byte separator is the colon (':').
  67. Where FDDI addresses are concerned the 'F' specifier can be used after
  68. the 'M' specifier to use dash ('-') separators instead of the default
  69. separator.
  70. For Bluetooth addresses the 'R' specifier shall be used after the 'M'
  71. specifier to use reversed byte order suitable for visual interpretation
  72. of Bluetooth addresses which are in the little endian order.
  73. IPv4 addresses:
  74. %pI4 1.2.3.4
  75. %pi4 001.002.003.004
  76. %p[Ii]4[hnbl]
  77. For printing IPv4 dot-separated decimal addresses. The 'I4' and 'i4'
  78. specifiers result in a printed address with ('i4') or without ('I4')
  79. leading zeros.
  80. The additional 'h', 'n', 'b', and 'l' specifiers are used to specify
  81. host, network, big or little endian order addresses respectively. Where
  82. no specifier is provided the default network/big endian order is used.
  83. IPv6 addresses:
  84. %pI6 0001:0002:0003:0004:0005:0006:0007:0008
  85. %pi6 00010002000300040005000600070008
  86. %pI6c 1:2:3:4:5:6:7:8
  87. For printing IPv6 network-order 16-bit hex addresses. The 'I6' and 'i6'
  88. specifiers result in a printed address with ('I6') or without ('i6')
  89. colon-separators. Leading zeros are always used.
  90. The additional 'c' specifier can be used with the 'I' specifier to
  91. print a compressed IPv6 address as described by
  92. http://tools.ietf.org/html/rfc5952
  93. IPv4/IPv6 addresses (generic, with port, flowinfo, scope):
  94. %pIS 1.2.3.4 or 0001:0002:0003:0004:0005:0006:0007:0008
  95. %piS 001.002.003.004 or 00010002000300040005000600070008
  96. %pISc 1.2.3.4 or 1:2:3:4:5:6:7:8
  97. %pISpc 1.2.3.4:12345 or [1:2:3:4:5:6:7:8]:12345
  98. %p[Ii]S[pfschnbl]
  99. For printing an IP address without the need to distinguish whether it's
  100. of type AF_INET or AF_INET6, a pointer to a valid 'struct sockaddr',
  101. specified through 'IS' or 'iS', can be passed to this format specifier.
  102. The additional 'p', 'f', and 's' specifiers are used to specify port
  103. (IPv4, IPv6), flowinfo (IPv6) and scope (IPv6). Ports have a ':' prefix,
  104. flowinfo a '/' and scope a '%', each followed by the actual value.
  105. In case of an IPv6 address the compressed IPv6 address as described by
  106. http://tools.ietf.org/html/rfc5952 is being used if the additional
  107. specifier 'c' is given. The IPv6 address is surrounded by '[', ']' in
  108. case of additional specifiers 'p', 'f' or 's' as suggested by
  109. https://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07
  110. In case of IPv4 addresses, the additional 'h', 'n', 'b', and 'l'
  111. specifiers can be used as well and are ignored in case of an IPv6
  112. address.
  113. Further examples:
  114. %pISfc 1.2.3.4 or [1:2:3:4:5:6:7:8]/123456789
  115. %pISsc 1.2.3.4 or [1:2:3:4:5:6:7:8]%1234567890
  116. %pISpfc 1.2.3.4:12345 or [1:2:3:4:5:6:7:8]:12345/123456789
  117. UUID/GUID addresses:
  118. %pUb 00010203-0405-0607-0809-0a0b0c0d0e0f
  119. %pUB 00010203-0405-0607-0809-0A0B0C0D0E0F
  120. %pUl 03020100-0504-0706-0809-0a0b0c0e0e0f
  121. %pUL 03020100-0504-0706-0809-0A0B0C0E0E0F
  122. For printing 16-byte UUID/GUIDs addresses. The additional 'l', 'L',
  123. 'b' and 'B' specifiers are used to specify a little endian order in
  124. lower ('l') or upper case ('L') hex characters - and big endian order
  125. in lower ('b') or upper case ('B') hex characters.
  126. Where no additional specifiers are used the default little endian
  127. order with lower case hex characters will be printed.
  128. dentry names:
  129. %pd{,2,3,4}
  130. %pD{,2,3,4}
  131. For printing dentry name; if we race with d_move(), the name might be
  132. a mix of old and new ones, but it won't oops. %pd dentry is a safer
  133. equivalent of %s dentry->d_name.name we used to use, %pd<n> prints
  134. n last components. %pD does the same thing for struct file.
  135. struct va_format:
  136. %pV
  137. For printing struct va_format structures. These contain a format string
  138. and va_list as follows:
  139. struct va_format {
  140. const char *fmt;
  141. va_list *va;
  142. };
  143. Do not use this feature without some mechanism to verify the
  144. correctness of the format string and va_list arguments.
  145. u64 SHOULD be printed with %llu/%llx, (unsigned long long):
  146. printk("%llu", u64_var);
  147. s64 SHOULD be printed with %lld/%llx, (long long):
  148. printk("%lld", s64_var);
  149. If <type> is dependent on a config option for its size (e.g., sector_t,
  150. blkcnt_t) or is architecture-dependent for its size (e.g., tcflag_t), use a
  151. format specifier of its largest possible type and explicitly cast to it.
  152. Example:
  153. printk("test: sector number/total blocks: %llu/%llu\n",
  154. (unsigned long long)sector, (unsigned long long)blockcount);
  155. Reminder: sizeof() result is of type size_t.
  156. Thank you for your cooperation and attention.
  157. By Randy Dunlap <rdunlap@infradead.org> and
  158. Andrew Murray <amurray@mpc-data.co.uk>