Back to home page

LXR

 
 

    


0001 If variable is of Type,         use printk format specifier:
0002 ---------------------------------------------------------
0003                 int                     %d or %x
0004                 unsigned int            %u or %x
0005                 long                    %ld or %lx
0006                 unsigned long           %lu or %lx
0007                 long long               %lld or %llx
0008                 unsigned long long      %llu or %llx
0009                 size_t                  %zu or %zx
0010                 ssize_t                 %zd or %zx
0011                 s32                     %d or %x
0012                 u32                     %u or %x
0013                 s64                     %lld or %llx
0014                 u64                     %llu or %llx
0015 
0016 If <type> is dependent on a config option for its size (e.g., sector_t,
0017 blkcnt_t) or is architecture-dependent for its size (e.g., tcflag_t), use a
0018 format specifier of its largest possible type and explicitly cast to it.
0019 Example:
0020 
0021         printk("test: sector number/total blocks: %llu/%llu\n",
0022                 (unsigned long long)sector, (unsigned long long)blockcount);
0023 
0024 Reminder: sizeof() result is of type size_t.
0025 
0026 The kernel's printf does not support %n. For obvious reasons, floating
0027 point formats (%e, %f, %g, %a) are also not recognized. Use of any
0028 unsupported specifier or length qualifier results in a WARN and early
0029 return from vsnprintf.
0030 
0031 Raw pointer value SHOULD be printed with %p. The kernel supports
0032 the following extended format specifiers for pointer types:
0033 
0034 Symbols/Function Pointers:
0035 
0036         %pF     versatile_init+0x0/0x110
0037         %pf     versatile_init
0038         %pS     versatile_init+0x0/0x110
0039         %pSR    versatile_init+0x9/0x110
0040                 (with __builtin_extract_return_addr() translation)
0041         %ps     versatile_init
0042         %pB     prev_fn_of_versatile_init+0x88/0x88
0043 
0044         For printing symbols and function pointers. The 'S' and 's' specifiers
0045         result in the symbol name with ('S') or without ('s') offsets. Where
0046         this is used on a kernel without KALLSYMS - the symbol address is
0047         printed instead.
0048 
0049         The 'B' specifier results in the symbol name with offsets and should be
0050         used when printing stack backtraces. The specifier takes into
0051         consideration the effect of compiler optimisations which may occur
0052         when tail-call's are used and marked with the noreturn GCC attribute.
0053 
0054         On ia64, ppc64 and parisc64 architectures function pointers are
0055         actually function descriptors which must first be resolved. The 'F' and
0056         'f' specifiers perform this resolution and then provide the same
0057         functionality as the 'S' and 's' specifiers.
0058 
0059 Kernel Pointers:
0060 
0061         %pK     0x01234567 or 0x0123456789abcdef
0062 
0063         For printing kernel pointers which should be hidden from unprivileged
0064         users. The behaviour of %pK depends on the kptr_restrict sysctl - see
0065         Documentation/sysctl/kernel.txt for more details.
0066 
0067 Struct Resources:
0068 
0069         %pr     [mem 0x60000000-0x6fffffff flags 0x2200] or
0070                 [mem 0x0000000060000000-0x000000006fffffff flags 0x2200]
0071         %pR     [mem 0x60000000-0x6fffffff pref] or
0072                 [mem 0x0000000060000000-0x000000006fffffff pref]
0073 
0074         For printing struct resources. The 'R' and 'r' specifiers result in a
0075         printed resource with ('R') or without ('r') a decoded flags member.
0076         Passed by reference.
0077 
0078 Physical addresses types phys_addr_t:
0079 
0080         %pa[p]  0x01234567 or 0x0123456789abcdef
0081 
0082         For printing a phys_addr_t type (and its derivatives, such as
0083         resource_size_t) which can vary based on build options, regardless of
0084         the width of the CPU data path. Passed by reference.
0085 
0086 DMA addresses types dma_addr_t:
0087 
0088         %pad    0x01234567 or 0x0123456789abcdef
0089 
0090         For printing a dma_addr_t type which can vary based on build options,
0091         regardless of the width of the CPU data path. Passed by reference.
0092 
0093 Raw buffer as an escaped string:
0094 
0095         %*pE[achnops]
0096 
0097         For printing raw buffer as an escaped string. For the following buffer
0098 
0099                 1b 62 20 5c 43 07 22 90 0d 5d
0100 
0101         few examples show how the conversion would be done (the result string
0102         without surrounding quotes):
0103 
0104                 %*pE            "\eb \C\a"\220\r]"
0105                 %*pEhp          "\x1bb \C\x07"\x90\x0d]"
0106                 %*pEa           "\e\142\040\\\103\a\042\220\r\135"
0107 
0108         The conversion rules are applied according to an optional combination
0109         of flags (see string_escape_mem() kernel documentation for the
0110         details):
0111                 a - ESCAPE_ANY
0112                 c - ESCAPE_SPECIAL
0113                 h - ESCAPE_HEX
0114                 n - ESCAPE_NULL
0115                 o - ESCAPE_OCTAL
0116                 p - ESCAPE_NP
0117                 s - ESCAPE_SPACE
0118         By default ESCAPE_ANY_NP is used.
0119 
0120         ESCAPE_ANY_NP is the sane choice for many cases, in particularly for
0121         printing SSIDs.
0122 
0123         If field width is omitted the 1 byte only will be escaped.
0124 
0125 Raw buffer as a hex string:
0126 
0127         %*ph    00 01 02  ...  3f
0128         %*phC   00:01:02: ... :3f
0129         %*phD   00-01-02- ... -3f
0130         %*phN   000102 ... 3f
0131 
0132         For printing a small buffers (up to 64 bytes long) as a hex string with
0133         certain separator. For the larger buffers consider to use
0134         print_hex_dump().
0135 
0136 MAC/FDDI addresses:
0137 
0138         %pM     00:01:02:03:04:05
0139         %pMR    05:04:03:02:01:00
0140         %pMF    00-01-02-03-04-05
0141         %pm     000102030405
0142         %pmR    050403020100
0143 
0144         For printing 6-byte MAC/FDDI addresses in hex notation. The 'M' and 'm'
0145         specifiers result in a printed address with ('M') or without ('m') byte
0146         separators. The default byte separator is the colon (':').
0147 
0148         Where FDDI addresses are concerned the 'F' specifier can be used after
0149         the 'M' specifier to use dash ('-') separators instead of the default
0150         separator.
0151 
0152         For Bluetooth addresses the 'R' specifier shall be used after the 'M'
0153         specifier to use reversed byte order suitable for visual interpretation
0154         of Bluetooth addresses which are in the little endian order.
0155 
0156         Passed by reference.
0157 
0158 IPv4 addresses:
0159 
0160         %pI4    1.2.3.4
0161         %pi4    001.002.003.004
0162         %p[Ii]4[hnbl]
0163 
0164         For printing IPv4 dot-separated decimal addresses. The 'I4' and 'i4'
0165         specifiers result in a printed address with ('i4') or without ('I4')
0166         leading zeros.
0167 
0168         The additional 'h', 'n', 'b', and 'l' specifiers are used to specify
0169         host, network, big or little endian order addresses respectively. Where
0170         no specifier is provided the default network/big endian order is used.
0171 
0172         Passed by reference.
0173 
0174 IPv6 addresses:
0175 
0176         %pI6    0001:0002:0003:0004:0005:0006:0007:0008
0177         %pi6    00010002000300040005000600070008
0178         %pI6c   1:2:3:4:5:6:7:8
0179 
0180         For printing IPv6 network-order 16-bit hex addresses. The 'I6' and 'i6'
0181         specifiers result in a printed address with ('I6') or without ('i6')
0182         colon-separators. Leading zeros are always used.
0183 
0184         The additional 'c' specifier can be used with the 'I' specifier to
0185         print a compressed IPv6 address as described by
0186         http://tools.ietf.org/html/rfc5952
0187 
0188         Passed by reference.
0189 
0190 IPv4/IPv6 addresses (generic, with port, flowinfo, scope):
0191 
0192         %pIS    1.2.3.4         or 0001:0002:0003:0004:0005:0006:0007:0008
0193         %piS    001.002.003.004 or 00010002000300040005000600070008
0194         %pISc   1.2.3.4         or 1:2:3:4:5:6:7:8
0195         %pISpc  1.2.3.4:12345   or [1:2:3:4:5:6:7:8]:12345
0196         %p[Ii]S[pfschnbl]
0197 
0198         For printing an IP address without the need to distinguish whether it's
0199         of type AF_INET or AF_INET6, a pointer to a valid 'struct sockaddr',
0200         specified through 'IS' or 'iS', can be passed to this format specifier.
0201 
0202         The additional 'p', 'f', and 's' specifiers are used to specify port
0203         (IPv4, IPv6), flowinfo (IPv6) and scope (IPv6). Ports have a ':' prefix,
0204         flowinfo a '/' and scope a '%', each followed by the actual value.
0205 
0206         In case of an IPv6 address the compressed IPv6 address as described by
0207         http://tools.ietf.org/html/rfc5952 is being used if the additional
0208         specifier 'c' is given. The IPv6 address is surrounded by '[', ']' in
0209         case of additional specifiers 'p', 'f' or 's' as suggested by
0210         https://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07
0211 
0212         In case of IPv4 addresses, the additional 'h', 'n', 'b', and 'l'
0213         specifiers can be used as well and are ignored in case of an IPv6
0214         address.
0215 
0216         Passed by reference.
0217 
0218         Further examples:
0219 
0220         %pISfc          1.2.3.4         or [1:2:3:4:5:6:7:8]/123456789
0221         %pISsc          1.2.3.4         or [1:2:3:4:5:6:7:8]%1234567890
0222         %pISpfc         1.2.3.4:12345   or [1:2:3:4:5:6:7:8]:12345/123456789
0223 
0224 UUID/GUID addresses:
0225 
0226         %pUb    00010203-0405-0607-0809-0a0b0c0d0e0f
0227         %pUB    00010203-0405-0607-0809-0A0B0C0D0E0F
0228         %pUl    03020100-0504-0706-0809-0a0b0c0e0e0f
0229         %pUL    03020100-0504-0706-0809-0A0B0C0E0E0F
0230 
0231         For printing 16-byte UUID/GUIDs addresses. The additional 'l', 'L',
0232         'b' and 'B' specifiers are used to specify a little endian order in
0233         lower ('l') or upper case ('L') hex characters - and big endian order
0234         in lower ('b') or upper case ('B') hex characters.
0235 
0236         Where no additional specifiers are used the default big endian
0237         order with lower case hex characters will be printed.
0238 
0239         Passed by reference.
0240 
0241 dentry names:
0242 
0243         %pd{,2,3,4}
0244         %pD{,2,3,4}
0245 
0246         For printing dentry name; if we race with d_move(), the name might be
0247         a mix of old and new ones, but it won't oops.  %pd dentry is a safer
0248         equivalent of %s dentry->d_name.name we used to use, %pd<n> prints
0249         n last components.  %pD does the same thing for struct file.
0250 
0251         Passed by reference.
0252 
0253 block_device names:
0254 
0255         %pg     sda, sda1 or loop0p1
0256 
0257         For printing name of block_device pointers.
0258 
0259 struct va_format:
0260 
0261         %pV
0262 
0263         For printing struct va_format structures. These contain a format string
0264         and va_list as follows:
0265 
0266         struct va_format {
0267                 const char *fmt;
0268                 va_list *va;
0269         };
0270 
0271         Implements a "recursive vsnprintf".
0272 
0273         Do not use this feature without some mechanism to verify the
0274         correctness of the format string and va_list arguments.
0275 
0276         Passed by reference.
0277 
0278 struct clk:
0279 
0280         %pC     pll1
0281         %pCn    pll1
0282         %pCr    1560000000
0283 
0284         For printing struct clk structures. '%pC' and '%pCn' print the name
0285         (Common Clock Framework) or address (legacy clock framework) of the
0286         structure; '%pCr' prints the current clock rate.
0287 
0288         Passed by reference.
0289 
0290 bitmap and its derivatives such as cpumask and nodemask:
0291 
0292         %*pb    0779
0293         %*pbl   0,3-6,8-10
0294 
0295         For printing bitmap and its derivatives such as cpumask and nodemask,
0296         %*pb output the bitmap with field width as the number of bits and %*pbl
0297         output the bitmap as range list with field width as the number of bits.
0298 
0299         Passed by reference.
0300 
0301 Flags bitfields such as page flags, gfp_flags:
0302 
0303         %pGp    referenced|uptodate|lru|active|private
0304         %pGg    GFP_USER|GFP_DMA32|GFP_NOWARN
0305         %pGv    read|exec|mayread|maywrite|mayexec|denywrite
0306 
0307         For printing flags bitfields as a collection of symbolic constants that
0308         would construct the value. The type of flags is given by the third
0309         character. Currently supported are [p]age flags, [v]ma_flags (both
0310         expect unsigned long *) and [g]fp_flags (expects gfp_t *). The flag
0311         names and print order depends on the particular type.
0312 
0313         Note that this format should not be used directly in TP_printk() part
0314         of a tracepoint. Instead, use the show_*_flags() functions from
0315         <trace/events/mmflags.h>.
0316 
0317         Passed by reference.
0318 
0319 Network device features:
0320 
0321         %pNF    0x000000000000c000
0322 
0323         For printing netdev_features_t.
0324 
0325         Passed by reference.
0326 
0327 If you add other %p extensions, please extend lib/test_printf.c with
0328 one or more test cases, if at all feasible.
0329 
0330 
0331 Thank you for your cooperation and attention.
0332 
0333 
0334 By Randy Dunlap <rdunlap@infradead.org> and
0335 Andrew Murray <amurray@mpc-data.co.uk>