vfs_stat()调用有什么问题? [英] What's wrong with vfs_stat() call?
本文介绍了vfs_stat()调用有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试对文件进行统计,
I'm trying to do a stat on files,
struct kstat stat;
int error = vfs_stat ("/bin/ls", &stat); // /bin/ls exists
if (error)
{
printk (KERN_INFO "error code %d\n", error);
}
else
{
printk (KERN_INFO "mode of ls: %o\n", stat.mode);
printk (KERN_INFO "owner of ls: %o\n", stat.uid);
}
return error;
但是错误总是设置为14
(错误地址),代码出了什么问题?
But error was always set to 14
(Bad Address), what's wrong with the code?
我正在运行3.9内核.
I'm running 3.9 kernel.
推荐答案
# define __user __attribute__((noderef, address_space(1)))
换句话说,vfs_stat()
仅支持使用指向用户空间的指针的文件名,并且不应在内核空间内取消引用.请注意,"/bin/ls"
并不指向用户空间,而是指向内核空间,因此不能在此处使用.
In other words, vfs_stat()
only supports using filename that is pointer into user space, and should not be dereferenced inside kernel space. Note that "/bin/ls"
does NOT point into user space, but into kernel space, and thus cannot be used here.
实际上,错误消息14(错误的地址)告诉您这个问题:)
Actually, error message 14 (bad address) tells this issue right into your face :)
这篇关于vfs_stat()调用有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文