From owner-freebsd-hackers@FreeBSD.ORG Tue Mar 2 04:31:05 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1F91B106566B for ; Tue, 2 Mar 2010 04:31:05 +0000 (UTC) (envelope-from nate@thatsmathematics.com) Received: from euclid.ucsd.edu (euclid.ucsd.edu [132.239.145.52]) by mx1.freebsd.org (Postfix) with ESMTP id D88408FC13 for ; Tue, 2 Mar 2010 04:31:04 +0000 (UTC) Received: from zeno.ucsd.edu (zeno.ucsd.edu [132.239.145.22]) by euclid.ucsd.edu (8.11.7p3+Sun/8.11.7) with ESMTP id o224V4Y21530; Mon, 1 Mar 2010 20:31:04 -0800 (PST) Received: from localhost (neldredg@localhost) by zeno.ucsd.edu (8.11.7p3+Sun/8.11.7) with ESMTP id o224V3P02961; Mon, 1 Mar 2010 20:31:03 -0800 (PST) X-Authentication-Warning: zeno.ucsd.edu: neldredg owned process doing -bs Date: Mon, 1 Mar 2010 20:31:03 -0800 (PST) From: Nate Eldredge X-X-Sender: neldredg@zeno.ucsd.edu To: Garrett Cooper In-Reply-To: <7d6fde3d1002281826n60c2061fiedfc4e548cc9f068@mail.gmail.com> Message-ID: References: <7d6fde3d1002281826n60c2061fiedfc4e548cc9f068@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Alexander Best , freebsd-hackers@freebsd.org Subject: Re: namei() returns EISDIR for "/" (Re: svn commit: r203990 - head/lib/libc/sys) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Mar 2010 04:31:05 -0000 On Sun, 28 Feb 2010, Garrett Cooper wrote: > On Sun, Feb 28, 2010 at 5:11 PM, Alexander Best wrote: >> i have a small test app to check {rm|mk}dir()'s errnos with certain args like >> /, ., /proc and non-empty dirs. i'll submit it to this thread as soon as i >> also add testcases for syscalls like rename(), unlink(), etc. >> >> most of the errno codes returned after applying your patch look correct. i >> wonder however why rmdir("/proc") returns EACCESS as unprivileged user. >> wouldn't it make more sense to also return EBUSY? why complain about >> permission related matters when even root won't be able to perform the >> operation. > > Hmm.. good question. POSIX doesn't fully expound on this case > (http://www.opengroup.org/onlinepubs/009695399/functions/rmdir.html), > and either seem possible... At: http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_03.html#tag_02_03 we have If more than one error occurs in processing a function call, any one of the possible errors may be returned, as the order of detection is undefined. So we're okay standard-wise. In general, though, I'd think it makes sense to do permissions checks before anything else, because in some cases the error code can leak information. For instance, if you try to open() a nonexistent file in a directory for which you don't have search permission ('x' bit), it's very important that open() fail with EACCES instead of ENOENT, since you aren't suppposed to be able to find out whether or not the file exists. Obviously that doesn't apply in this case, because anyone is entitled to know that /proc is the root of a mounted filesystem, but it seems to me that it's a good habit to check permission first. -- Nate Eldredge nate@thatsmathematics.com