sdbox-storage.h revision df3963075d67f76ade66b6a74764f4eae31d9c87
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#ifndef SDBOX_STORAGE_H
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define SDBOX_STORAGE_H
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "index-storage.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "dbox-storage.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
2b9e49e4e65e3e2dca38f56971029a3051ccdb99Timo Sirainen#define SDBOX_STORAGE_NAME "sdbox"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define SDBOX_MAIL_FILE_PREFIX "u."
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define SDBOX_MAIL_FILE_FORMAT SDBOX_MAIL_FILE_PREFIX"%u"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define SDBOX_INDEX_HEADER_MIN_SIZE (sizeof(uint32_t))
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct sdbox_index_header {
e5fb952c6d49d3b6bff1746551566202e92947daTimo Sirainen /* increased every time a full mailbox rebuild is done */
e5fb952c6d49d3b6bff1746551566202e92947daTimo Sirainen uint32_t rebuild_count;
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen guid_128_t mailbox_guid;
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen uint8_t flags; /* enum dbox_index_header_flags */
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen uint8_t unused[3];
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct sdbox_storage {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct dbox_storage storage;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct sdbox_mailbox {
d22301419109ed4a38351715e6760011421dadecTimo Sirainen struct mailbox box;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct sdbox_storage *storage;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen uint32_t hdr_ext_id;
e5fb952c6d49d3b6bff1746551566202e92947daTimo Sirainen /* if non-zero, storage should be rebuilt (except if rebuild_count
e5fb952c6d49d3b6bff1746551566202e92947daTimo Sirainen has changed from this value) */
e5fb952c6d49d3b6bff1746551566202e92947daTimo Sirainen uint32_t corrupted_rebuild_count;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen guid_128_t mailbox_guid;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
df3963075d67f76ade66b6a74764f4eae31d9c87Josef 'Jeff' Sipek#define SDBOX_STORAGE(s) container_of(DBOX_STORAGE(s), struct sdbox_storage, storage)
df3963075d67f76ade66b6a74764f4eae31d9c87Josef 'Jeff' Sipek#define SDBOX_MAILBOX(s) container_of(s, struct sdbox_mailbox, box)
df3963075d67f76ade66b6a74764f4eae31d9c87Josef 'Jeff' Sipek
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenextern struct mail_vfuncs sdbox_mail_vfuncs;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint sdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct dbox_file **file_r);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint sdbox_read_header(struct sdbox_mailbox *mbox,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen struct sdbox_index_header *hdr, bool log_error,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen bool *need_resize_r);
f605df8a4c15cc7a11e16fdde994d51473700890Timo Sirainenint sdbox_mailbox_create_indexes(struct mailbox *box,
f605df8a4c15cc7a11e16fdde994d51473700890Timo Sirainen const struct mailbox_update *update,
f605df8a4c15cc7a11e16fdde994d51473700890Timo Sirainen struct mail_index_transaction *trans);
0a7b04ec6441fdcf083392888b2e30844fc3e86dTimo Sirainenvoid sdbox_set_mailbox_corrupted(struct mailbox *box);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct mail_save_context *
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainensdbox_save_alloc(struct mailbox_transaction_context *_t);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint sdbox_save_begin(struct mail_save_context *ctx, struct istream *input);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint sdbox_save_finish(struct mail_save_context *ctx);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid sdbox_save_cancel(struct mail_save_context *ctx);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct dbox_file *
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainensdbox_save_file_get_file(struct mailbox_transaction_context *t, uint32_t seq);
e8762c2b4914db7997fa9eb644a91586952d1876Timo Sirainenvoid sdbox_save_add_file(struct mail_save_context *ctx, struct dbox_file *file);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint sdbox_transaction_save_commit_pre(struct mail_save_context *ctx);
9f19a50d5966643c4d1c5ca06868ac2ad31bc4d5Timo Sirainenvoid sdbox_transaction_save_commit_post(struct mail_save_context *ctx,
9f19a50d5966643c4d1c5ca06868ac2ad31bc4d5Timo Sirainen struct mail_index_transaction_commit_result *result);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid sdbox_transaction_save_rollback(struct mail_save_context *ctx);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint sdbox_copy(struct mail_save_context *ctx, struct mail *mail);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#endif