[dovecot-cvs] dovecot/src/lib-index mail-index-fsck.c,1.30,1.31
tss at dovecot.org
tss at dovecot.org
Wed Jan 17 18:45:45 UTC 2007
Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv32115
Modified Files:
mail-index-fsck.c
Log Message:
cleanup
Index: mail-index-fsck.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-fsck.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- mail-index-fsck.c 13 Jan 2006 20:26:13 -0000 1.30
+++ mail-index-fsck.c 17 Jan 2007 18:45:43 -0000 1.31
@@ -18,47 +18,65 @@
}
#define CHECK(field, oper) \
- if (hdr.field oper index->hdr->field) { \
+ if (hdr.field oper map->hdr.field) { \
mail_index_fsck_error(index, #field" %u -> %u", \
- index->hdr->field, hdr.field); \
+ map->hdr.field, hdr.field); \
}
-static int mail_index_fsck_locked(struct mail_index *index,
- const char **error_r)
+static void
+mail_index_fsck_locked(struct mail_index *index, struct mail_index_header *hdr)
+{
+ uint32_t log_seq;
+ uoff_t log_offset;
+
+ mail_transaction_log_get_head(index->log, &log_seq, &log_offset);
+
+ if (hdr->log_file_int_offset > hdr->log_file_ext_offset) {
+ mail_index_fsck_error(index,
+ "log_file_int_offset > log_file_ext_offset");
+ hdr->log_file_int_offset = hdr->log_file_ext_offset;
+ }
+
+ if ((hdr->log_file_seq == log_seq &&
+ hdr->log_file_ext_offset > log_offset) ||
+ (hdr->log_file_seq != log_seq &&
+ !mail_transaction_log_is_head_prev(index->log,
+ hdr->log_file_seq,
+ hdr->log_file_ext_offset))) {
+ mail_index_fsck_error(index,
+ "log file sync pos %u,%u -> %u, %"PRIuUOFF_T,
+ hdr->log_file_seq, hdr->log_file_ext_offset,
+ log_seq, log_offset);
+ hdr->log_file_seq = log_seq;
+ hdr->log_file_int_offset =
+ hdr->log_file_ext_offset = log_offset;
+ }
+}
+
+static int
+mail_index_fsck_map(struct mail_index *index, struct mail_index_map *map,
+ const char **error_r)
{
struct mail_index_header hdr;
const struct mail_index_record *rec;
- uint32_t i, last_uid, log_seq;
- uoff_t log_offset;
+ unsigned int records_count;
+ uint32_t i, last_uid;
*error_r = NULL;
/* locking already does the most important sanity checks for header */
- hdr = *index->hdr;
+ hdr = map->hdr;
if (hdr.uid_validity == 0 && hdr.next_uid != 1) {
*error_r = "uid_validity = 0 && next_uid != 1";
return 0;
}
- mail_transaction_log_get_head(index->log, &log_seq, &log_offset);
- if (hdr.log_file_int_offset > hdr.log_file_ext_offset) {
- mail_index_fsck_error(index,
- "log_file_int_offset > log_file_ext_offset");
- hdr.log_file_int_offset = hdr.log_file_ext_offset;
- }
- if ((hdr.log_file_seq == log_seq &&
- hdr.log_file_ext_offset > log_offset) ||
- (hdr.log_file_seq != log_seq &&
- !mail_transaction_log_is_head_prev(index->log,
- hdr.log_file_seq,
- hdr.log_file_ext_offset))) {
- mail_index_fsck_error(index,
- "log file sync pos %u,%u -> %u, %"PRIuUOFF_T,
- hdr.log_file_seq, hdr.log_file_ext_offset,
- log_seq, log_offset);
- hdr.log_file_seq = log_seq;
- hdr.log_file_int_offset = hdr.log_file_ext_offset = log_offset;
+ if (!index->log_locked)
+ records_count = map->hdr.messages_count;
+ else {
+ records_count = map->records_count;
+ mail_index_fsck_locked(index, &hdr);
}
hdr.flags &= ~MAIL_INDEX_HDR_FLAG_FSCK;
@@ -72,8 +90,8 @@
hdr.first_unseen_uid_lowwater = 0;
hdr.first_deleted_uid_lowwater = 0;
- rec = index->map->records; last_uid = 0;
- for (i = 0; i < index->map->records_count; i++) {
+ rec = map->records; last_uid = 0;
+ for (i = 0; i < map->records_count; i++) {
if (rec->uid <= last_uid) {
*error_r = "Record UIDs are not ordered";
return 0;
@@ -123,9 +141,7 @@
CHECK(first_unseen_uid_lowwater, <);
CHECK(first_deleted_uid_lowwater, <);
- if (mail_index_write_base_header(index, &hdr) < 0)
- return -1;
-
+ map->hdr = hdr;
return 1;
}
@@ -156,8 +172,14 @@
error = NULL;
ret = mail_index_map(index, TRUE);
- if (ret > 0)
- ret = mail_index_fsck_locked(index, &error);
+ if (ret > 0) {
+ ret = mail_index_fsck_map(index, index->map, &error);
+ if (ret > 0) {
+ if (mail_index_write_base_header(index,
+ &index->map->hdr) < 0)
+ ret = -1;
+ }
+ }
mail_index_unlock(index, lock_id);
if (lock_log)
More information about the dovecot-cvs
mailing list