Subject: Re: namei(".") behaviour
To: None <tech-kern@netbsd.org>
From: Juergen Hannken-Illjes <hannken@eis.cs.tu-bs.de>
List: tech-kern
Date: 07/29/2003 22:12:36
On Tue, Jul 29, 2003 at 12:47:01PM -0700, Greywolf wrote:
> Thus spake Juergen Hannken-Illjes ("JH> ") sometime Today...
> 
> JH> > While looking over the filesystem snapshot code from FreeBSD I discovered a
> JH> > somewhat strange behaviour of namei():
> JH> >
> JH> > If called for a DOT directory ("." or "...path/.") it returns with
> JH> >
> JH> >     nd.ni_dvp == nd.ni_vp
> JH> >
> JH> > Even if called with LOCKPARENT flag both (identical) vnodes are not locked.
> JH> > This leads to a bunch of code like
> JH> >
> JH> >     if (nd.ni_dvp == nd.ni_vp)
> JH> > 	vrele(nd.ni_dvp);
> JH> >     else
> JH> > 	vput(nd.ni_dvp);
> JH> >
> JH> > Is there a reason why the parent directory (nd.ni_dvp) is returned unlocked?
> 
> (kernel_t) (clue *) 404 question:
> 
> Why would you need to lock a parent if you're referencing "."?

Because I set the LOCKPARENT flag and want to vput(nd.ni_dvp) even if
referencing "."

> JH> > If the parent directory was locked this code would become as simple as
> JH> >
> JH> >     vput(nd.ni_dvp);
> JH>
> JH> To follow up myself...
> JH>
> JH> With Rev. 1.23 (mycroft) of kern/vfs_lookup.c a check for degenerate name
> JH> was removed. This check (in lookup) returned:
> JH>
> JH>     ENOTDIR if the last component was "" and not a directory
> JH>     EISDIR  if the last component was "" and mode != LOOKUP
> 
> ?!?
> 
> Do you mean
> 
> 	(nd = namei("/path/to/file/")) == ENOTDIR;
> 
> That makes sense.
> 
> I don't follow why (nd = namei("/path/to/dir/")) == EISDIR), though.

If the mode is != LOOKUP this means one of  CREATE, RENAME or DELETE.
This operation is usually forbidden (with rmdir and rename as a special case).

But the first part (always lock parent if requested) is my main interest.
-- 
Juergen Hannken-Illjes - hannken@eis.cs.tu-bs.de - TU Braunschweig (Germany)