[darcs-users] DeleteFile on Windows

Trent W. Buck twb at cybersource.com.au
Fri Oct 9 04:18:38 UTC 2009


Jason Dagit <dagit at codersbase.com> writes:

> I want to see if I understand the situation correctly.

On POSIX, there is an intermediary layer ("inodes") between filesystem
paths and objects on disk.

Let's make a file:

    $ touch /tmp/x
    $ ls -i /tmp/x
    11012 /tmp/x

I know have a new object with inode 11012 on disk, which is referenced
in /tmp's directory metadata as "x".

I can open it:

    $ cat /tmp/x

I can open the stream and leave it open:

    $ sleep 1h >>/tmp/x &
    [1] 4402

And at this point, I can delete /tmp's reference to that inode:

    $ rm /tmp/x
    $ touch /tmp/x
    $ ls -i /tmp/x
    11072 /tmp/x

But that sleep process still has the old inode open:

    $ lsof -p 4402 | grep 11012
    sleep   4402  twb    1w   REG       0,17        1  11012 /tmp/x (deleted)

Nothing else can open inode 11012, but the kernel cannot GC that inode's
data from the disk until sleep closes it.

So when you say

> On POSIX even if a file is open you can write over it, on windows this
> is not the case

You're overwriting the directory's reference, you're not overwriting the
underlying inode.


This is, incidentally, why you can replace files like libc.so while the
system is running -- all the running apps will continue to refer to the
old inode, but newly started apps will access the new inode.  On
Windows, at least historically, you had to restart the entire machine to
update such low-level files, because they're always open.



More information about the darcs-users mailing list