Skip to content

Commit

Permalink
[PATCH] teach seq_file to discard entries
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Al Viro committed Apr 22, 2008
1 parent 4e1b36f commit 521b5d0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions fs/pnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ int propagate_mnt(struct vfsmount *, struct dentry *, struct vfsmount *,
struct list_head *);
int propagate_umount(struct list_head *);
int propagate_mount_busy(struct vfsmount *, int);
void mnt_release_group_id(struct vfsmount *);
#endif /* _LINUX_PNODE_H */
16 changes: 12 additions & 4 deletions fs/seq_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -140,9 +143,10 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
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;
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions include/linux/seq_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct seq_operations {
int (*show) (struct seq_file *m, void *v);
};

#define SEQ_SKIP 1

int seq_open(struct file *, const struct seq_operations *);
ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
loff_t seq_lseek(struct file *, loff_t, int);
Expand Down

0 comments on commit 521b5d0

Please sign in to comment.