istream-mmap.c revision 0dffa25d211be541ee3c953b23566a1a990789df
/* Copyright (c) 2002-2016 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "mmap-util.h"
#include "istream-private.h"
#include <unistd.h>
struct mmap_istream {
struct istream_private istream;
struct timeval fstat_cache_stamp;
void *mmap_base;
bool autoclose_fd:1;
};
static size_t mmap_pagemask = 0;
bool close_parent ATTR_UNUSED)
{
i_error("mmap_istream.close(%s) failed: %m",
}
}
}
{
i_error("mmap_istream.munmap(%s) failed: %m",
}
_stream->buffer_size = 0;
mstream->mmap_offset = 0;
}
}
{
}
{
(mmap_get_page_size() - 1);
}
{
/* more bytes available without needing to mmap() */
}
return -1;
}
/* didn't skip enough bytes */
return -2;
}
i_error("mmap_istream.munmap(%s) failed: %m",
}
}
if (stream->buffer_size == 0) {
/* don't bother even trying mmap */
} else {
stream->buffer_size = 0;
"mmap() failed: %m");
i_error("mmap_istream.mmap(%s) failed: %m",
return -1;
}
}
MADV_SEQUENTIAL) < 0) {
i_error("mmap_istream.madvise(%s): %m",
}
}
}
bool mark ATTR_UNUSED)
{
if (stream->buffer_size != 0 &&
/* already mmaped */
} else {
/* force reading next time */
}
}
{
}
{
return 0;
i_error("mmap_istream.fstat(%s) failed: %m",
return -1;
}
return 0;
}
static int
{
return fstat_cached(mstream);
}
bool autoclose_fd)
{
struct mmap_istream *mstream;
if (mmap_pagemask == 0)
if (v_size == 0) {
i_error("i_stream_create_mmap(): fstat() failed: %m");
else {
if (start_offset > v_size)
v_size -= start_offset;
}
}
return istream;
}