summaryrefslogtreecommitdiffstats
path: root/scull/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'scull/main.c')
-rw-r--r--scull/main.c87
1 files changed, 45 insertions, 42 deletions
diff --git a/scull/main.c b/scull/main.c
index 791ab21..d0eef18 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,
+ proc_create_data("scullmem", 0 /* default mode */,
+ NULL /* parent dir */, &scullmem_proc_ops,
NULL /* client data */);
- entry = create_proc_entry("scullseq", 0, NULL);
- if (entry)
- entry->proc_fops = &scull_proc_ops;
+ proc_create("scullseq", 0, NULL, &scullseq_proc_ops);
}
static void scull_remove_proc(void)