一个使用 seq_file 接口的 proc_fs 例子
来源:互联网 发布:页面升级紧急通知域名 编辑:程序博客网 时间:2024/04/28 07:11
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <asm/uaccess.h>
static struct proc_dir_entry *pfile;
static char *myfruits[5] = {"apple", "orange", "banana", "watermelon", "pear"};
static void *my_seq_start(struct seq_file *s, loff_t *pos)
{
if (*pos >= 5)
return NULL;
return myfruits[*pos];
}
static void *my_seq_next(struct seq_file *s, void *v, loff_t *pos)
{
if (++*pos >= 5)
return NULL;
return myfruits[*pos];
}
static void my_seq_stop(struct seq_file *s, void *v)
{
// nothing to do;
}
static int my_seq_show(struct seq_file *s, void *v)
{
seq_printf(s, "%s ", (char *)v);
return 0;
}
static struct seq_operations proc_seq_ops = {
.start = my_seq_start,
.next = my_seq_next,
.stop = my_seq_stop,
.show = my_seq_show,
};
static int my_seq_open(struct inode *inode, struct file *file)
{
return seq_open(file, &proc_seq_ops);
}
static struct file_operations proc_fops = {
.open = my_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static int __init myproc_init(void)
{
pfile = proc_create("fruits", 0666, NULL, &proc_fops);
if (!pfile) {
printk(KERN_ERR "Can't create /proc/fruits/n");
remove_proc_entry("mydir", NULL);
return -1;
}
return 0;
}
static void __exit myproc_exit(void)
{
remove_proc_entry("fruits", NULL);
}
module_init(myproc_init);
module_exit(myproc_exit);
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <asm/uaccess.h>
static struct proc_dir_entry *pfile;
static char *myfruits[5] = {"apple", "orange", "banana", "watermelon", "pear"};
static void *my_seq_start(struct seq_file *s, loff_t *pos)
{
if (*pos >= 5)
return NULL;
return myfruits[*pos];
}
static void *my_seq_next(struct seq_file *s, void *v, loff_t *pos)
{
if (++*pos >= 5)
return NULL;
return myfruits[*pos];
}
static void my_seq_stop(struct seq_file *s, void *v)
{
// nothing to do;
}
static int my_seq_show(struct seq_file *s, void *v)
{
seq_printf(s, "%s ", (char *)v);
return 0;
}
static struct seq_operations proc_seq_ops = {
.start = my_seq_start,
.next = my_seq_next,
.stop = my_seq_stop,
.show = my_seq_show,
};
static int my_seq_open(struct inode *inode, struct file *file)
{
return seq_open(file, &proc_seq_ops);
}
static struct file_operations proc_fops = {
.open = my_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static int __init myproc_init(void)
{
pfile = proc_create("fruits", 0666, NULL, &proc_fops);
if (!pfile) {
printk(KERN_ERR "Can't create /proc/fruits/n");
remove_proc_entry("mydir", NULL);
return -1;
}
return 0;
}
static void __exit myproc_exit(void)
{
remove_proc_entry("fruits", NULL);
}
module_init(myproc_init);
module_exit(myproc_exit);
- 一个使用 seq_file 接口的 proc_fs 例子
- 一个使用 seq_file 接口的 proc_fs 例子
- 【内核】:一个使用 seq_file 接口的 proc_fs 例子
- seq_file接口
- 从seq_file接口读取的数据不全
- proc_fs文件的操作
- 接口的使用例子
- 一个天气接口的封装及使用例子
- 使用jmeter进行接口测试的一个简单例子。
- 使用jmeter进行接口压力测试的一个简单例子
- 序列文件(seq_file)接口
- seq_file接口编程浅析
- IPicture接口的使用例子
- 一个面向接口编程的好例子
- 一个面向接口编程的好例子
- 一个面向接口编程的好例子
- 一个面向接口编程的好例子
- c#接口简单易懂的一个例子
- 正则表达式学习笔记
- proc_fs 使用说明
- 慎用IEquatable
- Csdn之旅
- 用ini文件实现显示最近文件
- 一个使用 seq_file 接口的 proc_fs 例子
- 用SharpZip解压/压缩文件
- Flex Application 初始化顺序
- 采用System.Reflection.Emit动态建立程序集如何设置文件的版本信息,描述等信息
- 函数调用方式 08.11.2
- static的用法
- 函数调用的几个概念:_stdcall,_cdecl 08.11.2
- VC++中的回调函数,即callback类型函数 08.11.2
- 入侵检测系统(Intrusion Detection System,简称IDS)综述