sys_readlink失败EFAULT-替代 [英] sys_readlink fails EFAULT - alternative

查看:266
本文介绍了sys_readlink失败EFAULT-替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件描述符,并希望得到真实路径.目前,我叫sys_readlink 其工作的时候,但是往往我得到一个错误-14(-EFAULT).

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).

下面一些代码:

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?

推荐答案

这在任务结构,例如在filep得到它像

Get it from the filep in the task struct, e.g. something like

struct task_struct *task;
struct files_struct *files;
struct file *file;
char buf[buflen], *realpath;

task = current /* or some other task */;
get_task_struct(task);
files = get_files_struct(task);
put_task_struct(task);
spin_lock(&files->file_lock);
file = fcheck_files(files, fdno);
realpath = d_path(file->f_path, buf, buflen);
spin_unlock(&files->file_lock);
put_files_struct(files);

错误处理消隐为了简洁.

Error handling elided for brevity.

这篇关于sys_readlink失败EFAULT-替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