内核如何在DMESG中打印块设备的分区?
在添加内核启动或块设备上,它打印了块设备的分区,例如:
[ 4.168995] nvme0n1: p1 p2
[ 4.202666] nvme2n1: p1
[ 4.228494] nvme1n1: p1
[ 5.104852] sda: sda1 sda2
[ 5.681698] sdc: sdc1 sdc2
[ 5.717981] sde: sde1 sde2
[ 5.718320] sdb: sdb1
[ 5.727097] sdd: sdd1 sdd2
我想知道这些邮件在哪个内核代码中打印。
On kernel boot or block device added, it prints the partitions of block devices like:
[ 4.168995] nvme0n1: p1 p2
[ 4.202666] nvme2n1: p1
[ 4.228494] nvme1n1: p1
[ 5.104852] sda: sda1 sda2
[ 5.681698] sdc: sdc1 sdc2
[ 5.717981] sde: sde1 sde2
[ 5.718320] sdb: sdb1
[ 5.727097] sdd: sdd1 sdd2
I'd like to know in which piece of kernel code these messages are printed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我找到了答案(用于内核5.17)。
此消息在
block/partitions/core.c:check_partition()
中打印,但由多个函数生成。首先,它为pp_buf
分配一个页面以保存消息,并将块名为“”。以nvme0
为例。对于以
nvme0
或nbd0
之类的数字结尾的块设备,它将名称替换为p
后,将设备打印到缓冲区。然后,它调用
check_part []
中的函数以检查块设备是否具有支持的分区表。在这里,我将EFI(GPT)作为示例。该函数循环分区表条目和调用put_partition()
将分区附加到pp_buf
。put_partition()
(在block/partitions/check.h
中)使用设备名称和分区索引来形成分区名称。循环后,它将
\ n
附加到pp_buf
并返回到check_partition()
,然后打印pp_buf
,pp_buf ,提供我们在DMESG中看到的消息。I think I've found the answer (for kernel 5.17).
This message is printed in
block/partitions/core.c:check_partition()
, but it is generated by multiple functions. First it allocates a page forpp_buf
to hold the message, and puts the block name to it. Takingnvme0
as an example.For block devices ending with digits like
nvme0
ornbd0
, it replaces the name top
after printing the device to buffer.Then it calls the funtions in
check_part[]
to check if the block device has a supported partition table. Here I use efi (GPT) as the example. The function loops the partition table entries and callsput_partition()
to append partitions topp_buf
.put_partition()
(inblock/partitions/check.h
) uses the device name and partition index to form the partition name.After the loop, it appends
\n
to thepp_buf
and returns tocheck_partition()
, then printspp_buf
, giving the message we saw in dmesg.