Linux 设备驱动程序 proc seq

时间:2023-03-08 20:07:43

不能再简化

 #include<linux/module.h>
#include<linux/init.h> #include<linux/seq_file.h>
#include<linux/fs.h>
#include <linux/proc_fs.h>
void * meng_seq_start(struct seq_file*s,loff_t*pos)
{
if(*pos>)
return NULL;
return pos;
} void * meng_seq_next(struct seq_file*s,void *v,loff_t*pos)
{
(*pos)++;
if(*pos>)
return NULL;
return pos;
} void meng_seq_stop(struct seq_file*s,void *v)
{
}
char *meng_seq_data[]={"Hello.\n","This meng seq proc file.\n"}; int meng_seq_show(struct seq_file*s,void *v)
{
seq_printf(s,meng_seq_data[*((int*)v)]);
return ;
}
struct seq_operations meng_seq_ops={
.start=meng_seq_start,
.next=meng_seq_next,
.stop=meng_seq_stop,
.show=meng_seq_show
};
int meng_seq_proc_seq_open(struct inode*inode,struct file*file)
{
return seq_open(file,&meng_seq_ops);
} struct file_operations meng_seq_proc_ops=
{
.owner=THIS_MODULE,
.open=meng_seq_proc_seq_open,
.read=seq_read,
.llseek=seq_lseek,
.release=seq_release
}; int meng_seq_proc_init(void)
{
struct proc_dir_entry *entry=create_proc_entry("mengprocseq",,NULL);
if(entry)
entry->proc_fops=&meng_seq_proc_ops;
return ;
} void meng_seq_proc_exit(void)
{
remove_proc_entry("mengprocseq",NULL);
} module_init(meng_seq_proc_init);
module_exit(meng_seq_proc_exit);