vfs_read 在某些机器上面返回-14 读取文件 EFAULT
vfs_read 在某些机器上面返回-14 读取文件 EFAULT代码如下
mm_segment_t oldfs_;
int ret_ = 0;
struct inode *inode_ = NULL;
char *data_ = NULL;
loff_t size_ = 0;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0)
inode_ = file_inode(f);
#else
inode_ = f->f_dentry->d_inode;
#endif
*size = inode_->i_size;
size_ = *size;
*data = (char*) kmalloc(size_ + 1, GFP_ATOMIC);
data_ = *data;
oldfs_ = get_fs();
set_fs(get_ds());
f->f_pos=0;//f->f_op->llseek(f,0,0);//调整初始位置
ret_ = vfs_read(f, data_, size_, &f->f_pos);
set_fs(oldfs_);
//pr_info("httplistCannot read \"%d,%d,%d,%d\"\n", ret_,EBADF,EINVAL,EFAULT);
if (ret_ < 0){
pr_info("Cannot read \"%d\"\n", ret_);
return false;
}
请问各位,这个一般是什么地方出问题了呢? 非常感谢 找了很久没有找到答案 本地机器可以服务器不可以然后服务器上面用内核源码编译了一下这个模块 也不行的 不知道什么原因
理论上当set_fs(get_ds());之后,vfs read不会返回-14,
有点怀疑*data = (char*) kmalloc(size_ + 1, GFP_ATOMIC);
代码贴全一点?
输入参数是多少? 镇水铁牛 发表于 2015-12-07 20:08 static/image/common/back.gif
理论上当set_fs(get_ds());之后,vfs read不会返回-14,
有点怀疑*data = (char*) kmalloc(size_ + 1, GFP ...
你好我又单独写了一个helloworld的 写入读取文件在那个机器上面
还是返回的-14
麻烦您看看 这是代码
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
static char buf[] ="hello world";
static char buf1;
inthello_init(void)
{
struct file *fp;
mm_segment_t fs;
loff_t pos;
//printk("hello enter/n");
fp =filp_open("/tmp/kernel_file",O_RDWR | O_CREAT,0644);
if (IS_ERR(fp)){
printk("create file error\n");
return -1;
}
int ret_ = 0;
fs =get_fs();
set_fs(KERNEL_DS);
pos =0;
ret_=vfs_write(fp,buf, sizeof(buf), &pos);
printk("\nwrite ret is %d\n",ret_);
pos =0;
ret_=vfs_read(fp,buf1, sizeof(buf), &pos);
printk("\nreadret is%dread: %s\n",ret_,buf1);
filp_close(fp,NULL);
set_fs(fs);
return 0;
}
voidhello_exit(void)
{
printk("hello exit/n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
这个是出问题的机器上面的版本号centos62 2.6.32-220.el6.x86_64GMT 2011 x86_64 x86_64 x86_64 GNU/Linux 谢谢了 非常感谢
ret_=vfs_read(fp,buf1, sizeof(buf), &pos);中static char buf1;溢出了? 镇水铁牛 发表于 2015-12-07 20:22 static/image/common/back.gif
ret_=vfs_read(fp,buf1, sizeof(buf), &pos);中static char buf1;溢出了?
你好 刚打错了我字符串换成hello还是一样的 返回-14不知道是哪里出现了问题 回复 5# appl337733
我在centos7上测试正常。
对的 我在6.2上面测试不正常 不知道什么原因
页:
[1]