Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-index/mail-index.c @ 3231:f778bd8b228f HEAD
Changed keywords_buf to array. Added mail_index_sync_get_keywords().
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 27 Mar 2005 15:22:21 +0300 |
parents | f6e0d1826645 |
children | 40b4ba3c55b8 |
rev | line source |
---|---|
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* Copyright (C) 2003-2004 Timo Sirainen */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "buffer.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "mmap-util.h" |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
6 #include "read-full.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "write-full.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "mail-index-private.h" |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
9 #include "mail-index-sync-private.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "mail-transaction-log.h" |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
11 #include "mail-cache.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include <stdio.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include <stddef.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 #include <time.h> |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
16 #include <sys/stat.h> |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
17 |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
18 static int mail_index_try_open_only(struct mail_index *index); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
19 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 struct mail_index *mail_index_alloc(const char *dir, const char *prefix) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 struct mail_index *index; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 index = i_new(struct mail_index, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 index->dir = i_strdup(dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 index->prefix = i_strdup(prefix); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 index->fd = -1; |
2116 | 28 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
29 index->extension_pool = pool_alloconly_create("extension", 256); |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
30 ARRAY_CREATE(&index->extensions, index->extension_pool, |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
31 struct mail_index_ext, 5); |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
32 |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
33 ARRAY_CREATE(&index->expunge_handlers, default_pool, |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
34 mail_index_expunge_handler_t *, 4); |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
35 ARRAY_CREATE(&index->sync_handlers, default_pool, |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
36 struct mail_index_sync_handler, 4); |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
37 ARRAY_CREATE(&index->sync_lost_handlers, default_pool, |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
38 mail_index_sync_lost_handler_t *, 4); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 index->mode = 0600; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 index->gid = (gid_t)-1; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
42 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
43 index->keywords_ext_id = |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
44 mail_index_ext_register(index, "keywords", 128, 2, 1); |
3086 | 45 index->keywords_pool = pool_alloconly_create("keywords", 512); |
3231
f778bd8b228f
Changed keywords_buf to array. Added mail_index_sync_get_keywords().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
46 ARRAY_CREATE(&index->keywords_arr, default_pool, |
f778bd8b228f
Changed keywords_buf to array. Added mail_index_sync_get_keywords().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
47 const char *, 16); |
f778bd8b228f
Changed keywords_buf to array. Added mail_index_sync_get_keywords().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
48 (void)array_modifyable_append(&index->keywords_arr); |
f778bd8b228f
Changed keywords_buf to array. Added mail_index_sync_get_keywords().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
49 index->keywords = array_idx(&index->keywords_arr, 0); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 return index; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 void mail_index_free(struct mail_index *index) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 { |
1967 | 55 mail_index_close(index); |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
56 pool_unref(index->extension_pool); |
3086 | 57 pool_unref(index->keywords_pool); |
1967 | 58 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
59 array_free(&index->sync_handlers); |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
60 array_free(&index->sync_lost_handlers); |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
61 array_free(&index->expunge_handlers); |
3231
f778bd8b228f
Changed keywords_buf to array. Added mail_index_sync_get_keywords().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
62 array_free(&index->keywords_arr); |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
63 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 i_free(index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 i_free(index->dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 i_free(index->prefix); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 i_free(index); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 |
2650
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
70 void mail_index_set_permissions(struct mail_index *index, |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
71 mode_t mode, gid_t gid) |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
72 { |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
73 index->mode = mode & 0666; |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
74 index->gid = gid; |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
75 } |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
76 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
77 uint32_t mail_index_ext_register(struct mail_index *index, const char *name, |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
78 uint32_t default_hdr_size, |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
79 uint16_t default_record_size, |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
80 uint16_t default_record_align) |
2114
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
81 { |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
82 const struct mail_index_ext *extensions; |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
83 struct mail_index_ext ext; |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
84 unsigned int i, ext_count; |
2115
f720b3f15333
Modifying extra_records should work now.
Timo Sirainen <tss@iki.fi>
parents:
2114
diff
changeset
|
85 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
86 extensions = array_get(&index->extensions, &ext_count); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
87 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
88 i_assert(array_count(&index->sync_handlers) == ext_count); |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
89 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
90 /* see if it's already there */ |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
91 for (i = 0; i < ext_count; i++) { |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
92 if (strcmp(extensions[i].name, name) == 0) |
2116 | 93 return i; |
94 } | |
95 | |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
96 memset(&ext, 0, sizeof(ext)); |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
97 ext.name = p_strdup(index->extension_pool, name); |
2921
a5eda271256f
Wrong extension sync_handler might have been called if index extensions
Timo Sirainen <tss@iki.fi>
parents:
2913
diff
changeset
|
98 ext.index_idx = ext_count; |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
99 ext.hdr_size = default_hdr_size; |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
100 ext.record_size = default_record_size; |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
101 ext.record_align = default_record_align; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
102 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
103 array_append(&index->extensions, &ext, 1); |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
104 (void)array_modifyable_append(&index->sync_handlers); |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
105 return ext_count; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
106 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
107 |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
108 void mail_index_register_expunge_handler(struct mail_index *index, |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
109 uint32_t ext_id, |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
110 mail_index_expunge_handler_t *cb) |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
111 { |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
112 mail_index_expunge_handler_t **p; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
113 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
114 p = array_modifyable_idx(&index->expunge_handlers, ext_id); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
115 i_assert(*p == NULL); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
116 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
117 *p = cb; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
118 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
119 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
120 void mail_index_unregister_expunge_handler(struct mail_index *index, |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
121 uint32_t ext_id) |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
122 { |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
123 mail_index_expunge_handler_t **p; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
124 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
125 p = array_modifyable_idx(&index->expunge_handlers, ext_id); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
126 i_assert(*p != NULL); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
127 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
128 *p = NULL; |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
129 } |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
130 |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
131 void mail_index_register_sync_handler(struct mail_index *index, uint32_t ext_id, |
2869
d2daf90c79f1
Cache invalidating needed to hook into view syncing as well.
Timo Sirainen <tss@iki.fi>
parents:
2857
diff
changeset
|
132 mail_index_sync_handler_t *cb, |
d2daf90c79f1
Cache invalidating needed to hook into view syncing as well.
Timo Sirainen <tss@iki.fi>
parents:
2857
diff
changeset
|
133 enum mail_index_sync_handler_type type) |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
134 { |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
135 struct mail_index_sync_handler *h; |
2869
d2daf90c79f1
Cache invalidating needed to hook into view syncing as well.
Timo Sirainen <tss@iki.fi>
parents:
2857
diff
changeset
|
136 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
137 h = array_modifyable_idx(&index->sync_handlers, ext_id); |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
138 i_assert(h->callback == NULL); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
139 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
140 h->callback = cb; |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
141 h->type = type; |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
142 } |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
143 |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
144 void mail_index_unregister_sync_handler(struct mail_index *index, |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
145 uint32_t ext_id) |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
146 { |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
147 struct mail_index_sync_handler *h; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
148 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
149 h = array_modifyable_idx(&index->sync_handlers, ext_id); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
150 i_assert(h->callback != NULL); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
151 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
152 h->callback = NULL; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
153 h->type = 0; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
154 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
155 |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
156 void mail_index_register_sync_lost_handler(struct mail_index *index, |
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
157 mail_index_sync_lost_handler_t *cb) |
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
158 { |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
159 array_append(&index->sync_lost_handlers, &cb, 1); |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
160 } |
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
161 |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
162 void mail_index_unregister_sync_lost_handler(struct mail_index *index, |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
163 mail_index_sync_lost_handler_t *cb) |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
164 { |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
165 mail_index_sync_lost_handler_t *const *handlers; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
166 unsigned int i, count; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
167 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
168 handlers = array_get(&index->sync_lost_handlers, &count); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
169 for (i = 0; i < count; i++) { |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
170 if (handlers[i] == cb) { |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
171 array_delete(&index->sync_lost_handlers, i, 1); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
172 break; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
173 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
174 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
175 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
176 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
177 static void mail_index_map_init_extbufs(struct mail_index_map *map, |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
178 unsigned int initial_count) |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
179 { |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
180 size_t size; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
181 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
182 if (map->extension_pool == NULL) { |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
183 size = initial_count * sizeof(struct mail_index_ext) + |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
184 initial_count * sizeof(uint32_t) + |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
185 (initial_count * 20); /* for names */ |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
186 map->extension_pool = |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
187 pool_alloconly_create("extensions", |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
188 nearest_power(size)); |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
189 } else { |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
190 p_clear(map->extension_pool); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
191 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
192 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
193 ARRAY_CREATE(&map->extensions, map->extension_pool, |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
194 struct mail_index_ext, initial_count); |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
195 ARRAY_CREATE(&map->ext_id_map, map->extension_pool, |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
196 uint32_t, initial_count); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
197 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
198 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
199 uint32_t mail_index_map_lookup_ext(struct mail_index_map *map, const char *name) |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
200 { |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
201 const struct mail_index_ext *extensions; |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
202 unsigned int i, size; |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
203 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
204 if (!array_is_created(&map->extensions)) |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
205 return (uint32_t)-1; |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
206 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
207 extensions = array_get(&map->extensions, &size); |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
208 for (i = 0; i < size; i++) { |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
209 if (strcmp(extensions[i].name, name) == 0) |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
210 return i; |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
211 } |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
212 return (uint32_t)-1; |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
213 } |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
214 |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
215 uint32_t |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
216 mail_index_map_register_ext(struct mail_index *index, |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
217 struct mail_index_map *map, const char *name, |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
218 uint32_t hdr_offset, uint32_t hdr_size, |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
219 uint32_t record_offset, uint32_t record_size, |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
220 uint32_t record_align, uint32_t reset_id) |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
221 { |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
222 struct mail_index_ext *ext; |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
223 uint32_t idx, empty_idx = (uint32_t)-1; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
224 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
225 if (!array_is_created(&map->extensions)) { |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
226 mail_index_map_init_extbufs(map, 5); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
227 idx = 0; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
228 } else { |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
229 idx = array_count(&map->extensions); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
230 } |
3147
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
231 i_assert(mail_index_map_lookup_ext(map, name) == (uint32_t)-1); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
232 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
233 ext = array_modifyable_append(&map->extensions); |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
234 memset(ext, 0, sizeof(*ext)); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
235 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
236 ext->name = p_strdup(map->extension_pool, name); |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
237 ext->hdr_offset = hdr_offset; |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
238 ext->hdr_size = hdr_size; |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
239 ext->record_offset = record_offset; |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
240 ext->record_size = record_size; |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
241 ext->record_align = record_align; |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
242 ext->reset_id = reset_id; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
243 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
244 ext->index_idx = mail_index_ext_register(index, name, hdr_size, |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
245 record_size, record_align); |
2921
a5eda271256f
Wrong extension sync_handler might have been called if index extensions
Timo Sirainen <tss@iki.fi>
parents:
2913
diff
changeset
|
246 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
247 while (array_count(&map->ext_id_map) < ext->index_idx) |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
248 array_append(&map->ext_id_map, &empty_idx, 1); |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
249 array_idx_set(&map->ext_id_map, ext->index_idx, &idx); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
250 return idx; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
251 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
252 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
253 static int size_check(size_t *size_left, size_t size) |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
254 { |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
255 if (size > *size_left) |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
256 return FALSE; |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
257 *size_left -= size; |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
258 return TRUE; |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
259 } |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
260 |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
261 static size_t get_align(size_t name_len) |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
262 { |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
263 size_t size = sizeof(struct mail_index_ext_header) + name_len; |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
264 return MAIL_INDEX_HEADER_SIZE_ALIGN(size) - size; |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
265 } |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
266 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
267 static int mail_index_read_extensions(struct mail_index *index, |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
268 struct mail_index_map *map) |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
269 { |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
270 const struct mail_index_ext_header *ext_hdr; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
271 unsigned int i, old_count; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
272 const char *name; |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
273 uint32_t ext_id, offset, name_offset; |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
274 size_t size_left; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
275 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
276 /* extension headers always start from 64bit offsets, so if base header |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
277 doesn't happen to be 64bit aligned we'll skip some bytes */ |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
278 offset = MAIL_INDEX_HEADER_SIZE_ALIGN(map->hdr.base_header_size); |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
279 if (offset >= map->hdr.header_size && map->extension_pool == NULL) { |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
280 /* nothing to do, skip allocatations and all */ |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
281 return 1; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
282 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
283 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
284 old_count = array_count(&index->extensions); |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
285 mail_index_map_init_extbufs(map, old_count + 5); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
286 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
287 ext_id = (uint32_t)-1; |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
288 for (i = 0; i < old_count; i++) |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
289 array_append(&map->ext_id_map, &ext_id, 1); |
2116 | 290 |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
291 while (offset < map->hdr.header_size) { |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
292 ext_hdr = CONST_PTR_OFFSET(map->hdr_base, offset); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
293 |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
294 size_left = map->hdr.header_size - offset; |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
295 if (!size_check(&size_left, sizeof(*ext_hdr)) || |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
296 !size_check(&size_left, ext_hdr->name_size) || |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
297 !size_check(&size_left, get_align(ext_hdr->name_size)) || |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
298 !size_check(&size_left, ext_hdr->hdr_size)) { |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
299 mail_index_set_error(index, "Corrupted index file %s: " |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
300 "Header extension goes outside header", |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
301 index->filepath); |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
302 return -1; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
303 } |
3147
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
304 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
305 offset += sizeof(*ext_hdr); |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
306 name_offset = offset; |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
307 offset += ext_hdr->name_size + get_align(ext_hdr->name_size); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
308 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
309 t_push(); |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
310 name = t_strndup(CONST_PTR_OFFSET(map->hdr_base, name_offset), |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
311 ext_hdr->name_size); |
3147
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
312 |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
313 if (mail_index_map_lookup_ext(map, name) != (uint32_t)-1) { |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
314 mail_index_set_error(index, "Corrupted index file %s: " |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
315 "Duplicate header extension %s", |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
316 index->filepath, name); |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
317 t_pop(); |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
318 return -1; |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
319 } |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
320 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
321 mail_index_map_register_ext(index, map, name, |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
322 offset, ext_hdr->hdr_size, |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
323 ext_hdr->record_offset, |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
324 ext_hdr->record_size, |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
325 ext_hdr->record_align, |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
326 ext_hdr->reset_id); |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
327 t_pop(); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
328 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
329 offset += MAIL_INDEX_HEADER_SIZE_ALIGN(ext_hdr->hdr_size); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
330 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
331 return 1; |
2114
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
332 } |
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
333 |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
334 int mail_index_map_read_keywords(struct mail_index *index, |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
335 struct mail_index_map *map) |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
336 { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
337 const struct mail_index_ext *ext; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
338 const struct mail_index_keyword_header *kw_hdr; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
339 const struct mail_index_keyword_header_rec *kw_rec; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
340 const char *name, **keywords_list; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
341 unsigned int i, name_len; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
342 uint32_t ext_id; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
343 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
344 ext_id = mail_index_map_lookup_ext(map, "keywords"); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
345 if (ext_id == (uint32_t)-1) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
346 map->keywords = NULL; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
347 map->keywords_count = 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
348 return 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
349 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
350 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
351 ext = array_idx(&map->extensions, ext_id); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
352 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
353 kw_hdr = CONST_PTR_OFFSET(map->hdr_base, ext->hdr_offset); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
354 kw_rec = (const void *)(kw_hdr + 1); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
355 name = (const char *)(kw_rec + kw_hdr->keywords_count); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
356 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
357 if ((size_t)(name - (const char *)kw_hdr) > ext->hdr_size) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
358 mail_index_set_error(index, "Corrupted index file %s: " |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
359 "keywords_count larger than header size", |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
360 index->filepath); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
361 return -1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
362 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
363 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
364 /* make sure the header is valid */ |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
365 name_len = (const char *)kw_hdr + ext->hdr_size - name; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
366 for (i = 0; i < kw_hdr->keywords_count; i++) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
367 if (kw_rec[i].name_offset > name_len) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
368 mail_index_set_error(index, "Corrupted index file %s: " |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
369 "name_offset points outside allocated header", |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
370 index->filepath); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
371 return -1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
372 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
373 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
374 if (name[name_len-1] != '\0') { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
375 mail_index_set_error(index, "Corrupted index file %s: " |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
376 "header doesn't end with NUL", |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
377 index->filepath); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
378 return -1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
379 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
380 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
381 if (map->keywords_pool == NULL) |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
382 map->keywords_pool = pool_alloconly_create("keywords", 1024); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
383 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
384 /* Save keywords in memory. Only new keywords should come into the |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
385 mapping, so keep the existing keyword strings in memory to allow |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
386 mail_index_lookup_keywords() to safely return direct pointers |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
387 into them. */ |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
388 if (kw_hdr->keywords_count < map->keywords_count) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
389 mail_index_set_error(index, "Corrupted index file %s: " |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
390 "Keywords removed unexpectedly", |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
391 index->filepath); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
392 return -1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
393 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
394 if (kw_hdr->keywords_count == map->keywords_count) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
395 /* nothing changed */ |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
396 return 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
397 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
398 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
399 /* @UNSAFE */ |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
400 keywords_list = p_new(map->keywords_pool, |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
401 const char *, kw_hdr->keywords_count + 1); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
402 for (i = 0; i < map->keywords_count; i++) |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
403 keywords_list[i] = map->keywords[i]; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
404 for (; i < kw_hdr->keywords_count; i++) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
405 keywords_list[i] = p_strdup(map->keywords_pool, |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
406 name + kw_rec[i].name_offset); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
407 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
408 map->keywords = keywords_list; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
409 map->keywords_count = kw_hdr->keywords_count; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
410 return 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
411 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
412 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
413 const char *const *mail_index_get_keywords(struct mail_index *index) |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
414 { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
415 (void)mail_index_map_read_keywords(index, index->map); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
416 return index->map->keywords; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
417 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
418 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
419 static int mail_index_check_header(struct mail_index *index, |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
420 struct mail_index_map *map) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
421 { |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
422 const struct mail_index_header *hdr = &map->hdr; |
2114
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
423 unsigned char compat_data[sizeof(hdr->compat_data)]; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
424 |
2114
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
425 memset(compat_data, 0, sizeof(compat_data)); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
426 #ifndef WORDS_BIGENDIAN |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
427 compat_data[0] = MAIL_INDEX_COMPAT_LITTLE_ENDIAN; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
428 #endif |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
429 compat_data[1] = sizeof(uoff_t); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
430 compat_data[2] = sizeof(time_t); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
431 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
432 if (hdr->major_version != MAIL_INDEX_MAJOR_VERSION) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
433 /* major version change - handle silently(?) */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
434 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
435 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
436 if (memcmp(hdr->compat_data, compat_data, sizeof(compat_data)) != 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
437 /* architecture change - handle silently(?) */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
440 |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
441 if ((map->hdr.flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) { |
2095 | 442 /* we've already complained about it */ |
1930 | 443 return -1; |
444 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
445 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
446 /* following some extra checks that only take a bit of CPU */ |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
447 if (hdr->uid_validity == 0 && hdr->next_uid != 1) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 mail_index_set_error(index, "Corrupted index file %s: " |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
449 "uid_validity = 0, next_uid = %u", |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
450 index->filepath, hdr->next_uid); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
451 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
452 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
453 |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
454 if (hdr->record_size < sizeof(struct mail_index_record)) { |
2114
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
455 mail_index_set_error(index, "Corrupted index file %s: " |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
456 "record_size too small: %u < %"PRIuSIZE_T, |
2114
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
457 index->filepath, hdr->record_size, |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
458 sizeof(struct mail_index_record)); |
2114
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
459 return -1; |
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
460 } |
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
461 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 if (hdr->next_uid == 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
464 |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2021
diff
changeset
|
465 if (hdr->recent_messages_count > hdr->messages_count || |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2021
diff
changeset
|
466 hdr->seen_messages_count > hdr->messages_count || |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 hdr->deleted_messages_count > hdr->messages_count) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 if (hdr->first_recent_uid_lowwater > hdr->next_uid || |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
470 hdr->first_unseen_uid_lowwater > hdr->next_uid || |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
471 hdr->first_deleted_uid_lowwater > hdr->next_uid) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
473 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
474 return mail_index_read_extensions(index, map); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
475 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
476 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
477 static void mail_index_map_clear(struct mail_index *index, |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
478 struct mail_index_map *map) |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
479 { |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
480 if (map->buffer != NULL) { |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
481 i_assert(map->mmap_base == NULL); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
482 buffer_free(map->buffer); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
483 map->buffer = NULL; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
484 } else if (map->mmap_base != NULL) { |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
485 i_assert(map->buffer == NULL); |
1930 | 486 if (munmap(map->mmap_base, map->mmap_size) < 0) |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
487 mail_index_set_syscall_error(index, "munmap()"); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
488 map->mmap_base = NULL; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
489 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
490 |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
491 if (map->refcount > 0) { |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
492 memset(&map->hdr, 0, sizeof(map->hdr)); |
1930 | 493 map->mmap_size = 0; |
494 map->mmap_used_size = 0; | |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
495 map->records = NULL; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
496 map->records_count = 0; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
497 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
498 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
499 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
500 void mail_index_unmap(struct mail_index *index, struct mail_index_map *map) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
502 if (--map->refcount > 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
503 return; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
504 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
505 i_assert(map->refcount == 0); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
506 mail_index_map_clear(index, map); |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
507 if (map->extension_pool != NULL) |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
508 pool_unref(map->extension_pool); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
509 if (map->keywords_pool != NULL) |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
510 pool_unref(map->keywords_pool); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
511 buffer_free(map->hdr_copy_buf); |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
512 i_free(map); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
513 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
514 |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
515 static void mail_index_unmap_forced(struct mail_index *index, |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
516 struct mail_index_map *map) |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
517 { |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
518 mail_index_map_clear(index, map); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
519 mail_index_unmap(index, map); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
520 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
521 |
2922
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
522 static void mail_index_map_copy_hdr(struct mail_index_map *map, |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
523 const struct mail_index_header *hdr) |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
524 { |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
525 if (hdr->base_header_size < sizeof(map->hdr)) { |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
526 /* header smaller than ours, make a copy so our newer headers |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
527 won't have garbage in them */ |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
528 memset(&map->hdr, 0, sizeof(map->hdr)); |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
529 memcpy(&map->hdr, hdr, hdr->base_header_size); |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
530 } else { |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
531 map->hdr = *hdr; |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
532 } |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
533 } |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
534 |
1930 | 535 static int mail_index_mmap(struct mail_index *index, struct mail_index_map *map) |
536 { | |
537 const struct mail_index_header *hdr; | |
538 unsigned int records_count; | |
539 | |
2193 | 540 i_assert(!map->write_to_disk); |
541 | |
542 if (map->buffer != NULL) { | |
543 /* we had temporarily used a buffer, eg. for updating index */ | |
544 buffer_free(map->buffer); | |
545 map->buffer = NULL; | |
546 } | |
2043
4548def7ac02
Don't try to re-map dirty memory mapping.
Timo Sirainen <tss@iki.fi>
parents:
2038
diff
changeset
|
547 |
2761
f96a7b2d1c52
Removed mmap() memory area protections. They weren't always set correctly.
Timo Sirainen <tss@iki.fi>
parents:
2723
diff
changeset
|
548 map->mmap_base = index->readonly ? |
1930 | 549 mmap_ro_file(index->fd, &map->mmap_size) : |
550 mmap_rw_file(index->fd, &map->mmap_size); | |
551 if (map->mmap_base == MAP_FAILED) { | |
552 map->mmap_base = NULL; | |
553 mail_index_set_syscall_error(index, "mmap()"); | |
554 return -1; | |
555 } | |
556 | |
2822
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
557 hdr = map->mmap_base; |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
558 if (map->mmap_size > |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
559 offsetof(struct mail_index_header, major_version) && |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
560 hdr->major_version != MAIL_INDEX_MAJOR_VERSION) { |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
561 /* major version change - handle silently */ |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
562 return 0; |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
563 } |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
564 |
1930 | 565 if (map->mmap_size < MAIL_INDEX_HEADER_MIN_SIZE) { |
566 mail_index_set_error(index, "Corrupted index file %s: " | |
567 "File too small (%"PRIuSIZE_T")", | |
568 index->filepath, map->mmap_size); | |
569 return 0; | |
570 } | |
571 | |
572 map->mmap_used_size = hdr->header_size + | |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
573 hdr->messages_count * hdr->record_size; |
1930 | 574 |
575 if (map->mmap_used_size > map->mmap_size) { | |
576 records_count = (map->mmap_size - hdr->header_size) / | |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
577 hdr->record_size; |
1930 | 578 mail_index_set_error(index, "Corrupted index file %s: " |
579 "messages_count too large (%u > %u)", | |
2122 | 580 index->filepath, hdr->messages_count, |
1930 | 581 records_count); |
582 return 0; | |
583 } | |
584 | |
2922
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
585 mail_index_map_copy_hdr(map, hdr); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
586 |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
587 map->hdr_base = map->mmap_base; |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
588 map->records = PTR_OFFSET(map->mmap_base, map->hdr.header_size); |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
589 map->records_count = map->hdr.messages_count; |
1930 | 590 return 1; |
591 } | |
592 | |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
593 static int mail_index_read_header(struct mail_index *index, |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
594 struct mail_index_header *hdr, size_t *pos_r) |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
595 { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
596 size_t pos; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
597 int ret; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
598 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
599 memset(hdr, 0, sizeof(*hdr)); |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
600 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
601 ret = 1; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
602 for (pos = 0; ret > 0 && pos < sizeof(*hdr); ) { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
603 ret = pread(index->fd, PTR_OFFSET(hdr, pos), |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
604 sizeof(*hdr) - pos, pos); |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
605 if (ret > 0) |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
606 pos += ret; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
607 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
608 *pos_r = pos; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
609 return ret; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
610 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
611 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
612 static int mail_index_read_map(struct mail_index *index, |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
613 struct mail_index_map *map, int *retry_r) |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
614 { |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
615 struct mail_index_header hdr; |
1939 | 616 void *data = NULL; |
1930 | 617 ssize_t ret; |
618 size_t pos, records_size; | |
619 | |
2043
4548def7ac02
Don't try to re-map dirty memory mapping.
Timo Sirainen <tss@iki.fi>
parents:
2038
diff
changeset
|
620 i_assert(map->mmap_base == NULL); |
4548def7ac02
Don't try to re-map dirty memory mapping.
Timo Sirainen <tss@iki.fi>
parents:
2038
diff
changeset
|
621 |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
622 *retry_r = FALSE; |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
623 ret = mail_index_read_header(index, &hdr, &pos); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
624 |
2825
645b8442b519
one more major version change fix
Timo Sirainen <tss@iki.fi>
parents:
2824
diff
changeset
|
625 if (pos > (ssize_t)offsetof(struct mail_index_header, major_version) && |
2822
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
626 hdr.major_version != MAIL_INDEX_MAJOR_VERSION) { |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
627 /* major version change - handle silently */ |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
628 return 0; |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
629 } |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
630 |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
631 if (ret >= 0 && pos >= MAIL_INDEX_HEADER_MIN_SIZE && |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
632 (ret > 0 || pos >= hdr.base_header_size)) { |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
633 if (hdr.base_header_size < MAIL_INDEX_HEADER_MIN_SIZE || |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
634 hdr.header_size < hdr.base_header_size) { |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
635 mail_index_set_error(index, "Corrupted index file %s: " |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
636 "Corrupted header sizes (base %u, full %u)", |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
637 index->filepath, hdr.base_header_size, |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
638 hdr.header_size); |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
639 return 0; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
640 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
641 |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
642 buffer_reset(map->hdr_copy_buf); |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
643 buffer_append(map->hdr_copy_buf, &hdr, hdr.base_header_size); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
644 |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
645 /* @UNSAFE */ |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
646 data = buffer_append_space_unsafe(map->hdr_copy_buf, |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
647 hdr.header_size - |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
648 hdr.base_header_size); |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
649 ret = pread_full(index->fd, data, |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
650 hdr.header_size - hdr.base_header_size, |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
651 hdr.base_header_size); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
652 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
653 |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
654 if (ret > 0) { |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
655 records_size = hdr.messages_count * hdr.record_size; |
1930 | 656 |
657 if (map->buffer == NULL) { | |
658 map->buffer = buffer_create_dynamic(default_pool, | |
2708
f1e9f3ec8135
Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents:
2683
diff
changeset
|
659 records_size); |
1930 | 660 } |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
661 |
1930 | 662 /* @UNSAFE */ |
663 buffer_set_used_size(map->buffer, 0); | |
664 data = buffer_append_space_unsafe(map->buffer, records_size); | |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
665 |
1930 | 666 ret = pread_full(index->fd, data, records_size, |
667 hdr.header_size); | |
1939 | 668 } |
1930 | 669 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
670 if (ret < 0) { |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
671 if (errno == ESTALE) { |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
672 *retry_r = TRUE; |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
673 return 0; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
674 } |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
675 mail_index_set_syscall_error(index, "pread_full()"); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
676 return -1; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
677 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
678 if (ret == 0) { |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
679 mail_index_set_error(index, |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
680 "Corrupted index file %s: File too small", |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
681 index->filepath); |
2824
431f677bc0b9
More rebuilding fixes with mmap_disable=yes
Timo Sirainen <tss@iki.fi>
parents:
2823
diff
changeset
|
682 return 0; |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
683 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
684 |
1930 | 685 map->records = data; |
686 map->records_count = hdr.messages_count; | |
687 | |
2922
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
688 mail_index_map_copy_hdr(map, &hdr); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
689 map->hdr_base = map->hdr_copy_buf->data; |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
690 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
691 index->sync_log_file_seq = hdr.log_file_seq; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
692 index->sync_log_file_offset = hdr.log_file_int_offset; |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
693 return 1; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
694 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
695 |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
696 static int mail_index_sync_from_transactions(struct mail_index *index, |
2913 | 697 struct mail_index_map **map, |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
698 int sync_to_index) |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
699 { |
2913 | 700 const struct mail_index_header *map_hdr = &(*map)->hdr; |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
701 struct mail_index_view *view; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
702 struct mail_transaction_log_view *log_view; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
703 struct mail_index_sync_map_ctx sync_map_ctx; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
704 struct mail_index_header hdr; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
705 const struct mail_transaction_header *thdr; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
706 const void *tdata; |
2939
00b78082cd50
mmap_disable=yes: when we're syncing index by reading transaction log,
Timo Sirainen <tss@iki.fi>
parents:
2938
diff
changeset
|
707 uint32_t prev_seq, max_seq; |
00b78082cd50
mmap_disable=yes: when we're syncing index by reading transaction log,
Timo Sirainen <tss@iki.fi>
parents:
2938
diff
changeset
|
708 uoff_t prev_offset, max_offset; |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
709 size_t pos; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
710 int ret, skipped; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
711 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
712 if (sync_to_index) { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
713 /* read the real log position where we are supposed to be |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
714 synced */ |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
715 ret = mail_index_read_header(index, &hdr, &pos); |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
716 if (ret < 0 && errno != ESTALE) { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
717 mail_index_set_syscall_error(index, "pread()"); |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
718 return -1; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
719 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
720 if (pos < MAIL_INDEX_HEADER_MIN_SIZE) |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
721 return 0; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
722 |
2913 | 723 if (map_hdr->log_file_seq == hdr.log_file_seq && |
724 map_hdr->log_file_int_offset == hdr.log_file_int_offset) { | |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
725 /* nothing to do */ |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
726 return 1; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
727 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
728 |
2913 | 729 if (map_hdr->log_file_seq > hdr.log_file_seq || |
730 (map_hdr->log_file_seq == hdr.log_file_seq && | |
731 map_hdr->log_file_int_offset > hdr.log_file_int_offset)) { | |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
732 /* we went too far, have to re-read the file */ |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
733 return 0; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
734 } |
2913 | 735 if (map_hdr->log_file_ext_offset != |
736 map_hdr->log_file_int_offset || | |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
737 hdr.log_file_ext_offset != hdr.log_file_int_offset) { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
738 /* too much trouble to get this right. */ |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
739 return 0; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
740 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
741 max_seq = hdr.log_file_seq; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
742 max_offset = hdr.log_file_int_offset; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
743 } else { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
744 /* sync everything there is */ |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
745 max_seq = (uint32_t)-1; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
746 max_offset = (uoff_t)-1; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
747 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
748 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
749 log_view = mail_transaction_log_view_open(index->log); |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
750 if (mail_transaction_log_view_set(log_view, |
2913 | 751 map_hdr->log_file_seq, |
752 map_hdr->log_file_int_offset, | |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
753 max_seq, max_offset, |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
754 MAIL_TRANSACTION_TYPE_MASK) < 0) { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
755 mail_transaction_log_view_close(log_view); |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
756 return 0; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
757 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
758 |
2913 | 759 index->map = *map; |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
760 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
761 view = mail_index_view_open(index); |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
762 mail_index_sync_map_init(&sync_map_ctx, view, |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
763 MAIL_INDEX_SYNC_HANDLER_VIEW); |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
764 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
765 while ((ret = mail_transaction_log_view_next(log_view, &thdr, &tdata, |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
766 &skipped)) > 0) { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
767 if (mail_index_sync_record(&sync_map_ctx, thdr, tdata) < 0) { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
768 ret = -1; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
769 break; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
770 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
771 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
772 |
2939
00b78082cd50
mmap_disable=yes: when we're syncing index by reading transaction log,
Timo Sirainen <tss@iki.fi>
parents:
2938
diff
changeset
|
773 mail_transaction_log_view_get_prev_pos(log_view, &prev_seq, |
00b78082cd50
mmap_disable=yes: when we're syncing index by reading transaction log,
Timo Sirainen <tss@iki.fi>
parents:
2938
diff
changeset
|
774 &prev_offset); |
3173
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
3147
diff
changeset
|
775 i_assert(prev_seq <= max_seq && |
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
3147
diff
changeset
|
776 (prev_seq != max_seq || prev_offset <= max_offset)); |
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
3147
diff
changeset
|
777 |
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
3147
diff
changeset
|
778 index->map->hdr.log_file_seq = prev_seq; |
2939
00b78082cd50
mmap_disable=yes: when we're syncing index by reading transaction log,
Timo Sirainen <tss@iki.fi>
parents:
2938
diff
changeset
|
779 index->map->hdr.log_file_int_offset = |
00b78082cd50
mmap_disable=yes: when we're syncing index by reading transaction log,
Timo Sirainen <tss@iki.fi>
parents:
2938
diff
changeset
|
780 index->map->hdr.log_file_ext_offset = prev_offset; |
00b78082cd50
mmap_disable=yes: when we're syncing index by reading transaction log,
Timo Sirainen <tss@iki.fi>
parents:
2938
diff
changeset
|
781 |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
782 mail_index_sync_map_deinit(&sync_map_ctx); |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
783 mail_index_view_close(view); |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
784 mail_transaction_log_view_close(log_view); |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
785 |
2913 | 786 *map = index->map; |
787 index->map = NULL; | |
788 | |
2896
305476a6f8ed
When we actually read index file's header make sure it gets copied to memory
Timo Sirainen <tss@iki.fi>
parents:
2895
diff
changeset
|
789 if (sync_to_index) { |
305476a6f8ed
When we actually read index file's header make sure it gets copied to memory
Timo Sirainen <tss@iki.fi>
parents:
2895
diff
changeset
|
790 /* make sure log file offsets get copied. most of the other |
305476a6f8ed
When we actually read index file's header make sure it gets copied to memory
Timo Sirainen <tss@iki.fi>
parents:
2895
diff
changeset
|
791 fields should stay the same. */ |
2956 | 792 i_assert(hdr.messages_count == (*map)->hdr.messages_count); |
2913 | 793 (*map)->hdr = hdr; |
2896
305476a6f8ed
When we actually read index file's header make sure it gets copied to memory
Timo Sirainen <tss@iki.fi>
parents:
2895
diff
changeset
|
794 } |
305476a6f8ed
When we actually read index file's header make sure it gets copied to memory
Timo Sirainen <tss@iki.fi>
parents:
2895
diff
changeset
|
795 |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
796 return ret < 0 ? -1 : 1; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
797 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
798 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
799 static int mail_index_read_map_with_retry(struct mail_index *index, |
2913 | 800 struct mail_index_map **map, |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
801 int sync_to_index) |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
802 { |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
803 mail_index_sync_lost_handler_t *const *handlers; |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
804 unsigned int i, count; |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
805 int ret, retry; |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
806 |
2938
bc8ff03715b2
mmap_disable=yes: if mail_index_map() is called while syncing make sure we
Timo Sirainen <tss@iki.fi>
parents:
2937
diff
changeset
|
807 if (index->log_locked) { |
bc8ff03715b2
mmap_disable=yes: if mail_index_map() is called while syncing make sure we
Timo Sirainen <tss@iki.fi>
parents:
2937
diff
changeset
|
808 /* we're most likely syncing the index and we really don't |
bc8ff03715b2
mmap_disable=yes: if mail_index_map() is called while syncing make sure we
Timo Sirainen <tss@iki.fi>
parents:
2937
diff
changeset
|
809 want to read more than what was synced last time. */ |
bc8ff03715b2
mmap_disable=yes: if mail_index_map() is called while syncing make sure we
Timo Sirainen <tss@iki.fi>
parents:
2937
diff
changeset
|
810 sync_to_index = TRUE; |
bc8ff03715b2
mmap_disable=yes: if mail_index_map() is called while syncing make sure we
Timo Sirainen <tss@iki.fi>
parents:
2937
diff
changeset
|
811 } |
bc8ff03715b2
mmap_disable=yes: if mail_index_map() is called while syncing make sure we
Timo Sirainen <tss@iki.fi>
parents:
2937
diff
changeset
|
812 |
3177
95d2d8d5958b
Some error handling path crashfixes.
Timo Sirainen <tss@iki.fi>
parents:
3173
diff
changeset
|
813 if ((*map)->hdr.indexid != 0 && index->log != NULL) { |
95d2d8d5958b
Some error handling path crashfixes.
Timo Sirainen <tss@iki.fi>
parents:
3173
diff
changeset
|
814 /* we're not creating the index, or opening transaction log. |
95d2d8d5958b
Some error handling path crashfixes.
Timo Sirainen <tss@iki.fi>
parents:
3173
diff
changeset
|
815 sync this as a view from transaction log. */ |
2935
0b72e95cd3ae
Don't try to fsck when we're modifying index. It could have happened with
Timo Sirainen <tss@iki.fi>
parents:
2934
diff
changeset
|
816 index->sync_update = TRUE; |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
817 ret = mail_index_sync_from_transactions(index, map, |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
818 sync_to_index); |
2935
0b72e95cd3ae
Don't try to fsck when we're modifying index. It could have happened with
Timo Sirainen <tss@iki.fi>
parents:
2934
diff
changeset
|
819 index->sync_update = FALSE; |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
820 if (ret != 0) |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
821 return ret; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
822 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
823 /* transaction log lost/broken, fallback to re-reading it */ |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
824 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
825 |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
826 /* notify all "sync lost" handlers */ |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
827 handlers = array_get(&index->sync_lost_handlers, &count); |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
828 for (i = 0; i < count; i++) |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
829 (*handlers[i])(index); |
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
830 |
1965
41f6a04154a3
INDEX_KEYWORDS_BYTE_COUNT was counted wrong so index files were larger than
Timo Sirainen <tss@iki.fi>
parents:
1946
diff
changeset
|
831 for (i = 0; i < MAIL_INDEX_ESTALE_RETRY_COUNT; i++) { |
2913 | 832 ret = mail_index_read_map(index, *map, &retry); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
833 if (ret != 0 || !retry) |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
834 return ret; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
835 |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
836 /* ESTALE - reopen index file */ |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
837 if (close(index->fd) < 0) |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
838 mail_index_set_syscall_error(index, "close()"); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
839 index->fd = -1; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
840 |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
841 ret = mail_index_try_open_only(index); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
842 if (ret <= 0) { |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
843 if (ret == 0) { |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
844 /* the file was lost */ |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
845 errno = ENOENT; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
846 mail_index_set_syscall_error(index, "open()"); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
847 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
848 return -1; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
849 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
850 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
851 |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
852 /* Too many ESTALE retries */ |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
853 mail_index_set_syscall_error(index, "read_map()"); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
854 return -1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
855 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
856 |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
857 static int mail_index_map_try_existing(struct mail_index_map *map) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
858 { |
1946 | 859 const struct mail_index_header *hdr; |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
860 size_t used_size; |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
861 |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
862 if (MAIL_INDEX_MAP_IS_IN_MEMORY(map)) |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
863 return 0; |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
864 |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
865 hdr = map->mmap_base; |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
866 |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
867 /* always check corrupted-flag to avoid errors later */ |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
868 if ((hdr->flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
869 return -1; |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
870 |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
871 used_size = hdr->header_size + hdr->messages_count * hdr->record_size; |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
872 if (map->mmap_size >= used_size && map->hdr_base == hdr) { |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
873 map->records_count = hdr->messages_count; |
2922
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
874 mail_index_map_copy_hdr(map, hdr); |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
875 return 1; |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
876 } |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
877 return 0; |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
878 } |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
879 |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
880 int mail_index_map(struct mail_index *index, int force) |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
881 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
882 struct mail_index_map *map; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
883 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
884 |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
885 i_assert(!index->mapping); |
2913 | 886 i_assert(index->map == NULL || index->map->refcount > 0); |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
887 i_assert(index->lock_type != F_UNLCK); |
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
888 |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
889 index->mapping = TRUE; |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
890 |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
891 if (!force && index->map != NULL) { |
2937 | 892 i_assert(index->hdr != NULL); |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
893 ret = mail_index_map_try_existing(index->map); |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
894 if (ret != 0) { |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
895 index->mapping = FALSE; |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
896 return ret; |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
897 } |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
898 |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
899 if (index->lock_type == F_WRLCK) { |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
900 /* we're syncing, don't break the mapping */ |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
901 index->mapping = FALSE; |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
902 return 1; |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
903 } |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
904 } |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
905 |
2542
c3608081d0e4
When updating index mappings, don't let it affect existing views mappings.
Timo Sirainen <tss@iki.fi>
parents:
2409
diff
changeset
|
906 if (index->map != NULL && index->map->refcount > 1) { |
c3608081d0e4
When updating index mappings, don't let it affect existing views mappings.
Timo Sirainen <tss@iki.fi>
parents:
2409
diff
changeset
|
907 /* this map is already used by some views and they may have |
c3608081d0e4
When updating index mappings, don't let it affect existing views mappings.
Timo Sirainen <tss@iki.fi>
parents:
2409
diff
changeset
|
908 pointers into it. leave them and create a new mapping. */ |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
909 if (!index->mmap_disable) { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
910 map = NULL; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
911 } else { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
912 /* create a copy of the mapping instead so we don't |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
913 have to re-read it */ |
2911
f2c2b17d7659
Changed mail_index_map_to_memory() to mail_index_map_clone(). Even if the
Timo Sirainen <tss@iki.fi>
parents:
2902
diff
changeset
|
914 map = mail_index_map_clone(index->map, |
f2c2b17d7659
Changed mail_index_map_to_memory() to mail_index_map_clone(). Even if the
Timo Sirainen <tss@iki.fi>
parents:
2902
diff
changeset
|
915 index->map->hdr.record_size); |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
916 } |
2542
c3608081d0e4
When updating index mappings, don't let it affect existing views mappings.
Timo Sirainen <tss@iki.fi>
parents:
2409
diff
changeset
|
917 index->map->refcount--; |
c3608081d0e4
When updating index mappings, don't let it affect existing views mappings.
Timo Sirainen <tss@iki.fi>
parents:
2409
diff
changeset
|
918 index->map = NULL; |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
919 } else { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
920 map = index->map; |
2542
c3608081d0e4
When updating index mappings, don't let it affect existing views mappings.
Timo Sirainen <tss@iki.fi>
parents:
2409
diff
changeset
|
921 } |
c3608081d0e4
When updating index mappings, don't let it affect existing views mappings.
Timo Sirainen <tss@iki.fi>
parents:
2409
diff
changeset
|
922 |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2043
diff
changeset
|
923 if (map == NULL) { |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2043
diff
changeset
|
924 map = i_new(struct mail_index_map, 1); |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2043
diff
changeset
|
925 map->refcount = 1; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
926 map->hdr_copy_buf = |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
927 buffer_create_dynamic(default_pool, sizeof(map->hdr)); |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2043
diff
changeset
|
928 } else if (MAIL_INDEX_MAP_IS_IN_MEMORY(map)) { |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
929 i_assert(!map->write_to_disk); |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2043
diff
changeset
|
930 } else if (map->mmap_base != NULL) { |
2193 | 931 i_assert(map->buffer == NULL); |
1946 | 932 if (munmap(map->mmap_base, map->mmap_size) < 0) |
933 mail_index_set_syscall_error(index, "munmap()"); | |
934 map->mmap_base = NULL; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
935 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
936 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
937 index->hdr = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
938 index->map = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
939 |
2823
43bab10e060d
Rebuild broken index files with mmap_disabled=yes too..
Timo Sirainen <tss@iki.fi>
parents:
2822
diff
changeset
|
940 if (!index->mmap_disable) |
43bab10e060d
Rebuild broken index files with mmap_disabled=yes too..
Timo Sirainen <tss@iki.fi>
parents:
2822
diff
changeset
|
941 ret = mail_index_mmap(index, map); |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
942 else |
2913 | 943 ret = mail_index_read_map_with_retry(index, &map, force); |
2937 | 944 i_assert(index->map == NULL); |
945 | |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
946 if (ret > 0) { |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
947 ret = mail_index_check_header(index, map); |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
948 if (ret < 0) |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
949 ret = 0; |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
950 else if (ret == 0) { |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
951 index->fsck = TRUE; |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
952 ret = 1; |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
953 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
954 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
955 |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
956 if (ret <= 0) { |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
957 mail_index_unmap_forced(index, map); |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
958 index->mapping = FALSE; |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
959 return ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
960 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
961 |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
962 index->hdr = &map->hdr; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
963 index->map = map; |
2937 | 964 i_assert(map->hdr.messages_count == map->records_count); |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
965 index->mapping = FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
966 return 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
967 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
968 |
2114
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
969 struct mail_index_map * |
2911
f2c2b17d7659
Changed mail_index_map_to_memory() to mail_index_map_clone(). Even if the
Timo Sirainen <tss@iki.fi>
parents:
2902
diff
changeset
|
970 mail_index_map_clone(struct mail_index_map *map, uint32_t new_record_size) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
971 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
972 struct mail_index_map *mem_map; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
973 struct mail_index_header *hdr; |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
974 struct mail_index_ext *extensions; |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
975 void *src, *dest; |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
976 size_t size, copy_size; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
977 unsigned int i, count; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
978 |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
979 size = map->records_count * new_record_size; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
980 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
981 mem_map = i_new(struct mail_index_map, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
982 mem_map->refcount = 1; |
2708
f1e9f3ec8135
Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents:
2683
diff
changeset
|
983 mem_map->buffer = buffer_create_dynamic(default_pool, size); |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
984 if (map->hdr.record_size == new_record_size) |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
985 buffer_append(mem_map->buffer, map->records, size); |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
986 else { |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
987 copy_size = I_MIN(map->hdr.record_size, new_record_size); |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
988 src = map->records; |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
989 for (i = 0; i < map->records_count; i++) { |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
990 dest = buffer_append_space_unsafe(mem_map->buffer, |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
991 new_record_size); |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
992 memcpy(dest, src, copy_size); |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
993 src = PTR_OFFSET(src, map->hdr.record_size); |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
994 } |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
995 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
996 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
997 mem_map->records = buffer_get_modifyable_data(mem_map->buffer, NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
998 mem_map->records_count = map->records_count; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
999 |
2708
f1e9f3ec8135
Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents:
2683
diff
changeset
|
1000 mem_map->hdr_copy_buf = |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1001 buffer_create_dynamic(default_pool, map->hdr.header_size); |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1002 if (map->hdr.base_header_size < sizeof(*hdr)) |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1003 buffer_append_zero(mem_map->hdr_copy_buf, sizeof(*hdr)); |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1004 buffer_write(mem_map->hdr_copy_buf, 0, |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1005 &map->hdr, map->hdr.base_header_size); |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1006 buffer_append(mem_map->hdr_copy_buf, |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1007 CONST_PTR_OFFSET(map->hdr_base, |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1008 map->hdr.base_header_size), |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1009 map->hdr.header_size - map->hdr.base_header_size); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1010 |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1011 hdr = buffer_get_modifyable_data(mem_map->hdr_copy_buf, NULL); |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1012 if (hdr->base_header_size < sizeof(*hdr)) |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1013 hdr->base_header_size = sizeof(*hdr); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1014 hdr->record_size = new_record_size; |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1015 mem_map->hdr = *hdr; |
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1016 mem_map->hdr_base = hdr; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1017 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
1018 /* copy extensions */ |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1019 if (array_is_created(&map->ext_id_map)) { |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1020 count = array_count(&map->ext_id_map); |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
1021 mail_index_map_init_extbufs(mem_map, count + 2); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1022 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1023 array_append_array(&mem_map->extensions, &map->extensions); |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1024 array_append_array(&mem_map->ext_id_map, &map->ext_id_map); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1025 |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1026 /* fix the name pointers to use our own pool */ |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1027 extensions = array_get_modifyable(&mem_map->extensions, &count); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1028 for (i = 0; i < count; i++) { |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
1029 extensions[i].name = p_strdup(mem_map->extension_pool, |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
1030 extensions[i].name); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1031 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1032 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1033 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1034 return mem_map; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1035 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1036 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
1037 int mail_index_map_get_ext_idx(struct mail_index_map *map, |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
1038 uint32_t ext_id, uint32_t *idx_r) |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1039 { |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1040 const uint32_t *id; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1041 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1042 if (!array_is_created(&map->ext_id_map) || |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1043 ext_id >= array_count(&map->ext_id_map)) |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1044 return 0; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1045 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1046 id = array_idx(&map->ext_id_map, ext_id); |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1047 *idx_r = *id; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1048 return *idx_r != (uint32_t)-1; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1049 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1050 |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1051 static int mail_index_try_open_only(struct mail_index *index) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1052 { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1053 int i; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1054 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1055 for (i = 0; i < 3; i++) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1056 index->fd = open(index->filepath, O_RDWR); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1057 if (index->fd == -1 && errno == EACCES) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1058 index->fd = open(index->filepath, O_RDONLY); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1059 index->readonly = TRUE; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1060 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1061 if (index->fd != -1 || errno != ESTALE) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1062 break; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1063 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1064 /* May happen with some OSes with NFS. Try again, although |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1065 there's still a race condition with another computer |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1066 creating the index file again. However, we can't try forever |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1067 as ESTALE happens also if index directory has been deleted |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1068 from server.. */ |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1069 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1070 if (index->fd == -1) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1071 if (errno != ENOENT) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1072 return mail_index_set_syscall_error(index, "open()"); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1073 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1074 /* have to create it */ |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1075 return 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1076 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1077 return 1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1078 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1079 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1080 static int |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1081 mail_index_try_open(struct mail_index *index, unsigned int *lock_id_r) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1082 { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1083 unsigned int lock_id; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1084 int ret; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1085 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1086 if (lock_id_r != NULL) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1087 *lock_id_r = 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1088 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1089 ret = mail_index_try_open_only(index); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1090 if (ret <= 0) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1091 return ret; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1092 |
2409 | 1093 if (mail_index_lock_shared(index, FALSE, &lock_id) < 0) { |
1094 (void)close(index->fd); | |
1095 index->fd = -1; | |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1096 return -1; |
2409 | 1097 } |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1098 ret = mail_index_map(index, FALSE); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1099 if (ret == 0) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1100 /* it's corrupted - recreate it */ |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1101 mail_index_unlock(index, lock_id); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1102 if (lock_id_r != NULL) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1103 *lock_id_r = 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1104 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1105 (void)close(index->fd); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1106 index->fd = -1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1107 } else { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1108 if (lock_id_r != NULL) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1109 *lock_id_r = lock_id; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1110 else |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1111 mail_index_unlock(index, lock_id); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1112 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1113 return ret; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1114 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1115 |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1116 int mail_index_write_base_header(struct mail_index *index, |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1117 const struct mail_index_header *hdr) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1118 { |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1119 size_t hdr_size; |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1120 |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1121 hdr_size = I_MIN(sizeof(*hdr), hdr->base_header_size); |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1122 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1123 if (!MAIL_INDEX_MAP_IS_IN_MEMORY(index->map)) { |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1124 memcpy(index->map->mmap_base, hdr, hdr_size); |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1125 if (msync(index->map->mmap_base, hdr_size, MS_SYNC) < 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1126 return mail_index_set_syscall_error(index, "msync()"); |
3222
e38e04c7c67c
mail_index_write_base_header() didn't update the header in memory with
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
1127 index->map->hdr = *hdr; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1128 } else { |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1129 if (pwrite_full(index->fd, hdr, hdr_size, 0) < 0) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1130 mail_index_set_syscall_error(index, "pwrite_full()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1131 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1132 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1133 |
2902
1022caefca74
mail_index_write_base_header() doesn't crash anymore if index mapping is in
Timo Sirainen <tss@iki.fi>
parents:
2896
diff
changeset
|
1134 index->map->hdr = *hdr; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1135 buffer_write(index->map->hdr_copy_buf, 0, hdr, hdr_size); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1136 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1137 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1138 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1139 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1140 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1141 int mail_index_create_tmp_file(struct mail_index *index, const char **path_r) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1142 { |
2879
aa93c7216722
dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
1143 mode_t old_mask; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1144 const char *path; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1145 int fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1146 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1147 path = *path_r = t_strconcat(index->filepath, ".tmp", NULL); |
2879
aa93c7216722
dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
1148 old_mask = umask(0); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1149 fd = open(path, O_RDWR|O_CREAT|O_TRUNC, index->mode); |
2879
aa93c7216722
dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
1150 umask(old_mask); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1151 if (fd == -1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1152 return mail_index_file_set_syscall_error(index, path, "open()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1153 |
2879
aa93c7216722
dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
1154 if (index->gid != (gid_t)-1 && fchown(fd, (uid_t)-1, index->gid) < 0) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1155 mail_index_file_set_syscall_error(index, path, "fchown()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1156 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1157 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1158 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1159 return fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1160 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1161 |
1942 | 1162 static int mail_index_create(struct mail_index *index, |
1163 struct mail_index_header *hdr) | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1164 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1165 const char *path; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1166 uint32_t seq; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1167 uoff_t offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1168 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1169 |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1170 i_assert(index->lock_type == F_UNLCK); |
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1171 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1172 /* log file lock protects index creation */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1173 if (mail_transaction_log_sync_lock(index->log, &seq, &offset) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1174 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1175 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1176 ret = mail_index_try_open(index, NULL); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1177 if (ret != 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1178 mail_transaction_log_sync_unlock(index->log); |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1179 return ret < 0 ? -1 : 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1180 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1181 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1182 /* create it fully in index.tmp first */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1183 index->fd = mail_index_create_tmp_file(index, &path); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1184 if (index->fd == -1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1185 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1186 else if (write_full(index->fd, hdr, sizeof(*hdr)) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1187 mail_index_file_set_syscall_error(index, path, "write_full()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1188 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1189 } else { |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1190 index->lock_type = F_WRLCK; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1191 ret = mail_index_map(index, FALSE); |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1192 index->lock_type = F_UNLCK; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1193 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1194 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1195 if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1196 /* it's corrupted even while we just created it, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1197 should never happen unless someone pokes the file directly */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1198 mail_index_set_error(index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1199 "Newly created index file is corrupted: %s", path); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1200 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1201 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1202 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1203 if (ret < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1204 if (unlink(path) < 0 && errno != ENOENT) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1205 mail_index_file_set_syscall_error(index, path, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1206 "unlink()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1207 } |
2170 | 1208 } else { |
1209 /* make it visible to others */ | |
1210 if (rename(path, index->filepath) < 0) { | |
1211 mail_index_set_error(index, "rename(%s, %s) failed: %m", | |
1212 path, index->filepath); | |
1213 ret = -1; | |
1214 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1215 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1216 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1217 mail_transaction_log_sync_unlock(index->log); |
2170 | 1218 return ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1219 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1220 |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1221 static void mail_index_header_init(struct mail_index_header *hdr) |
2073
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1222 { |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1223 time_t now = time(NULL); |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1224 |
3105 | 1225 i_assert((sizeof(*hdr) % sizeof(uint64_t)) == 0); |
1226 | |
2073
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1227 memset(hdr, 0, sizeof(*hdr)); |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1228 |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1229 hdr->major_version = MAIL_INDEX_MAJOR_VERSION; |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1230 hdr->minor_version = MAIL_INDEX_MINOR_VERSION; |
2116 | 1231 hdr->base_header_size = sizeof(*hdr); |
2073
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1232 hdr->header_size = sizeof(*hdr); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1233 hdr->record_size = sizeof(struct mail_index_record); |
2073
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1234 |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1235 #ifndef WORDS_BIGENDIAN |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1236 hdr->compat_data[0] = MAIL_INDEX_COMPAT_LITTLE_ENDIAN; |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1237 #endif |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1238 hdr->compat_data[1] = sizeof(uoff_t); |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1239 hdr->compat_data[2] = sizeof(time_t); |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1240 |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1241 hdr->indexid = now; |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1242 |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1243 hdr->next_uid = 1; |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1244 } |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1245 |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1246 /* returns -1 = error, 0 = won't create, 1 = ok */ |
1942 | 1247 static int mail_index_open_files(struct mail_index *index, |
1248 enum mail_index_open_flags flags) | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1249 { |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1250 struct mail_index_header hdr; |
1935
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1930
diff
changeset
|
1251 unsigned int lock_id = 0; |
3129
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3105
diff
changeset
|
1252 int ret, created = FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1253 |
1935
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1930
diff
changeset
|
1254 ret = mail_index_try_open(index, &lock_id); |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1255 if (ret > 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1256 hdr = *index->hdr; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1257 else if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1258 /* doesn't exist, or corrupted */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1259 if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1260 return 0; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1261 mail_index_header_init(&hdr); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1262 index->hdr = &hdr; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1263 } else if (ret < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1264 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1265 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1266 index->indexid = hdr.indexid; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1267 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1268 index->log = mail_transaction_log_open_or_create(index); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1269 if (index->log == NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1270 return -1; |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1271 |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1272 if (index->fd == -1) { |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1273 if (lock_id != 0) { |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1274 mail_index_unlock(index, lock_id); |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1275 lock_id = 0; |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1276 } |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1277 if (mail_index_create(index, &hdr) < 0) |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1278 return -1; |
3129
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3105
diff
changeset
|
1279 created = TRUE; |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1280 } |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1281 |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1282 if (lock_id == 0) { |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1283 if (mail_index_lock_shared(index, FALSE, &lock_id) < 0) |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1284 return -1; |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1285 |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1286 } |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1287 |
3129
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3105
diff
changeset
|
1288 index->cache = created ? mail_cache_create(index) : |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3105
diff
changeset
|
1289 mail_cache_open_or_create(index); |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1290 |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1291 mail_index_unlock(index, lock_id); |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1292 return 1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1293 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1294 |
2723
12b503fbb8af
Replaced fcntl_locks_disable with lock_method, so it's now possible to use
Timo Sirainen <tss@iki.fi>
parents:
2715
diff
changeset
|
1295 int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags, |
12b503fbb8af
Replaced fcntl_locks_disable with lock_method, so it's now possible to use
Timo Sirainen <tss@iki.fi>
parents:
2715
diff
changeset
|
1296 enum mail_index_lock_method lock_method) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1297 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1298 int i = 0, ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1299 |
2926
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1300 if (index->opened) { |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1301 if (index->hdr != NULL && |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1302 (index->hdr->flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) { |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1303 /* corrupted, reopen files */ |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1304 mail_index_close(index); |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1305 } else { |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1306 return 0; |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1307 } |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1308 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1309 |
1967 | 1310 index->filepath = i_strconcat(index->dir, "/", index->prefix, NULL); |
1311 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1312 do { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1313 index->shared_lock_count = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1314 index->excl_lock_count = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1315 index->lock_type = F_UNLCK; |
2021 | 1316 index->lock_id = 2; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1317 |
2723
12b503fbb8af
Replaced fcntl_locks_disable with lock_method, so it's now possible to use
Timo Sirainen <tss@iki.fi>
parents:
2715
diff
changeset
|
1318 index->readonly = FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1319 index->nodiskspace = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1320 index->index_lock_timeout = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1321 index->log_locked = FALSE; |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1322 index->mmap_disable = |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1323 (flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) != 0; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1324 index->mmap_no_write = |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1325 (flags & MAIL_INDEX_OPEN_FLAG_MMAP_NO_WRITE) != 0; |
2723
12b503fbb8af
Replaced fcntl_locks_disable with lock_method, so it's now possible to use
Timo Sirainen <tss@iki.fi>
parents:
2715
diff
changeset
|
1326 index->lock_method = lock_method; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1327 |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1328 /* don't even bother to handle dotlocking without mmap being |
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1329 disabled. that combination simply doesn't make any sense */ |
2940
0e1481357fbb
Changed assert() to friendly human readable message.
Timo Sirainen <tss@iki.fi>
parents:
2939
diff
changeset
|
1330 if (lock_method == MAIL_INDEX_LOCK_DOTLOCK && |
0e1481357fbb
Changed assert() to friendly human readable message.
Timo Sirainen <tss@iki.fi>
parents:
2939
diff
changeset
|
1331 !index->mmap_disable) { |
0e1481357fbb
Changed assert() to friendly human readable message.
Timo Sirainen <tss@iki.fi>
parents:
2939
diff
changeset
|
1332 i_fatal("lock_method=dotlock and mmap_disable=no " |
0e1481357fbb
Changed assert() to friendly human readable message.
Timo Sirainen <tss@iki.fi>
parents:
2939
diff
changeset
|
1333 "combination isn't supported. " |
0e1481357fbb
Changed assert() to friendly human readable message.
Timo Sirainen <tss@iki.fi>
parents:
2939
diff
changeset
|
1334 "You don't _really_ want it anyway."); |
0e1481357fbb
Changed assert() to friendly human readable message.
Timo Sirainen <tss@iki.fi>
parents:
2939
diff
changeset
|
1335 } |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1336 |
1942 | 1337 ret = mail_index_open_files(index, flags); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1338 if (ret <= 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1339 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1340 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1341 index->opened = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1342 if (index->fsck) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1343 index->fsck = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1344 ret = mail_index_fsck(index); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1345 if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1346 /* completely broken, reopen */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1347 if (i++ < 3) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1348 continue; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1349 /* too many tries */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1350 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1351 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1352 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1353 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1354 } while (1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1355 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1356 if (ret <= 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1357 mail_index_close(index); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1358 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1359 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1360 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1361 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1362 void mail_index_close(struct mail_index *index) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1363 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1364 if (index->log != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1365 mail_transaction_log_close(index->log); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1366 index->log = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1367 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1368 |
1930 | 1369 if (index->map != NULL) { |
1370 mail_index_unmap(index, index->map); | |
1371 index->map = NULL; | |
1372 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1373 |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1374 if (index->cache != NULL) { |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1375 mail_cache_free(index->cache); |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1376 index->cache = NULL; |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1377 } |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1378 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1379 if (index->fd != -1) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1380 if (close(index->fd) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1381 mail_index_set_syscall_error(index, "close()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1382 index->fd = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1383 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1384 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1385 i_free(index->copy_lock_path); |
1930 | 1386 index->copy_lock_path = NULL; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1387 i_free(index->filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1388 index->filepath = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1389 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1390 index->indexid = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1391 index->opened = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1392 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1393 |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1394 int mail_index_reopen(struct mail_index *index, int fd) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1395 { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1396 struct mail_index_map *old_map; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1397 unsigned int old_shared_locks, old_lock_id, lock_id = 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1398 int ret, old_fd, old_lock_type; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1399 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1400 old_map = index->map; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1401 old_fd = index->fd; |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1402 old_map->refcount++; |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1403 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1404 /* new file, new locks. the old fd can keep it's locks, they don't |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1405 matter anymore as no-one's going to modify the file. */ |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1406 old_lock_type = index->lock_type; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1407 old_lock_id = index->lock_id; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1408 old_shared_locks = index->shared_lock_count; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1409 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1410 if (index->lock_type == F_RDLCK) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1411 index->lock_type = F_UNLCK; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1412 index->lock_id += 2; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1413 index->shared_lock_count = 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1414 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1415 if (fd != -1) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1416 index->fd = fd; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1417 ret = 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1418 } else { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1419 i_assert(index->excl_lock_count == 0); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1420 ret = mail_index_try_open_only(index); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1421 if (ret > 0) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1422 ret = mail_index_lock_shared(index, FALSE, &lock_id); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1423 else if (ret == 0) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1424 /* index file is lost */ |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1425 ret = -1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1426 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1427 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1428 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1429 if (ret == 0) { |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1430 /* read the new mapping. note that with mmap_disable we want |
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1431 to keep the old mapping in index->map so we can update it |
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1432 by reading transaction log. */ |
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1433 if (mail_index_map(index, TRUE) <= 0) |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1434 ret = -1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1435 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1436 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1437 if (lock_id != 0) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1438 mail_index_unlock(index, lock_id); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1439 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1440 if (ret == 0) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1441 mail_index_unmap(index, old_map); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1442 if (close(old_fd) < 0) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1443 mail_index_set_syscall_error(index, "close()"); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1444 } else { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1445 if (index->map != NULL) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1446 mail_index_unmap(index, index->map); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1447 if (index->fd != -1) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1448 if (close(index->fd) < 0) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1449 mail_index_set_syscall_error(index, "close()"); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1450 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1451 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1452 index->map = old_map; |
2884
173a0296e81d
Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents:
2879
diff
changeset
|
1453 index->hdr = &index->map->hdr; |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1454 index->fd = old_fd; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1455 index->lock_type = old_lock_type; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1456 index->lock_id = old_lock_id; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1457 index->shared_lock_count = old_shared_locks; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1458 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1459 return ret; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1460 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1461 |
2936
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1462 int mail_index_reopen_if_needed(struct mail_index *index) |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1463 { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1464 struct stat st1, st2; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1465 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1466 if (fstat(index->fd, &st1) < 0) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1467 return mail_index_set_syscall_error(index, "fstat()"); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1468 if (stat(index->filepath, &st2) < 0) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1469 mail_index_set_syscall_error(index, "stat()"); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1470 if (errno != ENOENT) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1471 return -1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1472 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1473 /* lost it? recreate */ |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1474 (void)mail_index_mark_corrupted(index); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1475 return -1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1476 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1477 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1478 if (st1.st_ino != st2.st_ino || |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1479 !CMP_DEV_T(st1.st_dev, st2.st_dev)) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1480 if (mail_index_reopen(index, -1) < 0) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1481 return -1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1482 return 1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1483 } else { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1484 return 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1485 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1486 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1487 |
2936
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1488 int mail_index_refresh(struct mail_index *index) |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1489 { |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1490 unsigned int lock_id; |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1491 int ret; |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1492 |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1493 if (index->excl_lock_count > 0) { |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1494 /* we have index exclusively locked, nothing could |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1495 have changed. */ |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1496 return 0; |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1497 } |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1498 |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1499 if (!index->mmap_disable) { |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1500 /* reopening is all we need */ |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1501 return mail_index_reopen_if_needed(index); |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1502 } |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1503 |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1504 /* mail_index_map() simply reads latest changes from transaction log, |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1505 which makes us fully refreshed. */ |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1506 if (mail_index_lock_shared(index, TRUE, &lock_id) < 0) |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1507 return -1; |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1508 |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1509 ret = mail_index_map(index, FALSE); |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1510 mail_index_unlock(index, lock_id); |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1511 return ret <= 0 ? -1 : 0; |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1512 } |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1513 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1514 struct mail_cache *mail_index_get_cache(struct mail_index *index) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1515 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1516 return index->cache; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1517 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1518 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1519 int mail_index_set_error(struct mail_index *index, const char *fmt, ...) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1520 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1521 va_list va; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1522 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1523 i_free(index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1524 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1525 if (fmt == NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1526 index->error = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1527 else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1528 va_start(va, fmt); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1529 index->error = i_strdup_vprintf(fmt, va); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1530 va_end(va); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1531 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1532 i_error("%s", index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1533 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1534 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1535 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1536 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1537 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1538 void mail_index_set_inconsistent(struct mail_index *index) |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1539 { |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1540 index->indexid = 0; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1541 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1542 |
1945 | 1543 void mail_index_mark_corrupted(struct mail_index *index) |
1943 | 1544 { |
1545 struct mail_index_header hdr; | |
1546 | |
1945 | 1547 mail_index_set_inconsistent(index); |
1548 | |
1943 | 1549 if (index->readonly) |
1945 | 1550 return; |
1943 | 1551 |
1552 hdr = *index->hdr; | |
1553 hdr.flags |= MAIL_INDEX_HDR_FLAG_CORRUPTED; | |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1554 if (mail_index_write_base_header(index, &hdr) == 0) { |
1945 | 1555 if (fsync(index->fd) < 0) |
1556 mail_index_set_syscall_error(index, "fsync()"); | |
1557 } | |
1943 | 1558 } |
1559 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1560 int mail_index_set_syscall_error(struct mail_index *index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1561 const char *function) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1562 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1563 i_assert(function != NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1564 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1565 if (ENOSPACE(errno)) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1566 index->nodiskspace = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1567 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1568 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1569 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1570 return mail_index_set_error(index, "%s failed with index file %s: %m", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1571 function, index->filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1572 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1573 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1574 int mail_index_file_set_syscall_error(struct mail_index *index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1575 const char *filepath, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1576 const char *function) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1577 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1578 i_assert(filepath != NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1579 i_assert(function != NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1580 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1581 if (ENOSPACE(errno)) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1582 index->nodiskspace = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1583 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1584 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1585 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1586 return mail_index_set_error(index, "%s failed with file %s: %m", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1587 function, filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1588 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1589 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1590 enum mail_index_error mail_index_get_last_error(struct mail_index *index) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1591 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1592 if (index->nodiskspace) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1593 return MAIL_INDEX_ERROR_DISKSPACE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1594 if (index->error != NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1595 return MAIL_INDEX_ERROR_INTERNAL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1596 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1597 return MAIL_INDEX_ERROR_NONE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1598 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1599 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1600 const char *mail_index_get_error_message(struct mail_index *index) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1601 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1602 return index->error; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1603 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1604 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1605 void mail_index_reset_error(struct mail_index *index) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1606 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1607 if (index->error != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1608 i_free(index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1609 index->error = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1610 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1611 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1612 index->nodiskspace = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1613 index->index_lock_timeout = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1614 } |
2407
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1615 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1616 uint32_t mail_index_uint32_to_offset(uint32_t offset) |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1617 { |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1618 unsigned char buf[4]; |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1619 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1620 i_assert(offset < 0x40000000); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1621 i_assert((offset & 3) == 0); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1622 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1623 offset >>= 2; |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1624 buf[0] = 0x80 | ((offset & 0x0fe00000) >> 21); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1625 buf[1] = 0x80 | ((offset & 0x001fc000) >> 14); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1626 buf[2] = 0x80 | ((offset & 0x00003f80) >> 7); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1627 buf[3] = 0x80 | (offset & 0x0000007f); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1628 return *((uint32_t *) buf); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1629 } |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1630 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1631 uint32_t mail_index_offset_to_uint32(uint32_t offset) |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1632 { |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1633 const unsigned char *buf = (const unsigned char *) &offset; |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1634 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1635 if ((offset & 0x80808080) != 0x80808080) |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1636 return 0; |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1637 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1638 return (((uint32_t)buf[3] & 0x7f) << 2) | |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1639 (((uint32_t)buf[2] & 0x7f) << 9) | |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1640 (((uint32_t)buf[1] & 0x7f) << 16) | |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1641 (((uint32_t)buf[0] & 0x7f) << 23); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1642 } |