亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1434 | 回復(fù): 6
打印 上一主題 下一主題

[內(nèi)核入門] vfs_read 在某些機(jī)器上面返回-14 讀取文件 EFAULT [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2015-12-07 17:24 |只看該作者 |倒序?yàn)g覽
vfs_read 在某些機(jī)器上面返回-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);//調(diào)整初始位置
    ret_ = vfs_read(f, data_, size_, &f->f_pos);
    set_fs(oldfs_);
                       
        //pr_info("httplist  Cannot read \"%d,%d,%d,%d\"\n", ret_,EBADF,EINVAL,EFAULT);

    if (ret_ < 0){
                pr_info("Cannot read \"%d\"\n", ret_);
        return false;
        }

請問各位,這個(gè)一般是什么地方出問題了呢? 非常感謝   找了很久沒有找到答案    本地機(jī)器可以  服務(wù)器不可以  然后服務(wù)器上面用內(nèi)核源碼編譯了一下這個(gè)模塊 也不行的 不知道什么原因


論壇徽章:
2
寅虎
日期:2014-11-25 21:47:342015小元宵徽章
日期:2015-03-06 15:58:18
2 [報(bào)告]
發(fā)表于 2015-12-07 20:08 |只看該作者
理論上當(dāng)set_fs(get_ds());之后,vfs read不會返回-14,
有點(diǎn)懷疑*data = (char*) kmalloc(size_ + 1, GFP_ATOMIC);

代碼貼全一點(diǎn)?
輸入?yún)?shù)是多少?

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2015-12-07 20:11 |只看該作者
鎮(zhèn)水鐵牛 發(fā)表于 2015-12-07 20:08
理論上當(dāng)set_fs(get_ds());之后,vfs read不會返回-14,
有點(diǎn)懷疑*data = (char*) kmalloc(size_ + 1, GFP ...


你好  我又單獨(dú)寫了一個(gè)helloworld的 寫入讀取文件  在那個(gè)機(jī)器上面
還是返回的-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[10];
    int  hello_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("\nread  ret is  %d  read: %s\n",ret_,buf1);
        filp_close(fp,NULL);
        set_fs(fs);
        return 0;
    }
    void  hello_exit(void)
    {
        printk("hello exit/n");
    }
     
    module_init(hello_init);
    module_exit(hello_exit);
     
    MODULE_LICENSE("GPL");
這個(gè)是出問題的機(jī)器上面的版本號  centos62 2.6.32-220.el6.x86_64  GMT 2011 x86_64 x86_64 x86_64 GNU/Linux   謝謝了 非常感謝

論壇徽章:
2
寅虎
日期:2014-11-25 21:47:342015小元宵徽章
日期:2015-03-06 15:58:18
4 [報(bào)告]
發(fā)表于 2015-12-07 20:22 |只看該作者
  ret_=vfs_read(fp,buf1, sizeof(buf), &pos);中static char buf1[10];溢出了?

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2015-12-07 20:27 |只看該作者
鎮(zhèn)水鐵牛 發(fā)表于 2015-12-07 20:22
ret_=vfs_read(fp,buf1, sizeof(buf), &pos);中static char buf1[10];溢出了?

你好 剛打錯(cuò)了  我字符串換成hello  還是一樣的 返回-14  不知道是哪里出現(xiàn)了問題

論壇徽章:
2
寅虎
日期:2014-11-25 21:47:342015小元宵徽章
日期:2015-03-06 15:58:18
6 [報(bào)告]
發(fā)表于 2015-12-07 21:50 |只看該作者
回復(fù) 5# appl337733

我在centos7上測試正常。
   

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2015-12-07 22:26 |只看該作者
對的 我在6.2上面測試不正常 不知道什么原因
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP