MCPcopy Create free account
hub / github.com/coreutils/coreutils / punch_hole

Function punch_hole

src/copy-file-data.c:44–58  ·  view source on GitHub ↗

Attempt to punch a hole to avoid any permanent speculative preallocation on file systems such as XFS. Return values as per fallocate(2) except ENOSYS etc. are ignored. */

Source from the content-addressed store, hash-verified

42 speculative preallocation on file systems such as XFS.
43 Return values as per fallocate(2) except ENOSYS etc. are ignored. */
44static int
45punch_hole (int fd, off_t offset, off_t length)
46{
47 int ret = 0;
48/* +0 is to work around older <linux/fs.h> defining HAVE_FALLOCATE to empty. */
49#if HAVE_FALLOCATE + 0
50# if defined FALLOC_FL_PUNCH_HOLE && defined FALLOC_FL_KEEP_SIZE
51 ret = fallocate (fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
52 offset, length);
53 if (ret < 0 && (is_ENOTSUP (errno) || errno == ENOSYS))
54 ret = 0;
55# endif
56#endif
57 return ret;
58}
59
60/* Create a hole at the end of the file with descriptor FD and name NAME.
61 The hole is of size SIZE. Assume FD is already at file end,

Callers 2

create_holeFunction · 0.85
copy_file_dataFunction · 0.85

Calls 1

is_ENOTSUPFunction · 0.85

Tested by

no test coverage detected