[英]How to get default kernel module name from *.ko files?
Usually, the filename of a kernel module is the same as the module name. 通常,内核模块的文件名与模块名称相同。 For example, after doing
insmod fuse.ko
, I can see fuse
inserted in /proc/modules
. 例如,在执行
insmod fuse.ko
,我可以看到在/proc/modules
插入了fuse
。
However, renaming the kernel module ( mv fuse.ko foo.ko
) doesn't affect the inserted module name. 但是,重命名内核模块(
mv fuse.ko foo.ko
)不会影响插入的模块名称。 Doing insmod foo.ko
still inserts fuse
in /proc/modules
. 进行
insmod foo.ko
仍会将fuse
插入/proc/modules
。
Is there any system call or glibc function that can extract the module name from a kernel module file? 是否有任何系统调用或glibc函数可以从内核模块文件中提取模块名称? In the previous example, I want to extract the name
fuse
from foo.ko
. 在前面的示例中,我想从
foo.ko
提取名称fuse
。
Name of the module is contained in THIS_MODULE module object (of type struct module
). 模块的名称包含在THIS_MODULE模块对象(类型
struct module
)中。 This object is stored in the kernel module file as a section .gnu.linkonce.this_module
. 该对象作为
.gnu.linkonce.this_module
部分存储在内核模块文件中。
So, you may examine content of that section and find module's name there: 因此,您可以检查该部分的内容并在其中找到模块的名称:
objdump -s -j .gnu.linkonce.this_module foo.ko
or 要么
readelf -x .gnu.linkonce.this_module foo.ko
Module name is located at offset 12 (on 32-bit machine) or at offset 24 (on 64-bit machine). 模块名称位于偏移量12(在32位计算机上)或偏移量24(在64位计算机上)。
modinfo
doesn't print module's name. modinfo
不打印模块的名称。 Probably, this is because offset of the name in the struct module
structure is not standardized. 可能是因为在
struct module
结构中名称的偏移量未标准化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.