Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Oct 2003 07:46:38 -0800
From:      andi payn <andi_payn@speedymail.org>
To:        freebsd-hackers@freebsd.org
Subject:   O_NOACCESS?
Message-ID:  <1067528798.36829.2128.camel@verdammt.falcotronic.net>

next in thread | raw e-mail | index | archive | help
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.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1067528798.36829.2128.camel>