summaryrefslogtreecommitdiffstats
path: root/fs/seq_file.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2013-03-31 13:43:23 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2013-04-09 14:13:29 -0400
commit2043f495c7c1a06f7748b5bcd17656d93c95e1a6 (patch)
treef3d0368632a1fda88bb385ddfc01600fe450e74f /fs/seq_file.c
parent70ef457dc92bdd03c0c8d640fce45909166983a1 (diff)
downloadlinux-stable-2043f495c7c1a06f7748b5bcd17656d93c95e1a6.tar.gz
linux-stable-2043f495c7c1a06f7748b5bcd17656d93c95e1a6.tar.bz2
linux-stable-2043f495c7c1a06f7748b5bcd17656d93c95e1a6.zip
new helper: single_open_size()
Same as single_open(), but preallocates the buffer of given size. Doesn't make any sense for sizes up to PAGE_SIZE and doesn't make sense if output of show() exceeds PAGE_SIZE only rarely - seq_read() will take care of growing the buffer and redoing show(). If you _know_ that it will be large, it might make more sense to look into saner iterator, rather than go with single-shot one. If that's impossible, single_open_size() might be for you. Again, don't use that without a good reason; occasionally that's really the best way to go, but very often there are better solutions. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/seq_file.c')
-rw-r--r--fs/seq_file.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 38bb59f3f2ad..774c1eb7f1c9 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -599,6 +599,24 @@ int single_open(struct file *file, int (*show)(struct seq_file *, void *),
}
EXPORT_SYMBOL(single_open);
+int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
+ void *data, size_t size)
+{
+ char *buf = kmalloc(size, GFP_KERNEL);
+ int ret;
+ if (!buf)
+ return -ENOMEM;
+ ret = single_open(file, show, data);
+ if (ret) {
+ kfree(buf);
+ return ret;
+ }
+ ((struct seq_file *)file->private_data)->buf = buf;
+ ((struct seq_file *)file->private_data)->size = size;
+ return 0;
+}
+EXPORT_SYMBOL(single_open_size);
+
int single_release(struct inode *inode, struct file *file)
{
const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;