From: Andreas Bombe <bombe@informatik.tu-muenchen.de>
To: Doug Alcorn <lathi@seapine.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: rm-ing files with open file descriptors
Date: Sat, 19 Jan 2002 05:18:57 +0100 [thread overview]
Message-ID: <20020119041857.GA10795@storm.local> (raw)
In-Reply-To: <87lmevjrep.fsf@localhost.localdomain>
In-Reply-To: <87lmevjrep.fsf@localhost.localdomain>
On Fri, Jan 18, 2002 at 04:11:26PM -0500, Doug Alcorn wrote:
>
> I had a weird situation with my application where the user deleted all
> the database files while the app was still reading and writing to the
> opened file descriptor. What was weird to me was that the app didn't
> complain. It just went merrily about it's business as if nothing were
> wrong. Of course, after the app shut down all it's data was lost.
Others already wrote that this is standard behaviour, but I'm in
lecturing mood right now.
You have to understand that under Unix, the user can not delete files.
Simple as that. Deleting files happens only at the kernel's discretion
(or in fsck after an unclean reboot).
In Unix style filesystems, files (inodes) and directory entries (links)
are separate things. Files as in inodes are just an entry in the
filesystem referenced by number. Directory entries aka file names aka
links are just a name associated with an inode number (try "ls -i"
sometime).
One inode can have multiple links pointing to it, they can be created
with ln (hardlinks, not "ln -s" symlinks). There is a syscall to deal
with removal of those links, but none that deal with file removal.
If a program does open("xyz") or something, the directory entry "xyz" is
consulted to find the inode, which is then opened. Now there is a
connection file descriptor <=> inode, the directory entries are totally
out of the loop now. It doesn't matter whether you move or remove the
links now.
Inodes have a reference count and they are automatically deleted when it
goes to zero. The reference count is the sum of link count and open
count. After you remove all links to the opened file it is still
referenced by the open and continues to exist. Only after the program
having the file open terminates does the ref count go to zero and cause
the file to be really deleted.
Whether that was an intended or accidental feature only someone with
more insight into Unix history can answer. It's that feature that lets
us do live upgrades of distributions without rebooting (executables and
libraries can be replaced without affecting the currently running
processes), at the very least much easier than it would be without this
behaviour.
It just may not be the most intuitive thing (like file name == file is),
but that is more than made up by its possibilities.
--
Andreas Bombe <bombe@informatik.tu-muenchen.de> DSA key 0x04880A44
next prev parent reply other threads:[~2002-01-19 4:20 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-18 21:11 rm-ing files with open file descriptors Doug Alcorn
2002-01-18 21:27 ` Xavier Bestel
2002-01-18 21:28 ` Ken Brownfield
2002-01-19 20:23 ` Rob Landley
2002-01-18 21:49 ` Richard B. Johnson
2002-01-19 0:50 ` Miquel van Smoorenburg
2002-01-19 2:29 ` H. Peter Anvin
2002-01-19 10:57 ` Xavier Bestel
2002-01-19 11:10 ` Miquel van Smoorenburg
2002-01-19 11:28 ` Alexander Viro
2002-01-19 12:01 ` Miquel van Smoorenburg
2002-01-23 12:18 ` Pavel Machek
2002-01-24 9:46 ` Herbert Xu
2002-01-19 17:44 ` Kai Henningsen
2002-01-20 15:30 ` Richard Kettlewell
2002-01-20 18:21 ` Doug McNaught
2002-01-20 23:10 ` Miquel van Smoorenburg
2002-01-20 3:55 ` Chris Wedgwood
2002-01-19 15:21 ` Horst von Brand
2002-01-19 15:32 ` Mr. James W. Laferriere
2002-01-19 20:26 ` Rob Landley
2002-01-19 17:53 ` Miquel van Smoorenburg
2002-01-20 15:48 ` Horst von Brand
2002-01-19 20:24 ` Rob Landley
2002-01-19 11:15 ` Ville Herva
2002-01-19 12:16 ` Matthias Schniedermeyer
2002-01-19 12:22 ` Xavier Bestel
2002-01-19 12:29 ` Alexander Viro
2002-01-19 12:46 ` Xavier Bestel
2002-01-19 13:18 ` Rogier Wolff
2002-01-19 15:24 ` Horst von Brand
2002-01-19 14:50 ` Horst von Brand
2002-01-20 14:23 ` Remi Turk
2002-01-20 20:02 ` Ville Herva
2002-01-20 20:44 ` Andreas Ferber
2002-01-20 21:08 ` Ville Herva
2002-01-21 9:06 ` Horst von Brand
2002-01-21 9:21 ` Ville Herva
2002-01-18 21:59 ` J Sloan
2002-01-19 4:18 ` Andreas Bombe [this message]
2002-01-19 14:51 ` christophe barbé
2002-01-19 18:01 ` Kai Henningsen
2002-01-20 3:43 ` christophe barbé
-- strict thread matches above, loose matches on Subject: below --
2002-01-18 22:11 Hank Leininger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020119041857.GA10795@storm.local \
--to=bombe@informatik.tu-muenchen.de \
--cc=lathi@seapine.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox