Linux, 工作, 生活, 家人

Linux

Linux kernel printk 參數.

Kernek printk 參數預設如下

If variable is of Type, use printk format specifier:
———————————————————
int %d or %x
unsigned int %u or %x
long %ld or %lx
unsigned long %lu or %lx
long long %lld or %llx
unsigned long long %llu or %llx
size_t %zu or %zx
ssize_t %zd or %zx
Raw pointer value SHOULD be printed with %p.

u64 SHOULD be printed with %llu/%llx, (unsigned long long):
printk(“%llu”, (unsigned long long)u64_var);
s64 SHOULD be printed with %lld/%llx, (long long):
printk(“%lld”, (long long)s64_var);

追了一下 kernel

難道就這樣了嗎?
2.26.29 發現有加一個新參數
%pM : 印出 MAC Address
仔細看了一下, printk 用 %p 做為 extension

‘F’ For symbolic function descriptor pointers with offset
‘f’ For simple symbolic function names without offset
‘S’ For symbolic direct pointers with offset
‘s’ For symbolic direct pointers without offset
‘R’ For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
‘r’ For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
‘M’ For a 6-byte MAC address, it prints the address in the
usual colon-separated hex notation
‘m’ For a 6-byte MAC address, it prints the hex address without colons
‘MF’ For a 6-byte MAC FDDI address, it prints the address
with a dash-separated hex notation
‘I’ [46] for IPv4/IPv6 addresses printed in the usual way
IPv4 uses dot-separated decimal without leading 0’s (1.2.3.4)
IPv6 uses colon separated network-order 16 bit hex with leading 0’s
‘i’ [46] for ‘raw’ IPv4/IPv6 addresses
IPv6 omits the colons (01020304…0f)
IPv4 uses dot-separated decimal with leading 0’s (010.123.045.006)
‘[Ii]4[hnbl]’ IPv4 addresses in host, network, big or little endian order
‘I6c’ for IPv6 addresses printed as specified by
http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-00
‘U’ For a 16 byte UUID/GUID, it prints the UUID/GUID in the form
“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
Options for %pU are:
b big endian lower case hex (default)
B big endian UPPER case hex
l little endian lower case hex
L little endian UPPER case hex
big endian output byte order is:
[0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15]
little endian output byte order is:
[3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15]
Note: The difference between ‘S’ and ‘F’ is that on ia64 and ppc64
function pointers are really function descriptors, which contain a
pointer to the real address.

還不錯用. 以後可以直接用了…..

發佈留言