Subject: Re: mkdir with trailing / (patch proposed)
To: Olaf Seibert <>
From: Greg A. Woods <>
List: tech-kern
Date: 04/29/2002 15:06:07
[ On Monday, April 29, 2002 at 15:49:56 (+0200), Olaf Seibert wrote: ]
> Subject: Re: mkdir with trailing / (patch proposed)
> On Sun 28 Apr 2002 at 19:17:35 -0400, Greg A. Woods wrote:
> > I can quote draft 11.2 of IEEE POSIX-1003.2, which says much the same:
> > 
> >  pathname:  A string that is used to identify a file.
> > 
> >  A pathname consists of, at most, {PATH_MAX} bytes, including the
> >  terminating null character.  It has an optional beginning slash, followed
> >  by zero or more filenames separated by slashes.  IF THE PATHNAME REFERS
> (emphasis added by Rhialto)
> [...]
> >   That goes for mkdir(2),
> > opendir() or any other system call accepting a pathname and which allows
> > directory names, as well as of course any standard user-level utility.
> There is one very important difference between mkdir(2) and opendir():
> the path name handed to mkdir(2) DOES NOT refer to a directory! This for
> the very simple reason that it does not exist yet.

I think if you took that interpretation to IEEE's Portable Application
Standards Committee you'd be laughed out of the room, but you're welcome
to try.

It is, after all a directory to be -- unless of course that name already
exits in the hierarchy and the call is forced to return an error code
(EEXIST), It is intended and expected to be a directory and will be one
by the time the call returns successfully, therefore _the_pathname_

Besides this "bug" exists very deep in the core of the NetBSD kernel --
it just manifests itself most obviously and most frequently with
mkdir(2).  See for example the need to avoid it as implemented in
/usr/src/bin/rmdir/rmdir.c too.  Obviously with rmdir(2) there can be no
mistake that the caller expects the pathname to refer to an existing
directory.  You cannot properly fix the kernel to allow the required
interpretation for all calls except for mkdir(2), at least not with any
sufficient degree of elegance or efficiency.

								Greg A. Woods

+1 416 218-0098;  <>;  <>;  <>
Planix, Inc. <>; VE3TCP; Secrets of the Weird <>