sys_readlink 失败 EFAULT - 替代方案
我有文件描述符并且想获取真实路径。目前我调用 sys_readlink /proc/self/fd/
有时有效,但我经常收到错误 -14 (-EFAULT)。
这里有一些代码:
fs = get_fs();
set_fs(KERNEL_DS);
err = sys_readlink(path, buf, size-1);
set_fs(fs);
是否有替代(可能更好)的方法从内核获取真实路径?
I have the filedescriptor and like to get the real path. Currently i call sys_readlink /proc/self/fd/<fd>
which works sometimes, but often i get an error -14 (-EFAULT).
Here some Code:
fs = get_fs();
set_fs(KERNEL_DS);
err = sys_readlink(path, buf, size-1);
set_fs(fs);
Is there an alternative (probably better) way to get the realpath from kernel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从任务结构中的 filep 获取它,例如为
简洁起见,省略了错误处理之类的内容。
Get it from the filep in the task struct, e.g. something like
Error handling elided for brevity.
-EFAULT 表示“buf”指针有问题。你先分配内存了吗?
编辑:看起来您正在内核模式下编程。事实证明,“真实”路径在内核模式下毫无意义。
-EFAULT means something's wrong with the "buf" pointer. Did you allocate memory first?
EDIT: It looks like you are programming in kernel mode. It turns out "the" real path is meaningless in kernel mode.