Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1026586
  • 博文数量: 836
  • 博客积分: 43880
  • 博客等级: 大将
  • 技术积分: 5485
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-20 17:36
文章分类

全部博文(836)

文章存档

2011年(1)

2008年(835)

我的朋友

分类: LINUX

2008-08-20 18:28:23


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

#defineMY_FILE"/root/LogFile"

charbuf[128];
structfile*file=NULL;



staticint__initinit(void)
{
mm_segment_told_fs;
printk("Hello,I''mthemodulethatintendstowritemessagestofile.\n");


if(file==NULL)
file=filp_open(MY_FILE,O_RDWR|O_APPEND|O_CREAT,0644);
if(IS_ERR(file)){
printk("erroroccuredwhileopeningfile%s,exiting...\n",MY_FILE);
return0;
}

sprintf(buf,"%s","TheMessages.");

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


return0;
}

staticvoid__exitfini(void)
{
if(file!=NULL)
filp_close(file,NULL);
}

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


下载本文示例代码
阅读(327) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~