获取内核代码中的当前工作目录 [英] Getting current working directory within kernel code

查看:137
本文介绍了获取内核代码中的当前工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,我需要知道目前可调用系统调用的可执行文件的工作目录。我认为这样的一些系统调用,如 open 将会使用这些信息。



你能告诉我如何获取字符串中当前的工作目录路径?

解决方案

您可以看看 getcwd 系统调用是如何实现的,看看如何做到这一点。



该系统调用在 fs / dcache.c 并调用:

  get_fs_root_and_pwd(current-> fs,& root,& pwd); 

pwd 结构路径变量,



该函数定义为内联函数 include / linux / fs_struct.h ,其中还包含:

  static inline void get_fs_pwd(struct fs_struct * fs,struct path * pwd)

这似乎是你之后。


I am working on a project in which I need to know the current working directory of the executable which called the system call. I think it would be possible as some system calls like open would make use of that information.

Could you please tell how I can get the current working directory path in a string?

解决方案

You can look at how the getcwd syscall is implemented to see how to do that.

That syscall is in fs/dcache.c and calls:

get_fs_root_and_pwd(current->fs, &root, &pwd);

root and pwd are struct path variables,

That function is defined as an inline function in include/linux/fs_struct.h, which also contains:

static inline void get_fs_pwd(struct fs_struct *fs, struct path *pwd)

and that seems to be what you are after.

这篇关于获取内核代码中的当前工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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