* [PATCH] update seq_file to support single_open()
@ 2003-04-17 22:18 Randy.Dunlap
2003-04-21 17:20 ` Marcelo Tosatti
0 siblings, 1 reply; 2+ messages in thread
From: Randy.Dunlap @ 2003-04-17 22:18 UTC (permalink / raw)
To: marcelo; +Cc: lkml
Hi Marcelo,
This patch updates the seq_file interface in 2.4.21-pre to be the same
as what's included in 2.5.67-bk7. That is, it addes single_open() and
single_release() methods for simpler seq file output.
It also corrects a few typos (straight from 2.5.67-bk7).
Please apply.
Thanks,
--
~Randy
--- linux-2420/include/linux/seq_file.h 2002-08-03 00:39:45.000000000 +0000
+++ linux-2421-pre7/include/linux/seq_file.h 2003-04-07 17:33:02.000000000 +0000
@@ -2,7 +2,13 @@
#define _LINUX_SEQ_FILE_H
#ifdef __KERNEL__
+#include <linux/types.h>
+#include <linux/string.h>
+#include <asm/semaphore.h>
+
struct seq_operations;
+struct file;
+struct inode;
struct seq_file {
char *buf;
@@ -52,5 +58,7 @@ static inline int seq_puts(struct seq_fi
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
--- linux-2420/fs/seq_file.c 2003-04-16 21:34:08.000000000 +0000
+++ linux-2421-pre7/fs/seq_file.c 2003-04-16 21:32:47.000000000 +0000
@@ -1,7 +1,7 @@
/*
* linux/fs/seq_file.c
*
- * helper functions for making syntetic files from sequences of records.
+ * helper functions for making synthetic files from sequences of records.
* initial implementation -- AV, Oct 2001.
*/
@@ -10,6 +10,7 @@
#include <linux/slab.h>
#include <asm/uaccess.h>
+#include <asm/page.h>
/**
* seq_open - initialize sequential file
@@ -42,7 +43,7 @@ int seq_open(struct file *file, struct s
*
* Ready-made ->f_op->read()
*/
-ssize_t seq_read(struct file *file, char *buf, size_t size, loff_t *ppos)
+ssize_t seq_read(struct file *file, char *buf, size_t size, loff_t *ppos)
{
struct seq_file *m = (struct seq_file *)file->private_data;
size_t copied = 0;
@@ -214,7 +215,7 @@ loff_t seq_lseek(struct file *file, loff
while ((retval=traverse(m, offset)) == -EAGAIN)
;
if (retval) {
- /* with extreme perjudice... */
+ /* with extreme prejudice... */
file->f_pos = 0;
m->index = 0;
m->count = 0;
@@ -249,7 +250,7 @@ int seq_release(struct inode *inode, str
* @s: string
* @esc: set of characters that need escaping
*
- * Puts string into buffer, replacing each occurence of character from
+ * Puts string into buffer, replacing each occurrence of character from
* @esc with usual octal escape. Returns 0 in case of success, -1 - in
* case of overflow.
*/
@@ -295,3 +296,45 @@ int seq_printf(struct seq_file *m, const
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;
+}
--- linux-2420/kernel/ksyms.c%SEQ Thu Apr 17 10:42:17 2003
+++ linux-2421-pre7/kernel/ksyms.c Thu Apr 17 14:49:54 2003
@@ -506,6 +506,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);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] update seq_file to support single_open()
2003-04-17 22:18 [PATCH] update seq_file to support single_open() Randy.Dunlap
@ 2003-04-21 17:20 ` Marcelo Tosatti
0 siblings, 0 replies; 2+ messages in thread
From: Marcelo Tosatti @ 2003-04-21 17:20 UTC (permalink / raw)
To: Randy.Dunlap; +Cc: lkml
Saved to 2.4.22-pre folder.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-04-21 17:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-17 22:18 [PATCH] update seq_file to support single_open() Randy.Dunlap
2003-04-21 17:20 ` Marcelo Tosatti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).