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. */
| 42 | speculative preallocation on file systems such as XFS. |
| 43 | Return values as per fallocate(2) except ENOSYS etc. are ignored. */ |
| 44 | static int |
| 45 | punch_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, |
no test coverage detected