博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

os fans

MSN & Mail:jinglexy at yahoo dot com dot cn
操作系统开发博客圈:http://blog.chinaunix.net/group/group_507.html
qq group(os fans): 3*2*2*6*2*9*2
  jinglexy.cublog.cn

关于作者
马甲:天衣有缝
职业:linux driver
位置:徐家汇上海交大
|| << >> ||
我的分类


how to read file in kernel(原创)
转载请声明原创:http://jinglexy.cublog.cn
MSN: jinglexy at yahoo dot com dot cn
it's simple, we just use the vfs func:
char *fw_read_helper(u32* len)
{
        int ret;
        int fd1;
        char *p = NULL;
        mm_segment_t fs;

        fs = get_fs();
        set_fs(KERNEL_DS);

        if(NULL == (p = kmalloc(FW_SIZE_HELPER, GFP_KERNEL))) {
                dpline();
                return NULL;
        }  

        fd1 = sys_open("/helper_gspi.bin", O_RDONLY, S_IRWXU);
        if(fd1 < 0) {
                kfree(p);
                dpline();
                printk("fd is %d\n", fd1);
                return NULL;
        }  

        ret = sys_read(fd1, p, FW_SIZE_HELPER);
        if(ret <= 0) {
                kfree(p);
                sys_close(fd1);
                dpline();
                return NULL;
        }  
        sys_close(fd1);
        set_fs(fs);

        *len = ret;
        return  p; 
        *len = sizeof(helperimage);
        return helperimage;
}

发表于: 2008-05-24,修改于: 2008-05-25 12:55,已浏览190次,有评论0条 推荐 投诉


网友评论
 发表评论