Whamcloud - gitweb
LU-15220 utils: use 'fallthrough' pseudo keyword for switch
[fs/lustre-release.git] / lustre / utils / liblustreapi_lseek.c
index 0b82bfa..9073999 100644 (file)
@@ -33,6 +33,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#ifndef FALLOC_FL_PUNCH_HOLE
+#include <linux/falloc.h> /* for RHEL7.3 glibc-headers and earlier */
+#endif
 #include <sys/syscall.h>
 #include <sys/ioctl.h>
 #include <errno.h>
@@ -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;
+}