bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2003-2018 Dovecot authors, see the included COPYING file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_cache_set_syscall_error(struct mail_cache *cache,
e8fd7988ec183fb6c104aed19a61f1a096c51d34Timo Sirainen mail_index_file_set_syscall_error(cache->index, cache->filepath,
6bc0f424bcdb9119d8159874cf98adfa53eefd9aTimo Sirainenstatic void mail_cache_unlink(struct mail_cache *cache)
fafa6393128960c70a9979af1c23cea41027fdd1Josef 'Jeff' Sipek if (!cache->index->readonly && !MAIL_INDEX_IS_IN_MEMORY(cache->index))
d35fee8d1e5e31614dba5e64d45ed23c7d6bfa53Timo Sirainenvoid mail_cache_reset(struct mail_cache *cache)
ad850190d946d34966a56838cfdb216e021b5b5fTimo Sirainen /* mark the cache as unusable */
d35fee8d1e5e31614dba5e64d45ed23c7d6bfa53Timo Sirainenvoid mail_cache_set_corrupted(struct mail_cache *cache, const char *fmt, ...)
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen "Corrupted index cache file %s: %s",
846624bdec0d5deec6cf22071158221391ec5f2dAki Tuomivoid mail_cache_set_seq_corrupted_reason(struct mail_cache_view *cache_view,
846624bdec0d5deec6cf22071158221391ec5f2dAki Tuomi "Corrupted record in index cache file %s: %s",
846624bdec0d5deec6cf22071158221391ec5f2dAki Tuomi /* drop cache pointer */
846624bdec0d5deec6cf22071158221391ec5f2dAki Tuomi mail_index_transaction_begin(view, MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
846624bdec0d5deec6cf22071158221391ec5f2dAki Tuomi mail_index_update_ext(t, seq, cache->ext_id, &empty, NULL);
8aacc9e7c84f8376822823ec98c2f551d4919b2eTimo Sirainenvoid mail_cache_file_close(struct mail_cache *cache)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (munmap(cache->mmap_base, cache->mmap_length) < 0)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_cache_set_syscall_error(cache, "munmap()");
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_cache_set_syscall_error(cache, "close()");
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainenstatic void mail_cache_init_file_cache(struct mail_cache *cache)
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainen file_cache_set_fd(cache->file_cache, cache->fd);
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainen (void)file_cache_set_size(cache->file_cache, st.st_size);
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen mail_cache_set_syscall_error(cache, "fstat()");
620b5ed41650da63b0ba15c489f9f312231d5d9bTimo Sirainenstatic int mail_cache_try_open(struct mail_cache *cache)
620b5ed41650da63b0ba15c489f9f312231d5d9bTimo Sirainen mail_cache_set_syscall_error(cache, "open()");
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainenstatic bool mail_cache_need_reopen(struct mail_cache *cache)
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen /* we're waiting for compression */
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen /* disabled */
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen /* see if the file has changed */
66ecc94150cbce23aad3240135e0782e0a74d479Timo Sirainen if ((cache->index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0) {
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen if (nfs_safe_stat(cache->filepath, &st) < 0) {
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen mail_cache_set_syscall_error(cache, "stat()");
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen /* file changed */
66ecc94150cbce23aad3240135e0782e0a74d479Timo Sirainen if ((cache->index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0) {
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen /* if the old file has been deleted, the new file may have
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen the same inode as the old one. we'll catch this here by
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen checking if fstat() fails with ESTALE */
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen mail_cache_set_syscall_error(cache, "fstat()");
620b5ed41650da63b0ba15c489f9f312231d5d9bTimo Sirainenstatic int mail_cache_reopen_now(struct mail_cache *cache)
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen ext = mail_index_view_get_ext(view, cache->ext_id);
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen if (ext == NULL || cache->hdr->file_seq != ext->reset_id) {
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen /* still different - maybe a race condition or maybe the
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen file_seq really is corrupted. either way, this shouldn't
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen happen often so we'll just mark cache to be compressed
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen later which fixes this. */
58be9d6bcc3800f5b3d76a064ee767fbe31a5a8aTimo Sirainen cache->need_compress_file_seq = cache->hdr->file_seq;
620b5ed41650da63b0ba15c489f9f312231d5d9bTimo Sirainenint mail_cache_reopen(struct mail_cache *cache)
620b5ed41650da63b0ba15c489f9f312231d5d9bTimo Sirainen /* reopening does no good */
25c22e54d1071d120641e9eecd0023e7373e65ffTimo Sirainenstatic void mail_cache_update_need_compress(struct mail_cache *cache)
67bbcd664bebce9a507a49c67273be4814d07c97Timo Sirainen const struct mail_index_cache_optimization_settings *set =
25c22e54d1071d120641e9eecd0023e7373e65ffTimo Sirainen const struct mail_cache_header *hdr = cache->hdr;
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen unsigned int records_count, cont_percentage, delete_percentage;
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen /* compress to get ourself into the new header version */
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen cache->need_compress_file_seq = hdr->file_seq;
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen msg_count = cache->index->map->rec_map->records_count;
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen else if (hdr->record_count == 0 || hdr->record_count > msg_count*2) {
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen /* probably not the real record_count, but hole offset that
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen Dovecot <=v2.1 versions used to use in this position.
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen we already checked that minor_version>0, but this could
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen happen if old Dovecot was used to access mailbox after
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen it had been updated. */
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen cont_percentage = hdr->continued_record_count * 100 / records_count;
67bbcd664bebce9a507a49c67273be4814d07c97Timo Sirainen if (cont_percentage >= set->compress_continued_percentage) {
25c22e54d1071d120641e9eecd0023e7373e65ffTimo Sirainen /* too many continued rows, compress */
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen delete_percentage = hdr->deleted_record_count * 100 /
67bbcd664bebce9a507a49c67273be4814d07c97Timo Sirainen if (delete_percentage >= set->compress_delete_percentage) {
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen /* too many deleted records, compress */
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen mail_cache_set_syscall_error(cache, "fstat()");
67bbcd664bebce9a507a49c67273be4814d07c97Timo Sirainen if ((uoff_t)st.st_size >= set->compress_min_size)
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen cache->need_compress_file_seq = hdr->file_seq;
8ac66221e8fdc2c5523cff1893e0d1c5de25fa49Timo Sirainenstatic bool mail_cache_verify_header(struct mail_cache *cache,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* check that the header is still ok */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (cache->mmap_length < sizeof(struct mail_cache_header)) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_cache_set_corrupted(cache, "File too small");
920b9f0fdfa5a5d7763e05736601a31bcb291a53Timo Sirainen if (hdr->major_version != MAIL_CACHE_MAJOR_VERSION) {
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen /* version changed - upgrade silently */
e192a3b1ca8ae857e7d87298ea507d32977ba570Timo Sirainen if (hdr->compat_sizeof_uoff_t != sizeof(uoff_t)) {
e192a3b1ca8ae857e7d87298ea507d32977ba570Timo Sirainen /* architecture change - handle silently(?) */
c4877db8b6559846f4b58be8e42422dc734c193fTimo Sirainen /* index id changed - handle silently */
8b9342aa96b2f297e23afb261f9f7dd859800952Timo Sirainen mail_cache_set_corrupted(cache, "file_seq is 0");
18d92dbbb752c79dc461514e52f7ef11847e636bTimo Sirainenmail_cache_map_finish(struct mail_cache *cache, uoff_t offset, size_t size,
f81801789c71f64a2fc3c44d09f9864bbc68cd45Timo Sirainen const struct mail_cache_header *hdr = hdr_data;
f81801789c71f64a2fc3c44d09f9864bbc68cd45Timo Sirainen /* verify the header validity only with offset=0. this way
f81801789c71f64a2fc3c44d09f9864bbc68cd45Timo Sirainen we won't waste time re-verifying it all the time */
18d92dbbb752c79dc461514e52f7ef11847e636bTimo Sirainenmail_cache_map_with_read(struct mail_cache *cache, size_t offset, size_t size,
18d92dbbb752c79dc461514e52f7ef11847e636bTimo Sirainen const void **data_r)
18d92dbbb752c79dc461514e52f7ef11847e636bTimo Sirainen cache->read_offset + cache->read_buf->used >= offset+size) {
18d92dbbb752c79dc461514e52f7ef11847e636bTimo Sirainen /* already mapped */
bb86f8f22f2561438ce710d2113f04a4d0082b50Timo Sirainen *data_r = CONST_PTR_OFFSET(cache->read_buf->data,
f81801789c71f64a2fc3c44d09f9864bbc68cd45Timo Sirainen return mail_cache_map_finish(cache, offset, size, hdr_data, TRUE);
ab1e5b156d1b5480d36ed6e8e06197339d803038Timo Sirainen if (offset == 0 && size < MAIL_CACHE_MIN_HEADER_READ_SIZE) {
ab1e5b156d1b5480d36ed6e8e06197339d803038Timo Sirainen /* we can usually read the fields header after the cache
ab1e5b156d1b5480d36ed6e8e06197339d803038Timo Sirainen header. we need them both, so try to read them all with one
ab1e5b156d1b5480d36ed6e8e06197339d803038Timo Sirainen pread() call. */
18d92dbbb752c79dc461514e52f7ef11847e636bTimo Sirainen data = buffer_append_space_unsafe(cache->read_buf, size);
18d92dbbb752c79dc461514e52f7ef11847e636bTimo Sirainen mail_cache_set_syscall_error(cache, "read()");
dad1d7b721e80a7e6c0282ace93aef86312fa579Timo Sirainen cache->mmap_length = offset + cache->read_buf->used;
82ed69779f49bd71ef1b570ce8aca67d357dbee8Timo Sirainenint mail_cache_map(struct mail_cache *cache, size_t offset, size_t size,
82ed69779f49bd71ef1b570ce8aca67d357dbee8Timo Sirainen const void **data_r)
9bd08aa09ea0cbd7b221aae9fc0534eb762d3de6Timo Sirainen /* verify offset + size before trying to allocate a huge amount of
9bd08aa09ea0cbd7b221aae9fc0534eb762d3de6Timo Sirainen memory due to them. note that we may be prefetching more than we
9bd08aa09ea0cbd7b221aae9fc0534eb762d3de6Timo Sirainen actually need, so don't fail too early. */
97144a346898fb62f9fae44fa5c076986553c66bTimo Sirainen if ((size > cache->mmap_length || offset + size > cache->mmap_length) &&
97144a346898fb62f9fae44fa5c076986553c66bTimo Sirainen (offset > 0 || size > sizeof(struct mail_cache_header))) {
9bd08aa09ea0cbd7b221aae9fc0534eb762d3de6Timo Sirainen i_error("fstat(%s) failed: %m", cache->filepath);
18d92dbbb752c79dc461514e52f7ef11847e636bTimo Sirainen return mail_cache_map_with_read(cache, offset, size, data_r);
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen ret = file_cache_read(cache->file_cache, offset, size);
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen /* In case of ESTALE we'll simply fail without error
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen messages. The caller will then just have to
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen fallback to generating the value itself.
211c638d81d382517d196ad47565e0d85012c927klemens We can't simply reopen the cache file, because
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen using it requires also having updated file
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen mail_cache_set_syscall_error(cache, "read()");
18d92dbbb752c79dc461514e52f7ef11847e636bTimo Sirainen *data_r = offset > cache->mmap_length ? NULL :
9af06b76539445d2d84d6e1bcb91685b6abeb4e0Timo Sirainen return mail_cache_map_finish(cache, offset, size,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* already mapped */
82ed69779f49bd71ef1b570ce8aca67d357dbee8Timo Sirainen *data_r = CONST_PTR_OFFSET(cache->mmap_base, offset);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (munmap(cache->mmap_base, cache->mmap_length) < 0)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_cache_set_syscall_error(cache, "munmap()");
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen /* unusable, waiting for compression or
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen index is in memory */
58be9d6bcc3800f5b3d76a064ee767fbe31a5a8aTimo Sirainen i_assert(cache->need_compress_file_seq != 0 ||
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* map the whole file */
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen cache->mmap_base = mmap_ro_file(cache->fd, &cache->mmap_length);
e9594e86dc601b72c1636f2b901dcfbf4ffaf47fAki Tuomi mail_cache_set_syscall_error(cache, t_strdup_printf(
18d92dbbb752c79dc461514e52f7ef11847e636bTimo Sirainen *data_r = offset > cache->mmap_length ? NULL :
f81801789c71f64a2fc3c44d09f9864bbc68cd45Timo Sirainen return mail_cache_map_finish(cache, offset, size,
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainenint mail_cache_open_and_verify(struct mail_cache *cache)
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainen /* failed for some reason - doesn't really matter,
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainen it's disabled for now. */
2608ab4495148a9362e75ec5c67dcbdec92dbae2Timo Sirainenmail_cache_open_or_create_path(struct mail_index *index, const char *path)
0b878c6a17c608fcd8b52a5762ed2c6a5cf4700aTimo Sirainen cache->field_pool = pool_alloconly_create("Cache fields", 2048);
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen hash_table_create(&cache->field_name_hash, cache->field_pool, 0,
66ecc94150cbce23aad3240135e0782e0a74d479Timo Sirainen (index->flags & MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL) != 0;
66ecc94150cbce23aad3240135e0782e0a74d479Timo Sirainen (index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
036626b19f14bef582f96e556913ae91b1d67881Timo Sirainen I_MIN(MAIL_CACHE_LOCK_TIMEOUT, index->max_lock_timeout_secs);
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen cache->dotlock_settings.stale_timeout = MAIL_CACHE_LOCK_CHANGE_TIMEOUT;
66ecc94150cbce23aad3240135e0782e0a74d479Timo Sirainen (index->flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) != 0)
17018da24e7dbb419c5047c316caadcb2fc5364aTimo Sirainen cache->file_cache = file_cache_new_path(-1, cache->filepath);
18d92dbbb752c79dc461514e52f7ef11847e636bTimo Sirainen (cache->index->flags & MAIL_INDEX_OPEN_FLAG_SAVEONLY) != 0;
59151b71059df1190acd75d8717ed04a7920c862Timo Sirainen mail_index_register_expunge_handler(index, cache->ext_id, FALSE,
f239eb76f77afcbc0bfc97c9b52b4407d1bc3fe6Timo Sirainenstruct mail_cache *mail_cache_open_or_create(struct mail_index *index)
2608ab4495148a9362e75ec5c67dcbdec92dbae2Timo Sirainen const char *path = t_strconcat(index->filepath,
2608ab4495148a9362e75ec5c67dcbdec92dbae2Timo Sirainen return mail_cache_open_or_create_path(index, path);
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenvoid mail_cache_free(struct mail_cache **_cache)
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen mail_index_unregister_expunge_handler(cache->index, cache->ext_id);
d0bbbc7057aa33b52ee378196dee7d773437468fTimo Sirainenstatic int mail_cache_lock_file(struct mail_cache *cache, bool nonblock)
763f83d3cc47bce05cbc396419c4db2b71dd8e68Timo Sirainen /* previous locking failed. don't waste time waiting on it
763f83d3cc47bce05cbc396419c4db2b71dd8e68Timo Sirainen again, just try once to see if it's available now. */
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen if (cache->index->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
51b979b6414b940f04677a7e2d064be119345954Timo Sirainen ret = mail_index_lock_fd(cache->index, cache->filepath,
51b979b6414b940f04677a7e2d064be119345954Timo Sirainen ret = file_dotlock_create(&cache->dotlock_settings,
bdcd91c28c0f5269d8971b9f5ec5d68f7155492aTimo Sirainen cache->file_lock = file_lock_from_dotlock(&dotlock);
bdcd91c28c0f5269d8971b9f5ec5d68f7155492aTimo Sirainen else if (ret < 0) {
5bdad39213d28ab35e615a7f4ea1712ab25b6a80Timo Sirainen "file_dotlock_create()");
4aae8acbcfa9cac96b4af39bfabcbe569e804827Timo Sirainen /* don't bother warning if locking failed due to a timeout. since cache
4aae8acbcfa9cac96b4af39bfabcbe569e804827Timo Sirainen updating isn't all that important we're using a very short timeout
4aae8acbcfa9cac96b4af39bfabcbe569e804827Timo Sirainen so it can be triggered sometimes on heavy load */
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen mail_index_flush_read_cache(cache->index, cache->filepath, cache->fd,
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainenstatic void mail_cache_unlock_file(struct mail_cache *cache)
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainenmail_cache_lock_full(struct mail_cache *cache, bool nonblock)
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainen if (mail_cache_lock_file(cache, nonblock) <= 0)
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainen /* locked the latest file */
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen /* okay, so it was just compressed. try again. */
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainen /* now verify that the index reset_id matches the cache's file_seq */
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainen for (i = 0; ; i++) {
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainen ext = mail_index_view_get_ext(iview, cache->ext_id);
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainen /* mismatch. try refreshing index once. if that doesn't help,
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainen we can't use the cache. */
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainen /* successfully locked - make sure our header is up to date */
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainen sizeof(struct mail_cache_header));
ab70f55bb8d824ca1ed7c74196f2f502edd29cc7Timo Sirainen if (mail_cache_map(cache, 0, 0, &data) <= 0) {
d0bbbc7057aa33b52ee378196dee7d773437468fTimo Sirainenint mail_cache_try_lock(struct mail_cache *cache)
a817fdcc43aedf423e2134091d5f83f91d64bcc9Timo Sirainenint mail_cache_unlock(struct mail_cache *cache)
62cfc346eb7b0a4fd9e1ab6edd63b98711161229Timo Sirainen /* we found it to be broken during the lock. just clean up. */
b780aa272b742a43579cdb523cc79cc8d4521306Timo Sirainen if (cache->index->fsync_mode == FSYNC_MODE_ALWAYS) {
51b979b6414b940f04677a7e2d064be119345954Timo Sirainen mail_cache_set_syscall_error(cache, "fdatasync()");
dbd9604da561399cc6255289d5b6f6f662ab2d00Timo Sirainenint mail_cache_write(struct mail_cache *cache, const void *data, size_t size,
dbd9604da561399cc6255289d5b6f6f662ab2d00Timo Sirainen if (pwrite_full(cache->fd, data, size, offset) < 0) {
dbd9604da561399cc6255289d5b6f6f662ab2d00Timo Sirainen mail_cache_set_syscall_error(cache, "pwrite_full()");
dbd9604da561399cc6255289d5b6f6f662ab2d00Timo Sirainen file_cache_write(cache->file_cache, data, size, offset);
289064eb21595d3e4460439eccdc48232d13f5e1Timo Sirainenint mail_cache_append(struct mail_cache *cache, const void *data, size_t size,
131b073bdc3650083b00616dc778dd3017c2bbb5Timo Sirainen mail_cache_set_syscall_error(cache, "fstat()");
044b0557e92ae0bb3b25af49d5468bad3d17db43Timo Sirainen mail_cache_set_corrupted(cache, "Cache file too large");
289064eb21595d3e4460439eccdc48232d13f5e1Timo Sirainen mail_cache_set_corrupted(cache, "Cache file too large");
131b073bdc3650083b00616dc778dd3017c2bbb5Timo Sirainen if (mail_cache_write(cache, data, size, *offset) < 0)
289064eb21595d3e4460439eccdc48232d13f5e1Timo Sirainen /* FIXME: this is updated only so that older Dovecot versions (<=v2.1)
289064eb21595d3e4460439eccdc48232d13f5e1Timo Sirainen can read this file. we can remove this later. */
131b073bdc3650083b00616dc778dd3017c2bbb5Timo Sirainen cache->hdr_copy.backwards_compat_used_file_size = *offset + size;
f3976df875193529127d584cb713983e8160bdcfTimo Sirainenbool mail_cache_exists(struct mail_cache *cache)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmail_cache_view_open(struct mail_cache *cache, struct mail_index_view *iview)
128ea07dab8d67124ea74bcc085a478784b6358aTimo Sirainenvoid mail_cache_view_close(struct mail_cache_view **_view)
5724e7103eed12fe36b55a7b5a8653284a2184b9Timo Sirainen if (view->cache->field_header_write_pending &&
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen (void)mail_cache_header_fields_update(view->cache);
8fa86f7ef06aa6cf0239c7ca2eb98889691d40d4Timo Sirainenvoid mail_cache_view_update_cache_decisions(struct mail_cache_view *view,
956f7778e413d3184d69e7b96e4a6b3cd5570bcdTimo Sirainenuint32_t mail_cache_get_first_new_seq(struct mail_index_view *view)
956f7778e413d3184d69e7b96e4a6b3cd5570bcdTimo Sirainen if (!mail_index_lookup_seq_range(view, idx_hdr->day_first_uid[7],
956f7778e413d3184d69e7b96e4a6b3cd5570bcdTimo Sirainen /* all messages are too old */