Re: [PATCH v2][RESEND] seq_file: don't set read position for invalid iterator
From: Miklos Szeredi
Date: Thu Nov 24 2016 - 10:40:04 EST
On Thu, Nov 24, 2016 at 4:23 PM, Tomasz Majchrzak
<tomasz.majchrzak@xxxxxxxxx> wrote:
> I don't understand it. Is it possible to map file position to the index
> (record)? I think there is no way to determine record size without actually
> reading it.
Right. So don't update m->index when a zero size record is read.
This will result in m->index always pointing to the first record at
the given offset. You use this property for the single record case
and zero offset, but I'd consider behavior consistent if this was not
just done for this special case.
>> But I doubt that we actually need to do that. For example just special casing
>> the zero offset (always translating to zero index) would be conceptually simpler
>> and equivalent to your patch for the sysfs case.
>
> Do you mean such piece of code?
>
> if (ppos == 0)
> m->index = 0;
Yes. Which is a special case, but it's at least simple and easy to prove right.
Thanks,
Miklos