public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH]Fix bug:rmdir could remove current working directory
  2001-10-11  0:32 [PATCH]Fix bug:rmdir could remove current working directory Mingming cao
@ 2001-10-10 21:45 ` Alexander Viro
  2001-10-11  1:03   ` Mingming cao
  2001-10-10 22:21 ` Ricky Beam
  1 sibling, 1 reply; 8+ messages in thread
From: Alexander Viro @ 2001-10-10 21:45 UTC (permalink / raw)
  To: Mingming cao; +Cc: Linus Torvalds, Alan Cox, linux-kernel



On Wed, 10 Oct 2001, Mingming cao wrote:

> Hi Linus, Alan and Al,
> 
> I found that rmdir(2) could remove current working directory
> successfully.  This happens when the given pathname points to current
> working directory, not ".", but something else. For example, the current
> working directory's absolute pathname.  I read the man page of
> rmdir(2).  It says in this case EBUSY error should be returned.  I
> suspected this is a bug and added a check in vfs_rmdir(). The following
> patch is against 2.4.10 and has been verified.  Please comment and
> apply.

It's not a bug.  Moreover, test you add is obviously bogus - what about
cwd of other processes?

Actually, rmdir() on a busy directory _is_ OK.  Implementation is allowed
to refuse doing that, but it's not required to.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH]Fix bug:rmdir could remove current working directory
  2001-10-11  1:03   ` Mingming cao
@ 2001-10-10 22:09     ` Alexander Viro
  2001-10-10 23:17     ` Linus Torvalds
       [not found]     ` <200110102317.f9ANHjN03120@penguin.transmeta.com>
  2 siblings, 0 replies; 8+ messages in thread
From: Alexander Viro @ 2001-10-10 22:09 UTC (permalink / raw)
  To: Mingming cao; +Cc: Linus Torvalds, Alan Cox, linux-kernel



On Wed, 10 Oct 2001, Mingming cao wrote:
 
> I thought about the case when rmdir() on the cwd of other processes,
> but, as you said, that is implementation dependent. However rmdir() on
> "." does returns EBUSY error. Should not we keep the rmdir() behavior
> consistent: rmdir() on the current working directory of the current
> process is not OK?

We do.  It's not just ".",  "foo/bar/." is also prohibited.  IOW, the
rule is "the last component of name should not be . or ..".  Please,
look through archives - it had been beaten to death many times.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH]Fix bug:rmdir could remove current working directory
  2001-10-11  0:32 [PATCH]Fix bug:rmdir could remove current working directory Mingming cao
  2001-10-10 21:45 ` Alexander Viro
@ 2001-10-10 22:21 ` Ricky Beam
  2001-10-10 23:36   ` John Levon
  1 sibling, 1 reply; 8+ messages in thread
From: Ricky Beam @ 2001-10-10 22:21 UTC (permalink / raw)
  To: Mingming cao; +Cc: linux-kernel

On Wed, 10 Oct 2001, Mingming cao wrote:
>I read the man page of
>rmdir(2).  It says in this case EBUSY error should be returned.  I
>suspected this is a bug and added a check in vfs_rmdir(). The following
>patch is against 2.4.10 and has been verified.  Please comment and
>apply.

The bug is in the manpage.  This was discussed over a year ago (some time
after 2.1.44 introduced dcache (it was broken then, but that's when it
appeared.))

--Ricky



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH]Fix bug:rmdir could remove current working directory
  2001-10-11  1:03   ` Mingming cao
  2001-10-10 22:09     ` Alexander Viro
@ 2001-10-10 23:17     ` Linus Torvalds
       [not found]     ` <200110102317.f9ANHjN03120@penguin.transmeta.com>
  2 siblings, 0 replies; 8+ messages in thread
From: Linus Torvalds @ 2001-10-10 23:17 UTC (permalink / raw)
  To: linux-kernel

In article <3BC4EFFC.42ACE59E@us.ibm.com>,
Mingming cao  <cmm@us.ibm.com> wrote:
>
>I thought about the case when rmdir() on the cwd of other processes,
>but, as you said, that is implementation dependent. However rmdir() on
>"." does returns EBUSY error.

That's a completely different thing, though - even though the difference
is rather subtle.

You can remove pretty much any empty directory (if the filesystem
permits it - some don't). HOWEVER, you can not use "." as the final
component of your pathname.

It has nothing to do with home directory: you can try just doing

	mkdir /tmp/hello
	rmdir /tmp/hello/.

and you'll get the same error (and it _should_ return EINVAL, not EBUSY.
EBUSY is for the "this filesystem doesn't allow you to remove a
directory that is in use" case).

			Linus

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH]Fix bug:rmdir could remove current working directory
  2001-10-10 22:21 ` Ricky Beam
@ 2001-10-10 23:36   ` John Levon
  0 siblings, 0 replies; 8+ messages in thread
From: John Levon @ 2001-10-10 23:36 UTC (permalink / raw)
  To: linux-kernel

On Wed, Oct 10, 2001 at 06:21:01PM -0400, Ricky Beam wrote:

