Skip to content

Commit

Permalink
Merge pull request martinezjavier#3 from luiorpe1/scull-3.10
Browse files Browse the repository at this point in the history
Scull updated for 3.10
  • Loading branch information
martinezjavier committed Aug 14, 2013
2 parents 6aae03d + cbfbcb9 commit 4511f80
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 73 deletions.
4 changes: 3 additions & 1 deletion scull/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ else
DEBFLAGS = -O2
endif

LDDINC=$(PWD)/../include

EXTRA_CFLAGS += $(DEBFLAGS)
EXTRA_CFLAGS += -I$(LDDINC)

Expand All @@ -25,7 +27,7 @@ KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

endif

Expand Down
87 changes: 45 additions & 42 deletions scull/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
55 changes: 25 additions & 30 deletions scull/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/cdev.h>
#include <asm/uaccess.h>
#include <linux/sched.h>
#include <linux/seq_file.h>

#include "scull.h" /* local definitions */

Expand Down Expand Up @@ -262,46 +263,40 @@ static int scull_p_fasync(int fd, struct file *filp, int mode)

/* FIXME this should use seq_file */
#ifdef SCULL_DEBUG
static void scullp_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;
}
}


static int scull_read_p_mem(char *buf, char **start, off_t offset, int count,
int *eof, void *data)
static int scull_read_p_mem(struct seq_file *s, void *v)
{
int i, len;
int i;
struct scull_pipe *p;

#define LIMIT (PAGE_SIZE-200) /* don't print any more after this size */
*start = buf;
len = sprintf(buf, "Default buffersize is %i\n", scull_p_buffer);
for(i = 0; i<scull_p_nr_devs && len <= LIMIT; i++) {
#define LIMIT (PAGE_SIZE-200) /* don't print any more after this size */
seq_printf(s, "Default buffersize is %i\n", scull_p_buffer);
for(i = 0; i<scull_p_nr_devs && s->count <= LIMIT; i++) {
p = &scull_p_devices[i];
if (down_interruptible(&p->sem))
return -ERESTARTSYS;
len += sprintf(buf+len, "\nDevice %i: %p\n", i, p);
/* len += sprintf(buf+len, " Queues: %p %p\n", p->inq, p->outq);*/
len += sprintf(buf+len, " Buffer: %p to %p (%i bytes)\n", p->buffer, p->end, p->buffersize);
len += sprintf(buf+len, " rp %p wp %p\n", p->rp, p->wp);
len += sprintf(buf+len, " readers %i writers %i\n", p->nreaders, p->nwriters);
seq_printf(s, "\nDevice %i: %p\n", i, p);
/* seq_printf(s, " Queues: %p %p\n", p->inq, p->outq);*/
seq_printf(s, " Buffer: %p to %p (%i bytes)\n", p->buffer, p->end, p->buffersize);
seq_printf(s, " rp %p wp %p\n", p->rp, p->wp);
seq_printf(s, " readers %i writers %i\n", p->nreaders, p->nwriters);
up(&p->sem);
scullp_proc_offset(buf, start, &offset, &len);
}
*eof = (len <= LIMIT);
return len;
return 0;
}

static int scullpipe_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, scull_read_p_mem, NULL);
}

static struct file_operations scullpipe_proc_ops = {
.owner = THIS_MODULE,
.open = scullpipe_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release
};

#endif

Expand Down Expand Up @@ -367,7 +362,7 @@ int scull_p_init(dev_t firstdev)
scull_p_setup_cdev(scull_p_devices + i, i);
}
#ifdef SCULL_DEBUG
create_proc_read_entry("scullpipe", 0, NULL, scull_read_p_mem, NULL);
proc_create("scullpipe", 0, NULL, &scullpipe_proc_ops);
#endif
return scull_p_nr_devs;
}
Expand Down

0 comments on commit 4511f80

Please sign in to comment.