can we remove a directory from within that directory??

2005-11-21 Thread kuldeep vyas
   [input][input][input][input] 
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;

k>ls /home/k/
  // my_dir gone 

k>pwd
/home/k/my_dir
  // oops!!

  // let's create my_file here!!
k>cat >my_file
bash: my_file: no such file or directory
  // I'm not allowed to a create file here.


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.

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

Happy contributing to LINUX!!

kuldeep vyas
  


-
 Yahoo! FareChase - Search multiple travel sites in one click.  
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


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

2005-11-21 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE-
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 [EMAIL PROTECTED]
-BEGIN PGP SIGNATURE-
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

iD8DBQFDgc/W84KuGfSFAYARAiIbAKCX/2SzbsWHbB/3DDBnQZGiVio/0wCfSQ4q
9Pw6xoNu9gBiM3o1shwxJRU=
=GbPm
-END PGP SIGNATURE-


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


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

2005-11-21 Thread Andreas Schwab
kuldeep vyas <[EMAIL PROTECTED]> writes:

> k>pwd
> /home/k/my_dir
>   // oops!!

Try /bin/pwd.

> pwd says I'm in my_dir, but my_dir doesn't exist.

It does, it just doesn't have a name any more.

> 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.

There is nothing wrong with unlinking a file (of any type) that is still
in use.

Andreas.

-- 
Andreas Schwab, SuSE Labs, [EMAIL PROTECTED]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


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

2005-11-21 Thread Phillip Susi
It is a general design philosophy of linux, and unix in general, that 
the kernel will not enforce locking of files.  This is why you can 
upgrade software without rebooting: the old file can be deleted and 
replaced with the new file, even though it is still in use.  Of course, 
it isn't actually deleted until everyone using it closes it, but it's 
name is removed from the directory tree immediately.


If you really want to mess up a system, you can rm -fr / ( as root of 
course ) and it will happily delete all the files on the system. 
Whatever is running at the time will keep running, but new opens will 
fail.  This behavior is pretty much by design.


kuldeep vyas wrote:
   [input][input][input][input] 
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;

k>ls /home/k/
  // my_dir gone 


k>pwd
/home/k/my_dir
  // oops!!

  // let's create my_file here!!
k>cat >my_file
bash: my_file: no such file or directory
  // I'm not allowed to a create file here.


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.


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


Happy contributing to LINUX!!

kuldeep vyas
  







___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


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

2005-11-21 Thread Philip Rowlands

On Mon, 21 Nov 2005, kuldeep vyas wrote:


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:-

[snip]


k>ls /home/k/
 // my_dir gone

k>pwd
/home/k/my_dir
 // oops!!


It's likely here that "pwd" is the shell's builtin version, rather than 
coreutils'.


Here what I see when calling /bin/pwd explicitly:

$ rmdir -v $(/bin/pwd)
rmdir: removing directory, /tmp/not-here
$ /bin/pwd
/bin/pwd: cannot get current directory: No such file or directory

I'd agree that this discrepancy between shell builtin and coreutil is 
somewhat confusing.



Cheers,
Phil


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


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

2005-11-21 Thread kuldeep vyas

  Hi Phillip,
  
  Thanks for information.
  While upgrading software (without reboot): this design technique is really 
good.
  But I've a doubt:-
When we purchase License of a software/tool, after expiry date: License 
Files
 1. are deleted, OR
 2. are modified so that they can't be used further, OR
 3. use date & time of the computer(on which they are running) to get 
expired,
 et al.
  
  Some softwares & tools can still be used even after expiry date,  because 
they had started running before expiry date & never closed  & hence still 
running even after expiry date. License files which  are in the directory tree: 
come into picture when software/tool is  started.
  Most of the softwares & tools are robust enough in design to handle this but 
some are still vulnerable.
I wonder whether Operating System provides some option to ensure that:
a file which is modified in the directory-tree must be accordingly  & 
instantly updated in all forms of memory(RAM, cache etc.)
  I mean whatever is running in the system should not be keep on running  once 
it's modified to stop & we shouldn't have to wait for next  open.
  
 Happy contributing to LINUX!!
  
  kuldeep vyas
  
  
  
   
  
  
  
Phillip Susi <[EMAIL PROTECTED]> wrote:  It is a general design philosophy of 
linux, and unix in general, that 
the kernel will not enforce locking of files.  This is why you can 
upgrade software without rebooting: the old file can be deleted and 
replaced with the new file, even though it is still in use.  Of course, 
it isn't actually deleted until everyone using it closes it, but it's 
name is removed from the directory tree immediately.

If you really want to mess up a system, you can rm -fr / ( as root of 
course ) and it will happily delete all the files on the system. 
Whatever is running at the time will keep running, but new opens will 
fail.  This behavior is pretty much by design.

kuldeep vyas wrote:
 
> 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;
> 
> k>ls /home/k/
>   // my_dir gone 
> 
> k>pwd
> /home/k/my_dir
>   // oops!!
> 
>   // let's create my_file here!!
> k>cat >my_file
> bash: my_file: no such file or directory
>   // I'm not allowed to a create file here.
> 
> 
> 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.
> 
> If my approach is not right, I'd like to know the 
> philosophy behind this.
> 
> Happy contributing to LINUX!!
> 
> kuldeep vyas
>   
> 
>   





-
 Yahoo! FareChase - Search multiple travel sites in one click.  
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


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

2005-11-22 Thread James Youngman
On Mon, Nov 21, 2005 at 10:45:08PM -0800, kuldeep vyas wrote:

> I wonder whether Operating System provides some option to ensure that:
> a file which is modified in the directory-tree must be accordingly  & 
> instantly updated in all forms of memory(RAM, cache etc.)
>   I mean whatever is running in the system should not be keep on running  
> once it's modified to stop & we shouldn't have to wait for next  open.

This is a question about your operating system, not coreutils.  It's
off-topic for this list, really.

With traditional Unix semantics, I/O against a file gives consistent
results across all processes (on the same machine) which have it open,
even if it is 'deleted'.

In Unix, the only meaning of the 'unlink' system call is to reduce the
link count of a file by one.  That's it.  It does nothing else.  There
is no separate 'delete' system call.

Once the link count of a file reaches zero, it can no longer be opened
(because it no longer has a name, no possible argument to the open(2)
system call can select it) but processes that already have it open can
continue to use it.

When a file is closed and no other processes have the file open, and
the current link count of the file is zero, the inode and data blocks
of the file's data are reclaimed.

I've tried to be clear here, but this is not really the place for long
explanations of how Unix works.  If you are still in need of further
information here, I would suggest that you read the book "Advanced
Programming in the Unix Environment" by W. Richard Stevens.

Regards,
James.


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils