Subject: Re: namei(".") behaviour
To: Juergen Hannken-Illjes <>
From: Greywolf <>
List: tech-kern
Date: 07/29/2003 12:47:01
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 "."?

JH> > If the parent directory was locked this code would become as simple as
JH> >
JH> >     vput(nd.ni_dvp);
JH> To follow up myself...
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>     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.

NetBSD: Someday, we won't burn your toast.