Implemented for Linux. Doesn't look like other OSes support this.
sys/quota.h sys/fs/ufs_quota.h ufs/ufs/quota.h jfs/quota.h sys/fs/quota_common.h \
mntent.h sys/mnttab.h sys/event.h sys/time.h sys/mkdev.h linux/dqblk_xfs.h \
xfs/xqm.h execinfo.h ucontext.h malloc_np.h sys/utsname.h sys/vmount.h \
- sys/utsname.h glob.h)
+ sys/utsname.h glob.h linux/falloc.h)
dnl * gcc specific options
if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
setrlimit setproctitle seteuid setreuid setegid setresgid \
strtoull strtoll strtouq strtoq \
setpriority quotactl getmntent kqueue kevent backtrace_symbols \
- walkcontext dirfd clearenv malloc_usable_size glob)
+ walkcontext dirfd clearenv malloc_usable_size glob fallocate)
AC_CHECK_LIB(rt, clock_gettime, [
AC_DEFINE(HAVE_CLOCK_GETTIME,, Define if you have the clock_gettime function)
#ifdef HAVE_POSIX_FALLOCATE
# define _XOPEN_SOURCE 600 /* Required by glibc, breaks Solaris 9 */
#endif
+#define _GNU_SOURCE /* for fallocate() */
#include "lib.h"
#include "file-set-size.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
+#ifdef HAVE_LINUX_FALLOC_H
+# include <linux/falloc.h>
+#endif
int file_set_size(int fd, off_t size)
{
}
return 0;
}
+
+int file_preallocate(int fd ATTR_UNUSED, off_t size ATTR_UNUSED)
+{
+#if defined(HAVE_FALLOCATE) && defined(FALLOC_FL_KEEP_SIZE)
+ /* Linux */
+ if (fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, size) < 0)
+ return errno == ENOSYS ? 0 : -1;
+ return 1;
+#else
+ return 0;
+#endif
+}
be zeros. The file offset may be anywhere after this call.
Returns -1 if failed, 0 if successful. */
int file_set_size(int fd, off_t size);
+/* Preallocate file to given size, without actually changing the size
+ reported by stat(). Returns 1 if ok, 0 if not supported by this filesystem,
+ -1 if error. */
+int file_preallocate(int fd, off_t size);
#endif