fallocate(2) System Calls Manual fallocate(2) fallocate - C (libc, -lc) #define _GNU_SOURCE /* feature_test_macros(7) */ #include int fallocate(int fd, int mode, off_t offset, off_t len); , Linux. POSIX.1 , ( posix_fallocate(3)). fallocate() , fd, , offset len . mode , . . (. . mode ) fallocate() , offset len. ( stat(2)) , offset+len . , offset len, , . posix_fallocate(3), . , offset len, - . mode FALLOC_FL_KEEP_SIZE, , , offset+len . . mode FALLOC_FL_UNSHARE_RANGE, extent- , , - . , . . , fallocate() , . FALLOC_FL_PUNCH_HOLE (, Linux 2.6.38) mode (.., ) offset len . , . , . FALLOC_FL_PUNCH_HOLE FALLOC_FL_KEEP_SIZE mode; , (punching) , ( stat(2)) . FALLOC_FL_PUNCH_HOLE; , . , , : o XFS ( Linux 2.6.38) o ext4 ( Linux 3.0) o Btrfs ( Linux 3.7) o tmpfs(5) ( Linux 3.5) o gfs2(5) ( Linux 4.16) (Collapsing) FALLOC_FL_COLLAPSE_RANGE (, Linux 3.15) mode . offset len . , , offset+len, offset, len . , . , offset len , . , fallocate() EINVAL. , offset len , ; ftruncate(2) . FALLOC_FL_COLLAPSE_RANGE mode . Linux 3.15 FALLOC_FL_COLLAPSE_RANGE ext4 ( extent) XFS. FALLOC_FL_ZERO_RANGE (, Linux 3.15) mode , offset len . , . . , , , extents. , ( ), - . mode FALLOC_FL_KEEP_SIZE, , , offset+len . FALLOC_FL_KEEP_SIZE. FALLOC_FL_ZERO_RANGE; , . , , : o XFS ( Linux 3.15) o ext4, extent ( Linux 3.15) o SMB3 ( Linux 3.17) o Btrfs ( Linux 4.16) FALLOC_FL_INSERT_RANGE ( Linux 4.1) mode (hole) . offset len . , offset, (. ., ) len . len . FALLOC_FL_COLLAPSE_RANGE, , fallocate() EINVAL. offset , . (. ., ) ftruncate(2). FALLOC_FL_INSERT_RANGE mode . FALLOC_FL_INSERT_RANGE ; XFS ( Linux 4.1) ext4 ( Linux 4.2). fallocate() 0; -1, errno . EBADF fd . EFBIG offset+len . EFBIG mode FALLOC_FL_INSERT_RANGE, +len . EINTR ; signal(7). EINVAL offset 0, len 0. EINVAL mode FALLOC_FL_COLLAPSE_RANGE, , offset len, . EINVAL mode FALLOC_FL_INSERT_RANGE, , offset, . EINVAL mode FALLOC_FL_COLLAPSE_RANGE FALLOC_FL_INSERT_RANGE, offset len . EINVAL mode FALLOC_FL_COLLAPSE_RANGE FALLOC_FL_INSERT_RANGE, ; FALLOC_FL_COLLAPSE_RANGE FALLOC_FL_INSERT_RANGE . EINVAL mode is FALLOC_FL_COLLAPSE_RANGE, FALLOC_FL_ZERO_RANGE, or FALLOC_FL_INSERT_RANGE, but the file referred to by fd is not a regular file. EIO -. ENODEV fd ( fd -- FIFO, ). ENOSPC , , fd. ENOSYS fallocate() . EOPNOTSUPP , fd, ; mode , , fd. EPERM , fd, (immutable) ( chattr(1)). EPERM mode specifies FALLOC_FL_PUNCH_HOLE, FALLOC_FL_COLLAPSE_RANGE, or FALLOC_FL_INSERT_RANGE and the file referred to by fd is marked append-only (see chattr(1)). EPERM (file seal); fcntl(2). ESPIPE fd FIFO. ETXTBSY mode FALLOC_FL_COLLAPSE_RANGE FALLOC_FL_INSERT_RANGE, , fd, . Linux. fallocate() Linux 2.6.23, glibc 2.10. FALLOC_FL_* glibc 2.18. fallocate(1), ftruncate(2), posix_fadvise(3), posix_fallocate(3) () Azamat Hackimov , Dmitry Bolkhovskikh , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux 6.9.1 2 2024 . fallocate(2)