list neigh
[cor_2_6_31.git] / fs / xfs / linux-2.6 / xfs_quotaops.c
blobcb6e2cca214f4b82528571c11e7dcd3138c7bf37
1 /*
2 * Copyright (c) 2008, Christoph Hellwig
3 * All Rights Reserved.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "xfs.h"
19 #include "xfs_dmapi.h"
20 #include "xfs_sb.h"
21 #include "xfs_inum.h"
22 #include "xfs_ag.h"
23 #include "xfs_mount.h"
24 #include "xfs_quota.h"
25 #include "xfs_log.h"
26 #include "xfs_trans.h"
27 #include "xfs_bmap_btree.h"
28 #include "xfs_inode.h"
29 #include "quota/xfs_qm.h"
30 #include <linux/quota.h>
33 STATIC int
34 xfs_quota_type(int type)
36 switch (type) {
37 case USRQUOTA:
38 return XFS_DQ_USER;
39 case GRPQUOTA:
40 return XFS_DQ_GROUP;
41 default:
42 return XFS_DQ_PROJ;
46 STATIC int
47 xfs_fs_quota_sync(
48 struct super_block *sb,
49 int type)
51 struct xfs_mount *mp = XFS_M(sb);
53 if (sb->s_flags & MS_RDONLY)
54 return -EROFS;
55 if (!XFS_IS_QUOTA_RUNNING(mp))
56 return -ENOSYS;
57 return -xfs_sync_data(mp, 0);
60 STATIC int
61 xfs_fs_get_xstate(
62 struct super_block *sb,
63 struct fs_quota_stat *fqs)
65 struct xfs_mount *mp = XFS_M(sb);
67 if (!XFS_IS_QUOTA_RUNNING(mp))
68 return -ENOSYS;
69 return -xfs_qm_scall_getqstat(mp, fqs);
72 STATIC int
73 xfs_fs_set_xstate(
74 struct super_block *sb,
75 unsigned int uflags,
76 int op)
78 struct xfs_mount *mp = XFS_M(sb);
79 unsigned int flags = 0;
81 if (sb->s_flags & MS_RDONLY)
82 return -EROFS;
83 if (!XFS_IS_QUOTA_RUNNING(mp))
84 return -ENOSYS;
85 if (!capable(CAP_SYS_ADMIN))
86 return -EPERM;
88 if (uflags & XFS_QUOTA_UDQ_ACCT)
89 flags |= XFS_UQUOTA_ACCT;
90 if (uflags & XFS_QUOTA_PDQ_ACCT)
91 flags |= XFS_PQUOTA_ACCT;
92 if (uflags & XFS_QUOTA_GDQ_ACCT)
93 flags |= XFS_GQUOTA_ACCT;
94 if (uflags & XFS_QUOTA_UDQ_ENFD)
95 flags |= XFS_UQUOTA_ENFD;
96 if (uflags & (XFS_QUOTA_PDQ_ENFD|XFS_QUOTA_GDQ_ENFD))
97 flags |= XFS_OQUOTA_ENFD;
99 switch (op) {
100 case Q_XQUOTAON:
101 return -xfs_qm_scall_quotaon(mp, flags);
102 case Q_XQUOTAOFF:
103 if (!XFS_IS_QUOTA_ON(mp))
104 return -EINVAL;
105 return -xfs_qm_scall_quotaoff(mp, flags);
106 case Q_XQUOTARM:
107 if (XFS_IS_QUOTA_ON(mp))
108 return -EINVAL;
109 return -xfs_qm_scall_trunc_qfiles(mp, flags);
112 return -EINVAL;
115 STATIC int
116 xfs_fs_get_xquota(
117 struct super_block *sb,
118 int type,
119 qid_t id,
120 struct fs_disk_quota *fdq)
122 struct xfs_mount *mp = XFS_M(sb);
124 if (!XFS_IS_QUOTA_RUNNING(mp))
125 return -ENOSYS;
126 if (!XFS_IS_QUOTA_ON(mp))
127 return -ESRCH;
129 return -xfs_qm_scall_getquota(mp, id, xfs_quota_type(type), fdq);
132 STATIC int
133 xfs_fs_set_xquota(
134 struct super_block *sb,
135 int type,
136 qid_t id,
137 struct fs_disk_quota *fdq)
139 struct xfs_mount *mp = XFS_M(sb);
141 if (sb->s_flags & MS_RDONLY)
142 return -EROFS;
143 if (!XFS_IS_QUOTA_RUNNING(mp))
144 return -ENOSYS;
145 if (!XFS_IS_QUOTA_ON(mp))
146 return -ESRCH;
147 if (!capable(CAP_SYS_ADMIN))
148 return -EPERM;
150 return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq);
153 struct quotactl_ops xfs_quotactl_operations = {
154 .quota_sync = xfs_fs_quota_sync,
155 .get_xstate = xfs_fs_get_xstate,
156 .set_xstate = xfs_fs_set_xstate,
157 .get_xquota = xfs_fs_get_xquota,
158 .set_xquota = xfs_fs_set_xquota,