printk格式中p的百分比[p]的含义

时间:2016-08-17 20:21:07

标签: c linux linux-kernel linux-device-driver device-driver

问题在于printk格式。我正在阅读的文档位于here

以下是我要问的摘录:

Physical addresses types phys_addr_t:

    %pa[p]  0x01234567 or 0x0123456789abcdef

    For printing a phys_addr_t type (and its derivatives, such as
    resource_size_t) which can vary based on build options, regardless of
    the width of the CPU data path. Passed by reference.

[p]中的%pa[p]代表什么?这是什么意思?

1 个答案:

答案 0 :(得分:5)

p中的[p]代表<{>} phys_addr_t ,用于%pap。这类似于d中的%pad代表 dma_addr_t ,如引用文档中所示:

DMA addresses types dma_addr_t:

    %pad    0x01234567 or 0x0123456789abcdef

    For printing a dma_addr_t type which can vary based on build options,
    regardless of the width of the CPU data path. Passed by reference.

由于%pa%pap之间没有记录的差异,这意味着它们的行为相同。括号内的内容表示可选修饰符。这可以在文档后面的%*pE定义中看到:

Raw buffer as an escaped string:

    %*pE[achnops]
...
    The conversion rules are applied according to an optional combination
    of flags (see string_escape_mem() kernel documentation for the
    details):
        a - ESCAPE_ANY
        c - ESCAPE_SPECIAL
        h - ESCAPE_HEX
        n - ESCAPE_NULL
        o - ESCAPE_OCTAL
        p - ESCAPE_NP
        s - ESCAPE_SPACE
    By default ESCAPE_ANY_NP is used.