如何解决在内核代码中获取当前目录的示例
此answer向我们展示了内核代码中当前的工作目录。我尝试在我的模块中实施此操作,但没有成功,我确实需要有人与我分享上述答案的完整程序。因为我真的不知道如何使用上面的答案以及如何实现它。
我尝试了以下操作:
我需要在get_fs_pwd
函数中使用哪个结构,pwd
参数是什么?答案没有提供如何真正获得cwd
的示例。
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs_struct.h>
MODULE_LICENSE("GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello,World\n");
get_fs_pwd(); // which struct do I need to use,and what is the pwd argument?
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye,cruel world.\n");
}
module_init(hello_init);
module_exit(hello_exit);
static inline void get_fs_pwd(struct fs_struct *fs,struct path *pwd)
{
spin_lock(&fs->lock);
*pwd = fs->pwd;
path_get(pwd);
spin_unlock(&fs->lock);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。