From owner-freebsd-fs@freebsd.org Tue Aug 22 18:30:20 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 C94E3DDACBC for ; Tue, 22 Aug 2017 18:30:20 +0000 (UTC) (envelope-from Nikolaus@rath.org) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9A8BD6FAD5 for ; Tue, 22 Aug 2017 18:30:20 +0000 (UTC) (envelope-from Nikolaus@rath.org) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 462A720E9B for ; Tue, 22 Aug 2017 14:30:13 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute1.internal (MEProxy); Tue, 22 Aug 2017 14:30:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=LAlif2B6cQBhzBIDFo5ZzjClCoNSgKBI72qYaTcpwXs=; b=PRH3x3lv SIaojK57zIhMq9dO4BMAu8KRrKG9x4FeyyQhDLbFviRXHdJLN5ECgTWOvtkZDLPS D53KxUGXT8WhSqLiQVTmWTiSQZURJ9JLkBGkRtiXTmwTkdunVMo2de5SLNbePTIs ti5yfp6rYItBsRsQm0aVvl7Us3c6oXqEzDN1657/cU2C9tjILQNJuJEX7IfduSJl 2516D8ywnVPa5Pbni1m/7kBokxgwb1Q0Da2e1eTtc/lTQ2+F1bDaurv+EjODp5zq ZVcor5dnuk4sLXY3JXy7e6L2xQ5PPG/SJuuFU8r8Nr/1KQU/kAMLxW+lg8PGXefJ nrNFBcXhwdz7jg== X-ME-Sender: X-Sasl-enc: 3LJhTCu7lMxxBnnPZE33Z1cqpsK1RRzcVc2YOE/A8J4j 1503426612 Received: from ebox.rath.org (ebox.rath.org [45.79.69.51]) by mail.messagingengine.com (Postfix) with ESMTPA id EE56F2470F for ; Tue, 22 Aug 2017 14:30:12 -0400 (EDT) Received: from vostro.rath.org (vostro [192.168.12.4]) by ebox.rath.org (Postfix) with ESMTPS id 9E0DCD7 for ; Tue, 22 Aug 2017 18:30:11 +0000 (UTC) Received: by vostro.rath.org (Postfix, from userid 1000) id CF3AC1031FD; Tue, 22 Aug 2017 20:30:09 +0200 (CEST) From: Nikolaus Rath To: freebsd-fs@freebsd.org Subject: Re: Can telldir() == 0 value be made special? References: <87bmn7kf3b.fsf@vostro.rath.org> Mail-Copies-To: never Mail-Followup-To: freebsd-fs@freebsd.org Date: Tue, 22 Aug 2017 20:30:09 +0200 In-Reply-To: (Conrad Meyer's message of "Tue, 22 Aug 2017 07:42:36 -0700") Message-ID: <87lgmbfob2.fsf@vostro.rath.org> User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 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:30:20 -0000 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_l= ock); > + 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_l= qe); > + } > + > 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? 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 --=20 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