changeset 6275:913b188f4dd4 HEAD

Removed explicit locking from views and maps. They were already locked all the time when they were used. Because of this change several functions can no longer fail, so they were changed to return void, and a lot of pointless error handling was removed.
author Timo Sirainen <tss@iki.fi>
date Sun, 12 Aug 2007 16:43:05 +0300
parents bd67afb92ee5
children b5a23c868935
files src/imap/cmd-append.c src/imap/cmd-select.c src/imap/imap-search.c src/imap/imap-status.c src/imap/imap-sync.c src/imap/imap-thread.c src/lib-index/mail-cache-compress.c src/lib-index/mail-cache-decisions.c src/lib-index/mail-index-map.c src/lib-index/mail-index-private.h src/lib-index/mail-index-sync-ext.c src/lib-index/mail-index-sync-keywords.c src/lib-index/mail-index-sync-update.c src/lib-index/mail-index-transaction-view.c src/lib-index/mail-index-view-private.h src/lib-index/mail-index-view-sync.c src/lib-index/mail-index-view.c src/lib-index/mail-index.h src/lib-index/mailbox-list-index-sync.c src/lib-storage/index/cydir/cydir-sync.c src/lib-storage/index/dbox/dbox-mail.c src/lib-storage/index/dbox/dbox-sync-expunge.c src/lib-storage/index/dbox/dbox-sync-full.c src/lib-storage/index/dbox/dbox-sync.c src/lib-storage/index/index-fetch.c src/lib-storage/index/index-mail.c src/lib-storage/index/index-search.c src/lib-storage/index/index-status.c src/lib-storage/index/index-storage.c src/lib-storage/index/index-storage.h src/lib-storage/index/index-sync-changes.c src/lib-storage/index/index-sync.c src/lib-storage/index/index-transaction.c src/lib-storage/index/maildir/maildir-sync-index.c src/lib-storage/index/maildir/maildir-sync.c src/lib-storage/index/mbox/mbox-sync-parse.c src/lib-storage/index/mbox/mbox-sync.c src/lib-storage/list/index-mailbox-list-sync.c src/lib-storage/list/index-mailbox-list.c src/lib-storage/mail-storage-private.h src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h src/plugins/fts-squat/fts-backend-squat.c src/plugins/fts/fts-storage.c src/plugins/lazy-expunge/lazy-expunge-plugin.c
diffstat 45 files changed, 315 insertions(+), 628 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/cmd-append.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/imap/cmd-append.c	Sun Aug 12 16:43:05 2007 +0300
@@ -441,7 +441,7 @@
 	return box;
 }
 
-static int get_keywords(struct cmd_append_context *ctx)
+static void get_keywords(struct cmd_append_context *ctx)
 {
 	struct client *client = ctx->client;
 	struct mailbox_status status;
@@ -450,10 +450,7 @@
 	   client_parse_mail_flags()'s keyword verification works.
 	   however if we're not appending to selected mailbox, we'll
 	   need to restore the keywords list. */
-	if (mailbox_get_status(ctx->box, STATUS_KEYWORDS,
-			       &status) < 0)
-		return -1;
-
+	mailbox_get_status(ctx->box, STATUS_KEYWORDS, &status);
 	if (ctx->box != client->mailbox) {
 		ctx->old_keywords = client->keywords;
 
@@ -462,7 +459,6 @@
 			pool_alloconly_create("append keywords pool", 256);
 	}
 	client_save_keywords(&client->keywords, status.keywords);
-	return 0;
 }
 
 bool cmd_append(struct client_command_context *cmd)
@@ -487,15 +483,10 @@
 	else {
 		ctx->storage = mailbox_get_storage(ctx->box);
 
-		if (get_keywords(ctx) < 0) {
-			client_send_storage_error(cmd, ctx->storage);
-			mailbox_close(&ctx->box);
-			ctx->failed = TRUE;
-		} else {
-			ctx->t = mailbox_transaction_begin(ctx->box,
+		get_keywords(ctx);
+		ctx->t = mailbox_transaction_begin(ctx->box,
 					MAILBOX_TRANSACTION_FLAG_EXTERNAL |
 					MAILBOX_TRANSACTION_FLAG_ASSIGN_UIDS);
-		}
 	}
 
 	io_remove(&client->io);
--- a/src/imap/cmd-select.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/imap/cmd-select.c	Sun Aug 12 16:43:05 2007 +0300
@@ -42,15 +42,9 @@
 		return TRUE;
 	}
 
-	if (mailbox_get_status(box, STATUS_MESSAGES | STATUS_RECENT |
-			       STATUS_FIRST_UNSEEN_SEQ | STATUS_UIDVALIDITY |
-			       STATUS_UIDNEXT | STATUS_KEYWORDS,
-			       &status) < 0) {
-		client_send_storage_error(cmd, storage);
-		mailbox_close(&box);
-		return TRUE;
-	}
-
+	mailbox_get_status(box, STATUS_MESSAGES | STATUS_RECENT |
+			   STATUS_FIRST_UNSEEN_SEQ | STATUS_UIDVALIDITY |
+			   STATUS_UIDNEXT | STATUS_KEYWORDS, &status);
 	client_save_keywords(&client->keywords, status.keywords);
 	client->messages_count = status.messages;
 	client->recent_count = status.recent;
--- a/src/imap/imap-search.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/imap/imap-search.c	Sun Aug 12 16:43:05 2007 +0300
@@ -35,15 +35,8 @@
 		}
 
 		last = seqset->seq2 == (uint32_t)-1;
-		if (mailbox_get_uids(box, seqset->seq1, seqset->seq2,
-				     &seqset->seq1, &seqset->seq2) < 0) {
-			struct mail_storage *storage = mailbox_get_storage(box);
-			enum mail_error error;
-
-			*error_r = mail_storage_get_last_error(storage, &error);
-			return -1;
-		}
-
+		mailbox_get_uids(box, seqset->seq1, seqset->seq2,
+				 &seqset->seq1, &seqset->seq2);
 		if (seqset->seq1 == 0 && last) {
 			/* we need special case for too_high_uid:* case */
 			seqset->seq1 = seqset->seq2 = (uint32_t)-1;
--- a/src/imap/imap-status.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/imap/imap-status.c	Sun Aug 12 16:43:05 2007 +0300
@@ -68,7 +68,7 @@
 	}
 
 	if (!failed)
-		failed = mailbox_get_status(box, items, status_r) < 0;
+		mailbox_get_status(box, items, status_r);
 
 	if (box != client->mailbox)
 		mailbox_close(&box);
--- a/src/imap/imap-sync.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/imap/imap-sync.c	Sun Aug 12 16:43:05 2007 +0300
@@ -50,11 +50,9 @@
 	ctx->messages_count = client->messages_count;
 
 	/* if keyword list changed, send the new list before flag changes */
-	if (mailbox_get_status(ctx->box, STATUS_KEYWORDS, &status) == 0) {
-		if (client_save_keywords(&client->keywords, status.keywords))
-			client_send_mailbox_flags(client, box, status.keywords);
-	}
-
+	mailbox_get_status(ctx->box, STATUS_KEYWORDS, &status);
+	if (client_save_keywords(&client->keywords, status.keywords))
+		client_send_mailbox_flags(client, box, status.keywords);
 	return ctx;
 }
 
--- a/src/imap/imap-thread.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/imap/imap-thread.c	Sun Aug 12 16:43:05 2007 +0300
@@ -688,10 +688,8 @@
 
 		if (!ctx->id_is_uid)
 			seq = id;
-		else {
-			if (mailbox_get_uids(ctx->box, id, id, &seq, &seq) < 0)
-				seq = 0;
-		}
+		else
+			mailbox_get_uids(ctx->box, id, id, &seq, &seq);
 
 		if (seq != 0 && mail_set_seq(ctx->mail, seq) == 0) {
 			t_push();
--- a/src/lib-index/mail-cache-compress.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mail-cache-compress.c	Sun Aug 12 16:43:05 2007 +0300
@@ -129,10 +129,9 @@
 		first_new_seq = 1;
 		message_count = mail_index_view_get_messages_count(view);
 	} else {
-		if (mail_index_lookup_uid_range(view, idx_hdr->day_first_uid[7],
-						(uint32_t)-1, &first_new_seq,
-						&message_count) < 0)
-			return -1;
+		mail_index_lookup_uid_range(view, idx_hdr->day_first_uid[7],
+					    (uint32_t)-1, &first_new_seq,
+					    &message_count);
 		if (first_new_seq == 0)
 			first_new_seq = message_count+1;
 	}
--- a/src/lib-index/mail-cache-decisions.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mail-cache-decisions.c	Sun Aug 12 16:43:05 2007 +0300
@@ -87,8 +87,7 @@
 	}
 
 	/* see if we want to change decision from TEMP to YES */
-	if (mail_index_lookup_uid(view->view, seq, &uid) < 0)
-		return;
+	mail_index_lookup_uid(view->view, seq, &uid);
 	hdr = mail_index_get_header(view->view);
 
 	if (ioloop_time - cache->fields[field].last_used > 3600*24) {
@@ -136,6 +135,6 @@
 	cache->fields[field].decision_dirty = TRUE;
 	cache->field_header_write_pending = TRUE;
 
-	if (mail_index_lookup_uid(view->view, seq, &uid) == 0)
-		cache->fields[field].uid_highwater = uid;
+	mail_index_lookup_uid(view->view, seq, &uid);
+	cache->fields[field].uid_highwater = uid;
 }
--- a/src/lib-index/mail-index-map.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mail-index-map.c	Sun Aug 12 16:43:05 2007 +0300
@@ -673,8 +673,6 @@
 	new_map = mail_index_map_alloc(index);
 	if (use_mmap) {
 		new_map->rec_map->lock_id = lock_id;
-		new_map->rec_map->lock_count++;
-		new_map->locked = TRUE;
 		ret = mail_index_mmap(new_map, file_size);
 	} else {
 		ret = mail_index_read_map(new_map, file_size);
@@ -751,6 +749,9 @@
 static void mail_index_record_map_free(struct mail_index_map *map,
 				       struct mail_index_record_map *rec_map)
 {
+	if (rec_map->lock_id != 0)
+		mail_index_unlock(map->index, &rec_map->lock_id);
+
 	if (rec_map->buffer != NULL) {
 		i_assert(rec_map->mmap_base == NULL);
 		buffer_free(rec_map->buffer);
@@ -791,7 +792,6 @@
 		return;
 
 	i_assert(map->refcount == 0);
-	mail_index_map_unlock(map);
 	mail_index_record_map_unlink(map);
 
 	if (map->extension_pool != NULL)
@@ -802,35 +802,6 @@
 	i_free(map);
 }
 
-int mail_index_map_lock(struct mail_index_map *map)
-{
-	if (map->locked)
-		return 0;
-
-	if (map->rec_map->lock_id != 0 || MAIL_INDEX_MAP_IS_IN_MEMORY(map)) {
-		map->rec_map->lock_count++;
-		map->locked = TRUE;
-		return 0;
-	}
-
-	if (mail_index_lock_shared(map->index, &map->rec_map->lock_id) < 0)
-		return -1;
-
-	mail_index_map_copy_hdr(map, map->rec_map->mmap_base);
-	map->rec_map->lock_count++;
-	map->locked = TRUE;
-	return 0;
-}
-
-void mail_index_map_unlock(struct mail_index_map *map)
-{
-	if (!map->locked)
-		return;
-
-	if (--map->rec_map->lock_count == 0)
-		mail_index_unlock(map->index, &map->rec_map->lock_id);
-}
-
 static void mail_index_map_copy_records(struct mail_index_record_map *dest,
 					const struct mail_index_record_map *src,
 					unsigned int record_size)
@@ -946,7 +917,6 @@
 	mail_index_map_copy_records(new_map, map->rec_map,
 				    map->hdr.record_size);
 
-	mail_index_map_unlock(map);
 	mail_index_record_map_unlink(map);
 	map->rec_map = new_map;
 }
@@ -967,11 +937,11 @@
 				    map->hdr.record_size);
 	mail_index_map_copy_header(map, map);
 
