CHECK_INCLUDE_FILES(glob.h HAVE_GLOB_H)
CHECK_INCLUDE_FILES(poll.h HAVE_POLL_H)
CHECK_INCLUDE_FILES(sys/sendfile.h HAVE_SYS_SENDFILE_H)
+CHECK_INCLUDE_FILES(linux/falloc.h HAVE_LINUX_FALLOC_H)
# Some dependencies
IF(HAVE_SYS_WAIT_H)
CHECK_SYMBOL_EXISTS(MAP_NOCORE sys/mman.h HAVE_MMAP_NOCORE)
CHECK_SYMBOL_EXISTS(O_DIRECT fcntl.h HAVE_O_DIRECT)
CHECK_SYMBOL_EXISTS(posix_fadvise fcntl.h HAVE_FADVISE)
+CHECK_SYMBOL_EXISTS(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE)
+CHECK_SYMBOL_EXISTS(fallocate fcntl.h HAVE_FALLOCATE)
CHECK_SYMBOL_EXISTS(fdatasync unistd.h HAVE_FDATASYNC)
CHECK_SYMBOL_EXISTS(_SC_NPROCESSORS_ONLN unistd.h HAVE_SC_NPROCESSORS_ONLN)
IF(HAVE_SIGINFO_H)
#endif /* HAVE_ENDIAN_H */
#if !defined(BYTE_ORDER) || (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN)
- error "Undefined or unknown BYTE_ORDER";
+ # error "Undefined or unknown BYTE_ORDER"
#endif
#cmakedefine HAVE_O_DIRECT 1
#cmakedefine HAVE_FADVISE 1
+
+#cmakedefine HAVE_FALLOCATE 1
+#cmakedefine HAVE_POSIX_FALLOCATE 1
+
#cmakedefine HAVE_FDATASYNC 1
#cmakedefine HAVE_COMPATIBLE_QUEUE_H 1
#include <fcntl.h>
#endif
+/* Linux specific falloc.h */
+#ifdef HAVE_LINUX_FALLOC_H
+#include <linux/falloc.h>
+#endif
+
/* poll */
#ifdef HAVE_POLL_H
#include <poll.h>
if ((flags & O_CREAT) != 0) {
/* Open file */
if ((fd = open (path, flags, S_IRUSR|S_IWUSR|S_IRGRP)) != -1) {
+ rspamd_fallocate (fd, 0, *len);
#ifdef HAVE_FADVISE
posix_fadvise (fd, 0, *len, POSIX_FADV_SEQUENTIAL);
#endif
return -1;
}
+ rspamd_fallocate (fd, 0, sizeof (header) + sizeof (section) + sizeof (block) * nblocks);
+
header.create_time = (guint64) time (NULL);
if (write (fd, &header, sizeof (header)) == -1) {
msg_info ("cannot write header to file %s, error %d, %s", filename, errno, strerror (errno));
return TRUE;
}
+gint
+rspamd_fallocate (gint fd, off_t offset, off_t len)
+{
+#if defined(HAVE_FALLOCATE) && defined(FALLOC_FL_KEEP_SIZE)
+ return fallocate (fd, FALLOC_FL_KEEP_SIZE, offset, len);
+#elif defined(HAVE_POSIX_FALLOCATE)
+ return posix_fallocate (fd, offset, len);
+#else
+ /* Return 0 as nothing can be done on this system */
+ return 0;
+#endif
+}
+
/*
* vi:ts=4
*/
*/
gboolean rspamd_strtoul (const gchar *s, gsize len, gulong *value);
+/**
+ * Try to allocate a file on filesystem (using fallocate or posix_fallocate)
+ * @param fd descriptor
+ * @param offset offset of file
+ * @param len length to allocate
+ * @return -1 in case of failure
+ */
+gint rspamd_fallocate (gint fd, off_t offset, off_t len);
+
#endif