From owner-freebsd-fs@FreeBSD.ORG Sat Mar 12 19:31:36 2011 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BDD8A106566C; Sat, 12 Mar 2011 19:31:36 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id 5A9DD8FC14; Sat, 12 Mar 2011 19:31:36 +0000 (UTC) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id 41D96359329; Sat, 12 Mar 2011 20:31:32 +0100 (CET) Received: by turtle.stack.nl (Postfix, from userid 1677) id 2C919173A3; Sat, 12 Mar 2011 20:31:32 +0100 (CET) Date: Sat, 12 Mar 2011 20:31:32 +0100 From: Jilles Tjoelker To: Kostik Belousov Message-ID: <20110312193131.GA97300@stack.nl> References: <20110312170123.GT78089@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110312170123.GT78089@deviant.kiev.zoral.com.ua> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-fs@freebsd.org, freebsd-standards@freebsd.org Subject: Re: open(O_NOFOLLOW) error when encountered symlink X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Mar 2011 19:31:36 -0000 On Sat, Mar 12, 2011 at 07:01:23PM +0200, Kostik Belousov wrote: > Hello, > I noted the following discussion and commits in the gnu tar repository: > http://lists.gnu.org/archive/html/bug-tar/2010-11/msg00080.html > > http://git.savannah.gnu.org/cgit/tar.git/commit/?id=1584b72ff271e7f826dd64d7a1c7cd2f66504acb > http://git.savannah.gnu.org/cgit/tar.git/commit/?id=649b747913d2b289e904b5f1d222af886acd209c > The issue is that in case of open(path, O_NOFOLLOW), when path is naming > a symlink, FreeBSD returns EMLINK error. On the other hand, the POSIX > requirement is absolutely clear that it shall be ELOOP. > I found FreeBSD commit r35088 that specifically changed the error code > from the required ELOOP to EMLINK. I doubt that somebody can remember > a reason for the change done more then 12 years ago. In fact that change was done hours after the new ELOOP error. > Anybody have strong objections against the patch below ? Although it loses information (ELOOP may also be caused by the directory prefix), I think we should make the change. Please move the error condition in open.2 below the other [ELOOP] error. usr.bin/cmp relies on the EMLINK error for the -h option and needs some adjustment. If ELOOP is returned and O_NOFOLLOW is in use, it needs to check using lstat() if the file is a symlink. > diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2 > index deca8bc..20877b5 100644 > --- a/lib/libc/sys/open.2 > +++ b/lib/libc/sys/open.2 > @@ -318,7 +318,7 @@ is specified and the named file would reside on a read-only file system. > The process has already reached its limit for open file descriptors. > .It Bq Er ENFILE > The system file table is full. > -.It Bq Er EMLINK > +.It Bq Er ELOOP > .Dv O_NOFOLLOW > was specified and the target is a symbolic link. > .It Bq Er ENXIO > diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c > index 7b5cad1..c7985ef 100644 > --- a/sys/kern/vfs_vnops.c > +++ b/sys/kern/vfs_vnops.c > @@ -194,7 +194,7 @@ restart: > vp = ndp->ni_vp; > } > if (vp->v_type == VLNK) { > - error = EMLINK; > + error = ELOOP; > goto bad; > } > if (vp->v_type == VSOCK) { -- Jilles Tjoelker