ibuffer-mmap.c revision b646fdb90f75ab80ea7feca42fa2e1f8e788b004
/*
ibuffer-mmap.c : Input buffer handling for mmap()ed files
Copyright (c) 2002 Timo Sirainen
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "lib.h"
#include "mmap-util.h"
#include "ibuffer-internal.h"
#include <unistd.h>
typedef struct {
int fd;
void *mmap_base;
unsigned int autoclose_fd:1;
} MmapIBuffer;
static size_t mmap_pagesize = 0;
static size_t mmap_pagemask = 0;
{
i_error("MmapIBuffer.close() failed: %m");
}
}
{
i_error("MmapIBuffer.munmap() failed: %m");
_buf->buffer_size = 0;
mbuf->mmap_offset = 0;
}
}
{
}
{
}
void *context __attr_unused__)
{
/* we never block */
}
{
}
{
/* end of file */
return -1;
}
/* more bytes available without needing to mmap() */
return io_buffer_set_mmaped_pos(buf);
}
/* didn't skip enough bytes */
return -2;
}
i_error("io_buffer_read_mmaped(): munmap() failed: %m");
}
buf->buffer_size = 0;
i_error("MmapIBuffer.mmap() failed: %m");
return -1;
}
/* madvise() only if non-limited mmap()ed buffer area larger than
page size */
if (limit_size > mmap_pagesize) {
}
return io_buffer_set_mmaped_pos(buf);
}
{
/* already mmaped */
} else {
/* force reading next time */
}
return 1;
}
{
}
int autoclose_fd)
{
if (mmap_pagesize == 0) {
mmap_pagesize = getpagesize();
}
if (v_size == 0) {
i_error("i_buffer_create_mmap(): fstat() failed: %m");
v_size = 0;
} else {
}
}
}