[DragonFlyBSD - Bug #3282] unexpected errno value from fopen()

sigttou bugtracker-admin at leaf.dragonflybsd.org
Mon Oct 12 01:37:42 PDT 2026


Issue #3282 has been updated by sigttou.

File 0001-kernel-Fix-fopen-w-to-return-EISDIR-keep-mkdir-EEXIST-master.patch added
File 0001-kernel-Fix-fopen-w-to-return-EISDIR-keep-mkdir-EEXIST-rel64.patch added

The fix imo belongs in @vn_open()@, the @open()@ specific layer where all other
@open()@ error cases already live.  In the @O_CREAT@ path there, @EEXIST@ from
@nlookup()@ can only come from a @.@ or @..@ last component or from @nlookup()@'s
root fast-track (@open("/", O_CREAT)@). An ordinary existing-file target
returns 0 and is handled later, so the mapping cannot misfire. The attached
patch reverts @nlookup()@ to @EEXIST@ and adds this to @vn_open()@:

 if (error == EEXIST && (fmode & O_EXCL) == 0)
    error = EISDIR;

@open(".", O_RDONLY|O_CREAT)@ still fails (@EISDIR@ now instead of
@EEXIST@).  POSIX would allow it to succeed like @open(".", O_RDONLY)@, but
making that work needs mode-aware create handling in @nlookup()@.

----------------------------------------
Bug #3282: unexpected errno value from fopen()
http://bugs.dragonflybsd.org/issues/3282#change-14837

* Author: bhaible
* Status: In Progress
* Priority: Normal
* Category: Kernel
* Target version: 6.4
* Start date: 2021-06-14
----------------------------------------
fopen(".", "w") fails with errno = EEXIST.
Per POSIX https://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html
one would expect one of EISDIR, EINVAL, EACCES.

How to reproduce: Run this program.

<pre>
#include <errno.h>
#include <stdio.h>

int main ()
{
  FILE *fp = fopen (".", "w");
  if (fp == NULL)
    {
      perror ("fopen");
    }
}

</pre>

---Files--------------------------------
sys.kern.vfs_nlookup.c.diff (6.7 KB)
0001-kernel-Fix-fopen-w-to-return-EISDIR-keep-mkdir-EEXIST-master.patch (2.97 KB)
0001-kernel-Fix-fopen-w-to-return-EISDIR-keep-mkdir-EEXIST-rel64.patch (2.97 KB)


-- 
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account


More information about the Bugs mailing list