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/security.h>
15 #include <linux/syscalls.h>
16 #include <linux/buffer_head.h>
17 #include <linux/capability.h>
18 #include <linux/quotaops.h>
19 #include <linux/types.h>
20 #include <linux/writeback.h>
21 #include "../internal.h"
23 static int check_quotactl_permission(struct super_block
*sb
, int type
, int cmd
,
27 /* these commands do not require any special privilegues */
34 /* allow to query information for dquots we "own" */
37 if ((type
== USRQUOTA
&& current_euid() == id
) ||
38 (type
== GRPQUOTA
&& in_egroup_p(id
)))
42 if (!capable(CAP_SYS_ADMIN
))
46 return security_quotactl(cmd
, type
, id
, sb
);
49 static int quota_sync_all(int type
)
51 struct super_block
*sb
, *n
;
54 if (type
>= MAXQUOTAS
)
56 ret
= security_quotactl(Q_SYNC
, type
, 0, NULL
);
61 list_for_each_entry_safe(sb
, n
, &super_blocks
, s_list
) {
62 if (list_empty(&sb
->s_instances
))
64 if (!sb
->s_qcop
|| !sb
->s_qcop
->quota_sync
)
68 spin_unlock(&sb_lock
);
69 down_read(&sb
->s_umount
);
71 sb
->s_qcop
->quota_sync(sb
, type
, 1);
72 up_read(&sb
->s_umount
);
76 spin_unlock(&sb_lock
);
81 static int quota_quotaon(struct super_block
*sb
, int type
, int cmd
, qid_t id
,
87 pathname
= getname(addr
);
89 return PTR_ERR(pathname
);
90 if (sb
->s_qcop
->quota_on
)
91 ret
= sb
->s_qcop
->quota_on(sb
, type
, id
, pathname
, 0);
96 static int quota_getfmt(struct super_block
*sb
, int type
, void __user
*addr
)
100 down_read(&sb_dqopt(sb
)->dqptr_sem
);
101 if (!sb_has_quota_active(sb
, type
)) {
102 up_read(&sb_dqopt(sb
)->dqptr_sem
);
105 fmt
= sb_dqopt(sb
)->info
[type
].dqi_format
->qf_fmt_id
;
106 up_read(&sb_dqopt(sb
)->dqptr_sem
);
107 if (copy_to_user(addr
, &fmt
, sizeof(fmt
)))
112 static int quota_getinfo(struct super_block
*sb
, int type
, void __user
*addr
)
114 struct if_dqinfo info
;
117 if (!sb
->s_qcop
->get_info
)
119 ret
= sb
->s_qcop
->get_info(sb
, type
, &info
);
120 if (!ret
&& copy_to_user(addr
, &info
, sizeof(info
)))
125 static int quota_setinfo(struct super_block
*sb
, int type
, void __user
*addr
)
127 struct if_dqinfo info
;
129 if (copy_from_user(&info
, addr
, sizeof(info
)))
131 if (!sb
->s_qcop
->set_info
)
133 return sb
->s_qcop
->set_info(sb
, type
, &info
);
136 static void copy_to_if_dqblk(struct if_dqblk
*dst
, struct fs_disk_quota
*src
)
138 dst
->dqb_bhardlimit
= src
->d_blk_hardlimit
;
139 dst
->dqb_bsoftlimit
= src
->d_blk_softlimit
;
140 dst
->dqb_curspace
= src
->d_bcount
;
141 dst
->dqb_ihardlimit
= src
->d_ino_hardlimit
;
142 dst
->dqb_isoftlimit
= src
->d_ino_softlimit
;
143 dst
->dqb_curinodes
= src
->d_icount
;
144 dst
->dqb_btime
= src
->d_btimer
;
145 dst
->dqb_itime
= src
->d_itimer
;
146 dst
->dqb_valid
= QIF_ALL
;
149 static int quota_getquota(struct super_block
*sb
, int type
, qid_t id
,
152 struct fs_disk_quota fdq
;
156 if (!sb
->s_qcop
->get_dqblk
)
158 ret
= sb
->s_qcop
->get_dqblk(sb
, type
, id
, &fdq
);
161 copy_to_if_dqblk(&idq
, &fdq
);
162 if (copy_to_user(addr
, &idq
, sizeof(idq
)))
167 static void copy_from_if_dqblk(struct fs_disk_quota
*dst
, struct if_dqblk
*src
)
169 dst
->d_blk_hardlimit
= src
->dqb_bhardlimit
;
170 dst
->d_blk_softlimit
= src
->dqb_bsoftlimit
;
171 dst
->d_bcount
= src
->dqb_curspace
;
172 dst
->d_ino_hardlimit
= src
->dqb_ihardlimit
;
173 dst
->d_ino_softlimit
= src
->dqb_isoftlimit
;
174 dst
->d_icount
= src
->dqb_curinodes
;
175 dst
->d_btimer
= src
->dqb_btime
;
176 dst
->d_itimer
= src
->dqb_itime
;
178 dst
->d_fieldmask
= 0;
179 if (src
->dqb_valid
& QIF_BLIMITS
)
180 dst
->d_fieldmask
|= FS_DQ_BSOFT
| FS_DQ_BHARD
;
181 if (src
->dqb_valid
& QIF_SPACE
)
182 dst
->d_fieldmask
|= FS_DQ_BCOUNT
;
183 if (src
->dqb_valid
& QIF_ILIMITS
)
184 dst
->d_fieldmask
|= FS_DQ_ISOFT
| FS_DQ_IHARD
;
185 if (src
->dqb_valid
& QIF_INODES
)
186 dst
->d_fieldmask
|= FS_DQ_ICOUNT
;
187 if (src
->dqb_valid
& QIF_BTIME
)
188 dst
->d_fieldmask
|= FS_DQ_BTIMER
;
189 if (src
->dqb_valid
& QIF_ITIME
)
190 dst
->d_fieldmask
|= FS_DQ_ITIMER
;
193 static int quota_setquota(struct super_block
*sb
, int type
, qid_t id
,
196 struct fs_disk_quota fdq
;
199 if (copy_from_user(&idq
, addr
, sizeof(idq
)))
201 if (!sb
->s_qcop
->set_dqblk
)
203 copy_from_if_dqblk(&fdq
, &idq
);
204 return sb
->s_qcop
->set_dqblk(sb
, type
, id
, &fdq
);
207 static int quota_setxstate(struct super_block
*sb
, int cmd
, void __user
*addr
)
211 if (copy_from_user(&flags
, addr
, sizeof(flags
)))
213 if (!sb
->s_qcop
->set_xstate
)
215 return sb
->s_qcop
->set_xstate(sb
, flags
, cmd
);
218 static int quota_getxstate(struct super_block
*sb
, void __user
*addr
)
220 struct fs_quota_stat fqs
;
223 if (!sb
->s_qcop
->get_xstate
)
225 ret
= sb
->s_qcop
->get_xstate(sb
, &fqs
);
226 if (!ret
&& copy_to_user(addr
, &fqs
, sizeof(fqs
)))
231 static int quota_setxquota(struct super_block
*sb
, int type
, qid_t id
,
234 struct fs_disk_quota fdq
;
236 if (copy_from_user(&fdq
, addr
, sizeof(fdq
)))
238 if (!sb
->s_qcop
->set_dqblk
)
240 return sb
->s_qcop
->set_dqblk(sb
, type
, id
, &fdq
);
243 static int quota_getxquota(struct super_block
*sb
, int type
, qid_t id
,
246 struct fs_disk_quota fdq
;
249 if (!sb
->s_qcop
->get_dqblk
)
251 ret
= sb
->s_qcop
->get_dqblk(sb
, type
, id
, &fdq
);
252 if (!ret
&& copy_to_user(addr
, &fdq
, sizeof(fdq
)))
257 /* Copy parameters and call proper function */
258 static int do_quotactl(struct super_block
*sb
, int type
, int cmd
, qid_t id
,
263 if (type
>= (XQM_COMMAND(cmd
) ? XQM_MAXQUOTAS
: MAXQUOTAS
))
268 ret
= check_quotactl_permission(sb
, type
, cmd
, id
);
274 return quota_quotaon(sb
, type
, cmd
, id
, addr
);
276 if (!sb
->s_qcop
->quota_off
)
278 return sb
->s_qcop
->quota_off(sb
, type
, 0);
280 return quota_getfmt(sb
, type
, addr
);
282 return quota_getinfo(sb
, type
, addr
);
284 return quota_setinfo(sb
, type
, addr
);
286 return quota_getquota(sb
, type
, id
, addr
);
288 return quota_setquota(sb
, type
, id
, addr
);
290 if (!sb
->s_qcop
->quota_sync
)
292 return sb
->s_qcop
->quota_sync(sb
, type
, 1);
296 return quota_setxstate(sb
, cmd
, addr
);
298 return quota_getxstate(sb
, addr
);
300 return quota_setxquota(sb
, type
, id
, addr
);
302 return quota_getxquota(sb
, type
, id
, addr
);
304 /* caller already holds s_umount */
305 if (sb
->s_flags
& MS_RDONLY
)
307 writeback_inodes_sb(sb
);
315 * look up a superblock on which quota ops will be performed
316 * - use the name of a block device to find the superblock thereon
318 static struct super_block
*quotactl_block(const char __user
*special
)
321 struct block_device
*bdev
;
322 struct super_block
*sb
;
323 char *tmp
= getname(special
);
326 return ERR_CAST(tmp
);
327 bdev
= lookup_bdev(tmp
);
330 return ERR_CAST(bdev
);
331 sb
= get_super(bdev
);
334 return ERR_PTR(-ENODEV
);
338 return ERR_PTR(-ENODEV
);
343 * This is the system call interface. This communicates with
344 * the user-level programs. Currently this only supports diskquota
345 * calls. Maybe we need to add the process quotas etc. in the future,
346 * but we probably should use rlimits for that.
348 SYSCALL_DEFINE4(quotactl
, unsigned int, cmd
, const char __user
*, special
,
349 qid_t
, id
, void __user
*, addr
)
352 struct super_block
*sb
= NULL
;
355 cmds
= cmd
>> SUBCMDSHIFT
;
356 type
= cmd
& SUBCMDMASK
;
359 * As a special case Q_SYNC can be called without a specific device.
360 * It will iterate all superblocks that have quota enabled and call
361 * the sync action on each of them.
365 return quota_sync_all(type
);
369 sb
= quotactl_block(special
);
373 ret
= do_quotactl(sb
, type
, cmds
, id
, addr
);
This page took 0.038967 seconds and 5 git commands to generate.