dovecot: Code cleanup

dovecot at dovecot.org dovecot at dovecot.org
Sat Sep 15 10:46:29 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/950e34795fbc
changeset: 6382:950e34795fbc
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Sep 15 10:34:08 2007 +0300
description:
Code cleanup

diffstat:

1 file changed, 84 insertions(+), 69 deletions(-)
src/lib-index/mail-index-fsck.c |  153 +++++++++++++++++++++------------------

diffs (206 lines):

diff -r 3ea531c2bf63 -r 950e34795fbc src/lib-index/mail-index-fsck.c
--- a/src/lib-index/mail-index-fsck.c	Sat Sep 15 10:27:28 2007 +0300
+++ b/src/lib-index/mail-index-fsck.c	Sat Sep 15 10:34:08 2007 +0300
@@ -19,57 +19,62 @@ static void mail_index_fsck_error(struct
 }
 
 #define CHECK(field, oper) \
-	if (hdr.field oper map->hdr.field) { \
+	if (hdr->field oper map->hdr.field) { \
 		mail_index_fsck_error(index, #field" %u -> %u", \
-				      map->hdr.field, hdr.field); \
-	}
-
-static void
-mail_index_fsck_map(struct mail_index *index, struct mail_index_map *map)
-{
-	struct mail_index_header hdr;
-	struct mail_index_record *rec, *next_rec;
+				      map->hdr.field, hdr->field); \
+	}
+
+static void
+mail_index_fsck_header(struct mail_index *index, struct mail_index_map *map,
+		       struct mail_index_header *hdr)
+{
 	uint32_t file_seq;
 	uoff_t file_offset;
+
+	/* mail_index_map_check_header() has already checked that the index
+	   isn't completely broken. */
+	if (hdr->uid_validity == 0 && hdr->next_uid != 1)
+		hdr->uid_validity = ioloop_time;
+
+	mail_transaction_log_get_head(index->log, &file_seq, &file_offset);
+	if (hdr->log_file_seq < file_seq) {
+		hdr->log_file_head_offset = hdr->log_file_tail_offset =
+			sizeof(struct mail_transaction_log_header);
+	} else {
+		if (hdr->log_file_head_offset > file_offset)
+			hdr->log_file_head_offset = file_offset;
+		if (hdr->log_file_tail_offset > hdr->log_file_head_offset)
+			hdr->log_file_tail_offset = hdr->log_file_head_offset;
+	}
+	hdr->log_file_seq = file_seq;
+
+        CHECK(log_file_seq, !=);
+	if (hdr->log_file_seq == map->hdr.log_file_seq) {
+		/* don't bother complaining about these if file changed too */
+		CHECK(log_file_head_offset, !=);
+		CHECK(log_file_tail_offset, !=);
+	}
+}
+
+static void
+mail_index_fsck_records(struct mail_index *index, struct mail_index_map *map,
+			struct mail_index_header *hdr)
+{
+	struct mail_index_record *rec, *next_rec;
 	uint32_t i, last_uid;
 	bool logged_unordered_uids = FALSE, logged_zero_uids = FALSE;
 	bool records_dropped = FALSE;
 
-	mail_transaction_log_get_head(index->log, &file_seq, &file_offset);
-
-	/* Remember the log head position. If we go back in the index's head
-	   offset, ignore errors in the log up to this offset. */
-	index->fsck_log_head_file_seq = file_seq;
-	index->fsck_log_head_file_offset = file_offset;
-
-	/* mail_index_map_check_header() has already checked that the index
-	   isn't completely broken. */
-	hdr = map->hdr;
-
-	if (hdr.uid_validity == 0 && hdr.next_uid != 1)
-		hdr.uid_validity = ioloop_time;
-
-	if (hdr.log_file_seq < file_seq) {
-		hdr.log_file_head_offset = hdr.log_file_tail_offset =
-			sizeof(struct mail_transaction_log_header);
-	} else {
-		if (hdr.log_file_head_offset > file_offset)
-			hdr.log_file_head_offset = file_offset;
-		if (hdr.log_file_tail_offset > hdr.log_file_head_offset)
-			hdr.log_file_tail_offset = hdr.log_file_head_offset;
-	}
-	hdr.log_file_seq = file_seq;
-
-	hdr.messages_count = 0;
-	hdr.seen_messages_count = 0;
-	hdr.deleted_messages_count = 0;
-
-	hdr.first_unseen_uid_lowwater = 0;
-	hdr.first_deleted_uid_lowwater = 0;
+	hdr->messages_count = 0;
+	hdr->seen_messages_count = 0;
+	hdr->deleted_messages_count = 0;
+
+	hdr->first_unseen_uid_lowwater = 0;
+	hdr->first_deleted_uid_lowwater = 0;
 
 	rec = map->rec_map->records; last_uid = 0;
 	for (i = 0; i < map->rec_map->records_count; ) {
-		next_rec = PTR_OFFSET(rec, hdr.record_size);
+		next_rec = PTR_OFFSET(rec, hdr->record_size);
 		if (rec->uid <= last_uid) {
 			/* log an error once, and skip this record */
 			if (rec->uid == 0) {
@@ -88,25 +93,25 @@ mail_index_fsck_map(struct mail_index *i
 			/* not the fastest way when we're skipping lots of
 			   records, but this should happen rarely so don't
 			   bother optimizing. */
-			memmove(rec, next_rec, hdr.record_size *
+			memmove(rec, next_rec, hdr->record_size *
 				(map->rec_map->records_count - i - 1));
 			map->rec_map->records_count--;
 			records_dropped = TRUE;
 			continue;
 		}
 
-		hdr.messages_count++;
+		hdr->messages_count++;
 		if ((rec->flags & MAIL_SEEN) != 0)
-			hdr.seen_messages_count++;
+			hdr->seen_messages_count++;
 		if ((rec->flags & MAIL_DELETED) != 0)
-			hdr.deleted_messages_count++;
+			hdr->deleted_messages_count++;
 
 		if ((rec->flags & MAIL_SEEN) == 0 &&
-		    hdr.first_unseen_uid_lowwater == 0)
-			hdr.first_unseen_uid_lowwater = rec->uid;
+		    hdr->first_unseen_uid_lowwater == 0)
+			hdr->first_unseen_uid_lowwater = rec->uid;
 		if ((rec->flags & MAIL_DELETED) != 0 &&
-		    hdr.first_deleted_uid_lowwater == 0)
-			hdr.first_deleted_uid_lowwater = rec->uid;
+		    hdr->first_deleted_uid_lowwater == 0)
+			hdr->first_deleted_uid_lowwater = rec->uid;
 
 		last_uid = rec->uid;
 		rec = next_rec;
@@ -118,27 +123,20 @@ mail_index_fsck_map(struct mail_index *i
 		index->inconsistency_id++;
 	}
 
-	if (hdr.next_uid <= last_uid) {
+	if (hdr->next_uid <= last_uid) {
 		mail_index_fsck_error(index, "next_uid %u -> %u",
-				      hdr.next_uid, last_uid+1);
-		hdr.next_uid = last_uid+1;
-	}
-
-	if (hdr.first_unseen_uid_lowwater == 0)
-                hdr.first_unseen_uid_lowwater = hdr.next_uid;
-	if (hdr.first_deleted_uid_lowwater == 0)
-                hdr.first_deleted_uid_lowwater = hdr.next_uid;
-	if (hdr.first_recent_uid > hdr.next_uid)
-		hdr.first_recent_uid = hdr.next_uid;
-	if (hdr.first_recent_uid == 0)
-		hdr.first_recent_uid = 1;
-
-        CHECK(log_file_seq, !=);
-	if (hdr.log_file_seq == map->hdr.log_file_seq) {
-		/* don't bother complaining about these if file changed too */
-		CHECK(log_file_head_offset, !=);
-		CHECK(log_file_tail_offset, !=);
-	}
+				      hdr->next_uid, last_uid+1);
+		hdr->next_uid = last_uid+1;
+	}
+
+	if (hdr->first_unseen_uid_lowwater == 0)
+                hdr->first_unseen_uid_lowwater = hdr->next_uid;
+	if (hdr->first_deleted_uid_lowwater == 0)
+                hdr->first_deleted_uid_lowwater = hdr->next_uid;
+	if (hdr->first_recent_uid > hdr->next_uid)
+		hdr->first_recent_uid = hdr->next_uid;
+	if (hdr->first_recent_uid == 0)
+		hdr->first_recent_uid = 1;
 
 	CHECK(uid_validity, !=);
         CHECK(messages_count, !=);
@@ -148,6 +146,23 @@ mail_index_fsck_map(struct mail_index *i
         CHECK(first_unseen_uid_lowwater, <);
 	CHECK(first_deleted_uid_lowwater, <);
 	CHECK(first_recent_uid, !=);
+}
+
+static void
+mail_index_fsck_map(struct mail_index *index, struct mail_index_map *map)
+{
+	struct mail_index_header hdr;
+
+	/* Remember the log head position. If we go back in the index's head
+	   offset, ignore errors in the log up to this offset. */
+	mail_transaction_log_get_head(index->log,
+				      &index->fsck_log_head_file_seq,
+				      &index->fsck_log_head_file_offset);
+
+	hdr = map->hdr;
+
+	mail_index_fsck_header(index, map, &hdr);
+	mail_index_fsck_records(index, map, &hdr);
 
 	map->hdr = hdr;
 }


More information about the dovecot-cvs mailing list