summaryrefslogtreecommitdiffstats
path: root/fs/seq_file.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2008-03-28 00:46:41 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2008-04-21 23:14:02 -0400
commit521b5d0c40386f4a9805cdec7bd979fc96a86aeb (patch)
tree2193c12ee3dc0551790c79370603acb57e0f59e7 /fs/seq_file.c
parent4e1b36fb485dd81b0818ef1bc8fb5c0f2923a283 (diff)
downloadop-kernel-dev-521b5d0c40386f4a9805cdec7bd979fc96a86aeb.zip
op-kernel-dev-521b5d0c40386f4a9805cdec7bd979fc96a86aeb.tar.gz
[PATCH] teach seq_file to discard entries
Allow ->show() return SEQ_SKIP; that will discard all output from that element and move on. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/seq_file.c')
-rw-r--r--fs/seq_file.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 8537702..bf2bcfd 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -25,6 +25,7 @@
* into the buffer. In case of error ->start() and ->next() return
* ERR_PTR(error). In the end of sequence they return %NULL. ->show()
* returns 0 in case of success and negative number in case of error.
+ * Returning SEQ_SKIP means "discard this element and move on".
*/
int seq_open(struct file *file, const struct seq_operations *op)
{
@@ -114,8 +115,10 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
if (!p || IS_ERR(p))
break;
err = m->op->show(m, p);
- if (err)
+ if (err < 0)
break;
+ if (unlikely(err))
+ m->count = 0;
if (m->count < m->size)
goto Fill;
m->op->stop(m, p);
@@ -140,9 +143,10 @@ Fill:
break;
}
err = m->op->show(m, p);
- if (err || m->count == m->size) {
+ if (m->count == m->size || err) {
m->count = offs;
- break;
+ if (likely(err <= 0))
+ break;
}
pos = next;
}
@@ -199,8 +203,12 @@ static int traverse(struct seq_file *m, loff_t offset)
if (IS_ERR(p))
break;
error = m->op->show(m, p);
- if (error)
+ if (error < 0)
break;
+ if (unlikely(error)) {
+ error = 0;
+ m->count = 0;
+ }
if (m->count == m->size)
goto Eoverflow;
if (pos + m->count > offset) {
OpenPOWER on IntegriCloud