Media file can be played after deleted?

2

I have experienced the following paradox many times, and I don't understand how it happens.

I open a big music/video file (say 100 MB), and when it starts playing, I delete it (permanently). In spite of this, the media player will be able to play the whole thing.
I guess it doesn't buffer the whole file at the beginning, because

  • memory usage by the process is only 15 MB
  • and that's not what media players do anyway.

So how does this happen?

Dave

Posted 2013-02-11T20:07:49.497

Reputation: 123

Answers

6

The exact details depend on your system, but the basic idea is that the underlying filesystem won't pull the rug out from under an open file. It deletes it from everywhere you can see it, but it won't actually clean up the blocks on disk (nor some representation of the directory structures that point to the file) until you close it.

On Unix systems this is common: most unix filesystems won't blow away an inode until the last open filehandle is closed.

On Windows, it seems that if the opening process specifies 'FILE_SHARE_DELETE' to the CreateFile call (which a well behaved program should do), then the filesystem driver processes the deletion, but the open files can still access it. Once the last open HANDLE to the file is closed, then the file is cleaned up by the file system driver.

Michael Kohne

Posted 2013-02-11T20:07:49.497

Reputation: 3 808

But I use Windows... Wether I can delete it or not seems to depend on the file type. – Dave – 2013-02-11T20:29:30.093

2@Dave - see my revision - Windows has a way that (well behaved) programs can cause this to work correctly. – Michael Kohne – 2013-02-11T20:37:35.300

agreed, this is a side effect of thread/multi-process resource share. – Frank Thomas – 2013-02-11T21:08:49.627