热门关键字:  ubuntu  分区  Fedora  linux系统进程  函数

当前位置 :| 主页>Linux教程>内核研究>

把内核中的信息打印到文件的方法

来源: 作者: 时间:2007-06-13 Tag: 点击:
#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");




相关文章:
精通initramfs构建step by step
Linux利用kexec迅速切换内核
进程上下文VS中断上下文
内核通知链 学习笔记
linux spi子系统驱动分析
menuconfig 配置选项
《Linux操作系统内核实习》之练习一
udev详解
什么叫微内核,宏内核?
Linux 信号signal处理机制
开发简单的 Linux2.6 内核模块
删除内核的perl脚本
Linux2.6内核usb gadget驱动移植
GCC hacks in the Linux kernel
iomem
kernel学习的想法
让自己的驱动支持udev
linux内核编译步骤
内核的等待队列
Linux内核wait_queue深入分析
升级和删除内核
SD卡驱动分析2
Linux Kernel VDSO本地权限提升漏洞
内核中的TCP的追踪分析-15-TCP(IPV4)的客户端与
linux 2.6内核可加载模块的编译
内核模块HelloWorld
在环回接口上发送一个数据报
ARP初始化
1分钟编译FreeBSD内核
linux设备模型之uart驱动架构分析