Hacker News new | past | comments | ask | show | jobs | submit login

> work around the fact that the sidecar file cannot be made inseparable from the main file while still being just another file.

Hmmm... have you ever heard about the concept of archive? It's a single file that you can copy around, but it contains literally several files inside!




Snark aside, this is obviously not a silver bullet. First reason that comes to mind: if you delete a file on the file system, the disk space can be reclaimed instantly. But if you delete a file in an archive, you must either rewrite the archive (since you can't "move" bytes in a file), or accept that disk space will be wasted.


> But if you delete a file in an archive, you must either rewrite the archive (since you can't "move" bytes in a file), or accept that disk space will be wasted.

Another option is to tell the operating system to deallocate part of the file, turning it into a sparse file. This can be done with fallocate(FALLOC_FL_PUNCH_HOLE) on Linux, FSCTL_SET_ZERO_DATA on Windows.

Linux also has fallocate(FALLOC_FL_COLLAPSE_SIZE) which lets you actually remove a byte range from the middle of a file, shifting up everything that comes after that byte range. So, in fact, you can "move" bytes in a file, on certain filesystems on Linux (ext4, xfs, among others).

Unfortunately, support for sparse files is quite variable across platforms. The macOS equivalent to fallocate(FALLOC_FL_PUNCH_HOLE) if fcntl(F_PUNCHHOLE), but the issue is HFS+ has never supported sparse files. UFS did, but UFS support was dropped from 10.7 onwards. The support is supposed to be back in APFS, but I don't know if it actually works.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: