From f76929f117abb38ad4f87f2eea0e83bdf549e820 Mon Sep 17 00:00:00 2001 From: Luis Ortega Perez de Villar Date: Fri, 16 Aug 2013 16:55:07 +0200 Subject: scullc: main: Don't use create_proc_read_entry() Don't use create_proc_read_entry() as it is deprecated, but rather use proc_create() and seq_file instead. --- scullc/main.c | 56 +++++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/scullc/main.c b/scullc/main.c index 814db02..c08114f 100644 --- a/scullc/main.c +++ b/scullc/main.c @@ -24,6 +24,7 @@ #include /* error codes */ #include /* size_t */ #include +#include #include /* O_ACCMODE */ #include #include @@ -59,61 +60,54 @@ struct kmem_cache *scullc_cache; * The proc filesystem: function to read and entry */ -void scullc_proc_offset(char *buf, char **start, off_t *offset, int *len) -{ - if (*offset == 0) - return; - if (*offset >= *len) { - /* Not there yet */ - *offset -= *len; - *len = 0; - } else { - /* We're into the interesting stuff now */ - *start = buf + *offset; - *offset = 0; - } -} - /* FIXME: Do we need this here?? It be ugly */ -int scullc_read_procmem(char *buf, char **start, off_t offset, - int count, int *eof, void *data) +int scullc_read_procmem(struct seq_file *m, void *v) { - int i, j, quantum, qset, len = 0; - int limit = count - 80; /* Don't print more than this */ + int i, j, quantum, qset; + int limit = m->size - 80; /* Don't print more than this */ struct scullc_dev *d; - *start = buf; for(i = 0; i < scullc_devs; i++) { d = &scullc_devices[i]; if (down_interruptible (&d->sem)) return -ERESTARTSYS; qset = d->qset; /* retrieve the features of each device */ quantum=d->quantum; - len += sprintf(buf+len,"\nDevice %i: qset %i, quantum %i, sz %li\n", + seq_printf(m,"\nDevice %i: qset %i, quantum %i, sz %li\n", i, qset, quantum, (long)(d->size)); for (; d; d = d->next) { /* scan the list */ - len += sprintf(buf+len," item at %p, qset at %p\n",d,d->data); - scullc_proc_offset (buf, start, &offset, &len); - if (len > limit) + seq_printf(m," item at %p, qset at %p\n",d,d->data); + if (m->count > limit) goto out; if (d->data && !d->next) /* dump only the last item - save space */ for (j = 0; j < qset; j++) { if (d->data[j]) - len += sprintf(buf+len," % 4i:%8p\n",j,d->data[j]); - scullc_proc_offset (buf, start, &offset, &len); - if (len > limit) + seq_printf(m," % 4i:%8p\n",j,d->data[j]); + if (m->count > limit) goto out; } } out: up (&scullc_devices[i].sem); - if (len > limit) + if (m->count > limit) break; } - *eof = 1; - return len; + return 0; } +static int scullc_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, scullc_read_procmem, NULL); +} + +static struct file_operations scullc_proc_ops = { + .owner = THIS_MODULE, + .open = scullc_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release +}; + #endif /* SCULLC_USE_PROC */ /* @@ -572,7 +566,7 @@ int scullc_init(void) } #ifdef SCULLC_USE_PROC /* only when available */ - create_proc_read_entry("scullcmem", 0, NULL, scullc_read_procmem, NULL); + proc_create("scullcmem", 0, NULL, &scullc_proc_ops); #endif return 0; /* succeed */ -- cgit v1.2.1-18-gbd029