Skip to content

Comment on Ask HN: why is it faster to delete files from a disc than to write them?

Comments

Here's a very simplified example. Note that I am using some made up notation here: "." represents NULL charcaters, and the numbers would actually be stored in hexadecimal.

The contents of 48 byte disk with a 7 byte file allocation table (FAT):

    [................................................]
     FAT----DATA-------------------------------------
Write a file named "blah" with contents "abcdefghi":
    [blah.90abcdefghi................................]
     FAT----DATA-------------------------------------
Notice that the FAT area contains the filename, a "9" representing the length of the file, and a "0" indicating the spot in the data area where the file begins. In fact, the file system might choose the put the data somewhere else, and that's absolutely fine. For example:
    [blah.95.....abcdefghi...........................]
     FAT----DATA-------------------------------------
Represents the exact same contents with the file stored at an offset of 5. So say I want to delete this file now. A typical file system would do something like this:
    [.lah.95.....abcdefghi...........................]
     FAT----DATA-------------------------------------
It writes a single NULL byte to the file system to mark the filename as empty, and the file is gone. None of the rest of the data is cleaned up.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.