mail-cache.c revision 66ecc94150cbce23aad3240135e0782e0a74d479
a4544a5a0e622ef69e38641f87ab1b5685e05911Phill Cunnington/* Copyright (c) 2003-2009 Dovecot authors, see the included COPYING file */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid mail_cache_set_syscall_error(struct mail_cache *cache,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster "%s failed with index cache file %s: %m",
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid mail_cache_set_corrupted(struct mail_cache *cache, const char *fmt, ...)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* mark the cache as unusable */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster "Corrupted index cache file %s: %s",
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid mail_cache_file_close(struct mail_cache *cache)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (munmap(cache->mmap_base, cache->mmap_length) < 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mail_cache_set_syscall_error(cache, "munmap()");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mail_cache_set_syscall_error(cache, "close()");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic void mail_cache_init_file_cache(struct mail_cache *cache)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster file_cache_set_fd(cache->file_cache, cache->fd);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster file_cache_set_size(cache->file_cache, st.st_size);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mail_cache_set_syscall_error(cache, "fstat()");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic bool mail_cache_need_reopen(struct mail_cache *cache)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* we're waiting for compression */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* disabled */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* see if the file has changed */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((cache->index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* file changed */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((cache->index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* if the old file has been deleted, the new file may have
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster the same inode as the old one. we'll catch this here by
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster checking if fstat() fails with ESTALE */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mail_cache_set_syscall_error(cache, "fstat()");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* reopening does no good */
unsigned int cont_percentage;
return FALSE;
return FALSE;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
if (size == 0)
if (ret < 0) {
if (offset == 0) {
if (offset == 0)
if (offset == 0)
int ret;
if (ret > 0)
if (ret < 0) {
return ret;
return cache;
return cache;
return cache;
int ret;
if (ret < 0) {
if (ret <= 0)
return ret;
TRUE);
bool nonblock)
int i, ret;
(require_same_reset_id || i == 0)) {
ret = 0;
ret = 0;
if (ret > 0) {
sizeof(struct mail_cache_header));
return ret;
int ret = 0;
return ret;
struct mail_cache_view *
return view;
&message_count)) {
return first_new_seq;