From 542aeada0dd544b751c689a8a530e5c915cd7e4e Mon Sep 17 00:00:00 2001 From: Luis Ortega Perez de Villar Date: Fri, 19 Jul 2013 13:17:35 +0200 Subject: Don't use create_proc_entry() and create_proc_read_entry() Don't use create_proc_entry() and create_proc_read_entry() as they are deprecated, but rather use proc_create() and proc_create_data() respectively and seq_file instead. --- scull/main.c | 89 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 46 insertions(+), 43 deletions(-) (limited to 'scull/main.c') diff --git a/scull/main.c b/scull/main.c index 791ab21..3946c8e 100644 --- a/scull/main.c +++ b/scull/main.c @@ -85,41 +85,34 @@ int scull_trim(struct scull_dev *dev) * The proc filesystem: function to read and entry */ -int scull_read_procmem(char *buf, char **start, off_t offset, - int count, int *eof, void *data) +int scull_read_procmem(struct seq_file *s, void *v) { - int i, j, len = 0; - int limit = count - 80; /* Don't print more than this */ - - for (i = 0; i < scull_nr_devs && len <= limit; i++) { - struct scull_dev *d = &scull_devices[i]; - struct scull_qset *qs = d->data; - if (down_interruptible(&d->sem)) - return -ERESTARTSYS; - len += sprintf(buf+len,"\nDevice %i: qset %i, q %i, sz %li\n", - i, d->qset, d->quantum, d->size); - for (; qs && len <= limit; qs = qs->next) { /* scan the list */ - len += sprintf(buf + len, " item at %p, qset at %p\n", - qs, qs->data); - if (qs->data && !qs->next) /* dump only the last item */ - for (j = 0; j < d->qset; j++) { - if (qs->data[j]) - len += sprintf(buf + len, - " % 4i: %8p\n", - j, qs->data[j]); - } - } - up(&scull_devices[i].sem); - } - *eof = 1; - return len; + int i, j; + int limit = s->size - 80; /* Don't print more than this */ + + for (i = 0; i < scull_nr_devs && s->count <= limit; i++) { + struct scull_dev *d = &scull_devices[i]; + struct scull_qset *qs = d->data; + if (down_interruptible(&d->sem)) + return -ERESTARTSYS; + seq_printf(s,"\nDevice %i: qset %i, q %i, sz %li\n", + i, d->qset, d->quantum, d->size); + for (; qs && s->count <= limit; qs = qs->next) { /* scan the list */ + seq_printf(s, " item at %p, qset at %p\n", + qs, qs->data); + if (qs->data && !qs->next) /* dump only the last item */ + for (j = 0; j < d->qset; j++) { + if (qs->data[j]) + seq_printf(s, " % 4i: %8p\n", + j, qs->data[j]); + } + } + up(&scull_devices[i].sem); + } + return 0; } -/* - * For now, the seq_file implementation will exist in parallel. The - * older read_procmem function should maybe go away, though. - */ /* * Here are our sequence iteration methods. Our "position" is @@ -180,20 +173,33 @@ static struct seq_operations scull_seq_ops = { }; /* - * Now to implement the /proc file we need only make an open + * Now to implement the /proc files we need only make an open * method which sets up the sequence operators. */ -static int scull_proc_open(struct inode *inode, struct file *file) +static int scullmem_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, scull_read_procmem, NULL); +} + +static int scullseq_proc_open(struct inode *inode, struct file *file) { return seq_open(file, &scull_seq_ops); } /* - * Create a set of file operations for our proc file. + * Create a set of file operations for our proc files. */ -static struct file_operations scull_proc_ops = { +static struct file_operations scullmem_proc_ops = { + .owner = THIS_MODULE, + .open = scullmem_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release +}; + +static struct file_operations scullseq_proc_ops = { .owner = THIS_MODULE, - .open = scull_proc_open, + .open = scullseq_proc_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release @@ -206,13 +212,10 @@ static struct file_operations scull_proc_ops = { static void scull_create_proc(void) { - struct proc_dir_entry *entry; - create_proc_read_entry("scullmem", 0 /* default mode */, - NULL /* parent dir */, scull_read_procmem, - NULL /* client data */); - entry = create_proc_entry("scullseq", 0, NULL); - if (entry) - entry->proc_fops = &scull_proc_ops; + proc_create_data("scullmem", 0 /* default mode */, + NULL /* parent dir */, &scullmem_proc_ops, + NULL /* client data */); + proc_create("scullseq", 0, NULL, &scullseq_proc_ops); } static void scull_remove_proc(void) -- cgit v1.2.1-18-gbd029 From cbfbcb953aa0f1d004f3bce5d8c83400cbfbdc7c Mon Sep 17 00:00:00 2001 From: Luis Ortega Perez de Villar Date: Fri, 19 Jul 2013 22:05:41 +0200 Subject: scull: main | pipe : Fix coding style Replace white space indentation introduced with the previous patch with 8 characters width TABs to comply with the kernel coding style. --- scull/main.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'scull/main.c') diff --git a/scull/main.c b/scull/main.c index 3946c8e..d0eef18 100644 --- a/scull/main.c +++ b/scull/main.c @@ -178,7 +178,7 @@ static struct seq_operations scull_seq_ops = { */ static int scullmem_proc_open(struct inode *inode, struct file *file) { - return single_open(file, scull_read_procmem, NULL); + return single_open(file, scull_read_procmem, NULL); } static int scullseq_proc_open(struct inode *inode, struct file *file) @@ -190,11 +190,11 @@ static int scullseq_proc_open(struct inode *inode, struct file *file) * Create a set of file operations for our proc files. */ static struct file_operations scullmem_proc_ops = { - .owner = THIS_MODULE, - .open = scullmem_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release + .owner = THIS_MODULE, + .open = scullmem_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release }; static struct file_operations scullseq_proc_ops = { @@ -212,10 +212,10 @@ static struct file_operations scullseq_proc_ops = { static void scull_create_proc(void) { - proc_create_data("scullmem", 0 /* default mode */, - NULL /* parent dir */, &scullmem_proc_ops, - NULL /* client data */); - proc_create("scullseq", 0, NULL, &scullseq_proc_ops); + proc_create_data("scullmem", 0 /* default mode */, + NULL /* parent dir */, &scullmem_proc_ops, + NULL /* client data */); + proc_create("scullseq", 0, NULL, &scullseq_proc_ops); } static void scull_remove_proc(void) -- cgit v1.2.1-18-gbd029