Mercurial > dovecot > original-hg > dovecot-1.2
changeset 4844:a0ba02928787 HEAD
Bytes and kilobytes were somewhat mixed up everywhere. Also fixes a
compiling problem.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 22 Nov 2006 19:23:09 +0200 |
parents | 57955b19a35d |
children | 5cb424ffa365 |
files | src/plugins/quota/quota-dict.c src/plugins/quota/quota-dirsize.c src/plugins/quota/quota-fs.c src/plugins/quota/quota-maildir.c src/plugins/quota/quota.c src/plugins/quota/quota.h |
diffstat | 6 files changed, 39 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/quota/quota-dict.c Mon Nov 20 00:38:09 2006 +0200 +++ b/src/plugins/quota/quota-dict.c Wed Nov 22 19:23:09 2006 +0200 @@ -65,7 +65,7 @@ dict_quota_root_get_resources(struct quota_root *root __attr_unused__) { static const char *resources[] = { - QUOTA_NAME_STORAGE, QUOTA_NAME_MESSAGES, NULL + QUOTA_NAME_STORAGE_KILOBYTES, QUOTA_NAME_MESSAGES, NULL }; return resources; @@ -79,11 +79,11 @@ const char *value; int ret; - if (strcmp(name, QUOTA_NAME_STORAGE) == 0) { + if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0) { t_push(); ret = dict_lookup(root->dict, unsafe_data_stack_pool, DICT_QUOTA_CURRENT_BYTES_PATH, &value); - *value_r = ret <= 0 ? 0 : strtoull(value, NULL, 10) / 1024; + *value_r = ret <= 0 ? 0 : strtoull(value, NULL, 10); t_pop(); } else if (strcmp(name, QUOTA_NAME_MESSAGES) == 0) { t_push();
--- a/src/plugins/quota/quota-dirsize.c Mon Nov 20 00:38:09 2006 +0200 +++ b/src/plugins/quota/quota-dirsize.c Wed Nov 22 19:23:09 2006 +0200 @@ -34,7 +34,7 @@ static const char *const * dirsize_quota_root_get_resources(struct quota_root *root __attr_unused__) { - static const char *resources[] = { QUOTA_NAME_STORAGE, NULL }; + static const char *resources[] = { QUOTA_NAME_STORAGE_KILOBYTES, NULL }; return resources; } @@ -166,6 +166,7 @@ } /* now sum up the found paths */ + *value_r = 0; count_paths = array_get(&paths, &count); for (i = 0; i < count; i++) { if (get_usage(count_paths[i].path, count_paths[i].is_file, @@ -183,13 +184,12 @@ dirsize_quota_get_resource(struct quota_root *_root, const char *name, uint64_t *value_r, uint64_t *limit __attr_unused__) { - if (strcasecmp(name, QUOTA_NAME_STORAGE) != 0) + if (strcasecmp(name, QUOTA_NAME_STORAGE_BYTES) != 0) return 0; if (get_quota_root_usage(_root, value_r) < 0) return -1; - *value_r /= 1024; return 1; }
--- a/src/plugins/quota/quota-fs.c Mon Nov 20 00:38:09 2006 +0200 +++ b/src/plugins/quota/quota-fs.c Wed Nov 22 19:23:09 2006 +0200 @@ -184,7 +184,7 @@ static const char *const * fs_quota_root_get_resources(struct quota_root *root __attr_unused__) { - static const char *resources[] = { QUOTA_NAME_STORAGE, NULL }; + static const char *resources[] = { QUOTA_NAME_STORAGE_KILOBYTES, NULL }; return resources; } @@ -202,7 +202,8 @@ *value_r = 0; *limit_r = 0; - if (strcasecmp(name, QUOTA_NAME_STORAGE) != 0 || root->mount == NULL) + if (strcasecmp(name, QUOTA_NAME_STORAGE_BYTES) != 0 || + root->mount == NULL) return 0; #if defined (HAVE_QUOTACTL) && defined(HAVE_SYS_QUOTA_H) @@ -221,8 +222,8 @@ } /* values always returned in 512 byte blocks */ - *value_r = xdqblk.d_bcount >> 1; - *limit_r = xdqblk.d_blk_softlimit >> 1; + *value_r = xdqblk.d_bcount * 512; + *limit_r = xdqblk.d_blk_softlimit * 512; } else #endif { @@ -241,8 +242,8 @@ return -1; } - *value_r = dqblk.dqb_curblocks / 1024; - *limit_r = dqblk.dqb_bsoftlimit; + *value_r = dqblk.dqb_curblocks; + *limit_r = dqblk.dqb_bsoftlimit * 1024; } #elif defined(HAVE_QUOTACTL) /* BSD, AIX */ @@ -252,8 +253,8 @@ root->mount->mount_path); return -1; } - *value_r = (uint64_t)dqblk.dqb_curblocks * 1024 / DEV_BSIZE; - *limit_r = (uint64_t)dqblk.dqb_bsoftlimit * 1024 / DEV_BSIZE; + *value_r = (uint64_t)dqblk.dqb_curblocks * DEV_BSIZE; + *limit_r = (uint64_t)dqblk.dqb_bsoftlimit * DEV_BSIZE; #else /* Solaris */ if (root->mount->fd == -1) @@ -266,8 +267,8 @@ i_error("ioctl(%s, Q_QUOTACTL) failed: %m", root->mount->path); return -1; } - *value_r = (uint64_t)dqblk.dqb_curblocks * 1024 / DEV_BSIZE; - *limit_r = (uint64_t)dqblk.dqb_bsoftlimit * 1024 / DEV_BSIZE; + *value_r = (uint64_t)dqblk.dqb_curblocks * DEV_BSIZE; + *limit_r = (uint64_t)dqblk.dqb_bsoftlimit * DEV_BSIZE; #endif return 1; }
--- a/src/plugins/quota/quota-maildir.c Mon Nov 20 00:38:09 2006 +0200 +++ b/src/plugins/quota/quota-maildir.c Wed Nov 22 19:23:09 2006 +0200 @@ -134,8 +134,7 @@ ctx = i_new(struct maildir_list_context, 1); ctx->storage = storage; ctx->path = str_new(default_pool, 512); - ctx->iter = mailbox_list_iter_init(mail_storage_get_list(storage), - "", "*", + ctx->iter = mailbox_list_iter_init(mail_storage_get_list(storage), "*", MAILBOX_LIST_ITER_FAST_FLAGS); return ctx; } @@ -591,7 +590,7 @@ maildir_quota_root_get_resources(struct quota_root *root __attr_unused__) { static const char *resources_both[] = { - QUOTA_NAME_STORAGE, + QUOTA_NAME_STORAGE_KILOBYTES, QUOTA_NAME_MESSAGES, NULL }; @@ -608,8 +607,8 @@ if (maildirquota_refresh(root) < 0) return -1; - if (strcmp(name, QUOTA_NAME_STORAGE) == 0) - *value_r = root->total_bytes / 1024; + if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0) + *value_r = root->total_bytes; else if (strcmp(name, QUOTA_NAME_MESSAGES) == 0) *value_r = root->total_count; else
--- a/src/plugins/quota/quota.c Mon Nov 20 00:38:09 2006 +0200 +++ b/src/plugins/quota/quota.c Wed Nov 22 19:23:09 2006 +0200 @@ -300,7 +300,8 @@ for (; iter->i < count; iter->i++) { ret = quota_get_resource(roots[iter->i], "", - QUOTA_NAME_STORAGE, &value, &limit); + QUOTA_NAME_STORAGE_KILOBYTES, + &value, &limit); if (ret == 0) { ret = quota_get_resource(roots[iter->i], "", QUOTA_NAME_MESSAGES, @@ -348,11 +349,17 @@ const char *name, uint64_t *value_r, uint64_t *limit_r) { uint64_t bytes_limit, count_limit; + bool kilobytes = FALSE; int ret; + if (strcmp(name, QUOTA_NAME_STORAGE_KILOBYTES) == 0) { + name = QUOTA_NAME_STORAGE_BYTES; + kilobytes = TRUE; + } + (void)quota_root_get_rule_limits(root, mailbox_name, &bytes_limit, &count_limit); - if (strcmp(name, QUOTA_NAME_STORAGE) == 0) + if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0) *limit_r = bytes_limit; else if (strcmp(name, QUOTA_NAME_MESSAGES) == 0) *limit_r = count_limit; @@ -360,6 +367,10 @@ *limit_r = 0; ret = root->backend.v.get_resource(root, name, value_r, limit_r); + if (kilobytes && ret > 0) { + *value_r /= 1024; + *limit_r /= 1024; + } return ret <= 0 ? ret : (*limit_r == 0 ? 0 : 1); } @@ -397,7 +408,8 @@ roots = array_get("a->roots, &count); for (i = 0; i < count; i++) { ret = quota_get_resource(roots[i], mailbox_name, - QUOTA_NAME_STORAGE, ¤t, &limit); + QUOTA_NAME_STORAGE_BYTES, + ¤t, &limit); if (ret > 0) { left = limit < current ? 0 : limit - current; if (ctx->bytes_left > left)
--- a/src/plugins/quota/quota.h Mon Nov 20 00:38:09 2006 +0200 +++ b/src/plugins/quota/quota.h Wed Nov 22 19:23:09 2006 +0200 @@ -5,7 +5,9 @@ struct mailbox; /* Message storage size kilobytes. */ -#define QUOTA_NAME_STORAGE "STORAGE" +#define QUOTA_NAME_STORAGE_KILOBYTES "STORAGE" +/* Message storage size bytes. This is used only internally. */ +#define QUOTA_NAME_STORAGE_BYTES "STORAGE_BYTES" /* Number of messages. */ #define QUOTA_NAME_MESSAGES "MESSAGES"