22#include <linux/module.h>
33#include <linux/init.h>
44#include <linux/proc_fs.h>
5+ #include <linux/seq_file.h>
56#include <linux/string.h>
67#include <linux/jiffies.h>
78#include <linux/timer.h>
@@ -45,21 +46,22 @@ static void led_blink(unsigned long timeout)
4546 add_timer (& led_blink_timer );
4647}
4748
48- static int led_read_proc (char * buf , char * * start , off_t offset , int count ,
49- int * eof , void * data )
49+ static int led_proc_show (struct seq_file * m , void * v )
5050{
51- int len = 0 ;
52-
5351 if (get_auxio () & AUXIO_LED )
54- len = sprintf ( buf , "on\n" );
52+ seq_puts ( m , "on\n" );
5553 else
56- len = sprintf (buf , "off\n" );
54+ seq_puts (m , "off\n" );
55+ return 0 ;
56+ }
5757
58- return len ;
58+ static int led_proc_open (struct inode * inode , struct file * file )
59+ {
60+ return single_open (file , led_proc_show , NULL );
5961}
6062
61- static int led_write_proc (struct file * file , const char __user * buffer ,
62- unsigned long count , void * data )
63+ static ssize_t led_proc_write (struct file * file , const char __user * buffer ,
64+ size_t count , loff_t * ppos )
6365{
6466 char * buf = NULL ;
6567
@@ -103,6 +105,15 @@ static int led_write_proc(struct file *file, const char __user *buffer,
103105 return count ;
104106}
105107
108+ static const struct file_operations led_proc_fops = {
109+ .owner = THIS_MODULE ,
110+ .open = led_proc_open ,
111+ .read = seq_read ,
112+ .llseek = seq_lseek ,
113+ .release = single_release ,
114+ .write = led_proc_write ,
115+ };
116+
106117static struct proc_dir_entry * led ;
107118
108119#define LED_VERSION "0.1"
@@ -112,12 +123,9 @@ static int __init led_init(void)
112123 init_timer (& led_blink_timer );
113124 led_blink_timer .function = led_blink ;
114125
115- led = create_proc_entry ("led" , 0 , NULL );
126+ led = proc_create ("led" , 0 , NULL , & led_proc_fops );
116127 if (!led )
117128 return - ENOMEM ;
118-
119- led -> read_proc = led_read_proc ; /* reader function */
120- led -> write_proc = led_write_proc ; /* writer function */
121129 led -> owner = THIS_MODULE ;
122130
123131 printk (KERN_INFO
0 commit comments