dbox-file.h revision 3c89294a59c9c12743d4dc57d8ed3831e0e209ec
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen/* The file begins with a header followed by zero or more messages:
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen <dbox message header>
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen <message body>
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen Metadata block begins with DBOX_MAGIC_POST, followed by zero or more lines
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen in format <key character><value><LF>. The block ends with an empty line.
18a41cbd38f83429b790414c1159c097af4a59b8Timo Sirainen Unknown metadata should be ignored, but preserved when copying.
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen There should be no duplicates for the current metadata, but future
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen extensions may need them so they should be preserved.
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen/* prefer flock(). fcntl() locking currently breaks if trying to access the
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen same file from multiple mail_storages within same process. that's why we
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen fallback to dotlocks. */
395682d473b161c86165e7b9323ce4e45afb94bdTimo Sirainen /* Must be sizeof(struct dbox_message_header) when appending (hex) */
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen /* Creation UNIX timestamp (hex) */
18a41cbd38f83429b790414c1159c097af4a59b8Timo Sirainen /* metadata used by old Dovecot versions */
18a41cbd38f83429b790414c1159c097af4a59b8Timo Sirainen /* Globally unique identifier for the message. Preserved when
18a41cbd38f83429b790414c1159c097af4a59b8Timo Sirainen /* POP3 UIDL overriding the default format */
18a41cbd38f83429b790414c1159c097af4a59b8Timo Sirainen /* Received UNIX timestamp in hex */
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen /* Physical message size in hex. Necessary only if it differs from
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen the dbox_message_header.message_size_hex, for example because the
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen message is compressed. */
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen /* Virtual message size in hex (line feeds counted as CRLF) */
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen /* Pointer to external message data. Format is:
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen 1*(<start offset> <byte count> <options> <ref>) */
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen /* Mailbox name where this message was originally saved to.
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen When rebuild finds a message whose mailbox is unknown, it's
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen placed to this mailbox. */
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen /* metadata used by old Dovecot versions */
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen /* Normal message */
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen unsigned char type;
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen unsigned char space1;
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen unsigned char space2;
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen /* <space reserved for future extensions, LF is always last> */
18a41cbd38f83429b790414c1159c097af4a59b8Timo Sirainen unsigned char save_lf;
18a41cbd38f83429b790414c1159c097af4a59b8Timo Sirainen unsigned char magic_post[sizeof(DBOX_MAGIC_POST)-1];
8eba883232f80178b60fa416f73292bf5f990fecTimo Sirainen /* Metadata for the currently seeked metadata block. */
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen uoff_t first_append_offset, last_checkpoint_offset, last_flush_offset;
44320b37d20bb75e0d433423318db2f4e29d5b91Timo Sirainen#define dbox_file_is_open(file) ((file)->fd != -1)
44320b37d20bb75e0d433423318db2f4e29d5b91Timo Sirainen#define dbox_file_is_in_alt(file) ((file)->cur_path == (file)->alt_path)
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen/* Open the file. Returns 1 if ok, 0 if file header is corrupted, -1 if error.
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen If file is deleted, deleted_r=TRUE and 1 is returned. */
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainenint dbox_file_open(struct dbox_file *file, bool *deleted_r);
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen/* Try to open file only from primary path. */
18a41cbd38f83429b790414c1159c097af4a59b8Timo Sirainenint dbox_file_open_primary(struct dbox_file *file, bool *notfound_r);
44320b37d20bb75e0d433423318db2f4e29d5b91Timo Sirainen/* Close the file handle from the file, but don't free it. */
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen/* fstat() or stat() the file. If file is already deleted, fails with
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen errno=ENOENT. */
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainenint dbox_file_stat(struct dbox_file *file, struct stat *st_r);
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen/* Try to lock the dbox file. Returns 1 if ok, 0 if already locked by someone
4182d8cd818e76856a5a1e25b343fe5ddf69fd8eTimo Sirainen else, -1 if error. */
18a41cbd38f83429b790414c1159c097af4a59b8Timo Sirainenint dbox_file_try_lock(struct dbox_file *file);
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen/* Seek to given offset in file. Returns 1 if ok/expunged, 0 if file/offset is
const char *dbox_generate_tmp_filename(void);