Browse Source

[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>
Pavel Emelyanov 17 years ago
parent
commit
39699037a5
2 changed files with 35 additions and 0 deletions
  1. 33 0
      fs/seq_file.c
  2. 2 0
      include/linux/seq_file.h

+ 33 - 0
fs/seq_file.c

@@ -429,6 +429,39 @@ int seq_release_private(struct inode *inode, struct file *file)
 }
 }
 EXPORT_SYMBOL(seq_release_private);
 EXPORT_SYMBOL(seq_release_private);
 
 
+void *__seq_open_private(struct file *f, const struct seq_operations *ops,
+		int psize)
+{
+	int rc;
+	void *private;
+	struct seq_file *seq;
+
+	private = kzalloc(psize, GFP_KERNEL);
+	if (private == NULL)
+		goto out;
+
+	rc = seq_open(f, ops);
+	if (rc < 0)
+		goto out_free;
+
+	seq = f->private_data;
+	seq->private = private;
+	return private;
+
+out_free:
+	kfree(private);
+out:
+	return NULL;
+}
+EXPORT_SYMBOL(__seq_open_private);
+
+int seq_open_private(struct file *filp, const struct seq_operations *ops,
+		int psize)
+{
+	return __seq_open_private(filp, ops, psize) ? 0 : -ENOMEM;
+}
+EXPORT_SYMBOL(seq_open_private);
+
 int seq_putc(struct seq_file *m, char c)
 int seq_putc(struct seq_file *m, char c)
 {
 {
 	if (m->count < m->size) {
 	if (m->count < m->size) {

+ 2 - 0
include/linux/seq_file.h

@@ -46,6 +46,8 @@ int seq_path(struct seq_file *, struct vfsmount *, struct dentry *, char *);
 
 
 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
 int single_release(struct inode *, struct file *);
 int single_release(struct inode *, struct file *);
+void *__seq_open_private(struct file *, const struct seq_operations *, int);
+int seq_open_private(struct file *, const struct seq_operations *, int);
 int seq_release_private(struct inode *, struct file *);
 int seq_release_private(struct inode *, struct file *);
 
 
 #define SEQ_START_TOKEN ((void *)1)
 #define SEQ_START_TOKEN ((void *)1)