X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Fliblustreapi_lseek.c;h=90739994950dd9c4ac96342c0e001085a49a9cc3;hb=3d635dd3f24421c181aca5673cd81ed8f3e2c622;hp=0b82bfa1525809000f9a5823e33ebff52d934f73;hpb=0561c144cc1bb623e05d08b5055009e8d86047f4;p=fs%2Flustre-release.git diff --git a/lustre/utils/liblustreapi_lseek.c b/lustre/utils/liblustreapi_lseek.c index 0b82bfa..9073999 100644 --- a/lustre/utils/liblustreapi_lseek.c +++ b/lustre/utils/liblustreapi_lseek.c @@ -33,6 +33,9 @@ #include #include #include +#ifndef FALLOC_FL_PUNCH_HOLE +#include /* for RHEL7.3 glibc-headers and earlier */ +#endif #include #include #include @@ -109,3 +112,24 @@ off_t llapi_data_seek(int src_fd, off_t offset, size_t *length) *length = hole_off - data_off; return data_off; } + +/** + * Punch hole in a file. + * + * \param fd file descriptor + * \param start offset to start from + * \param length hole length + * + * \retval 0 on success. + * \retval -errno on failure to punch hole + */ +int llapi_hole_punch(int fd, off_t start, size_t length) +{ + int rc; + + rc = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + start, length); + if (rc) + rc = -errno; + return rc; +}