index file so required alignmentation comes pretty much from sizeof(off_t).
--HG--
branch : HEAD
preferred_off_t_bits=64)
AC_ARG_WITH(mem-align,
-[ --with-mem-align=BYTES Set the memory alignment (default: sizeof(off_t))],
+[ --with-mem-align=BYTES Set the memory alignment (default: 8)],
mem_align=$withval,
mem_align=8)
+AC_ARG_WITH(index-align,
+[ --with-index-align=BYTES Set the index file alignment (default: detect)],
+ index_align=$withval,
+ index_align=0)
+
AC_ARG_WITH(passwd,
[ --with-passwd Build with /etc/passwd support (default)],
if test x$withval = xno; then
AC_DEFINE(IOLOOP_SELECT,, Implement I/O loop with select())
])
-dnl * memory alignment
-AC_DEFINE_UNQUOTED(MEM_ALIGN_SIZE, $mem_align, Required memory alignment)
-
dnl * OS specific options
case "$host_os" in
hpux*)
AC_DEFINE_UNQUOTED(OFF_T_MAX, $offt_max, Maximum value of off_t)
])
-dnl currently we break if off_t is smaller than mem_align
-if test $offt_bits = 32 -a $mem_align = 8; then
- mem_align=4
-fi
-
AC_DEFINE_UNQUOTED(PRIuUOFF_T, "$uofft_fmt", printf() format for uoff_t)
dnl * make sure size_t isn't signed. we'd probably work fine with it, but
AC_DEFINE(HAVE_SOCKLEN_T,, Define to 'int' if you don't have socklen_t)
fi
+dnl * memory alignment
+if test "$index_align" = "0"; then
+ if test $offt_bits = 64; then
+ index_align=8
+ else
+ index_align=4
+ fi
+fi
+
+AC_DEFINE_UNQUOTED(MEM_ALIGN_SIZE, $mem_align, Required memory alignment)
+AC_DEFINE_UNQUOTED(INDEX_ALIGN_SIZE, $index_align, Required index alignment)
+
dnl * find random source
AC_MSG_CHECKING([for /dev/urandom])
if test -c /dev/urandom; then
{
uoff_t offset;
- i_assert((size & (MEM_ALIGN_SIZE-1)) == 0);
+ i_assert((size & (INDEX_ALIGN_SIZE-1)) == 0);
i_assert(data->index->lock_type == MAIL_LOCK_EXCLUSIVE);
if (!mmap_update(data, 0, sizeof(struct mail_index_data_header)))
return NULL;
}
- if ((pos % MEM_ALIGN_SIZE) != 0) {
+ if ((pos % INDEX_ALIGN_SIZE) != 0) {
index_data_set_corrupted(data, "Data position (%"PRIuUOFF_T") "
"is not memory aligned for record %u",
pos, index_rec->uid);
break;
}
- if ((rec->full_field_size % MEM_ALIGN_SIZE) != 0) {
+ if ((rec->full_field_size % INDEX_ALIGN_SIZE) != 0) {
index_data_set_corrupted(data, "Field %d size %u "
"is not memory aligned for record %u",
(int)field, rec->full_field_size,
hdr->compat_data[2] == sizeof(unsigned int) &&
hdr->compat_data[3] == sizeof(time_t) &&
hdr->compat_data[4] == sizeof(uoff_t) &&
- hdr->compat_data[5] == MEM_ALIGN_SIZE;
+ hdr->compat_data[5] == INDEX_ALIGN_SIZE;
}
static int mail_index_init_file(struct mail_index *index,
hdr->compat_data[2] = sizeof(unsigned int);
hdr->compat_data[3] = sizeof(time_t);
hdr->compat_data[4] = sizeof(uoff_t);
- hdr->compat_data[5] = MEM_ALIGN_SIZE;
+ hdr->compat_data[5] = INDEX_ALIGN_SIZE;
hdr->indexid = ioloop_time;
/* mark the index requiring rebuild - rebuild() removes this flag
if (update->fields[i] != NULL) {
/* value was modified - use it */
- field_min_size = MEM_ALIGN(update->field_sizes[i]);
+ field_min_size = INDEX_ALIGN(update->field_sizes[i]);
*min_size += SIZEOF_MAIL_INDEX_DATA + field_min_size;
*max_size += SIZEOF_MAIL_INDEX_DATA +
- MEM_ALIGN(update->field_sizes[i] +
- update->field_extra_sizes[i]);
+ INDEX_ALIGN(update->field_sizes[i] +
+ update->field_extra_sizes[i]);
if (!field_exists ||
rec->full_field_size < field_min_size)
{
size_t size;
- size = MEM_ALIGN(base);
+ size = INDEX_ALIGN(base);
extra -= size - base;
- if (*max_extra < MEM_ALIGN_SIZE || extra == 0)
+ if (*max_extra < INDEX_ALIGN_SIZE || extra == 0)
return size; /* no extra / extra went into alignment */
- extra = MEM_ALIGN(extra);
+ extra = INDEX_ALIGN(extra);
if (extra > *max_extra) {
/* partial */
- extra = *max_extra & ~(size_t)(MEM_ALIGN_SIZE-1);
+ extra = *max_extra & ~(size_t)(INDEX_ALIGN_SIZE-1);
i_assert(extra <= *max_extra);
}
/* the field doesn't exist, jump to next */
continue;
}
- i_assert((full_field_size % MEM_ALIGN_SIZE) == 0);
+ i_assert((full_field_size % INDEX_ALIGN_SIZE) == 0);
destrec = buffer_append_space(buf, SIZEOF_MAIL_INDEX_DATA +
full_field_size);
2 = sizeof(unsigned int),
3 = sizeof(time_t),
4 = sizeof(uoff_t),
- 5 = MEM_ALIGN_SIZE */
+ 5 = INDEX_ALIGN_SIZE */
unsigned int indexid;
unsigned int sync_id; /* re-mmap() when changed, required only
struct mail_index_data_record {
unsigned int field; /* enum mail_data_field */
unsigned int full_field_size;
- char data[MEM_ALIGN_SIZE]; /* variable size */
+ char data[INDEX_ALIGN_SIZE]; /* variable size */
};
#define SIZEOF_MAIL_INDEX_DATA \
- (sizeof(struct mail_index_data_record) - MEM_ALIGN_SIZE)
+ (sizeof(struct mail_index_data_record) - INDEX_ALIGN_SIZE)
#define DATA_RECORD_SIZE(rec) \
(SIZEOF_MAIL_INDEX_DATA + (rec)->full_field_size)
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
+ /* Just remember that full_field_size will be INDEX_ALIGNed, so
it may differer from the given size parameter. */
void (*update_field_raw)(struct mail_index_update *update,
enum mail_data_field field,
#define INDEX_IS_IN_MEMORY(index) \
((index)->anon_mmap)
+/* Returns alignmentation for given size */
+#define INDEX_ALIGN(size) \
+ (((size) + INDEX_ALIGN_SIZE-1) & ~((unsigned int) INDEX_ALIGN_SIZE-1))
+
#endif