2 * Quota code necessary even when VFS quota support is not compiled
3 * into the kernel. The interesting stuff is over in dquot.c, here
4 * we have symbols for initial quotactl(2) handling, the sysctl(2)
5 * variables, etc - things needed even when quota support disabled.
9 #include <linux/namei.h>
10 #include <linux/slab.h>
11 #include <asm/current.h>
12 #include <asm/uaccess.h>
13 #include <linux/kernel.h>
14 #include <linux/smp_lock.h>
15 #include <linux/security.h>
17 /* Check validity of quotactl */
18 static int check_quotactl_valid(struct super_block
*sb
, int type
, int cmd
, qid_t id
)
20 if (type
>= MAXQUOTAS
)
22 if (!sb
&& cmd
!= Q_SYNC
)
24 /* Is operation supported? */
25 if (sb
&& !sb
->s_qcop
)
32 if (!sb
->s_qcop
->quota_on
)
36 if (!sb
->s_qcop
->quota_off
)
40 if (!sb
->s_qcop
->set_info
)
44 if (!sb
->s_qcop
->get_info
)
48 if (!sb
->s_qcop
->set_dqblk
)
52 if (!sb
->s_qcop
->get_dqblk
)
56 if (sb
&& !sb
->s_qcop
->quota_sync
)
62 if (!sb
->s_qcop
->set_xstate
)
66 if (!sb
->s_qcop
->get_xstate
)
70 if (!sb
->s_qcop
->set_xquota
)
74 if (!sb
->s_qcop
->get_xquota
)
81 /* Is quota turned on for commands which need it? */
89 /* This is just informative test so we are satisfied without a lock */
90 if (!sb_has_quota_enabled(sb
, type
))
93 /* Check privileges */
94 if (cmd
== Q_GETQUOTA
|| cmd
== Q_XGETQUOTA
) {
95 if (((type
== USRQUOTA
&& current
->euid
!= id
) ||
96 (type
== GRPQUOTA
&& !in_egroup_p(id
))) &&
97 !capable(CAP_SYS_ADMIN
))
100 else if (cmd
!= Q_GETFMT
&& cmd
!= Q_SYNC
&& cmd
!= Q_GETINFO
&& cmd
!= Q_XGETQSTAT
)
101 if (!capable(CAP_SYS_ADMIN
))
104 return security_quotactl (cmd
, type
, id
, sb
);
107 static struct super_block
*get_super_to_sync(int type
)
109 struct list_head
*head
;
114 list_for_each(head
, &super_blocks
) {
115 struct super_block
*sb
= list_entry(head
, struct super_block
, s_list
);
117 for (cnt
= 0, dirty
= 0; cnt
< MAXQUOTAS
; cnt
++)
118 if ((type
== cnt
|| type
== -1) && sb_has_quota_enabled(sb
, cnt
)
119 && info_any_dquot_dirty(&sb_dqopt(sb
)->info
[cnt
]))
124 spin_unlock(&sb_lock
);
125 down_read(&sb
->s_umount
);
132 spin_unlock(&sb_lock
);
136 void sync_dquots(struct super_block
*sb
, int type
)
139 if (sb
->s_qcop
->quota_sync
)
140 sb
->s_qcop
->quota_sync(sb
, type
);
143 while ((sb
= get_super_to_sync(type
))) {
144 if (sb
->s_qcop
->quota_sync
)
145 sb
->s_qcop
->quota_sync(sb
, type
);
151 /* Copy parameters and call proper function */
152 static int do_quotactl(struct super_block
*sb
, int type
, int cmd
, qid_t id
, caddr_t addr
)
160 if (IS_ERR(pathname
= getname(addr
)))
161 return PTR_ERR(pathname
);
162 ret
= sb
->s_qcop
->quota_on(sb
, type
, id
, pathname
);
167 return sb
->s_qcop
->quota_off(sb
, type
);
172 down_read(&sb_dqopt(sb
)->dqptr_sem
);
173 if (!sb_has_quota_enabled(sb
, type
)) {
174 up_read(&sb_dqopt(sb
)->dqptr_sem
);
177 fmt
= sb_dqopt(sb
)->info
[type
].dqi_format
->qf_fmt_id
;
178 up_read(&sb_dqopt(sb
)->dqptr_sem
);
179 if (copy_to_user(addr
, &fmt
, sizeof(fmt
)))
184 struct if_dqinfo info
;
186 if ((ret
= sb
->s_qcop
->get_info(sb
, type
, &info
)))
188 if (copy_to_user(addr
, &info
, sizeof(info
)))
193 struct if_dqinfo info
;
195 if (copy_from_user(&info
, addr
, sizeof(info
)))
197 return sb
->s_qcop
->set_info(sb
, type
, &info
);
202 if ((ret
= sb
->s_qcop
->get_dqblk(sb
, type
, id
, &idq
)))
204 if (copy_to_user(addr
, &idq
, sizeof(idq
)))
211 if (copy_from_user(&idq
, addr
, sizeof(idq
)))
213 return sb
->s_qcop
->set_dqblk(sb
, type
, id
, &idq
);
216 sync_dquots(sb
, type
);
224 if (copy_from_user(&flags
, addr
, sizeof(flags
)))
226 return sb
->s_qcop
->set_xstate(sb
, flags
, cmd
);
229 struct fs_quota_stat fqs
;
231 if ((ret
= sb
->s_qcop
->get_xstate(sb
, &fqs
)))
233 if (copy_to_user(addr
, &fqs
, sizeof(fqs
)))
238 struct fs_disk_quota fdq
;
240 if (copy_from_user(&fdq
, addr
, sizeof(fdq
)))
242 return sb
->s_qcop
->set_xquota(sb
, type
, id
, &fdq
);
245 struct fs_disk_quota fdq
;
247 if ((ret
= sb
->s_qcop
->get_xquota(sb
, type
, id
, &fdq
)))
249 if (copy_to_user(addr
, &fdq
, sizeof(fdq
)))
253 /* We never reach here unless validity check is broken */
261 * This is the system call interface. This communicates with
262 * the user-level programs. Currently this only supports diskquota
263 * calls. Maybe we need to add the process quotas etc. in the future,
264 * but we probably should use rlimits for that.
266 asmlinkage
long sys_quotactl(unsigned int cmd
, const char *special
, qid_t id
, caddr_t addr
)
269 struct super_block
*sb
= NULL
;
270 struct block_device
*bdev
;
274 cmds
= cmd
>> SUBCMDSHIFT
;
275 type
= cmd
& SUBCMDMASK
;
277 if (cmds
!= Q_SYNC
|| special
) {
278 tmp
= getname(special
);
281 bdev
= lookup_bdev(tmp
);
284 return PTR_ERR(bdev
);
285 sb
= get_super(bdev
);
291 ret
= check_quotactl_valid(sb
, type
, cmds
, id
);
293 ret
= do_quotactl(sb
, type
, cmds
, id
, addr
);