读取内核空间中的符号链接 [英] Reading a symbolic link in kernel-space
问题描述
我正在编写LKM,需要找出特定符号链接指向的位置.基本上,我需要系统调用readlinkat
(或readlink
)的功能,但要在内核空间中.有没有简单的方法可以做到这一点?
I'm writing a LKM and need to find out where a specific symlink is pointing to. Basically I need the functionality of the syscall readlinkat
(or readlink
) but in kernel-space. Is there an easy way to do this?
直接使用readlinkat
对我不起作用,我总是得到EFAULT(我想这是因为我的缓冲区显然在内核内存空间中,而不在用户空间中).
Using readlinkat
directly is not working for me, I'm always getting EFAULT (I guess this is because my buffer is obviously in kernel memory space and not in user-space).
推荐答案
首先,您不能直接在内核模块中使用用户空间系统调用(readlinkat()
或readlink()
).而是需要在内核空间中使用导出的函数/符号.
Firstly, you can't use user space system calls(readlinkat()
or readlink()
) directly in your kernel module. Rather you need to use exported function / symbol within the kernel space.
接下来,可能要研究结构inode_operations 特定于您正在使用的文件系统.还要查看内部调用vfs_readlink()
的 generic_readlink()
.
Next, may want to look into the struct inode_operations specific to the file system which you are using. Also look into generic_readlink()
which internally call vfs_readlink()
.
这篇关于读取内核空间中的符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!