open(O_NOFOLLOW) error when encountered symlink

Kostik Belousov kostikbel at
Sat Mar 12 17:21:39 UTC 2011

I noted the following discussion and commits in the gnu tar repository:

The issue is that in case of open(path, O_NOFOLLOW), when path is naming
a symlink, FreeBSD returns EMLINK error. On the other hand, the POSIX
requirement is absolutely clear that it shall be ELOOP.

I found FreeBSD commit r35088 that specifically changed the error code
from the required ELOOP to EMLINK. I doubt that somebody can remember
a reason for the change done more then 12 years ago.

Anybody have strong objections against the patch below ?

diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2
index deca8bc..20877b5 100644
--- a/lib/libc/sys/open.2
+++ b/lib/libc/sys/open.2
@@ -318,7 +318,7 @@ is specified and the named file would reside on a read-only file system.
 The process has already reached its limit for open file descriptors.
 The system file table is full.
+.It Bq Er ELOOP
 was specified and the target is a symbolic link.
 .It Bq Er ENXIO
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index 7b5cad1..c7985ef 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -194,7 +194,7 @@ restart:
 		vp = ndp->ni_vp;
 	if (vp->v_type == VLNK) {
-		error = EMLINK;
+		error = ELOOP;
 		goto bad;
 	if (vp->v_type == VSOCK) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url :

More information about the freebsd-standards mailing list