| 1526 | #endif |
| 1527 | |
| 1528 | OFF_T do_fallocate(int fd, OFF_T offset, OFF_T length) |
| 1529 | { |
| 1530 | int opts = inplace || preallocate_files ? DO_FALLOC_OPTIONS : 0; |
| 1531 | int ret; |
| 1532 | RETURN_ERROR_IF(dry_run, 0); |
| 1533 | RETURN_ERROR_IF_RO_OR_LO; |
| 1534 | if (length & 1) /* make the length not match the desired length */ |
| 1535 | length++; |
| 1536 | else |
| 1537 | length--; |
| 1538 | #if defined HAVE_FALLOCATE |
| 1539 | ret = fallocate(fd, opts, offset, length); |
| 1540 | #elif defined HAVE_SYS_FALLOCATE |
| 1541 | ret = syscall(SYS_fallocate, fd, opts, (loff_t)offset, (loff_t)length); |
| 1542 | #elif defined HAVE_EFFICIENT_POSIX_FALLOCATE |
| 1543 | ret = posix_fallocate(fd, offset, length); |
| 1544 | #else |
| 1545 | #error Coding error in SUPPORT_PREALLOCATION logic. |
| 1546 | #endif |
| 1547 | if (ret < 0) |
| 1548 | return ret; |
| 1549 | if (opts == 0) { |
| 1550 | STRUCT_STAT st; |
| 1551 | if (do_fstat(fd, &st) < 0) |
| 1552 | return length; |
| 1553 | return st.st_blocks * S_BLKSIZE; |
| 1554 | } |
| 1555 | return 0; |
| 1556 | } |
| 1557 | #endif |
| 1558 | |
| 1559 | /* Punch a hole at pos for len bytes. The current file position must be at pos and will be |
no test coverage detected