码迷,mamicode.com
首页 > 系统相关 > 详细

Linux 设备驱动程序 proc seq

时间:2014-05-26 15:20:31      阅读:351      评论:0      收藏:0      [点我收藏+]

标签:style   c   class   blog   code   java   

不能再简化

bubuko.com,布布扣
 1 #include<linux/module.h>
 2 #include<linux/init.h>
 3 
 4 #include<linux/seq_file.h>
 5 #include<linux/fs.h>
 6 #include <linux/proc_fs.h>
 7 void * meng_seq_start(struct seq_file*s,loff_t*pos)
 8 {
 9         if(*pos>1)
10                 return NULL;
11         return pos;
12 }
13 
14 void * meng_seq_next(struct seq_file*s,void *v,loff_t*pos)
15 {
16         (*pos)++;
17          if(*pos>1)
18                  return NULL;
19          return pos;
20 }
21 
22 void  meng_seq_stop(struct seq_file*s,void *v)
23 {
24 }
25 char *meng_seq_data[2]={"Hello.\n","This meng seq proc file.\n"};
26 
27 int meng_seq_show(struct seq_file*s,void *v)
28 {
29         seq_printf(s,meng_seq_data[*((int*)v)]);
30         return 0;
31 }
32 struct seq_operations meng_seq_ops={
33 .start=meng_seq_start,
34 .next=meng_seq_next,
35 .stop=meng_seq_stop,
36 .show=meng_seq_show
37 };
38 int meng_seq_proc_seq_open(struct inode*inode,struct file*file)
39 {
40         return seq_open(file,&meng_seq_ops);
41 }
42 
43 struct file_operations meng_seq_proc_ops=
44 {
45         .owner=THIS_MODULE,
46         .open=meng_seq_proc_seq_open,
47         .read=seq_read,
48         .llseek=seq_lseek,
49         .release=seq_release
50 };
51 
52 
53 
54 int meng_seq_proc_init(void)
55 {
56         struct proc_dir_entry *entry=create_proc_entry("mengprocseq",0,NULL);
57         if(entry)
58                 entry->proc_fops=&meng_seq_proc_ops;
59         return 0;
60 }
61 
62 
63 void meng_seq_proc_exit(void)
64 {
65         remove_proc_entry("mengprocseq",NULL);
66 }
67 
68 module_init(meng_seq_proc_init);
69 module_exit(meng_seq_proc_exit);
bubuko.com,布布扣

 

Linux 设备驱动程序 proc seq,布布扣,bubuko.com

Linux 设备驱动程序 proc seq

标签:style   c   class   blog   code   java   

原文地址:http://www.cnblogs.com/mengqingzhong/p/3746252.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!