Subject: Re: mkdir with trailing / (patch proposed)
To: NetBSD Userlevel Technical Discussion List <tech-userlevel@netbsd.org>
From: Olaf Seibert <rhialto@polderland.nl>
List: tech-kern
Date: 04/30/2002 20:28:24
On Mon 29 Apr 2002 at 15:06:07 -0400, Greg A. Woods wrote:
> 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.

Aha, that makes a difference indeed. I was assuming an implementation
where trailing slashes were being processed only after verifying that
the pathname so far was actually a directory. Which seems reasonable to
me. So I ought to check how it is actually done.

Aside: I wrote a pathname parser inside a filesystem on AmigaOS.  (MSH:,
for those who remember it). AmigaDOS has different semantics for
slashes: a leading slash refers to the parent directory, : refers to the
root of the current filesystem, and the empty path refers to the current
directory. In parsing that you have to be careful to consume exactly one
slash after each directory component (unless at the end of the
pathname), so you can interpret a/b diffently than a//b. a/b/ is
equivalent to a/b (it is "a/b/" + "") but only allowed if b is a
directory.

> 								Greg A. Woods
-Olaf.
-- 
___ Olaf 'Rhialto' Seibert - rhialto@polder    -- Ah only did well at school
\X/ land.nl       -- tae git intae an O level class tae git away fae Begbie.