annotate src/plugins/quota/quota-fs.c @ 4547:912e6d3053e8 HEAD

Default _LINUX_QUOTA_VERSION to 1 instead of 2, since older Linux v1 sys/quota.h didn't define it at all.
author Timo Sirainen <tss@iki.fi>
date Mon, 07 Aug 2006 01:22:22 +0300
parents f598896bb40a
children ef71b2fdd433
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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: 4066
diff changeset
1 /* Copyright (C) 2005-2006 Timo Sirainen */
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 /* Only for reporting filesystem quota */
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #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: 4066
diff changeset
6 #include "array.h"
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "str.h"
4188
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
8 #include "mountpoint.h"
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "quota-private.h"
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "quota-fs.h"
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #ifdef HAVE_FS_QUOTA
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include <stdio.h>
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include <stdlib.h>
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
16 #include <fcntl.h>
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include <unistd.h>
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #include <sys/stat.h>
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
19 #ifdef HAVE_LINUX_DQBLK_XFS_H
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
20 # include <linux/dqblk_xfs.h>
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
21 #endif
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22
4530
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
23 #ifndef DEV_BSIZE
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
24 # define DEV_BSIZE 512
3762
4d44a337ac08 Fixed to work with struct dqblk.dqb_curspace also which is apparently the
Timo Sirainen <tss@iki.fi>
parents: 3751
diff changeset
25 #endif
4d44a337ac08 Fixed to work with struct dqblk.dqb_curspace also which is apparently the
Timo Sirainen <tss@iki.fi>
parents: 3751
diff changeset
26
4547
912e6d3053e8 Default _LINUX_QUOTA_VERSION to 1 instead of 2, since older Linux v1
Timo Sirainen <tss@iki.fi>
parents: 4530
diff changeset
27 /* Older sys/quota.h doesn't define _LINUX_QUOTA_VERSION at all, which means
912e6d3053e8 Default _LINUX_QUOTA_VERSION to 1 instead of 2, since older Linux v1
Timo Sirainen <tss@iki.fi>
parents: 4530
diff changeset
28 it supports only v1 quota */
4530
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
29 #ifndef _LINUX_QUOTA_VERSION
4547
912e6d3053e8 Default _LINUX_QUOTA_VERSION to 1 instead of 2, since older Linux v1
Timo Sirainen <tss@iki.fi>
parents: 4530
diff changeset
30 # define _LINUX_QUOTA_VERSION 1
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
31 #endif
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
32
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: 4066
diff changeset
33 struct fs_quota_mountpoint {
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: 4066
diff changeset
34 char *mount_path;
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: 4066
diff changeset
35 char *device_path;
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
36 char *type;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
38 #ifdef HAVE_Q_QUOTACTL
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
39 int fd;
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: 4066
diff changeset
40 char *path;
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
41 #endif
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: 4066
diff changeset
42 };
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
43
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: 4066
diff changeset
44 struct fs_quota_root {
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 struct quota_root root;
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: 4066
diff changeset
46
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: 4066
diff changeset
47 uid_t uid;
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: 4066
diff changeset
48 struct fs_quota_mountpoint *mount;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 };
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50
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: 4066
diff changeset
51 extern struct quota_backend quota_backend_fs;
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: 4066
diff changeset
52
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
53 static struct quota_root *fs_quota_alloc(void)
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: 4066
diff changeset
54 {
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: 4066
diff changeset
55 struct fs_quota_root *root;
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: 4066
diff changeset
56
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: 4066
diff changeset
57 root = i_new(struct fs_quota_root, 1);
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: 4066
diff changeset
58 root->uid = geteuid();
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: 4066
diff changeset
59
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: 4066
diff changeset
60 return &root->root;
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: 4066
diff changeset
61 }
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62
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: 4066
diff changeset
63 static void fs_quota_mountpoint_free(struct fs_quota_mountpoint *mount)
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 {
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: 4066
diff changeset
65 #ifdef HAVE_Q_QUOTACTL
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: 4066
diff changeset
66 if (mount->fd != -1) {
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: 4066
diff changeset
67 if (close(mount->fd) < 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: 4066
diff changeset
68 i_error("close(%s) failed: %m", mount->path);
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: 4066
diff changeset
69 }
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: 4066
diff changeset
70 i_free(mount->path);
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: 4066
diff changeset
71 #endif
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: 4066
diff changeset
72
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: 4066
diff changeset
73 i_free(mount->device_path);
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: 4066
diff changeset
74 i_free(mount->mount_path);
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
75 i_free(mount->type);
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: 4066
diff changeset
76 i_free(mount);
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: 4066
diff changeset
77 }
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: 4066
diff changeset
78
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: 4066
diff changeset
79 static void fs_quota_deinit(struct quota_root *_root)
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: 4066
diff changeset
80 {
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: 4066
diff changeset
81 struct fs_quota_root *root = (struct fs_quota_root *)_root;
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: 4066
diff changeset
82
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: 4066
diff changeset
83 if (root->mount != NULL)
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: 4066
diff changeset
84 fs_quota_mountpoint_free(root->mount);
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: 4066
diff changeset
85 i_free(root);
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: 4066
diff changeset
86 }
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: 4066
diff changeset
87
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: 4066
diff changeset
88 static struct fs_quota_mountpoint *fs_quota_mountpoint_get(const char *dir)
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: 4066
diff changeset
89 {
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: 4066
diff changeset
90 struct fs_quota_mountpoint *mount;
4188
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
91 struct mountpoint point;
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
92 int ret;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93
4188
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
94 ret = mountpoint_get(dir, default_pool, &point);
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
95 if (ret <= 0)
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: 4066
diff changeset
96 return NULL;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97
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: 4066
diff changeset
98 mount = i_new(struct fs_quota_mountpoint, 1);
4188
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
99 mount->device_path = point.device_path;
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
100 mount->mount_path = point.mount_path;
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
101 mount->type = point.type;
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: 4066
diff changeset
102 return mount;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 }
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
105 static struct fs_quota_root *
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
106 fs_quota_root_find_mountpoint(struct quota *quota,
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
107 const struct fs_quota_mountpoint *mount)
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
109 struct quota_root *const *roots;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
110 struct fs_quota_root *empty = NULL;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
111 unsigned int i, count;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
112
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
113 roots = array_get(&quota->roots, &count);
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
114 for (i = 0; i < count; i++) {
4514
511f1f5c76fa Changes to make trash plugin working again.
Timo Sirainen <tss@iki.fi>
parents: 4509
diff changeset
115 if (roots[i]->backend.name == quota_backend_fs.name) {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
116 struct fs_quota_root *root =
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
117 (struct fs_quota_root *)roots[i];
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
118
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
119 if (root->mount == NULL)
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
120 empty = root;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
121 else if (strcmp(root->mount->mount_path,
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
122 mount->mount_path) == 0)
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
123 return root;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
124 }
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
125 }
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
126 return empty;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
127 }
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
128
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
129 static void fs_quota_storage_added(struct quota *quota,
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
130 struct mail_storage *storage)
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
131 {
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: 4066
diff changeset
132 struct fs_quota_mountpoint *mount;
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
133 struct quota_root *_root;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
134 struct fs_quota_root *root;
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: 4066
diff changeset
135 const char *dir;
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: 4066
diff changeset
136 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: 4066
diff changeset
137
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: 4066
diff changeset
138 dir = mail_storage_get_mailbox_path(storage, "", &is_file);
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
139 mount = fs_quota_mountpoint_get(dir);
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
140 if (getenv("DEBUG") != 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: 4066
diff changeset
141 i_info("fs quota add storage dir = %s", dir);
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: 4066
diff changeset
142 i_info("fs quota block device = %s", mount->device_path);
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: 4066
diff changeset
143 i_info("fs quota mount point = %s", mount->mount_path);
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: 4066
diff changeset
144 }
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
146 root = fs_quota_root_find_mountpoint(quota, mount);
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
147 if (root != NULL && root->mount != NULL) {
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
148 /* already exists */
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
149 fs_quota_mountpoint_free(mount);
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
150 return;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
151 }
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
152
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
153 if (root == NULL) {
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
154 /* create a new root for this mountpoint */
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
155 _root = quota_root_init(quota, quota_backend_fs.name);
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
156 root = (struct fs_quota_root *)_root;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
157 root->root.name =
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
158 p_strdup_printf(root->root.pool, "%s%d",
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
159 quota_backend_fs.name,
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
160 array_count(&quota->roots));
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
161 } else {
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
162 /* this is the default root. */
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
163 }
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
164 root->mount = mount;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
165
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
166 #ifdef HAVE_Q_QUOTACTL
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: 4066
diff changeset
167 if (mount->path == NULL) {
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: 4066
diff changeset
168 mount->path = i_strconcat(mount->mount_path, "/quotas", NULL);
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: 4066
diff changeset
169 mount->fd = open(mount->path, O_RDONLY);
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: 4066
diff changeset
170 if (mount->fd == -1 && errno != ENOENT)
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: 4066
diff changeset
171 i_error("open(%s) failed: %m", mount->path);
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
172 }
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
173 #endif
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 }
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176 static const char *const *
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 fs_quota_root_get_resources(struct quota_root *root __attr_unused__)
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 {
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 static const char *resources[] = { QUOTA_NAME_STORAGE, NULL };
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181 return resources;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182 }
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 static int
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: 4066
diff changeset
185 fs_quota_get_resource(struct quota_root *_root, const char *name,
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186 uint64_t *value_r, uint64_t *limit_r)
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187 {
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: 4066
diff changeset
188 struct fs_quota_root *root = (struct fs_quota_root *)_root;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 struct dqblk dqblk;
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
190 #ifdef HAVE_Q_QUOTACTL
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
191 struct quotctl ctl;
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
192 #endif
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194 *value_r = 0;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195 *limit_r = 0;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196
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: 4066
diff changeset
197 if (strcasecmp(name, QUOTA_NAME_STORAGE) != 0 || root->mount == NULL)
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
198 return 0;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
200 #if defined (HAVE_QUOTACTL) && defined(HAVE_SYS_QUOTA_H)
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
201 /* Linux */
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
202 #ifdef HAVE_LINUX_DQBLK_XFS_H
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
203 if (strcmp(root->mount->type, "xfs") == 0) {
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
204 /* XFS */
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
205 struct fs_disk_quota xdqblk;
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
206
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
207 if (quotactl(QCMD(Q_XGETQUOTA, USRQUOTA),
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
208 root->mount->device_path,
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
209 root->uid, (caddr_t)&xdqblk) < 0) {
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
210 i_error("quotactl(Q_XGETQUOTA, %s) failed: %m",
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
211 root->mount->device_path);
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
212 return -1;
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
213 }
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
214
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
215 /* values always returned in 512 byte blocks */
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
216 *value_r = xdqblk.d_bcount >> 1;
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
217 *limit_r = xdqblk.d_blk_softlimit >> 1;
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
218 } else
4192
26e028337e1e quotactl() parameters were backwards for BSDs and AIX.
Timo Sirainen <tss@iki.fi>
parents: 4188
diff changeset
219 #endif
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
220 {
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
221 /* ext2, ext3 */
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
222 if (quotactl(QCMD(Q_GETQUOTA, USRQUOTA),
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
223 root->mount->device_path,
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
224 root->uid, (caddr_t)&dqblk) < 0) {
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
225 i_error("quotactl(Q_GETQUOTA, %s) failed: %m",
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
226 root->mount->device_path);
4530
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
227 if (errno == EINVAL) {
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
228 i_error("Dovecot was compiled with Linux quota "
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
229 "v%d support, try changing it "
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
230 "(--with-linux-quota configure option)",
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
231 _LINUX_QUOTA_VERSION);
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
232 }
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
233 return -1;
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
234 }
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
235
4530
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
236 #if _LINUX_QUOTA_VERSION < 2
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
237 *value_r = dqblk.dqb_curblocks / 1024;
4530
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
238 #else
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
239 *value_r = dqblk.dqb_curspace / 1024;
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
240 #endif
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
241 *limit_r = dqblk.dqb_bsoftlimit;
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
242 }
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
243 #elif defined(HAVE_QUOTACTL)
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
244 /* BSD, AIX */
4468
ce47b2f84cdb BSD's quotactl() wants a file path, not a device path.
Timo Sirainen <tss@iki.fi>
parents: 4448
diff changeset
245 if (quotactl(root->mount->mount_path, QCMD(Q_GETQUOTA, USRQUOTA),
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: 4066
diff changeset
246 root->uid, (void *)&dqblk) < 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: 4066
diff changeset
247 i_error("quotactl(Q_GETQUOTA, %s) failed: %m",
4468
ce47b2f84cdb BSD's quotactl() wants a file path, not a device path.
Timo Sirainen <tss@iki.fi>
parents: 4448
diff changeset
248 root->mount->mount_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: 4066
diff changeset
249 quota_set_error(_root->setup->quota, "Internal quota error");
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250 return -1;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
251 }
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
252 *value_r = (uint64_t)dqblk.dqb_curblocks * 1024 / DEV_BSIZE;
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
253 *limit_r = (uint64_t)dqblk.dqb_bsoftlimit * 1024 / DEV_BSIZE;
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
254 #else
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
255 /* Solaris */
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: 4066
diff changeset
256 if (root->mount->fd == -1)
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
257 return 0;
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
258
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
259 ctl.op = Q_GETQUOTA;
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: 4066
diff changeset
260 ctl.uid = root->uid;
4066
30ad1815cf1e Compiler warning fix
Timo Sirainen <tss@iki.fi>
parents: 4063
diff changeset
261 ctl.addr = (caddr_t)&dqblk;
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: 4066
diff changeset
262 if (ioctl(root->mount->fd, Q_QUOTACTL, &ctl) < 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: 4066
diff changeset
263 i_error("ioctl(%s, Q_QUOTACTL) failed: %m", root->mount->path);
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: 4066
diff changeset
264 quota_set_error(_root->setup->quota, "Internal quota error");
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
265 return -1;
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
266 }
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
267 *value_r = (uint64_t)dqblk.dqb_curblocks * 1024 / DEV_BSIZE;
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
268 *limit_r = (uint64_t)dqblk.dqb_bsoftlimit * 1024 / DEV_BSIZE;
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
269 #endif
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
270 return 1;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
271 }
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
272
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
273 static int
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
274 fs_quota_update(struct quota_root *root __attr_unused__,
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
275 struct quota_transaction_context *ctx __attr_unused__)
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276 {
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277 return 0;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278 }
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
279
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: 4066
diff changeset
280 struct quota_backend quota_backend_fs = {
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281 "fs",
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282
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: 4066
diff changeset
283 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
284 fs_quota_alloc,
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
285 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: 4066
diff changeset
286 fs_quota_deinit,
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
287
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
288 fs_quota_storage_added,
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
289
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: 4066
diff changeset
290 fs_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: 4066
diff changeset
291 fs_quota_get_resource,
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
292 fs_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: 4066
diff changeset
293 }
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
294 };
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
295
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
296 #endif