diff options
author | Pavel Emelyanov <xemul@openvz.org> | 2007-10-10 05:28:42 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:55:33 -0400 |
commit | 39699037a5c94d7cd1363dfe48a50c78c643fd9a (patch) | |
tree | ea5a0ab329dbe43531c3b713536e45491e1cb51f | |
parent | 59e90b2d22500f2e9cc635793562154abc8f4621 (diff) |
[FS] seq_file: Introduce the seq_open_private()
This function allocates the zeroed chunk of memory and
call seq_open(). The __seq_open_private() helper returns
the allocated memory to make it possible for the caller
to initialize it.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | fs/seq_file.c | 33 | ||||
-rw-r--r-- | include/linux/seq_file.h | 2 |
2 files changed, 35 insertions, 0 deletions
diff --git a/fs/seq_file.c b/fs/seq_file.c index bbb19be260ce..ca71c115bdaa 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c | |||
@@ -429,6 +429,39 @@ int seq_release_private(struct inode *inode, struct file *file) | |||
429 | } | 429 | } |
430 | EXPORT_SYMBOL(seq_release_private); | 430 | EXPORT_SYMBOL(seq_release_private); |
431 | 431 | ||
432 | void *__seq_open_private(struct file *f, const struct seq_operations *ops, | ||
433 | int psize) | ||
434 | { | ||
435 | int rc; | ||
436 | void *private; | ||
437 | struct seq_file *seq; | ||
438 | |||
439 | private = kzalloc(psize, GFP_KERNEL); | ||
440 | if (private == NULL) | ||
441 | goto out; | ||
442 | |||
443 | rc = seq_open(f, ops); | ||
444 | if (rc < 0) | ||
445 | goto out_free; | ||
446 | |||
447 | seq = f->private_data; | ||
448 | seq->private = private; | ||
449 | return private; | ||
450 | |||
451 | out_free: | ||
452 | kfree(private); | ||
453 | out: | ||
454 | return NULL; | ||
455 | } | ||
456 | EXPORT_SYMBOL(__seq_open_private); | ||
457 | |||
458 | int seq_open_private(struct file *filp, const struct seq_operations *ops, | ||
459 | int psize) | ||
460 | { | ||
461 | return __seq_open_private(filp, ops, psize) ? 0 : -ENOMEM; | ||
462 | } | ||
463 | EXPORT_SYMBOL(seq_open_private); | ||
464 | |||
432 | int seq_putc(struct seq_file *m, char c) | 465 | int seq_putc(struct seq_file *m, char c) |
433 | { | 466 | { |
434 | if (m->count < m->size) { | 467 | if (m->count < m->size) { |
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index 83783ab0f552..8bf1e05115b4 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h | |||
@@ -46,6 +46,8 @@ int seq_path(struct seq_file *, struct vfsmount *, struct dentry *, char *); | |||
46 | 46 | ||
47 | int single_open(struct file *, int (*)(struct seq_file *, void *), void *); | 47 | int single_open(struct file *, int (*)(struct seq_file *, void *), void *); |
48 | int single_release(struct inode *, struct file *); | 48 | int single_release(struct inode *, struct file *); |
49 | void *__seq_open_private(struct file *, const struct seq_operations *, int); | ||
50 | int seq_open_private(struct file *, const struct seq_operations *, int); | ||
49 | int seq_release_private(struct inode *, struct file *); | 51 | int seq_release_private(struct inode *, struct file *); |
50 | 52 | ||
51 | #define SEQ_START_TOKEN ((void *)1) | 53 | #define SEQ_START_TOKEN ((void *)1) |