From owner-freebsd-fs@freebsd.org Tue Aug 22 18:35:53 2017 Return-Path: Delivered-To: freebsd-fs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 63F2FDDB297 for ; Tue, 22 Aug 2017 18:35:53 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-yw0-x232.google.com (mail-yw0-x232.google.com [IPv6:2607:f8b0:4002:c05::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 399706FEF5 for ; Tue, 22 Aug 2017 18:35:53 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: by mail-yw0-x232.google.com with SMTP id y64so28459968ywf.3 for ; Tue, 22 Aug 2017 11:35:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=z79oEXAr/WwBxxwPLYlMV0rS32/Tmc+3lRHjRN/ixC0=; b=O1YrxeUQ8dE6Vj5bcR3lx+VBNdwjd5gwchsU0GAktSA+iTFRyn0zgVxD2tnT75b5Ab BnP5q3yLgDeE5hephVJCWJ39HLHl/Hv/2DcCocpSLY20qLJVGdURvFz71HudRmCX0zjS U0dPfV5+HggdkOfcMgVj4lcSXQ7GHVKaWI6p8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=z79oEXAr/WwBxxwPLYlMV0rS32/Tmc+3lRHjRN/ixC0=; b=M7GHAxE1Yp407SQP8f52Y/gBV6r8OfV/ToftDKfgJ7dab4TUnRfvf1iex7dpJNfZRO zxYDFivOXBVwzUAgk3BARckY+eL6F4fLEeSozVh8xUaa7/S8QhWjaDNd4hWOQzDWyI1Y fznHXHroEhgU+xIUQnPcnNv9Q42wT8lpbllRqU/CKHkHTRMT8Aj27lx6gqU/iLwkET8H UecnukRTANZSeqKcBBjN4it2BD5QUCkDzy3cazNbVeawIZre927jQFEn9dTw1grwpzj5 a4VVRFcOlOaR90CxZ3+PUqTBWo4NGOkbrVkEJViImyK1W0f2+DAq+7M8yHsJ42+M+rHG XtkA== X-Gm-Message-State: AHYfb5jB4P5vN0dcTsmWeyoxzf0kQpMwveR7/ab9qkSaiSsiKr/XiFQe /Sw9rjzvXvm37Tce0cb45OA2HUaG0UvW X-Received: by 10.13.230.74 with SMTP id p71mr57511ywe.456.1503426952053; Tue, 22 Aug 2017 11:35:52 -0700 (PDT) MIME-Version: 1.0 Received: by 10.37.57.21 with HTTP; Tue, 22 Aug 2017 11:35:21 -0700 (PDT) In-Reply-To: <87lgmbfob2.fsf@vostro.rath.org> References: <87bmn7kf3b.fsf@vostro.rath.org> <87lgmbfob2.fsf@vostro.rath.org> From: Eitan Adler Date: Tue, 22 Aug 2017 14:35:21 -0400 Message-ID: Subject: Re: Can telldir() == 0 value be made special? To: "freebsd-fs@freebsd.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Aug 2017 18:35:53 -0000 On 22 August 2017 at 14:30, Nikolaus Rath wrote: > On Aug 22 2017, Conrad Meyer 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