-	mail_index_map_unlock(map);
 	if (new_map != map->rec_map) {
 		mail_index_record_map_unlink(map);
 		map->rec_map = new_map;
-	} else if (new_map->mmap_base != NULL) {
+	} else {
+		mail_index_unlock(map->index, &new_map->lock_id);
 		if (munmap(new_map->mmap_base, new_map->mmap_size) < 0)
 			mail_index_set_syscall_error(map->index, "munmap()");
 		new_map->mmap_base = NULL;
--- a/src/lib-index/mail-index-private.h	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mail-index-private.h	Sun Aug 12 16:43:05 2007 +0300
@@ -108,8 +108,6 @@
 
 	void *mmap_base;
 	size_t mmap_size, mmap_used_size;
-
-	unsigned int lock_count;
 	unsigned int lock_id;
 
 	buffer_t *buffer;
@@ -141,7 +139,6 @@
 
 	struct mail_index_record_map *rec_map;
 
-	unsigned int locked:1;
 	unsigned int keywords_read:1;
 	unsigned int write_base_header:1;
 	unsigned int write_ext_header:1;
@@ -273,11 +270,6 @@
 /* Unreference given mapping and unmap it if it's dropped to zero. */
 void mail_index_unmap(struct mail_index_map **map);
 
-/* Lock the map if the data is mmaped and map is unlocked. */
-int mail_index_map_lock(struct mail_index_map *map);
-/* Unlock the map if it's locked. */
-void mail_index_map_unlock(struct mail_index_map *map);
-
 /* Clone a map. The returned map is always in memory. */
 struct mail_index_map *mail_index_map_clone(const struct mail_index_map *map);
 void mail_index_record_map_move_to_private(struct mail_index_map *map);
--- a/src/lib-index/mail-index-sync-ext.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mail-index-sync-ext.c	Sun Aug 12 16:43:05 2007 +0300
@@ -517,9 +517,7 @@
 	i_assert(ctx->cur_ext_id != (uint32_t)-1);
 	i_assert(!ctx->cur_ext_ignore);
 
-	if (mail_index_lookup_uid_range(view, u->uid, u->uid, &seq, &seq) < 0)
-		return -1;
-
+	mail_index_lookup_uid_range(view, u->uid, u->uid, &seq, &seq);
 	if (seq == 0)
 		return 1;
 
--- a/src/lib-index/mail-index-sync-keywords.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mail-index-sync-keywords.c	Sun Aug 12 16:43:05 2007 +0300
@@ -208,9 +208,7 @@
 
 	i_assert(keyword_idx != (unsigned int)-1);
 
-	if (mail_index_lookup_uid_range(view, uid1, uid2, &seq1, &seq2) < 0)
-		return -1;
-
+	mail_index_lookup_uid_range(view, uid1, uid2, &seq1, &seq2);
 	if (seq1 == 0)
 		return 1;
 
@@ -326,9 +324,8 @@
 	ext = array_idx(&map->extensions, ext_id);
 	end = CONST_PTR_OFFSET(r, hdr->size);
 	for (; r != end; r++) {
-		if (mail_index_lookup_uid_range(ctx->view, r->uid1, r->uid2,
-						&seq1, &seq2) < 0)
-			return -1;
+		mail_index_lookup_uid_range(ctx->view, r->uid1, r->uid2,
+					    &seq1, &seq2);
 		if (seq1 == 0)
 			continue;
 
--- a/src/lib-index/mail-index-sync-update.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mail-index-sync-update.c	Sun Aug 12 16:43:05 2007 +0300
@@ -230,9 +230,8 @@
 	unsigned int i;
 
 	for (i = 0; i < count; i++, e++) {
-		if (mail_index_lookup_uid_range(ctx->view, e->uid1, e->uid2,
-						&seq1, &seq2) < 0)
-			return -1;
+		mail_index_lookup_uid_range(ctx->view, e->uid1, e->uid2,
+					    &seq1, &seq2);
 		if (seq1 == 0) {
 			/* everything expunged already */
 			continue;
@@ -343,10 +342,7 @@
 	uint8_t flag_mask, old_flags;
 	uint32_t idx, seq1, seq2;
 
-	if (mail_index_lookup_uid_range(view, u->uid1, u->uid2,
-					&seq1, &seq2) < 0)
-		return -1;
-
+	mail_index_lookup_uid_range(view, u->uid1, u->uid2, &seq1, &seq2);
 	if (seq1 == 0)
 		return 1;
 
@@ -686,9 +682,6 @@
 
 	i_assert(index->map == map || type == MAIL_INDEX_SYNC_HANDLER_VIEW);
 
-	if (mail_index_map_lock(map) < 0)
-		return -1;
-
 	if (!force) {
 		/* see if we'd prefer to reopen the index file instead of
 		   syncing the current map from the transaction log */
--- a/src/lib-index/mail-index-transaction-view.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mail-index-transaction-view.c	Sun Aug 12 16:43:05 2007 +0300
@@ -86,46 +86,42 @@
 
 }
 
-static int _tview_lookup_uid(struct mail_index_view *view, uint32_t seq,
-			     uint32_t *uid_r)
+static void _tview_lookup_uid(struct mail_index_view *view, uint32_t seq,
+			      uint32_t *uid_r)
 {
 	struct mail_index_view_transaction *tview =
 		(struct mail_index_view_transaction *)view;
 
-	if (seq >= tview->t->first_new_seq) {
+	if (seq >= tview->t->first_new_seq)
 		*uid_r = mail_index_transaction_lookup(tview->t, seq)->uid;
-		return 0;
-	} else {
-		return tview->super->lookup_uid(view, seq, uid_r);
-	}
+	else
+		tview->super->lookup_uid(view, seq, uid_r);
 }
 
-static int _tview_lookup_uid_range(struct mail_index_view *view,
-				   uint32_t first_uid, uint32_t last_uid,
-				   uint32_t *first_seq_r, uint32_t *last_seq_r)
+static void _tview_lookup_uid_range(struct mail_index_view *view,
+				    uint32_t first_uid, uint32_t last_uid,
+				    uint32_t *first_seq_r, uint32_t *last_seq_r)
 {
 	struct mail_index_view_transaction *tview =
 		(struct mail_index_view_transaction *)view;
 	const struct mail_index_record *rec;
 	uint32_t seq;
 
-	if (tview->super->lookup_uid_range(view, first_uid, last_uid,
-					   first_seq_r, last_seq_r) < 0)
-		return -1;
-
+	tview->super->lookup_uid_range(view, first_uid, last_uid,
+				       first_seq_r, last_seq_r);
 	if (tview->t->last_new_seq == 0) {
 		/* no new messages, the results are final. */
-		return 0;
+		return;
 	}
 
 	rec = mail_index_transaction_lookup(tview->t, tview->t->first_new_seq);
 	if (rec->uid == 0) {
 		/* new messages don't have UIDs */
-		return 0;
+		return;
 	}
 	if (last_uid < rec->uid) {
 		/* all wanted messages were existing */
-		return 0;
+		return;
 	}
 
 	/* at least some of the wanted messages are newly created */
@@ -141,12 +137,11 @@
 		}
 	}
 	i_assert(seq >= tview->t->first_new_seq);
-	return 0;
 }
 
-static int _tview_lookup_first(struct mail_index_view *view,
-			       enum mail_flags flags, uint8_t flags_mask,
-			       uint32_t *seq_r)
+static void _tview_lookup_first(struct mail_index_view *view,
+				enum mail_flags flags, uint8_t flags_mask,
+				uint32_t *seq_r)
 {
 	struct mail_index_view_transaction *tview =
 		(struct mail_index_view_transaction *)view;
@@ -154,11 +149,9 @@
 	unsigned int append_count;
 	uint32_t seq, message_count;
 
-	if (tview->super->lookup_first(view, flags, flags_mask, seq_r) < 0)
-		return -1;
-
+	tview->super->lookup_first(view, flags, flags_mask, seq_r);
 	if (*seq_r != 0)
-		return 0;
+		return;
 
 	rec = array_get(&tview->t->appends, &append_count);
 	seq = tview->t->first_new_seq;
@@ -171,8 +164,6 @@
 			break;
 		}
 	}
-
-	return 0;
 }
 
 static struct mail_index_map *
@@ -223,16 +214,15 @@
 	return 1;
 }
 
