Re: 2.6.10-mm3: lseek broken on /proc/self/maps

From: Prasanna Meda
Date: Fri Jan 14 2005 - 19:45:18 EST


Jeremy Fitzhardinge wrote:

> lseek doesn't seem to have any effect on /proc/<pid>/maps. It should
> either work as expected, or fail.
>

An oversight, f_version is not reset by seq_lseek as done by generic_lseek.
Please try the attached patch.


>
> I've attached a test program which uses a doubling buffer policy to try
> to read the whole buffer. If it runs out of buffer, it simply allocates
> a new one, lseeks back to the beginning of the buffer, and tries again.
> However, the lseek seems to have no effect, because the next read
> continues from where the previous one (before the lseek) left off.
>
> Re-opening the file between each attempt works as expected.
>

Thanks a lot for testing all the corner cases.

I missed the point that seq_lseek did not reset the f_version,
like generic_lseek did, until Jeremy proved with an example.

Signed-off-by: Prasanna Meda <pmeda@xxxxxxxxxx>

--- fs/seq_file.c Fri Jan 14 23:51:27 2005
+++ fs/seq_file.c Fri Jan 14 23:51:59 2005
@@ -117,6 +117,7 @@ ssize_t seq_read(struct file *file, char
if (!m->buf)
goto Enomem;
m->count = 0;
+ m->version = 0;
}
m->op->stop(m, p);
m->count = 0;
@@ -173,6 +174,7 @@ static int traverse(struct seq_file *m,
int error = 0;
void *p;

+ m->version = 0;
m->index = 0;
m->count = m->from = 0;
if (!offset)
@@ -227,6 +229,7 @@ loff_t seq_lseek(struct file *file, loff
long long retval = -EINVAL;

down(&m->sem);
+ m->version = file->f_version;
switch (origin) {
case 1:
offset += file->f_pos;
@@ -240,6 +243,7 @@ loff_t seq_lseek(struct file *file, loff
if (retval) {
/* with extreme prejudice... */
file->f_pos = 0;
+ m->version = 0;
m->index = 0;
m->count = 0;
} else {
@@ -248,6 +252,7 @@ loff_t seq_lseek(struct file *file, loff
}
}
up(&m->sem);
+ file->f_version = m->version;
return retval;
}
EXPORT_SYMBOL(seq_lseek);