annotate src/plugins/quota/quota-fs.c @ 4552:ef71b2fdd433 HEAD

Put back specific checks for struct dqblk.dqb_curblocks vs curspace. The removal broke compiling for some OSes such as OSX.
author Timo Sirainen <tss@iki.fi>
date Thu, 10 Aug 2006 20:46:05 +0300
parents 912e6d3053e8
children a54558861acc
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
4552
ef71b2fdd433 Put back specific checks for struct dqblk.dqb_curblocks vs curspace. The
Timo Sirainen <tss@iki.fi>
parents: 4547
diff changeset
27 #ifdef HAVE_STRUCT_DQBLK_CURSPACE
ef71b2fdd433 Put back specific checks for struct dqblk.dqb_curblocks vs curspace. The
Timo Sirainen <tss@iki.fi>
parents: 4547
diff changeset
28 # define dqb_curblocks dqb_curspace
ef71b2fdd433 Put back specific checks for struct dqblk.dqb_curblocks vs curspace. The
Timo Sirainen <tss@iki.fi>
parents: 4547
diff changeset
29 #endif
ef71b2fdd433 Put back specific checks for struct dqblk.dqb_curblocks vs curspace. The
Timo Sirainen <tss@iki.fi>
parents: 4547
diff changeset
30
4547
912e6d3053e8 Default _LINUX_QUOTA_VERSION to 1 instead of 2, since older Linux v1
Timo Sirainen <tss@iki.fi>
parents: 4530
diff changeset
31 /* 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
32 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
33 #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
34 # 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
35 #endif
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
36
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
37 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
38 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
39 char *device_path;
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
40 char *type;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
42 #ifdef HAVE_Q_QUOTACTL
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
43 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
44 char *path;
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
45 #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
46 };
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
47
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
48 struct fs_quota_root {
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 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
50
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 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
52 struct fs_quota_mountpoint *mount;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 };
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54
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
55 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
56
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
57 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
58 {
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 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
60
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 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
62 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
63
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
64 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
65 }
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66
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
67 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
68 {
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
69 #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
70 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
71 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
72 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
73 }
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->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
75 #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
76
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 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
78 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
79 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
80 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
81 }
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 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
84 {
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 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
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 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
88 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
89 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
90 }
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
91
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
92 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
93 {
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
94 struct fs_quota_mountpoint *mount;
4188
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
95 struct mountpoint point;
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
96 int ret;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97
4188
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
98 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
99 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
100 return NULL;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101
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 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
103 mount->device_path = point.device_path;
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
104 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
105 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
106 return mount;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 }
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 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
110 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
111 const struct fs_quota_mountpoint *mount)
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
113 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
114 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
115 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
116
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
117 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
118 for (i = 0; i < count; i++) {
4514
511f1f5c76fa Changes to make trash plugin working again.
Timo Sirainen <tss@iki.fi>
parents: 4509
diff changeset
119 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
120 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
121 (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
122
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
123 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
124 empty = root;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
125 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
126 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
127 return root;
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 }
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
130 return empty;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
131 }
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
132
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
133 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
134 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
135 {
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
136 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
137 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
138 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
139 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
140 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
141
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 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
143 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
144 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
145 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
146 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
147 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
148 }
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
150 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
151 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
152 /* already exists */
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
153 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
154 return;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
155 }
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
156
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
157 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
158 /* 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
159 _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
160 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
161 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
162 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
163 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
164 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
165 } else {
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
166 /* 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
167 }
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
168 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
169
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
170 #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
171 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
172 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
173 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
174 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
175 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
176 }
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
177 #endif
3751
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
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 static const char *const *
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181 fs_quota_root_get_resources(struct quota_root *root __attr_unused__)
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 static const char *resources[] = { QUOTA_NAME_STORAGE, NULL };
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 return resources;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186 }
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188 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
189 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
190 uint64_t *value_r, uint64_t *limit_r)
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 {
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
192 struct fs_quota_root *root = (struct fs_quota_root *)_root;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 struct dqblk dqblk;
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
194 #ifdef HAVE_Q_QUOTACTL
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
195 struct quotctl ctl;
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
196 #endif
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
197
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
198 *value_r = 0;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199 *limit_r = 0;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200
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
201 if (strcasecmp(name, QUOTA_NAME_STORAGE) != 0 || root->mount == NULL)
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
202 return 0;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
204 #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
205 /* Linux */
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
206 #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
207 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
208 /* XFS */
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
209 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
210
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
211 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
212 root->mount->device_path,
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
213 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
214 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
215 root->mount->device_path);
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
216 return -1;
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
217 }
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
218
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
219 /* 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
220 *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
221 *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
222 } else
4192
26e028337e1e quotactl() parameters were backwards for BSDs and AIX.
Timo Sirainen <tss@iki.fi>
parents: 4188
diff changeset
223 #endif
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
224 {
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
225 /* ext2, ext3 */
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
226 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
227 root->mount->device_path,
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
228 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
229 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
230 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
231 if (errno == EINVAL) {
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
232 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
233 "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
234 "(--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
235 _LINUX_QUOTA_VERSION);
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
236 }
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
237 return -1;
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
238 }
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
239
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
240 *value_r = dqblk.dqb_curblocks / 1024;
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