-static int _tview_get_header_ext(struct mail_index_view *view,
-				 struct mail_index_map *map, uint32_t ext_id,
-				 const void **data_r, size_t *data_size_r)
+static void _tview_get_header_ext(struct mail_index_view *view,
+				  struct mail_index_map *map, uint32_t ext_id,
+				  const void **data_r, size_t *data_size_r)
 {
 	struct mail_index_view_transaction *tview =
 		(struct mail_index_view_transaction *)view;
 
 	/* FIXME: check updates */
-	return tview->super->get_header_ext(view, map, ext_id,
-					    data_r, data_size_r);
+	tview->super->get_header_ext(view, map, ext_id, data_r, data_size_r);
 }
 
 static bool _tview_ext_get_reset_id(struct mail_index_view *view,
--- a/src/lib-index/mail-index-view-private.h	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mail-index-view-private.h	Sun Aug 12 16:43:05 2007 +0300
@@ -18,19 +18,20 @@
 	int (*lookup_full)(struct mail_index_view *view, uint32_t seq,
 			   struct mail_index_map **map_r,
 			   const struct mail_index_record **rec_r);
-	int (*lookup_uid)(struct mail_index_view *view, uint32_t seq,
-			  uint32_t *uid_r);
-	int (*lookup_uid_range)(struct mail_index_view *view,
-				uint32_t first_uid, uint32_t last_uid,
-				uint32_t *first_seq_r, uint32_t *last_seq_r);
-	int (*lookup_first)(struct mail_index_view *view, enum mail_flags flags,
-			    uint8_t flags_mask, uint32_t *seq_r);
+	void (*lookup_uid)(struct mail_index_view *view, uint32_t seq,
+			   uint32_t *uid_r);
+	void (*lookup_uid_range)(struct mail_index_view *view,
+				 uint32_t first_uid, uint32_t last_uid,
+				 uint32_t *first_seq_r, uint32_t *last_seq_r);
+	void (*lookup_first)(struct mail_index_view *view,
+			     enum mail_flags flags, uint8_t flags_mask,
+			     uint32_t *seq_r);
 	int (*lookup_ext_full)(struct mail_index_view *view, uint32_t seq,
 			       uint32_t ext_id, struct mail_index_map **map_r,
 			       const void **data_r);
-	int (*get_header_ext)(struct mail_index_view *view,
-			      struct mail_index_map *map, uint32_t ext_id,
-			      const void **data_r, size_t *data_size_r);
+	void (*get_header_ext)(struct mail_index_view *view,
+			       struct mail_index_map *map, uint32_t ext_id,
+			       const void **data_r, size_t *data_size_r);
 	bool (*ext_get_reset_id)(struct mail_index_view *view,
 				 struct mail_index_map *map,
 				 uint32_t ext_id, uint32_t *reset_id_r);
--- a/src/lib-index/mail-index-view-sync.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mail-index-view-sync.c	Sun Aug 12 16:43:05 2007 +0300
@@ -185,12 +185,8 @@
 	src = dest = array_get_modifiable(expunges_r, &count);
 	src_end = src + count;
 	for (; src != src_end; src++) {
-		ret = mail_index_lookup_uid_range(view, src->seq1,
-						  src->seq2,
-						  &dest->seq1,
-						  &dest->seq2);
-		i_assert(ret == 0);
-
+		mail_index_lookup_uid_range(view, src->seq1, src->seq2,
+					    &dest->seq1, &dest->seq2);
 		if (dest->seq1 == 0)
 			count--;
 		else {
@@ -206,21 +202,20 @@
 	return 0;
 }
 
-static int have_existing_expunges(struct mail_index_view *view,
-				  const struct seq_range *range, size_t size)
+static bool have_existing_expunges(struct mail_index_view *view,
+				   const struct seq_range *range, size_t size)
 {
 	const struct seq_range *range_end;
 	uint32_t seq1, seq2;
 
 	range_end = CONST_PTR_OFFSET(range, size);
 	for (; range < range_end; range++) {
-		if (mail_index_lookup_uid_range(view, range->seq1, range->seq2,
-						&seq1, &seq2) < 0)
-			return -1;
+		mail_index_lookup_uid_range(view, range->seq1, range->seq2,
+					    &seq1, &seq2);
 		if (seq1 != 0)
-			return 1;
+			return TRUE;
 	}
-	return 0;
+	return FALSE;
 }
 
 static bool view_sync_have_expunges(struct mail_index_view *view)
@@ -229,7 +224,8 @@
 	const void *data;
 	uint32_t seq;
 	uoff_t offset;
-	int ret = 0;
+	bool have_expunges = FALSE;
+	int ret;
 
 	mail_transaction_log_view_get_prev_pos(view->log_view,
 					       &seq, &offset);
@@ -244,16 +240,17 @@
 		}
 
 		/* we have an expunge. see if it still exists. */
-		ret = have_existing_expunges(view, data, hdr->size);
-		if (ret != 0)
+		if (have_existing_expunges(view, data, hdr->size)) {
+			have_expunges = TRUE;
 			break;
+		}
 	}
 
 	mail_transaction_log_view_seek(view->log_view, seq, offset);
 
 	/* handle failures as having expunges (which is safer).
 	   we'll probably fail later. */
-	return ret != 0;
+	return ret < 0 || have_expunges;
 }
 
 int mail_index_view_sync_begin(struct mail_index_view *view,
@@ -269,9 +266,6 @@
 	i_assert(!view->syncing);
 	i_assert(view->transactions == 0);
 
-	if (mail_index_map_lock(view->index->map) < 0)
-		return -1;
-
 	sync_expunges = (flags & MAIL_INDEX_VIEW_SYNC_FLAG_NOEXPUNGES) == 0;
 	if (sync_expunges) {
 		/* get list of all expunges first */
--- a/src/lib-index/mail-index-view.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mail-index-view.c	Sun Aug 12 16:43:05 2007 +0300
@@ -41,9 +41,6 @@
 {
 	i_assert(view->refcount == 0);
 
-	/* we're not unlocking the view, because views could be temporarily
-	   created and closed and the current map should stay locked
-	   (especially syncing) */
 	mail_transaction_log_view_close(&view->log_view);
 
 	if (array_is_created(&view->syncs_hidden))
@@ -70,18 +67,6 @@
 }
 #endif
 
-void mail_index_view_unlock(struct mail_index_view *view __attr_unused__)
-{
-#ifdef DEBUG
-	mail_index_view_check_nextuid(view);
-#endif
-
-	/* currently this is a no-op. if we unlock any maps, they might get
-	   changed and then it's unspecified what parts of the memory mapping
-	   are up-to-date. we could also copy the map to memory always, but
-	   that kinds of defeats the purpose of mmaps. */
-}
-
 bool mail_index_view_is_inconsistent(struct mail_index_view *view)
 {
 	if (view->index->indexid != view->indexid)
@@ -165,9 +150,6 @@
 
 	i_assert(seq > 0 && seq <= mail_index_view_get_messages_count(view));
 
-	if (mail_index_map_lock(view->map) < 0)
-		return -1;
-
 	/* look up the record */
 	rec = MAIL_INDEX_MAP_IDX(view->map, seq-1);
 	if (rec->uid == 0) {
@@ -183,11 +165,9 @@
 		return 1;
 	}
 
-	/* look up the record from head mapping. it may contain some changes. */
-	if (mail_index_map_lock(view->index->map) < 0)
-		return -1;
+	/* look up the record from head mapping. it may contain some changes.
 
-	/* start looking up from the same sequence as in the old view.
+	   start looking up from the same sequence as in the old view.
 	   if there are no expunges, it's there. otherwise it's somewhere
 	   before (since records can't be inserted).
 
@@ -226,15 +206,12 @@
 	}
 }
 
-static int _view_lookup_uid(struct mail_index_view *view, uint32_t seq,
-			    uint32_t *uid_r)
+static void _view_lookup_uid(struct mail_index_view *view, uint32_t seq,
+			     uint32_t *uid_r)
 {
 	i_assert(seq > 0 && seq <= mail_index_view_get_messages_count(view));
 
-	/* UID lookups don't require the view to be locked. only expunges
-	   change them, and expunges will recreate the file */
 	*uid_r = MAIL_INDEX_MAP_IDX(view->map, seq-1)->uid;
-	return 0;
 }
 
 static uint32_t mail_index_bsearch_uid(struct mail_index_view *view,
@@ -286,24 +263,23 @@
 	return idx+1;
 }
 
-static int _view_lookup_uid_range(struct mail_index_view *view,
-				  uint32_t first_uid, uint32_t last_uid,
-				  uint32_t *first_seq_r, uint32_t *last_seq_r)
+static void _view_lookup_uid_range(struct mail_index_view *view,
+				   uint32_t first_uid, uint32_t last_uid,
+				   uint32_t *first_seq_r, uint32_t *last_seq_r)
 {
 	i_assert(first_uid > 0);
 	i_assert(first_uid <= last_uid);
 
-	/* no locking needed for UIDs, see _view_lookup_uid() */
 	if (view->map->hdr.messages_count == 0) {
 		*first_seq_r = *last_seq_r = 0;
-		return 0;
+		return;
 	}
 
 	*first_seq_r = mail_index_bsearch_uid(view, first_uid, 0, 1);
 	if (*first_seq_r == 0 ||
 	    MAIL_INDEX_MAP_IDX(view->map, *first_seq_r-1)->uid > last_uid) {
 		*first_seq_r = *last_seq_r = 0;
-		return 0;
+		return;
 	}
 
 	if (last_uid >= view->map->hdr.next_uid-1) {
@@ -311,11 +287,11 @@
 		last_uid = view->map->hdr.next_uid-1;
 		if (first_uid > last_uid) {
 			*first_seq_r = *last_seq_r = 0;
-			return 0;
+			return;
 		}
 
 		*last_seq_r = view->map->hdr.messages_count;
-		return 0;
+		return;
 	}
 
 	if (first_uid == last_uid)
@@ -326,12 +302,11 @@
 						     *first_seq_r - 1, -1);
 	}
 	i_assert(*last_seq_r >= *first_seq_r);
-	return 0;
 }
 
-static int _view_lookup_first(struct mail_index_view *view,
-			      enum mail_flags flags, uint8_t flags_mask,
-			      uint32_t *seq_r)
+static void _view_lookup_first(struct mail_index_view *view,
+			       enum mail_flags flags, uint8_t flags_mask,
+			       uint32_t *seq_r)
 {
 #define LOW_UPDATE(x) \
 	STMT_START { if ((x) > low_uid) low_uid = x; } STMT_END
@@ -348,21 +323,14 @@
 	if (low_uid == 1)
 		seq = 1;
 	else {
-		if (mail_index_lookup_uid_range(view, low_uid, low_uid,
-						&seq, &seq) < 0)
-			return -1;
-
+		mail_index_lookup_uid_range(view, low_uid, low_uid,
+					    &seq, &seq);
 		if (seq == 0)
-			return 0;
+			return;
 	}
 
 	i_assert(view->map->hdr.messages_count <=
 		 view->map->rec_map->records_count);
-
-	/* we can delay locking until we're looking at the flags */
-	if (mail_index_map_lock(view->map) < 0)
-		return -1;
-
 	for (; seq <= view->map->hdr.messages_count; seq++) {
 		rec = MAIL_INDEX_MAP_IDX(view->map, seq-1);
 		if ((rec->flags & flags_mask) == (uint8_t)flags) {
@@ -370,8 +338,6 @@
 			break;
 		}
 	}
-
-	return 0;
 }
 
 static int _view_lookup_ext_full(struct mail_index_view *view, uint32_t seq,
@@ -398,9 +364,9 @@
 	return ret;
 }
 
-static int _view_get_header_ext(struct mail_index_view *view,
-				struct mail_index_map *map, uint32_t ext_id,
-				const void **data_r, size_t *data_size_r)
+static void _view_get_header_ext(struct mail_index_view *view,
+				 struct mail_index_map *map, uint32_t ext_id,
+				 const void **data_r, size_t *data_size_r)
 {
 	const struct mail_index_ext *ext;
 	uint32_t idx;
@@ -410,20 +376,16 @@
 		map = view->index->map;
 	}
 
-	if (mail_index_map_lock(map) < 0)
-		return -1;
-
 	if (!mail_index_map_get_ext_idx(map, ext_id, &idx)) {
 		/* extension doesn't exist in this index file */
 		*data_r = NULL;
 		*data_size_r = 0;
-		return 0;
+		return;
 	}
 
 	ext = array_idx(&map->extensions, idx);
 	*data_r = CONST_PTR_OFFSET(map->hdr_base, ext->hdr_offset);
 	*data_size_r = ext->hdr_size;
