Why are there no file insertion syscalls
On recent Linux systems that is actually possible, but with block (4096 most of the time), not byte granularity, and only on some filesystems (ext4 and xfs).
Quoting from the fallocate(2)
manpage:
int fallocate(int fd, int mode, off_t offset, off_t len);
[...]
Collapsing file space
Specifying the
FALLOC_FL_COLLAPSE_RANGE
flag (available since Linux 3.15) inmode
removes a byte range from a file, without leaving a hole. The byte range to be collapsed starts atoffset
and continues forlen
bytes. At the completion of the operation, the contents of the file starting at the locationoffset+len
will be appended at the locationoffset
, and the file will belen
bytes smaller.[...]
Increasing file space
Specifying the
FALLOC_FL_INSERT_RANGE
flag (available since Linux 4.1) inmode
increases the file space by inserting a hole within the file size without overwriting any existing data. The hole will start atoffset
and continue forlen
bytes. When inserting the hole inside file, the contents of the file starting atoffset
will be shifted upward (i.e., to a higher file offset) bylen
bytes. Inserting a hole inside a file increases the file size bylen
bytes.
As all current file systems do not require the file to be stored in a continuous memory block,
Filesystems might not require files to be stored in a continuous area (and that would be very inflexible indeed), but usually files are stored in fixed-size blocks (or sequences of contiguous blocks). Doing it that way simplifies the implementation, and the blocks are usually multiples of the block size of the underlying device.
So, implementing inserts of blocks with arbitrary length would make the file system format and implementation rather more complex or require moving potentially large amounts of data around. Neither of those is really good, and complex data structures can be built in userspace on top of the filesystem API.