mail-index.c revision bc1d1497d715cc5c820ff518f070f78c39ef6cdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (C) 2003-2004 Timo Sirainen */
46c31f64b9f0949f00b7819f45b22f2d64b2ea27Timo Sirainenstruct mail_index_module_register mail_index_module_register = { 0 };
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_index *mail_index_alloc(const char *dir, const char *prefix)
8fa41238067c854435884c459963fde6f8c6436bTimo Sirainen pool_alloconly_create(MEMPOOL_GROWING"index extension", 1024);
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen p_array_init(&index->extensions, index->extension_pool, 5);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen mail_index_ext_register(index, "keywords", 128, 2, 1);
41e1c7380edda701719d8ce1fb4d465d2ec4c84dTimo Sirainen index->keywords_pool = pool_alloconly_create("keywords", 512);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen hash_create(default_pool, index->keywords_pool, 0,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen strcase_hash, (hash_cmp_callback_t *)strcasecmp);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen index->log = mail_transaction_log_alloc(index);
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenvoid mail_index_free(struct mail_index **_index)
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainenvoid mail_index_set_permissions(struct mail_index *index,
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenuint32_t mail_index_ext_register(struct mail_index *index, const char *name,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen const struct mail_index_registered_ext *extensions;
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen unsigned int i, ext_count;
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen extensions = array_get(&index->extensions, &ext_count);
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen /* see if it's already there */
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen for (i = 0; i < ext_count; i++) {
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen rext.name = p_strdup(index->extension_pool, name);
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenvoid mail_index_register_expunge_handler(struct mail_index *index,
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen rext = array_idx_modifiable(&index->extensions, ext_id);
7d7b5c98f086ffa8ac9c90f21db17748ca607202Timo Sirainen i_assert(rext->expunge_handler == NULL || rext->expunge_handler == cb);
da985034a708db2f61394b30d117050ae6829ee5Timo Sirainen rext->expunge_handler_call_always = call_always;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenvoid mail_index_unregister_expunge_handler(struct mail_index *index,
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen rext = array_idx_modifiable(&index->extensions, ext_id);
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenvoid mail_index_register_sync_handler(struct mail_index *index, uint32_t ext_id,
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen rext = array_idx_modifiable(&index->extensions, ext_id);
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen i_assert(rext->sync_handler.callback == NULL);
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenvoid mail_index_unregister_sync_handler(struct mail_index *index,
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen rext = array_idx_modifiable(&index->extensions, ext_id);
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen i_assert(rext->sync_handler.callback != NULL);
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainenvoid mail_index_register_sync_lost_handler(struct mail_index *index,
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen array_append(&index->sync_lost_handlers, &cb, 1);
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenvoid mail_index_unregister_sync_lost_handler(struct mail_index *index,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen mail_index_sync_lost_handler_t *const *handlers;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen unsigned int i, count;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen handlers = array_get(&index->sync_lost_handlers, &count);
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen for (i = 0; i < count; i++) {
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen array_delete(&index->sync_lost_handlers, i, 1);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenbool mail_index_keyword_lookup(struct mail_index *index,
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen unsigned int *idx_r)
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen /* keywords_hash keeps a name => index mapping of keywords.
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen Keywords are never removed from it, so the index values are valid
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen for the lifetime of the mail_index. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen if (hash_lookup_full(index->keywords_hash, keyword, NULL, &value)) {
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen *idx_r = POINTER_CAST_TO(value, unsigned int);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen keyword = keyword_dup = p_strdup(index->keywords_pool, keyword);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen hash_insert(index->keywords_hash, keyword_dup, POINTER_CAST(*idx_r));
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainenint mail_index_map_parse_keywords(struct mail_index *index,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen const struct mail_index_keyword_header *kw_hdr;
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen const struct mail_index_keyword_header_rec *kw_rec;
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen unsigned int i, name_area_end_offset, old_count;
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen ext_id = mail_index_map_lookup_ext(map, "keywords");
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen /* Extension header contains:
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen - struct mail_index_keyword_header
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen - struct mail_index_keyword_header_rec * keywords_count
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen - const char names[] * keywords_count
b4931fc08faa0079f32f29286f4c3abd0d8788bcTimo Sirainen i_assert(ext->hdr_offset < map->hdr.header_size);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen kw_hdr = CONST_PTR_OFFSET(map->hdr_base, ext->hdr_offset);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen name = (const char *)(kw_rec + kw_hdr->keywords_count);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen old_count = !array_is_created(&map->keyword_idx_map) ? 0 :
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen /* Keywords can only be added into same mapping. Removing requires a
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen new mapping (recreating the index file) */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* nothing changed */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* make sure the header is valid */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen mail_index_set_error(index, "Corrupted index file %s: "
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen "Keywords removed unexpectedly",
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen if ((size_t)(name - (const char *)kw_hdr) > ext->hdr_size) {
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen mail_index_set_error(index, "Corrupted index file %s: "
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen "keywords_count larger than header size",
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen name_area_end_offset = (const char *)kw_hdr + ext->hdr_size - name;
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen for (i = 0; i < kw_hdr->keywords_count; i++) {
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen if (kw_rec[i].name_offset > name_area_end_offset) {
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen mail_index_set_error(index, "Corrupted index file %s: "
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen "name_offset points outside allocated header",
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen mail_index_set_error(index, "Corrupted index file %s: "
871c7b8969e8627dc4c8b3e56fd126f948e6bce6Timo Sirainen "Keyword header doesn't end with NUL",
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* create file -> index mapping */
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen i_array_init(&map->keyword_idx_map, kw_hdr->keywords_count);
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen /* Check that existing headers are still the same. It's behind DEBUG
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen since it's pretty useless waste of CPU normally. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen for (i = 0; i < array_count(&map->keyword_idx_map); i++) {
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen const char *keyword = name + kw_rec[i].name_offset;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen const unsigned int *old_idx;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen unsigned int idx;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen old_idx = array_idx(&map->keyword_idx_map, i);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen if (!mail_index_keyword_lookup(index, keyword, FALSE, &idx) ||
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen mail_index_set_error(index, "Corrupted index file %s: "
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen "Keywords changed unexpectedly",
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen /* Register the newly seen keywords */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen const char *keyword = name + kw_rec[i].name_offset;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen unsigned int idx;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen (void)mail_index_keyword_lookup(index, keyword, TRUE, &idx);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainenconst ARRAY_TYPE(keywords) *mail_index_get_keywords(struct mail_index *index)
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen /* Make sure all the keywords are in index->keywords. It's quick to do
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen if nothing has changed. */
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen (void)mail_index_map_parse_keywords(index, index->map);
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainenint mail_index_try_open_only(struct mail_index *index)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* Note that our caller must close index->fd by itself. */
89b548af722113acb5d63dfffb44423cb60f91e4Timo Sirainen index->fd = nfs_safe_open(index->filepath, O_RDWR);
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen return mail_index_set_syscall_error(index, "open()");
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen /* have to create it */
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen unsigned int lock_id;
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen ret = mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD, &lock_id);
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen /* it's corrupted - recreate it */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen mail_index_set_syscall_error(index, "close()");
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_create_tmp_file(struct mail_index *index, const char **path_r)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen path = *path_r = t_strconcat(index->filepath, ".tmp", NULL);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen fd = open(path, O_RDWR|O_CREAT|O_TRUNC, index->mode);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen return mail_index_file_set_syscall_error(index, path, "open()");
d22390f33eedbd2413debabc0662dde5241b1aa6Timo Sirainen if (index->gid != (gid_t)-1 && fchown(fd, (uid_t)-1, index->gid) < 0) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_index_file_set_syscall_error(index, path, "fchown()");
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstatic bool mail_index_open_files(struct mail_index *index,
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen ret = mail_transaction_log_create(index->log);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen ret = created ? 0 : mail_index_try_open(index);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* doesn't exist / corrupted */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* open/create failed, fallback to in-memory indexes */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0)
f239eb76f77afcbc0bfc97c9b52b4407d1bc3fe6Timo Sirainen index->cache = created ? mail_cache_create(index) :
a53cb86b4d733d9c48ee4d285bed477c80825804Timo Sirainenint mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
0c27b881989bc2b391281650ee89a8cc4d89f5e7Timo Sirainen /* corrupted, reopen files */
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen index->filepath = MAIL_INDEX_IS_IN_MEMORY(index) ?
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen i_strconcat(index->dir, "/", index->prefix, NULL);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen (flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) != 0;
8887bf3757d51d73887dd20b1db3334d867d3817Timo Sirainen (flags & MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL) != 0;
369a1084c500a9df7448ffa9409ce32e42060bc2Timo Sirainen (flags & MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE) != 0;
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* doesn't exist and create flag not used */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* completely broken, reopen */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen if (i++ < 3) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* too many tries */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstatic void mail_index_close_file(struct mail_index *index)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_index_set_syscall_error(index, "close()");
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenvoid mail_index_close(struct mail_index *index)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenint mail_index_reopen_if_changed(struct mail_index *index)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen return mail_index_set_syscall_error(index, "fstat()");
6143fece58262865ce89b5012b73ef08f2ad6abcTimo Sirainen if (nfs_safe_stat(index->filepath, &st2) < 0) {
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen return mail_index_set_syscall_error(index, "stat()");
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen if (st1.st_ino == st2.st_ino && CMP_DEV_T(st1.st_dev, st2.st_dev)) {
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* the same file */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* new file, new locks. the old fd can keep its locks, they don't
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen matter anymore as no-one's going to modify the file. */
d30da25fb6be1f1c667d93767c9194000194b618Timo Sirainenint mail_index_refresh(struct mail_index *index)
d30da25fb6be1f1c667d93767c9194000194b618Timo Sirainen unsigned int lock_id;
d30da25fb6be1f1c667d93767c9194000194b618Timo Sirainen /* we have index exclusively locked, nothing could
d30da25fb6be1f1c667d93767c9194000194b618Timo Sirainen have changed. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen ret = mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD, &lock_id);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_cache *mail_index_get_cache(struct mail_index *index)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_set_error(struct mail_index *index, const char *fmt, ...)
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainenvoid mail_index_set_inconsistent(struct mail_index *index)
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainenint mail_index_move_to_memory(struct mail_index *index)
f4e0148e539c6dd4e12b8305ab0dd5e63c46ba67Timo Sirainen /* set the index as being into memory */
2bd96c58be42146cb84076331604cadb2994fce5Timo Sirainen index->filepath = i_strdup("(in-memory index)");
27db4ce5fe399c981e09dcf9e885a1546afd34f4Timo Sirainen /* index was never even opened. just mark it as being in
5cc772dc8b507be0bc1996b5717943ba13432e08Timo Sirainen memory and let the caller re-open the index. */
a045c3aba2610c6ed0bf1c346df1c6d8f7b9fbfdTimo Sirainen /* move index map to memory */
ccffbed92cb02c24fd717808a84138240bf1885bTimo Sirainen if (!MAIL_INDEX_MAP_IS_IN_MEMORY(index->map)) {
ae14dfd895881f9d1c6899b0c09f1a8b51447d61Timo Sirainen /* move transaction log to memory */
902222fb0928d1701f20a384b73f327b1d9a15ddTimo Sirainen mail_transaction_log_move_to_memory(index->log);
a045c3aba2610c6ed0bf1c346df1c6d8f7b9fbfdTimo Sirainen /* close the index file. */
a045c3aba2610c6ed0bf1c346df1c6d8f7b9fbfdTimo Sirainen mail_index_set_syscall_error(index, "close()");
87712707722ef7d73acb065546e61afa4455cd9eTimo Sirainenvoid mail_index_mark_corrupted(struct mail_index *index)
8d131435ba4648c8821160ec38d508c97177c715Timo Sirainen index->map->hdr.flags |= MAIL_INDEX_HDR_FLAG_CORRUPTED;
bc1d1497d715cc5c820ff518f070f78c39ef6cdcTimo Sirainen if (unlink(index->filepath) < 0 && errno != ENOENT && errno != ESTALE)
bc1d1497d715cc5c820ff518f070f78c39ef6cdcTimo Sirainen mail_index_set_syscall_error(index, "unlink()");
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_set_syscall_error(struct mail_index *index,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen return mail_index_set_error(index, "%s failed with index file %s: %m",
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_file_set_syscall_error(struct mail_index *index,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen return mail_index_set_error(index, "%s failed with file %s: %m",
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenconst char *mail_index_get_error_message(struct mail_index *index)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_reset_error(struct mail_index *index)
2b498cb82aaad8a11adb5a27a29c55b9c334a1ecTimo Sirainen/* FIXME: Unfortunately these functions were originally written to use
2b498cb82aaad8a11adb5a27a29c55b9c334a1ecTimo Sirainen endian-specific code and we can't avoid that without breaking backwards
2b498cb82aaad8a11adb5a27a29c55b9c334a1ecTimo Sirainen compatibility. When we do break it, just select one of these. */
44ff75ca53188056ff5a3e50428e3f2078800b3cTimo Sirainenuint32_t mail_index_uint32_to_offset(uint32_t offset)
2b498cb82aaad8a11adb5a27a29c55b9c334a1ecTimo Sirainen 0x00008000 | ((offset & 0x00003f80) >> 7 << 8) |
2b498cb82aaad8a11adb5a27a29c55b9c334a1ecTimo Sirainen 0x00800000 | ((offset & 0x001fc000) >> 14 << 16) |
2b498cb82aaad8a11adb5a27a29c55b9c334a1ecTimo Sirainen 0x80000000 | ((offset & 0x0fe00000) >> 21 << 24);
44ff75ca53188056ff5a3e50428e3f2078800b3cTimo Sirainenuint32_t mail_index_offset_to_uint32(uint32_t offset)
2b498cb82aaad8a11adb5a27a29c55b9c334a1ecTimo Sirainenuint32_t mail_index_uint32_to_offset(uint32_t offset)
2b498cb82aaad8a11adb5a27a29c55b9c334a1ecTimo Sirainen return 0x80000000 | ((offset & 0x0000007f) << 24) |
2b498cb82aaad8a11adb5a27a29c55b9c334a1ecTimo Sirainen 0x00800000 | ((offset & 0x00003f80) >> 7 << 16) |
2b498cb82aaad8a11adb5a27a29c55b9c334a1ecTimo Sirainen 0x00008000 | ((offset & 0x001fc000) >> 14 << 8) |