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>
16 #include <linux/syscalls.h>
17 #include <linux/buffer_head.h>
19 /* Check validity of generic quotactl commands */
20 static int generic_quotactl_valid(struct super_block
*sb
, int type
, int cmd
, qid_t id
)
22 if (type
>= MAXQUOTAS
)
24 if (!sb
&& cmd
!= Q_SYNC
)
26 /* Is operation supported? */
27 if (sb
&& !sb
->s_qcop
)
34 if (!sb
->s_qcop
->quota_on
)
38 if (!sb
->s_qcop
->quota_off
)
42 if (!sb
->s_qcop
->set_info
)
46 if (!sb
->s_qcop
->get_info
)
50 if (!sb
->s_qcop
->set_dqblk
)
54 if (!sb
->s_qcop
->get_dqblk
)
58 if (sb
&& !sb
->s_qcop
->quota_sync
)
65 /* Is quota turned on for commands which need it? */
73 /* This is just informative test so we are satisfied without a lock */
74 if (!sb_has_quota_enabled(sb
, type
))
78 /* Check privileges */
79 if (cmd
== Q_GETQUOTA
) {
80 if (((type
== USRQUOTA
&& current
->euid
!= id
) ||
81 (type
== GRPQUOTA
&& !in_egroup_p(id
))) &&
82 !capable(CAP_SYS_ADMIN
))
85 else if (cmd
!= Q_GETFMT
&& cmd
!= Q_SYNC
&& cmd
!= Q_GETINFO
)
86 if (!capable(CAP_SYS_ADMIN
))
92 /* Check validity of XFS Quota Manager commands */
93 static int xqm_quotactl_valid(struct super_block
*sb
, int type
, int cmd
, qid_t id
)
95 if (type
>= XQM_MAXQUOTAS
)
106 if (!sb
->s_qcop
->set_xstate
)
110 if (!sb
->s_qcop
->get_xstate
)
114 if (!sb
->s_qcop
->set_xquota
)
118 if (!sb
->s_qcop
->get_xquota
)
122 if (!sb
->s_qcop
->quota_sync
)
129 /* Check privileges */
130 if (cmd
== Q_XGETQUOTA
) {
131 if (((type
== XQM_USRQUOTA
&& current
->euid
!= id
) ||
132 (type
== XQM_GRPQUOTA
&& !in_egroup_p(id
))) &&
133 !capable(CAP_SYS_ADMIN
))
135 } else if (cmd
!= Q_XGETQSTAT
&& cmd
!= Q_XQUOTASYNC
) {
136 if (!capable(CAP_SYS_ADMIN
))
143 static int check_quotactl_valid(struct super_block
*sb
, int type
, int cmd
, qid_t id
)
147 if (XQM_COMMAND(cmd
))
148 error
= xqm_quotactl_valid(sb
, type
, cmd
, id
);
150 error
= generic_quotactl_valid(sb
, type
, cmd
, id
);
152 error
= security_quotactl(cmd
, type
, id
, sb
);
156 static void quota_sync_sb(struct super_block
*sb
, int type
)
159 struct inode
*discard
[MAXQUOTAS
];
161 sb
->s_qcop
->quota_sync(sb
, type
);
162 /* This is not very clever (and fast) but currently I don't know about
163 * any other simple way of getting quota data to disk and we must get
164 * them there for userspace to be visible... */
165 if (sb
->s_op
->sync_fs
)
166 sb
->s_op
->sync_fs(sb
, 1);
167 sync_blockdev(sb
->s_bdev
);
169 /* Now when everything is written we can discard the pagecache so
170 * that userspace sees the changes. We need i_sem and so we could
171 * not do it inside dqonoff_sem. Moreover we need to be carefull
172 * about races with quotaoff() (that is the reason why we have own
173 * reference to inode). */
174 down(&sb_dqopt(sb
)->dqonoff_sem
);
175 for (cnt
= 0; cnt
< MAXQUOTAS
; cnt
++) {
177 if (type
!= -1 && cnt
!= type
)
179 if (!sb_has_quota_enabled(sb
, cnt
))
181 discard
[cnt
] = igrab(sb_dqopt(sb
)->files
[cnt
]);
183 up(&sb_dqopt(sb
)->dqonoff_sem
);
184 for (cnt
= 0; cnt
< MAXQUOTAS
; cnt
++) {
186 down(&discard
[cnt
]->i_sem
);
187 truncate_inode_pages(&discard
[cnt
]->i_data
, 0);
188 up(&discard
[cnt
]->i_sem
);
194 void sync_dquots(struct super_block
*sb
, int type
)
199 if (sb
->s_qcop
->quota_sync
)
200 quota_sync_sb(sb
, type
);
206 list_for_each_entry(sb
, &super_blocks
, s_list
) {
207 /* This test just improves performance so it needn't be reliable... */
208 for (cnt
= 0, dirty
= 0; cnt
< MAXQUOTAS
; cnt
++)
209 if ((type
== cnt
|| type
== -1) && sb_has_quota_enabled(sb
, cnt
)
210 && info_any_dirty(&sb_dqopt(sb
)->info
[cnt
]))
215 spin_unlock(&sb_lock
);
216 down_read(&sb
->s_umount
);
217 if (sb
->s_root
&& sb
->s_qcop
->quota_sync
)
218 quota_sync_sb(sb
, type
);
219 up_read(&sb
->s_umount
);
221 if (__put_super_and_need_restart(sb
))
224 spin_unlock(&sb_lock
);
227 /* Copy parameters and call proper function */
228 static int do_quotactl(struct super_block
*sb
, int type
, int cmd
, qid_t id
, void __user
*addr
)
236 if (IS_ERR(pathname
= getname(addr
)))
237 return PTR_ERR(pathname
);
238 ret
= sb
->s_qcop
->quota_on(sb
, type
, id
, pathname
);
243 return sb
->s_qcop
->quota_off(sb
, type
);
248 down_read(&sb_dqopt(sb
)->dqptr_sem
);
249 if (!sb_has_quota_enabled(sb
, type
)) {
250 up_read(&sb_dqopt(sb
)->dqptr_sem
);
253 fmt
= sb_dqopt(sb
)->info
[type
].dqi_format
->qf_fmt_id
;
254 up_read(&sb_dqopt(sb
)->dqptr_sem
);
255 if (copy_to_user(addr
, &fmt
, sizeof(fmt
)))
260 struct if_dqinfo info
;
262 if ((ret
= sb
->s_qcop
->get_info(sb
, type
, &info
)))
264 if (copy_to_user(addr
, &info
, sizeof(info
)))
269 struct if_dqinfo info
;
271 if (copy_from_user(&info
, addr
, sizeof(info
)))
273 return sb
->s_qcop
->set_info(sb
, type
, &info
);
278 if ((ret
= sb
->s_qcop
->get_dqblk(sb
, type
, id
, &idq
)))
280 if (copy_to_user(addr
, &idq
, sizeof(idq
)))
287 if (copy_from_user(&idq
, addr
, sizeof(idq
)))
289 return sb
->s_qcop
->set_dqblk(sb
, type
, id
, &idq
);
292 sync_dquots(sb
, type
);
300 if (copy_from_user(&flags
, addr
, sizeof(flags
)))
302 return sb
->s_qcop
->set_xstate(sb
, flags
, cmd
);
305 struct fs_quota_stat fqs
;
307 if ((ret
= sb
->s_qcop
->get_xstate(sb
, &fqs
)))
309 if (copy_to_user(addr
, &fqs
, sizeof(fqs
)))
314 struct fs_disk_quota fdq
;
316 if (copy_from_user(&fdq
, addr
, sizeof(fdq
)))
318 return sb
->s_qcop
->set_xquota(sb
, type
, id
, &fdq
);
321 struct fs_disk_quota fdq
;
323 if ((ret
= sb
->s_qcop
->get_xquota(sb
, type
, id
, &fdq
)))
325 if (copy_to_user(addr
, &fdq
, sizeof(fdq
)))
330 return sb
->s_qcop
->quota_sync(sb
, type
);
331 /* We never reach here unless validity check is broken */
339 * This is the system call interface. This communicates with
340 * the user-level programs. Currently this only supports diskquota
341 * calls. Maybe we need to add the process quotas etc. in the future,
342 * but we probably should use rlimits for that.
344 asmlinkage
long sys_quotactl(unsigned int cmd
, const char __user
*special
, qid_t id
, void __user
*addr
)
347 struct super_block
*sb
= NULL
;
348 struct block_device
*bdev
;
352 cmds
= cmd
>> SUBCMDSHIFT
;
353 type
= cmd
& SUBCMDMASK
;
355 if (cmds
!= Q_SYNC
|| special
) {
356 tmp
= getname(special
);
359 bdev
= lookup_bdev(tmp
);
362 return PTR_ERR(bdev
);
363 sb
= get_super(bdev
);
369 ret
= check_quotactl_valid(sb
, type
, cmds
, id
);
371 ret
= do_quotactl(sb
, type
, cmds
, id
, addr
);
This page took 0.039661 seconds and 6 git commands to generate.