Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Aug 2017 14:35:21 -0400
From:      Eitan Adler <lists@eitanadler.com>
To:        "freebsd-fs@freebsd.org" <freebsd-fs@freebsd.org>
Subject:   Re: Can telldir() == 0 value be made special?
Message-ID:  <CAF6rxg=J7TYQQtG4%2B9TzEPPAb7LTReAm6U3A19Aq24PWrnK4vw@mail.gmail.com>
In-Reply-To: <87lgmbfob2.fsf@vostro.rath.org>
References:  <87bmn7kf3b.fsf@vostro.rath.org> <CAG6CVpVViqnbGuVn_JETBC5Q0NoYfC4VJK7iWjEfA7tFurQ2ag@mail.gmail.com> <87lgmbfob2.fsf@vostro.rath.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 22 August 2017 at 14:30, Nikolaus Rath <Nikolaus@rath.org> wrote:
> On Aug 22 2017, Conrad Meyer <cem@freebsd.org> wrote:
>> Hi Nikolaus,
>>
>> As you have surmised, DIR* seekpoints are created dynamically whenever
>> requested by user's telldir() call:
>
> Good to know, thanks!
>
>> I believe we could special case zero without breaking ABI
>> compatibility of correct programs.  Something like this:
>>
>> --- a/lib/libc/gen/telldir.c
>> +++ b/lib/libc/gen/telldir.c
>> @@ -70,6 +70,20 @@ telldir(DIR *dirp)
>>                 }
>>         }
>>         if (lp =3D=3D NULL) {
>> +               /* Create special zero telldir entry, similar to Linux *=
/
>> +               if (dirp->dd_td->td_loccnt =3D=3D 0 && dirp->dd_loc !=3D=
 0) {
>> +                       lp =3D malloc(sizeof(struct ddloc));
>> +                       if (lp =3D=3D NULL) {
>> +                               if (__isthreaded)
>> +                                       _pthread_mutex_unlock(&dirp->dd_=
lock);
>> +                               return (-1);
>> +                       }
>> +                       lp->loc_index =3D dirp->dd_td->td_loccnt++;
>> +                       lp->loc_seek =3D 0;
>> +                       lp->loc_loc =3D 0;
>> +                       LIST_INSERT_HEAD(&dirp->dd_td->td_locq, lp, loc_=
lqe);
>> +               }
>> +
>>                 lp =3D malloc(sizeof(struct ddloc));
>>                 if (lp =3D=3D NULL) {
>>                         if (__isthreaded)
>>
>> I don't know if there are any downsides to special-casing zero like
>> this, other than additional code complexity.
>
> This seems a little more complex than I would have expected.

> Is this
> maybe turning zero into a valid argument for seekdir() even if telldir()
> has never been called?

No, this code is called inside of telldir. I'd be against adding that
behavior by contract since it complicates the contract of seekdir. No
objection to this behavior by implementation though if it is simpler
than modifying telldir (doubtful).

What this is doing is ensuring that there will always be a 0 entry
*after* telldir is called, and that seekdir(0) will return to the
start of the directory if called with an argument of 0.


> That would be even better, but the minimal change that I need is just to
> ensure that telldir() either (a) never returns zero, or (b) only returns
> zero if called at the beginning of the stream.
>
>
> Best,
> -Nikolaus
>
> --
> GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
>
>              =C2=BBTime flies like an arrow, fruit flies like a Banana.=
=C2=AB
> _______________________________________________
> freebsd-fs@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-fs
> To unsubscribe, send any mail to "freebsd-fs-unsubscribe@freebsd.org"



--=20
Eitan Adler



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAF6rxg=J7TYQQtG4%2B9TzEPPAb7LTReAm6U3A19Aq24PWrnK4vw>