[dovecot-cvs] dovecot/src/lib-index mail-custom-flags.c,1.16,1.17 mail-custom-flags.h,1.5,1.6 mail-index-compress.c,1.22,1.23 mail-index-data.c,1.32,1.33 mail-index-data.h,1.12,1.13 mail-index-fsck.c,1.11,1.12 mail-index-open.c,1.22,1.23 Message-Id: <20030105130956.04620238E1@danu.procontrol.fi>

cras at procontrol.fi cras at procontrol.fi
Sun Jan 5 15:09:56 EET 2003


Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv25916/src/lib-index

Modified Files:
	mail-custom-flags.c mail-custom-flags.h mail-index-compress.c 
	mail-index-data.c mail-index-data.h mail-index-fsck.c 
	mail-index-open.c mail-index-update-cache.c 
	mail-index-update.c mail-index-util.c mail-index-util.h 
	mail-index.c mail-index.h mail-lockdir.c mail-lockdir.h 
	mail-modifylog.c mail-modifylog.h mail-tree-redblack.c 
	mail-tree.c mail-tree.h 
Log Message:
Naming style changes, finally got tired of most of the typedefs. Also the
previous enum -> macro change reverted so that we don't use the highest bit
anymore, that's incompatible with old indexes so they will be rebuilt.



Index: mail-custom-flags.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-custom-flags.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- mail-custom-flags.c	8 Dec 2002 05:23:08 -0000	1.16
+++ mail-custom-flags.c	5 Jan 2003 13:09:52 -0000	1.17
@@ -20,8 +20,8 @@
 #define COUNTER_SIZE 4
 #define HEADER_SIZE (COUNTER_SIZE + 1) /* 0000\n */
 
-struct _MailCustomFlags {
-	MailIndex *index;
+struct mail_custom_flags {
+	struct mail_index *index;
 	char *filepath;
 	int fd;
 	int lock_type;
@@ -37,9 +37,9 @@
 	unsigned int changed:1;
 };
 
-static int lock_file(MailCustomFlags *mcf, int type);
+static int lock_file(struct mail_custom_flags *mcf, int type);
 
-static int index_cf_set_syscall_error(MailCustomFlags *mcf,
+static int index_cf_set_syscall_error(struct mail_custom_flags *mcf,
 				      const char *function)
 {
 	i_assert(function != NULL);
@@ -49,7 +49,7 @@
 	return FALSE;
 }
 
-static int update_mmap(MailCustomFlags *mcf)
+static int update_mmap(struct mail_custom_flags *mcf)
 {
 	if (mcf->mmap_base != NULL) {
 		if (munmap(mcf->mmap_base, mcf->mmap_length) < 0)
@@ -66,7 +66,7 @@
 	return TRUE;
 }
 
-static int custom_flags_init(MailCustomFlags *mcf)
+static int custom_flags_init(struct mail_custom_flags *mcf)
 {
 	static char buf[HEADER_SIZE] = "0000\n";
 	int failed;
@@ -102,7 +102,7 @@
 	return !failed;
 }
 
-static void custom_flags_sync(MailCustomFlags *mcf)
+static void custom_flags_sync(struct mail_custom_flags *mcf)
 {
 	char *data, *data_end, *line;
 	unsigned int num;
@@ -165,7 +165,7 @@
 	}
 }
 
-static int custom_flags_check_sync(MailCustomFlags *mcf)
+static int custom_flags_check_sync(struct mail_custom_flags *mcf)
 {
 	if (mcf->noupdate)
 		return TRUE;
@@ -195,7 +195,7 @@
 	return TRUE;
 }
 
-static int lock_file(MailCustomFlags *mcf, int type)
+static int lock_file(struct mail_custom_flags *mcf, int type)
 {
 	if (mcf->lock_type == type)
 		return TRUE;
@@ -224,9 +224,9 @@
 	return TRUE;
 }
 
-int mail_custom_flags_open_or_create(MailIndex *index)
+int mail_custom_flags_open_or_create(struct mail_index *index)
 {
-	MailCustomFlags *mcf;
+	struct mail_custom_flags *mcf;
 	const char *path;
 	int fd;
 
@@ -239,7 +239,7 @@
 		return index_file_set_syscall_error(index, path, "open()");
 	}
 
-	mcf = i_new(MailCustomFlags, 1);
+	mcf = i_new(struct mail_custom_flags, 1);
 	mcf->index = index;
 	mcf->filepath = i_strdup(path);
 	mcf->fd = fd;
@@ -267,7 +267,7 @@
 	return TRUE;
 }
 
-void mail_custom_flags_free(MailCustomFlags *mcf)
+void mail_custom_flags_free(struct mail_custom_flags *mcf)
 {
 	int i;
 
@@ -286,7 +286,7 @@
 	i_free(mcf);
 }
 
-static int custom_flags_update_counter(MailCustomFlags *mcf)
+static int custom_flags_update_counter(struct mail_custom_flags *mcf)
 {
 	int i;
 
@@ -315,7 +315,8 @@
 	return TRUE;
 }
 
-static int custom_flags_add(MailCustomFlags *mcf, int idx, const char *name)
+static int custom_flags_add(struct mail_custom_flags *mcf,
+			    int idx, const char *name)
 {
 	const char *buf;
 	size_t len;
@@ -357,7 +358,7 @@
 	return TRUE;
 }
 
-static int custom_flags_remove(MailCustomFlags *mcf, unsigned int idx)
+static int custom_flags_remove(struct mail_custom_flags *mcf, unsigned int idx)
 {
 	char *data, *data_end, *line;
 	unsigned int num;
@@ -405,7 +406,7 @@
 	return FALSE;
 }
 
-static int find_first_unused_flag(MailCustomFlags *mcf)
+static int find_first_unused_flag(struct mail_custom_flags *mcf)
 {
 	int i;
 
@@ -417,8 +418,8 @@
 	return -1;
 }
 
-static void remove_unused_custom_flags(MailCustomFlags *mcf,
-				       MailFlags used_flags)
+static void remove_unused_custom_flags(struct mail_custom_flags *mcf,
+				       enum mail_flags used_flags)
 {
 	unsigned int i;
 
@@ -432,10 +433,10 @@
 	}
 }
 
-static MailFlags get_used_flags(MailCustomFlags *mcf)
+static enum mail_flags get_used_flags(struct mail_custom_flags *mcf)
 {
-	MailIndexRecord *rec;
-	MailFlags used_flags;
+	struct mail_index_record *rec;
+	enum mail_flags used_flags;
 
 	used_flags = 0;
 
@@ -448,7 +449,7 @@
 	return used_flags;
 }
 
