使用/proc 文件,只读的例子
来源:互联网 发布:手机免费网络电视直播 编辑:程序博客网 时间:2024/05/24 06:36
只用/proc文件是常用的调试方式,因为如果用很多的printk的话,对性能,及log显示都不是很好。
下面是一个简单的创建只读的proc文件的kernel module的例子。
例子中只是简单的输出了一句话,对于实际的项目可以打印不同的东西。
但是这个例子的缺点在于,使用proc文件读取时,只能读取一个page的大小?
/*
* =====================================================================================
*
* Filename: proc.c
*
* Description: This is a standalone module to show the usage of
* /proc file.
*
* Version: 1.0
* Created: 11/21/2010 01:12:35 PM
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Company:
*
* =====================================================================================
*/
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/kernel.h> /* printk() */
#include <linux/slab.h> /* kmalloc() */
#include <linux/fs.h> /* everything... */
#include <linux/errno.h> /* error codes */
#include <linux/types.h> /* size_t */
#include <linux/proc_fs.h>
#include <linux/fcntl.h> /* O_ACCMODE */
#include <linux/seq_file.h>
#include <linux/cdev.h>
#include <asm/system.h> /* cli(), *_flags */
#include <asm/uaccess.h> /* copy_*_user */
#include "scull.h" /* local definitions */
MODULE_AUTHOR("Alessandro Rubini, Jonathan Corbet");
MODULE_LICENSE("Dual BSD/GPL");
/*
* buf: point to a page size buffer allocate by kernel
* the content is displayed to user
* start:
* offset: offset and count is the same meaning as for the
* count: read method
* eof: point to an integer that must be set by the driver to signal that
* it has no more data to return
* data: driver-specific data pointer, for internal bookkeeping
*/
int read_procmem(char *buf, char **start, off_t offset,
int count, int *eof, void *data)
{
int i, j, len = 0;
int limit = count - 80; /* Don't print more than this */
len = sprintf(buf, "proc_file test/n");
*eof = 1;/* delete this line seems work two? */
return len;
}
int scull_init_module(void)
{
PDEBUG("proc test/n");
/* create file /proc/proc_test */
create_proc_read_entry("proc_test", 0 /* default mode */,
NULL /* parent dir */, read_procmem,
NULL /* client data */);
return 0;
}
void scull_cleanup_module(void)
{
/* remove /proc/proc_test */
remove_proc_entry("proc_test", NULL /* parent dir */);
return;
}
module_init(scull_init_module);
module_exit(scull_cleanup_module);
- 使用/proc 文件,只读的例子
- 使用proc接口例子
- 注意使用 /proc文件
- proc一个很好的例子
- 只读字段的使用
- proc的makefile文件
- proc文件的读写
- 使用proc_create创建proc文件
- 使用seq_file,实现大文件的/proc file
- /proc文件系统的使用
- proc文件系统的使用
- 一个编写过程的例子 ArraySum PROC
- Proc中单独文件编译(make)文件例子
- proc文件的读写函数
- 使用Python删除Windows中只读文件
- 只读文件
- 使用proc函数的实例
- 使用proc函数的实例
- 在Vista下如何配置使用rational rose 2003
- APACHE 2.2.8+TOMCAT6.0.14配置负载均衡
- 给大家推荐一下不错的博客
- 就这样
- 关于C&C++内存访问
- 使用/proc 文件,只读的例子
- 黄河“第一桥”
- Android个人原创软件《LED display》
- 超时
- PCB设计步骤:
- win7 IIS 配置和ASP.NET的运行配置
- 正则表达式的十二罗汉
- 未来的搜索引擎
- 在中国做企业要运用东方智慧--唐骏演讲