Sample Header Ad - 728x90

System call to remove content from file or Append it in the middle?

0 votes
1 answer
90 views
One issue that I ran into when making a custom database, without creating an entire block-chain based filesystem from scratch, is deletion and insertion from/to the *middle*. It's easy to many a binary file format that one can continually append to, and truncate from the end or from the beginning. But the issues happen when trying to edit a variable length entry in the middle or remove an entry from the middle, or insert a new entry to the middle. One generally has to rewrite at least the second half of the file to adjust for the new middle. Do any Linux based filesystems offer some kind of system call that allows one to simply "insert" data in the middle of a large file, without loading the 2nd half into RAM in order to rewrite it (and same goes for removing content from the center)? If this exists, it would be significantly easier to manage "array" or even hash based mini databases on disk without creating elaborate linked lists etc. If there's no native API is it possible to manually modify the inodes of the filesystem to achieve minimal rewriting, possibly only one or 2 4kb blocks loaded into ram for each operation, regardless of file size?
Asked by B''H Bi'ezras -- Boruch Hashem (121 rep)
Mar 18, 2025, 05:54 PM
Last activity: Mar 18, 2025, 09:55 PM