Strange behaviour from mkdir()?

mal content artifact.one at googlemail.com
Mon Jun 5 19:14:06 PDT 2006


On 06/06/06, Pieter de Goeje <pieter at degoeje.nl> wrote:
> Hi MC,
>
> On Sunday 04 June 2006 20:48, mal content wrote:
> > Is this expected behaviour (I'm using the mkdir utility
> > for the example, but the problem occurs using the system
> > call directly):
> >
> > # mkdir .
> > mkdir: .: File exists
> > # mkdir ..
> > mkdir: ..: File exists
> >
> > Now, the unusual one:
> >
> > # mkdir /
> > mkdir: /: Is a directory
> >
> > Shouldn't it say 'file exists'?
> In fact, the _only_ directory that I could find that shows this behaviour
> is /. (I am using 6-stable)
>
> >
> > The mkdir() man page doesn't say that the function can set
> > errno to EISDIR and yet that's what's happening here.
> >
>
> I did some research on it, and it seems the mkdir utility is aware of the
> EISDIR error. Kinda weird if you ask me, since it isn't documented.

I followed the kern_mkdir() function and ended up in /src/sys/kern/vfs_lookup.c
where this bit of code appears:

                    785:        /*
                    786:         * Check for degenerate name (e.g. / or "")
                    787:         * which is a way of talking about a directory,
                    788:         * e.g. like "/." or ".".
                    789:         */
                    790:        if (cnp->cn_nameptr[0] == '\0') {
                    791:                if (cnp->cn_nameiop != LOOKUP
|| wantparent) {
                    792:                        error = EISDIR;
                    793:                        goto bad;
                    794:                }
                    795:                if (dp->v_type != VDIR) {
                    796:                        error = ENOTDIR;
                    797:                        goto bad;
                    798:                }

Not sure if that code is completely correct, but what do I know...

MC


More information about the freebsd-hackers mailing list