rmdir(2) and mkdir(2) both return EISDIR for argument "/"

Alexander Best alexbestms at math.uni-muenster.de
Fri Nov 6 16:43:14 UTC 2009


Gary Jennejohn schrieb am 2009-11-06:
> On Fri, 06 Nov 2009 16:32:22 +0100 (CET)
> Alexander Best <alexbestms at math.uni-muenster.de> wrote:

> > Alex Dupre schrieb am 2009-11-06:
> > > Alexander Best ha scritto:
> > > > i dug up this old pr
> > > > http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/59739

> > > I think the EISDIR error is coming from kern/vfs_lookup.c,
> > > lookup()
> > > function with cn_nameptr = "":


> > >         /*
> > >          * Check for degenerate name (e.g. / or "")
> > >          * which is a way of talking about a directory,
> > >          * e.g. like "/." or ".".
> > >          */
> > >         if (cnp->cn_nameptr[0] == '\0') {
> > >                 ...
> > >                 if (cnp->cn_nameiop != LOOKUP) {
> > >                         error = EISDIR;
> > >                         goto bad;
> > >                 }
> > >                 ...

> > thanks a lot for finding the problem in the src. what do you think
> > of the
> > patch attached to this message? after applying it the example code
> > i posted in
> > my previous message returns the following output (instead of
> > EISDIR):

> > rmdir errno: 16 (which is EBUSY)
> > mkdir errno: 17 (which is EEXIST)

> > i don't know if these really are the correct return values, but
> > it's what the
> > originator of the PR requested.


> What if cn_nameiop is != LOOKUP but also neither DELETE nor CREATE,
> assuming that case is possible?  I'd leave the original if-clause at
> the end to catch that.

> ---
> Gary Jennejohn

how about this patch?

1. i've added "if (cnp->cn_nameiop != LOOKUP)" although i don't think it's
necessary since the first blocks should cover all the possible cases.
2. i've used rename() to test the case (cnp->cn_nameiop != RENAME). is this
correct or does rename() use a combo of DELETE and CREATE? problem is that the
rename(2) manual doesn't seem to cover the case that arg 1 is a mountpoint.
right now EBUSY gets returned if cnp->cn_nameiop != RENAME. however BUSY needs
to be added to all manuals which use cnp->cn_nameiop != RENAME (shouldn't be
too many). or are there any other suggestions what rename() should return if
arg 1 is a mountpoint?

cheers.
alex
-------------- next part --------------
--- vfs_lookup.c	2009-11-06 16:14:41.000000000 +0100
+++ /usr/src/sys/kern/vfs_lookup.c	2009-11-06 17:41:40.000000000 +0100
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_lookup.c 195939 2009-07-29 07:44:43Z rwatson $");
 
 #include "opt_kdtrace.h"
 #include "opt_ktrace.h"
@@ -563,6 +563,15 @@
 			error = ENOTDIR;
 			goto bad;
 		}
+		if (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME) {
+			error = EBUSY;
+			goto bad;
+		}
+		if (cnp->cn_nameiop == CREATE) {
+			error = EEXIST;
+			goto bad;
+		}
+		/* XXX This block might not be needed. */
 		if (cnp->cn_nameiop != LOOKUP) {
 			error = EISDIR;
 			goto bad;


More information about the freebsd-hackers mailing list