-static int get_flag_index(MailCustomFlags *mcf, const char *flag,
+static int get_flag_index(struct mail_custom_flags *mcf, const char *flag,
 			  int index_hint)
 {
 	int i, first_empty;
@@ -505,10 +506,11 @@
 	return first_empty;
 }
 
-int mail_custom_flags_fix_list(MailCustomFlags *mcf, MailFlags *flags,
+int mail_custom_flags_fix_list(struct mail_custom_flags *mcf,
+			       enum mail_flags *flags,
 			       const char *custom_flags[], unsigned int count)
 {
-	MailFlags oldflags, flag;
+	enum mail_flags oldflags, flag;
 	int i, idx;
 
 	i_assert(count < 32);
@@ -542,12 +544,12 @@
 	return 1;
 }
 
-const char **mail_custom_flags_list_get(MailCustomFlags *mcf)
+const char **mail_custom_flags_list_get(struct mail_custom_flags *mcf)
 {
 	return (const char **) mcf->custom_flags;
 }
 
-int mail_custom_flags_has_changes(MailCustomFlags *mcf)
+int mail_custom_flags_has_changes(struct mail_custom_flags *mcf)
 {
 	if (!mcf->changed)
 		return FALSE;

Index: mail-custom-flags.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-custom-flags.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mail-custom-flags.h	23 Oct 2002 19:13:39 -0000	1.5
+++ mail-custom-flags.h	5 Jan 2003 13:09:52 -0000	1.6
@@ -7,24 +7,25 @@
 
 #define CUSTOM_FLAGS_FILE_NAME ".customflags"
 
-int mail_custom_flags_open_or_create(MailIndex *index);
-void mail_custom_flags_free(MailCustomFlags *mcf);
+int mail_custom_flags_open_or_create(struct mail_index *index);
+void mail_custom_flags_free(struct mail_custom_flags *mcf);
 
 /* Change custom flags so that they reflect the real flag numbers in
    the file. Initially flags contains the custom flags in the order of the
    specified list, it's modified to reflect the actual list. Returns 1 if ok,
    0 if number of custom flags exceeded or -1 if error */
-int mail_custom_flags_fix_list(MailCustomFlags *mcf, MailFlags *flags,
+int mail_custom_flags_fix_list(struct mail_custom_flags *mcf,
+			       enum mail_flags *flags,
 			       const char *custom_flags[], unsigned int count);
 
 /* Returns a pointer to list of flags. Note that calls to
    mail_cutom_flags_fix_list() may modify the flags in the returned list.
    It can modify only the flags that aren't in use anywhere, so this should
    be safe. */
-const char **mail_custom_flags_list_get(MailCustomFlags *mcf);
+const char **mail_custom_flags_list_get(struct mail_custom_flags *mcf);
 
 /* Returns TRUE if there's been any changes since this function was
    called last time, or since open if this is the first call. */
-int mail_custom_flags_has_changes(MailCustomFlags *mcf);
+int mail_custom_flags_has_changes(struct mail_custom_flags *mcf);
 
 #endif

Index: mail-index-compress.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-compress.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- mail-index-compress.c	6 Nov 2002 07:12:47 -0000	1.22
+++ mail-index-compress.c	5 Jan 2003 13:09:52 -0000	1.23
@@ -10,7 +10,7 @@
 #include <stdio.h>
 #include <unistd.h>
 
-int mail_index_truncate(MailIndex *index)
+int mail_index_truncate(struct mail_index *index)
 {
 	uoff_t empty_space, truncate_threshold;
 
@@ -29,9 +29,9 @@
 			(empty_space * INDEX_TRUNCATE_KEEP_PERCENTAGE / 100);
 
 		/* keep the size record-aligned */
-		index->mmap_full_length -=
-			(index->mmap_full_length - sizeof(MailIndexHeader)) %
-			sizeof(MailIndexRecord);
+		index->mmap_full_length -= (index->mmap_full_length -
+					    sizeof(struct mail_index_header)) %
+			sizeof(struct mail_index_record);
 
 		if (index->mmap_full_length < INDEX_FILE_MIN_SIZE)
                         index->mmap_full_length = INDEX_FILE_MIN_SIZE;
@@ -45,9 +45,9 @@
 	return TRUE;
 }
 
-int mail_index_compress(MailIndex *index)
+int mail_index_compress(struct mail_index *index)
 {
-	MailIndexRecord *rec, *hole_rec, *end_rec;
+	struct mail_index_record *rec, *hole_rec, *end_rec;
 	unsigned int idx;
 	int tree_fd;
 
@@ -66,19 +66,16 @@
 	/* if we get interrupted, the whole index is probably corrupted.
 	   so keep rebuild-flag on while doing this */
 	index->header->flags |= MAIL_INDEX_FLAG_REBUILD;
-	if (!mail_index_fmdatasync(index, sizeof(MailIndexHeader)))
+	if (!mail_index_fmdatasync(index, sizeof(struct mail_index_header)))
 		return FALSE;
 
 	/* first actually compress the data */
-	end_rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				       index->mmap_used_length);
-	hole_rec = (MailIndexRecord *) ((char *) index->mmap_base +
-					sizeof(MailIndexHeader)) +
-		index->header->first_hole_index;
+	hole_rec = INDEX_RECORD_AT(index, index->header->first_hole_index);
+	end_rec = INDEX_END_RECORD(index);
 	rec = hole_rec + index->header->first_hole_records;
 	while (rec < end_rec) {
 		if (rec->uid != 0) {
-			memcpy(hole_rec, rec, sizeof(MailIndexRecord));
+			memcpy(hole_rec, rec, sizeof(struct mail_index_record));
 			idx = INDEX_RECORD_INDEX(index, hole_rec);
 			if (!mail_tree_update(index->tree, rec->uid, idx))
 				return FALSE;
@@ -117,11 +114,12 @@
 	return TRUE;
 }
 
-static int mail_index_copy_data(MailIndex *index, int fd, const char *path)
+static int mail_index_copy_data(struct mail_index *index,
+				int fd, const char *path)
 {
-	MailIndexDataHeader data_hdr;
-	MailIndexDataRecordHeader *rec_hdr;
-	MailIndexRecord *rec;
+	struct mail_index_data_header data_hdr;
+	struct mail_index_data_record_header *rec_hdr;
+	struct mail_index_record *rec;
 	unsigned char *mmap_data;
 	size_t mmap_data_size;
 	uoff_t offset;
@@ -144,20 +142,19 @@
 	/* now we'll begin the actual moving. keep rebuild-flag on
 	   while doing it. */
 	index->header->flags |= MAIL_INDEX_FLAG_REBUILD;
-	if (!mail_index_fmdatasync(index, sizeof(MailIndexHeader)))
+	if (!mail_index_fmdatasync(index, sizeof(struct mail_index_header)))
 		return FALSE;
 
 	offset = sizeof(data_hdr);
 	rec = index->lookup(index, 1);
 	while (rec != NULL) {
-		if (rec->data_position +
-		    sizeof(MailIndexDataRecordHeader) > mmap_data_size) {
+		if (rec->data_position + sizeof(*rec_hdr) > mmap_data_size) {
 			index_set_corrupted(index,
 				"data_position points outside file");
 			return FALSE;
 		}
 
-		rec_hdr = (MailIndexDataRecordHeader *)
+		rec_hdr = (struct mail_index_data_record_header *)
 			(mmap_data + rec->data_position);
 		if (rec->data_position + rec_hdr->data_size > mmap_data_size) {
 			index_set_corrupted(index,
@@ -195,7 +192,7 @@
 	return TRUE;
 }
 
-int mail_index_compress_data(MailIndex *index)
+int mail_index_compress_data(struct mail_index *index)
 {
 	const char *temppath, *datapath;
 	int fd, failed;

Index: mail-index-data.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-data.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- mail-index-data.c	18 Dec 2002 01:52:14 -0000	1.32
+++ mail-index-data.c	5 Jan 2003 13:09:52 -0000	1.33
@@ -21,13 +21,13 @@
 #define COMPRESS_PERCENTAGE 20
 
 /* Initial size for the file */
-#define INDEX_DATA_INITIAL_SIZE (sizeof(MailIndexDataHeader) + 10240)
+#define INDEX_DATA_INITIAL_SIZE (sizeof(struct mail_index_data_header) + 10240)
 
 /* When more space is needed, grow the file n% larger than the previous size */
 #define INDEX_DATA_GROW_PERCENTAGE 10
 
-struct _MailIndexData {
-	MailIndex *index;
+struct mail_index_data {
+	struct mail_index *index;
 
 	int fd;
 	char *filepath;
@@ -36,7 +36,7 @@
 	size_t mmap_full_length;
 	size_t mmap_used_length;
 
-	MailIndexDataHeader *header;
+	struct mail_index_data_header *header;
 
 	unsigned int anon_mmap:1;
 	unsigned int dirty_mmap:1;
@@ -44,7 +44,7 @@
 	unsigned int fsynced:1;
 };
 
-int index_data_set_corrupted(MailIndexData *data, const char *fmt, ...)
+int index_data_set_corrupted(struct mail_index_data *data, const char *fmt, ...)
 {
 	va_list va;
 
@@ -61,7 +61,7 @@
 	return FALSE;
 }
 
-static int index_data_set_syscall_error(MailIndexData *data,
+static int index_data_set_syscall_error(struct mail_index_data *data,
 					const char *function)
 {
 	i_assert(function != NULL);
@@ -71,7 +71,7 @@
 	return FALSE;
 }
 
-static void mail_index_data_file_close(MailIndexData *data)
+static void mail_index_data_file_close(struct mail_index_data *data)
 {
 	if (data->anon_mmap) {
 		if (munmap_anon(data->mmap_base, data->mmap_full_length) < 0)
@@ -91,7 +91,7 @@
 	}
 }
 
-static int data_file_reopen(MailIndexData *data)
+static int data_file_reopen(struct mail_index_data *data)
 {
 	int fd;
 
@@ -107,9 +107,9 @@
 	return TRUE;
 }
 
-static int mmap_update(MailIndexData *data, uoff_t pos, size_t size)
+static int mmap_update(struct mail_index_data *data, uoff_t pos, size_t size)
 {
-	MailIndexDataHeader *hdr;
+	struct mail_index_data_header *hdr;
 
 	if (data->header != NULL &&
 	    data->header->indexid != data->index->indexid) {
@@ -170,12 +170,12 @@
 		return index_data_set_syscall_error(data, "mmap()");
 	}
 
-	if (data->mmap_full_length < sizeof(MailIndexDataHeader))
+	if (data->mmap_full_length < sizeof(struct mail_index_data_header))
 		return index_data_set_corrupted(data, "File too small");
 
 	hdr = data->mmap_base;
 
-	if (hdr->used_file_size < sizeof(MailIndexDataHeader)) {
+	if (hdr->used_file_size < sizeof(struct mail_index_data_header)) {
 		index_data_set_corrupted(data, "used_file_size too small ("
 					 "%"PRIuUOFF_T")", hdr->used_file_size);
 		return FALSE;
@@ -195,9 +195,9 @@
 	return TRUE;
 }
 
-int mail_index_data_open(MailIndex *index)
+int mail_index_data_open(struct mail_index *index)
 {
-	MailIndexData *data;
+	struct mail_index_data *data;
 	const char *path;
 	int fd;
 
@@ -211,14 +211,14 @@
 		return index_file_set_syscall_error(index, path, "open()");
 	}
 
-	data = i_new(MailIndexData, 1);
+	data = i_new(struct mail_index_data, 1);
 	data->index = index;
 	data->fd = fd;
 	data->filepath = i_strdup(path);
 
 	index->data = data;
 
-	if (!mmap_update(data, 0, sizeof(MailIndexDataHeader))) {
+	if (!mmap_update(data, 0, sizeof(struct mail_index_data_header))) {
 		mail_index_data_free(data);
 		return FALSE;
 	}
@@ -235,12 +235,13 @@
 	return TRUE;
 }
 
-static const char *init_data_file(MailIndex *index, MailIndexDataHeader *hdr,
+static const char *init_data_file(struct mail_index *index,
+				  struct mail_index_data_header *hdr,
 				  int fd, const char *temppath)
 {
 	const char *realpath;
 
-	if (write_full(fd, hdr, sizeof(MailIndexDataHeader)) < 0) {
+	if (write_full(fd, hdr, sizeof(*hdr)) < 0) {
 		index_file_set_syscall_error(index, temppath, "write_full()");
 		return NULL;
 	}
@@ -263,16 +264,16 @@
 	return realpath;
 }
 
-int mail_index_data_create(MailIndex *index)
+int mail_index_data_create(struct mail_index *index)
 {
-        MailIndexDataHeader hdr;
-	MailIndexData *data;
+        struct mail_index_data_header hdr;
+	struct mail_index_data *data;
 	const char *temppath, *realpath;
 	int fd;
 
-	memset(&hdr, 0, sizeof(MailIndexDataHeader));
+	memset(&hdr, 0, sizeof(struct mail_index_data_header));
 	hdr.indexid = index->indexid;
-	hdr.used_file_size = sizeof(MailIndexDataHeader);
+	hdr.used_file_size = sizeof(struct mail_index_data_header);
 
 	realpath = NULL;
 
@@ -300,13 +301,13 @@
 		}
 	}
 
-	data = i_new(MailIndexData, 1);
+	data = i_new(struct mail_index_data, 1);
 
 	if (fd == -1) {
 		data->mmap_full_length = INDEX_DATA_INITIAL_SIZE;
 		data->mmap_base = mmap_anon(data->mmap_full_length);
 
-		memcpy(data->mmap_base, &hdr, sizeof(MailIndexDataHeader));
+		memcpy(data->mmap_base, &hdr, sizeof(hdr));
 		data->header = data->mmap_base;
 		data->mmap_used_length = data->header->used_file_size;
 
@@ -319,7 +320,7 @@
 	data->index = index;
 	data->fd = fd;
 
-	if (!mmap_update(data, 0, sizeof(MailIndexDataHeader))) {
+	if (!mmap_update(data, 0, sizeof(struct mail_index_data_header))) {
 		mail_index_data_free(data);
 		return FALSE;
 	}
@@ -328,7 +329,7 @@
 	return TRUE;
 }
 
-void mail_index_data_free(MailIndexData *data)
+void mail_index_data_free(struct mail_index_data *data)
 {
 	data->index->data = NULL;
 
@@ -338,16 +339,16 @@
 	i_free(data);
 }
 
-int mail_index_data_reset(MailIndexData *data)
+int mail_index_data_reset(struct mail_index_data *data)
 {
-	MailIndexDataHeader hdr;
+	struct mail_index_data_header hdr;
 
-	memset(&hdr, 0, sizeof(MailIndexDataHeader));
+	memset(&hdr, 0, sizeof(struct mail_index_data_header));
 	hdr.indexid = data->index->indexid;
-	hdr.used_file_size = sizeof(MailIndexDataHeader);
+	hdr.used_file_size = sizeof(struct mail_index_data_header);
 
 	if (data->anon_mmap) {
-		memcpy(data->mmap_base, &hdr, sizeof(MailIndexDataHeader));
+		memcpy(data->mmap_base, &hdr, sizeof(hdr));
 		return TRUE;
 	}
 
@@ -360,7 +361,7 @@
 	if (lseek(data->fd, 0, SEEK_SET) < 0)
 		return index_data_set_syscall_error(data, "lseek()");
 
-	if (write_full(data->fd, &hdr, sizeof(MailIndexDataHeader)) < 0) {
+	if (write_full(data->fd, &hdr, sizeof(hdr)) < 0) {
 		if (errno == ENOSPC)
 			data->index->nodiskspace = TRUE;
 		return index_data_set_syscall_error(data, "write_full()");
@@ -371,25 +372,26 @@
 	return mmap_update(data, 0, 0);
 }
 
-int mail_index_data_mark_file_deleted(MailIndexData *data)
+int mail_index_data_mark_file_deleted(struct mail_index_data *data)
 {
 	if (data->anon_mmap)
 		return TRUE;
 
 	data->header->indexid = 0;
-	if (msync(data->mmap_base, sizeof(MailIndexDataHeader), MS_SYNC) < 0)
+	if (msync(data->mmap_base,
+		  sizeof(struct mail_index_data_header), MS_SYNC) < 0)
 		return index_data_set_syscall_error(data, "msync()");
 
 	data->fsynced = FALSE;
 	return TRUE;
 }
 
-void mail_index_data_mark_modified(MailIndexData *data)
+void mail_index_data_mark_modified(struct mail_index_data *data)
 {
 	data->modified = TRUE;
 }
 
-static int mail_index_data_grow(MailIndexData *data, size_t size)
+static int mail_index_data_grow(struct mail_index_data *data, size_t size)
 {
 	void *base;
 	uoff_t new_fsize;
@@ -427,7 +429,7 @@
 		return TRUE;
 	}
 
-	if (pos < (int)sizeof(MailIndexDataHeader))
+	if (pos < (off_t)sizeof(struct mail_index_data_header))
 		return index_data_set_corrupted(data, "Header is missing");
 
 	if (file_set_size(data->fd, (off_t)new_fsize) < 0) {
@@ -439,7 +441,7 @@
 	return mmap_update(data, 0, 0);
 }
 
-uoff_t mail_index_data_append(MailIndexData *data, const void *buffer,
+uoff_t mail_index_data_append(struct mail_index_data *data, const void *buffer,
 			      size_t size)
 {
 	uoff_t offset;
@@ -447,7 +449,7 @@
 	i_assert((size & (MEM_ALIGN_SIZE-1)) == 0);
 	i_assert(data->index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
-	if (!mmap_update(data, 0, sizeof(MailIndexDataHeader)))
+	if (!mmap_update(data, 0, sizeof(struct mail_index_data_header)))
 		return 0;
 
 	if (size > data->mmap_full_length ||
@@ -466,9 +468,10 @@
 	return offset;
 }
 
-int mail_index_data_delete(MailIndexData *data, MailIndexRecord *index_rec)
+int mail_index_data_delete(struct mail_index_data *data,
+			   struct mail_index_record *index_rec)
 {
-        MailIndexDataRecordHeader *rec_hdr;
+        struct mail_index_data_record_header *rec_hdr;
 	uoff_t max_del_space;
 
 	i_assert(data->index->lock_type == MAIL_LOCK_EXCLUSIVE);
@@ -482,8 +485,8 @@
 
 	/* clear the record data. not really needed, but better not to keep
 	   deleted information lying around.. */
-	memset((char *) rec_hdr + sizeof(MailIndexDataRecordHeader), 0,
-	       rec_hdr->data_size - sizeof(MailIndexDataRecordHeader));
+	memset((char *) rec_hdr + sizeof(*rec_hdr), 0,
+	       rec_hdr->data_size - sizeof(*rec_hdr));
 
 	/* see if we've reached the max. deleted space in file */
 	if (data->header->used_file_size >= COMPRESS_MIN_SIZE &&
@@ -498,7 +501,7 @@
 	return TRUE;
 }
 
-int mail_index_data_sync_file(MailIndexData *data, int *fsync_fd)
+int mail_index_data_sync_file(struct mail_index_data *data, int *fsync_fd)
 {
 	*fsync_fd = -1;
 
@@ -520,8 +523,9 @@
 	return TRUE;
 }
 
-MailIndexDataRecordHeader *
-mail_index_data_lookup_header(MailIndexData *data, MailIndexRecord *index_rec)
+struct mail_index_data_record_header *
+mail_index_data_lookup_header(struct mail_index_data *data,
+			      struct mail_index_record *index_rec)
 {
 	uoff_t pos;
 
@@ -531,14 +535,17 @@
 		return NULL;
 	}
 
-	if (!mmap_update(data, pos, sizeof(MailIndexDataRecordHeader)))
+	if (!mmap_update(data, pos,
+			 sizeof(struct mail_index_data_record_header)))
 		return NULL;
 
-	if (pos + sizeof(MailIndexDataRecordHeader) > data->mmap_used_length) {
+	if (pos + sizeof(struct mail_index_data_record_header) >
+	    data->mmap_used_length) {
 		index_data_set_corrupted(data,
 			"Data position of record %u points outside file "
 			"(%"PRIuUOFF_T" + %"PRIuSIZE_T" > %"PRIuSIZE_T")",
-			index_rec->uid, pos, sizeof(MailIndexDataRecordHeader),
+			index_rec->uid, pos,
+			sizeof(struct mail_index_data_record_header),
 			data->mmap_used_length);
 		return NULL;
 	}
@@ -550,15 +557,17 @@
 		return NULL;
 	}
 
-	return (MailIndexDataRecordHeader *) ((char *) data->mmap_base + pos);
+	return (struct mail_index_data_record_header *)
+		((char *) data->mmap_base + pos);
 }
 
-MailIndexDataRecord *
-mail_index_data_lookup(MailIndexData *data, MailIndexRecord *index_rec,
-		       MailDataField field)
+struct mail_index_data_record *
+mail_index_data_lookup(struct mail_index_data *data,
+		       struct mail_index_record *index_rec,
+		       enum mail_data_field field)
 {
-        MailIndexDataRecordHeader *rec_hdr;
-	MailIndexDataRecord *rec;
+        struct mail_index_data_record_header *rec_hdr;
+	struct mail_index_data_record *rec;
 	uoff_t pos, max_pos;
 
 	index_reset_error(data->index);
@@ -588,12 +597,13 @@
 		return NULL;
 	}
 
-	pos += sizeof(MailIndexDataRecordHeader);
+	pos += sizeof(struct mail_index_data_record_header);
 	do {
-		rec = (MailIndexDataRecord *) ((char *) data->mmap_base + pos);
+		rec = (struct mail_index_data_record *)
+			((char *) data->mmap_base + pos);
 
 		if (rec->full_field_size > max_pos ||
-		    pos + sizeof(MailIndexDataRecord) > max_pos ||
+		    pos + sizeof(struct mail_index_data_record) > max_pos ||
 		    pos + DATA_RECORD_SIZE(rec) > max_pos) {
 			index_data_set_corrupted(data,
 				"Field %d size points outside file "
@@ -626,11 +636,12 @@
 	return NULL;
 }
 
-MailIndexDataRecord *
-mail_index_data_next(MailIndexData *data, MailIndexRecord *index_rec,
-		     MailIndexDataRecord *rec)
+struct mail_index_data_record *
+mail_index_data_next(struct mail_index_data *data,
+		     struct mail_index_record *index_rec,
+		     struct mail_index_data_record *rec)
 {
-        MailIndexDataRecordHeader *rec_hdr;
+        struct mail_index_data_record_header *rec_hdr;
 	uoff_t pos, end_pos, max_pos;
 
 	index_reset_error(data->index);
@@ -638,8 +649,8 @@
 	if (rec == NULL)
 		return NULL;
 
-	rec_hdr = (MailIndexDataRecordHeader *) ((char *) data->mmap_base +
-						 index_rec->data_position);
+	rec_hdr = (struct mail_index_data_record_header *)
+		((char *) data->mmap_base + index_rec->data_position);
 
 	/* get position to next record */
 	pos = DATA_FILE_POSITION(data, rec) + DATA_RECORD_SIZE(rec);
@@ -649,7 +660,8 @@
 	if (pos >= max_pos)
 		return NULL;
 
-	rec = (MailIndexDataRecord *) ((char *) data->mmap_base + pos);
+	rec = (struct mail_index_data_record *)
+		((char *) data->mmap_base + pos);
 	end_pos = pos + DATA_RECORD_SIZE(rec);
 	if (end_pos < pos || end_pos > max_pos) {
 		index_data_set_corrupted(data, "Field size points outside file "
@@ -661,7 +673,8 @@
 	return rec;
 }
 
-int mail_index_data_record_verify(MailIndexData *data, MailIndexDataRecord *rec)
+int mail_index_data_record_verify(struct mail_index_data *data,
+				  struct mail_index_data_record *rec)
 {
 	int i;
 
@@ -687,7 +700,7 @@
 	return FALSE;
 }
 
-void *mail_index_data_get_mmaped(MailIndexData *data, size_t *size)
+void *mail_index_data_get_mmaped(struct mail_index_data *data, size_t *size)
 {
 	if (!mmap_update(data, 0, 0))
 		return NULL;

Index: mail-index-data.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-data.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- mail-index-data.h	21 Dec 2002 22:39:15 -0000	1.12
+++ mail-index-data.h	5 Jan 2003 13:09:52 -0000	1.13
@@ -3,57 +3,61 @@
 
 #define DATA_FILE_PREFIX ".data"
 
-int mail_index_data_open(MailIndex *index);
-int mail_index_data_create(MailIndex *index);
-void mail_index_data_free(MailIndexData *data);
+int mail_index_data_open(struct mail_index *index);
+int mail_index_data_create(struct mail_index *index);
+void mail_index_data_free(struct mail_index_data *data);
 
 /* Truncate the data file and update it's indexid */
-int mail_index_data_reset(MailIndexData *data);
+int mail_index_data_reset(struct mail_index_data *data);
 
 /* Set indexid to 0 to notify other processes using this file that they should
    re-open it. */
-int mail_index_data_mark_file_deleted(MailIndexData *data);
+int mail_index_data_mark_file_deleted(struct mail_index_data *data);
 
 /* Mark the file as being modified */
-void mail_index_data_mark_modified(MailIndexData *data);
+void mail_index_data_mark_modified(struct mail_index_data *data);
 
 /* Append new data at the end of the file. Returns the position in file
    where the data begins, or 0 if error occured. */
-uoff_t mail_index_data_append(MailIndexData *data, const void *buffer,
+uoff_t mail_index_data_append(struct mail_index_data *data, const void *buffer,
 			      size_t size);
 
 /* Mark the given record deleted. */
-int mail_index_data_delete(MailIndexData *data, MailIndexRecord *index_rec);
+int mail_index_data_delete(struct mail_index_data *data,
+			   struct mail_index_record *index_rec);
 
 /* Synchronize the data into disk */
-int mail_index_data_sync_file(MailIndexData *data, int *fsync_fd);
+int mail_index_data_sync_file(struct mail_index_data *data, int *fsync_fd);
 
 /* Looks up a record header from data file. Returns NULL if not found or
    if error occured. */
-MailIndexDataRecordHeader *
-mail_index_data_lookup_header(MailIndexData *data, MailIndexRecord *index_rec);
+struct mail_index_data_record_header *
+mail_index_data_lookup_header(struct mail_index_data *data,
+			      struct mail_index_record *index_rec);
 
 /* Looks up a field from data file. If field is 0, returns the first field
    found. Returns NULL if not found or if error occured. */
-MailIndexDataRecord *
-mail_index_data_lookup(MailIndexData *data, MailIndexRecord *index_rec,
-		       MailDataField field);
+struct mail_index_data_record *
+mail_index_data_lookup(struct mail_index_data *data,
+		       struct mail_index_record *index_rec,
+		       enum mail_data_field field);
 
 /* Returns the next record in data file, or NULL if there's no more. */
-MailIndexDataRecord *
-mail_index_data_next(MailIndexData *data, MailIndexRecord *index_rec,
-		     MailIndexDataRecord *rec);
+struct mail_index_data_record *
+mail_index_data_next(struct mail_index_data *data,
+		     struct mail_index_record *index_rec,
+		     struct mail_index_data_record *rec);
 
 /* Returns TRUE if rec->data is a valid \0-terminated string */
-int mail_index_data_record_verify(MailIndexData *data,
-				  MailIndexDataRecord *rec);
+int mail_index_data_record_verify(struct mail_index_data *data,
+				  struct mail_index_data_record *rec);
 
 /* Return the whole data file mmap()ed. */
-void *mail_index_data_get_mmaped(MailIndexData *data, size_t *size);
+void *mail_index_data_get_mmaped(struct mail_index_data *data, size_t *size);
 
 /* "Error in index data file %s: ...". Also marks the index file as
    corrupted. */
-int index_data_set_corrupted(MailIndexData *data, const char *fmt, ...)
+int index_data_set_corrupted(struct mail_index_data *data, const char *fmt, ...)
 	__attr_format__(2, 3);
 
 #endif

Index: mail-index-fsck.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-fsck.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- mail-index-fsck.c	21 Dec 2002 10:58:25 -0000	1.11
+++ mail-index-fsck.c	5 Jan 2003 13:09:52 -0000	1.12
@@ -10,9 +10,9 @@
 			  index->filepath, old_hdr->field, new_hdr->field);
 
 
-static void print_differences(MailIndex *index,
-			      MailIndexHeader *old_hdr,
-			      MailIndexHeader *new_hdr)
+static void print_differences(struct mail_index *index,
+			      struct mail_index_header *old_hdr,
+			      struct mail_index_header *new_hdr)
 {
 	if (old_hdr->first_hole_index != new_hdr->first_hole_index) {
 		i_warning("fsck %s: first_hole_position %u != %u",
@@ -46,13 +46,12 @@
 	}
 }
 
-int mail_index_fsck(MailIndex *index)
+int mail_index_fsck(struct mail_index *index)
 {
 	/* we verify only the fields in the header. other problems will be
 	   noticed and fixed while reading the messages. */
-	MailIndexHeader old_hdr;
-	MailIndexHeader *hdr;
-	MailIndexRecord *rec, *end_rec;
+	struct mail_index_header old_hdr, *hdr;
+	struct mail_index_record *rec, *end_rec;
 	unsigned int max_uid, pos;
 
 	i_assert(index->lock_type != MAIL_LOCK_SHARED);
@@ -61,7 +60,7 @@
 		return FALSE;
 
 	hdr = index->header;
-	memcpy(&old_hdr, hdr, sizeof(MailIndexHeader));
+	memcpy(&old_hdr, hdr, sizeof(struct mail_index_header));
 
 	hdr->first_hole_index = 0;
 	hdr->first_hole_records = 0;
@@ -73,10 +72,8 @@
 	hdr->first_unseen_uid_lowwater = 0;
 	hdr->first_deleted_uid_lowwater = 0;
 
-	rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				   sizeof(MailIndexHeader));
-	end_rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				       index->mmap_used_length);
+	rec = INDEX_RECORD_AT(index, 0);
+	end_rec = INDEX_END_RECORD(index);
 
 	max_uid = 0;
 	for (; rec < end_rec; rec++) {

Index: mail-index-open.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-open.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- mail-index-open.c	2 Jan 2003 11:29:24 -0000	1.22
+++ mail-index-open.c	5 Jan 2003 13:09:52 -0000	1.23
@@ -46,14 +46,14 @@
 	return TRUE;
 }
 
-static int read_and_verify_header(int fd, MailIndexHeader *hdr,
+static int read_and_verify_header(int fd, struct mail_index_header *hdr,
 				  int check_version)
 {
 	/* read the header */
 	if (lseek(fd, 0, SEEK_SET) != 0)
 		return FALSE;
 
-	if (read(fd, hdr, sizeof(MailIndexHeader)) != sizeof(MailIndexHeader))
+	if (read(fd, hdr, sizeof(*hdr)) != sizeof(*hdr))
 		return FALSE;
 
 	/* check the compatibility */
@@ -67,9 +67,10 @@
 
 /* Returns TRUE if we're compatible with given index file. May delete the
    file if it's from older version. */
-static int mail_check_compatible_index(MailIndex *index, const char *path)
+static int mail_check_compatible_index(struct mail_index *index,
+				       const char *path)
 {
-        MailIndexHeader hdr;
+        struct mail_index_header hdr;
 	int fd, compatible;
 
 	fd = open(path, O_RDONLY);
@@ -94,7 +95,7 @@
 }
 
 /* Returns a file name of compatible index */
-static const char *mail_find_index(MailIndex *index)
+static const char *mail_find_index(struct mail_index *index)
 {
 	const char *name;
 	char path[PATH_MAX];
@@ -116,9 +117,9 @@
 	return NULL;
 }
 
-static int mail_index_open_init(MailIndex *index, int update_recent)
+static int mail_index_open_init(struct mail_index *index, int update_recent)
 {
-	MailIndexHeader *hdr;
+	struct mail_index_header *hdr;
 
 	hdr = index->header;
 
@@ -155,7 +156,8 @@
 	return TRUE;
 }
 
-static int index_open_and_fix(MailIndex *index, int update_recent, int fast)
+static int index_open_and_fix(struct mail_index *index,
+			      int update_recent, int fast)
 {
 	int rebuild;
 
@@ -247,7 +249,8 @@
 	return TRUE;
 }
 
-static int mail_index_verify_header(MailIndex *index, MailIndexHeader *hdr)
+static int mail_index_verify_header(struct mail_index *index,
+				    struct mail_index_header *hdr)
 {
 	/* if index is being created, we'll wait here until it's finished */
 	if (!mail_index_wait_lock(index, F_RDLCK))
@@ -267,10 +270,10 @@
 	return TRUE;
 }
 
-static int mail_index_open_file(MailIndex *index, const char *path,
+static int mail_index_open_file(struct mail_index *index, const char *path,
 				int update_recent, int fast)
 {
-        MailIndexHeader hdr;
+        struct mail_index_header hdr;
 
 	/* the index file should already be checked that it exists and
 	   we're compatible with it. */
@@ -301,7 +304,8 @@
 	return TRUE;
 }
 
-static int mail_index_init_new_file(MailIndex *index, MailIndexHeader *hdr,
+static int mail_index_init_new_file(struct mail_index *index,
+				    struct mail_index_header *hdr,
 				    const char *temp_path)
 {
 	const char *index_path;
@@ -310,14 +314,14 @@
 	/* set the index's path temporarily */
 	index->filepath = t_strdup_noconst(temp_path);
 
-	if (write_full(index->fd, hdr, sizeof(MailIndexHeader)) < 0) {
+	if (write_full(index->fd, hdr, sizeof(struct mail_index_header)) < 0) {
 		index_set_syscall_error(index, "write_full()");
 		index->filepath = NULL;
 		return FALSE;
 	}
 
-	fsize = sizeof(MailIndexHeader) +
-		INDEX_MIN_RECORDS_COUNT * sizeof(MailIndexRecord);
+	fsize = sizeof(struct mail_index_header) +
+		INDEX_MIN_RECORDS_COUNT * sizeof(struct mail_index_record);
 	if (file_set_size(index->fd, fsize) < 0) {
 		index_set_syscall_error(index, "file_set_size()");
 		index->filepath = NULL;
@@ -371,10 +375,10 @@
 	return TRUE;
 }
 
-static int mail_index_create(MailIndex *index, int *dir_unlocked,
+static int mail_index_create(struct mail_index *index, int *dir_unlocked,
 			     int update_recent)
 {
-	MailIndexHeader hdr;
+	struct mail_index_header hdr;
 	const char *path;
 	int nodiskspace;
 
@@ -477,9 +481,10 @@
 	return FALSE;
 }
 
-void mail_index_init_header(MailIndex *index, MailIndexHeader *hdr)
+void mail_index_init_header(struct mail_index *index,
+			    struct mail_index_header *hdr)
 {
-	memset(hdr, 0, sizeof(MailIndexHeader));
+	memset(hdr, 0, sizeof(struct mail_index_header));
 	hdr->compat_data[0] = MAIL_INDEX_VERSION;
 	hdr->compat_data[1] = MAIL_INDEX_COMPAT_FLAGS;
 	hdr->compat_data[2] = sizeof(unsigned int);
@@ -495,7 +500,7 @@
 	/* set the fields we always want to cache */
 	hdr->cache_fields |= index->default_cache_fields;
 
-	hdr->used_file_size = sizeof(MailIndexHeader);
+	hdr->used_file_size = sizeof(struct mail_index_header);
 	hdr->uid_validity = ioloop_time;
 	hdr->next_uid = 1;
 }
@@ -506,7 +511,7 @@
 			 "temp.", time(NULL) - TEMP_FILE_TIMEOUT);
 }
 
-void mail_index_init(MailIndex *index, const char *dir)
+void mail_index_init(struct mail_index *index, const char *dir)
 {
 	size_t len;
 
@@ -520,7 +525,7 @@
 	index->mail_read_mmaped = getenv("MAIL_READ_MMAPED") != NULL;
 }
 
-int mail_index_open(MailIndex *index, int update_recent, int fast)
+int mail_index_open(struct mail_index *index, int update_recent, int fast)
 {
 	const char *name, *path;
 
@@ -543,7 +548,8 @@
 	return TRUE;
 }
 
-int mail_index_open_or_create(MailIndex *index, int update_recent, int fast)
+int mail_index_open_or_create(struct mail_index *index,
+			      int update_recent, int fast)
 {
 	int failed, dir_unlocked;
 

Index: mail-index-update-cache.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-update-cache.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- mail-index-update-cache.c	6 Dec 2002 01:09:22 -0000	1.12
+++ mail-index-update-cache.c	5 Jan 2003 13:09:52 -0000	1.13
@@ -6,11 +6,11 @@
 
 #include <unistd.h>
 
-static int cache_record(MailIndex *index, MailIndexRecord *rec,
-			MailDataField cache_fields)
+static int cache_record(struct mail_index *index, struct mail_index_record *rec,
+			enum mail_data_field cache_fields)
 {
-	MailIndexUpdate *update;
-	IStream *input;
+	struct mail_index_update *update;
+	struct istream *input;
 	time_t internal_date;
 	int failed, deleted;
 
@@ -30,10 +30,10 @@
 	return !failed;
 }
 
-int mail_index_update_cache(MailIndex *index)
+int mail_index_update_cache(struct mail_index *index)
 {
-	MailIndexRecord *rec;
-	MailDataField cache_fields;
+	struct mail_index_record *rec;
+	enum mail_data_field cache_fields;
 
 	if (!index->set_lock(index, MAIL_LOCK_EXCLUSIVE))
 		return FALSE;
@@ -42,7 +42,8 @@
 
 	rec = index->lookup(index, 1);
 	while (rec != NULL) {
-		if ((rec->data_fields & cache_fields) != cache_fields) {
+		if (((enum mail_data_field)rec->data_fields & cache_fields) !=
+		    cache_fields) {
 			t_push();
 			if (!cache_record(index, rec, cache_fields)) {
 				t_pop();

Index: mail-index-update.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-update.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- mail-index-update.c	4 Jan 2003 17:26:30 -0000	1.43
+++ mail-index-update.c	5 Jan 2003 13:09:52 -0000	1.44
@@ -4,7 +4,7 @@
 #include "buffer.h"
 #include "istream.h"
 #include "ioloop.h"
-#include "rfc822-date.h"
+#include "message-date.h"
 #include "message-parser.h"
 #include "message-part-serialize.h"
 #include "message-size.h"
@@ -14,12 +14,12 @@
 #include "mail-index-data.h"
 #include "mail-index-util.h"
 
-struct _MailIndexUpdate {
-	Pool pool;
+struct mail_index_update {
+	pool_t pool;
 
-	MailIndex *index;
-	MailIndexRecord *rec;
-	MailIndexDataRecordHeader data_hdr;
+	struct mail_index *index;
+	struct mail_index_record *rec;
+	struct mail_index_data_record_header data_hdr;
 
 	unsigned int updated_fields;
 	void *fields[DATA_FIELD_MAX_BITS];
@@ -27,17 +27,18 @@
 	size_t field_extra_sizes[DATA_FIELD_MAX_BITS];
 };
 
-MailIndexUpdate *mail_index_update_begin(MailIndex *index, MailIndexRecord *rec)
+struct mail_index_update *
+mail_index_update_begin(struct mail_index *index, struct mail_index_record *rec)
 {
-	Pool pool;
-	MailIndexUpdate *update;
-	MailIndexDataRecordHeader *data_hdr;
+	pool_t pool;
+	struct mail_index_update *update;
+	struct mail_index_data_record_header *data_hdr;
 
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
-	pool = pool_alloconly_create("MailIndexUpdate", 4096);
+	pool = pool_alloconly_create("mail_index_update", 4096);
 
-	update = p_new(pool, MailIndexUpdate, 1);
+	update = p_new(pool, struct mail_index_update, 1);
 	update->pool = pool;
 	update->index = index;
 	update->rec = rec;
@@ -48,7 +49,7 @@
 	return update;
 }
 
-static int mail_field_get_index(MailDataField field)
+static int mail_field_get_index(enum mail_data_field field)
 {
 	unsigned int i, mask;
 
@@ -60,16 +61,16 @@
 	return -1;
 }
 
-static void get_data_block_sizes(MailIndexUpdate *update,
+static void get_data_block_sizes(struct mail_index_update *update,
 				 size_t *min_size, size_t *max_size,
 				 int *no_grown_fields)
 {
-	MailIndexDataRecord *rec;
-	MailDataField field;
+	struct mail_index_data_record *rec;
+	enum mail_data_field field;
 	unsigned int field_min_size;
 	int i, field_exists;
 
-	*min_size = *max_size = sizeof(MailIndexDataRecordHeader);
+	*min_size = *max_size = sizeof(struct mail_index_data_record_header);
 	*no_grown_fields = TRUE;
 
 	rec = mail_index_data_lookup(update->index->data, update->rec, 0);
@@ -124,13 +125,13 @@
 
 /* extra_size is the amount of data in data_size which can be used for
    field_extra_sizes */
-static void *create_data_block(MailIndexUpdate *update, size_t data_size,
-			       size_t extra_size)
+static void *create_data_block(struct mail_index_update *update,
+			       size_t data_size, size_t extra_size)
 {
-        MailIndexDataRecordHeader *dest_hdr;
-        MailIndexDataRecord *rec, *destrec;
-	MailDataField field;
-	Buffer *buf;
+        struct mail_index_data_record_header *dest_hdr;
+        struct mail_index_data_record *rec, *destrec;
+	enum mail_data_field field;
+	buffer_t *buf;
 	const void *src;
 	size_t src_size;
 	size_t full_field_size;
@@ -184,8 +185,8 @@
 
 /* Append all the data at the end of the data file and update 
    the index's data position */
-static int update_by_append(MailIndexUpdate *update, size_t data_size,
-			    size_t extra_size)
+static int update_by_append(struct mail_index_update *update,
+			    size_t data_size, size_t extra_size)
 {
 	void *mem;
 	uoff_t fpos;
@@ -207,9 +208,10 @@
 }
 
 /* Replace the whole block - assumes there's enough space to do it */
-static void update_by_replace_block(MailIndexUpdate *update, size_t extra_size)
+static void update_by_replace_block(struct mail_index_update *update,
+				    size_t extra_size)
 {
-	MailIndexDataRecordHeader *data_hdr;
+	struct mail_index_data_record_header *data_hdr;
 	size_t data_size;
 	void *mem;
 
@@ -231,10 +233,10 @@
 
 /* Replace the modified fields in the file - assumes there's enough
    space to do it */
-static void update_by_replace_fields(MailIndexUpdate *update)
+static void update_by_replace_fields(struct mail_index_update *update)
 {
-	MailIndexDataRecordHeader *data_hdr;
-	MailIndexDataRecord *rec;
+	struct mail_index_data_record_header *data_hdr;
+	struct mail_index_data_record *rec;
 	size_t field_size;
 	int index;
 
@@ -267,9 +269,9 @@
         mail_index_data_mark_modified(update->index->data);
 }
 
-int mail_index_update_end(MailIndexUpdate *update)
+int mail_index_update_end(struct mail_index_update *update)
 {
-	MailIndexDataRecordHeader *data_hdr;
+	struct mail_index_data_record_header *data_hdr;
 	size_t min_size, max_size, extra_size;
 	int no_grown_fields, failed = FALSE;
 
@@ -304,7 +306,8 @@
 	return !failed;
 }
 
-static void update_field_full(MailIndexUpdate *update, MailDataField field,
+static void update_field_full(struct mail_index_update *update,
+			      enum mail_data_field field,
 			      const void *value, size_t size,
 			      size_t extra_space)
 {
@@ -320,7 +323,8 @@
 	memcpy(update->fields[index], value, size);
 }
 
-static void update_header_field(MailIndexUpdate *update, MailDataField field,
+static void update_header_field(struct mail_index_update *update,
+				enum mail_data_field field,
 				const void *value, size_t size __attr_unused__)
 {
 	switch (field) {
@@ -347,13 +351,15 @@
 	update->updated_fields |= field;
 }
 
-void mail_index_update_field(MailIndexUpdate *update, MailDataField field,
+void mail_index_update_field(struct mail_index_update *update,
+			     enum mail_data_field field,
 			     const char *value, size_t extra_space)
 {
 	update_field_full(update, field, value, strlen(value) + 1, extra_space);
 }
 
-void mail_index_update_field_raw(MailIndexUpdate *update, MailDataField field,
+void mail_index_update_field_raw(struct mail_index_update *update,
+				 enum mail_data_field field,
 				 const void *value, size_t size)
 {
 	if (field >= DATA_FIELD_LAST)
@@ -362,21 +368,21 @@
 		update_field_full(update, field, value, size, 0);
 }
 
-typedef struct {
-	MailIndexUpdate *update;
-	Pool envelope_pool;
-	MessagePartEnvelopeData *envelope;
+struct header_update_context {
+	struct mail_index_update *update;
+	pool_t envelope_pool;
+	struct message_part_envelope_data *envelope;
 
 	MessageHeaderFunc header_func;
 	void *context;
-} HeaderUpdateContext;
+};
 
-static void update_header_func(MessagePart *part,
+static void update_header_func(struct message_part *part,
 			       const unsigned char *name, size_t name_len,
 			       const unsigned char *value, size_t value_len,
 			       void *context)
 {
-	HeaderUpdateContext *ctx = context;
+	struct header_update_context *ctx = context;
 
 	if (part != NULL && part->parent != NULL)
 		return;
@@ -397,15 +403,16 @@
 	}
 }
 
-void mail_index_update_headers(MailIndexUpdate *update, IStream *input,
-                               MailDataField cache_fields,
+void mail_index_update_headers(struct mail_index_update *update,
+			       struct istream *input,
+                               enum mail_data_field cache_fields,
 			       MessageHeaderFunc header_func, void *context)
 {
-	HeaderUpdateContext ctx;
-	MessagePart *part;
-	MessageSize hdr_size, body_size;
-	Pool pool;
-	Buffer *buf;
+	struct header_update_context ctx;
+	struct message_part *part;
+	struct message_size hdr_size, body_size;
+	pool_t pool;
+	buffer_t *buf;
 	const char *value;
 	size_t size;
 	uoff_t start_offset;

Index: mail-index-util.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-util.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- mail-index-util.c	18 Dec 2002 01:52:14 -0000	1.17
+++ mail-index-util.c	5 Jan 2003 13:09:52 -0000	1.18
@@ -12,7 +12,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-int index_set_error(MailIndex *index, const char *fmt, ...)
+int index_set_error(struct mail_index *index, const char *fmt, ...)
 {
 	va_list va;
 
@@ -31,7 +31,7 @@
 	return FALSE;
 }
 
-int index_set_corrupted(MailIndex *index, const char *fmt, ...)
+int index_set_corrupted(struct mail_index *index, const char *fmt, ...)
 {
 	va_list va;
 
@@ -48,7 +48,7 @@
 	return FALSE;
 }
 
-int index_set_syscall_error(MailIndex *index, const char *function)
+int index_set_syscall_error(struct mail_index *index, const char *function)
 {
 	i_assert(function != NULL);
 
@@ -57,7 +57,7 @@
 	return FALSE;
 }
 
-int index_file_set_syscall_error(MailIndex *index, const char *filepath,
+int index_file_set_syscall_error(struct mail_index *index, const char *filepath,
 				 const char *function)
 {
 	i_assert(filepath != NULL);
@@ -69,7 +69,7 @@
 	return FALSE;
 }
 
-void index_reset_error(MailIndex *index)
+void index_reset_error(struct mail_index *index)
 {
 	if (index->error != NULL) {
 		i_free(index->error);
@@ -79,7 +79,7 @@
 	index->nodiskspace = FALSE;
 }
 
-int mail_index_create_temp_file(MailIndex *index, const char **path)
+int mail_index_create_temp_file(struct mail_index *index, const char **path)
 {
 	int fd;
 
@@ -109,7 +109,7 @@
 
 static void mail_index_lock_notify(unsigned int secs_left, void *context)
 {
-	MailIndex *index = context;
+	struct mail_index *index = context;
 
 	if (index->lock_notify_func == NULL)
 		return;
@@ -118,7 +118,7 @@
 				secs_left, index->lock_notify_context);
 }
 
-int mail_index_wait_lock(MailIndex *index, int lock_type)
+int mail_index_wait_lock(struct mail_index *index, int lock_type)
 {
 	int ret;
 

Index: mail-index-util.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-util.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- mail-index-util.h	21 Dec 2002 22:39:15 -0000	1.9
+++ mail-index-util.h	5 Jan 2003 13:09:52 -0000	1.10
@@ -16,28 +16,28 @@
 #endif
 
 /* Set the current error message */
-int index_set_error(MailIndex *index, const char *fmt, ...)
+int index_set_error(struct mail_index *index, const char *fmt, ...)
 	__attr_format__(2, 3);
 
 /* "Error in index file %s: ...". Also marks the index file as corrupted. */
-int index_set_corrupted(MailIndex *index, const char *fmt, ...)
+int index_set_corrupted(struct mail_index *index, const char *fmt, ...)
 	__attr_format__(2, 3);
 
 /* "%s failed with index file %s: %m" */
-int index_set_syscall_error(MailIndex *index, const char *function);
+int index_set_syscall_error(struct mail_index *index, const char *function);
 
 /* "%s failed with file %s: %m" */
-int index_file_set_syscall_error(MailIndex *index, const char *filepath,
+int index_file_set_syscall_error(struct mail_index *index, const char *filepath,
 				 const char *function);
 
 /* Reset the current error */
-void index_reset_error(MailIndex *index);
+void index_reset_error(struct mail_index *index);
 
 /* Create temporary file into index's directory. Returns opened file handle
    and sets *path to the full path of the created file.  */
-int mail_index_create_temp_file(MailIndex *index, const char **path);
+int mail_index_create_temp_file(struct mail_index *index, const char **path);
 
 /* Wrapper to file_set_lock(), also calling index's lock notify callback. */
-int mail_index_wait_lock(MailIndex *index, int lock_type);
+int mail_index_wait_lock(struct mail_index *index, int lock_type);
 
 #endif

Index: mail-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- mail-index.c	4 Jan 2003 17:45:09 -0000	1.79
+++ mail-index.c	5 Jan 2003 13:09:52 -0000	1.80
@@ -16,20 +16,20 @@
 #include <fcntl.h>
 #include <utime.h>
 
-static int mmap_verify(MailIndex *index)
+static int mmap_verify(struct mail_index *index)
 {
-	MailIndexHeader *hdr;
+	struct mail_index_header *hdr;
 	unsigned int extra;
 
 	index->mmap_used_length = 0;
 
-	if (index->mmap_full_length < sizeof(MailIndexHeader)) {
+	if (index->mmap_full_length < sizeof(struct mail_index_header)) {
                 index_set_corrupted(index, "File too small");
 		return FALSE;
 	}
 
-	extra = (index->mmap_full_length - sizeof(MailIndexHeader)) %
-		sizeof(MailIndexRecord);
+	extra = (index->mmap_full_length - sizeof(struct mail_index_header)) %
+		sizeof(struct mail_index_record);
 
 	if (extra != 0) {
 		/* partial write or corrupted -
@@ -53,8 +53,8 @@
 		return FALSE;
 	}
 
-	if ((hdr->used_file_size - sizeof(MailIndexHeader)) %
-	    sizeof(MailIndexRecord) != 0) {
+	if ((hdr->used_file_size - sizeof(struct mail_index_header)) %
+	    sizeof(struct mail_index_record) != 0) {
 		index_set_corrupted(index, "Invalid used_file_size in header "
 				    "(%"PRIuUOFF_T")",
 				    hdr->used_file_size);
@@ -80,13 +80,13 @@
 	return TRUE;
 }
 
-int mail_index_mmap_update(MailIndex *index)
+int mail_index_mmap_update(struct mail_index *index)
 {
 	if (index->anon_mmap)
 		return mmap_verify(index);
 
 	if (index->mmap_base != NULL) {
-		index->header = (MailIndexHeader *) index->mmap_base;
+		index->header = (struct mail_index_header *) index->mmap_base;
 
 		/* make sure file size hasn't changed */
 		if (index->header->sync_id == index->sync_id) {
@@ -117,7 +117,7 @@
 	return mmap_verify(index);
 }
 
-void mail_index_close(MailIndex *index)
+void mail_index_close(struct mail_index *index)
 {
 	index->set_flags = 0;
 	index->set_cache_fields = 0;
@@ -175,7 +175,7 @@
 	}
 }
 
-static int mail_index_sync_file(MailIndex *index)
+static int mail_index_sync_file(struct mail_index *index)
 {
 	unsigned int i;
 	int failed, fsync_fds[3];
@@ -215,7 +215,7 @@
 	return !failed;
 }
 
-static void mail_index_update_timestamp(MailIndex *index)
+static void mail_index_update_timestamp(struct mail_index *index)
 {
 	struct utimbuf ut;
 
@@ -226,7 +226,7 @@
 		index_set_syscall_error(index, "utime()");
 }
 
-int mail_index_fmdatasync(MailIndex *index, size_t size)
+int mail_index_fmdatasync(struct mail_index *index, size_t size)
 {
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
@@ -240,7 +240,7 @@
 	return TRUE;
 }
 
-static void mail_index_update_header_changes(MailIndex *index)
+static void mail_index_update_header_changes(struct mail_index *index)
 {
 	if (index->set_flags != 0) {
 		index->header->flags |= index->set_flags;
@@ -253,7 +253,7 @@
 	}
 }
 
-static int mail_index_write_header_changes(MailIndex *index)
+static int mail_index_write_header_changes(struct mail_index *index)
 {
 	int failed;
 
@@ -269,7 +269,8 @@
 
 	mail_index_update_header_changes(index);
 
-	failed = msync(index->mmap_base, sizeof(MailIndexHeader), MS_SYNC) < 0;
+	failed = msync(index->mmap_base,
+		       sizeof(struct mail_index_header), MS_SYNC) < 0;
 	if (failed)
 		index_set_syscall_error(index, "msync()");
 
@@ -283,9 +284,9 @@
 	return !failed;
 }
 
-static int mail_index_lock_remove(MailIndex *index)
+static int mail_index_lock_remove(struct mail_index *index)
 {
-	MailLockType old_lock_type;
+	enum mail_lock_type old_lock_type;
 
 	if (!mail_index_wait_lock(index, F_UNLCK))
 		return FALSE;
@@ -297,7 +298,7 @@
 		/* releasing shared lock. we may need to update some
 		   flags in header. */
 		unsigned int old_flags;
-		MailDataField old_cache;
+		enum mail_data_field old_cache;
 
 		old_flags = index->header->flags;
 		old_cache = index->header->cache_fields;
@@ -311,8 +312,8 @@
 	return TRUE;
 }
 
-static int mail_index_lock_change(MailIndex *index, MailLockType lock_type,
-				  int try_lock)
+static int mail_index_lock_change(struct mail_index *index,
+				  enum mail_lock_type lock_type, int try_lock)
 {
 	int ret, fd_lock_type;
 
@@ -390,7 +391,8 @@
 		   when the lock is released, the FSCK flag will also be
 		   removed. */
 		index->header->flags |= MAIL_INDEX_FLAG_FSCK;
-		if (!mail_index_fmdatasync(index, sizeof(MailIndexHeader))) {
+		if (!mail_index_fmdatasync(index,
+					   sizeof(struct mail_index_header))) {
 			(void)index->set_lock(index, MAIL_LOCK_UNLOCK);
 			return FALSE;
 		}
@@ -399,8 +401,8 @@
 	return TRUE;
 }
 
-static int mail_index_lock_full(MailIndex *index, MailLockType lock_type,
-				int try_lock)
+static int mail_index_lock_full(struct mail_index *index,
+				enum mail_lock_type lock_type, int try_lock)
 {
 	int keep_fsck;
 
@@ -428,7 +430,8 @@
 		/* remove the FSCK flag only after successful fsync() */
 		if (mail_index_sync_file(index) && !keep_fsck) {
 			index->header->flags &= ~MAIL_INDEX_FLAG_FSCK;
-			if (msync(index->mmap_base, sizeof(MailIndexHeader),
+			if (msync(index->mmap_base,
+				  sizeof(struct mail_index_header),
 				  MS_SYNC) < 0) {
 				/* we only failed to remove the fsck flag,
 				   so this isn't fatal. */
@@ -445,27 +448,26 @@
 		return mail_index_lock_change(index, lock_type, try_lock);
 }
 
-int mail_index_set_lock(MailIndex *index, MailLockType lock_type)
+int mail_index_set_lock(struct mail_index *index, enum mail_lock_type lock_type)
 {
 	return mail_index_lock_full(index, lock_type, FALSE);
 }
 
-int mail_index_try_lock(MailIndex *index, MailLockType lock_type)
+int mail_index_try_lock(struct mail_index *index, enum mail_lock_type lock_type)
 {
 	return mail_index_lock_full(index, lock_type, TRUE);
 }
 
-void mail_index_set_lock_notify_callback(MailIndex *index,
-					 MailLockNotifyFunc func,
-					 void *context)
+void mail_index_set_lock_notify_callback(struct mail_index *index,
+					 MailLockNotifyFunc func, void *context)
 {
 	index->lock_notify_func = func;
 	index->lock_notify_context = context;
 }
 
-int mail_index_verify_hole_range(MailIndex *index)
+int mail_index_verify_hole_range(struct mail_index *index)
 {
-	MailIndexHeader *hdr;
+	struct mail_index_header *hdr;
 	unsigned int max_records;
 
 	hdr = index->header;
@@ -489,17 +491,18 @@
 	return TRUE;
 }
 
-MailIndexHeader *mail_index_get_header(MailIndex *index)
+struct mail_index_header *mail_index_get_header(struct mail_index *index)
 {
 	i_assert(index->lock_type != MAIL_LOCK_UNLOCK);
 
 	return index->header;
 }
 
-MailIndexRecord *mail_index_lookup(MailIndex *index, unsigned int seq)
+struct mail_index_record *mail_index_lookup(struct mail_index *index,
+					    unsigned int seq)
 {
-	MailIndexHeader *hdr;
-	MailIndexRecord *rec;
+	struct mail_index_header *hdr;
+	struct mail_index_record *rec;
 	const char *error;
 	unsigned int idx;
 
@@ -547,8 +550,7 @@
 		return NULL;
 	}
 
-	rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				   sizeof(MailIndexHeader)) + idx;
+	rec = INDEX_RECORD_AT(index, idx);
 	if (rec->uid == 0) {
 		index_set_corrupted(index, "%s", error);
 		return NULL;
@@ -557,19 +559,19 @@
 	return rec;
 }
 
-MailIndexRecord *mail_index_next(MailIndex *index, MailIndexRecord *rec)
+struct mail_index_record *mail_index_next(struct mail_index *index,
+					  struct mail_index_record *rec)
 {
-	MailIndexRecord *end_rec;
+	struct mail_index_record *end_rec;
 
 	i_assert(index->lock_type != MAIL_LOCK_UNLOCK);
-	i_assert(rec >= (MailIndexRecord *) index->mmap_base);
+	i_assert(rec >= (struct mail_index_record *) index->mmap_base);
 
 	if (rec == NULL)
 		return NULL;
 
 	/* go to the next non-deleted record */
-	end_rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				       index->mmap_used_length);
+	end_rec = INDEX_END_RECORD(index);
 	while (++rec < end_rec) {
 		if (rec->uid != 0)
 			return rec;
@@ -578,12 +580,11 @@
 	return NULL;
 }
 
-MailIndexRecord *mail_index_lookup_uid_range(MailIndex *index,
-					     unsigned int first_uid,
-					     unsigned int last_uid,
-					     unsigned int *seq_r)
+struct mail_index_record *
+mail_index_lookup_uid_range(struct mail_index *index, unsigned int first_uid,
+			    unsigned int last_uid, unsigned int *seq_r)
 {
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 	unsigned int idx;
 
 	i_assert(index->lock_type != MAIL_LOCK_UNLOCK);
@@ -604,8 +605,7 @@
 		return NULL;
 	}
 
-	rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				   sizeof(MailIndexHeader)) + idx;
+	rec = INDEX_RECORD_AT(index, idx);
 	if (rec->uid < first_uid || rec->uid > last_uid) {
 		index_set_error(index, "Corrupted binary tree for index %s: "
 				"lookup returned offset to wrong UID "
@@ -618,10 +618,11 @@
 	return rec;
 }
 
-const char *mail_index_lookup_field(MailIndex *index, MailIndexRecord *rec,
-				    MailDataField field)
+const char *mail_index_lookup_field(struct mail_index *index,
+				    struct mail_index_record *rec,
+				    enum mail_data_field field)
 {
-	MailIndexDataRecord *datarec;
+	struct mail_index_data_record *datarec;
 
 	datarec = (rec->data_fields & field) == 0 ? NULL :
 		mail_index_data_lookup(index->data, rec, field);
@@ -636,11 +637,13 @@
 	return datarec->data;
 }
 
-const void *mail_index_lookup_field_raw(MailIndex *index, MailIndexRecord *rec,
-					MailDataField field, size_t *size)
+const void *mail_index_lookup_field_raw(struct mail_index *index,
+					struct mail_index_record *rec,
+					enum mail_data_field field,
+					size_t *size)
 {
-	MailIndexDataRecordHeader *datahdr;
-	MailIndexDataRecord *datarec;
+	struct mail_index_data_record_header *datahdr;
+	struct mail_index_data_record *datarec;
 
 	if ((rec->data_fields & field) == 0) {
 		*size = 0;
@@ -685,7 +688,8 @@
 	}
 }
 
-void mail_index_cache_fields_later(MailIndex *index, MailDataField field)
+void mail_index_cache_fields_later(struct mail_index *index,
+				   enum mail_data_field field)
 {
 	i_assert(index->lock_type != MAIL_LOCK_UNLOCK);
 
@@ -707,7 +711,8 @@
 	}
 }
 
-time_t mail_get_internal_date(MailIndex *index, MailIndexRecord *rec)
+time_t mail_get_internal_date(struct mail_index *index,
+			      struct mail_index_record *rec)
 {
 	const time_t *date;
 	size_t size;
@@ -722,8 +727,10 @@
 	}
 }
 
-void mail_index_mark_flag_changes(MailIndex *index, MailIndexRecord *rec,
-				  MailFlags old_flags, MailFlags new_flags)
+void mail_index_mark_flag_changes(struct mail_index *index,
+				  struct mail_index_record *rec,
+				  enum mail_flags old_flags,
+				  enum mail_flags new_flags)
 {
 	if ((old_flags & MAIL_SEEN) == 0 && (new_flags & MAIL_SEEN)) {
 		/* unseen -> seen */
@@ -766,28 +773,25 @@
 	}
 }
 
-static void update_first_hole_records(MailIndex *index)
+static void update_first_hole_records(struct mail_index *index)
 {
-        MailIndexRecord *rec, *end_rec;
+        struct mail_index_record *rec, *end_rec;
 
 	/* see if first_hole_records can be grown */
-	rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				   sizeof(MailIndexHeader)) +
-		index->header->first_hole_index +
-		index->header->first_hole_records;
-	end_rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				       index->mmap_used_length);
+	rec = INDEX_RECORD_AT(index, index->header->first_hole_index +
+			      index->header->first_hole_records);
+	end_rec = INDEX_END_RECORD(index);
 	while (rec < end_rec && rec->uid == 0) {
 		index->header->first_hole_records++;
 		rec++;
 	}
 }
 
-static int mail_index_truncate_hole(MailIndex *index)
+static int mail_index_truncate_hole(struct mail_index *index)
 {
-	index->header->used_file_size = sizeof(MailIndexHeader) +
+	index->header->used_file_size = sizeof(struct mail_index_header) +
 		(uoff_t)index->header->first_hole_index *
-		sizeof(MailIndexRecord);
+		sizeof(struct mail_index_record);
 	index->header->first_hole_index = 0;
 	index->header->first_hole_records = 0;
 
@@ -809,10 +813,10 @@
 	 (records) * (100-INDEX_COMPRESS_PERCENTAGE) / 100 > \
 	 	(hdr)->messages_count)
 
-int mail_index_expunge(MailIndex *index, MailIndexRecord *rec,
+int mail_index_expunge(struct mail_index *index, struct mail_index_record *rec,
 		       unsigned int seq, int external_change)
 {
-	MailIndexHeader *hdr;
+	struct mail_index_header *hdr;
 	unsigned int records, uid, idx;
 
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
@@ -891,8 +895,9 @@
 	return TRUE;
 }
 
-int mail_index_update_flags(MailIndex *index, MailIndexRecord *rec,
-			    unsigned int seq, MailFlags flags,
+int mail_index_update_flags(struct mail_index *index,
+			    struct mail_index_record *rec,
+			    unsigned int seq, enum mail_flags flags,
 			    int external_change)
 {
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
@@ -909,7 +914,7 @@
 					 rec->uid, external_change);
 }
 
-static int mail_index_grow(MailIndex *index)
+static int mail_index_grow(struct mail_index *index)
 {
 	uoff_t pos;
 	unsigned int grow_count;
@@ -920,7 +925,8 @@
 	if (grow_count < 16)
 		grow_count = 16;
 
-	pos = index->mmap_full_length + (grow_count * sizeof(MailIndexRecord));
+	pos = index->mmap_full_length +
+		(grow_count * sizeof(struct mail_index_record));
 	i_assert(pos < OFF_T_MAX);
 
 	if (index->anon_mmap) {
@@ -952,9 +958,9 @@
 	return TRUE;
 }
 
-MailIndexRecord *mail_index_append_begin(MailIndex *index)
+struct mail_index_record *mail_index_append_begin(struct mail_index *index)
 {
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
@@ -964,20 +970,21 @@
 	}
 
 	i_assert(index->header->used_file_size == index->mmap_used_length);
-	i_assert(index->mmap_used_length + sizeof(MailIndexRecord) <=
+	i_assert(index->mmap_used_length + sizeof(struct mail_index_record) <=
 		 index->mmap_full_length);
 
-	rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				   index->mmap_used_length);
-	memset(rec, 0, sizeof(MailIndexRecord));
+	rec = (struct mail_index_record *) ((char *) index->mmap_base +
+					    index->mmap_used_length);
+	memset(rec, 0, sizeof(struct mail_index_record));
 
-	index->header->used_file_size += sizeof(MailIndexRecord);
-	index->mmap_used_length += sizeof(MailIndexRecord);
+	index->header->used_file_size += sizeof(struct mail_index_record);
+	index->mmap_used_length += sizeof(struct mail_index_record);
 
 	return rec;
 }
 
-int mail_index_append_end(MailIndex *index, MailIndexRecord *rec)
+int mail_index_append_end(struct mail_index *index,
+			  struct mail_index_record *rec)
 {
 	i_assert(rec->uid == 0);
 
@@ -999,7 +1006,7 @@
 	return TRUE;
 }
 
-MailIndexError mail_index_get_last_error(MailIndex *index)
+enum mail_index_error mail_index_get_last_error(struct mail_index *index)
 {
 	if (index->inconsistent)
 		return MAIL_INDEX_ERROR_INCONSISTENT;
@@ -1016,7 +1023,7 @@
 	return MAIL_INDEX_ERROR_NONE;
 }
 
-const char *mail_index_get_last_error_text(MailIndex *index)
+const char *mail_index_get_last_error_text(struct mail_index *index)
 {
 	return index->error;
 }

Index: mail-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- mail-index.h	4 Jan 2003 17:45:09 -0000	1.60
+++ mail-index.h	5 Jan 2003 13:09:52 -0000	1.61
@@ -4,15 +4,15 @@
 #include "message-parser.h"
 #include "imap-util.h"
 
-#define MAIL_INDEX_VERSION 1
+#define MAIL_INDEX_VERSION 2
 
 #define INDEX_FILE_PREFIX ".imap.index"
 
-enum {
+enum mail_index_header_compat {
 	MAIL_INDEX_COMPAT_LITTLE_ENDIAN	= 0x01
 };
 
-enum {
+enum mail_index_header_flag {
 	/* Rebuild flag is set while index is being rebuilt or when
 	   some error is noticed in the index file. If this flag is set,
 	   the index shouldn't be used before rebuilding it. */
@@ -26,30 +26,29 @@
 	MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS	= 0x80
 };
 
-/* Use macros instead of enum so highest bit can be used without kludging */
-#define DATA_FIELD_LOCATION		0x00000001
-#define DATA_FIELD_ENVELOPE		0x00000002
-#define DATA_FIELD_BODY			0x00000004
-#define DATA_FIELD_BODYSTRUCTURE	0x00000008
-#define DATA_FIELD_MD5			0x00000010
-#define DATA_FIELD_MESSAGEPART		0x00000020
-
-#define DATA_FIELD_LAST			0x00000040
-#define DATA_FIELD_MAX_BITS		6
+enum mail_data_field {
+	DATA_FIELD_LOCATION		= 0x00000001,
+	DATA_FIELD_ENVELOPE		= 0x00000002,
+	DATA_FIELD_BODY			= 0x00000004,
+	DATA_FIELD_BODYSTRUCTURE	= 0x00000008,
+	DATA_FIELD_MD5			= 0x00000010,
+	DATA_FIELD_MESSAGEPART		= 0x00000020,
 
-/* separate from above, but in same bitmask */
-#define DATA_HDR_INTERNAL_DATE		0x80000000
-#define DATA_HDR_VIRTUAL_SIZE		0x40000000
-#define DATA_HDR_HEADER_SIZE		0x20000000
-#define DATA_HDR_BODY_SIZE		0x10000000
+	DATA_FIELD_LAST			= 0x00000040,
+	DATA_FIELD_MAX_BITS		= 6,
 
-typedef unsigned int MailDataField;
+	/* separate from above, but in same bitmask */
+	DATA_HDR_INTERNAL_DATE		= 0x40000000,
+	DATA_HDR_VIRTUAL_SIZE		= 0x20000000,
+	DATA_HDR_HEADER_SIZE		= 0x10000000,
+	DATA_HDR_BODY_SIZE		= 0x08000000
+};
 
 #define IS_BODYSTRUCTURE_FIELD(field) \
 	(((field) & (DATA_FIELD_BODY | DATA_FIELD_BODYSTRUCTURE | \
 		     DATA_FIELD_MESSAGEPART)) != 0)
 
-typedef enum {
+enum mail_index_mail_flag {
 	/* If binary flags are set, it's not checked whether mail is
 	   missing CRs. So this flag may be set as an optimization for
 	   regular non-binary mails as well if it's known that it contains
@@ -60,24 +59,24 @@
 	/* Currently this means with mbox format that message flags have
 	   been changed in index, but not written into mbox file yet. */
 	INDEX_MAIL_FLAG_DIRTY		= 0x0004
-} MailIndexMailFlags;
+};
 
-typedef enum {
+enum mail_lock_type {
 	MAIL_LOCK_UNLOCK = 0,
 	MAIL_LOCK_SHARED,
 	MAIL_LOCK_EXCLUSIVE
-} MailLockType;
+};
 
-typedef enum {
+enum mail_lock_notify_type {
 	/* Mailbox is locked, will abort in secs_left */
 	MAIL_LOCK_NOTIFY_MAILBOX_ABORT,
 	/* Mailbox lock looks stale, will override in secs_left */
 	MAIL_LOCK_NOTIFY_MAILBOX_OVERRIDE,
 	/* Index is locked, will abort in secs_left */
 	MAIL_LOCK_NOTIFY_INDEX_ABORT
-} MailLockNotifyType;
+};
 
-typedef enum {
+enum mail_index_error {
 	/* No errors */
 	MAIL_INDEX_ERROR_NONE,
 	/* Internal error, see get_error_text() for more information. */
@@ -94,27 +93,12 @@
 	MAIL_INDEX_ERROR_INDEX_LOCK_TIMEOUT,
 	/* Mailbox locking timeouted */
 	MAIL_INDEX_ERROR_MAILBOX_LOCK_TIMEOUT
-} MailIndexError;
+};
 
-typedef void (*MailLockNotifyFunc)(MailLockNotifyType notify_type,
+typedef void (*MailLockNotifyFunc)(enum mail_lock_notify_type notify_type,
 				   unsigned int secs_left, void *context);
 
-typedef struct _MailIndex MailIndex;
-typedef struct _MailIndexData MailIndexData;
-typedef struct _MailTree MailTree;
-typedef struct _MailModifyLog MailModifyLog;
-typedef struct _MailCustomFlags MailCustomFlags;
-
-typedef struct _MailIndexHeader MailIndexHeader;
-typedef struct _MailIndexDataHeader MailIndexDataHeader;
-
-typedef struct _MailIndexRecord MailIndexRecord;
-typedef struct _MailIndexDataRecord MailIndexDataRecord;
-typedef struct _MailIndexDataRecordHeader MailIndexDataRecordHeader;
-
-typedef struct _MailIndexUpdate MailIndexUpdate;
-
-struct _MailIndexHeader {
+struct mail_index_header {
 	unsigned char compat_data[8];
 	/* 0 = version
 	   1 = flags,
@@ -148,7 +132,7 @@
 	unsigned int first_deleted_uid_lowwater;
 };
 
-struct _MailIndexDataHeader {
+struct mail_index_data_header {
 	unsigned int indexid;
 	unsigned int reserved; /* for alignment mostly */
 
@@ -156,17 +140,17 @@
 	uoff_t deleted_space;
 };
 
-struct _MailIndexRecord {
+struct mail_index_record {
 	unsigned int uid;
-	unsigned int msg_flags; /* MailFlags */
+	unsigned int msg_flags; /* enum mail_flags */
 
-	unsigned int index_flags; /* MailIndexMailFlags */
-	unsigned int data_fields; /* MailDataField */
+	unsigned int index_flags; /* enum mail_index_mail_flag */
+	unsigned int data_fields; /* enum mail_data_field */
 
 	uoff_t data_position;
 };
 
-struct _MailIndexDataRecordHeader {
+struct mail_index_data_record_header {
 	unsigned int data_size; /* including this header */
 
 	time_t internal_date;
@@ -176,29 +160,30 @@
 	uoff_t body_size;
 };
 
-struct _MailIndexDataRecord {
-	unsigned int field; /* MailDataField */
+struct mail_index_data_record {
+	unsigned int field; /* enum mail_data_field */
 	unsigned int full_field_size;
 	char data[MEM_ALIGN_SIZE]; /* variable size */
 };
 
 #define SIZEOF_MAIL_INDEX_DATA \
-	(sizeof(MailIndexDataRecord) - MEM_ALIGN_SIZE)
+	(sizeof(struct mail_index_data_record) - MEM_ALIGN_SIZE)
 
 #define DATA_RECORD_SIZE(rec) \
         (SIZEOF_MAIL_INDEX_DATA + (rec)->full_field_size)
 
-struct _MailIndex {
+struct mail_index {
 	/* If fast is TRUE, compressing and cache updates are not performed.
 	   Note that opening same index twice in the same process is a bad
 	   idea since they share the same file locks. As soon one of the
 	   indexes is closed, the locks in second index are dropped which
 	   especially hurts modify log since it keeps locks all the time. */
-	int (*open)(MailIndex *index, int update_recent, int fast);
-	int (*open_or_create)(MailIndex *index, int update_recent, int fast);
+	int (*open)(struct mail_index *index, int update_recent, int fast);
+	int (*open_or_create)(struct mail_index *index,
+			      int update_recent, int fast);
 
 	/* Free index from memory. */
-	void (*free)(MailIndex *index);
+	void (*free)(struct mail_index *index);
 
 	/* Lock/unlock index. May block. Note that unlocking must not
 	   reset error from get_last_error() as unlocking can be done as
@@ -212,16 +197,18 @@
 	   data to be updated later, b) use try_lock() if the update is
 	   preferred but not required, c) unlock + lock again, but make
 	   sure that won't create race conditions. */
-	int (*set_lock)(MailIndex *index, MailLockType lock_type);
+	int (*set_lock)(struct mail_index *index,
+			enum mail_lock_type lock_type);
 
 	/* Try locking the index. Returns TRUE if the lock was got and
 	   FALSE if lock isn't possible to get currently or some other error
 	   occured. Never blocks. */
-	int (*try_lock)(MailIndex *index, MailLockType lock_type);
+	int (*try_lock)(struct mail_index *index,
+			enum mail_lock_type lock_type);
 
 	/* If we have to wait for the lock, the given lock notify function
 	   is called once in a while. */
-	void (*set_lock_notify_callback)(MailIndex *index,
+	void (*set_lock_notify_callback)(struct mail_index *index,
 					 MailLockNotifyFunc func,
 					 void *context);
 
@@ -230,66 +217,74 @@
 	   Index MUST NOT have shared lock, but exclusive lock or no lock at
 	   all is fine. Note that this function may leave the index
 	   exclusively locked, and always sets index->inconsistent = TRUE. */
-	int (*rebuild)(MailIndex *index);
+	int (*rebuild)(struct mail_index *index);
 
 	/* Verify that the index is valid. If anything invalid is found,
 	   index is set inconsistent and to be rebuilt at next open.
 	   Same locking issues as with rebuild(). */
-	int (*fsck)(MailIndex *index);
+	int (*fsck)(struct mail_index *index);
 
 	/* Synchronize the index with the mailbox. Index must not have shared
 	   lock when calling this function. The data_lock_type specifies what
 	   lock should be set to data file (mbox file). This function may
 	   leave the index in ANY locking state. If changes is non-NULL, it's
 	   set to TRUE if any changes were noticed. */
-	int (*sync_and_lock)(MailIndex *index, MailLockType data_lock_type,
-			     int *changes);
+	int (*sync_and_lock)(struct mail_index *index,
+			     enum mail_lock_type data_lock_type, int *changes);
 
 	/* Returns the index header (never fails). The index needs to be
 	   locked before calling this function, and must be kept locked as
 	   long as you keep using the returned structure. */
-	MailIndexHeader *(*get_header)(MailIndex *index);
+	struct mail_index_header *(*get_header)(struct mail_index *index);
 
 	/* sequence -> data lookup. The index needs to be locked before calling
 	   this function, and must be kept locked as long as you keep using
 	   the returned structure. */
-	MailIndexRecord *(*lookup)(MailIndex *index, unsigned int seq);
+	struct mail_index_record *(*lookup)(struct mail_index *index,
+					    unsigned int seq);
 
 	/* Return the next record after specified record, or NULL if it was
 	   last record. The index must be locked all the time between
 	   lookup() and last next() call. */
-	MailIndexRecord *(*next)(MailIndex *index, MailIndexRecord *rec);
+	struct mail_index_record *(*next)(struct mail_index *index,
+					  struct mail_index_record *rec);
 
 	/* Find first existing UID in range. Sequence number is also retrieved
 	   if seq_r is non-NULL. */
-	MailIndexRecord *(*lookup_uid_range)(MailIndex *index,
-					     unsigned int first_uid,
-					     unsigned int last_uid,
-					     unsigned int *seq_r);
+	struct mail_index_record *(*lookup_uid_range)(struct mail_index *index,
+						      unsigned int first_uid,
+						      unsigned int last_uid,
+						      unsigned int *seq_r);
 
 	/* Find field from specified record, or NULL if it's not in index.
 	   Makes sure that the field ends with \0. */
-	const char *(*lookup_field)(MailIndex *index, MailIndexRecord *rec,
-				    MailDataField field);
+	const char *(*lookup_field)(struct mail_index *index,
+				    struct mail_index_record *rec,
+				    enum mail_data_field field);
 
 	/* Find field from specified record, or NULL if it's not in index. */
-	const void *(*lookup_field_raw)(MailIndex *index, MailIndexRecord *rec,
-					MailDataField field, size_t *size);
+	const void *(*lookup_field_raw)(struct mail_index *index,
+					struct mail_index_record *rec,
+					enum mail_data_field field,
+					size_t *size);
 
 	/* Mark the fields to be cached later. If any of them is already
 	   set in hdr->cache_fields, mark the caching to happen next time
 	   index is opened. */
-	void (*cache_fields_later)(MailIndex *index, MailDataField field);
+	void (*cache_fields_later)(struct mail_index *index,
+				   enum mail_data_field field);
 
 	/* Open mail file and return it as mmap()ed IStream. If we fail,
 	   we return NULL and set deleted = TRUE if failure was because the
 	   mail was just deleted (ie. not an error). internal_date is set
 	   if it's non-NULL. */
-	IStream *(*open_mail)(MailIndex *index, MailIndexRecord *rec,
-			      time_t *internal_date, int *deleted);
+	struct istream *(*open_mail)(struct mail_index *index,
+				     struct mail_index_record *rec,
+				     time_t *internal_date, int *deleted);
 
 	/* Returns internal date of message, or (time_t)-1 if error occured. */
-	time_t (*get_internal_date)(MailIndex *index, MailIndexRecord *rec);
+	time_t (*get_internal_date)(struct mail_index *index,
+				    struct mail_index_record *rec);
 
 	/* Expunge a mail from index. Tree and modifylog is also updated. The
 	   index must be exclusively locked before calling this function.
@@ -301,21 +296,23 @@
 	   Note that the sequence numbers also update immediately after this
 	   call, so if you want to delete messages 1..4 just call this
 	   function 4 times with seq being 1. */
-	int (*expunge)(MailIndex *index, MailIndexRecord *rec,
+	int (*expunge)(struct mail_index *index, struct mail_index_record *rec,
 		       unsigned int seq, int external_change);
 
 	/* Update mail flags. The index must be exclusively locked before
 	   calling this function. This shouldn't be called in the middle of
 	   update_begin() as it may modify location field. */
-	int (*update_flags)(MailIndex *index, MailIndexRecord *rec,
-			    unsigned int seq, MailFlags flags,
+	int (*update_flags)(struct mail_index *index,
+			    struct mail_index_record *rec,
+			    unsigned int seq, enum mail_flags flags,
 			    int external_change);
 
 	/* Append a new record to index. The index must be exclusively
 	   locked before calling this function. rec->uid is updated in
 	   append_end(). */
-	MailIndexRecord *(*append_begin)(MailIndex *index);
-	int (*append_end)(MailIndex *index, MailIndexRecord *rec);
+	struct mail_index_record *(*append_begin)(struct mail_index *index);
+	int (*append_end)(struct mail_index *index,
+			  struct mail_index_record *rec);
 
 	/* Updating fields happens by calling update_begin(), one or more
 	   update_field()s and finally update_end() which does the actual
@@ -330,40 +327,43 @@
 
 	   The files may not actually be updated until after you've unlocked
 	   the file. */
-	MailIndexUpdate *(*update_begin)(MailIndex *index,
-					 MailIndexRecord *rec);
-	int (*update_end)(MailIndexUpdate *update);
+	struct mail_index_update *
+		(*update_begin)(struct mail_index *index,
+				struct mail_index_record *rec);
+	int (*update_end)(struct mail_index_update *update);
 
-	void (*update_field)(MailIndexUpdate *update, MailDataField field,
+	void (*update_field)(struct mail_index_update *update,
+			     enum mail_data_field field,
 			     const char *value, size_t extra_space);
 	/* Just remember that full_field_size will be MEM_ALIGNed, so
 	   it may differer from the given size parameter. */
-	void (*update_field_raw)(MailIndexUpdate *update, MailDataField field,
+	void (*update_field_raw)(struct mail_index_update *update,
+				 enum mail_data_field field,
 				 const void *value, size_t size);
 
 	/* Returns the last error code. */
-	MailIndexError (*get_last_error)(MailIndex *index);
+	enum mail_index_error (*get_last_error)(struct mail_index *index);
 
 	/* Returns the full error message for last error. This message may
 	   contain paths etc. so it shouldn't be shown to users. */
-	const char *(*get_last_error_text)(MailIndex *index);
+	const char *(*get_last_error_text)(struct mail_index *index);
 
 /* private: */
-	MailIndexData *data;
-	MailTree *tree;
-	MailModifyLog *modifylog;
-	MailCustomFlags *custom_flags;
+	struct mail_index_data *data;
+	struct mail_tree *tree;
+	struct mail_modify_log *modifylog;
+	struct mail_custom_flags *custom_flags;
 
 	char *dir; /* directory where to place the index files */
 	char *filepath; /* index file path */
 	char *mailbox_path; /* file/directory for mailbox location */
-	MailDataField default_cache_fields, never_cache_fields;
+	enum mail_data_field default_cache_fields, never_cache_fields;
 	unsigned int indexid;
 	unsigned int sync_id;
 
 	int mbox_fd;
-	IStream *mbox_stream;
-	MailLockType mbox_lock_type;
+	struct istream *mbox_stream;
+	enum mail_lock_type mbox_lock_type;
 	dev_t mbox_dotlock_dev;
 	ino_t mbox_dotlock_ino;
 
@@ -384,9 +384,9 @@
 	size_t mmap_used_length;
 	size_t mmap_full_length;
 
-	MailIndexHeader *header;
+	struct mail_index_header *header;
 
-        MailLockType lock_type;
+        enum mail_lock_type lock_type;
 	time_t file_sync_stamp;
 	unsigned int first_recent_uid;
 
@@ -396,7 +396,7 @@
 	/* these fields are OR'ed to the fields in index header once we
 	   get around grabbing exclusive lock */
 	unsigned int set_flags;
-	MailDataField set_cache_fields;
+	enum mail_data_field set_cache_fields;
 
 	unsigned int anon_mmap:1;
 	unsigned int opened:1;
@@ -424,60 +424,78 @@
 #endif
 
 /* defaults - same as above but prefixed with mail_index_. */
-int mail_index_open(MailIndex *index, int update_recent, int fast);
-int mail_index_open_or_create(MailIndex *index, int update_recent, int fast);
-int mail_index_set_lock(MailIndex *index, MailLockType lock_type);
-int mail_index_try_lock(MailIndex *index, MailLockType lock_type);
-void mail_index_set_lock_notify_callback(MailIndex *index,
+int mail_index_open(struct mail_index *index, int update_recent, int fast);
+int mail_index_open_or_create(struct mail_index *index,
+			      int update_recent, int fast);
+int mail_index_set_lock(struct mail_index *index,
+			enum mail_lock_type lock_type);
+int mail_index_try_lock(struct mail_index *index,
+			enum mail_lock_type lock_type);
+void mail_index_set_lock_notify_callback(struct mail_index *index,
 					 MailLockNotifyFunc func,
 					 void *context);
-int mail_index_fsck(MailIndex *index);
-MailIndexHeader *mail_index_get_header(MailIndex *index);
-MailIndexRecord *mail_index_lookup(MailIndex *index, unsigned int seq);
-MailIndexRecord *mail_index_next(MailIndex *index, MailIndexRecord *rec);
-MailIndexRecord *mail_index_lookup_uid_range(MailIndex *index,
-					     unsigned int first_uid,
-					     unsigned int last_uid,
-					     unsigned int *seq_r);
-const char *mail_index_lookup_field(MailIndex *index, MailIndexRecord *rec,
-				    MailDataField field);
-const void *mail_index_lookup_field_raw(MailIndex *index, MailIndexRecord *rec,
-					MailDataField field, size_t *size);
-void mail_index_cache_fields_later(MailIndex *index, MailDataField field);
-int mail_index_expunge(MailIndex *index, MailIndexRecord *rec,
+int mail_index_fsck(struct mail_index *index);
+struct mail_index_header *mail_index_get_header(struct mail_index *index);
+struct mail_index_record *mail_index_lookup(struct mail_index *index,
+					    unsigned int seq);
+struct mail_index_record *mail_index_next(struct mail_index *index,
+					  struct mail_index_record *rec);
+struct mail_index_record *
+mail_index_lookup_uid_range(struct mail_index *index, unsigned int first_uid,
+			    unsigned int last_uid, unsigned int *seq_r);
+const char *mail_index_lookup_field(struct mail_index *index,
+				    struct mail_index_record *rec,
+				    enum mail_data_field field);
+const void *mail_index_lookup_field_raw(struct mail_index *index,
+					struct mail_index_record *rec,
+					enum mail_data_field field,
+					size_t *size);
+void mail_index_cache_fields_later(struct mail_index *index,
+				   enum mail_data_field field);
+int mail_index_expunge(struct mail_index *index, struct mail_index_record *rec,
 		       unsigned int seq, int external_change);
-int mail_index_update_flags(MailIndex *index, MailIndexRecord *rec,
-			    unsigned int seq, MailFlags flags,
+int mail_index_update_flags(struct mail_index *index,
+			    struct mail_index_record *rec,
+			    unsigned int seq, enum mail_flags flags,
 			    int external_change);
-MailIndexRecord *mail_index_append_begin(MailIndex *index);
-int mail_index_append_end(MailIndex *index, MailIndexRecord *rec);
-MailIndexUpdate *mail_index_update_begin(MailIndex *index,
-					 MailIndexRecord *rec);
-int mail_index_update_end(MailIndexUpdate *update);
-void mail_index_update_field(MailIndexUpdate *update, MailDataField field,
+struct mail_index_record *mail_index_append_begin(struct mail_index *index);
+int mail_index_append_end(struct mail_index *index,
+			  struct mail_index_record *rec);
+struct mail_index_update *
+mail_index_update_begin(struct mail_index *index,
+			struct mail_index_record *rec);
+int mail_index_update_end(struct mail_index_update *update);
+void mail_index_update_field(struct mail_index_update *update,
+			     enum mail_data_field field,
 			     const char *value, size_t extra_space);
-void mail_index_update_field_raw(MailIndexUpdate *update, MailDataField field,
+void mail_index_update_field_raw(struct mail_index_update *update,
+				 enum mail_data_field field,
 				 const void *value, size_t size);
-time_t mail_get_internal_date(MailIndex *index, MailIndexRecord *rec);
-MailIndexError mail_index_get_last_error(MailIndex *index);
-const char *mail_index_get_last_error_text(MailIndex *index);
+time_t mail_get_internal_date(struct mail_index *index,
+			      struct mail_index_record *rec);
+enum mail_index_error mail_index_get_last_error(struct mail_index *index);
+const char *mail_index_get_last_error_text(struct mail_index *index);
 
 /* INTERNAL: */
-void mail_index_init(MailIndex *index, const char *dir);
-int mail_index_mmap_update(MailIndex *index);
-void mail_index_init_header(MailIndex *index, MailIndexHeader *hdr);
-void mail_index_close(MailIndex *index);
-int mail_index_fmdatasync(MailIndex *index, size_t size);
-int mail_index_verify_hole_range(MailIndex *index);
-void mail_index_mark_flag_changes(MailIndex *index, MailIndexRecord *rec,
-				  MailFlags old_flags, MailFlags new_flags);
-void mail_index_update_headers(MailIndexUpdate *update, IStream *input,
-                               MailDataField cache_fields,
+void mail_index_init(struct mail_index *index, const char *dir);
+int mail_index_mmap_update(struct mail_index *index);
+void mail_index_init_header(struct mail_index *index,
+			    struct mail_index_header *hdr);
+void mail_index_close(struct mail_index *index);
+int mail_index_fmdatasync(struct mail_index *index, size_t size);
+int mail_index_verify_hole_range(struct mail_index *index);
+void mail_index_mark_flag_changes(struct mail_index *index,
+				  struct mail_index_record *rec,
+				  enum mail_flags old_flags,
+				  enum mail_flags new_flags);
+void mail_index_update_headers(struct mail_index_update *update,
+			       struct istream *input,
+                               enum mail_data_field cache_fields,
 			       MessageHeaderFunc header_func, void *context);
-int mail_index_update_cache(MailIndex *index);
-int mail_index_compress(MailIndex *index);
-int mail_index_compress_data(MailIndex *index);
-int mail_index_truncate(MailIndex *index);
+int mail_index_update_cache(struct mail_index *index);
+int mail_index_compress(struct mail_index *index);
+int mail_index_compress_data(struct mail_index *index);
+int mail_index_truncate(struct mail_index *index);
 
 /* Maximum allowed UID number. */
 #define MAX_ALLOWED_UID 4294967295U /* 2^32 - 1 */
@@ -507,9 +525,20 @@
 #define INDEX_FILE_POSITION(index, ptr) \
 	((uoff_t) ((char *) (ptr) - (char *) ((index)->mmap_base)))
 
+/* record for given index */
+#define INDEX_RECORD_AT(index, idx) \
+	((struct mail_index_record *) \
+	 ((char *) index->mmap_base + sizeof(struct mail_index_header)) + (idx))
+
+/* returns the next record after last one */
+#define INDEX_END_RECORD(index) \
+	((struct mail_index_record *) \
+	 ((char *) (index)->mmap_base + (index)->mmap_used_length))
+
 /* index number for uoff_t position */
 #define INDEX_POSITION_INDEX(pos) \
-	(((pos) - sizeof(MailIndexHeader)) / sizeof(MailIndexRecord))
+	(((pos) - sizeof(struct mail_index_header)) / \
+	 sizeof(struct mail_index_record))
 
 /* index number for given record */
 #define INDEX_RECORD_INDEX(index, ptr) \
@@ -521,15 +550,15 @@
 
 /* get number of records in mmaped index */
 #define MAIL_INDEX_RECORD_COUNT(index) \
-	((index->mmap_used_length - sizeof(MailIndexHeader)) / \
-	 sizeof(MailIndexRecord))
+	((index->mmap_used_length - sizeof(struct mail_index_header)) / \
+	 sizeof(struct mail_index_record))
 
 /* minimum size for index file */
 #define INDEX_FILE_MIN_SIZE \
-	(sizeof(MailIndexHeader) + \
-	 INDEX_MIN_RECORDS_COUNT * sizeof(MailIndexRecord))
+	(sizeof(struct mail_index_header) + \
+	 INDEX_MIN_RECORDS_COUNT * sizeof(struct mail_index_record))
 
-/* MailLockType to fcntl() lock type */
+/* enum mail_lock_type to fcntl() lock type */
 #define MAIL_LOCK_TO_FLOCK(lock_type) \
         ((lock_type) == MAIL_LOCK_EXCLUSIVE ? F_WRLCK : \
 		(lock_type) == MAIL_LOCK_SHARED ? F_RDLCK : F_UNLCK)

Index: mail-lockdir.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-lockdir.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mail-lockdir.c	18 Dec 2002 01:52:14 -0000	1.3
+++ mail-lockdir.c	5 Jan 2003 13:09:52 -0000	1.4
@@ -51,8 +51,8 @@
 	return FALSE;
 }
 
-static int mail_index_unlock_dir(MailIndex *index, const char *private_path,
-				 const char *lockpath)
+static int mail_index_unlock_dir(struct mail_index *index,
+				 const char *private_path, const char *lockpath)
 {
 	struct stat st, lockst;
 
@@ -92,7 +92,8 @@
 	return TRUE;
 }
 
-int mail_index_lock_dir(MailIndex *index, MailLockType lock_type)
+int mail_index_lock_dir(struct mail_index *index,
+			enum mail_lock_type lock_type)
 {
 	struct stat st;
 	const char *private_path, *lockpath;

Index: mail-lockdir.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-lockdir.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- mail-lockdir.h	9 Aug 2002 09:16:13 -0000	1.1.1.1
+++ mail-lockdir.h	5 Jan 2003 13:09:52 -0000	1.2
@@ -2,6 +2,7 @@
 #define __MAIL_LOCKDIR_H
 
 /* Exclusively lock whole directory where index is located. */
-int mail_index_lock_dir(MailIndex *index, MailLockType lock_type);
+int mail_index_lock_dir(struct mail_index *index,
+			enum mail_lock_type lock_type);
 
 #endif

Index: mail-modifylog.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-modifylog.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- mail-modifylog.c	8 Dec 2002 05:23:08 -0000	1.37
+++ mail-modifylog.c	5 Jan 2003 13:09:52 -0000	1.38
@@ -18,9 +18,10 @@
 #define MAX_MODIFYLOG_SIZE (4096*8)
 
 /* How large chunks to use to grow log file */
-#define MODIFYLOG_GROW_SIZE (sizeof(ModifyLogRecord) * 128)
+#define MODIFYLOG_GROW_SIZE (sizeof(struct modify_log_record) * 128)
 
-#define MODIFY_LOG_INITIAL_SIZE (sizeof(ModifyLogHeader) + MODIFYLOG_GROW_SIZE)
+#define MODIFY_LOG_INITIAL_SIZE \
+	(sizeof(struct modify_log_header) + MODIFYLOG_GROW_SIZE)
 
 #define MODIFYLOG_FILE_POSITION(log, ptr) \
 	((size_t) ((char *) (ptr) - (char *) (log)->mmap_base))
@@ -30,10 +31,8 @@
 	((char *) (ptr) >= (char *) (area_ptr) && \
 	 (char *) (ptr) < (char *) (area_ptr) + (area_size))
 
-typedef struct _ModifyLogFile ModifyLogFile;
-
-struct _ModifyLogFile {
-	MailModifyLog *log;
+struct modify_log_file {
+	struct mail_modify_log *log;
 
 	int fd;
 	char *filepath;
@@ -42,10 +41,10 @@
 	size_t mmap_used_length;
 	size_t mmap_full_length;
 
-	ModifyLogRecord *last_expunge, *last_flags;
+	struct modify_log_record *last_expunge, *last_flags;
 	int last_expunge_external, last_flags_external;
 
-	ModifyLogHeader *header;
+	struct modify_log_header *header;
 	uoff_t synced_position;
 	unsigned int synced_id;
 
@@ -54,18 +53,18 @@
 	unsigned int second_log:1;
 };
 
-struct _MailModifyLog {
-	MailIndex *index;
+struct mail_modify_log {
+	struct mail_index *index;
 
-	ModifyLogRecord *iterator_end;
+	struct modify_log_record *iterator_end;
 
-	ModifyLogFile file1, file2;
-	ModifyLogFile *head, *tail;
+	struct modify_log_file file1, file2;
+	struct modify_log_file *head, *tail;
 };
 
-static const ModifyLogExpunge no_expunges = { 0, 0, 0 };
+static const struct modify_log_expunge no_expunges = { 0, 0, 0 };
 
-static int modifylog_set_syscall_error(ModifyLogFile *file,
+static int modifylog_set_syscall_error(struct modify_log_file *file,
 				       const char *function)
 {
 	i_assert(function != NULL);
@@ -76,7 +75,8 @@
 	return FALSE;
 }
 
-static int modifylog_set_corrupted(ModifyLogFile *file, const char *fmt, ...)
+static int modifylog_set_corrupted(struct modify_log_file *file,
+				   const char *fmt, ...)
 {
 	va_list va;
 
@@ -96,7 +96,7 @@
 	return FALSE;
 }
 
-static int modifylog_drop_lock(ModifyLogFile *file)
+static int modifylog_drop_lock(struct modify_log_file *file)
 {
 	int ret;
 
@@ -118,7 +118,8 @@
 	return 1;
 }
 
-static int modifylog_file_have_other_users(ModifyLogFile *file, int keep_lock)
+static int modifylog_file_have_other_users(struct modify_log_file *file,
+					   int keep_lock)
 {
 	int ret;
 
@@ -140,9 +141,10 @@
 }
 
 /* returns 1 = yes, 0 = no, -1 = error */
-static int modifylog_have_other_users(MailModifyLog *log, int keep_lock)
+static int modifylog_have_other_users(struct mail_modify_log *log,
+				      int keep_lock)
 {
-	ModifyLogFile *file;
+	struct modify_log_file *file;
 	int ret;
 
 	ret = modifylog_file_have_other_users(log->head, keep_lock);
@@ -161,9 +163,9 @@
 	return ret;
 }
 
-static int mmap_update(ModifyLogFile *file, int forced)
+static int mmap_update(struct modify_log_file *file, int forced)
 {
-	ModifyLogHeader *hdr;
+	struct modify_log_header *hdr;
 	unsigned int extra;
 
 	if (!forced && file->header != NULL &&
@@ -201,15 +203,15 @@
 		return modifylog_set_syscall_error(file, "mmap()");
 	}
 
-	if (file->mmap_full_length < sizeof(ModifyLogHeader)) {
+	if (file->mmap_full_length < sizeof(struct modify_log_header)) {
 		index_set_error(file->log->index, "Too small modify log %s",
 				file->filepath);
 		(void)unlink(file->filepath);
 		return FALSE;
 	}
 
-	extra = (file->mmap_full_length - sizeof(ModifyLogHeader)) %
-		sizeof(ModifyLogRecord);
+	extra = (file->mmap_full_length - sizeof(struct modify_log_header)) %
+		sizeof(struct modify_log_record);
 
 	if (extra != 0) {
 		/* partial write or corrupted -
@@ -228,8 +230,8 @@
 		return FALSE;
 	}
 
-	if ((hdr->used_file_size - sizeof(ModifyLogHeader)) %
-	    sizeof(ModifyLogRecord) != 0) {
+	if ((hdr->used_file_size - sizeof(struct modify_log_header)) %
+	    sizeof(struct modify_log_record) != 0) {
 		modifylog_set_corrupted(file,
 			"Invalid used_file_size in header (%"PRIuUOFF_T")",
 			hdr->used_file_size);
@@ -243,7 +245,7 @@
 	return TRUE;
 }
 
-static int mmap_init_update(ModifyLogFile *file)
+static int mmap_init_update(struct modify_log_file *file)
 {
 	if (!mmap_update(file, TRUE))
 		return FALSE;
@@ -253,11 +255,11 @@
 	return TRUE;
 }
 
-static MailModifyLog *mail_modifylog_new(MailIndex *index)
+static struct mail_modify_log *mail_modifylog_new(struct mail_index *index)
 {
-	MailModifyLog *log;
+	struct mail_modify_log *log;
 
-	log = i_new(MailModifyLog, 1);
+	log = i_new(struct mail_modify_log, 1);
 	log->index = index;
 
 	log->file1.fd = -1;
@@ -273,7 +275,7 @@
 	return log;
 }
 
-static void modifylog_munmap(ModifyLogFile *file)
+static void modifylog_munmap(struct modify_log_file *file)
 {
 	if (file->anon_mmap) {
 		if (munmap_anon(file->mmap_base, file->mmap_full_length) < 0)
@@ -291,7 +293,7 @@
 	file->last_flags = NULL;
 }
 
-static void modifylog_close_file(ModifyLogFile *file)
+static void modifylog_close_file(struct modify_log_file *file)
 {
 	modifylog_munmap(file);
 
@@ -302,17 +304,18 @@
 	}
 }
 
-static void mail_modifylog_init_header(MailModifyLog *log, ModifyLogHeader *hdr)
+static void mail_modifylog_init_header(struct mail_modify_log *log,
+				       struct modify_log_header *hdr)
 {
-	memset(hdr, 0, sizeof(ModifyLogHeader));
+	memset(hdr, 0, sizeof(struct modify_log_header));
 	hdr->indexid = log->index->indexid;
-	hdr->used_file_size = sizeof(ModifyLogHeader);
+	hdr->used_file_size = sizeof(struct modify_log_header);
 }
 
-static int mail_modifylog_init_fd(ModifyLogFile *file, int fd)
+static int mail_modifylog_init_fd(struct modify_log_file *file, int fd)
 {
-	MailIndex *index = file->log->index;
-        ModifyLogHeader hdr;
+	struct mail_index *index = file->log->index;
+        struct modify_log_header hdr;
 
         mail_modifylog_init_header(file->log, &hdr);
 	if (write_full(fd, &hdr, sizeof(hdr)) < 0) {
@@ -334,18 +337,18 @@
 	return TRUE;
 }
 
-static int modifylog_mark_full(ModifyLogFile *file)
+static int modifylog_mark_full(struct modify_log_file *file)
 {
 	unsigned int sync_id = SYNC_ID_FULL;
 
 	if (file->mmap_base != NULL) {
 		file->header->sync_id = SYNC_ID_FULL;
 
-		if (msync(file->mmap_base, sizeof(ModifyLogHeader),
+		if (msync(file->mmap_base, sizeof(struct modify_log_header),
 			  MS_SYNC) < 0)
 			return modifylog_set_syscall_error(file, "msync()");
 	} else {
-		off_t offset = offsetof(ModifyLogHeader, sync_id);
+		off_t offset = offsetof(struct modify_log_header, sync_id);
 
 		if (lseek(file->fd, offset, SEEK_SET) < 0)
 			return modifylog_set_syscall_error(file, "lseek()");
@@ -360,9 +363,9 @@
 }
 
 /* Returns 1 = ok, 0 = can't lock file, -1 = error */
-static int modifylog_reuse_or_create_file(ModifyLogFile *file)
+static int modifylog_reuse_or_create_file(struct modify_log_file *file)
 {
-	MailIndex *index = file->log->index;
+	struct mail_index *index = file->log->index;
 	int fd, ret;
 
 	if (index->nodiskspace)
@@ -404,10 +407,10 @@
 }
 
 /* Returns 1 = ok, 0 = full, -1 = error */
-static int mail_modifylog_open_and_verify(ModifyLogFile *file)
+static int mail_modifylog_open_and_verify(struct modify_log_file *file)
 {
-	MailIndex *index = file->log->index;
-	ModifyLogHeader hdr;
+	struct mail_index *index = file->log->index;
+	struct modify_log_header hdr;
 	ssize_t ret;
 	int fd;
 
@@ -459,7 +462,7 @@
 	return ret;
 }
 
-static int modifylog_files_open_or_create(MailModifyLog *log)
+static int modifylog_files_open_or_create(struct mail_modify_log *log)
 {
 	int i, ret1, ret2;
 
@@ -513,7 +516,7 @@
 	return FALSE;
 }
 
-static void modifylog_create_anon(ModifyLogFile *file)
+static void modifylog_create_anon(struct modify_log_file *file)
 {
 	file->mmap_full_length = MODIFY_LOG_INITIAL_SIZE;
 	file->mmap_base = mmap_anon(file->mmap_full_length);
@@ -528,9 +531,9 @@
 	file->filepath = i_strdup("(in-memory modify log)");
 }
 
-int mail_modifylog_create(MailIndex *index)
+int mail_modifylog_create(struct mail_index *index)
 {
-	MailModifyLog *log;
+	struct mail_modify_log *log;
 	int ret;
 
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
@@ -558,9 +561,9 @@
 	return TRUE;
 }
 
-int mail_modifylog_open_or_create(MailIndex *index)
+int mail_modifylog_open_or_create(struct mail_index *index)
 {
-	MailModifyLog *log;
+	struct mail_modify_log *log;
 
 	log = mail_modifylog_new(index);
 
@@ -574,7 +577,7 @@
 	return TRUE;
 }
 
-void mail_modifylog_free(MailModifyLog *log)
+void mail_modifylog_free(struct mail_modify_log *log)
 {
 	log->index->modifylog = NULL;
 
@@ -586,9 +589,9 @@
 	i_free(log);
 }
 
-int mail_modifylog_sync_file(MailModifyLog *log, int *fsync_fd)
+int mail_modifylog_sync_file(struct mail_modify_log *log, int *fsync_fd)
 {
-	ModifyLogFile *file = log->head;
+	struct modify_log_file *file = log->head;
 
 	*fsync_fd = -1;
 
@@ -605,16 +608,16 @@
 	return TRUE;
 }
 
-void mail_modifylog_notify_lock_drop(MailModifyLog *log)
+void mail_modifylog_notify_lock_drop(struct mail_modify_log *log)
 {
 	log->head->last_expunge = NULL;
 	log->head->last_flags = NULL;
 }
 
 /* if head file is closed, change it */
-static int modifylog_update_head(MailModifyLog *log)
+static int modifylog_update_head(struct mail_modify_log *log)
 {
-	ModifyLogFile *file;
+	struct modify_log_file *file;
 
 	if (!mmap_update(log->head, FALSE))
 		return FALSE;
@@ -639,12 +642,12 @@
 
 	/* we're non-synced */
 	file->synced_id = 0;
-	file->synced_position = sizeof(ModifyLogHeader);
+	file->synced_position = sizeof(struct modify_log_header);
 	log->head = file;
 	return TRUE;
 }
 
-static int mmap_update_both(MailModifyLog *log)
+static int mmap_update_both(struct mail_modify_log *log)
 {
 	if (!modifylog_update_head(log))
 		return FALSE;
@@ -657,7 +660,7 @@
 	return TRUE;
 }
 
-static int mail_modifylog_grow(ModifyLogFile *file)
+static int mail_modifylog_grow(struct modify_log_file *file)
 {
 	uoff_t new_fsize;
 	void *base;
@@ -692,10 +695,11 @@
 	return TRUE;
 }
 
-static int mail_modifylog_append(ModifyLogFile *file, ModifyLogRecord **rec,
+static int mail_modifylog_append(struct modify_log_file *file,
+				 struct modify_log_record **rec,
 				 int external_change)
 {
-	ModifyLogRecord *destrec;
+	struct modify_log_record *destrec;
 
 	i_assert(file->log->index->lock_type == MAIL_LOCK_EXCLUSIVE);
 	i_assert(file->header->sync_id != SYNC_ID_FULL);
@@ -720,20 +724,20 @@
 	}
 
 	i_assert(file->header->used_file_size == file->mmap_used_length);
-	i_assert(file->mmap_used_length + sizeof(ModifyLogRecord) <=
+	i_assert(file->mmap_used_length + sizeof(struct modify_log_record) <=
 		 file->mmap_full_length);
 
-	destrec = (ModifyLogRecord *) ((char *) file->mmap_base +
-				       file->mmap_used_length);
-	memcpy(destrec, *rec, sizeof(ModifyLogRecord));
+	destrec = (struct modify_log_record *) ((char *) file->mmap_base +
+						file->mmap_used_length);
+	memcpy(destrec, *rec, sizeof(struct modify_log_record));
 
 	if (!external_change && file->header->sync_id == file->synced_id) {
-		file->synced_position += sizeof(ModifyLogRecord);
+		file->synced_position += sizeof(struct modify_log_record);
 		file->synced_id++;
 	}
 
-	file->header->used_file_size += sizeof(ModifyLogRecord);
-	file->mmap_used_length += sizeof(ModifyLogRecord);
+	file->header->used_file_size += sizeof(struct modify_log_record);
+	file->mmap_used_length += sizeof(struct modify_log_record);
 
 	file->header->sync_id++;
 	file->modified = TRUE;
@@ -742,11 +746,11 @@
 	return TRUE;
 }
 
-int mail_modifylog_add_expunge(MailModifyLog *log, unsigned int seq,
+int mail_modifylog_add_expunge(struct mail_modify_log *log, unsigned int seq,
 			       unsigned int uid, int external_change)
 {
-	ModifyLogFile *file;
-	ModifyLogRecord rec, *recp;
+	struct modify_log_file *file;
+	struct modify_log_record rec, *recp;
 
 	if (!modifylog_update_head(log))
 		return FALSE;
@@ -786,11 +790,11 @@
 	return TRUE;
 }
 
-int mail_modifylog_add_flags(MailModifyLog *log, unsigned int seq,
+int mail_modifylog_add_flags(struct mail_modify_log *log, unsigned int seq,
 			     unsigned int uid, int external_change)
 {
-	ModifyLogFile *file;
-	ModifyLogRecord rec, *recp;
+	struct modify_log_file *file;
+	struct modify_log_record rec, *recp;
 
 	if (!modifylog_update_head(log))
 		return FALSE;
@@ -823,26 +827,27 @@
 	return TRUE;
 }
 
-static void mail_modifylog_get_nonsynced_file(ModifyLogFile *file,
-					      const ModifyLogRecord **arr,
-					      unsigned int *count)
+static void
+mail_modifylog_get_nonsynced_file(struct modify_log_file *file,
+				  const struct modify_log_record **arr,
+				  unsigned int *count)
 {
-	ModifyLogRecord *end_rec;
+	struct modify_log_record *end_rec;
 
 	i_assert(file->synced_position <= file->mmap_used_length);
-	i_assert(file->synced_position >= sizeof(ModifyLogHeader));
+	i_assert(file->synced_position >= sizeof(struct modify_log_header));
 
-	*arr = (ModifyLogRecord *) ((char *) file->mmap_base +
-				    file->synced_position);
-	end_rec = (ModifyLogRecord *) ((char *) file->mmap_base +
-				       file->mmap_used_length);
+	*arr = (struct modify_log_record *) ((char *) file->mmap_base +
+					     file->synced_position);
+	end_rec = (struct modify_log_record *) ((char *) file->mmap_base +
+						file->mmap_used_length);
 	*count = (unsigned int) (end_rec - *arr);
 }
 
-int mail_modifylog_get_nonsynced(MailModifyLog *log,
-				 const ModifyLogRecord **arr1,
+int mail_modifylog_get_nonsynced(struct mail_modify_log *log,
+				 const struct modify_log_record **arr1,
 				 unsigned int *count1,
-				 const ModifyLogRecord **arr2,
+				 const struct modify_log_record **arr2,
 				 unsigned int *count2)
 {
 	i_assert(log->index->lock_type != MAIL_LOCK_UNLOCK);
@@ -860,21 +865,22 @@
 	return TRUE;
 }
 
-static int mail_modifylog_try_truncate(ModifyLogFile *file)
+static int mail_modifylog_try_truncate(struct modify_log_file *file)
 {
 	if (modifylog_have_other_users(file->log, TRUE) != 0)
 		return FALSE;
 
 	file->header->sync_id = 0;
-	file->header->used_file_size = sizeof(ModifyLogHeader);
+	file->header->used_file_size = sizeof(struct modify_log_header);
 
-	if (msync(file->mmap_base, sizeof(ModifyLogHeader), MS_SYNC) < 0) {
+	if (msync(file->mmap_base,
+		  sizeof(struct modify_log_header), MS_SYNC) < 0) {
 		modifylog_set_syscall_error(file, "msync()");
 		return FALSE;
 	}
 
 	file->synced_id = 0;
-	file->synced_position = sizeof(ModifyLogHeader);
+	file->synced_position = sizeof(struct modify_log_header);
 
 	if (file_set_size(file->fd, MODIFY_LOG_INITIAL_SIZE) < 0)
 		modifylog_set_syscall_error(file, "file_set_size()");
@@ -883,9 +889,9 @@
 }
 
 /* switches to active modify log, updating our sync mark to end of it */
-static int mail_modifylog_switch_file(MailModifyLog *log)
+static int mail_modifylog_switch_file(struct mail_modify_log *log)
 {
-	ModifyLogFile *file;
+	struct modify_log_file *file;
 
 	(void)mail_modifylog_try_truncate(log->tail);
 
@@ -904,9 +910,9 @@
 	return mmap_init_update(log->head);
 }
 
-static int mail_modifylog_try_switch_file(MailModifyLog *log)
+static int mail_modifylog_try_switch_file(struct mail_modify_log *log)
 {
-	ModifyLogFile *file;
+	struct modify_log_file *file;
 
 	if (log->head->anon_mmap)
 		return TRUE;
@@ -932,7 +938,7 @@
 	return mmap_init_update(log->head);
 }
 
-int mail_modifylog_mark_synced(MailModifyLog *log)
+int mail_modifylog_mark_synced(struct mail_modify_log *log)
 {
 	i_assert(log->index->lock_type != MAIL_LOCK_UNLOCK);
 
@@ -960,29 +966,29 @@
 
 static int compare_expunge(const void *p1, const void *p2)
 {
-	const ModifyLogExpunge *e1 = p1;
-	const ModifyLogExpunge *e2 = p2;
+	const struct modify_log_expunge *e1 = p1;
+	const struct modify_log_expunge *e2 = p2;
 
 	return e1->uid1 < e2->uid1 ? -1 : e1->uid1 > e2->uid1 ? 1 : 0;
 }
 
-static ModifyLogRecord *modifylog_first(MailModifyLog *log)
+static struct modify_log_record *modifylog_first(struct mail_modify_log *log)
 {
-	ModifyLogFile *file;
-        ModifyLogRecord *rec;
+	struct modify_log_file *file;
+        struct modify_log_record *rec;
 
 	file = log->tail;
-	rec = (ModifyLogRecord *) ((char *) file->mmap_base +
-				   file->synced_position);
-	log->iterator_end = (ModifyLogRecord *) ((char *) file->mmap_base +
-						 file->mmap_used_length);
+	rec = (struct modify_log_record *) ((char *) file->mmap_base +
+					    file->synced_position);
+	log->iterator_end = (struct modify_log_record *)
+		((char *) file->mmap_base + file->mmap_used_length);
 	return rec < log->iterator_end ? rec : NULL;
 }
 
-static ModifyLogRecord *modifylog_next(MailModifyLog *log,
-				       ModifyLogRecord *rec)
+static struct modify_log_record *
+modifylog_next(struct mail_modify_log *log, struct modify_log_record *rec)
 {
-	ModifyLogFile *file;
+	struct modify_log_file *file;
 
 	rec++;
 	if (rec < log->iterator_end)
@@ -993,15 +999,16 @@
 		return NULL; /* end of head */
 
 	/* end of tail, jump to beginning of head */
-	rec = (ModifyLogRecord *) ((char *) file->mmap_base +
-				   sizeof(ModifyLogHeader));
-	log->iterator_end = (ModifyLogRecord *) ((char *) file->mmap_base +
-						 file->mmap_used_length);
+	rec = (struct modify_log_record *) ((char *) file->mmap_base +
+					    sizeof(struct modify_log_header));
+	log->iterator_end = (struct modify_log_record *)
+		((char *) file->mmap_base + file->mmap_used_length);
 	return rec < log->iterator_end ? rec : NULL;
 }
 
-static unsigned int modifylog_get_record_count_after(MailModifyLog *log,
-						     ModifyLogRecord *rec)
+static unsigned int
+modifylog_get_record_count_after(struct mail_modify_log *log,
+				 struct modify_log_record *rec)
 {
 	unsigned int count = 0;
 
@@ -1011,33 +1018,33 @@
 		/* only head */
 		count = (log->head->mmap_used_length -
 			 MODIFYLOG_FILE_POSITION(log->head, rec)) /
-			sizeof(ModifyLogRecord);
+			sizeof(struct modify_log_record);
 	} else {
 		/* tail */
 		count = (log->tail->mmap_used_length -
 			 MODIFYLOG_FILE_POSITION(log->tail, rec)) /
-			sizeof(ModifyLogRecord);
+			sizeof(struct modify_log_record);
 
 		if (log->head != log->tail) {
 			/* + head */
 			count += (log->tail->mmap_used_length -
-				  sizeof(ModifyLogHeader)) /
-				sizeof(ModifyLogRecord);
+				  sizeof(struct modify_log_header)) /
+				sizeof(struct modify_log_record);
 		}
 	}
 
 	return count;
 }
 
-const ModifyLogExpunge *
-mail_modifylog_seq_get_expunges(MailModifyLog *log,
+const struct modify_log_expunge *
+mail_modifylog_seq_get_expunges(struct mail_modify_log *log,
 				unsigned int first_seq,
 				unsigned int last_seq,
 				unsigned int *expunges_before)
 {
-	ModifyLogRecord *rec;
-	ModifyLogExpunge *expunge;
-	Buffer *buf;
+	struct modify_log_record *rec;
+	struct modify_log_expunge *expunge;
+	buffer_t *buf;
 	size_t count;
 	unsigned int before, max_records;
 
@@ -1070,9 +1077,10 @@
 	if (max_records > last_seq - first_seq + 1)
 		max_records = last_seq - first_seq + 1;
 
-	i_assert((max_records+1) < SSIZE_T_MAX/sizeof(ModifyLogExpunge));
+	i_assert((max_records+1) <
+		 SSIZE_T_MAX / sizeof(struct modify_log_expunge));
 	buf = buffer_create_static_hard(data_stack_pool, (max_records+1) *
-					sizeof(ModifyLogExpunge));
+					sizeof(struct modify_log_expunge));
 
 	before = 0;
 	for (; rec != NULL; rec = modifylog_next(log, rec)) {
@@ -1124,27 +1132,28 @@
 	memset(expunge, 0, sizeof(*expunge));
 
 	/* extract the array from buffer */
-	count = buffer_get_used_size(buf)/sizeof(ModifyLogExpunge);
+	count = buffer_get_used_size(buf)/sizeof(struct modify_log_expunge);
 	expunge = buffer_free_without_data(buf);
 
 	/* sort the UID array, not including the terminating 0 */
-	qsort(expunge, count-1, sizeof(ModifyLogExpunge), compare_expunge);
+	qsort(expunge, count-1, sizeof(struct modify_log_expunge),
+	      compare_expunge);
 
 	*expunges_before = before;
 	return expunge;
 }
 
-const ModifyLogExpunge *
-mail_modifylog_uid_get_expunges(MailModifyLog *log,
+const struct modify_log_expunge *
+mail_modifylog_uid_get_expunges(struct mail_modify_log *log,
 				unsigned int first_uid,
 				unsigned int last_uid,
 				unsigned int *expunges_before)
 {
 	/* pretty much copy&pasted from sequence code above ..
 	   kind of annoying */
-	ModifyLogRecord *rec;
-	ModifyLogExpunge *expunge;
-	Buffer *buf;
+	struct modify_log_record *rec;
+	struct modify_log_expunge *expunge;
+	buffer_t *buf;
 	size_t count;
 	unsigned int before, max_records;
 
@@ -1177,9 +1186,10 @@
 	if (max_records > last_uid - first_uid + 1)
 		max_records = last_uid - first_uid + 1;
 
-	i_assert((max_records+1) < SSIZE_T_MAX/sizeof(ModifyLogExpunge));
+	i_assert((max_records+1) <
+		 SSIZE_T_MAX / sizeof(struct modify_log_expunge));
 	buf = buffer_create_static_hard(data_stack_pool, (max_records+1) *
-					sizeof(ModifyLogExpunge));
+					sizeof(struct modify_log_expunge));
 
 	before = 0;
 	for (; rec != NULL; rec = modifylog_next(log, rec)) {
@@ -1212,26 +1222,28 @@
 	memset(expunge, 0, sizeof(*expunge));
 
 	/* extract the array from buffer */
-	count = buffer_get_used_size(buf)/sizeof(ModifyLogExpunge);
+	count = buffer_get_used_size(buf) / sizeof(struct modify_log_expunge);
 	expunge = buffer_free_without_data(buf);
 
 	/* sort the UID array, not including the terminating 0 */
-	qsort(expunge, count-1, sizeof(ModifyLogExpunge), compare_expunge);
+	qsort(expunge, count-1, sizeof(struct modify_log_expunge),
+	      compare_expunge);
 
 	*expunges_before = before;
 	return expunge;
 }
 
-static unsigned int modifylog_file_get_expunge_count(ModifyLogFile *file)
+static unsigned int
+modifylog_file_get_expunge_count(struct modify_log_file *file)
 {
-	ModifyLogRecord *rec, *end_rec;
+	struct modify_log_record *rec, *end_rec;
 	unsigned int expunges;
 
 	/* find the first expunged message that affects our range */
-	rec = (ModifyLogRecord *) ((char *) file->mmap_base +
-				   file->synced_position);
-	end_rec = (ModifyLogRecord *) ((char *) file->mmap_base +
-				       file->mmap_used_length);
+	rec = (struct modify_log_record *) ((char *) file->mmap_base +
+					    file->synced_position);
+	end_rec = (struct modify_log_record *) ((char *) file->mmap_base +
+						file->mmap_used_length);
 
 	expunges = 0;
 	while (rec < end_rec) {
@@ -1243,7 +1255,7 @@
 	return expunges;
 }
 
-unsigned int mail_modifylog_get_expunge_count(MailModifyLog *log)
+unsigned int mail_modifylog_get_expunge_count(struct mail_modify_log *log)
 {
 	unsigned int expunges;
 

Index: mail-modifylog.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-modifylog.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mail-modifylog.h	23 Oct 2002 19:49:23 -0000	1.6
+++ mail-modifylog.h	5 Jan 2003 13:09:52 -0000	1.7
@@ -1,67 +1,63 @@
 #ifndef __MAIL_MODIFYLOG_H
 #define __MAIL_MODIFYLOG_H
 
-typedef enum {
+enum modify_log_record_type {
 	RECORD_TYPE_EXPUNGE,
 	RECORD_TYPE_FLAGS_CHANGED
-} ModifyLogRecordType;
-
-typedef struct _ModifyLogHeader ModifyLogHeader;
-typedef struct _ModifyLogRecord ModifyLogRecord;
-typedef struct _ModifyLogExpunge ModifyLogExpunge;
+};
 
 /* if sync_id has this value, the log file is full and should be
    deleted or reused. */
 #define SYNC_ID_FULL ((unsigned int)-1)
 
-struct _ModifyLogHeader {
+struct modify_log_header {
 	unsigned int indexid;
 	unsigned int sync_id;
 	uoff_t used_file_size;
 };
 
-struct _ModifyLogRecord {
+struct modify_log_record {
 	unsigned int type;
 	unsigned int seq1, seq2;
 	unsigned int uid1, uid2;
 };
 
 /* for mail_modifylog_*_get_expunges() */
-struct _ModifyLogExpunge {
+struct modify_log_expunge {
 	unsigned int uid1, uid2; /* NOTE: may be outside wanted range */
 	unsigned int seq_count;
 };
 
 /* NOTE: All these functions require the index file to be locked. */
 
-int mail_modifylog_create(MailIndex *index);
-int mail_modifylog_open_or_create(MailIndex *index);
-void mail_modifylog_free(MailModifyLog *log);
+int mail_modifylog_create(struct mail_index *index);
+int mail_modifylog_open_or_create(struct mail_index *index);
+void mail_modifylog_free(struct mail_modify_log *log);
 
 /* Append EXPUGE or FLAGS entry to modify log. Index must be exclusively
    locked before calling these functions, and modifylog must have been
    marked synced within the same lock. */
-int mail_modifylog_add_expunge(MailModifyLog *log, unsigned int seq,
+int mail_modifylog_add_expunge(struct mail_modify_log *log, unsigned int seq,
 			       unsigned int uid, int external_change);
-int mail_modifylog_add_flags(MailModifyLog *log, unsigned int seq,
+int mail_modifylog_add_flags(struct mail_modify_log *log, unsigned int seq,
 			     unsigned int uid, int external_change);
 
 /* Synchronize the data into disk */
-int mail_modifylog_sync_file(MailModifyLog *log, int *fsync_fd);
+int mail_modifylog_sync_file(struct mail_modify_log *log, int *fsync_fd);
 
 /* Must be called when exclusive lock is dropped from index. */
-void mail_modifylog_notify_lock_drop(MailModifyLog *log);
+void mail_modifylog_notify_lock_drop(struct mail_modify_log *log);
 
 /* Updates arr and count parameters to list nonsynced log entries.
    Returns TRUE if successful. */
-int mail_modifylog_get_nonsynced(MailModifyLog *log,
-				 const ModifyLogRecord **arr1,
+int mail_modifylog_get_nonsynced(struct mail_modify_log *log,
+				 const struct modify_log_record **arr1,
 				 unsigned int *count1,
-				 const ModifyLogRecord **arr2,
+				 const struct modify_log_record **arr2,
 				 unsigned int *count2);
 
 /* Marks the modify log as being synced with in-memory state. */
-int mail_modifylog_mark_synced(MailModifyLog *log);
+int mail_modifylog_mark_synced(struct mail_modify_log *log);
 
 /* Finds expunged messages for the given sequence range, and number of
    expunged messages before the range. Returns 0,0 terminated list of
@@ -74,8 +70,8 @@
 
    Also the last expunge record's both uid and seq_count ranges may go
    past last_seq */
-const ModifyLogExpunge *
-mail_modifylog_seq_get_expunges(MailModifyLog *log,
+const struct modify_log_expunge *
+mail_modifylog_seq_get_expunges(struct mail_modify_log *log,
 				unsigned int first_seq,
 				unsigned int last_seq,
 				unsigned int *expunges_before);
@@ -87,13 +83,13 @@
    expunges_before=0, {uid1=1, uid2=9, seq_count=9} if only message 10
    exists. This is because we have no idea how many messages there are
    between UIDs since they're not guaranteed to be contiguous. */
-const ModifyLogExpunge *
-mail_modifylog_uid_get_expunges(MailModifyLog *log,
+const struct modify_log_expunge *
+mail_modifylog_uid_get_expunges(struct mail_modify_log *log,
 				unsigned int first_uid,
 				unsigned int last_uid,
 				unsigned int *expunges_before);
 
 /* Get number of non-synced expunges in modify log. */
-unsigned int mail_modifylog_get_expunge_count(MailModifyLog *log);
+unsigned int mail_modifylog_get_expunge_count(struct mail_modify_log *log);
 
 #endif

Index: mail-tree-redblack.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-tree-redblack.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- mail-tree-redblack.c	18 Dec 2002 01:52:14 -0000	1.20
+++ mail-tree-redblack.c	5 Jan 2003 13:09:52 -0000	1.21
@@ -84,7 +84,7 @@
 */
 
 static unsigned int
-rb_alloc(MailTree *tree)
+rb_alloc(struct mail_tree *tree)
 {
 	unsigned int x;
 
@@ -94,23 +94,23 @@
 	}
 
 	i_assert(tree->header->used_file_size == tree->mmap_used_length);
-	i_assert(tree->mmap_used_length + sizeof(MailTreeNode) <=
+	i_assert(tree->mmap_used_length + sizeof(struct mail_tree_node) <=
 		 tree->mmap_full_length);
 
-	x = (tree->mmap_used_length - sizeof(MailTreeHeader)) /
-		sizeof(MailTreeNode);
+	x = (tree->mmap_used_length - sizeof(struct mail_tree_header)) /
+		sizeof(struct mail_tree_node);
 
-	tree->header->used_file_size += sizeof(MailTreeNode);
-	tree->mmap_used_length += sizeof(MailTreeNode);
+	tree->header->used_file_size += sizeof(struct mail_tree_node);
+	tree->mmap_used_length += sizeof(struct mail_tree_node);
 
-	memset(&tree->node_base[x], 0, sizeof(MailTreeNode));
+	memset(&tree->node_base[x], 0, sizeof(struct mail_tree_node));
 	return x;
 }
 
 static void
-rb_move(MailTree *tree, unsigned int src, unsigned int dest)
+rb_move(struct mail_tree *tree, unsigned int src, unsigned int dest)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
 
 	/* update parent */
 	if (node[src].up != RBNULL) {
@@ -130,21 +130,22 @@
 	if (tree->header->root == src)
 		tree->header->root = dest;
 
-	memcpy(&node[dest], &node[src], sizeof(MailTreeNode));
-	memset(&node[src], 0, sizeof(MailTreeNode));
+	memcpy(&node[dest], &node[src], sizeof(struct mail_tree_node));
+	memset(&node[src], 0, sizeof(struct mail_tree_node));
 }
 
 static void
-rb_free(MailTree *tree, unsigned int x)
+rb_free(struct mail_tree *tree, unsigned int x)
 {
 	unsigned int last;
 
 	i_assert(tree->mmap_used_length >=
-		 sizeof(MailTreeHeader) + sizeof(MailTreeNode));
+		 sizeof(struct mail_tree_header) +
+		 sizeof(struct mail_tree_node));
 
 	/* get index to last used record */
-	last = (tree->mmap_used_length - sizeof(MailTreeHeader)) /
-		sizeof(MailTreeNode) - 1;
+	last = (tree->mmap_used_length - sizeof(struct mail_tree_header)) /
+		sizeof(struct mail_tree_node) - 1;
 
 	if (last != x) {
 		/* move it over the one we want free'd */
@@ -152,8 +153,8 @@
 	}
 
 	/* mark the moved node unused */
-	tree->mmap_used_length -= sizeof(MailTreeNode);
-	tree->header->used_file_size -= sizeof(MailTreeNode);
+	tree->mmap_used_length -= sizeof(struct mail_tree_node);
+	tree->header->used_file_size -= sizeof(struct mail_tree_node);
 
 	_mail_tree_truncate(tree);
 }
@@ -177,9 +178,9 @@
 */
 
 static void
-rb_left_rotate(MailTree *tree, unsigned int x)
+rb_left_rotate(struct mail_tree *tree, unsigned int x)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
 	unsigned int y, a_nodes, c_nodes;
 
 	i_assert(x != RBNULL);
@@ -222,9 +223,9 @@
 }
 
 static void
-rb_right_rotate(MailTree *tree, unsigned int y)
+rb_right_rotate(struct mail_tree *tree, unsigned int y)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
 	unsigned int x, a_nodes, c_nodes;
 
 	i_assert(y != RBNULL);
@@ -269,9 +270,9 @@
 /* Return index to the smallest key greater than x
 */
 static unsigned int 
-rb_successor(MailTree *tree, unsigned int x)
+rb_successor(struct mail_tree *tree, unsigned int x)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
 	unsigned int y;
 
 	if (node[x].right != RBNULL) {
@@ -299,9 +300,9 @@
 
 /* Restore the reb-black properties after insert */
 static int
-rb_insert_fix(MailTree *tree, unsigned int z)
+rb_insert_fix(struct mail_tree *tree, unsigned int z)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
 	unsigned int x, y, x_up_up;
 
 	/* color this new node red */
@@ -380,9 +381,9 @@
 
 /* Restore the reb-black properties after a delete */
 static void
-rb_delete_fix(MailTree *tree, unsigned int x)
+rb_delete_fix(struct mail_tree *tree, unsigned int x)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
 	unsigned int w;
 
 	while (x != tree->header->root && IS_NODE_BLACK(node[x])) {
@@ -490,9 +491,9 @@
 /* Delete the node z, and free up the space
 */
 static void
-rb_delete(MailTree *tree, unsigned int z)
+rb_delete(struct mail_tree *tree, unsigned int z)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
         unsigned int x, y, b;
 
 	if (node[z].left == RBNULL || node[z].right == RBNULL) {
@@ -550,9 +551,9 @@
 
 #ifdef DEBUG_TREE
 int
-rb_check1(MailTree *tree, unsigned int x)
+rb_check1(struct mail_tree *tree, unsigned int x)
 {
-        MailTreeNode *node = tree->node_base;
+        struct mail_tree_node *node = tree->node_base;
 
 	if (IS_NODE_RED(node[x])) {
 		if (!IS_NODE_BLACK(node[node[x].left]) ||
@@ -585,9 +586,9 @@
 	return 0;
 }
 
-int count_black(MailTree *tree, unsigned int x)
+int count_black(struct mail_tree *tree, unsigned int x)
 {
-        MailTreeNode *node = tree->node_base;
+        struct mail_tree_node *node = tree->node_base;
 	int nleft, nright;
 
 	if (x == RBNULL)
@@ -610,9 +611,9 @@
 	return nleft;
 }
 
-int count_nodes(MailTree *tree, unsigned int x)
+int count_nodes(struct mail_tree *tree, unsigned int x)
 {
-        MailTreeNode *node = tree->node_base;
+        struct mail_tree_node *node = tree->node_base;
 	int nleft, nright;
 
 	if (x == RBNULL)
@@ -633,9 +634,9 @@
 	return nleft+nright+1;
 }
 
-void dumptree(MailTree *tree, unsigned int x, int n)
+void dumptree(struct mail_tree *tree, unsigned int x, int n)
 {
-        MailTreeNode *node = tree->node_base;
+        struct mail_tree_node *node = tree->node_base;
 
 	if (x != RBNULL) {
 		n++;
@@ -651,9 +652,9 @@
 }
 
 int
-rb_check(MailTree *tree)
+rb_check(struct mail_tree *tree)
 {
-        MailTreeNode *node = tree->node_base;
+        struct mail_tree_node *node = tree->node_base;
 	unsigned int root;
 
 	root = tree->header->root;
@@ -685,11 +686,12 @@
 }
 #endif
 
-unsigned int mail_tree_lookup_uid_range(MailTree *tree, unsigned int *seq_r,
+unsigned int mail_tree_lookup_uid_range(struct mail_tree *tree,
+					unsigned int *seq_r,
 					unsigned int first_uid,
 					unsigned int last_uid)
 {
-	MailTreeNode *node;
+	struct mail_tree_node *node;
 	unsigned int x, y, seq;
 
 	i_assert(first_uid > 0 && last_uid > 0);
@@ -746,9 +748,9 @@
 	return x == RBNULL ? (unsigned int)-1 : node[x].value;
 }
 
-unsigned int mail_tree_lookup_sequence(MailTree *tree, unsigned int seq)
+unsigned int mail_tree_lookup_sequence(struct mail_tree *tree, unsigned int seq)
 {
-        MailTreeNode *node;
+        struct mail_tree_node *node;
 	unsigned int x, upleft_nodes, left_nodes;
 
 	i_assert(seq != 0);
@@ -782,9 +784,10 @@
 	return (unsigned int)-1;
 }
 
-int mail_tree_insert(MailTree *tree, unsigned int uid, unsigned int index)
+int mail_tree_insert(struct mail_tree *tree,
+		     unsigned int uid, unsigned int index)
 {
-        MailTreeNode *node;
+        struct mail_tree_node *node;
 	unsigned int x, z;
 
 	i_assert(uid != 0);
@@ -841,9 +844,10 @@
 	return TRUE;
 }
 
-int mail_tree_update(MailTree *tree, unsigned int uid, unsigned int index)
+int mail_tree_update(struct mail_tree *tree,
+		     unsigned int uid, unsigned int index)
 {
-	MailTreeNode *node;
+	struct mail_tree_node *node;
 	unsigned int x;
 
 	i_assert(uid != 0);
@@ -875,9 +879,9 @@
 	return FALSE;
 }
 
-void mail_tree_delete(MailTree *tree, unsigned int uid)
+void mail_tree_delete(struct mail_tree *tree, unsigned int uid)
 {
-	MailTreeNode *node;
+	struct mail_tree_node *node;
 	unsigned int x;
 
 	i_assert(uid != 0);

Index: mail-tree.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-tree.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- mail-tree.c	20 Nov 2002 16:15:57 -0000	1.12
+++ mail-tree.c	5 Jan 2003 13:09:52 -0000	1.13
@@ -12,10 +12,10 @@
 #include <fcntl.h>
 
 #define MAIL_TREE_MIN_SIZE \
-	(sizeof(MailTreeHeader) + \
-	 INDEX_MIN_RECORDS_COUNT * sizeof(MailTreeNode))
+	(sizeof(struct mail_tree_header) + \
+	 INDEX_MIN_RECORDS_COUNT * sizeof(struct mail_tree_node))
 
-static int tree_set_syscall_error(MailTree *tree, const char *function)
+static int tree_set_syscall_error(struct mail_tree *tree, const char *function)
 {
 	i_assert(function != NULL);
 
@@ -24,7 +24,7 @@
 	return FALSE;
 }
 
-int _mail_tree_set_corrupted(MailTree *tree, const char *fmt, ...)
+int _mail_tree_set_corrupted(struct mail_tree *tree, const char *fmt, ...)
 {
 	va_list va;
 
@@ -44,7 +44,7 @@
 	return FALSE;
 }
 
-static int mmap_update(MailTree *tree)
+static int mmap_update(struct mail_tree *tree)
 {
 	i_assert(!tree->anon_mmap);
 
@@ -73,21 +73,21 @@
 	return TRUE;
 }
 
-static int mmap_verify(MailTree *tree)
+static int mmap_verify(struct mail_tree *tree)
 {
-	MailTreeHeader *hdr;
+	struct mail_tree_header *hdr;
 	unsigned int extra;
 
 	if (tree->mmap_full_length <
-	    sizeof(MailTreeHeader) + sizeof(MailTreeNode)) {
+	    sizeof(struct mail_tree_header) + sizeof(struct mail_tree_node)) {
 		index_set_error(tree->index, "Too small binary tree file %s",
 				tree->filepath);
 		(void)unlink(tree->filepath);
 		return FALSE;
 	}
 
-	extra = (tree->mmap_full_length - sizeof(MailTreeHeader)) %
-		sizeof(MailTreeNode);
+	extra = (tree->mmap_full_length - sizeof(struct mail_tree_header)) %
+		sizeof(struct mail_tree_node);
 
 	if (extra != 0) {
 		/* partial write or corrupted -
@@ -106,8 +106,8 @@
 		return FALSE;
 	}
 
-	if ((hdr->used_file_size - sizeof(MailTreeHeader)) %
-	    sizeof(MailTreeNode) != 0) {
+	if ((hdr->used_file_size - sizeof(struct mail_tree_header)) %
+	    sizeof(struct mail_tree_node) != 0) {
 		_mail_tree_set_corrupted(tree,
 			"Invalid used_file_size in header (%"PRIuUOFF_T")",
 			hdr->used_file_size);
@@ -115,15 +115,15 @@
 	}
 
 	tree->header = tree->mmap_base;
-	tree->node_base = (MailTreeNode *) ((char *) tree->mmap_base +
-					    sizeof(MailTreeHeader));
+	tree->node_base = (struct mail_tree_node *)
+		((char *) tree->mmap_base + sizeof(struct mail_tree_header));
 	tree->sync_id = hdr->sync_id;
 	tree->mmap_used_length = hdr->used_file_size;
 	tree->mmap_highwater = tree->mmap_used_length;
 	return TRUE;
 }
 
-int _mail_tree_mmap_update(MailTree *tree, int forced)
+int _mail_tree_mmap_update(struct mail_tree *tree, int forced)
 {
 	debug_mprotect(tree->mmap_base, tree->mmap_full_length,
 		       tree->index);
@@ -143,9 +143,9 @@
 	return mmap_update(tree) && mmap_verify(tree);
 }
 
-static MailTree *mail_tree_open(MailIndex *index)
+static struct mail_tree *mail_tree_open(struct mail_index *index)
 {
-	MailTree *tree;
+	struct mail_tree *tree;
 	const char *path;
 	int fd;
 
@@ -159,7 +159,7 @@
 		return NULL;
 	}
 
-	tree = i_new(MailTree, 1);
+	tree = i_new(struct mail_tree, 1);
 	tree->fd = fd;
 	tree->index = index;
 	tree->filepath = i_strdup(path);
@@ -168,11 +168,11 @@
 	return tree;
 }
 
-static MailTree *mail_tree_create_anon(MailIndex *index)
+static struct mail_tree *mail_tree_create_anon(struct mail_index *index)
 {
-	MailTree *tree;
+	struct mail_tree *tree;
 
-	tree = i_new(MailTree, 1);
+	tree = i_new(struct mail_tree, 1);
 	tree->anon_mmap = TRUE;
 	tree->fd = -1;
 	tree->index = index;
@@ -182,9 +182,9 @@
 	return tree;
 }
 
-int mail_tree_create(MailIndex *index)
+int mail_tree_create(struct mail_index *index)
 {
-	MailTree *tree;
+	struct mail_tree *tree;
 
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
@@ -201,7 +201,7 @@
 	return TRUE;
 }
 
-static int mail_tree_open_init(MailTree *tree)
+static int mail_tree_open_init(struct mail_tree *tree)
 {
 	if (!mmap_update(tree))
 		return FALSE;
@@ -227,9 +227,9 @@
 	return TRUE;
 }
 
-int mail_tree_open_or_create(MailIndex *index)
+int mail_tree_open_or_create(struct mail_index *index)
 {
-	MailTree *tree;
+	struct mail_tree *tree;
 
 	tree = mail_tree_open(index);
 	if (tree == NULL)
@@ -254,7 +254,7 @@
 	return TRUE;
 }
 
-static void mail_tree_close(MailTree *tree)
+static void mail_tree_close(struct mail_tree *tree)
 {
 	if (tree->anon_mmap) {
 		if (munmap_anon(tree->mmap_base, tree->mmap_full_length) < 0)
@@ -277,7 +277,7 @@
 	i_free(tree->filepath);
 }
 
-void mail_tree_free(MailTree *tree)
+void mail_tree_free(struct mail_tree *tree)
 {
 	tree->index->tree = NULL;
 
@@ -285,19 +285,20 @@
 	i_free(tree);
 }
 
-static int mail_tree_init(MailTree *tree)
+static int mail_tree_init(struct mail_tree *tree)
 {
-        MailTreeHeader hdr;
+        struct mail_tree_header hdr;
 
 	/* first node is always used, and is the RBNULL node */
-	memset(&hdr, 0, sizeof(MailTreeHeader));
+	memset(&hdr, 0, sizeof(struct mail_tree_header));
 	hdr.indexid = tree->index->indexid;
-	hdr.used_file_size = sizeof(MailTreeHeader) + sizeof(MailTreeNode);
+	hdr.used_file_size = sizeof(struct mail_tree_header) +
+		sizeof(struct mail_tree_node);
 
 	if (tree->anon_mmap) {
 		tree->mmap_full_length = MAIL_TREE_MIN_SIZE;
 		tree->mmap_base = mmap_anon(tree->mmap_full_length);
-		memcpy(tree->mmap_base, &hdr, sizeof(MailTreeHeader));
+		memcpy(tree->mmap_base, &hdr, sizeof(struct mail_tree_header));
 		return mmap_verify(tree);
 	}
 
@@ -321,9 +322,9 @@
 	return TRUE;
 }
 
-int mail_tree_rebuild(MailTree *tree)
+int mail_tree_rebuild(struct mail_tree *tree)
 {
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 
 	if (!tree->index->set_lock(tree->index, MAIL_LOCK_EXCLUSIVE))
 		return FALSE;
@@ -349,7 +350,7 @@
 	return TRUE;
 }
 
-int mail_tree_sync_file(MailTree *tree, int *fsync_fd)
+int mail_tree_sync_file(struct mail_tree *tree, int *fsync_fd)
 {
 	*fsync_fd = -1;
 
@@ -368,7 +369,7 @@
 	return TRUE;
 }
 
-int _mail_tree_grow(MailTree *tree)
+int _mail_tree_grow(struct mail_tree *tree)
 {
 	uoff_t new_fsize;
 	unsigned int grow_count;
@@ -380,7 +381,7 @@
 		grow_count = 16;
 
 	new_fsize = (uoff_t)tree->mmap_full_length +
-		(grow_count * sizeof(MailTreeNode));
+		(grow_count * sizeof(struct mail_tree_node));
 	i_assert(new_fsize < OFF_T_MAX);
 
 	if (tree->anon_mmap) {
@@ -413,7 +414,7 @@
 	return TRUE;
 }
 
-void _mail_tree_truncate(MailTree *tree)
+void _mail_tree_truncate(struct mail_tree *tree)
 {
 	/* pretty much copy&pasted from mail_index_compress() */
 	uoff_t empty_space, truncate_threshold;
@@ -433,9 +434,9 @@
 			(empty_space * INDEX_TRUNCATE_KEEP_PERCENTAGE / 100);
 
 		/* keep the size record-aligned */
-		tree->mmap_full_length -=
-			(tree->mmap_full_length - sizeof(MailTreeHeader)) %
-			sizeof(MailTreeNode);
+		tree->mmap_full_length -= (tree->mmap_full_length -
+					   sizeof(struct mail_tree_header)) %
+			sizeof(struct mail_tree_node);
 
 		if (tree->mmap_full_length < MAIL_TREE_MIN_SIZE)
 			tree->mmap_full_length = MAIL_TREE_MIN_SIZE;

Index: mail-tree.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-tree.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mail-tree.h	21 Dec 2002 22:39:15 -0000	1.7
+++ mail-tree.h	5 Jan 2003 13:09:52 -0000	1.8
@@ -1,29 +1,26 @@
 #ifndef __MAIL_TREE_H
 #define __MAIL_TREE_H
 
-typedef struct _MailTreeHeader MailTreeHeader;
-typedef struct _MailTreeNode MailTreeNode;
-
-struct _MailTree {
-	MailIndex *index;
+struct mail_tree {
+	struct mail_index *index;
 
 	int fd;
 	char *filepath;
 
 	void *mmap_base;
-	MailTreeNode *node_base;
+	struct mail_tree_node *node_base;
 	size_t mmap_used_length;
 	size_t mmap_full_length;
 	size_t mmap_highwater; /* for msync()ing */
 
-        MailTreeHeader *header;
+        struct mail_tree_header *header;
 	unsigned int sync_id;
 
 	unsigned int anon_mmap:1;
 	unsigned int modified:1;
 };
 
-struct _MailTreeHeader {
+struct mail_tree_header {
 	unsigned int indexid;
 	unsigned int sync_id;
 
@@ -32,7 +29,7 @@
 	unsigned int root;
 };
 
-struct _MailTreeNode {
+struct mail_tree_node {
 	unsigned int left;
 	unsigned int right;
 	unsigned int up;
@@ -46,35 +43,39 @@
 	unsigned int value;
 };
 
-int mail_tree_create(MailIndex *index);
-int mail_tree_open_or_create(MailIndex *index);
-void mail_tree_free(MailTree *tree);
+int mail_tree_create(struct mail_index *index);
+int mail_tree_open_or_create(struct mail_index *index);
+void mail_tree_free(struct mail_tree *tree);
 
-int mail_tree_rebuild(MailTree *tree);
-int mail_tree_sync_file(MailTree *tree, int *fsync_fd);
+int mail_tree_rebuild(struct mail_tree *tree);
+int mail_tree_sync_file(struct mail_tree *tree, int *fsync_fd);
 
 /* Find first existing UID in range. Returns (unsigned int)-1 if not found. */
-unsigned int mail_tree_lookup_uid_range(MailTree *tree, unsigned int *seq_r,
+unsigned int mail_tree_lookup_uid_range(struct mail_tree *tree,
+					unsigned int *seq_r,
 					unsigned int first_uid,
 					unsigned int last_uid);
 
 /* Find message by sequence number. Returns (unsigned int)-1 if not found. */
-unsigned int mail_tree_lookup_sequence(MailTree *tree, unsigned int seq);
+unsigned int mail_tree_lookup_sequence(struct mail_tree *tree,
+				       unsigned int seq);
 
 /* Insert a new record in tree. */
-int mail_tree_insert(MailTree *tree, unsigned int uid, unsigned int index);
+int mail_tree_insert(struct mail_tree *tree,
+		     unsigned int uid, unsigned int index);
 
 /* Update existing record in tree. */
-int mail_tree_update(MailTree *tree, unsigned int uid, unsigned int index);
+int mail_tree_update(struct mail_tree *tree,
+		     unsigned int uid, unsigned int index);
 
 /* Delete record from tree. */
-void mail_tree_delete(MailTree *tree, unsigned int uid);
+void mail_tree_delete(struct mail_tree *tree, unsigned int uid);
 
 /* private: */
-int _mail_tree_set_corrupted(MailTree *tree, const char *fmt, ...)
+int _mail_tree_set_corrupted(struct mail_tree *tree, const char *fmt, ...)
 	__attr_format__(2, 3);
-int _mail_tree_mmap_update(MailTree *tree, int forced);
-int _mail_tree_grow(MailTree *tree);
-void _mail_tree_truncate(MailTree *tree);
+int _mail_tree_mmap_update(struct mail_tree *tree, int forced);
+int _mail_tree_grow(struct mail_tree *tree);
+void _mail_tree_truncate(struct mail_tree *tree);
 
 #endif




More information about the dovecot-cvs mailing list