O_NOACCESS?

From: andi payn (andi_payn_at_speedymail.org)
Date: 10/30/03

  • Next message: andi payn: "kevent and related stuff"
    To: freebsd-hackers@freebsd.org
    Date: Thu, 30 Oct 2003 07:46:38 -0800
    
    

    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.

    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: andi payn: "kevent and related stuff"

    Relevant Pages

    • Re: New Sarge install
      ... > I am new to Linux and have some questions about a new install of Sarge. ... > am installing a dual boot with FreeBSD on a Dell Latitude C600 laptop. ... edit lilo with entry for FreeBSD and then install the second os. ...
      (Debian-User)
    • Re: installing second os with freebsd
      ... XP is on partitions C: and D: and FreeBSD takes up the remaining space on the drive. ... From Win XP delete the D: DRIVE (But NOT the Partition) ... The FAT32 partition would be a useful as a data store for now and could be eliminated next time you install both FBSD and Linux. ... Have a look at Slackware Linux: Very similar to FBSD and less 'proprietory' than most other Linux systems, defaults to Lilo loader with Grub as an option. ...
      (comp.unix.bsd.freebsd.misc)
    • Re: FreeBSD 4.x Opteron Question
      ... the FreeBSD developers told everyone that 5.3 was da ... initially over linux not because there's a bunch of good guys on the ... My tests measure kernel performance; ... > a networking device is a key performance indicator. ...
      (freebsd-questions)
    • Re: Newbie Experience
      ... I've only been around since FreeBSD 5.4 ... FreeBSD kernel too. ... always sunshine and linux is farts. ... in the hey day of AT&T Unix I'm ...
      (freebsd-questions)
    • Re: Review of FreeBSD 5.4
      ... but not less problems compared to FreeBSD. ... If you like to have a bleeding edge system using debian --- just go ... > the linux kernel suffers. ... When the kernel suffers, everyone who uses ...
      (comp.unix.bsd.freebsd.misc)