Re: removing a mounted loopback file works

J. S. Connell (ankh@canuck.gen.nz)
Thu, 1 Apr 1999 18:53:48 -0500 (EST)


On Thu, 1 Apr 1999, Tril wrote:

> But then I can remove the file slink1-i386.raw while it is mounted. After
> removing it, it's still listed as in use by mtab, /proc/mounts, and
> losetup /dev/loop0, and I can still access the filesystem through /mnt.

Yes. UNIX semantics dictate that unlinking an open file (and it's open if
it's mounted) simply removes its directory entry. The inodes and whatnot
are not reclaimed until the last user closes the file.

> If I try to unmount it then it takes longer than if I had not removed the
> file.

... because it's busy deallocating inodes and marking blocks as free.

> I think the correct behavior is for "rm" to return an error (permission
> denied, or some other error) if I try to remove the last (hard) link to a
> mounted file.

You can't remove the directory the image is mounted on, but the image file
is fair game. It's just another file, after all, that a process (well, I
guess the kernel's not a process, but it's close enough) happens to have
open.

--Jeff

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/