mail-index-data.h revision 025961fd171e7be79d7be7dee3d619de317f0b1e
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#ifndef __MAIL_INDEX_DATA_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define __MAIL_INDEX_DATA_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen#define DATA_FILE_PREFIX ".data"
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_data_open(MailIndex *index);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenint mail_index_data_create(MailIndex *index);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_data_free(MailIndexData *data);
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen/* Truncate the data file and update it's indexid */
15b9759df8e4f6fb00c115353827a2aebbebfebcTimo Sirainenint mail_index_data_reset(MailIndexData *data);
15b9759df8e4f6fb00c115353827a2aebbebfebcTimo Sirainen
15b9759df8e4f6fb00c115353827a2aebbebfebcTimo Sirainen/* Set indexid to 0 to notify other processes using this file that they should
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen re-open it. */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenint mail_index_data_mark_deleted(MailIndexData *data);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen/* Mark the file as being modified */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenvoid mail_index_data_mark_modified(MailIndexData *data);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen/* Append new data at the end of the file. Returns the position in file
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen where the data begins, or 0 if error occured. */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenuoff_t mail_index_data_append(MailIndexData *data, const void *buffer,
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen size_t size);
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen/* Increase header->deleted_space field */
f7539a17ea306191b53b8f5e752e228937df9ec3Timo Sirainenint mail_index_data_add_deleted_space(MailIndexData *data, size_t data_size);
0a3b01714dadf97dcc7439ad4eeba690ab044966Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Synchronize the data into disk */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_data_sync_file(MailIndexData *data, int *fsync_fd);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Looks up a field from data file. If field is 0, returns the first field
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen found. Returns NULL if not found or if error occured. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo SirainenMailIndexDataRecord *
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainenmail_index_data_lookup(MailIndexData *data, MailIndexRecord *index_rec,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MailField field);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns the next record in data file, or NULL if there's no more. */
6ef7e31619edfaa17ed044b45861d106a86191efTimo SirainenMailIndexDataRecord *
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenmail_index_data_next(MailIndexData *data, MailIndexRecord *index_rec,
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen MailIndexDataRecord *rec);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen/* Returns TRUE if rec->data is a valid \0-terminated string */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenint mail_index_data_record_verify(MailIndexData *data,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen MailIndexDataRecord *rec);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen/* Return the whole data file mmap()ed. */
57a8c6a95e4bce3eeaba36985adb81c07dd683ffTimo Sirainenvoid *mail_index_data_get_mmaped(MailIndexData *data, size_t *size);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen/* "Error in index data file %s: ...". Also marks the index file as
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen corrupted. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint index_data_set_corrupted(MailIndexData *data, const char *fmt, ...);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen#endif
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen