[英]Create a symlink to a file in kernel module
I am trying to create a symbolic link to a file in a Linux kernel module. 我试图在Linux内核模块中创建到文件的符号链接。 With the following code, I have created a directory in
sys/kernel
and then created a file in that directory: 使用以下代码,我在
sys/kernel
创建了一个目录,然后在该目录中创建了一个文件:
// Create the base directory in sys/kernel
if (!(pmd_kobjSysKernelDir =
kobject_create_and_add(PMD_DRIVER_NAME, kernel_kobj)))
return -ENODEV;
if ((retVal = sysfs_create_file(
pmd_kobjSysKernelDir, &dev_attr_sysfs.attr)))
{
dev_err(&client->dev,
"couldn't create %s file \n", dev_attr_sysfs.attr.name);
return retVal;
}
Now I am trying to create a symbolic link to the file, that is represented by the dev_attr_sysfs
structure. 现在,我正在尝试创建到文件的符号链接,该链接由
dev_attr_sysfs
结构表示。 The problem is, I only found sysfs_create_link
function, which seems to be able to create only directory symbolic links (I think). 问题是,我只找到了
sysfs_create_link
函数,该函数似乎只能创建目录符号链接(我认为)。 Is there a way to use it in order to create a symbolic link to a file? 有没有一种方法可以使用它来创建到文件的符号链接? If not, is there any other dedicated function?
如果没有,还有其他专用功能吗?
You can directly call sys_symlink
or sys_symlinkat
. 您可以直接调用
sys_symlink
或sys_symlinkat
。 Or it is better to look in implementation file fs/namei.c
. 或者最好查看实现文件
fs/namei.c
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.