Commit ec3a47e7 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] new helpers for /proc

new helpers for seq_file - for cases where we don't have a non-trivial
iterator and just want to use seq_{printf,putc,...}.
parent c6e6354f
......@@ -357,25 +357,7 @@ static int devices_read_proc(char *page, char **start, off_t off,
return proc_calc_metrics(page, start, off, count, eof, len);
}
static void *single_start(struct seq_file *p, loff_t *pos)
{
return NULL + (*pos == 0);
}
static void *single_next(struct seq_file *p, void *v, loff_t *pos)
{
++*pos;
return NULL;
}
static void single_stop(struct seq_file *p, void *v)
{
}
extern int show_interrupts(struct seq_file *p, void *v);
static struct seq_operations proc_interrupts_op = {
start: single_start,
next: single_next,
stop: single_stop,
show: show_interrupts,
};
static int interrupts_open(struct inode *inode, struct file *file)
{
unsigned size = PAGE_SIZE;
......@@ -389,7 +371,7 @@ static int interrupts_open(struct inode *inode, struct file *file)
if (!buf)
return -ENOMEM;
res = seq_open(file, &proc_interrupts_op);
res = single_open(file, show_interrupts, NULL);
if (!res) {
m = file->private_data;
m->buf = buf;
......@@ -402,7 +384,7 @@ static struct file_operations proc_interrupts_operations = {
open: interrupts_open,
read: seq_read,
llseek: seq_lseek,
release: seq_release,
release: single_release,
};
static int filesystems_read_proc(char *page, char **start, off_t off,
......
......@@ -293,3 +293,45 @@ int seq_printf(struct seq_file *m, const char *f, ...)
m->count = m->size;
return -1;
}
static void *single_start(struct seq_file *p, loff_t *pos)
{
return NULL + (*pos == 0);
}
static void *single_next(struct seq_file *p, void *v, loff_t *pos)
{
++*pos;
return NULL;
}
static void single_stop(struct seq_file *p, void *v)
{
}
int single_open(struct file *file, int (*show)(struct seq_file *, void*), void *data)
{
struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
int res = -ENOMEM;
if (op) {
op->start = single_start;
op->next = single_next;
op->stop = single_stop;
op->show = show;
res = seq_open(file, op);
if (!res)
((struct seq_file *)file->private_data)->private = data;
else
kfree(op);
}
return res;
}
int single_release(struct inode *inode, struct file *file)
{
struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
int res = seq_release(inode, file);
kfree(op);
return res;
}
......@@ -58,5 +58,7 @@ static inline int seq_puts(struct seq_file *m, const char *s)
int seq_printf(struct seq_file *, const char *, ...)
__attribute__ ((format (printf,2,3)));
int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
int single_release(struct inode *, struct file *);
#endif
#endif
......@@ -522,6 +522,8 @@ EXPORT_SYMBOL(seq_open);
EXPORT_SYMBOL(seq_release);
EXPORT_SYMBOL(seq_read);
EXPORT_SYMBOL(seq_lseek);
EXPORT_SYMBOL(single_open);
EXPORT_SYMBOL(single_release);
/* Program loader interfaces */
EXPORT_SYMBOL(setup_arg_pages);
......
......@@ -233,18 +233,6 @@ static struct file_operations status_fops =
release: seq_release,
};
static void *single_start(struct seq_file *p, loff_t *pos)
{
return *pos == 0 ? p->private : NULL;
}
static void *single_next(struct seq_file *p, void *v, loff_t *pos)
{
++*pos;
return NULL;
}
static void single_stop(struct seq_file *p, void *v)
{
}
static int wandev_show(struct seq_file *m, void *v)
{
wan_device_t *wandev = v;
......@@ -306,20 +294,10 @@ static int wandev_show(struct seq_file *m, void *v)
"aborted frames transmitted", wandev->stats.tx_aborted_errors);
return 0;
}
static struct seq_operations wandev_op = {
start: single_start,
next: single_next,
stop: single_stop,
show: wandev_show,
};
static int wandev_open(struct inode *inode, struct file *file)
{
int ret = seq_open(file, &wandev_op);
if (!ret) {
struct seq_file *m = file->private_data;
m->private = PDE(inode)->data;
}
return ret;
return single_open(file, wandev_show, PDE(inode)->data);
}
static struct file_operations wandev_fops =
......@@ -327,7 +305,7 @@ static struct file_operations wandev_fops =
open: wandev_open,
read: seq_read,
llseek: seq_lseek,
release: seq_release,
release: single_release,
ioctl: wanrouter_ioctl,
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment