[Novalug] smart deletion
John Franklin
franklin@elfie.org
Thu Sep 11 17:29:30 EDT 2014
Short answer: Gary is correct. The file (inode) is deleted (freed) when the reference count reaches zero. Directory entries and open file handles both count as references.
Based on a quick skimming, the other answers also look correct, but are more detailed. (One minor nit of Jason's answer: the version on disk is called an inode. The version in memory is called a vnode.)
jf
On Sep 11, 2014, at 4:25 PM, covici--- via Novalug <novalug@firemountain.net> wrote:
> I think it works by reference counts, so its much simpler -- at least
> this is my understanding and I know it works at least in ext4.
>
> Gary Knott via Novalug <novalug@firemountain.net> wrote:
>
>> If you run some program P that opens and reads
>> some file, say fx, and then while fx is still open and being read,
>> you run an editor and change and save fx, then:
>> (1) the directory entry for fx is changed, and any program that
>> opens and reads fx will get the new file.
>> (2) the program P continues to read the old version of fx.
>> (3) somehow the blocks that comprise the old file fx
>> will be reclaimed for re-use when it is safe to do so.
>>
>> Q: how does this work? I have one idea:
>>
>> 1. when the editor calls to delete fx (I think the call is unlink(...))
>> the OS detects that fx is open, and puts its inode and open-file-pointer
>> (id)
>> on a list of files to be deleted when they are closed.
>>
>> 2. Then the directory entry is changed to link to the new
>> file. (how is this done?)
>>
>> 3. Then when the open defunct file fx is closed, (explicitly
>> or implicitly when the program P is killed,) a check is made
>> as to whether that file is open anywhere (how can we know? -
>> there must be a table of file-pointer vs. inode?)
>> And if it's not, then the blocks are reclaimed.
>>
>> But there are some holes in this scenario, and
>> several other situations that need to be covered. Can anyone
>> explain how it really works, or point to a story that explains it?
>>
>> - gary knott, garyknott@gmail.com
>> **********************************************************************
>> The Novalug mailing list is hosted by firemountain.net.
>>
>> To unsubscribe or change delivery options:
>> http://www.firemountain.net/mailman/listinfo/novalug
>
> --
> Your life is like a penny. You're going to lose it. The question is:
> How do
> you spend it?
>
> John Covici
> covici@ccs.covici.com
> **********************************************************************
> The Novalug mailing list is hosted by firemountain.net.
>
> To unsubscribe or change delivery options:
> http://www.firemountain.net/mailman/listinfo/novalug
--
John Franklin
franklin@elfie.org
More information about the Novalug
mailing list