Does Windows (or NTFS) support placeholder files with fake sizes?
Every time I start Photoshop, it immediately creates a 2GB temporary file on the hard drive where the cache is located. It's a platter drive, and I don't hear any of the hard-drive noises that would normally be associated with writing 2GB of data. Is it possible to create an empty placeholder file with a "fake" size to reserve space in case it actually needs to cache some data later?
Solution 1:
There are two different ways this can be accomplished on an NTFS volume.
The SetEndOfFile
function, on NTFS file systems, reserves the disk space for the file but does not fill that space with anything. There might be a little disk activity here from updating the NTFS bookkeeping. When a program does anything to a file past the last byte that has previously been written, NTFS scribbles over the run between the last written (last "valid") byte and the requested byte (to avoid security problems) and updates the valid data pointer.
Then there are sparse files. Unlike normal files extended with SetEndOfFile
, NTFS keeps track of which sectors have actual data in them rather than just which byte is the last one with valid data. Long runs of zeroes where nothing has been written are not stored on the physical disk.
You can check whether a file is sparse with fsutil sparse queryflag
followed by the path to the file. If it's not sparse, the program is using the first approach.
Further reading: Why does my single-byte write take forever?
Solution 2:
Yes, this is called "sparse file".
NTFS and ReFS support it, but FAT32 and ExFAT not.
A program can explicitly tell the OS which byte ranges of a file should have space on the disk (per default, it's everything). The other, unallocated parts are treated like the contain just a lot of bytes with value 0 if read by the program.
In the file properties dialog, you'll see a "normal" file size, that's the "fake" one, and a size how much is used on the disk, that's the allocated part (plus some byte to get full HDD blocks).
Also see https://en.wikipedia.org/wiki/Sparse_file