>  Why do you feel files are so unloved?  :)

Why was Ken unliking his files?  I just went a step in the wrong direction.  :-)

It looks like my original reply didn't copy to the list due to me sending
from my other Email account.  So, one more time:

From: Ben Scott <dragonh...@gmail.com>

> On Tue, Feb 19, 2013 at 2:40 PM, Ken D'Ambrosio <k...@jots.org> wrote:
> > If process A is reading from a file, and process B deletes it, process
> > A can continue to read from it until... well, until it stops reading
> > from it.

>   Remember, in *nix, one doesn't really delete files (inodes).  One
> unlinks directory entries.  The kernel deletes files once all
> references are gone.

Well, FS writers generally keep the link count and open count separate
entities, largely because they are.  Then there's a separate "ref count"
for all the kernel threads that are mucking with the kernel data
structures for that inode.  That's usually incremented when the file is
opened so the kernel doesn't have to check the open count.  (The process
has a file struct for each open file, hence holds a ref for that pointer.)

When the ref count is requested to drop to zero then the open count
should be zero, and if the link count is zero then the inode is freed.
The kernel data structures are freed, and by then there's no ref count
left to decrement to zero.

>   One of the things fsck does is check for inodes with a zero actual
> reference count, and link them in "lost+found" by inode number.

More precisely, given that the FS is unmounted when fsck is willing to
make changes, nothing has the file open, let alone reffed, so the link count
is the sole test, well, if there are indeed no directory entries linking to
the file.  If there are, that means the inode was written before a directory
block without the directory entry to the file was written, so fsck will
update the directory too.

  -Ric

-- 
r...@wermenh.com                http://WermeNH.com/
_______________________________________________
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/

Reply via email to