> On Wed, 10 Oct 2001, Mingming cao wrote:
> >I read the man page of
> >rmdir(2).  It says in this case EBUSY error should be returned.  I
> >suspected this is a bug and added a check in vfs_rmdir(). The following
> >patch is against 2.4.10 and has been verified.  Please comment and
> >apply.
> 
> The bug is in the manpage.  This was discussed over a year ago (some time

Well, the manpage only states what certain error nr. returns may mean, not what
will be returned when. Do you have an improvement on :

       EBUSY  pathname is the current working directory or root directory of some process.

regards
john

-- 
"Beware of bugs in the above code; I have only proved it correct, not tried
it."
	- Donald Knuth

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH]Fix bug:rmdir could remove current working directory
@ 2001-10-11  0:32 Mingming cao
  2001-10-10 21:45 ` Alexander Viro
  2001-10-10 22:21 ` Ricky Beam
  0 siblings, 2 replies; 8+ messages in thread
From: Mingming cao @ 2001-10-11  0:32 UTC (permalink / raw)
  To: Linus Torvalds, Alan Cox, viro; +Cc: linux-kernel

Hi Linus, Alan and Al,

I found that rmdir(2) could remove current working directory
successfully.  This happens when the given pathname points to current
working directory, not ".", but something else. For example, the current
working directory's absolute pathname.  I read the man page of
rmdir(2).  It says in this case EBUSY error should be returned.  I
suspected this is a bug and added a check in vfs_rmdir(). The following
patch is against 2.4.10 and has been verified.  Please comment and
apply.

-- 
Mingming Cao

--- linux-2.4.10/fs/namei.c	Tue Sep 18 11:01:47 2001
+++ /home/ming/linux-tk/fs/namei.c	Tue Oct  9 11:58:50 2001
@@ -1362,6 +1362,8 @@
 		error = -ENOENT;
 	else if (d_mountpoint(dentry))
 		error = -EBUSY;
+	else if (dentry == current->fs->pwd)
+		error = -EBUSY;
 	else {
 		lock_kernel();
 		error = dir->i_op->rmdir(dir, dentry);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH]Fix bug:rmdir could remove current working directory
  2001-10-10 21:45 ` Alexander Viro
@ 2001-10-11  1:03   ` Mingming cao
  2001-10-10 22:09     ` Alexander Viro
                       ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Mingming cao @ 2001-10-11  1:03 UTC (permalink / raw)
  To: Alexander Viro; +Cc: Linus Torvalds, Alan Cox, linux-kernel

Alexander Viro wrote:
> 
> On Wed, 10 Oct 2001, Mingming cao wrote:
> 
> > Hi Linus, Alan and Al,
> >
> > I found that rmdir(2) could remove current working directory
> > successfully.  This happens when the given pathname points to current
> > working directory, not ".", but something else. For example, the current
> > working directory's absolute pathname.  I read the man page of
> > rmdir(2).  It says in this case EBUSY error should be returned.  I
> > suspected this is a bug and added a check in vfs_rmdir(). The following
> > patch is against 2.4.10 and has been verified.  Please comment and
> > apply.
> 
> It's not a bug.  Moreover, test you add is obviously bogus - what about
> cwd of other processes?
> 
> Actually, rmdir() on a busy directory _is_ OK.  Implementation is allowed
> to refuse doing that, but it's not required to.

I thought about the case when rmdir() on the cwd of other processes,
but, as you said, that is implementation dependent. However rmdir() on
"." does returns EBUSY error. Should not we keep the rmdir() behavior
consistent: rmdir() on the current working directory of the current
process is not OK?

-- 
Mingming Cao

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH]Fix bug:rmdir could remove current working directory
       [not found]     ` <200110102317.f9ANHjN03120@penguin.transmeta.com>
@ 2001-10-11  3:02       ` Mingming cao
  0 siblings, 0 replies; 8+ messages in thread
From: Mingming cao @ 2001-10-11  3:02 UTC (permalink / raw)
  To: Linus Torvalds, Al Viro; +Cc: linux-kernel

Linus Torvalds wrote:
> 
> In article <3BC4EFFC.42ACE59E@us.ibm.com>,
> Mingming cao  <cmm@us.ibm.com> wrote:
> >
> >I thought about the case when rmdir() on the cwd of other processes,
> >but, as you said, that is implementation dependent. However rmdir() on
> >"." does returns EBUSY error.
> 
> That's a completely different thing, though - even though the difference
> is rather subtle.
> 
> You can remove pretty much any empty directory (if the filesystem
> permits it - some don't). HOWEVER, you can not use "." as the final
> component of your pathname.
> 
> It has nothing to do with home directory: you can try just doing
> 
>         mkdir /tmp/hello
>         rmdir /tmp/hello/.
> 
> and you'll get the same error (and it _should_ return EINVAL, not EBUSY.
> EBUSY is for the "this filesystem doesn't allow you to remove a
> directory that is in use" case).
> 
>                         Linus

I misunderstanded the rule.  Thanks for clarifying!

-- 
Mingming Cao

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-10-11  0:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-10-11  0:32 [PATCH]Fix bug:rmdir could remove current working directory Mingming cao
2001-10-10 21:45 ` Alexander Viro
2001-10-11  1:03   ` Mingming cao
2001-10-10 22:09     ` Alexander Viro
2001-10-10 23:17     ` Linus Torvalds
     [not found]     ` <200110102317.f9ANHjN03120@penguin.transmeta.com>
2001-10-11  3:02       ` Mingming cao
2001-10-10 22:21 ` Ricky Beam
2001-10-10 23:36   ` John Levon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox