istream-mmap.c revision 411d6baa37f31d90730e90c4a28c43e1974bbe58
/* Copyright (c) 2002-2003 Timo Sirainen */
#include "lib.h"
#include "mmap-util.h"
#include "istream-internal.h"
#include <unistd.h>
struct mmap_istream {
int fd;
void *mmap_base;
unsigned int autoclose_fd:1;
};
static size_t mmap_pagemask = 0;
{
i_error("mmap_istream.close() failed: %m");
}
}
{
i_error("mmap_istream.munmap() failed: %m");
_stream->buffer_size = 0;
mstream->mmap_offset = 0;
}
}
{
}
{
/* allow only full page sizes */
if (max_size < mmap_get_page_size())
else {
if (max_size % mmap_get_page_size() != 0) {
max_size += mmap_get_page_size() -
(max_size % mmap_get_page_size());
}
}
}
{
/* more bytes available without needing to mmap() */
}
return -1;
}
/* didn't skip enough bytes */
return -2;
}
i_error("io_stream_read_mmaped(): munmap() failed: %m");
}
if (stream->buffer_size == 0) {
/* don't bother even trying mmap */
} else {
stream->buffer_size = 0;
i_error("mmap_istream.mmap() failed: %m");
return -1;
}
}
MADV_SEQUENTIAL) < 0)
i_error("mmap_istream.madvise(): %m");
}
}
{
if (stream->buffer_size != 0 &&
/* already mmaped */
} else {
/* force reading next time */
}
}
{
}
int 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;
}