-	return 0;
 }
 
 static bool _view_ext_get_reset_id(struct mail_index_view *view __attr_unused__,
@@ -556,24 +518,25 @@
 	return ret;
 }
 
-int mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq,
-			  uint32_t *uid_r)
+void mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq,
+			   uint32_t *uid_r)
 {
-	return view->v.lookup_uid(view, seq, uid_r);
+	view->v.lookup_uid(view, seq, uid_r);
 }
 
-int mail_index_lookup_uid_range(struct mail_index_view *view,
-				uint32_t first_uid, uint32_t last_uid,
-				uint32_t *first_seq_r, uint32_t *last_seq_r)
+void mail_index_lookup_uid_range(struct mail_index_view *view,
+				 uint32_t first_uid, uint32_t last_uid,
+				 uint32_t *first_seq_r, uint32_t *last_seq_r)
 {
-	return view->v.lookup_uid_range(view, first_uid, last_uid,
-					first_seq_r, last_seq_r);
+	view->v.lookup_uid_range(view, first_uid, last_uid,
+				 first_seq_r, last_seq_r);
 }
 
-int mail_index_lookup_first(struct mail_index_view *view, enum mail_flags flags,
-			    uint8_t flags_mask, uint32_t *seq_r)
+void mail_index_lookup_first(struct mail_index_view *view,
+			     enum mail_flags flags, uint8_t flags_mask,
+			     uint32_t *seq_r)
 {
-	return view->v.lookup_first(view, flags, flags_mask, seq_r);
+	view->v.lookup_first(view, flags, flags_mask, seq_r);
 }
 
 int mail_index_lookup_ext(struct mail_index_view *view, uint32_t seq,
@@ -591,17 +554,17 @@
 	return view->v.lookup_ext_full(view, seq, ext_id, map_r, data_r);
 }
 
-int mail_index_get_header_ext(struct mail_index_view *view, uint32_t ext_id,
-			      const void **data_r, size_t *data_size_r)
+void mail_index_get_header_ext(struct mail_index_view *view, uint32_t ext_id,
+			       const void **data_r, size_t *data_size_r)
 {
-	return view->v.get_header_ext(view, NULL, ext_id, data_r, data_size_r);
+	view->v.get_header_ext(view, NULL, ext_id, data_r, data_size_r);
 }
 
-int mail_index_map_get_header_ext(struct mail_index_view *view,
-				  struct mail_index_map *map, uint32_t ext_id,
-				  const void **data_r, size_t *data_size_r)
+void mail_index_map_get_header_ext(struct mail_index_view *view,
+				   struct mail_index_map *map, uint32_t ext_id,
+				   const void **data_r, size_t *data_size_r)
 {
-	return view->v.get_header_ext(view, map, ext_id, data_r, data_size_r);
+	view->v.get_header_ext(view, map, ext_id, data_r, data_size_r);
 }
 
 bool mail_index_ext_get_reset_id(struct mail_index_view *view,
--- a/src/lib-index/mail-index.h	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mail-index.h	Sun Aug 12 16:43:05 2007 +0300
@@ -192,8 +192,6 @@
 
 /* Returns the index for given view. */
 struct mail_index *mail_index_view_get_index(struct mail_index_view *view);
-/* Call whenever you've done with requesting messages from view for a while. */
-void mail_index_view_unlock(struct mail_index_view *view);
 /* Returns number of mails in view. */
 uint32_t mail_index_view_get_messages_count(struct mail_index_view *view);
 /* Returns TRUE if we lost track of changes for some reason. */
@@ -309,18 +307,19 @@
 			       ARRAY_TYPE(keyword_indexes) *keyword_idx);
 /* Returns the UID for given message. May be slightly faster than
    mail_index_lookup()->uid. */
-int mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq,
-			  uint32_t *uid_r);
+void mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq,
+			   uint32_t *uid_r);
 /* Convert UID range to sequence range. If no UIDs are found, sequences are
    set to 0. Note that any of the returned sequences may have been expunged
    already. */
-int mail_index_lookup_uid_range(struct mail_index_view *view,
-				uint32_t first_uid, uint32_t last_uid,
-				uint32_t *first_seq_r, uint32_t *last_seq_r);
+void mail_index_lookup_uid_range(struct mail_index_view *view,
+				 uint32_t first_uid, uint32_t last_uid,
+				 uint32_t *first_seq_r, uint32_t *last_seq_r);
 /* Find first mail with (mail->flags & flags_mask) == flags. Useful mostly for
    taking advantage of lowwater-fields in headers. */
-int mail_index_lookup_first(struct mail_index_view *view, enum mail_flags flags,
-			    uint8_t flags_mask, uint32_t *seq_r);
+void mail_index_lookup_first(struct mail_index_view *view,
+			     enum mail_flags flags, uint8_t flags_mask,
+			     uint32_t *seq_r);
 
 /* Append a new record to index. */
 void mail_index_append(struct mail_index_transaction *t, uint32_t uid,
@@ -419,11 +418,11 @@
 				 uint32_t ext_id, uint32_t *reset_id_r);
 
 /* Returns extension header. */
-int mail_index_get_header_ext(struct mail_index_view *view, uint32_t ext_id,
-			      const void **data_r, size_t *data_size_r);
-int mail_index_map_get_header_ext(struct mail_index_view *view,
-				  struct mail_index_map *map, uint32_t ext_id,
-				  const void **data_r, size_t *data_size_r);
+void mail_index_get_header_ext(struct mail_index_view *view, uint32_t ext_id,
+			       const void **data_r, size_t *data_size_r);
+void mail_index_map_get_header_ext(struct mail_index_view *view,
+				   struct mail_index_map *map, uint32_t ext_id,
+				   const void **data_r, size_t *data_size_r);
 /* Returns the wanted extension record for given message. If it doesn't exist,
    *data_r is set to NULL. Return values are same as for mail_index_lookup(). */
 int mail_index_lookup_ext(struct mail_index_view *view, uint32_t seq,
--- a/src/lib-index/mailbox-list-index-sync.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-index/mailbox-list-index-sync.c	Sun Aug 12 16:43:05 2007 +0300
@@ -204,10 +204,8 @@
 		return mailbox_list_index_set_corrupted(ctx->index,
 							"Record with UID=0");
 	}
-	if (mail_index_lookup_uid_range(ctx->mail_view, rec->uid, rec->uid,
-					&rec->seq, &rec->seq) < 0)
-		return -1;
-
+	mail_index_lookup_uid_range(ctx->mail_view, rec->uid, rec->uid,
+				    &rec->seq, &rec->seq);
 	if (rec->seq == 0) {
 		mail_hdr = mail_index_get_header(ctx->mail_view);
 		if (rec->uid < mail_hdr->next_uid) {
@@ -602,12 +600,10 @@
 			/* expunge from mail index */
 			uint32_t seq;
 
-			if (mail_index_lookup_uid_range(ctx->mail_view,
-							sync_recs[src].uid,
-							sync_recs[src].uid,
-							&seq, &seq) < 0)
-				return -1;
-
+			mail_index_lookup_uid_range(ctx->mail_view,
+						    sync_recs[src].uid,
+						    sync_recs[src].uid,
+						    &seq, &seq);
 			if (seq != 0)
 				mail_index_expunge(ctx->trans, seq);
 			// FIXME: expunge also NONEXISTENT parents
@@ -734,11 +730,11 @@
 			recs[j].deleted = TRUE;
 
 			/* expunge from mail index */
-			if (mail_index_lookup_uid_range(ctx->mail_view,
-							sync_recs[i].uid,
-							sync_recs[i].uid,
-							&seq, &seq) == 0 &&
-			    seq != 0)
+			mail_index_lookup_uid_range(ctx->mail_view,
+						    sync_recs[i].uid,
+						    sync_recs[i].uid,
+						    &seq, &seq);
+			if (seq != 0)
 				mail_index_expunge(ctx->trans, seq);
 
 			/* If we compress the file, the record must be removed
--- a/src/lib-storage/index/cydir/cydir-sync.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/cydir/cydir-sync.c	Sun Aug 12 16:43:05 2007 +0300
@@ -6,7 +6,7 @@
 #include "cydir-storage.h"
 #include "cydir-sync.h"
 
-static int cydir_sync_set_uidvalidity(struct cydir_sync_context *ctx)
+static void cydir_sync_set_uidvalidity(struct cydir_sync_context *ctx)
 {
 	uint32_t uid_validity = ioloop_time;
 
@@ -14,7 +14,6 @@
 		offsetof(struct mail_index_header, uid_validity),
 		&uid_validity, sizeof(uid_validity), TRUE);
 	ctx->uid_validity = uid_validity;
-	return 0;
 }
 
 static string_t *cydir_get_path_prefix(struct cydir_mailbox *mbox)
@@ -30,7 +29,7 @@
 	return path;
 }
 
-static int
+static void
 cydir_sync_expunge(struct cydir_sync_context *ctx, uint32_t seq1, uint32_t seq2)
 {
 	struct mailbox *box = &ctx->mbox->ibox.box;
@@ -42,10 +41,7 @@
 	}
 
 	for (; seq1 <= seq2; seq1++) {
-		if (mail_index_lookup_uid(ctx->sync_view, seq1, &uid) < 0) {
-			mail_storage_set_index_error(&ctx->mbox->ibox);
-			return -1;
-		}
+		mail_index_lookup_uid(ctx->sync_view, seq1, &uid);
 
 		str_truncate(ctx->path, ctx->path_dir_prefix_len);
 		str_printfa(ctx->path, "%u.", uid);
@@ -61,7 +57,6 @@
 			/* continue anyway */
 		}
 	}
-	return 0;
 }
 
 static int cydir_sync_index(struct cydir_sync_context *ctx)
@@ -75,17 +70,12 @@
 	hdr = mail_index_get_header(ctx->sync_view);
 	if (hdr->uid_validity != 0)
 		ctx->uid_validity = hdr->uid_validity;
-	else {
-		if (cydir_sync_set_uidvalidity(ctx) < 0)
-			return -1;
-	}
+	else
+		cydir_sync_set_uidvalidity(ctx);
 
 	/* mark the newly seen messages as recent */
