Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-index/mail-index.c @ 4071:cd3d26cf124a HEAD
Renamed safe-open.* to nfs-workarounds.*, safe_open() to nfs_safe_open() and
added a new global NFS_ESTALE_RETRY_COUNT which everyone uses instead of
defining their own.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 26 Feb 2006 12:15:39 +0200 |
parents | 96ae9c096bde |
children | 7e6acdd8d18d |
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" |
3470
346a494c2feb
Moved array declaration to array-decl.h and include it in lib.h. So array.h
Timo Sirainen <tss@iki.fi>
parents:
3445
diff
changeset
|
4 #include "array.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "buffer.h" |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
6 #include "hash.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "mmap-util.h" |
4071
cd3d26cf124a
Renamed safe-open.* to nfs-workarounds.*, safe_open() to nfs_safe_open() and
Timo Sirainen <tss@iki.fi>
parents:
4067
diff
changeset
|
8 #include "nfs-workarounds.h" |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
9 #include "read-full.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "write-full.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #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
|
12 #include "mail-index-sync-private.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #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
|
14 #include "mail-cache.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #include <stdio.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 #include <stddef.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 #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
|
19 #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
|
20 |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
21 static int mail_index_try_open_only(struct mail_index *index); |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
22 static void mail_index_create_in_memory(struct mail_index *index, |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
23 const struct mail_index_header *hdr); |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
24 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 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
|
26 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 struct mail_index *index; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 index = i_new(struct mail_index, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 index->dir = i_strdup(dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 index->prefix = i_strdup(prefix); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 index->fd = -1; |
2116 | 33 |
3294 | 34 index->extension_pool = pool_alloconly_create("extension", 512); |
3191
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->extensions, index->extension_pool, |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
36 struct mail_index_registered_ext, 5); |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
37 |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
38 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
|
39 mail_index_sync_lost_handler_t *, 4); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 index->mode = 0600; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 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
|
43 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
44 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
|
45 mail_index_ext_register(index, "keywords", 128, 2, 1); |
3086 | 46 index->keywords_pool = pool_alloconly_create("keywords", 512); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
47 ARRAY_CREATE(&index->keywords, default_pool, const char *, 16); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
48 index->keywords_hash = |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
49 hash_create(default_pool, index->keywords_pool, 0, |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
50 strcase_hash, (hash_cmp_callback_t *)strcasecmp); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 return index; |
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 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
54 void mail_index_free(struct mail_index **_index) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
56 struct mail_index *index = *_index; |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
57 |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
58 *_index = NULL; |
1967 | 59 mail_index_close(index); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
60 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
61 hash_destroy(index->keywords_hash); |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
62 pool_unref(index->extension_pool); |
3086 | 63 pool_unref(index->keywords_pool); |
1967 | 64 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
65 array_free(&index->sync_lost_handlers); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
66 array_free(&index->keywords); |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
67 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 i_free(index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 i_free(index->dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 i_free(index->prefix); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 i_free(index); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 |
2650
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
74 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
|
75 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
|
76 { |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
77 index->mode = mode & 0666; |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
78 index->gid = gid; |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
79 } |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
80 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 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
|
85 { |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
86 const struct mail_index_registered_ext *extensions; |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
87 struct mail_index_registered_ext rext; |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
88 unsigned int i, ext_count; |
2115
f720b3f15333
Modifying extra_records should work now.
Timo Sirainen <tss@iki.fi>
parents:
2114
diff
changeset
|
89 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
90 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
|
91 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
92 /* 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
|
93 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
|
94 if (strcmp(extensions[i].name, name) == 0) |
2116 | 95 return i; |
96 } | |
97 | |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
98 memset(&rext, 0, sizeof(rext)); |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
99 rext.name = p_strdup(index->extension_pool, name); |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
100 rext.index_idx = ext_count; |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
101 rext.hdr_size = default_hdr_size; |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
102 rext.record_size = default_record_size; |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
103 rext.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
|
104 |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
105 array_append(&index->extensions, &rext, 1); |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
106 return ext_count; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
107 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
108 |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 { |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
113 struct mail_index_registered_ext *rext; |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
114 |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
115 rext = array_idx_modifyable(&index->extensions, ext_id); |
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
116 i_assert(rext->expunge_handler == NULL); |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
117 |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
118 rext->expunge_handler = cb; |
3224
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 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
121 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
|
122 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
|
123 { |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
124 struct mail_index_registered_ext *rext; |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
125 |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
126 rext = array_idx_modifyable(&index->extensions, ext_id); |
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
127 i_assert(rext->expunge_handler != NULL); |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
128 |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
129 rext->expunge_handler = 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
|
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 |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 { |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
136 struct mail_index_registered_ext *rext; |
2869
d2daf90c79f1
Cache invalidating needed to hook into view syncing as well.
Timo Sirainen <tss@iki.fi>
parents:
2857
diff
changeset
|
137 |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
138 rext = array_idx_modifyable(&index->extensions, ext_id); |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
139 i_assert(rext->sync_handler.callback == NULL); |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
140 |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
141 rext->sync_handler.callback = cb; |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
142 rext->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
|
143 } |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
144 |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
145 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
|
146 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
|
147 { |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
148 struct mail_index_registered_ext *rext; |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
149 |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
150 rext = array_idx_modifyable(&index->extensions, ext_id); |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
151 i_assert(rext->sync_handler.callback != NULL); |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
152 |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
153 rext->sync_handler.callback = NULL; |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
154 rext->sync_handler.type = 0; |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
155 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
156 |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
157 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
|
158 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
|
159 { |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
160 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
|
161 } |
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
162 |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
163 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
|
164 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
|
165 { |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
166 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
|
167 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
|
168 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
169 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
|
170 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
|
171 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
|
172 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
|
173 break; |
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 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
177 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
178 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
|
179 unsigned int initial_count) |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
180 { |
3294 | 181 #define EXTENSION_NAME_APPROX_LEN 20 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
182 size_t size; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
183 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
184 if (map->extension_pool == NULL) { |
3294 | 185 size = (sizeof(array_t) + BUFFER_APPROX_SIZE) * 2 + |
186 initial_count * (EXTENSION_NAME_APPROX_LEN + | |
187 sizeof(struct mail_index_ext) + | |
188 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
|
189 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
|
190 pool_alloconly_create("extensions", |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
191 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
|
192 } else { |
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
193 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
|
194 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
195 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 uint32_t, initial_count); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
200 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
201 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
202 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
|
203 { |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
204 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
|
205 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
|
206 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
207 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
|
208 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
|
209 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 return i; |
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 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
|
216 } |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
217 |
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 |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 { |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
225 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
|
226 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
|
227 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
228 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
|
229 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
|
230 idx = 0; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
231 } else { |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
232 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
|
233 } |
3147
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
234 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
|
235 |
3445
74475a126e2f
Renamed array_modifyable_*() functions. I could never remember how they were
Timo Sirainen <tss@iki.fi>
parents:
3369
diff
changeset
|
236 ext = array_append_space(&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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
245 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
|
246 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
|
247 |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
248 /* Update index ext_id -> map ext_id mapping. Fill non-used |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
249 ext_ids with (uint32_t)-1 */ |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
250 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
|
251 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
|
252 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
|
253 return idx; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
254 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
255 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
256 static bool size_check(size_t *size_left, size_t size) |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
257 { |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
258 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
|
259 return FALSE; |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
260 *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
|
261 return TRUE; |
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 |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
264 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
|
265 { |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
266 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
|
267 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
|
268 } |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
269 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
270 static int mail_index_parse_extensions(struct mail_index *index, |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
271 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
|
272 { |
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 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
|
274 unsigned int i, old_count; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
275 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
|
276 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
|
277 size_t size_left; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
278 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
279 /* 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
|
280 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
|
281 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
|
282 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
|
283 /* 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
|
284 return 1; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
285 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
286 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
287 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
|
288 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
|
289 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
290 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
|
291 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
|
292 array_append(&map->ext_id_map, &ext_id, 1); |
2116 | 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 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
|
295 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
|
296 |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
297 /* Extension header contains: |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
298 - struct mail_index_ext_header |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
299 - name (not 0-terminated) |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
300 - 64bit alignment padding |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
301 - extension header contents |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
302 - 64bit alignment padding |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
303 */ |
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
|
304 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
|
305 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
|
306 !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
|
307 !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
|
308 !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
|
309 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
|
310 "Header extension goes outside header", |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
311 index->filepath); |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
312 return -1; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
313 } |
3147
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
314 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
319 t_push(); |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
320 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
|
321 ext_hdr->name_size); |
3147
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
322 |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
323 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
|
324 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
|
325 "Duplicate header extension %s", |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
326 index->filepath, name); |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
327 t_pop(); |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
328 return -1; |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
329 } |
6c7d463eaf1e
Don't allow duplicate extension names in index header.
Timo Sirainen <tss@iki.fi>
parents:
3129
diff
changeset
|
330 |
3497
872218271484
Check that record alignmentation is actually used correctly. If not,
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
331 if ((ext_hdr->record_offset % ext_hdr->record_align) != 0 || |
872218271484
Check that record alignmentation is actually used correctly. If not,
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
332 (map->hdr.record_size % ext_hdr->record_align) != 0) { |
872218271484
Check that record alignmentation is actually used correctly. If not,
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
333 mail_index_set_error(index, "Corrupted index file %s: " |
872218271484
Check that record alignmentation is actually used correctly. If not,
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
334 "Record field %s alignmentation %u not used", |
872218271484
Check that record alignmentation is actually used correctly. If not,
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
335 index->filepath, name, ext_hdr->record_align); |
872218271484
Check that record alignmentation is actually used correctly. If not,
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
336 t_pop(); |
872218271484
Check that record alignmentation is actually used correctly. If not,
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
337 return -1; |
872218271484
Check that record alignmentation is actually used correctly. If not,
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
338 } |
872218271484
Check that record alignmentation is actually used correctly. If not,
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
339 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 t_pop(); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
347 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
348 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
|
349 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
350 return 1; |
2114
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
351 } |
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
352 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
353 bool mail_index_keyword_lookup(struct mail_index *index, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
354 const char *keyword, bool autocreate, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
355 unsigned int *idx_r) |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
356 { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
357 char *keyword_dup; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
358 void *value; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
359 |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
360 /* keywords_hash keeps a name => index mapping of keywords. |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
361 Keywords are never removed from it, so the index values are valid |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
362 for the lifetime of the mail_index. */ |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
363 if (hash_lookup_full(index->keywords_hash, keyword, NULL, &value)) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
364 *idx_r = POINTER_CAST_TO(value, unsigned int); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
365 return TRUE; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
366 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
367 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
368 if (!autocreate) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
369 *idx_r = (unsigned int)-1; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
370 return FALSE; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
371 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
372 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
373 keyword = keyword_dup = p_strdup(index->keywords_pool, keyword); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
374 *idx_r = array_count(&index->keywords); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
375 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
376 hash_insert(index->keywords_hash, keyword_dup, POINTER_CAST(*idx_r)); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
377 array_append(&index->keywords, &keyword, 1); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
378 return TRUE; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
379 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
380 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
381 int mail_index_map_parse_keywords(struct mail_index *index, |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
382 struct mail_index_map *map) |
3016
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 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
|
385 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
|
386 const struct mail_index_keyword_header_rec *kw_rec; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
387 const char *name; |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
388 unsigned int i, name_area_end_offset, old_count; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
389 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
|
390 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
391 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
|
392 if (ext_id == (uint32_t)-1) { |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
393 if (array_is_created(&map->keyword_idx_map)) |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
394 array_clear(&map->keyword_idx_map); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
395 return 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
396 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
397 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
398 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
|
399 |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
400 /* Extension header contains: |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
401 - struct mail_index_keyword_header |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
402 - struct mail_index_keyword_header_rec * keywords_count |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
403 - const char names[] * keywords_count |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
404 */ |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
405 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
|
406 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
|
407 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
|
408 |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
409 old_count = !array_is_created(&map->keyword_idx_map) ? 0 : |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
410 array_count(&map->keyword_idx_map); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
411 |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
412 /* Keywords can only be added into same mapping. Removing requires a |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
413 new mapping (recreating the index file) */ |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
414 if (kw_hdr->keywords_count == old_count) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
415 /* nothing changed */ |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
416 return 0; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
417 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
418 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
419 /* make sure the header is valid */ |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
420 if (kw_hdr->keywords_count < old_count) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
421 mail_index_set_error(index, "Corrupted index file %s: " |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
422 "Keywords removed unexpectedly", |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
423 index->filepath); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
424 return -1; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
425 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
426 |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
427 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
|
428 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
|
429 "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
|
430 index->filepath); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
431 return -1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
432 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
433 |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
434 name_area_end_offset = (const char *)kw_hdr + ext->hdr_size - name; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
435 for (i = 0; i < kw_hdr->keywords_count; i++) { |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
436 if (kw_rec[i].name_offset > name_area_end_offset) { |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
437 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
|
438 "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
|
439 index->filepath); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
440 return -1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
441 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
442 } |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
443 if (name[name_area_end_offset-1] != '\0') { |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
444 mail_index_set_error(index, "Corrupted index file %s: " |
3550 | 445 "Keyword header doesn't end with NUL", |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
446 index->filepath); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
447 return -1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
448 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
449 |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
450 /* create file -> index mapping */ |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
451 if (!array_is_created(&map->keyword_idx_map)) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
452 ARRAY_CREATE(&map->keyword_idx_map, default_pool, |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
453 unsigned int, kw_hdr->keywords_count); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
454 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
455 |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
456 #ifdef DEBUG |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
457 /* Check that existing headers are still the same. It's behind DEBUG |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
458 since it's pretty useless waste of CPU normally. */ |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
459 for (i = 0; i < array_count(&map->keyword_idx_map); i++) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
460 const char *keyword = name + kw_rec[i].name_offset; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
461 const unsigned int *old_idx; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
462 unsigned int idx; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
463 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
464 old_idx = array_idx(&map->keyword_idx_map, i); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
465 if (!mail_index_keyword_lookup(index, keyword, FALSE, &idx) || |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
466 idx != *old_idx) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
467 mail_index_set_error(index, "Corrupted index file %s: " |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
468 "Keywords changed unexpectedly", |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
469 index->filepath); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
470 return -1; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
471 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
472 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
473 #endif |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
474 /* Register the newly seen keywords */ |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
475 i = array_count(&map->keyword_idx_map); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
476 for (; i < kw_hdr->keywords_count; i++) { |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
477 const char *keyword = name + kw_rec[i].name_offset; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
478 unsigned int idx; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
479 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
480 (void)mail_index_keyword_lookup(index, keyword, TRUE, &idx); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
481 array_append(&map->keyword_idx_map, &idx, 1); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
482 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
483 return 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
484 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
485 |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
486 const array_t *mail_index_get_keywords(struct mail_index *index) |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
487 { |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
488 /* Make sure all the keywords are in index->keywords. It's quick to do |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
489 if nothing has changed. */ |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
490 (void)mail_index_map_parse_keywords(index, index->map); |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
491 |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
492 return &index->keywords; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
493 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
494 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
495 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
|
496 struct mail_index_map *map) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
497 { |
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
|
498 const struct mail_index_header *hdr = &map->hdr; |
3819
61f0e1fe9b55
Moved uoff_t and time_t compatibility checks to cache file, since they're
Timo Sirainen <tss@iki.fi>
parents:
3818
diff
changeset
|
499 enum mail_index_header_compat_flags compat_flags = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
500 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 #ifndef WORDS_BIGENDIAN |
3819
61f0e1fe9b55
Moved uoff_t and time_t compatibility checks to cache file, since they're
Timo Sirainen <tss@iki.fi>
parents:
3818
diff
changeset
|
502 compat_flags |= MAIL_INDEX_COMPAT_LITTLE_ENDIAN; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
503 #endif |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
504 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
505 if (hdr->major_version != MAIL_INDEX_MAJOR_VERSION) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
506 /* major version change - handle silently(?) */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
507 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
508 } |
3819
61f0e1fe9b55
Moved uoff_t and time_t compatibility checks to cache file, since they're
Timo Sirainen <tss@iki.fi>
parents:
3818
diff
changeset
|
509 if (hdr->compat_flags != compat_flags) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
510 /* architecture change - handle silently(?) */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
511 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
512 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
513 |
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
|
514 if ((map->hdr.flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) { |
2095 | 515 /* we've already complained about it */ |
1930 | 516 return -1; |
517 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
518 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
519 /* 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
|
520 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
|
521 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
|
522 "uid_validity = 0, next_uid = %u", |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
523 index->filepath, hdr->next_uid); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
524 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
525 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
526 |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
527 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
|
528 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
|
529 "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
|
530 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
|
531 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
|
532 return -1; |
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
533 } |
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
534 |
3353
286cc0cd888a
Check broken flag counter values every time when updating them. Added
Timo Sirainen <tss@iki.fi>
parents:
3296
diff
changeset
|
535 if ((hdr->flags & MAIL_INDEX_HDR_FLAG_FSCK) != 0) |
286cc0cd888a
Check broken flag counter values every time when updating them. Added
Timo Sirainen <tss@iki.fi>
parents:
3296
diff
changeset
|
536 return 0; |
286cc0cd888a
Check broken flag counter values every time when updating them. Added
Timo Sirainen <tss@iki.fi>
parents:
3296
diff
changeset
|
537 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
538 if (hdr->next_uid == 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
539 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
540 |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2021
diff
changeset
|
541 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
|
542 hdr->seen_messages_count > hdr->messages_count || |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
543 hdr->deleted_messages_count > hdr->messages_count) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
544 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
545 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
|
546 hdr->first_unseen_uid_lowwater > hdr->next_uid || |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
547 hdr->first_deleted_uid_lowwater > hdr->next_uid) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
548 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
549 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
550 return mail_index_parse_extensions(index, map); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
551 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
552 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
553 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
|
554 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
|
555 { |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
556 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
|
557 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
|
558 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
|
559 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
|
560 } 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
|
561 i_assert(map->buffer == NULL); |
1930 | 562 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
|
563 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
|
564 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
|
565 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
566 |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
567 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
|
568 memset(&map->hdr, 0, sizeof(map->hdr)); |
1930 | 569 map->mmap_size = 0; |
570 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
|
571 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
|
572 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
|
573 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
574 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
575 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
576 void mail_index_unmap(struct mail_index *index, struct mail_index_map **_map) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
577 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
578 struct mail_index_map *map = *_map; |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
579 |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
580 *_map = NULL; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
581 if (--map->refcount > 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
582 return; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
583 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
584 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
|
585 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
|
586 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
|
587 pool_unref(map->extension_pool); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
588 if (array_is_created(&map->keyword_idx_map)) |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
589 array_free(&map->keyword_idx_map); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
590 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
|
591 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
|
592 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
593 |
2922
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
594 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
|
595 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
|
596 { |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
597 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
|
598 /* 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
|
599 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
|
600 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
|
601 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
|
602 } else { |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
603 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
|
604 } |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
605 } |
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
606 |
1930 | 607 static int mail_index_mmap(struct mail_index *index, struct mail_index_map *map) |
608 { | |
609 const struct mail_index_header *hdr; | |
610 unsigned int records_count; | |
611 | |
2193 | 612 i_assert(!map->write_to_disk); |
613 | |
614 if (map->buffer != NULL) { | |
615 /* we had temporarily used a buffer, eg. for updating index */ | |
616 buffer_free(map->buffer); | |
617 map->buffer = NULL; | |
618 } | |
2043
4548def7ac02
Don't try to re-map dirty memory mapping.
Timo Sirainen <tss@iki.fi>
parents:
2038
diff
changeset
|
619 |
2761
f96a7b2d1c52
Removed mmap() memory area protections. They weren't always set correctly.
Timo Sirainen <tss@iki.fi>
parents:
2723
diff
changeset
|
620 map->mmap_base = index->readonly ? |
1930 | 621 mmap_ro_file(index->fd, &map->mmap_size) : |
622 mmap_rw_file(index->fd, &map->mmap_size); | |
623 if (map->mmap_base == MAP_FAILED) { | |
624 map->mmap_base = NULL; | |
625 mail_index_set_syscall_error(index, "mmap()"); | |
626 return -1; | |
627 } | |
628 | |
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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 /* 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
|
634 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
|
635 } |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
636 |
1930 | 637 if (map->mmap_size < MAIL_INDEX_HEADER_MIN_SIZE) { |
638 mail_index_set_error(index, "Corrupted index file %s: " | |
639 "File too small (%"PRIuSIZE_T")", | |
640 index->filepath, map->mmap_size); | |
641 return 0; | |
642 } | |
643 | |
644 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
|
645 hdr->messages_count * hdr->record_size; |
1930 | 646 |
647 if (map->mmap_used_size > map->mmap_size) { | |
648 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
|
649 hdr->record_size; |
1930 | 650 mail_index_set_error(index, "Corrupted index file %s: " |
651 "messages_count too large (%u > %u)", | |
2122 | 652 index->filepath, hdr->messages_count, |
1930 | 653 records_count); |
654 return 0; | |
655 } | |
656 | |
2922
fadf33c24902
With mmap_disabled=no the index header wasn't always updated causing various
Timo Sirainen <tss@iki.fi>
parents:
2921
diff
changeset
|
657 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
|
658 |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
659 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
|
660 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
|
661 map->records_count = map->hdr.messages_count; |
1930 | 662 return 1; |
663 } | |
664 | |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
665 static int mail_index_read_header(struct mail_index *index, |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
666 void *buf, size_t buf_size, size_t *pos_r) |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
667 { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
668 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
|
669 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
|
670 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
671 memset(buf, 0, sizeof(struct mail_index_header)); |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
672 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
673 /* try to read the whole header, but it's not necessarily an error to |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
674 read less since the older versions of the index format could be |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
675 smaller. Request reading up to buf_size, but accept if we only got |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
676 the header. */ |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
677 pos = 0; |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
678 do { |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
679 ret = pread(index->fd, PTR_OFFSET(buf, pos), |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
680 buf_size - pos, pos); |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
681 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
|
682 pos += ret; |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
683 } while (ret > 0 && pos < sizeof(struct mail_index_header)); |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
684 |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
685 *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
|
686 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
|
687 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
688 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
689 static int mail_index_read_map(struct mail_index *index, |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
690 struct mail_index_map *map, bool *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
|
691 { |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
692 const struct mail_index_header *hdr; |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
693 unsigned char buf[512]; |
1939 | 694 void *data = NULL; |
1930 | 695 ssize_t ret; |
696 size_t pos, records_size; | |
697 | |
2043
4548def7ac02
Don't try to re-map dirty memory mapping.
Timo Sirainen <tss@iki.fi>
parents:
2038
diff
changeset
|
698 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
|
699 |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
700 *retry_r = FALSE; |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
701 ret = mail_index_read_header(index, buf, sizeof(buf), &pos); |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
702 hdr = (const struct mail_index_header *)buf; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
703 |
2825
645b8442b519
one more major version change fix
Timo Sirainen <tss@iki.fi>
parents:
2824
diff
changeset
|
704 if (pos > (ssize_t)offsetof(struct mail_index_header, major_version) && |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
705 hdr->major_version != MAIL_INDEX_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
|
706 /* 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
|
707 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
|
708 } |
280c933983a9
Handle major version changes silently even if the file isn't large enough to
Timo Sirainen <tss@iki.fi>
parents:
2821
diff
changeset
|
709 |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
710 if (ret >= 0 && pos >= MAIL_INDEX_HEADER_MIN_SIZE && |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
711 (ret > 0 || pos >= hdr->base_header_size)) { |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
712 if (hdr->base_header_size < MAIL_INDEX_HEADER_MIN_SIZE || |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
713 hdr->header_size < hdr->base_header_size) { |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
714 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
|
715 "Corrupted header sizes (base %u, full %u)", |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
716 index->filepath, hdr->base_header_size, |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
717 hdr->header_size); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
718 return 0; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
719 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
720 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
721 if (pos > hdr->header_size) |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
722 pos = hdr->header_size; |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
723 |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
724 /* place the base header into memory. */ |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
725 buffer_reset(map->hdr_copy_buf); |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
726 buffer_append(map->hdr_copy_buf, buf, pos); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
727 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
728 if (pos != hdr->header_size) { |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
729 /* @UNSAFE: read the rest of the header into memory */ |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
730 data = buffer_append_space_unsafe(map->hdr_copy_buf, |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
731 hdr->header_size - |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
732 pos); |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
733 ret = pread_full(index->fd, data, |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
734 hdr->header_size - pos, pos); |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
735 } |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
736 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
737 |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
738 if (ret > 0) { |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
739 /* header read, read the records now. */ |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
740 records_size = hdr->messages_count * hdr->record_size; |
1930 | 741 |
742 if (map->buffer == NULL) { | |
743 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
|
744 records_size); |
1930 | 745 } |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
746 |
1930 | 747 /* @UNSAFE */ |
748 buffer_set_used_size(map->buffer, 0); | |
749 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
|
750 |
1930 | 751 ret = pread_full(index->fd, data, records_size, |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
752 hdr->header_size); |
1939 | 753 } |
1930 | 754 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
755 if (ret < 0) { |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
756 if (errno == ESTALE) { |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
757 /* a new index file was renamed over this one. */ |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
758 *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
|
759 return 0; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
760 } |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
761 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
|
762 return -1; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
763 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
764 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
|
765 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
|
766 "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
|
767 index->filepath); |
2824
431f677bc0b9
More rebuilding fixes with mmap_disable=yes
Timo Sirainen <tss@iki.fi>
parents:
2823
diff
changeset
|
768 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
|
769 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
770 |
1930 | 771 map->records = data; |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
772 map->records_count = hdr->messages_count; |
1930 | 773 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
774 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
|
775 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
|
776 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
777 index->sync_log_file_seq = hdr->log_file_seq; |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
778 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
|
779 return 1; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
780 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
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 static int mail_index_sync_from_transactions(struct mail_index *index, |
2913 | 783 struct mail_index_map **map, |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
784 bool sync_to_index) |
2885
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 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
|
787 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
|
788 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
|
789 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
|
790 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
|
791 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
|
792 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
|
793 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
|
794 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
|
795 size_t pos; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
796 int ret; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
797 bool skipped; |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
798 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
799 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
|
800 /* 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
|
801 synced */ |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
802 ret = mail_index_read_header(index, &hdr, sizeof(hdr), &pos); |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
803 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
|
804 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
|
805 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
|
806 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
807 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
|
808 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
|
809 |
2913 | 810 if (map_hdr->log_file_seq == hdr.log_file_seq && |
811 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
|
812 /* 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
|
813 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
|
814 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
815 |
2913 | 816 if (map_hdr->log_file_seq > hdr.log_file_seq || |
817 (map_hdr->log_file_seq == hdr.log_file_seq && | |
818 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
|
819 /* 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
|
820 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
|
821 } |
2913 | 822 if (map_hdr->log_file_ext_offset != |
823 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
|
824 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
|
825 /* 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
|
826 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
|
827 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
828 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
|
829 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
|
830 } else { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
831 /* 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
|
832 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
|
833 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
|
834 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
835 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
836 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
|
837 if (mail_transaction_log_view_set(log_view, |
2913 | 838 map_hdr->log_file_seq, |
839 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
|
840 max_seq, max_offset, |
3832
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3831
diff
changeset
|
841 MAIL_TRANSACTION_TYPE_MASK) <= 0) { |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3831
diff
changeset
|
842 /* can't use it. sync by re-reading index. */ |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
843 mail_transaction_log_view_close(&log_view); |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
844 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
|
845 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
846 |
2913 | 847 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
|
848 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
849 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
|
850 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
|
851 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
|
852 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
853 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
|
854 &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
|
855 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
|
856 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
|
857 break; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
858 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
859 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
860 |
2939
00b78082cd50
mmap_disable=yes: when we're syncing index by reading transaction log,
Timo Sirainen <tss@iki.fi>
parents:
2938
diff
changeset
|
861 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
|
862 &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
|
863 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
|
864 (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
|
865 |
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
3147
diff
changeset
|
866 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
|
867 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
|
868 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
|
869 |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
870 mail_index_sync_map_deinit(&sync_map_ctx); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
871 mail_index_view_close(&view); |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
872 mail_transaction_log_view_close(&log_view); |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
873 |
2913 | 874 *map = index->map; |
875 index->map = NULL; | |
876 | |
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
|
877 if (sync_to_index) { |
3369
b4a462cc8737
Fix to mmap_disable=yes syncing
Timo Sirainen <tss@iki.fi>
parents:
3353
diff
changeset
|
878 /* make sure we did everything right. note that although the |
b4a462cc8737
Fix to mmap_disable=yes syncing
Timo Sirainen <tss@iki.fi>
parents:
3353
diff
changeset
|
879 message counts should be equal, the flag counters may not */ |
2956 | 880 i_assert(hdr.messages_count == (*map)->hdr.messages_count); |
3369
b4a462cc8737
Fix to mmap_disable=yes syncing
Timo Sirainen <tss@iki.fi>
parents:
3353
diff
changeset
|
881 i_assert(hdr.log_file_seq == (*map)->hdr.log_file_seq); |
b4a462cc8737
Fix to mmap_disable=yes syncing
Timo Sirainen <tss@iki.fi>
parents:
3353
diff
changeset
|
882 i_assert(hdr.log_file_int_offset == (*map)->hdr.log_file_int_offset); |
b4a462cc8737
Fix to mmap_disable=yes syncing
Timo Sirainen <tss@iki.fi>
parents:
3353
diff
changeset
|
883 i_assert(hdr.log_file_ext_offset == (*map)->hdr.log_file_ext_offset); |
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
|
884 } |
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
|
885 |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
886 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
|
887 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
888 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
889 static int mail_index_read_map_with_retry(struct mail_index *index, |
2913 | 890 struct mail_index_map **map, |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
891 bool 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
|
892 { |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
893 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
|
894 unsigned int i, count; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
895 int ret; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
896 bool retry; |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
897 |
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
|
898 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
|
899 /* 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
|
900 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
|
901 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
|
902 } |
bc8ff03715b2
mmap_disable=yes: if mail_index_map() is called while syncing make sure we
Timo Sirainen <tss@iki.fi>
parents:
2937
diff
changeset
|
903 |
3177
95d2d8d5958b
Some error handling path crashfixes.
Timo Sirainen <tss@iki.fi>
parents:
3173
diff
changeset
|
904 if ((*map)->hdr.indexid != 0 && index->log != NULL) { |
95d2d8d5958b
Some error handling path crashfixes.
Timo Sirainen <tss@iki.fi>
parents:
3173
diff
changeset
|
905 /* 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
|
906 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
|
907 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
|
908 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
|
909 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
|
910 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
|
911 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
|
912 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
|
913 |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
914 /* 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
|
915 } |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
916 |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
917 /* 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
|
918 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
|
919 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
|
920 (*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
|
921 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
922 for (i = 0;; i++) { |
2913 | 923 ret = mail_index_read_map(index, *map, &retry); |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
924 if (ret != 0 || !retry || i == MAIL_INDEX_ESTALE_RETRY_COUNT) |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
925 return ret; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
926 |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
927 /* ESTALE - reopen index file */ |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
928 if (close(index->fd) < 0) |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
929 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
|
930 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
|
931 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
932 ret = mail_index_try_open_only(index); |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
933 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
|
934 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
|
935 /* 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
|
936 errno = ENOENT; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
937 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
|
938 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
939 return -1; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
940 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
941 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
942 |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
943 /* 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
|
944 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
|
945 return -1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
946 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
947 |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
948 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
|
949 { |
1946 | 950 const struct mail_index_header *hdr; |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
951 size_t used_size; |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
952 |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
953 if (MAIL_INDEX_MAP_IS_IN_MEMORY(map)) |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
954 return 0; |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
955 |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
956 hdr = map->mmap_base; |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
957 |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
958 /* always check corrupted-flag to avoid errors later */ |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
959 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
|
960 return -1; |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
961 |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
962 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
|
963 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
|
964 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
|
965 mail_index_map_copy_hdr(map, hdr); |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
966 return 1; |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
967 } |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
968 return 0; |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
969 } |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
970 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
971 int mail_index_map(struct mail_index *index, bool force) |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
972 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
973 struct mail_index_map *map; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
974 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
975 |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
976 i_assert(!index->mapping); |
2913 | 977 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
|
978 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
|
979 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
980 if (MAIL_INDEX_IS_IN_MEMORY(index)) { |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
981 if (index->map == NULL) |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
982 mail_index_create_in_memory(index, NULL); |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
983 return 1; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
984 } |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
985 |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
986 index->mapping = TRUE; |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
987 |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
988 if (!force && index->map != NULL) { |
2937 | 989 i_assert(index->hdr != NULL); |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
990 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
|
991 if (ret != 0) { |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
992 index->mapping = FALSE; |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
993 return ret; |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
994 } |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
995 |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
996 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
|
997 /* 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
|
998 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
|
999 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
|
1000 } |
2553
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
1001 } |
1fed92b6cc01
Avoid re-mmaping if not needed.
Timo Sirainen <tss@iki.fi>
parents:
2542
diff
changeset
|
1002 |
2542
c3608081d0e4
When updating index mappings, don't let it affect existing views mappings.
Timo Sirainen <tss@iki.fi>
parents:
2409
diff
changeset
|
1003 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
|
1004 /* 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
|
1005 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
|
1006 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
|
1007 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
|
1008 } else { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
1009 /* 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
|
1010 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
|
1011 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
|
1012 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
|
1013 } |
2542
c3608081d0e4
When updating index mappings, don't let it affect existing views mappings.
Timo Sirainen <tss@iki.fi>
parents:
2409
diff
changeset
|
1014 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
|
1015 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
|
1016 } else { |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
1017 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
|
1018 } |
c3608081d0e4
When updating index mappings, don't let it affect existing views mappings.
Timo Sirainen <tss@iki.fi>
parents:
2409
diff
changeset
|
1019 |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2043
diff
changeset
|
1020 if (map == NULL) { |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2043
diff
changeset
|
1021 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
|
1022 map->refcount = 1; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1023 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
|
1024 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
|
1025 } 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
|
1026 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
|
1027 } else if (map->mmap_base != NULL) { |
2193 | 1028 i_assert(map->buffer == NULL); |
1946 | 1029 if (munmap(map->mmap_base, map->mmap_size) < 0) |
1030 mail_index_set_syscall_error(index, "munmap()"); | |
1031 map->mmap_base = NULL; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1032 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1033 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1034 index->hdr = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1035 index->map = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1036 |
2823
43bab10e060d
Rebuild broken index files with mmap_disabled=yes too..
Timo Sirainen <tss@iki.fi>
parents:
2822
diff
changeset
|
1037 if (!index->mmap_disable) |
43bab10e060d
Rebuild broken index files with mmap_disabled=yes too..
Timo Sirainen <tss@iki.fi>
parents:
2822
diff
changeset
|
1038 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
|
1039 else |
2913 | 1040 ret = mail_index_read_map_with_retry(index, &map, force); |
2937 | 1041 i_assert(index->map == NULL); |
1042 | |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
1043 if (ret > 0) { |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
1044 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
|
1045 if (ret < 0) |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
1046 ret = 0; |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
1047 else if (ret == 0) { |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
1048 index->fsck = TRUE; |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
1049 ret = 1; |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
1050 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1051 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1052 |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
1053 if (ret <= 0) { |
3831 | 1054 mail_index_map_clear(index, map); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1055 mail_index_unmap(index, &map); |
3179
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
1056 index->mapping = FALSE; |
c620532e7bc8
Assert if mail_index_map() is called recursively.
Timo Sirainen <tss@iki.fi>
parents:
3177
diff
changeset
|
1057 return ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1058 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1059 |
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
|
1060 index->hdr = &map->hdr; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1061 index->map = map; |
2937 | 1062 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
|
1063 index->mapping = FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1064 return 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1065 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1066 |
3296
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1067 int mail_index_get_latest_header(struct mail_index *index, |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1068 struct mail_index_header *hdr_r) |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1069 { |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1070 size_t pos; |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1071 unsigned int i; |
3296
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1072 int ret; |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1073 |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1074 if (!index->mmap_disable) { |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1075 ret = mail_index_map(index, FALSE); |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1076 if (ret > 0) |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1077 *hdr_r = *index->hdr; |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1078 else |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1079 memset(hdr_r, 0, sizeof(*hdr_r)); |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1080 return ret; |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1081 } |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1082 |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1083 for (i = 0;; i++) { |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1084 ret = mail_index_read_header(index, hdr_r, sizeof(*hdr_r), |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1085 &pos); |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1086 if (ret >= 0 || errno != ESTALE || |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1087 i == MAIL_INDEX_ESTALE_RETRY_COUNT) |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1088 break; |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1089 |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1090 /* ESTALE - reopen index file */ |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1091 if (close(index->fd) < 0) |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1092 mail_index_set_syscall_error(index, "close()"); |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1093 index->fd = -1; |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1094 |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1095 ret = mail_index_try_open_only(index); |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1096 if (ret <= 0) { |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1097 if (ret == 0) { |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1098 /* the file was lost */ |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1099 errno = ENOENT; |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1100 mail_index_set_syscall_error(index, "open()"); |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1101 } |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1102 return -1; |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1103 } |
3296
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1104 } |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1105 return ret; |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1106 } |
c2b8904dc21b
mmap_disable=yes: Transaction log might have been rotated before everything
Timo Sirainen <tss@iki.fi>
parents:
3294
diff
changeset
|
1107 |
2114
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
1108 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
|
1109 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
|
1110 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1111 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
|
1112 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
|
1113 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
|
1114 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
|
1115 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
|
1116 unsigned int i, count; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1117 |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1118 size = map->records_count * new_record_size; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1119 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1120 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
|
1121 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
|
1122 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
|
1123 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
|
1124 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
|
1125 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
|
1126 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
|
1127 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
|
1128 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
|
1129 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
|
1130 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
|
1131 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
|
1132 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
|
1133 } |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1134 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1135 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1136 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
|
1137 mem_map->records_count = map->records_count; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1138 |
2708
f1e9f3ec8135
Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents:
2683
diff
changeset
|
1139 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
|
1140 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
|
1141 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
|
1142 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
|
1143 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
|
1144 &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
|
1145 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
|
1146 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
|
1147 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
|
1148 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
|
1149 |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1150 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
|
1151 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
|
1152 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
|
1153 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
|
1154 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
|
1155 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
|
1156 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
1157 /* copy extensions */ |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1158 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
|
1159 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
|
1160 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
|
1161 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1162 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
|
1163 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
|
1164 |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1165 /* 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
|
1166 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
|
1167 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
|
1168 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
|
1169 extensions[i].name); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1170 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1171 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1172 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1173 return mem_map; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1174 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1175 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
1176 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
|
1177 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
|
1178 { |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1179 const uint32_t *id; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1180 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1181 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
|
1182 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
|
1183 return 0; |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1184 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
1185 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
|
1186 *idx_r = *id; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1187 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
|
1188 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1189 |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1190 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
|
1191 { |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1192 i_assert(!MAIL_INDEX_IS_IN_MEMORY(index)); |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1193 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1194 /* Note that our caller must close index->fd by itself. |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1195 mail_index_reopen() for example wants to revert back to old |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1196 index file if opening the new one fails. */ |
4071
cd3d26cf124a
Renamed safe-open.* to nfs-workarounds.*, safe_open() to nfs_safe_open() and
Timo Sirainen <tss@iki.fi>
parents:
4067
diff
changeset
|
1197 index->fd = nfs_safe_open(index->filepath, O_RDWR); |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1198 index->readonly = FALSE; |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1199 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1200 if (index->fd == -1 && errno == EACCES) { |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1201 index->fd = open(index->filepath, O_RDONLY); |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1202 index->readonly = TRUE; |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1203 } |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1204 |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1205 if (index->fd == -1) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1206 if (errno != ENOENT) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1207 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
|
1208 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1209 /* have to create it */ |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1210 return 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1211 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1212 return 1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1213 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1214 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1215 static int |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1216 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
|
1217 { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1218 unsigned int lock_id; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1219 int ret; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1220 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1221 i_assert(index->fd == -1); |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1222 |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1223 if (lock_id_r != NULL) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1224 *lock_id_r = 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1225 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1226 if (MAIL_INDEX_IS_IN_MEMORY(index)) |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1227 return 0; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1228 |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1229 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
|
1230 if (ret <= 0) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1231 return ret; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1232 |
2409 | 1233 if (mail_index_lock_shared(index, FALSE, &lock_id) < 0) { |
1234 (void)close(index->fd); | |
1235 index->fd = -1; | |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1236 return -1; |
2409 | 1237 } |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1238 ret = mail_index_map(index, FALSE); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1239 if (ret == 0) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1240 /* it's corrupted - recreate it */ |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1241 mail_index_unlock(index, lock_id); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1242 if (lock_id_r != NULL) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1243 *lock_id_r = 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1244 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1245 (void)close(index->fd); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1246 index->fd = -1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1247 } else { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1248 if (lock_id_r != NULL) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1249 *lock_id_r = lock_id; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1250 else |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1251 mail_index_unlock(index, lock_id); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1252 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1253 return ret; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1254 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1255 |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1256 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
|
1257 const struct mail_index_header *hdr) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1258 { |
2240
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1259 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
|
1260 |
51719889ffcf
Record size is allowed to change between index files. This will allow adding
Timo Sirainen <tss@iki.fi>
parents:
2209
diff
changeset
|
1261 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
|
1262 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1263 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
|
1264 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
|
1265 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
|
1266 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
|
1267 index->map->hdr = *hdr; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1268 } else { |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1269 if (!MAIL_INDEX_IS_IN_MEMORY(index)) { |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1270 if (pwrite_full(index->fd, hdr, hdr_size, 0) < 0) { |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1271 mail_index_set_syscall_error(index, |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1272 "pwrite_full()"); |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1273 return -1; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1274 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1275 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1276 |
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
|
1277 index->map->hdr = *hdr; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1278 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
|
1279 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1280 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1281 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1282 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1283 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1284 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
|
1285 { |
2879
aa93c7216722
dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
1286 mode_t old_mask; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1287 const char *path; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1288 int fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1289 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1290 i_assert(!MAIL_INDEX_IS_IN_MEMORY(index)); |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1291 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1292 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
|
1293 old_mask = umask(0); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1294 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
|
1295 umask(old_mask); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1296 if (fd == -1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1297 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
|
1298 |
2879
aa93c7216722
dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
1299 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
|
1300 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
|
1301 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1302 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1303 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1304 return fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1305 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1306 |
1942 | 1307 static int mail_index_create(struct mail_index *index, |
1308 struct mail_index_header *hdr) | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1309 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1310 const char *path; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1311 uint32_t seq; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1312 uoff_t offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1313 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1314 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1315 i_assert(!MAIL_INDEX_IS_IN_MEMORY(index)); |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1316 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
|
1317 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1318 /* log file lock protects index creation */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1319 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
|
1320 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1321 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1322 ret = mail_index_try_open(index, NULL); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1323 if (ret != 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1324 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
|
1325 return ret < 0 ? -1 : 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1326 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1327 |
3582
bfa542369fdc
When creating a new index file, mark its log offsets so that the possibly
Timo Sirainen <tss@iki.fi>
parents:
3556
diff
changeset
|
1328 /* mark the existing log file as synced */ |
bfa542369fdc
When creating a new index file, mark its log offsets so that the possibly
Timo Sirainen <tss@iki.fi>
parents:
3556
diff
changeset
|
1329 hdr->log_file_seq = seq; |
bfa542369fdc
When creating a new index file, mark its log offsets so that the possibly
Timo Sirainen <tss@iki.fi>
parents:
3556
diff
changeset
|
1330 hdr->log_file_int_offset = offset; |
bfa542369fdc
When creating a new index file, mark its log offsets so that the possibly
Timo Sirainen <tss@iki.fi>
parents:
3556
diff
changeset
|
1331 hdr->log_file_ext_offset = offset; |
bfa542369fdc
When creating a new index file, mark its log offsets so that the possibly
Timo Sirainen <tss@iki.fi>
parents:
3556
diff
changeset
|
1332 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1333 /* create it fully in index.tmp first */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1334 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
|
1335 if (index->fd == -1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1336 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1337 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
|
1338 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
|
1339 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1340 } else { |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1341 index->lock_type = F_WRLCK; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1342 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
|
1343 index->lock_type = F_UNLCK; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1344 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1345 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1346 if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1347 /* 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
|
1348 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
|
1349 mail_index_set_error(index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1350 "Newly created index file is corrupted: %s", path); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1351 ret = -1; |
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 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1354 if (ret < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1355 if (unlink(path) < 0 && errno != ENOENT) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1356 mail_index_file_set_syscall_error(index, path, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1357 "unlink()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1358 } |
2170 | 1359 } else { |
1360 /* make it visible to others */ | |
1361 if (rename(path, index->filepath) < 0) { | |
1362 mail_index_set_error(index, "rename(%s, %s) failed: %m", | |
1363 path, index->filepath); | |
1364 ret = -1; | |
1365 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1366 } |
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 mail_transaction_log_sync_unlock(index->log); |
2170 | 1369 return ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1370 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1371 |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1372 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
|
1373 { |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1374 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
|
1375 |
3105 | 1376 i_assert((sizeof(*hdr) % sizeof(uint64_t)) == 0); |
1377 | |
2073
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1378 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
|
1379 |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1380 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
|
1381 hdr->minor_version = MAIL_INDEX_MINOR_VERSION; |
2116 | 1382 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
|
1383 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
|
1384 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
|
1385 |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1386 #ifndef WORDS_BIGENDIAN |
3819
61f0e1fe9b55
Moved uoff_t and time_t compatibility checks to cache file, since they're
Timo Sirainen <tss@iki.fi>
parents:
3818
diff
changeset
|
1387 hdr->compat_flags |= MAIL_INDEX_COMPAT_LITTLE_ENDIAN; |
2073
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1388 #endif |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1389 |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1390 hdr->indexid = now; |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1391 |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1392 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
|
1393 } |
a58c51c8f37b
Don't complain about transaction log indexid changes when rebuilding index.
Timo Sirainen <tss@iki.fi>
parents:
2063
diff
changeset
|
1394 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1395 static void mail_index_create_in_memory(struct mail_index *index, |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1396 const struct mail_index_header *hdr) |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1397 { |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1398 struct mail_index_header tmp_hdr; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1399 struct mail_index_map tmp_map; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1400 |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1401 if (hdr == NULL) { |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1402 mail_index_header_init(&tmp_hdr); |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1403 hdr = &tmp_hdr; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1404 } |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1405 |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1406 memset(&tmp_map, 0, sizeof(tmp_map)); |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1407 tmp_map.hdr = *hdr; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1408 tmp_map.hdr_base = hdr; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1409 |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1410 /* a bit kludgy way to do this, but it initializes everything |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1411 nicely and correctly */ |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1412 index->map = mail_index_map_clone(&tmp_map, hdr->record_size); |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1413 index->hdr = &index->map->hdr; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1414 } |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1415 |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1416 /* returns -1 = error, 0 = won't create, 1 = ok */ |
1942 | 1417 static int mail_index_open_files(struct mail_index *index, |
1418 enum mail_index_open_flags flags) | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1419 { |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1420 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
|
1421 unsigned int lock_id = 0; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
1422 int ret; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
1423 bool created = FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1424 |
1935
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1930
diff
changeset
|
1425 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
|
1426 if (ret > 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1427 hdr = *index->hdr; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1428 else if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1429 /* doesn't exist, or corrupted */ |
3912
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
1430 if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0 && |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
1431 !MAIL_INDEX_IS_IN_MEMORY(index)) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1432 return 0; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
1433 mail_index_header_init(&hdr); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1434 index->hdr = &hdr; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1435 } else if (ret < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1436 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1437 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1438 index->indexid = hdr.indexid; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1439 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1440 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
|
1441 if (index->log == NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1442 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
|
1443 |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1444 if (index->fd == -1) { |
3556 | 1445 if (index->indexid != hdr.indexid) { |
1446 /* looks like someone else created the transaction log | |
1447 before we had the chance. use its indexid so we | |
1448 don't try to create conflicting ones. */ | |
1449 hdr.indexid = index->indexid; | |
1450 } | |
1451 | |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1452 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
|
1453 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
|
1454 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
|
1455 } |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1456 if (!MAIL_INDEX_IS_IN_MEMORY(index)) { |
3833
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
1457 if (mail_index_create(index, &hdr) < 0) { |
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
1458 /* fallback to in-memory index */ |
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
1459 mail_index_move_to_memory(index); |
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
1460 mail_index_create_in_memory(index, &hdr); |
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
1461 } |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1462 } else { |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1463 mail_index_create_in_memory(index, &hdr); |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1464 } |
3129
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3105
diff
changeset
|
1465 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
|
1466 } |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1467 |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1468 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
|
1469 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
|
1470 return -1; |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1471 |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1472 } |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1473 |
3129
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3105
diff
changeset
|
1474 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
|
1475 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
|
1476 |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1477 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
|
1478 return 1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1479 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1480 |
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
|
1481 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
|
1482 enum mail_index_lock_method lock_method) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1483 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1484 int i = 0, ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1485 |
2926
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1486 if (index->opened) { |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1487 if (index->hdr != NULL && |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1488 (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
|
1489 /* corrupted, reopen files */ |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1490 mail_index_close(index); |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1491 } else { |
4067
96ae9c096bde
mail_index_open(): If index is already open, return 1 instead of 0 so the
Timo Sirainen <tss@iki.fi>
parents:
4053
diff
changeset
|
1492 return 1; |
2926
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1493 } |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
1494 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1495 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1496 index->filepath = MAIL_INDEX_IS_IN_MEMORY(index) ? |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1497 i_strdup("(in-memory index)") : |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1498 i_strconcat(index->dir, "/", index->prefix, NULL); |
1967 | 1499 |
3824
3e756ea0474b
Comment updates, small cleanups and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
3819
diff
changeset
|
1500 for (;;) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1501 index->shared_lock_count = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1502 index->excl_lock_count = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1503 index->lock_type = F_UNLCK; |
2021 | 1504 index->lock_id = 2; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1505 |
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
|
1506 index->readonly = FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1507 index->nodiskspace = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1508 index->index_lock_timeout = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1509 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
|
1510 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
|
1511 (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
|
1512 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
|
1513 (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
|
1514 index->lock_method = lock_method; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1515 |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1516 /* 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
|
1517 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
|
1518 if (lock_method == MAIL_INDEX_LOCK_DOTLOCK && |
0e1481357fbb
Changed assert() to friendly human readable message.
Timo Sirainen <tss@iki.fi>
parents:
2939
diff
changeset
|
1519 !index->mmap_disable) { |
0e1481357fbb
Changed assert() to friendly human readable message.
Timo Sirainen <tss@iki.fi>
parents:
2939
diff
changeset
|
1520 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
|
1521 "combination isn't supported. " |
0e1481357fbb
Changed assert() to friendly human readable message.
Timo Sirainen <tss@iki.fi>
parents:
2939
diff
changeset
|
1522 "You don't _really_ want it anyway."); |
0e1481357fbb
Changed assert() to friendly human readable message.
Timo Sirainen <tss@iki.fi>
parents:
2939
diff
changeset
|
1523 } |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1524 |
1942 | 1525 ret = mail_index_open_files(index, flags); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1526 if (ret <= 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1527 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1528 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1529 index->opened = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1530 if (index->fsck) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1531 index->fsck = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1532 ret = mail_index_fsck(index); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1533 if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1534 /* completely broken, reopen */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1535 if (i++ < 3) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1536 continue; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1537 /* too many tries */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1538 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1539 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1540 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1541 break; |
3824
3e756ea0474b
Comment updates, small cleanups and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
3819
diff
changeset
|
1542 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1543 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1544 if (ret <= 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1545 mail_index_close(index); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1546 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1547 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1548 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1549 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1550 void mail_index_close(struct mail_index *index) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1551 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1552 if (index->log != NULL) |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1553 mail_transaction_log_close(&index->log); |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1554 if (index->map != NULL) |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1555 mail_index_unmap(index, &index->map); |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1556 if (index->cache != NULL) |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1557 mail_cache_free(&index->cache); |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
1558 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1559 if (index->fd != -1) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1560 if (close(index->fd) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1561 mail_index_set_syscall_error(index, "close()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1562 index->fd = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1563 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1564 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1565 i_free_and_null(index->copy_lock_path); |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1566 i_free_and_null(index->filepath); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1567 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1568 index->indexid = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1569 index->opened = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1570 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1571 |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1572 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
|
1573 { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1574 struct mail_index_map *old_map; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1575 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
|
1576 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
|
1577 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1578 i_assert(!MAIL_INDEX_IS_IN_MEMORY(index)); |
4026
20c335412d7d
Added some locking related asserts, comments and when replacing index file, open it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4023
diff
changeset
|
1579 i_assert(index->copy_lock_path == NULL || index->excl_lock_count == 0); |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1580 |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1581 old_map = index->map; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1582 old_fd = index->fd; |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1583 old_map->refcount++; |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1584 |
3551
65dc45982df9
Removed fcntl() text from some locking error messages, because if
Timo Sirainen <tss@iki.fi>
parents:
3550
diff
changeset
|
1585 /* new file, new locks. the old fd can keep its locks, they don't |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1586 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
|
1587 old_lock_type = index->lock_type; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1588 old_lock_id = index->lock_id; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1589 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
|
1590 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1591 if (index->lock_type == F_RDLCK) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1592 index->lock_type = F_UNLCK; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1593 index->lock_id += 2; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1594 index->shared_lock_count = 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1595 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1596 if (fd != -1) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1597 index->fd = fd; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1598 ret = 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1599 } else { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1600 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
|
1601 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
|
1602 if (ret > 0) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1603 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
|
1604 else if (ret == 0) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1605 /* index file is lost */ |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1606 ret = -1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1607 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1608 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1609 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1610 if (ret == 0) { |
2895
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1611 /* 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
|
1612 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
|
1613 by reading transaction log. */ |
51be21fc2c9d
Avoid re-reading index file with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
1614 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
|
1615 ret = -1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1616 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1617 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1618 if (lock_id != 0) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1619 mail_index_unlock(index, lock_id); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1620 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1621 if (ret == 0) { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1622 mail_index_unmap(index, &old_map); |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1623 if (close(old_fd) < 0) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1624 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
|
1625 } else { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1626 if (index->map != NULL) |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1627 mail_index_unmap(index, &index->map); |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1628 if (index->fd != -1) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1629 if (close(index->fd) < 0) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1630 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
|
1631 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1632 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1633 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
|
1634 index->hdr = &index->map->hdr; |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1635 index->fd = old_fd; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1636 index->lock_type = old_lock_type; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1637 index->lock_id = old_lock_id; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1638 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
|
1639 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1640 return ret; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1641 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1642 |
2936
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1643 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
|
1644 { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1645 struct stat st1, st2; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1646 |
4026
20c335412d7d
Added some locking related asserts, comments and when replacing index file, open it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4023
diff
changeset
|
1647 i_assert(index->copy_lock_path == NULL); |
20c335412d7d
Added some locking related asserts, comments and when replacing index file, open it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4023
diff
changeset
|
1648 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1649 if (MAIL_INDEX_IS_IN_MEMORY(index)) |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1650 return 0; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1651 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1652 if (fstat(index->fd, &st1) < 0) { |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1653 if (errno == ESTALE) { |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1654 /* deleted, reopen */ |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1655 if (mail_index_reopen(index, -1) < 0) |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1656 return -1; |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1657 return 1; |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1658 } |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1659 return mail_index_set_syscall_error(index, "fstat()"); |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
1660 } |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1661 if (stat(index->filepath, &st2) < 0) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1662 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
|
1663 if (errno != ENOENT) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1664 return -1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1665 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1666 /* lost it? recreate */ |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1667 (void)mail_index_mark_corrupted(index); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1668 return -1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1669 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1670 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1671 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
|
1672 !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
|
1673 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
|
1674 return -1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1675 return 1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1676 } else { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1677 return 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1678 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1679 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
1680 |
2936
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1681 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
|
1682 { |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1683 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
|
1684 int ret; |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1685 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1686 if (MAIL_INDEX_IS_IN_MEMORY(index)) |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1687 return 0; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1688 |
2936
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1689 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
|
1690 /* 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
|
1691 have changed. */ |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1692 return 0; |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1693 } |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1694 |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1695 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
|
1696 /* 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
|
1697 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
|
1698 } |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1699 |
3555
afe8ab9072f0
When refreshing transaction log while trying to find new log file, don't
Timo Sirainen <tss@iki.fi>
parents:
3551
diff
changeset
|
1700 i_assert(!index->mapping); |
afe8ab9072f0
When refreshing transaction log while trying to find new log file, don't
Timo Sirainen <tss@iki.fi>
parents:
3551
diff
changeset
|
1701 |
2936
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1702 /* 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
|
1703 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
|
1704 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
|
1705 return -1; |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1706 |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1707 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
|
1708 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
|
1709 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
|
1710 } |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
1711 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1712 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
|
1713 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1714 return index->cache; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1715 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1716 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1717 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
|
1718 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1719 va_list va; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1720 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1721 i_free(index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1722 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1723 if (fmt == NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1724 index->error = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1725 else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1726 va_start(va, fmt); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1727 index->error = i_strdup_vprintf(fmt, va); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1728 va_end(va); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1729 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1730 i_error("%s", index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1731 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1732 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1733 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1734 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1735 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1736 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
|
1737 { |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1738 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
|
1739 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
1740 |
3833
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
1741 int mail_index_move_to_memory(struct mail_index *index) |
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
1742 { |
3911
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1743 struct mail_index_map *map; |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1744 int ret = 0; |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1745 |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1746 /* set the index as being into memory */ |
3833
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
1747 i_free_and_null(index->dir); |
3911
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1748 |
3912
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
1749 if (index->map == NULL) { |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
1750 /* mbox file was never even opened. just mark it as being in |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
1751 memory and let the caller re-open the index. */ |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
1752 i_assert(index->fd == -1); |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
1753 return -1; |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
1754 } |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
1755 |
3911
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1756 /* move index map to memory */ |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1757 map = mail_index_map_clone(index->map, index->map->hdr.record_size); |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1758 mail_index_unmap(index, &index->map); |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1759 index->map = map; |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1760 index->hdr = &map->hdr; |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1761 |
4053
94b3363165c8
If transaction log opening fails, don't crash when trying to move it to
Timo Sirainen <tss@iki.fi>
parents:
4026
diff
changeset
|
1762 if (index->log != NULL) { |
94b3363165c8
If transaction log opening fails, don't crash when trying to move it to
Timo Sirainen <tss@iki.fi>
parents:
4026
diff
changeset
|
1763 /* move transaction log to memory */ |
94b3363165c8
If transaction log opening fails, don't crash when trying to move it to
Timo Sirainen <tss@iki.fi>
parents:
4026
diff
changeset
|
1764 if (mail_transaction_log_move_to_memory(index->log) < 0) |
94b3363165c8
If transaction log opening fails, don't crash when trying to move it to
Timo Sirainen <tss@iki.fi>
parents:
4026
diff
changeset
|
1765 ret = -1; |
94b3363165c8
If transaction log opening fails, don't crash when trying to move it to
Timo Sirainen <tss@iki.fi>
parents:
4026
diff
changeset
|
1766 } |
3911
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1767 |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1768 /* close the index file. */ |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1769 if (close(index->fd) < 0) |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1770 mail_index_set_syscall_error(index, "close()"); |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1771 index->fd = -1; |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1772 |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1773 return ret; |
3833
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
1774 } |
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
1775 |
1945 | 1776 void mail_index_mark_corrupted(struct mail_index *index) |
1943 | 1777 { |
1778 struct mail_index_header hdr; | |
1779 | |
1945 | 1780 mail_index_set_inconsistent(index); |
1781 | |
1943 | 1782 if (index->readonly) |
1945 | 1783 return; |
1943 | 1784 |
1785 hdr = *index->hdr; | |
1786 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
|
1787 if (mail_index_write_base_header(index, &hdr) == 0) { |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
1788 if (!MAIL_INDEX_IS_IN_MEMORY(index) && fsync(index->fd) < 0) |
1945 | 1789 mail_index_set_syscall_error(index, "fsync()"); |
1790 } | |
1943 | 1791 } |
1792 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1793 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
|
1794 const char *function) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1795 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1796 i_assert(function != NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1797 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1798 if (ENOSPACE(errno)) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1799 index->nodiskspace = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1800 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1801 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1802 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1803 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
|
1804 function, index->filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1805 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1806 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1807 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
|
1808 const char *filepath, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1809 const char *function) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1810 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1811 i_assert(filepath != NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1812 i_assert(function != NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1813 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1814 if (ENOSPACE(errno)) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1815 index->nodiskspace = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1816 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1817 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1818 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1819 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
|
1820 function, filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1821 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1822 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1823 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
|
1824 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1825 if (index->nodiskspace) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1826 return MAIL_INDEX_ERROR_DISKSPACE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1827 if (index->error != NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1828 return MAIL_INDEX_ERROR_INTERNAL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1829 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1830 return MAIL_INDEX_ERROR_NONE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1831 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1832 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1833 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
|
1834 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1835 return index->error; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1836 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1837 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1838 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
|
1839 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1840 if (index->error != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1841 i_free(index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1842 index->error = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1843 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1844 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1845 index->nodiskspace = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1846 index->index_lock_timeout = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1847 } |
2407
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1848 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1849 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
|
1850 { |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1851 unsigned char buf[4]; |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1852 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1853 i_assert(offset < 0x40000000); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1854 i_assert((offset & 3) == 0); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1855 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1856 offset >>= 2; |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1857 buf[0] = 0x80 | ((offset & 0x0fe00000) >> 21); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1858 buf[1] = 0x80 | ((offset & 0x001fc000) >> 14); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1859 buf[2] = 0x80 | ((offset & 0x00003f80) >> 7); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1860 buf[3] = 0x80 | (offset & 0x0000007f); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1861 return *((uint32_t *) buf); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1862 } |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1863 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1864 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
|
1865 { |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1866 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
|
1867 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1868 if ((offset & 0x80808080) != 0x80808080) |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1869 return 0; |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1870 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1871 return (((uint32_t)buf[3] & 0x7f) << 2) | |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1872 (((uint32_t)buf[2] & 0x7f) << 9) | |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1873 (((uint32_t)buf[1] & 0x7f) << 16) | |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1874 (((uint32_t)buf[0] & 0x7f) << 23); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
1875 } |