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