【发布时间】:2012-05-03 12:48:18
【问题描述】:
美好的一天。我试图从结构文件中获取完整路径
char *buf = (char*)__get_free_page(GFP_USER);
char *buf2 = (char*)__get_free_page(GFP_USER);
char *name = dentry_path(file->f_dentry, buf, PAGE_SIZE);
char *root = dentry_path(file->f_vfsmnt->mnt_mountpoint, buf2, PAGE_SIZE);
***some operations***
free_page((unsigned long)buf);
free_page((unsigned long)buf2);
kfree(*root);
kfree(*name);
但我得到一个错误 fs/read_write.c:707: 错误:请求成员 'mnt_mountpoint' 在不是结构或联合的东西中
如何从文件中获取 vsfmount 结构体?
内核版本linux-2.6.37.6
【问题讨论】:
-
有什么区别吗?据我了解,系统中的任何文件都可以显示为结构文件。结构文件 { 联合 { 结构 list_head fu_list;结构 rcu_head fu_rcuhead; } f_u;结构路径 f_path; #define f_dentry f_path.dentry #define f_vfsmnt f_path.mnt
-
您的代码似乎没有遵循内核版本。看看
include/linux/fs.h、include/linux/path.h和fs/mount.h。您需要将container_of用于f_vfsmnt,它现在是私有mount结构的一部分。 -
Ilya,内核版本是 linux-2.6.37.6。结构文件具有结构路径 f_path;并定义了路径的mnt链接-#define f_vfsmnt f_path.mnt,mnt本身有mnt_root和mnt_mountpoint
-
您可以尝试在
read_write.c中添加#include <linux/mount.h>进行检查吗? -
哦,我明白了!没有。谢谢你。
标签: linux-kernel kernel-module