-	if (mail_index_lookup_uid_range(ctx->sync_view, hdr->first_recent_uid,
-					hdr->next_uid, &seq1, &seq2) < 0) {
-		mail_storage_set_index_error(&ctx->mbox->ibox);
-		return -1;
-	}
+	mail_index_lookup_uid_range(ctx->sync_view, hdr->first_recent_uid,
+				    hdr->next_uid, &seq1, &seq2);
 	if (seq1 != 0) {
 		index_mailbox_set_recent_seq(&ctx->mbox->ibox, ctx->sync_view,
 					     seq1, seq2);
@@ -94,12 +84,9 @@
 	while (ret > 0 &&
 	       (ret = mail_index_sync_next(ctx->index_sync_ctx,
 					   &sync_rec)) > 0) {
-		if (mail_index_lookup_uid_range(ctx->sync_view,
-						sync_rec.uid1, sync_rec.uid2,
-						&seq1, &seq2) < 0) {
-			mail_storage_set_index_error(&ctx->mbox->ibox);
-			return -1;
-		}
+		mail_index_lookup_uid_range(ctx->sync_view,
+					    sync_rec.uid1, sync_rec.uid2,
+					    &seq1, &seq2);
 		if (seq1 == 0) {
 			/* already expunged, nothing to do. */
 			continue;
@@ -110,8 +97,7 @@
 			/* don't care */
 			break;
 		case MAIL_INDEX_SYNC_TYPE_EXPUNGE:
-			if (cydir_sync_expunge(ctx, seq1, seq2) < 0)
-				ret = -1;
+			cydir_sync_expunge(ctx, seq1, seq2);
 			break;
 		case MAIL_INDEX_SYNC_TYPE_FLAGS:
 		case MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD:
--- a/src/lib-storage/index/dbox/dbox-mail.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/dbox/dbox-mail.c	Sun Aug 12 16:43:05 2007 +0300
@@ -63,11 +63,7 @@
 		if (synced)
 			return -1;
 
-		if (mail_index_lookup_uid(trans->trans_view, seq, &uid) < 0) {
-			mail_storage_set_index_error(&mbox->ibox);
-			return -1;
-		}
-
+		mail_index_lookup_uid(trans->trans_view, seq, &uid);
 		mail_storage_set_critical(&mbox->storage->storage,
 			"Cached message offset lost for uid %u in "
 			"dbox %s", uid, mbox->path);
--- a/src/lib-storage/index/dbox/dbox-sync-expunge.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/dbox/dbox-sync-expunge.c	Sun Aug 12 16:43:05 2007 +0300
@@ -14,20 +14,13 @@
 
 #include <stddef.h>
 
-static int
+static void
 dbox_sync_rec_get_uids(struct dbox_sync_context *ctx,
 		       const struct dbox_sync_rec *sync_rec,
 		       uint32_t *uid1_r, uint32_t *uid2_r)
 {
-	if (mail_index_lookup_uid(ctx->sync_view, sync_rec->seq1, uid1_r) < 0) {
-		mail_storage_set_index_error(&ctx->mbox->ibox);
-		return -1;
-	}
-	if (mail_index_lookup_uid(ctx->sync_view, sync_rec->seq2, uid2_r) < 0) {
-		mail_storage_set_index_error(&ctx->mbox->ibox);
-		return -1;
-	}
-	return 0;
+	mail_index_lookup_uid(ctx->sync_view, sync_rec->seq1, uid1_r);
+	mail_index_lookup_uid(ctx->sync_view, sync_rec->seq2, uid2_r);
 }
 
 static int
@@ -49,9 +42,7 @@
 		if (sync_rec->type != MAIL_INDEX_SYNC_TYPE_EXPUNGE)
 			continue;
 
-		if (dbox_sync_rec_get_uids(ctx, sync_rec, uid1_r, uid2_r) < 0)
-			return -1;
-
+		dbox_sync_rec_get_uids(ctx, sync_rec, uid1_r, uid2_r);
 		if (box->v.sync_notify != NULL) {
 			/* all of the UIDs uid1..uid2 should exist */
 			for (uid = *uid1_r; uid <= *uid2_r; uid++) {
@@ -120,11 +111,8 @@
 	sync_recs = array_get(&sync_entry->sync_recs, &sync_count);
 	if (sync_idx == sync_count)
 		uid1 = uid2 = 0;
-	else {
-		if (dbox_sync_rec_get_uids(ctx, &sync_recs[sync_idx],
-					   &uid1, &uid2) < 0)
-			return -1;
-	}
+	else
+		dbox_sync_rec_get_uids(ctx, &sync_recs[sync_idx], &uid1, &uid2);
 
 	file_seq = dbox_uidlist_get_new_file_seq(mbox->uidlist);
 
@@ -165,13 +153,8 @@
 		uint32_t uid = mbox->file->seeked_uid;
 		uint64_t hdr_offset = output->offset;
 
-		if (mail_index_lookup_uid_range(ctx->sync_view, uid, uid,
-						&seq, &seq) < 0) {
-			mail_storage_set_index_error(&ctx->mbox->ibox);
-			ret = -1;
-			break;
-		}
-
+		mail_index_lookup_uid_range(ctx->sync_view, uid, uid,
+					    &seq, &seq);
 		if (seq == 0) {
 			mail_storage_set_critical(storage,
 				"Expunged UID %u reappeared in file %s",
@@ -299,9 +282,7 @@
 		return 0;
 	}
 
-	if (dbox_sync_rec_get_uids(ctx, &sync_recs[sync_idx],
-				   &exp_uid1, &exp_uid2) < 0)
-		return -1;
+	dbox_sync_rec_get_uids(ctx, &sync_recs[sync_idx], &exp_uid1, &exp_uid2);
 
 	/* find the first non-expunged mail */
 	first_expunged_uid = exp_uid1;
@@ -430,7 +411,7 @@
 	return 0;
 }
 
-static int
+static void
 uidlist_entry_remove_uids(struct dbox_sync_context *ctx,
 			  const struct dbox_sync_file_entry *sync_entry)
 {
@@ -442,7 +423,7 @@
 	entry = dbox_uidlist_entry_lookup(ctx->mbox->uidlist,
 					  sync_entry->file_seq);
 	if (entry == NULL)
-		return 0;
+		return;
 
 	recs = array_get(&sync_entry->sync_recs, &count);
 	for (i = 0; i < count; i++) {
@@ -450,11 +431,7 @@
 			continue;
 
 		for (seq = recs[i].seq1; seq <= recs[i].seq2; seq++) {
-			if (mail_index_lookup_uid(ctx->sync_view,
-						  seq, &uid) < 0) {
-				mail_storage_set_index_error(&ctx->mbox->ibox);
-				return -1;
-			}
+			mail_index_lookup_uid(ctx->sync_view, seq, &uid);
 			seq_range_array_remove(&entry->uid_list, uid);
 		}
 	}
@@ -464,7 +441,6 @@
 					 entry->file_seq);
 	}
 	dbox_uidlist_sync_set_modified(ctx->uidlist_sync_ctx);
-	return 0;
 }
 
 int dbox_sync_expunge(struct dbox_sync_context *ctx,
@@ -522,5 +498,6 @@
 	}
 
 	/* remove UIDs from the uidlist entry */
-	return uidlist_entry_remove_uids(ctx, sync_entry);
+	uidlist_entry_remove_uids(ctx, sync_entry);
+	return 0;
 }
--- a/src/lib-storage/index/dbox/dbox-sync-full.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/dbox/dbox-sync-full.c	Sun Aug 12 16:43:05 2007 +0300
@@ -55,13 +55,9 @@
 		mail_index_append(ctx->trans, mbox->file->seeked_uid, &seq);
 		*seq_r = 0;
 	} else {
-		if (mail_index_lookup_uid_range(ctx->sync_view,
-						mbox->file->seeked_uid,
-						mbox->file->seeked_uid,
-						&seq, &seq) < 0) {
-			mail_storage_set_index_error(&ctx->mbox->ibox);
-			return -1;
-		}
+		mail_index_lookup_uid_range(ctx->sync_view,
+					    mbox->file->seeked_uid,
+					    mbox->file->seeked_uid, &seq, &seq);
 		if (seq == 0) {
 			/* not found. it should have been there. */
 			mail_storage_set_critical(&mbox->storage->storage,
--- a/src/lib-storage/index/dbox/dbox-sync.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/dbox/dbox-sync.c	Sun Aug 12 16:43:05 2007 +0300
@@ -85,13 +85,9 @@
 		return 0;
 	}
 
-	if (mail_index_lookup_uid_range(ctx->sync_view,
-					sync_rec->uid1, sync_rec->uid2,
-					&seq1, &seq2) < 0) {
-		mail_storage_set_index_error(&ctx->mbox->ibox);
-		return -1;
-	}
-
+	mail_index_lookup_uid_range(ctx->sync_view,
+				    sync_rec->uid1, sync_rec->uid2,
+				    &seq1, &seq2);
 	if (seq1 == 0) {
 		/* already expunged everything. nothing to do. */
 		return 0;
@@ -145,11 +141,7 @@
 				      &file_seq, &offset) < 0)
 		return -1;
 
-	if (mail_index_lookup_uid(ctx->sync_view, sync_rec->seq2, &uid2) < 0) {
-		mail_storage_set_index_error(&mbox->ibox);
-		return -1;
-	}
-
+	mail_index_lookup_uid(ctx->sync_view, sync_rec->seq2, &uid2);
 	if ((ret = dbox_file_seek(mbox, file_seq, offset, FALSE)) <= 0)
 		return ret;
 
--- a/src/lib-storage/index/index-fetch.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/index-fetch.c	Sun Aug 12 16:43:05 2007 +0300
@@ -4,17 +4,11 @@
 #include "index-storage.h"
 #include "index-mail.h"
 
-int index_storage_get_uids(struct mailbox *box,
-			   uint32_t uid1, uint32_t uid2,
-			   uint32_t *seq1_r, uint32_t *seq2_r)
+void index_storage_get_uids(struct mailbox *box,
+			    uint32_t uid1, uint32_t uid2,
+			    uint32_t *seq1_r, uint32_t *seq2_r)
 {
 	struct index_mailbox *ibox = (struct index_mailbox *)box;
 
-	if (mail_index_lookup_uid_range(ibox->view, uid1, uid2,
-					seq1_r, seq2_r) < 0) {
-		mail_storage_set_index_error(ibox);
-		return -1;
-	}
-
-	return 0;
+	mail_index_lookup_uid_range(ibox->view, uid1, uid2, seq1_r, seq2_r);
 }
--- a/src/lib-storage/index/index-mail.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/index-mail.c	Sun Aug 12 16:43:05 2007 +0300
@@ -1054,10 +1054,7 @@
 	struct index_mail *mail = (struct index_mail *)_mail;
 	uint32_t seq;
 
-	if (mail_index_lookup_uid_range(mail->ibox->view,
-					uid, uid, &seq, &seq) < 0)
-		return -1;
-
+	mail_index_lookup_uid_range(mail->ibox->view, uid, uid, &seq, &seq);
 	if (seq == 0) {
 		index_mail_reset(mail);
 		mail->mail.mail.uid = uid;
--- a/src/lib-storage/index/index-search.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/index-search.c	Sun Aug 12 16:43:05 2007 +0300
@@ -62,10 +62,10 @@
 static const enum message_header_parser_flags hdr_parser_flags =
 	MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE;
 
-static int search_parse_msgset_args(const struct mail_index_header *hdr,
-				    struct mail_search_arg *args,
-				    uint32_t *seq1_r, uint32_t *seq2_r,
-				    bool not);
+static void search_parse_msgset_args(const struct mail_index_header *hdr,
+				     struct mail_search_arg *args,
+				     uint32_t *seq1_r, uint32_t *seq2_r,
+				     bool not);
 
 static int seqset_contains(struct mail_search_seqset *set, uint32_t seq)
 {
@@ -649,10 +649,10 @@
 	return;
 }
 
-static int search_or_parse_msgset_args(const struct mail_index_header *hdr,
-				       struct mail_search_arg *args,
-				       uint32_t *seq1_r, uint32_t *seq2_r,
-				       bool not)
+static void search_or_parse_msgset_args(const struct mail_index_header *hdr,
+					struct mail_search_arg *args,
+					uint32_t *seq1_r, uint32_t *seq2_r,
+					bool not)
 {
 	uint32_t seq1, seq2, min_seq1 = 0, max_seq2 = 0;
 
@@ -664,15 +664,11 @@
 		seq1 = 1; seq2 = hdr->messages_count;
 
 		if (args->type == SEARCH_SUB) {
-			if (search_parse_msgset_args(hdr, args->value.subargs,
-						     &seq1, &seq2, cur_not) < 0)
-				return -1;
+			search_parse_msgset_args(hdr, args->value.subargs,
+						 &seq1, &seq2, cur_not);
 		} else if (args->type == SEARCH_OR) {
-			if (search_or_parse_msgset_args(hdr,
-							args->value.subargs,
-							&seq1, &seq2,
-							cur_not) < 0)
-				return -1;
+			search_or_parse_msgset_args(hdr, args->value.subargs,
+						    &seq1, &seq2, cur_not);
 		} else if (args->type == SEARCH_SEQSET) {
 			search_msgset_fix(hdr, args->value.seqset,
 					  &seq1, &seq2, cur_not);
@@ -694,13 +690,12 @@
 		*seq1_r = min_seq1;
 	if (max_seq2 < *seq2_r)
 		*seq2_r = max_seq2;
-	return 0;
 }
 
-static int search_parse_msgset_args(const struct mail_index_header *hdr,
-				    struct mail_search_arg *args,
-				    uint32_t *seq1_r, uint32_t *seq2_r,
-				    bool not)
+static void search_parse_msgset_args(const struct mail_index_header *hdr,
+				     struct mail_search_arg *args,
+				     uint32_t *seq1_r, uint32_t *seq2_r,
+				     bool not)
 {
 	for (; args != NULL; args = args->next) {
 		bool cur_not = args->not;
@@ -709,96 +704,81 @@
 			cur_not = !cur_not;
 
 		if (args->type == SEARCH_SUB) {
-			if (search_parse_msgset_args(hdr, args->value.subargs,
-						     seq1_r, seq2_r,
-						     cur_not) < 0)
-				return -1;
+			search_parse_msgset_args(hdr, args->value.subargs,
+						 seq1_r, seq2_r, cur_not);
 		} else if (args->type == SEARCH_OR) {
 			/* go through our children and use the widest seqset
 			   range */
-			if (search_or_parse_msgset_args(hdr,
-							args->value.subargs,
-							seq1_r, seq2_r,
-							cur_not) < 0)
-				return -1;
+			search_or_parse_msgset_args(hdr, args->value.subargs,
+						    seq1_r, seq2_r, cur_not);
 		} else if (args->type == SEARCH_SEQSET) {
 			search_msgset_fix(hdr, args->value.seqset,
 					  seq1_r, seq2_r, cur_not);
 		}
 	}
-	return 0;
 }
 
-static int search_limit_lowwater(struct index_search_context *ctx,
-				 uint32_t uid_lowwater, uint32_t *first_seq)
+static void search_limit_lowwater(struct index_search_context *ctx,
+				  uint32_t uid_lowwater, uint32_t *first_seq)
 {
 	uint32_t seq1, seq2;
 
 	if (uid_lowwater == 0)
-		return 0;
+		return;
 
-	if (mail_index_lookup_uid_range(ctx->view, uid_lowwater,
-					(uint32_t)-1, &seq1, &seq2) < 0) {
-		mail_storage_set_index_error(ctx->ibox);
-		return -1;
-	}
-
+	mail_index_lookup_uid_range(ctx->view, uid_lowwater, (uint32_t)-1,
+				    &seq1, &seq2);
 	if (*first_seq < seq1)
 		*first_seq = seq1;
-	return 0;
 }
 
-static int search_limit_by_flags(struct index_search_context *ctx,
-                                 const struct mail_index_header *hdr,
-				 struct mail_search_arg *args,
-				 uint32_t *seq1, uint32_t *seq2)
+static bool search_limit_by_flags(struct index_search_context *ctx,
+				  const struct mail_index_header *hdr,
+				  struct mail_search_arg *args,
+				  uint32_t *seq1, uint32_t *seq2)
 {
 	for (; args != NULL; args = args->next) {
 		switch (args->type) {
 		case SEARCH_SEEN:
 			/* SEEN with 0 seen? */
 			if (!args->not && hdr->seen_messages_count == 0)
-				return 0;
+				return FALSE;
 
 			if (hdr->seen_messages_count == hdr->messages_count) {
 				/* UNSEEN with all seen? */
 				if (args->not)
-					return 0;
+					return FALSE;
 
 				/* SEEN with all seen */
 				args->match_always = TRUE;
 			} else if (args->not) {
 				/* UNSEEN with lowwater limiting */
-				if (search_limit_lowwater(ctx,
-                                		hdr->first_unseen_uid_lowwater,
-						seq1) < 0)
-					return -1;
+				search_limit_lowwater(ctx,
+                                	hdr->first_unseen_uid_lowwater, seq1);
 			}
 			break;
 		case SEARCH_DELETED:
 			/* DELETED with 0 deleted? */
 			if (!args->not && hdr->deleted_messages_count == 0)
-				return 0;
+				return FALSE;
 
 			if (hdr->deleted_messages_count ==
 			    hdr->messages_count) {
 				/* UNDELETED with all deleted? */
 				if (args->not)
-					return 0;
+					return FALSE;
 
 				/* DELETED with all deleted */
 				args->match_always = TRUE;
 			} else if (!args->not) {
 				/* DELETED with lowwater limiting */
-				if (search_limit_lowwater(ctx,
-                                		hdr->first_deleted_uid_lowwater,
-						seq1) < 0)
-					return -1;
+				search_limit_lowwater(ctx,
+                                	hdr->first_deleted_uid_lowwater, seq1);
 			}
 			break;
 		case SEARCH_ALL:
 			if (args->not)
-				return 0;
+				return FALSE;
 			break;
 		default:
 			break;
@@ -808,11 +788,10 @@
 	return *seq1 <= *seq2;
 }
 
-static int search_get_seqset(struct index_search_context *ctx,
-			     struct mail_search_arg *args)
+static void search_get_seqset(struct index_search_context *ctx,
+			      struct mail_search_arg *args)
 {
         const struct mail_index_header *hdr;
-	int ret;
 
 	hdr = mail_index_get_header(ctx->view);
 	if (hdr->messages_count == 0) {
@@ -821,35 +800,28 @@
 		   UID FETCH. */
 		ctx->seq1 = 1;
 		ctx->seq2 = 0;
-		return 0;
+		return;
 	}
 
 	ctx->seq1 = 1;
 	ctx->seq2 = hdr->messages_count;
 
-	if (search_parse_msgset_args(hdr, args, &ctx->seq1, &ctx->seq2,
-				     FALSE) < 0)
-		return -1;
-
+	search_parse_msgset_args(hdr, args, &ctx->seq1, &ctx->seq2, FALSE);
 	if (ctx->seq1 == 0) {
 		ctx->seq1 = 1;
 		ctx->seq2 = hdr->messages_count;
 	}
 	if (ctx->seq1 > ctx->seq2) {
 		/* no matches */
-		return 0;
+		return;
 	}
 
 	/* UNSEEN and DELETED in root search level may limit the range */
-	ret = search_limit_by_flags(ctx, hdr, args, &ctx->seq1, &ctx->seq2);
-	if (ret < 0)
-		return -1;
-	if (ret == 0) {
+	if (!search_limit_by_flags(ctx, hdr, args, &ctx->seq1, &ctx->seq2)) {
 		/* no matches */
 		ctx->seq1 = 1;
 		ctx->seq2 = 0;
 	}
-	return 0;
 }
 
 struct mail_search_context *
@@ -874,16 +846,11 @@
 
 	mail_search_args_reset(ctx->mail_ctx.args, TRUE);
 
-	if (search_get_seqset(ctx, args) < 0) {
-		ctx->failed = TRUE;
-		ctx->seq1 = 1;
-		ctx->seq2 = 0;
-	} else {
-		(void)mail_search_args_foreach(args, search_init_seqset_arg,
-					       ctx);
-		/* Need to reset results for match_always cases */
-		mail_search_args_reset(ctx->mail_ctx.args, FALSE);
-	}
+	search_get_seqset(ctx, args);
+	(void)mail_search_args_foreach(args, search_init_seqset_arg, ctx);
+
+	/* Need to reset results for match_always cases */
+	mail_search_args_reset(ctx->mail_ctx.args, FALSE);
 	return &ctx->mail_ctx;
 }
 
--- a/src/lib-storage/index/index-status.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/index-status.c	Sun Aug 12 16:43:05 2007 +0300
@@ -3,12 +3,16 @@
 #include "lib.h"
 #include "index-storage.h"
 
-int index_storage_get_status_locked(struct index_mailbox *ibox,
-				    enum mailbox_status_items items,
-				    struct mailbox_status *status_r)
+void index_storage_get_status(struct mailbox *box,
+			      enum mailbox_status_items items,
+			      struct mailbox_status *status_r)
 {
+	struct index_mailbox *ibox = (struct index_mailbox *)box;
 	const struct mail_index_header *hdr;
 
+	if (!box->opened)
+		index_storage_mailbox_open(ibox);
+
 	memset(status_r, 0, sizeof(struct mailbox_status));
 
 	/* we can get most of the status items without any trouble */
@@ -23,29 +27,10 @@
 	status_r->uidnext = hdr->next_uid;
 
 	if (items & STATUS_FIRST_UNSEEN_SEQ) {
-		if (mail_index_lookup_first(ibox->view, 0, MAIL_SEEN,
-					    &status_r->first_unseen_seq) < 0) {
-			mail_storage_set_index_error(ibox);
-			return -1;
-		}
+		mail_index_lookup_first(ibox->view, 0, MAIL_SEEN,
+					&status_r->first_unseen_seq);
 	}
 
 	if (items & STATUS_KEYWORDS)
 		status_r->keywords = mail_index_get_keywords(ibox->index);
-	return 0;
 }
-
-int index_storage_get_status(struct mailbox *box,
-			     enum mailbox_status_items items,
-			     struct mailbox_status *status)
-{
-	struct index_mailbox *ibox = (struct index_mailbox *)box;
-	int ret;
-
-	if (!box->opened)
-		index_storage_mailbox_open(ibox);
-
-	ret = index_storage_get_status_locked(ibox, items, status);
-	mail_index_view_unlock(ibox->view);
-	return ret;
-}
--- a/src/lib-storage/index/index-storage.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/index-storage.c	Sun Aug 12 16:43:05 2007 +0300
@@ -466,8 +466,6 @@
 void mail_storage_set_index_error(struct index_mailbox *ibox)
 {
 	mail_storage_set_internal_error(ibox->box.storage);
-
-	mail_index_view_unlock(ibox->view);
 	mail_index_reset_error(ibox->index);
 }
 
--- a/src/lib-storage/index/index-storage.h	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/index-storage.h	Sun Aug 12 16:43:05 2007 +0300
@@ -137,15 +137,11 @@
 
 int index_storage_sync(struct mailbox *box, enum mailbox_sync_flags flags);
 
-int index_storage_get_status(struct mailbox *box,
-			     enum mailbox_status_items items,
-			     struct mailbox_status *status);
-int index_storage_get_status_locked(struct index_mailbox *ibox,
-				    enum mailbox_status_items items,
-				    struct mailbox_status *status_r);
-
-int index_storage_get_uids(struct mailbox *box, uint32_t uid1, uint32_t uid2,
-			   uint32_t *seq1_r, uint32_t *seq2_r);
+void index_storage_get_status(struct mailbox *box,
+			      enum mailbox_status_items items,
+			      struct mailbox_status *status_r);
+void index_storage_get_uids(struct mailbox *box, uint32_t uid1, uint32_t uid2,
+			    uint32_t *seq1_r, uint32_t *seq2_r);
 
 struct mailbox_header_lookup_ctx *
 index_header_lookup_init(struct mailbox *box, const char *const headers[]);
--- a/src/lib-storage/index/index-sync-changes.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/index-sync-changes.c	Sun Aug 12 16:43:05 2007 +0300
@@ -134,13 +134,10 @@
 				break;
 
 			/* mark the changes as dirty */
-			if (mail_index_lookup_uid_range(ctx->sync_view,
-							sync_rec->uid1,
-							sync_rec->uid2,
-							&seq1, &seq2) < 0) {
-				mail_storage_set_index_error(ctx->ibox);
-				return -1;
-			}
+			mail_index_lookup_uid_range(ctx->sync_view,
+						    sync_rec->uid1,
+						    sync_rec->uid2,
+						    &seq1, &seq2);
 			memset(sync_rec, 0, sizeof(*sync_rec));
 
 			if (seq1 == 0)
--- a/src/lib-storage/index/index-sync.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/index-sync.c	Sun Aug 12 16:43:05 2007 +0300
@@ -36,11 +36,9 @@
 				  uint32_t seq1, uint32_t seq2)
 {
 	uint32_t uid;
-	int ret;
 
 	for (; seq1 <= seq2; seq1++) {
-		ret = mail_index_lookup_uid(view, seq1, &uid);
-		i_assert(ret == 0);
+		mail_index_lookup_uid(view, seq1, &uid);
 		index_mailbox_set_recent_uid(ibox, uid);
 	}
 }
@@ -84,15 +82,12 @@
 					 uint32_t seq1, uint32_t seq2)
 {
 	uint32_t uid;
-	int ret;
 
 	if (!array_is_created(&ibox->recent_flags))
 		return;
 
 	for (; seq1 <= seq2; seq1++) {
-		ret = mail_index_lookup_uid(ibox->view, seq1, &uid);
-		i_assert(ret == 0);
-
+		mail_index_lookup_uid(ibox->view, seq1, &uid);
 		if (seq_range_array_remove(&ibox->recent_flags, uid))
 			ibox->recent_flags_count--;
 	}
@@ -208,14 +203,10 @@
 		case MAIL_INDEX_SYNC_TYPE_KEYWORD_REMOVE:
 		case MAIL_INDEX_SYNC_TYPE_KEYWORD_RESET:
 			/* FIXME: hide the flag updates for expunged messages */
-			if (mail_index_lookup_uid_range(ctx->ibox->view,
-						sync.uid1, sync.uid2,
-						&sync_rec_r->seq1,
-						&sync_rec_r->seq2) < 0) {
-				ctx->failed = TRUE;
-				return -1;
-			}
-
+			mail_index_lookup_uid_range(ctx->ibox->view,
+						    sync.uid1, sync.uid2,
+						    &sync_rec_r->seq1,
+						    &sync_rec_r->seq2);
 			if (sync_rec_r->seq1 == 0)
 				break;
 
@@ -258,7 +249,7 @@
 	return 0;
 }
 
-static int
+static void
 index_mailbox_expunge_unseen_recent(struct index_mailbox_sync_context *ctx)
 {
 	struct index_mailbox *ibox = ctx->ibox;
@@ -266,7 +257,7 @@
 	uint32_t seq, start_uid, uid;
 
 	if (!array_is_created(&ibox->recent_flags))
-		return 0;
+		return;
 
 	/* expunges array contained expunges for the messages that were already
 	   visible in this view, but append+expunge would be invisible.
@@ -275,20 +266,12 @@
 	hdr = mail_index_get_header(ibox->view);
 	if (ctx->messages_count == 0)
 		uid = 0;
-	else {
-		if (mail_index_lookup_uid(ibox->view, ctx->messages_count,
-					  &uid) < 0) {
-			mail_storage_set_index_error(ibox);
-			return -1;
-		}
-	}
+	else
+		mail_index_lookup_uid(ibox->view, ctx->messages_count, &uid);
 
 	for (seq = ctx->messages_count + 1; seq <= hdr->messages_count; seq++) {
 		start_uid = uid;
-		if (mail_index_lookup_uid(ibox->view, seq, &uid) < 0) {
-			mail_storage_set_index_error(ibox);
-			return -1;
-		}
+		mail_index_lookup_uid(ibox->view, seq, &uid);
 		if (start_uid + 1 > uid - 1)
 			continue;
 
@@ -320,7 +303,6 @@
 		}
 	}
 #endif
-	return 0;
 }
 
 int index_mailbox_sync_deinit(struct mailbox_sync_context *_ctx,
@@ -336,20 +318,16 @@
 
 	if (ctx->sync_ctx != NULL)
 		mail_index_view_sync_end(&ctx->sync_ctx);
-	if (index_mailbox_expunge_unseen_recent(ctx) < 0)
-		ret = -1;
+	index_mailbox_expunge_unseen_recent(ctx);
 
 	if (ibox->keep_recent) {
 		/* mailbox syncing didn't necessarily update our recent state */
 		hdr = mail_index_get_header(ibox->view);
 		if (hdr->first_recent_uid > ibox->recent_flags_prev_uid) {
-			if (mail_index_lookup_uid_range(ibox->view,
-							hdr->first_recent_uid,
-							hdr->next_uid,
-							&seq1, &seq2) < 0) {
-				mail_storage_set_index_error(ctx->ibox);
-				return -1;
-			}
+			mail_index_lookup_uid_range(ibox->view,
+						    hdr->first_recent_uid,
+						    hdr->next_uid,
+						    &seq1, &seq2);
 			if (seq1 != 0) {
 				index_mailbox_set_recent_seq(ibox, ibox->view,
 							     seq1, seq2);
@@ -357,13 +335,9 @@
 		}
 	}
 
-	if (ret == 0) {
-		ret = status_items == 0 ? 0 :
-			index_storage_get_status_locked(ctx->ibox, status_items,
-							status_r);
-	}
+	if (ret == 0 && status_items != 0)
+		mailbox_get_status(_ctx->box, status_items, status_r);
 
-	mail_index_view_unlock(ibox->view);
 	i_free(ctx);
 	return ret;
 }
--- a/src/lib-storage/index/index-transaction.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/index-transaction.c	Sun Aug 12 16:43:05 2007 +0300
@@ -23,7 +23,6 @@
 {
 	mail_cache_view_close(t->cache_view);
 	mail_index_view_close(&t->trans_view);
-	mail_index_view_unlock(t->ibox->view);
 	array_free(&t->mailbox_ctx.module_contexts);
 	i_free(t);
 }
--- a/src/lib-storage/index/maildir/maildir-sync-index.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync-index.c	Sun Aug 12 16:43:05 2007 +0300
@@ -246,10 +246,8 @@
 	const void *data;
 	size_t data_size;
 
-	if (mail_index_get_header_ext(mbox->ibox.view, mbox->maildir_ext_id,
-				      &data, &data_size) < 0)
-		data_size = 0;
-
+	mail_index_get_header_ext(mbox->ibox.view, mbox->maildir_ext_id,
+				  &data, &data_size);
 	if (data_size != sizeof(mbox->maildir_hdr) ||
 	    maildir_index_header_has_changed(data, &mbox->maildir_hdr)) {
 		mail_index_update_header_ext(trans, mbox->maildir_ext_id, 0,
--- a/src/lib-storage/index/maildir/maildir-sync.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.c	Sun Aug 12 16:43:05 2007 +0300
@@ -525,12 +525,8 @@
 		return -1;
 	}
 
-	if (mail_index_get_header_ext(mbox->ibox.view, mbox->maildir_ext_id,
-				      &data, &data_size) < 0) {
-		mail_storage_set_index_error(&mbox->ibox);
-		return -1;
-	}
-
+	mail_index_get_header_ext(mbox->ibox.view, mbox->maildir_ext_id,
+				  &data, &data_size);
 	if (data_size == 0) {
 		/* doesn't exist */
 		return 0;
--- a/src/lib-storage/index/mbox/mbox-sync-parse.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-parse.c	Sun Aug 12 16:43:05 2007 +0300
@@ -562,11 +562,7 @@
 	   just not yet been rewritten. In that case use MD5 sum, if it
 	   exists. */
 
-	if (mail_index_lookup_uid(view, seq, &uid) < 0) {
-		mail_storage_set_index_error(&mbox->ibox);
-		return -1;
-	}
-
+	mail_index_lookup_uid(view, seq, &uid);
 	memset(&ctx, 0, sizeof(ctx));
         mbox_md5_ctx = mbox_md5_init();
 
--- a/src/lib-storage/index/mbox/mbox-sync.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Sun Aug 12 16:43:05 2007 +0300
@@ -840,10 +840,8 @@
 
 	if (seq <= 1)
 		uid = 0;
-	else if (mail_index_lookup_uid(sync_ctx->sync_view, seq-1, &uid) < 0) {
-		mail_storage_set_index_error(&mbox->ibox);
-		return -1;
-	}
+	else
+		mail_index_lookup_uid(sync_ctx->sync_view, seq-1, &uid);
 
 	sync_ctx->prev_msg_uid = uid;
 
@@ -870,12 +868,8 @@
 
 	i_assert(!sync_ctx->index_reset);
 
-	if (mail_index_lookup_uid_range(sync_view, uid, (uint32_t)-1,
-					&seq1, &seq2) < 0) {
-		mail_storage_set_index_error(&sync_ctx->mbox->ibox);
-		return -1;
-	}
-
+	mail_index_lookup_uid_range(sync_view, uid, (uint32_t)-1,
+				    &seq1, &seq2);
 	if (seq1 == 0) {
 		/* doesn't exist anymore, seek to end of file */
 		st = i_stream_stat(sync_ctx->file_input, TRUE);
--- a/src/lib-storage/list/index-mailbox-list-sync.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/list/index-mailbox-list-sync.c	Sun Aug 12 16:43:05 2007 +0300
@@ -110,10 +110,10 @@
 
 	/* found from list index. lookup the mail index record for it */
 	view = mail_index_view_open(ilist->mail_index);
-	ret = mail_index_lookup_uid_range(view, uid, uid, &seq, &seq);
-	if (ret < 0 || seq == 0) {
+	mail_index_lookup_uid_range(view, uid, uid, &seq, &seq);
+	if (seq == 0) {
 		mail_index_view_close(&view);
-		return ret;
+		return 0;
 	}
 
 	t_push();
@@ -163,7 +163,7 @@
 	return 1;
 }
 
-static int
+static void
 index_list_get_status(struct mailbox *box, enum mailbox_status_items items,
 		      struct mailbox_status *status)
 {
@@ -171,11 +171,11 @@
 
 	if ((items & ~CACHED_STATUS_ITEMS) == 0) {
 		if (index_list_get_cached_status(box, status) > 0)
-			return 0;
+			return;
 		/* nonsynced / error, fallback to doing it the slow way */
 	}
 
-	return ibox->module_ctx.super.get_status(box, items, status);
+	ibox->module_ctx.super.get_status(box, items, status);
 }
 
 static int index_list_lookup_or_create(struct index_mailbox_list *ilist,
@@ -317,8 +317,9 @@
 		/* nothing synced. just return the status. */
 		i_free(ctx);
 
-		return status_items == 0 ? 0 :
+		if (status_items != 0)
 			index_list_get_status(box, status_items, status_r);
+		return 0;
 	}
 
 	list = mail_storage_get_list(box->storage);
@@ -346,8 +347,8 @@
 	}
 
 	view = mail_index_view_open(ilist->mail_index);
-	if (mail_index_lookup_uid_range(view, uid, uid, &seq, &seq) == 0 &&
-	    seq > 0)
+	mail_index_lookup_uid_range(view, uid, uid, &seq, &seq);
+	if (seq != 0)
 		(void)index_list_update(ilist, box, view, seq, status);
 	mail_index_view_close(&view);
 	return 0;
--- a/src/lib-storage/list/index-mailbox-list.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/list/index-mailbox-list.c	Sun Aug 12 16:43:05 2007 +0300
@@ -296,9 +296,7 @@
 	const struct mail_index_record *rec;
 	uint32_t seq;
 
-	if (mail_index_lookup_uid_range(ctx->mail_view, uid, uid,
-					&seq, &seq) < 0)
-		return -1;
+	mail_index_lookup_uid_range(ctx->mail_view, uid, uid, &seq, &seq);
 	if (seq == 0) {
 		i_error("Mailbox list index desynced: "
 			"Record uid=%u expunged from mail index", uid);
--- a/src/lib-storage/mail-storage-private.h	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/mail-storage-private.h	Sun Aug 12 16:43:05 2007 +0300
@@ -76,8 +76,8 @@
 
 	int (*close)(struct mailbox *box);
 
-	int (*get_status)(struct mailbox *box, enum mailbox_status_items items,
-			  struct mailbox_status *status);
+	void (*get_status)(struct mailbox *box, enum mailbox_status_items items,
+			   struct mailbox_status *status_r);
 
 	/* Lookup sync extension record and figure out if it mailbox has
 	   changed since. Returns 1 = yes, 0 = no, -1 = error. */
@@ -122,8 +122,8 @@
 	void (*keywords_free)(struct mailbox_transaction_context *t,
 			      struct mail_keywords *keywords);
 
-	int (*get_uids)(struct mailbox *box, uint32_t uid1, uint32_t uid2,
-			uint32_t *seq1_r, uint32_t *seq2_r);
+	void (*get_uids)(struct mailbox *box, uint32_t uid1, uint32_t uid2,
+			 uint32_t *seq1_r, uint32_t *seq2_r);
 
 	struct mail *
 		(*mail_alloc)(struct mailbox_transaction_context *t,
--- a/src/lib-storage/mail-storage.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/mail-storage.c	Sun Aug 12 16:43:05 2007 +0300
@@ -485,11 +485,11 @@
 	return box->v.allow_new_keywords(box);
 }
 
-int mailbox_get_status(struct mailbox *box,
-		       enum mailbox_status_items items,
-		       struct mailbox_status *status)
+void mailbox_get_status(struct mailbox *box,
+			enum mailbox_status_items items,
+			struct mailbox_status *status_r)
 {
-	return box->v.get_status(box, items, status);
+	box->v.get_status(box, items, status_r);
 }
 
 struct mailbox_sync_context *
@@ -547,10 +547,10 @@
 	t->box->v.keywords_free(t, keywords);
 }
 
-int mailbox_get_uids(struct mailbox *box, uint32_t uid1, uint32_t uid2,
-		     uint32_t *seq1_r, uint32_t *seq2_r)
+void mailbox_get_uids(struct mailbox *box, uint32_t uid1, uint32_t uid2,
+		      uint32_t *seq1_r, uint32_t *seq2_r)
 {
-	return box->v.get_uids(box, uid1, uid2, seq1_r, seq2_r);
+	box->v.get_uids(box, uid1, uid2, seq1_r, seq2_r);
 }
 
 struct mailbox_header_lookup_ctx *
--- a/src/lib-storage/mail-storage.h	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/lib-storage/mail-storage.h	Sun Aug 12 16:43:05 2007 +0300
@@ -279,8 +279,8 @@
 bool mailbox_allow_new_keywords(struct mailbox *box);
 
 /* Gets the mailbox status information. */
-int mailbox_get_status(struct mailbox *box, enum mailbox_status_items items,
-		       struct mailbox_status *status);
+void mailbox_get_status(struct mailbox *box, enum mailbox_status_items items,
+			struct mailbox_status *status_r);
 
 /* Synchronize the mailbox. */
 struct mailbox_sync_context *
@@ -329,8 +329,8 @@
 			   struct mail_keywords **keywords);
 
 /* Convert uid range to sequence range. */
-int mailbox_get_uids(struct mailbox *box, uint32_t uid1, uint32_t uid2,
-		     uint32_t *seq1_r, uint32_t *seq2_r);
+void mailbox_get_uids(struct mailbox *box, uint32_t uid1, uint32_t uid2,
+		      uint32_t *seq1_r, uint32_t *seq2_r);
 
 /* Initialize header lookup for given headers. */
 struct mailbox_header_lookup_ctx *
--- a/src/plugins/fts-squat/fts-backend-squat.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/plugins/fts-squat/fts-backend-squat.c	Sun Aug 12 16:43:05 2007 +0300
@@ -35,9 +35,7 @@
 		return NULL;
 	}
 
-	if (mailbox_get_status(box, STATUS_UIDVALIDITY, &status) < 0)
-		return NULL;
-
+	mailbox_get_status(box, STATUS_UIDVALIDITY, &status);
 	mmap_disable = (storage->flags &
 			(MAIL_STORAGE_FLAG_MMAP_DISABLE |
 			 MAIL_STORAGE_FLAG_MMAP_NO_WRITE)) != 0;
--- a/src/plugins/fts/fts-storage.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/plugins/fts/fts-storage.c	Sun Aug 12 16:43:05 2007 +0300
@@ -84,9 +84,9 @@
 	return ret;
 }
 
-static int uid_range_to_seq(struct mailbox *box,
-			    ARRAY_TYPE(seq_range) *uid_range,
-			    ARRAY_TYPE(seq_range) *seq_range)
+static void uid_range_to_seq(struct mailbox *box,
+			     ARRAY_TYPE(seq_range) *uid_range,
+			     ARRAY_TYPE(seq_range) *seq_range)
 {
 	const struct seq_range *range;
 	struct seq_range new_range;
@@ -95,16 +95,11 @@
 	range = array_get(uid_range, &count);
 	i_array_init(seq_range, count);
 	for (i = 0; i < count; i++) {
-		if (mailbox_get_uids(box, range[i].seq1, range[i].seq2,
-				     &new_range.seq1, &new_range.seq2) < 0) {
-			array_free(seq_range);
-			return -1;
-		}
-
+		mailbox_get_uids(box, range[i].seq1, range[i].seq2,
+				 &new_range.seq1, &new_range.seq2);
 		if (new_range.seq1 != 0)
 			array_append(seq_range, &new_range, 1);
 	}
-	return 0;
 }
 
 static int fts_build_mail_flush(struct fts_storage_build_context *ctx)
@@ -246,9 +241,8 @@
 	}
 
 	memset(&seqset, 0, sizeof(seqset));
-	if (mailbox_get_uids(t->box, last_uid+1, (uint32_t)-1,
-			     &seqset.seq1, &seqset.seq2) < 0)
-		return -1;
+	mailbox_get_uids(t->box, last_uid+1, (uint32_t)-1,
+			 &seqset.seq1, &seqset.seq2);
 	if (seqset.seq1 == 0) {
 		/* no new messages */
 		return 0;
@@ -260,11 +254,8 @@
 		i_assert(last_uid < last_uid_locked);
 
 		last_uid = last_uid_locked;
-		if (mailbox_get_uids(t->box, last_uid+1, (uint32_t)-1,
-				     &seqset.seq1, &seqset.seq2) < 0) {
-			(void)fts_backend_build_deinit(build);
-			return -1;
-		}
+		mailbox_get_uids(t->box, last_uid+1, (uint32_t)-1,
+				 &seqset.seq1, &seqset.seq2);
 		if (seqset.seq1 == 0) {
 			/* no new messages */
 			(void)fts_backend_build_deinit(build);
@@ -467,7 +458,7 @@
 
 	fts_search_filter_args(fctx, fctx->args, &uid_result);
 
-	(void)uid_range_to_seq(box, &uid_result, &fctx->result);
+	uid_range_to_seq(box, &uid_result, &fctx->result);
 	array_free(&uid_result);
 }
 
--- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Sun Aug 12 16:34:37 2007 +0300
+++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Sun Aug 12 16:43:05 2007 +0300
@@ -175,12 +175,8 @@
 
 	range = array_get(&lt->expunge_seqs, &count);
 	for (i = 0; i < count && ret == 0; i++) {
-		if (mailbox_get_uids(srcbox, range[i].seq1, range[i].seq2,
-				     &seq1, &seq2) < 0) {
-			ret = -1;
-			break;
-		}
-
+		mailbox_get_uids(srcbox, range[i].seq1, range[i].seq2,
+				 &seq1, &seq2);
 		for (uid = range[i].seq1; uid <= range[i].seq2; uid++) {
 			if (maildir_file_do(msrcbox, uid, lazy_expunge_move,
 					    &ctx) < 0) {