[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: can we remove a directory from within that directory??

From: Eric Blake
Subject: Re: can we remove a directory from within that directory??
Date: Mon, 21 Nov 2005 06:47:03 -0700
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Hash: SHA1

According to kuldeep vyas on 11/21/2005 4:42 AM:
> Hi,
> I'm using Redhat 9 (kernel 2.4.20-8 on i686)
> I logged in as k(username), then I started terminal, &
> then I gave following commands:-
> k>pwd
> /home/k
> k>mkdir my_dir
>   // i created a directory: my_dir
> k>cd my_dir
>   // let's go in my_dir
>   // now let's try to remove my_dir
> k>rmdir /home/k/my_dir
>   // no error;
> pwd says I'm in my_dir, but my_dir doesn't exist.
> I think: user should not be allowed to remove a directory,
> until & unless he is placed in a directory which is 
> hierarchically above the one he has chosen to remove.

POSIX allows this behavior, but does not require it.  Basically, on
systems where it is legal to remove a directory that is in use, such as on
Linux, the directory continues to exist until all references to it (such
as processes that have it as the current working directory) have closed
their file descriptors, even though the directory is no longer accessible
from the file system.  On other platforms, such as cygwin, where removing
an in-use directory is forbidden by the OS, rmdir faithfully returns the
error 'Device or resource busy'.  It is a feature of Linux, and not a bug
in coreutils, that rmdir on Linux can remove an in-use directory; and
coreutils is just happy to provide the exact capabilities of the
underlying system in this case.

> If my approach is not right, I'd like to know the 
> philosophy behind this.

You are welcome to try and patch the Linux kernel to have rmdir fail with
EBUSY if the directory is in use, but you will probably find that this
increases the complexity of the kernel and would be a tough sell to the
kernel crowd.

- --
Life is short - so eat dessert first!

Eric Blake             address@hidden
Version: GnuPG v1.4.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org


reply via email to

[Prev in Thread] Current Thread [Next in Thread]