]>
git.saurik.com Git - apple/hfs.git/blob - core/hfs_quota.c
2 * Copyright (c) 2002-2015 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1982, 1986, 1990, 1993, 1995
30 * The Regents of the University of California. All rights reserved.
32 * This code is derived from software contributed to Berkeley by
33 * Robert Elz at The University of Melbourne.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * derived from @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95
69 #include <sys/param.h>
70 #include <sys/kernel.h>
71 #include <sys/systm.h>
72 #include <sys/mount.h>
73 #include <sys/malloc.h>
76 #include <sys/kauth.h>
77 #include <sys/vnode.h>
78 #include <sys/quota.h>
82 #include "hfs_cnode.h"
83 #include "hfs_quota.h"
84 #include "hfs_mount.h"
88 * Quota name to error message mapping.
91 static char *quotatypes
[] = INITQFNAMES
;
95 * Set up the quotas for a cnode.
97 * This routine completely defines the semantics of quotas.
98 * If other criterion want to be used to establish quotas, the
99 * MAXQUOTAS value in quotas.h should be increased, and the
100 * additional dquots set up here.
104 register struct cnode
*cp
;
106 struct hfsmount
*hfsmp
;
109 int drop_usrquota
= false;
111 vp
= cp
->c_vp
? cp
->c_vp
: cp
->c_rsrc_vp
;
114 * Set up the user quota based on file uid.
115 * EINVAL means that quotas are not enabled.
117 if (cp
->c_dquot
[USRQUOTA
] == NODQUOT
) {
118 error
= dqget(cp
->c_uid
, &hfsmp
->hfs_qfiles
[USRQUOTA
], USRQUOTA
, &cp
->c_dquot
[USRQUOTA
]);
119 if ((error
!= 0) && (error
!= EINVAL
)) {
121 } else if (error
== 0) {
122 drop_usrquota
= true;
127 * Set up the group quota based on file gid.
128 * EINVAL means that quotas are not enabled.
130 if (cp
->c_dquot
[GRPQUOTA
] == NODQUOT
) {
131 error
= dqget(cp
->c_gid
, &hfsmp
->hfs_qfiles
[GRPQUOTA
], GRPQUOTA
, &cp
->c_dquot
[GRPQUOTA
]);
132 if ((error
!= 0) && (error
!= EINVAL
)) {
133 if (drop_usrquota
== true) {
134 dqrele(cp
->c_dquot
[USRQUOTA
]);
135 cp
->c_dquot
[USRQUOTA
] = NODQUOT
;
145 * Update disk usage, and take corrective action.
148 hfs_chkdq(cp
, change
, cred
, flags
)
149 register struct cnode
*cp
;
154 register struct dquot
*dq
;
161 if ((flags
& CHOWN
) == 0)
167 for (i
= 0; i
< MAXQUOTAS
; i
++) {
168 if ((dq
= cp
->c_dquot
[i
]) == NODQUOT
)
172 ncurbytes
= dq
->dq_curbytes
+ change
;
174 dq
->dq_curbytes
= ncurbytes
;
177 dq
->dq_flags
&= ~DQ_BLKS
;
178 dq
->dq_flags
|= DQ_MOD
;
186 * This use of proc_ucred() is safe because kernproc credential never
189 if (!IS_VALID_CRED(cred
))
190 cred
= proc_ucred(kernproc
);
191 if (suser(cred
, NULL
) || proc_forcequota(p
)) {
192 for (i
= 0; i
< MAXQUOTAS
; i
++) {
193 if ((dq
= cp
->c_dquot
[i
]) == NODQUOT
)
195 error
= hfs_chkdqchg(cp
, change
, cred
, i
);
201 if ((flags
& FORCE
) || error
== 0) {
202 for (i
= 0; i
< MAXQUOTAS
; i
++) {
203 if ((dq
= cp
->c_dquot
[i
]) == NODQUOT
)
207 dq
->dq_curbytes
+= change
;
208 dq
->dq_flags
|= DQ_MOD
;
217 * Check for a valid change to a users allocation.
218 * Issue an error message and vfs event if appropriate.
221 hfs_chkdqchg(cp
, change
, cred
, type
)
227 register struct dquot
*dq
= cp
->c_dquot
[type
];
229 struct vnode
*vp
= cp
->c_vp
? cp
->c_vp
: cp
->c_rsrc_vp
;
232 fsid
.val
[0] = VTOHFS(vp
)->hfs_raw_dev
;
233 fsid
.val
[1] = vfs_typenum(VTOVFS(vp
));
237 ncurbytes
= dq
->dq_curbytes
+ change
;
239 * If user would exceed their hard limit, disallow space allocation.
241 if (ncurbytes
>= dq
->dq_bhardlimit
&& dq
->dq_bhardlimit
) {
242 if ((dq
->dq_flags
& DQ_BLKS
) == 0 &&
243 cp
->c_uid
== kauth_cred_getuid(cred
)) {
245 printf("\nhfs: write failed, %s disk limit reached\n",
248 dq
->dq_flags
|= DQ_BLKS
;
249 vfs_event_signal(&fsid
, VQ_QUOTA
, (intptr_t)NULL
);
256 * If user is over their soft limit for too long, disallow space
257 * allocation. Reset time limit as they cross their soft limit.
259 if (ncurbytes
>= dq
->dq_bsoftlimit
&& dq
->dq_bsoftlimit
) {
263 if (dq
->dq_curbytes
< dq
->dq_bsoftlimit
) {
264 dq
->dq_btime
= tv
.tv_sec
+
265 VTOHFS(vp
)->hfs_qfiles
[type
].qf_btime
;
267 if (cp
->c_uid
== kauth_cred_getuid(cred
))
268 printf("\nhfs: warning, %s %s\n",
269 quotatypes
[type
], "disk quota exceeded");
271 vfs_event_signal(&fsid
, VQ_QUOTA
, (intptr_t)NULL
);
276 if (tv
.tv_sec
> (time_t)dq
->dq_btime
) {
277 if ((dq
->dq_flags
& DQ_BLKS
) == 0 &&
278 cp
->c_uid
== kauth_cred_getuid(cred
)) {
280 printf("\nhfs: write failed, %s %s\n",
282 "disk quota exceeded for too long");
284 dq
->dq_flags
|= DQ_BLKS
;
285 vfs_event_signal(&fsid
, VQ_QUOTA
, (intptr_t)NULL
);
298 * Check the inode limit, applying corrective action.
301 hfs_chkiq(cp
, change
, cred
, flags
)
302 register struct cnode
*cp
;
307 register struct dquot
*dq
;
309 int ncurinodes
, error
=0;
313 if ((flags
& CHOWN
) == 0)
319 for (i
= 0; i
< MAXQUOTAS
; i
++) {
320 if ((dq
= cp
->c_dquot
[i
]) == NODQUOT
)
324 ncurinodes
= dq
->dq_curinodes
+ change
;
326 dq
->dq_curinodes
= ncurinodes
;
328 dq
->dq_curinodes
= 0;
329 dq
->dq_flags
&= ~DQ_INODS
;
330 dq
->dq_flags
|= DQ_MOD
;
338 * This use of proc_ucred() is safe because kernproc credential never
341 if (!IS_VALID_CRED(cred
))
342 cred
= proc_ucred(kernproc
);
343 if (suser(cred
, NULL
) || proc_forcequota(p
)) {
344 for (i
= 0; i
< MAXQUOTAS
; i
++) {
345 if ((dq
= cp
->c_dquot
[i
]) == NODQUOT
)
347 error
= hfs_chkiqchg(cp
, change
, cred
, i
);
353 if ((flags
& FORCE
) || error
== 0) {
354 for (i
= 0; i
< MAXQUOTAS
; i
++) {
355 if ((dq
= cp
->c_dquot
[i
]) == NODQUOT
)
359 dq
->dq_curinodes
+= change
;
360 dq
->dq_flags
|= DQ_MOD
;
370 * Check to see if a change to a user's allocation should be permitted or not.
371 * Issue an error message if it should not be permitted. Return 0 if
372 * it should be allowed.
374 int hfs_isiqchg_allowed(dq
, hfsmp
, change
, cred
, type
, uid
)
376 struct hfsmount
* hfsmp
;
382 u_int32_t ncurinodes
;
385 fsid
.val
[0] = hfsmp
->hfs_raw_dev
;
386 fsid
.val
[1] = vfs_typenum(HFSTOVFS(hfsmp
));
390 ncurinodes
= dq
->dq_curinodes
+ change
;
392 * If user would exceed their hard limit, disallow cnode allocation.
394 if (ncurinodes
>= dq
->dq_ihardlimit
&& dq
->dq_ihardlimit
) {
395 if ((dq
->dq_flags
& DQ_INODS
) == 0 &&
396 uid
== kauth_cred_getuid(cred
)) {
397 dq
->dq_flags
|= DQ_INODS
;
398 vfs_event_signal(&fsid
, VQ_QUOTA
, (intptr_t)NULL
);
405 * If user is over their soft limit for too long, disallow cnode
406 * allocation. Reset time limit as they cross their soft limit.
408 if (ncurinodes
>= dq
->dq_isoftlimit
&& dq
->dq_isoftlimit
) {
412 if (dq
->dq_curinodes
< dq
->dq_isoftlimit
) {
413 dq
->dq_itime
= tv
.tv_sec
+ hfsmp
->hfs_qfiles
[type
].qf_itime
;
414 vfs_event_signal(&fsid
, VQ_QUOTA
, (intptr_t)NULL
);
418 if (tv
.tv_sec
> (time_t)dq
->dq_itime
) {
419 if (((dq
->dq_flags
& DQ_INODS
) == 0) &&
420 (uid
== kauth_cred_getuid(cred
))) {
421 dq
->dq_flags
|= DQ_INODS
;
422 vfs_event_signal(&fsid
, VQ_QUOTA
, (intptr_t)NULL
);
436 * Check for a valid change to a users allocation.
437 * Issue an error message if appropriate.
440 hfs_chkiqchg(cp
, change
, cred
, type
)
446 register struct dquot
*dq
= cp
->c_dquot
[type
];
447 u_int32_t ncurinodes
;
448 struct vnode
*vp
= cp
->c_vp
? cp
->c_vp
: cp
->c_rsrc_vp
;
452 ncurinodes
= dq
->dq_curinodes
+ change
;
454 * If user would exceed their hard limit, disallow cnode allocation.
456 if (ncurinodes
>= dq
->dq_ihardlimit
&& dq
->dq_ihardlimit
) {
457 if ((dq
->dq_flags
& DQ_INODS
) == 0 &&
458 cp
->c_uid
== kauth_cred_getuid(cred
)) {
460 printf("\nhfs: write failed, %s cnode limit reached\n",
463 dq
->dq_flags
|= DQ_INODS
;
470 * If user is over their soft limit for too long, disallow cnode
471 * allocation. Reset time limit as they cross their soft limit.
473 if (ncurinodes
>= dq
->dq_isoftlimit
&& dq
->dq_isoftlimit
) {
477 if (dq
->dq_curinodes
< dq
->dq_isoftlimit
) {
478 dq
->dq_itime
= tv
.tv_sec
+
479 VTOHFS(vp
)->hfs_qfiles
[type
].qf_itime
;
481 if (cp
->c_uid
== kauth_cred_getuid(cred
))
482 printf("\nhfs: warning, %s %s\n",
483 quotatypes
[type
], "cnode quota exceeded");
489 if (tv
.tv_sec
> (time_t)dq
->dq_itime
) {
490 if ((dq
->dq_flags
& DQ_INODS
) == 0 &&
491 cp
->c_uid
== kauth_cred_getuid(cred
)) {
493 printf("\nhfs: write failed, %s %s\n",
495 "cnode quota exceeded for too long");
497 dq
->dq_flags
|= DQ_INODS
;
511 * On filesystems with quotas enabled, it is an error for a file to change
512 * size and not to have a dquot structure associated with it.
516 register struct cnode
*cp
;
518 struct vnode
*vp
= cp
->c_vp
? cp
->c_vp
: cp
->c_rsrc_vp
;
519 struct hfsmount
*hfsmp
= VTOHFS(vp
);
522 for (i
= 0; i
< MAXQUOTAS
; i
++) {
523 if (hfsmp
->hfs_qfiles
[i
].qf_vp
== NULLVP
)
525 if (cp
->c_dquot
[i
] == NODQUOT
) {
526 vprint("chkdquot: missing dquot", vp
);
527 panic("missing dquot");
534 * Code to process quotactl commands.
538 * Q_QUOTAON - set up a quota file for a particular file system.
540 struct hfs_quotaon_cargs
{
545 hfs_quotaon_callback(struct vnode
*vp
, void *cargs
)
547 struct hfs_quotaon_cargs
*args
;
549 args
= (struct hfs_quotaon_cargs
*)cargs
;
551 args
->error
= hfs_getinoquota(VTOC(vp
));
553 return (VNODE_RETURNED_DONE
);
555 return (VNODE_RETURNED
);
559 hfs_quotaon(p
, mp
, type
, fnamep
)
565 struct hfsmount
*hfsmp
= VFSTOHFS(mp
);
566 struct quotafile
*qfp
;
569 struct hfs_quotaon_cargs args
;
571 /* Finish setting up quota structures. */
574 qfp
= &hfsmp
->hfs_qfiles
[type
];
576 if ( (qf_get(qfp
, QTF_OPENING
)) )
579 error
= vnode_open(fnamep
, FREAD
|FWRITE
, 0, 0, &vp
, NULL
);
583 if (!vnode_isreg(vp
)) {
584 (void) vnode_close(vp
, FREAD
|FWRITE
, NULL
);
588 vfs_setflags(mp
, (u_int64_t
)((unsigned int)MNT_QUOTA
));
589 hfs_lock_mount (hfsmp
);
590 hfsmp
->hfs_flags
|= HFS_QUOTAS
;
591 hfs_unlock_mount (hfsmp
);
592 vnode_setnoflush(vp
);
594 * Save the credential of the process that turned on quotas.
596 qfp
->qf_cred
= kauth_cred_proc_ref(p
);
599 * Finish initializing the quota file
601 error
= dqfileopen(qfp
, type
);
603 (void) vnode_close(vp
, FREAD
|FWRITE
, NULL
);
605 if (IS_VALID_CRED(qfp
->qf_cred
))
606 kauth_cred_unref(&qfp
->qf_cred
);
610 qf_put(qfp
, QTF_OPENING
);
613 * Search vnodes associated with this mount point,
614 * adding references to quota file being opened.
615 * NB: only need to add dquot's for cnodes being modified.
617 * hfs_quota_callback will be called for each vnode open for
618 * 'write' (VNODE_WRITEABLE) hung off of this mount point
619 * the vnode will be in an 'unbusy' state (VNODE_WAIT) and
620 * properly referenced and unreferenced around the callback
624 vnode_iterate(mp
, VNODE_WRITEABLE
| VNODE_WAIT
, hfs_quotaon_callback
, (void *)&args
);
629 hfs_quotaoff(p
, mp
, type
);
634 qf_put(qfp
, QTF_OPENING
);
641 * Q_QUOTAOFF - turn off disk quotas for a filesystem.
643 struct hfs_quotaoff_cargs
{
648 hfs_quotaoff_callback(struct vnode
*vp
, void *cargs
)
650 struct hfs_quotaoff_cargs
*args
;
654 args
= (struct hfs_quotaoff_cargs
*)cargs
;
658 dq
= cp
->c_dquot
[args
->type
];
659 cp
->c_dquot
[args
->type
] = NODQUOT
;
663 return (VNODE_RETURNED
);
667 hfs_quotaoff(__unused
struct proc
*p
, struct mount
*mp
, register int type
)
670 struct hfsmount
*hfsmp
= VFSTOHFS(mp
);
671 struct quotafile
*qfp
;
673 struct hfs_quotaoff_cargs args
;
676 * If quotas haven't been initialized, there's no work to be done.
678 if (!dqisinitialized())
681 qfp
= &hfsmp
->hfs_qfiles
[type
];
683 if ( (qf_get(qfp
, QTF_CLOSING
)) )
688 * Sync out any orpaned dirty dquot entries.
693 * Search vnodes associated with this mount point,
694 * deleting any references to quota file being closed.
696 * hfs_quotaoff_callback will be called for each vnode
697 * hung off of this mount point
698 * the vnode will be in an 'unbusy' state (VNODE_WAIT) and
699 * properly referenced and unreferenced around the callback
703 vnode_iterate(mp
, VNODE_WAIT
, hfs_quotaoff_callback
, (void *)&args
);
706 /* Finish tearing down the quota file */
707 dqfileclose(qfp
, type
);
709 vnode_clearnoflush(qvp
);
710 error
= vnode_close(qvp
, FREAD
|FWRITE
, NULL
);
714 if (IS_VALID_CRED(qfp
->qf_cred
))
715 kauth_cred_unref(&qfp
->qf_cred
);
716 for (type
= 0; type
< MAXQUOTAS
; type
++)
717 if (hfsmp
->hfs_qfiles
[type
].qf_vp
!= NULLVP
)
719 if (type
== MAXQUOTAS
) {
720 vfs_clearflags(mp
, (u_int64_t
)((unsigned int)MNT_QUOTA
));
721 hfs_lock_mount (hfsmp
);
722 hfsmp
->hfs_flags
&= ~HFS_QUOTAS
;
723 hfs_unlock_mount (hfsmp
);
726 qf_put(qfp
, QTF_CLOSING
);
732 * hfs_quotacheck - checks quotas mountwide for a hypothetical situation. It probes
733 * the quota data structures to see if adding an inode would be allowed or not. If it
734 * will be allowed, the change is made. Otherwise, it reports an error back out so the
735 * caller will know not to proceed with inode allocation in the HFS Catalog.
737 * Note that this function ONLY tests for addition of inodes, not subtraction.
739 int hfs_quotacheck(hfsmp
, change
, uid
, gid
, cred
)
740 struct hfsmount
*hfsmp
;
746 struct dquot
*dq
= NULL
;
753 if (!IS_VALID_CRED(cred
)) {
754 /* This use of proc_ucred() is safe because kernproc credential never changes */
755 cred
= proc_ucred(kernproc
);
758 if (suser(cred
, NULL
) || proc_forcequota(p
)) {
759 for (i
= 0; i
< MAXQUOTAS
; i
++) {
760 /* Select if user or group id should be used */
763 else if (i
== GRPQUOTA
)
766 error
= dqget(id
, &hfsmp
->hfs_qfiles
[i
], i
, &dq
);
767 if (error
&& (error
!= EINVAL
))
774 /* Check quota information */
775 error
= hfs_isiqchg_allowed(dq
, hfsmp
, change
, cred
, i
, id
);
782 /* Update quota information */
783 dq
->dq_curinodes
+= change
;
794 * Q_GETQUOTA - return current values in a dqblk structure.
797 hfs_getquota(mp
, id
, type
, datap
)
806 error
= dqget(id
, &VFSTOHFS(mp
)->hfs_qfiles
[type
], type
, &dq
);
811 bcopy(&dq
->dq_dqb
, datap
, sizeof(dq
->dq_dqb
));
820 * Q_SETQUOTA - assign an entire dqblk structure.
823 hfs_setquota(mp
, id
, type
, datap
)
830 struct hfsmount
*hfsmp
= VFSTOHFS(mp
);
831 struct dqblk
* newlimp
= (struct dqblk
*) datap
;
835 error
= dqget(id
, &hfsmp
->hfs_qfiles
[type
], type
, &dq
);
841 * Copy all but the current values.
842 * Reset time limit if previously had no soft limit or were
843 * under it, but now have a soft limit and are over it.
845 newlimp
->dqb_curbytes
= dq
->dq_curbytes
;
846 newlimp
->dqb_curinodes
= dq
->dq_curinodes
;
847 if (dq
->dq_id
!= 0) {
848 newlimp
->dqb_btime
= dq
->dq_btime
;
849 newlimp
->dqb_itime
= dq
->dq_itime
;
851 if (newlimp
->dqb_bsoftlimit
&&
852 dq
->dq_curbytes
>= newlimp
->dqb_bsoftlimit
&&
853 (dq
->dq_bsoftlimit
== 0 || dq
->dq_curbytes
< dq
->dq_bsoftlimit
)) {
855 newlimp
->dqb_btime
= tv
.tv_sec
+ hfsmp
->hfs_qfiles
[type
].qf_btime
;
857 if (newlimp
->dqb_isoftlimit
&&
858 dq
->dq_curinodes
>= newlimp
->dqb_isoftlimit
&&
859 (dq
->dq_isoftlimit
== 0 || dq
->dq_curinodes
< dq
->dq_isoftlimit
)) {
861 newlimp
->dqb_itime
= tv
.tv_sec
+ hfsmp
->hfs_qfiles
[type
].qf_itime
;
863 bcopy(newlimp
, &dq
->dq_dqb
, sizeof(dq
->dq_dqb
));
864 if (dq
->dq_curbytes
< dq
->dq_bsoftlimit
)
865 dq
->dq_flags
&= ~DQ_BLKS
;
866 if (dq
->dq_curinodes
< dq
->dq_isoftlimit
)
867 dq
->dq_flags
&= ~DQ_INODS
;
868 if (dq
->dq_isoftlimit
== 0 && dq
->dq_bsoftlimit
== 0 &&
869 dq
->dq_ihardlimit
== 0 && dq
->dq_bhardlimit
== 0)
870 dq
->dq_flags
|= DQ_FAKE
;
872 dq
->dq_flags
&= ~DQ_FAKE
;
873 dq
->dq_flags
|= DQ_MOD
;
882 * Q_SETUSE - set current cnode and byte usage.
885 hfs_setuse(mp
, id
, type
, datap
)
891 struct hfsmount
*hfsmp
= VFSTOHFS(mp
);
895 struct dqblk
*quotablkp
= (struct dqblk
*) datap
;
897 error
= dqget(id
, &hfsmp
->hfs_qfiles
[type
], type
, &dq
);
903 * Reset time limit if have a soft limit and were
904 * previously under it, but are now over it.
906 if (dq
->dq_bsoftlimit
&& dq
->dq_curbytes
< dq
->dq_bsoftlimit
&&
907 quotablkp
->dqb_curbytes
>= dq
->dq_bsoftlimit
) {
909 dq
->dq_btime
= tv
.tv_sec
+ hfsmp
->hfs_qfiles
[type
].qf_btime
;
911 if (dq
->dq_isoftlimit
&& dq
->dq_curinodes
< dq
->dq_isoftlimit
&&
912 quotablkp
->dqb_curinodes
>= dq
->dq_isoftlimit
) {
914 dq
->dq_itime
= tv
.tv_sec
+ hfsmp
->hfs_qfiles
[type
].qf_itime
;
916 dq
->dq_curbytes
= quotablkp
->dqb_curbytes
;
917 dq
->dq_curinodes
= quotablkp
->dqb_curinodes
;
918 if (dq
->dq_curbytes
< dq
->dq_bsoftlimit
)
919 dq
->dq_flags
&= ~DQ_BLKS
;
920 if (dq
->dq_curinodes
< dq
->dq_isoftlimit
)
921 dq
->dq_flags
&= ~DQ_INODS
;
922 dq
->dq_flags
|= DQ_MOD
;
932 * Q_SYNC - sync quota files to disk.
935 hfs_qsync_callback(struct vnode
*vp
, __unused
void *cargs
)
943 for (i
= 0; i
< MAXQUOTAS
; i
++) {
945 if (dq
!= NODQUOT
&& (dq
->dq_flags
& DQ_MOD
))
948 return (VNODE_RETURNED
);
955 struct hfsmount
*hfsmp
= VFSTOHFS(mp
);
958 if (!dqisinitialized())
962 * Check if the mount point has any quotas.
963 * If not, simply return.
965 for (i
= 0; i
< MAXQUOTAS
; i
++)
966 if (hfsmp
->hfs_qfiles
[i
].qf_vp
!= NULLVP
)
972 * Sync out any orpaned dirty dquot entries.
974 for (i
= 0; i
< MAXQUOTAS
; i
++)
975 if (hfsmp
->hfs_qfiles
[i
].qf_vp
!= NULLVP
)
976 dqsync_orphans(&hfsmp
->hfs_qfiles
[i
]);
979 * Search vnodes associated with this mount point,
980 * synchronizing any modified dquot structures.
982 * hfs_qsync_callback will be called for each vnode
983 * hung off of this mount point
985 * properly referenced and unreferenced around the callback
987 vnode_iterate(mp
, 0, hfs_qsync_callback
, (void *)NULL
);
993 * Q_QUOTASTAT - get quota on/off status
996 hfs_quotastat(mp
, type
, datap
)
1001 struct hfsmount
*hfsmp
= VFSTOHFS(mp
);
1005 if ((((unsigned int)vfs_flags(mp
)) & MNT_QUOTA
) && (hfsmp
->hfs_qfiles
[type
].qf_vp
!= NULLVP
))
1006 qstat
= 1; /* quotas are on for this type */
1008 qstat
= 0; /* quotas are off for this type */
1010 *((int *)datap
) = qstat
;