MCPcopy Create free account
hub / github.com/RsyncProject/rsync / do_punch_hole

Function do_punch_hole

syscall.c:1561–1596  ·  view source on GitHub ↗

Punch a hole at pos for len bytes. The current file position must be at pos and will be * changed to be at pos + len. */

Source from the content-addressed store, hash-verified

1559/* Punch a hole at pos for len bytes. The current file position must be at pos and will be
1560 * changed to be at pos + len. */
1561int do_punch_hole(int fd, OFF_T pos, OFF_T len)
1562{
1563#ifdef HAVE_FALLOCATE
1564# ifdef HAVE_FALLOC_FL_PUNCH_HOLE
1565 if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, pos, len) == 0) {
1566 if (do_lseek(fd, len, SEEK_CUR) != pos + len)
1567 return -1;
1568 return 0;
1569 }
1570# endif
1571# ifdef HAVE_FALLOC_FL_ZERO_RANGE
1572 if (fallocate(fd, FALLOC_FL_ZERO_RANGE, pos, len) == 0) {
1573 if (do_lseek(fd, len, SEEK_CUR) != pos + len)
1574 return -1;
1575 return 0;
1576 }
1577# endif
1578#else
1579 (void)pos;
1580#endif
1581 {
1582 char zeros[4096];
1583 memset(zeros, 0, sizeof zeros);
1584 while (len > 0) {
1585 int chunk = len > (int)sizeof zeros ? (int)sizeof zeros : len;
1586 int wrote = write(fd, zeros, chunk);
1587 if (wrote <= 0) {
1588 if (wrote < 0 && errno == EINTR)
1589 continue;
1590 return -1;
1591 }
1592 len -= wrote;
1593 }
1594 }
1595 return 0;
1596}
1597
1598int do_open_nofollow(const char *pathname, int flags)
1599{

Callers 2

sparse_endFunction · 0.85
write_sparseFunction · 0.85

Calls 1

do_lseekFunction · 0.85

Tested by

no test coverage detected