From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 30 07:46:44 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8E44616A4CE for ; Thu, 30 Oct 2003 07:46:44 -0800 (PST) Received: from mta11.adelphia.net (mta11.adelphia.net [68.168.78.205]) by mx1.FreeBSD.org (Postfix) with ESMTP id 74BF843FE9 for ; Thu, 30 Oct 2003 07:46:43 -0800 (PST) (envelope-from andi_payn@speedymail.org) Received: from [10.1.0.9] ([68.65.235.109]) by mta11.adelphia.net (InterMail vM.5.01.06.05 201-253-122-130-105-20030824) with ESMTP id <20031030154645.JYJS24277.mta11.adelphia.net@[10.1.0.9]> for ; Thu, 30 Oct 2003 10:46:45 -0500 From: andi payn To: freebsd-hackers@freebsd.org Content-Type: text/plain Message-Id: <1067528798.36829.2128.camel@verdammt.falcotronic.net> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 Date: Thu, 30 Oct 2003 07:46:38 -0800 Content-Transfer-Encoding: 7bit Subject: O_NOACCESS? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Oct 2003 15:46:44 -0000 As far as I can tell, FreeBSD doesn't have anything equivalent to linux's O_NOACCESS (which is not in any of the standard headers, but it's equal to O_WRONLY | O_RDWR, or O_ACCMODE). In linux, this can be used to say, "give me an fd for this file, but don't try to open it for reading or writing or anything else." This allows you to get an fd to pass to fcntl (e.g., for dnotify), or call ioctl's on, etc.--even if you don't have either read or write access to the file. The obvious question is, "Why should this ever be allowed?" Well, if you can stat the file, why can't you, e.g., ask kevent to monitor it? In FreeBSD, this doesn't work; you just get EINVAL. Having O_NOACCESS would be useful for the fam port, for porting pieces of lilo, and probably for other things I haven't thought of yet. (I believe that either this was added to linux to support lilo, or the open syscall just happened to work this way, and once the lilo developers discovered this and took advantage of it, it's been retained that way ever since to keep lilo working.) On the other hand, BSD has done without it for many years, and there's probably a good reason it's never been added. So, what is that good reason? I don't think there's a backwards-compatibility issue. The open(2) manpage specifies that EINVAL will be returned if "An attempt was made to open a descriptor with an illegal combination of O_RDONLY, O_WRONLY, and O_RDWR." However, it doesn't specify what constitutes an illegal combination--and nowhere does it say that exactly one of the three must be specified. (Interestingly, the manpage on my Mandrake 9.1 box _does_ say that exactly one must be specified, which is not true in linux....) While a reader would be unlikely to assume that "O_WRONLY | O_RDWR" means "open for no access," I can't imagine many programs rely on the fact that this combination returns an error. If there is such an issue, well, there are other flag bits left unused (3 in the low 16 bits, plus 15 in the high 16 bits); if not, it would probably be nicer to use the same value as linux. Meanwhile, as mentioned above, doesn't define O_NOACCESS in any of the standard header files (IIRC, programs that use it--like lilo--explicitly #define it as 3, or O_WRONLY | O_RDWR, or O_ACCMODE), and it's not documented in the man pages. I think that, if it's added to FreeBSD, it should be added in a cleaner and better-documented way. Anyway, would a patch to add this feature be considered? And if so, does anyone have any input into questions like whether O_NOACCESS should be 3 as it is in linux or use some unused flag bit instead, whether it should be defined in fcntl.h or elsewhere, etc.? Thanks.