设置首页  |   加入收藏  |  联系我们   
您的位置: 主页>Linux知识>内核研究>正文
怎么样把内核中的信息打印到文件
文章来源:  编辑:  发布时间:2007-10-29

#include
#include
#include
#include
#include
#include
#include
#include
#include

#define MY_FILE "/root/LogFile"

char buf[128];
struct file *file = NULL;



static int __init init(void)
{
        mm_segment_t old_fs;
        printk("Hello, I'm the module that intends to write messages to file.\n");


        if(file == NULL)
                file = filp_open(MY_FILE, O_RDWR | O_APPEND | O_CREAT, 0644);
        if (IS_ERR(file)) {
                printk("error occured while opening file %s, exiting...\n", MY_FILE);
                return 0;
        }

        sprintf(buf,"%s", "The Messages.");

        old_fs = get_fs();
        set_fs(KERNEL_DS);
        file->f_op->write(file, (char *)buf, sizeof(buf), &file->f_pos);
        set_fs(old_fs);


        return 0;
}

static void __exit fini(void)
{
        if(file != NULL)
                filp_close(file, NULL);
}

module_init(init);
module_exit(fini);
MODULE_LICENSE("GPL");
(e129)

 
Tags:文件 打印 信息 怎么样 #include file buf NULL void
Google
 
上一篇: Linux内核稳定版Linux 2.6.16.4发布   下一篇: 内核稳定版Linux 2.6.16.8正式发布
【返回顶部】 【打印】 【大】 【中】 【小】 【关闭】

 我来说两句
用户名: 新注册) 密码: 匿名评论 [论坛讨论]
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 相关文章
 热门文章

 
版权所有  2005-2006  Linux集中营  闽ICP备07500055号