From 4fce74899576fa97c58a7e1de977d9c5a4551645 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?=
Date: Thu, 21 May 2009 08:03:00 +0100
Subject: [PATCH] fallocate: New module to ensure this interface is available
FIXME: reference online man page somewhere in docs
fallocate() allows one to associate a unit of space
with a (portion of a) file before writing. This info can
then be used to immediately determine if enough space is available,
and also allow efficient allocation on the storage device.
* m4/fallocate.m4: check we can link to fallocate()
* m4/fcntl_h.m4: default to not replacing fallocate()
* lib/fcntl.in.h: replacement declaration
* lib/fallocate.c: replacement stub
* modules/fallocate: dependencies for new module
* modules/fcntl: substitute REPLACE_FALLOCATE in fcntl.in.h
* MODULES.html.sh (File system functions): add it
---
MODULES.html.sh | 1 +
lib/fallocate.c | 31 +++++++++++++++++++++++++++++++
lib/fcntl.in.h | 6 ++++++
m4/fallocate.m4 | 29 +++++++++++++++++++++++++++++
m4/fcntl_h.m4 | 5 +++--
modules/fallocate | 24 ++++++++++++++++++++++++
modules/fcntl | 1 +
7 files changed, 95 insertions(+), 2 deletions(-)
create mode 100644 lib/fallocate.c
create mode 100644 m4/fallocate.m4
create mode 100644 modules/fallocate
diff --git a/MODULES.html.sh b/MODULES.html.sh
index 06afa2d..6a1e058 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2438,6 +2438,7 @@ func_all_modules ()
func_module dirfd
func_module double-slash-root
func_module euidaccess
+ func_module fallocate
func_module file-type
func_module fileblocks
func_module filemode
diff --git a/lib/fallocate.c b/lib/fallocate.c
new file mode 100644
index 0000000..afa4a67
--- /dev/null
+++ b/lib/fallocate.c
@@ -0,0 +1,31 @@
+/* Allocate storage for a file descriptor.
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+/* Written by Pádraig Brady
, 2009. */
+
+#include
+#include
+#include
+
+/* FIXME: look at orig email for this file definition. */
+int rpl_fallocate (int fd, int mode, off_t offset, off_t len)
+{
+ /* This is a valid replacement for missing glibc fallocate(),
+ because code calling fallocate() must also handle this error
+ in the case that the kernel or filesystem don't support this. */
+ return ENOSYS; /* FIXME: glibc interface may change to set errno and ret -1 */
+ /* FIXME: support fcntl(fd, F_ALLOCSP, ...) on solaris. */
+}
diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h
index fd7520e..3af41ad 100644
--- a/lib/fcntl.in.h
+++ b/lib/fcntl.in.h
@@ -138,6 +138,12 @@ extern void _gl_register_fd (int fd, const char *filename);
# define O_TEXT 0
#endif
+#if @REPLACE_FALLOCATE@
+# define fallocate rpl_fallocate
+# undef FALLOC_FL_KEEP_SIZE /* Ensure this name is available. */
+# define FALLOC_FL_KEEP_SIZE 0x01
+int fallocate (int fd, int mode, off_t offset, off_t len);
+#endif
#endif /* _GL_FCNTL_H */
#endif /* _GL_FCNTL_H */
diff --git a/m4/fallocate.m4 b/m4/fallocate.m4
new file mode 100644
index 0000000..510d965
--- /dev/null
+++ b/m4/fallocate.m4
@@ -0,0 +1,29 @@
+# fallocate.m4 serial 1
+dnl Copyright (C) 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FALLOCATE],
+[
+ dnl Remove this when glibc doesn't require it
+ AC_CHECK_HEADERS_ONCE([linux/falloc.h])
+
+ AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
+ dnl Persuade glibc to declare fallocate().
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+ AC_CACHE_CHECK([for fallocate], [gl_cv_func_fallocate], [
+ AC_TRY_LINK([#include /* fallocate() declaration */
+ #include /* FALLOC_FL_KEEP_SIZE define */],
+ [fallocate(-1, FALLOC_FL_KEEP_SIZE, 0, 0);],
+ [gl_cv_func_fallocate=yes], [gl_cv_func_fallocate=no])])
+
+ if test $gl_cv_func_fallocate = yes; then
+ AC_DEFINE([HAVE_FALLOCATE], [1], [Defined if fallocate() exists])
+ else
+ AC_REQUIRE([AC_C_INLINE])
+ REPLACE_FALLOCATE=1; AC_SUBST([REPLACE_FALLOCATE])
+ AC_LIBOBJ([fallocate])
+ fi
+])
diff --git a/m4/fcntl_h.m4 b/m4/fcntl_h.m4
index 1ae0b15..8f2c4c0 100644
--- a/m4/fcntl_h.m4
+++ b/m4/fcntl_h.m4
@@ -90,7 +90,8 @@ AC_DEFUN([gl_FCNTL_MODULE_INDICATOR],
AC_DEFUN([gl_FCNTL_H_DEFAULTS],
[
- GNULIB_OPEN=0; AC_SUBST([GNULIB_OPEN])
+ GNULIB_OPEN=0; AC_SUBST([GNULIB_OPEN])
dnl Assume proper GNU behavior unless another module says otherwise.
- REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN])
+ REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN])
+ REPLACE_FALLOCATE=0; AC_SUBST([REPLACE_FALLOCATE])
])
diff --git a/modules/fallocate b/modules/fallocate
new file mode 100644
index 0000000..c4eac45
--- /dev/null
+++ b/modules/fallocate
@@ -0,0 +1,24 @@
+Description:
+fallocate() function: allocate disk space for a file.
+
+Files:
+m4/fallocate.m4
+lib/fallocate.c
+
+Depends-on:
+extensions
+fcntl
+
+configure.ac:
+gl_FUNC_FALLOCATE
+
+Makefile.am:
+
+Include:
+#include
+
+License:
+LGPL
+
+Maintainer:
+Pádraig Brady
diff --git a/modules/fcntl b/modules/fcntl
index de0aeb9..8f33e7d 100644
--- a/modules/fcntl
+++ b/modules/fcntl
@@ -26,6 +26,7 @@ fcntl.h: fcntl.in.h
-e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \
-e 's|@''GNULIB_OPEN''@|$(GNULIB_OPEN)|g' \
-e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \
+ -e 's|@''REPLACE_FALLOCATE''@|$(REPLACE_FALLOCATE)|g' \
< $(srcdir)/fcntl.in.h; \
} > $@-t
mv $@-t $@
--
1.5.3.6