6

Assuming

  • we have huge file F.
  • we like to put "around" seek s a new empty (filled with zeros) block in O(1) time (i.e. without rewriting all remining part)
  • "around" means we can round s to nearest filesystem blocksisze, and block to insert could be also filesystem blocksize

Is there a systemcall/filesystem that would allow such?

If not, is it good idea to mimic such behaviour using btrfs_clone (mentined here ) and how?

3

Quote from this answer :

As of Linux 4.1, fallocate(2) supports the FALLOC_FL_INSERT_RANGE flag, which allows one to insert a hole of a given length in the middle of a file without rewriting the following data. However, it is rather limited: the hole must be inserted at a filesystem block boundary, and the size of the inserted hole must be a multiple of the filesystem block size. Additionally, in 4.1, this feature was only supported by the XFS filesystem, with Ext4 support added in 4.2.

From fallocate(1) :

fallocate -d [-o offset] [-l length] filename
(...)
       -d, --dig-holes
              Detect  and  dig  holes.   This  makes  the  file  sparse in-place, without using extra disk space.  The minimum size of the hole depends on
              filesystem I/O block size (usually 4096 bytes).  Also, when using this option, --keep-size is implied.  If no range is specified by --offset
              and --length, then the entire file is analyzed for holes.

              You  can  think  of  this option as doing a "cp --sparse" and then renaming the destination file to the original, without the need for extra
              disk space.

              See --punch-hole for a list of supported filesystems.
(...)
       -p, --punch-hole
(...)
              Supported for XFS (since Linux 2.6.38), ext4 (since Linux 3.0), Btrfs (since Linux 3.7) and tmpfs (since Linux 3.5).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.