FALLOC_FL_COLLAPSE_RANGE
The Linux collapse-range operation removes a byte range from a Linux file, shifts later data left and reduces the file size.
Transformation: removing length L at offset O moves the suffix beginning at O+L to O and subtracts L from logical length. Unlike hole punching, it leaves no gap. In a logical illustration of equal aligned chunks, removing B from ABCD produces ACD. [1]
Boundaries: O must be nonnegative, L positive and O+L strictly below the old EOF. Removing a suffix through EOF calls for truncation instead. Filesystem support and alignment are required; no other mode flag, including KEEP_SIZE, may accompany collapse. [2]
Interface: util-linux exposes --collapse-range (-c). Check failures without assigning one universal errno to rejected flag combinations: Linux v6.12 vfs_fallocate uses EOPNOTSUPP for conflicting modes. [3] [4]
Persistence: the logical range transformation does not specify media sanitization. [1] Synchronizing modified file data and required metadata is a separate concern. [5]
Observed offset trap: a bounded Linux/ext4 probe kept the open-file position at byte 8192 while collapse changed its next byte from C to D and insert from C to B. This is one environment, not a portability guarantee. [7]
Relations
Citations
- Linux v6.12: fallocate range-mode contracts
- Linux man-pages: fallocate(2), range boundaries and mode restrictions
- util-linux v2.41.2: fallocate command options
- Linux v6.12: vfs_fallocate flag validation
- Linux man-pages: fsync(2), data and metadata synchronization
- Hesela: Native range transformation and cursor observation
Further reading
Sources & caveats
- Primary-documentation synthesis with logical illustrations and a separately scoped native Linux/ext4 byte-and-cursor probe; not a performance or crash measurement.
- Pinned Linux v6.12 and util-linux v2.41.2 sources do not establish support for every filesystem configuration.