[dovecot-cvs] dovecot/src/lib-index mail-index-fsck.c, 1.26, 1.27 mail-index-sync-update.c, 1.84, 1.85 mail-index-sync.c, 1.59, 1.60 mail-index.c, 1.199, 1.200 mail-index.h, 1.149, 1.150

cras at dovecot.org cras at dovecot.org
Fri Apr 29 15:02:36 EEST 2005


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv4557

Modified Files:
	mail-index-fsck.c mail-index-sync-update.c mail-index-sync.c 
	mail-index.c mail-index.h 
Log Message:
Check broken flag counter values every time when updating them. Added
fsck-flag to index header, if it's set do fsck when opening index and when  
syncing.



Index: mail-index-fsck.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-fsck.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- mail-index-fsck.c	5 Dec 2004 01:41:45 -0000	1.26
+++ mail-index-fsck.c	29 Apr 2005 12:02:33 -0000	1.27
@@ -40,6 +40,8 @@
 		return 0;
 	}
 
+	hdr.flags &= ~MAIL_INDEX_HDR_FLAG_FSCK;
+
 	hdr.messages_count = 0;
 	hdr.recent_messages_count = 0;
 	hdr.seen_messages_count = 0;

Index: mail-index-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-update.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- mail-index-sync-update.c	23 Apr 2005 13:28:22 -0000	1.84
+++ mail-index-sync-update.c	29 Apr 2005 12:02:33 -0000	1.85
@@ -31,14 +31,21 @@
 }
 
 static void
-mail_index_header_update_counts(struct mail_index_header *hdr,
+mail_index_header_update_counts(struct mail_index *index,
+				struct mail_index_header *hdr,
 				uint8_t old_flags, uint8_t new_flags)
 {
 	if (((old_flags ^ new_flags) & MAIL_RECENT) != 0) {
 		/* different recent-flag */
 		if ((old_flags & MAIL_RECENT) == 0)
 			hdr->recent_messages_count++;
-		else if (--hdr->recent_messages_count == 0)
+		else if (hdr->recent_messages_count == 0 ||
+			 hdr->recent_messages_count > hdr->messages_count) {
+                        hdr->flags |= MAIL_INDEX_HDR_FLAG_FSCK;
+			mail_index_set_error(index,
+				"Recent counter wrong in index file %s",
+				index->filepath);
+		} else if (--hdr->recent_messages_count == 0)
 			hdr->first_recent_uid_lowwater = hdr->next_uid;
 	}
 
@@ -46,7 +53,12 @@
 		/* different seen-flag */
 		if ((old_flags & MAIL_SEEN) != 0)
 			hdr->seen_messages_count--;
-		else if (++hdr->seen_messages_count == hdr->messages_count)
+		else if (hdr->seen_messages_count >= hdr->messages_count) {
+                        hdr->flags |= MAIL_INDEX_HDR_FLAG_FSCK;
+			mail_index_set_error(index,
+				"Seen counter wrong in index file %s",
+				index->filepath);
+		} else if (++hdr->seen_messages_count == hdr->messages_count)
 			hdr->first_unseen_uid_lowwater = hdr->next_uid;
 	}
 
@@ -54,7 +66,13 @@
 		/* different deleted-flag */
 		if ((old_flags & MAIL_DELETED) == 0)
 			hdr->deleted_messages_count++;
-		else if (--hdr->deleted_messages_count == 0)
+		else if (hdr->deleted_messages_count == 0 ||
+			 hdr->deleted_messages_count > hdr->messages_count) {
+                        hdr->flags |= MAIL_INDEX_HDR_FLAG_FSCK;
+			mail_index_set_error(index,
+				"Deleted counter wrong in index file %s",
+				index->filepath);
+		} else if (--hdr->deleted_messages_count == 0)
 			hdr->first_deleted_uid_lowwater = hdr->next_uid;
 	}
 }
@@ -125,7 +143,8 @@
 
 	for (seq = seq1; seq <= seq2; seq++) {
                 rec = MAIL_INDEX_MAP_IDX(map, seq-1);
-		mail_index_header_update_counts(&map->hdr, rec->flags, 0);
+		mail_index_header_update_counts(view->index, &map->hdr,
+						rec->flags, 0);
 	}
 
 	for (i = 0; i < expunge_handlers_count; i++) {
@@ -193,7 +212,7 @@
 	if ((rec->flags & MAIL_INDEX_MAIL_FLAG_DIRTY) != 0)
 		map->hdr.flags |= MAIL_INDEX_HDR_FLAG_HAVE_DIRTY;
 
-	mail_index_header_update_counts(&map->hdr, 0, rec->flags);
+	mail_index_header_update_counts(view->index, &map->hdr, 0, rec->flags);
 	mail_index_header_update_lowwaters(&map->hdr, rec);
 	return 1;
 }
@@ -233,7 +252,8 @@
 		old_flags = rec->flags;
 		rec->flags = (rec->flags & flag_mask) | u->add_flags;
 
-		mail_index_header_update_counts(hdr, old_flags, rec->flags);
+		mail_index_header_update_counts(view->index, hdr,
+						old_flags, rec->flags);
                 mail_index_header_update_lowwaters(hdr, rec);
 	}
 	return 1;

Index: mail-index-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- mail-index-sync.c	26 Apr 2005 18:36:48 -0000	1.59
+++ mail-index-sync.c	29 Apr 2005 12:02:33 -0000	1.60
@@ -339,6 +339,14 @@
 		}
 	}
 
+	if ((index->hdr->flags & MAIL_INDEX_HDR_FLAG_FSCK) != 0) {
+		if (mail_index_fsck(index) <= 0) {
+			mail_index_unlock(index, lock_id);
+			mail_transaction_log_sync_unlock(index->log);
+			return -1;
+		}
+	}
+
 	if (!mail_index_need_lock(index, sync_recent,
 				  log_file_seq, log_file_offset)) {
 		mail_index_unlock(index, lock_id);

Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.199
retrieving revision 1.200
diff -u -d -r1.199 -r1.200
--- mail-index.c	16 Apr 2005 22:01:11 -0000	1.199
+++ mail-index.c	29 Apr 2005 12:02:33 -0000	1.200
@@ -508,6 +508,9 @@
 		return -1;
 	}
 
+	if ((hdr->flags & MAIL_INDEX_HDR_FLAG_FSCK) != 0)
+		return 0;
+
 	if (hdr->next_uid == 0)
 		return 0;
 

Index: mail-index.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.149
retrieving revision 1.150
diff -u -d -r1.149 -r1.150
--- mail-index.h	23 Apr 2005 15:18:21 -0000	1.149
+++ mail-index.h	29 Apr 2005 12:02:34 -0000	1.150
@@ -35,7 +35,9 @@
 enum mail_index_header_flag {
 	/* Index file is corrupted, reopen or recreate it. */
 	MAIL_INDEX_HDR_FLAG_CORRUPTED		= 0x0001,
-	MAIL_INDEX_HDR_FLAG_HAVE_DIRTY		= 0x0002
+	MAIL_INDEX_HDR_FLAG_HAVE_DIRTY		= 0x0002,
+	/* fsck the index next time when opening */
+	MAIL_INDEX_HDR_FLAG_FSCK		= 0x0004
 };
 
 enum mail_index_mail_flags {



More information about the dovecot-cvs mailing list