annotate src/plugins/quota/quota-dirsize.c @ 7086:7ed926ed7aa4 HEAD

Updated copyright notices to include year 2008.
author Timo Sirainen <tss@iki.fi>
date Tue, 01 Jan 2008 22:05:21 +0200
parents f622ddfb69b2
children e6693a0ec8e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7086
7ed926ed7aa4 Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents: 7003
diff changeset
1 /* Copyright (c) 2005-2008 Dovecot authors, see the included COPYING file */
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 /* Quota reporting based on simply summing sizes of all files in mailbox
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 together. */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "lib.h"
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
7 #include "array.h"
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "str.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "quota-private.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include <stdlib.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include <unistd.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include <dirent.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include <sys/stat.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
16 struct quota_count_path {
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
17 const char *path;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
18 bool is_file;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 };
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
20 ARRAY_DEFINE_TYPE(quota_count_path, struct quota_count_path);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
22 extern struct quota_backend quota_backend_dirsize;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
24 static struct quota_root *dirsize_quota_alloc(void)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
26 return i_new(struct quota_root, 1);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
29 static void dirsize_quota_deinit(struct quota_root *_root)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
31 i_free(_root);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 static const char *const *
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6362
diff changeset
35 dirsize_quota_root_get_resources(struct quota_root *root ATTR_UNUSED)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 {
4844
a0ba02928787 Bytes and kilobytes were somewhat mixed up everywhere. Also fixes a
Timo Sirainen <tss@iki.fi>
parents: 4596
diff changeset
37 static const char *resources[] = { QUOTA_NAME_STORAGE_KILOBYTES, NULL };
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 return resources;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 static int get_dir_usage(const char *dir, uint64_t *value)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 DIR *dirp;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 string_t *path;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 struct dirent *d;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 struct stat st;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 unsigned int path_pos;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 int ret;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 dirp = opendir(dir);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 if (dirp == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 if (errno == ENOENT)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 return 0;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 i_error("opendir(%s) failed: %m", dir);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 return -1;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 path = t_str_new(128);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 str_append(path, dir);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 str_append_c(path, '/');
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 path_pos = str_len(path);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 ret = 0;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 while ((d = readdir(dirp)) != NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 if (d->d_name[0] == '.' &&
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 (d->d_name[1] == '\0' ||
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 (d->d_name[1] == '.' && d->d_name[2] == '\0'))) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 /* skip . and .. */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 continue;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 str_truncate(path, path_pos);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 str_append(path, d->d_name);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 if (lstat(str_c(path), &st) < 0) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 if (errno == ENOENT)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 continue;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 i_error("lstat(%s) failed: %m", dir);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 ret = -1;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83 break;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 } else if (S_ISDIR(st.st_mode)) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 if (get_dir_usage(str_c(path), value) < 0) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 ret = -1;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 break;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 } else {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 *value += st.st_size;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 (void)closedir(dirp);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 return ret;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
98 static int get_usage(const char *path, bool is_file, uint64_t *value_r)
4181
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
99 {
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
100 struct stat st;
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
101
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
102 if (is_file) {
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
103 if (lstat(path, &st) < 0) {
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
104 if (errno == ENOENT)
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
105 return 0;
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
106
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
107 i_error("lstat(%s) failed: %m", path);
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
108 return -1;
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
109 }
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
110 *value_r += st.st_size;
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
111 } else {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
112 if (get_dir_usage(path, value_r) < 0)
4181
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
113 return -1;
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
114 }
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
115 return 0;
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
116 }
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
117
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
118 static void quota_count_path_add(ARRAY_TYPE(quota_count_path) *paths,
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
119 const char *path, bool is_file)
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
120 {
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
121 struct quota_count_path *count_path;
6362
ad46cb956a0a If INBOX is a substring of already added path, don't assert-crash. Also
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
122 unsigned int i, count, path_len;
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
123
6362
ad46cb956a0a If INBOX is a substring of already added path, don't assert-crash. Also
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
124 path_len = strlen(path);
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
125 count_path = array_get_modifiable(paths, &count);
6362
ad46cb956a0a If INBOX is a substring of already added path, don't assert-crash. Also
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
126 for (i = 0; i < count; ) {
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
127 if (strncmp(count_path[i].path, path,
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
128 strlen(count_path[i].path)) == 0) {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
129 /* this path has already been counted */
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
130 return;
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
131 }
6362
ad46cb956a0a If INBOX is a substring of already added path, don't assert-crash. Also
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
132 if (strncmp(count_path[i].path, path, path_len) == 0 &&
ad46cb956a0a If INBOX is a substring of already added path, don't assert-crash. Also
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
133 count_path[i].path[path_len] == '/') {
ad46cb956a0a If INBOX is a substring of already added path, don't assert-crash. Also
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
134 /* the new path contains the existing path.
ad46cb956a0a If INBOX is a substring of already added path, don't assert-crash. Also
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
135 drop it and see if there are more to drop. */
ad46cb956a0a If INBOX is a substring of already added path, don't assert-crash. Also
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
136 array_delete(paths, i, 1);
ad46cb956a0a If INBOX is a substring of already added path, don't assert-crash. Also
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
137 count_path = array_get_modifiable(paths, &count);
ad46cb956a0a If INBOX is a substring of already added path, don't assert-crash. Also
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
138 } else {
ad46cb956a0a If INBOX is a substring of already added path, don't assert-crash. Also
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
139 i++;
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
140 }
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
141 }
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
142
6362
ad46cb956a0a If INBOX is a substring of already added path, don't assert-crash. Also
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
143 count_path = array_append_space(paths);
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
144 count_path->path = t_strdup(path);
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
145 count_path->is_file = is_file;
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
146 }
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
147
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 static int
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
149 get_quota_root_usage(struct quota_root *root, uint64_t *value_r)
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
150 {
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
151 struct mail_storage *const *storages;
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
152 ARRAY_TYPE(quota_count_path) paths;
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
153 const struct quota_count_path *count_paths;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
154 unsigned int i, count;
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
155 const char *path;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
156 bool is_file;
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
157
4596
bf4e98a0de3f Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents: 4594
diff changeset
158 t_array_init(&paths, 8);
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
159 storages = array_get(&root->quota->storages, &count);
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
160 for (i = 0; i < count; i++) {
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
161 path = mail_storage_get_mailbox_path(storages[i], "", &is_file);
7003
f622ddfb69b2 Fixed with mboxes.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
162 quota_count_path_add(&paths, path, FALSE);
4181
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
163
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
164 /* INBOX may be in different path. */
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
165 path = mail_storage_get_mailbox_path(storages[i], "INBOX",
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
166 &is_file);
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
167 quota_count_path_add(&paths, path, is_file);
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
168 }
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
169
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
170 /* now sum up the found paths */
4844
a0ba02928787 Bytes and kilobytes were somewhat mixed up everywhere. Also fixes a
Timo Sirainen <tss@iki.fi>
parents: 4596
diff changeset
171 *value_r = 0;
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
172 count_paths = array_get(&paths, &count);
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
173 for (i = 0; i < count; i++) {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
174 if (get_usage(count_paths[i].path, count_paths[i].is_file,
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
175 value_r) < 0)
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
176 return -1;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
177 }
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
178 return 0;
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
179 }
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
180
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
181 static int
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
182 dirsize_quota_get_resource(struct quota_root *_root, const char *name,
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6362
diff changeset
183 uint64_t *value_r, uint64_t *limit ATTR_UNUSED)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 {
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
185 int ret;
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
186
4844
a0ba02928787 Bytes and kilobytes were somewhat mixed up everywhere. Also fixes a
Timo Sirainen <tss@iki.fi>
parents: 4596
diff changeset
187 if (strcasecmp(name, QUOTA_NAME_STORAGE_BYTES) != 0)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188 return 0;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
190 T_FRAME(
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
191 ret = get_quota_root_usage(_root, value_r);
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
192 );
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
193
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
194 return ret < 0 ? -1 : 1;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
197 static int
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6362
diff changeset
198 dirsize_quota_update(struct quota_root *root ATTR_UNUSED,
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6362
diff changeset
199 struct quota_transaction_context *ctx ATTR_UNUSED)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
201 return 0;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
202 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
204 struct quota_backend quota_backend_dirsize = {
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205 "dirsize",
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
207 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
208 dirsize_quota_alloc,
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
209 NULL,
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
210 dirsize_quota_deinit,
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
211 NULL,
5704
4bf8438b497f Allow backend-specific quota rules with backend=<string>.
Timo Sirainen <tss@iki.fi>
parents: 4844
diff changeset
212 NULL,
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
213 dirsize_quota_root_get_resources,
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
214 dirsize_quota_get_resource,
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
215 dirsize_quota_update
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
216 }
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217 };