Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Feb 2002 21:47:10 -0800
From:      Alfred Perlstein <bright@mu.org>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        fs@FreeBSD.ORG
Subject:   Re: mkdir / == odd
Message-ID:  <20020219054710.GD12136@elvis.mu.org>
In-Reply-To: <20020219162133.D858-100000@gamplex.bde.org>
References:  <20020218132751.GX12136@elvis.mu.org> <20020219162133.D858-100000@gamplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
* Bruce Evans <bde@zeta.org.au> [020218 21:33] wrote:
> On Mon, 18 Feb 2002, Alfred Perlstein wrote:
> 
> > # mkdir /
> > mkdir: /: Is a directory
> >
> > shouldn't mkdir get a EEXIST error back?
> 
> Looks like I didn't fix this special case when I fixed trailing slash
> handling in rev.1.8 of vfs_lookup.c.
> 
> > this patch to mkdir also fixes it.
> 
> Um, kernel bugs can't be fixed in userland.

I wasn't sure if this error was there for hysterical raisins or
not, hence the userland work-around.

> > Index: mkdir.c
> > ===================================================================
> > RCS file: /home/ncvs/src/bin/mkdir/mkdir.c,v
> > retrieving revision 1.23
> > diff -u -r1.23 mkdir.c
> > --- mkdir.c	5 Feb 2002 21:55:12 -0000	1.23
> > +++ mkdir.c	18 Feb 2002 13:28:06 -0000
> > @@ -143,7 +143,7 @@
> >  	p = path;
> >  	oumask = 0;
> >  	retval = 0;
> > -	if (p[0] == '/')		/* Skip leading '/'. */
> > +	while (p[0] == '/')		/* Skip leading '/'. */
> >  		++p;
> >  	for (first = 1, last = 0; !last ; ++p) {
> >  		if (p[0] == '\0')
> >
> 
> Skipping even one slash here probably breaks mkdir(1) on systems where a
> leading "//" is special.

*nod*

I was looking at something like this: (untested)

Index: vfs_lookup.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/vfs_lookup.c,v
retrieving revision 1.49
diff -u -r1.49 vfs_lookup.c
--- vfs_lookup.c	13 Jan 2002 21:37:48 -0000	1.49
+++ vfs_lookup.c	18 Feb 2002 20:59:59 -0000
@@ -386,7 +386,11 @@
 			goto bad;
 		}
 		if (cnp->cn_nameiop != LOOKUP) {
-			error = EISDIR;
+			if (cnp->cn_nameiop == CREATE &&
+			    (ndp->ni_cnd.cn_flags & WILLBEDIR) != 0)
+				error = EEXIST;
+			else
+				error = EISDIR;
 			goto bad;
 		}
 		if (wantparent) {

-- 
-Alfred Perlstein [alfred@freebsd.org]
'Instead of asking why a piece of software is using "1970s technology,"
 start asking why software is ignoring 30 years of accumulated wisdom.'
Tax deductible donations for FreeBSD: http://www.freebsdfoundation.org/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-fs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020219054710.GD12136>