Subject: Re: Linux emulation and mkdir with trailing /
To: John Darrow <John.P.Darrow@wheaton.edu>
From: Bill Studenmund <firstname.lastname@example.org>
Date: 09/29/2000 10:19:15
On Fri, 29 Sep 2000, John Darrow wrote:
> I just caught up on this discussion, but the earlier quote from the
> standards seems clear to me: trailing slashes are valid as a no-op, but
> _only_ if the preceding component is a directory - thus _normally_ requiring
> it to already exist. The special case is mkdir, which may be creating the
> directory in question. As such, it seems the simplest way to follow the
> standard is for the name lookup routines to strip the trailing slashes only
> if they find a valid directory already exists, and to otherwise (either no
> existing entry, or a non-directory found) return an error, and for the
> mkdir(2) call to strip off the trailing slashes on its own before calling
> the lookup routine.
I agree with everything except for the last phrase of the paragraph. :-)
The problem with that is that namei is the thing which does the copying
in, not the mkdir syscall. To have mkdir do the fix, we'd have to create a
temporary buffer in mkdir, copyin, and then call namei(). Since namei()
really wants to copy the path, we now have an extra buffer around.
I think an easier fix is the one I posted, and which others expanded on.
We just add a new flag to namei which says we're happy to create a missing
directory, so don't return an error iff the last component is missing.
Since rename needs the same work, it's better to do it in namei(). :-)