]>
git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfs_quota.c
2 * Copyright (c) 2002-2008 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
67 #include <sys/param.h>
68 #include <sys/kernel.h>
69 #include <sys/systm.h>
70 #include <sys/mount.h>
71 #include <sys/malloc.h>
74 #include <sys/kauth.h>
75 #include <sys/vnode.h>
76 #include <sys/vnode_internal.h>
77 #include <sys/quota.h>
78 #include <sys/proc_internal.h>
79 #include <kern/kalloc.h>
82 #include <hfs/hfs_cnode.h>
83 #include <hfs/hfs_quota.h>
84 #include <hfs/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 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
;
233 ncurbytes
= dq
->dq_curbytes
+ change
;
235 * If user would exceed their hard limit, disallow space allocation.
237 if (ncurbytes
>= dq
->dq_bhardlimit
&& dq
->dq_bhardlimit
) {
238 if ((dq
->dq_flags
& DQ_BLKS
) == 0 &&
239 cp
->c_uid
== kauth_cred_getuid(cred
)) {
241 printf("\nhfs: write failed, %s disk limit reached\n",
244 dq
->dq_flags
|= DQ_BLKS
;
251 * If user is over their soft limit for too long, disallow space
252 * allocation. Reset time limit as they cross their soft limit.
254 if (ncurbytes
>= dq
->dq_bsoftlimit
&& dq
->dq_bsoftlimit
) {
258 if (dq
->dq_curbytes
< dq
->dq_bsoftlimit
) {
259 dq
->dq_btime
= tv
.tv_sec
+
260 VTOHFS(vp
)->hfs_qfiles
[type
].qf_btime
;
262 if (cp
->c_uid
== kauth_cred_getuid(cred
))
263 printf("\nhfs: warning, %s %s\n",
264 quotatypes
[type
], "disk quota exceeded");
270 if (tv
.tv_sec
> (time_t)dq
->dq_btime
) {
271 if ((dq
->dq_flags
& DQ_BLKS
) == 0 &&
272 cp
->c_uid
== kauth_cred_getuid(cred
)) {
274 printf("\nhfs: write failed, %s %s\n",
276 "disk quota exceeded for too long");
278 dq
->dq_flags
|= DQ_BLKS
;
291 * Check the inode limit, applying corrective action.
294 hfs_chkiq(cp
, change
, cred
, flags
)
295 register struct cnode
*cp
;
300 register struct dquot
*dq
;
302 int ncurinodes
, error
=0;
306 if ((flags
& CHOWN
) == 0)
312 for (i
= 0; i
< MAXQUOTAS
; i
++) {
313 if ((dq
= cp
->c_dquot
[i
]) == NODQUOT
)
317 ncurinodes
= dq
->dq_curinodes
+ change
;
319 dq
->dq_curinodes
= ncurinodes
;
321 dq
->dq_curinodes
= 0;
322 dq
->dq_flags
&= ~DQ_INODS
;
323 dq
->dq_flags
|= DQ_MOD
;
331 * This use of proc_ucred() is safe because kernproc credential never
334 if (!IS_VALID_CRED(cred
))
335 cred
= proc_ucred(kernproc
);
336 if (suser(cred
, NULL
) || proc_forcequota(p
)) {
337 for (i
= 0; i
< MAXQUOTAS
; i
++) {
338 if ((dq
= cp
->c_dquot
[i
]) == NODQUOT
)
340 error
= hfs_chkiqchg(cp
, change
, cred
, i
);
346 if ((flags
& FORCE
) || error
== 0) {
347 for (i
= 0; i
< MAXQUOTAS
; i
++) {
348 if ((dq
= cp
->c_dquot
[i
]) == NODQUOT
)
352 dq
->dq_curinodes
+= change
;
353 dq
->dq_flags
|= DQ_MOD
;
363 * Check to see if a change to a user's allocation should be permitted or not.
364 * Issue an error message if it should not be permitted. Return 0 if
365 * it should be allowed.
367 int hfs_isiqchg_allowed(dq
, hfsmp
, change
, cred
, type
, uid
)
369 struct hfsmount
* hfsmp
;
375 u_int32_t ncurinodes
;
379 ncurinodes
= dq
->dq_curinodes
+ change
;
381 * If user would exceed their hard limit, disallow cnode allocation.
383 if (ncurinodes
>= dq
->dq_ihardlimit
&& dq
->dq_ihardlimit
) {
384 if ((dq
->dq_flags
& DQ_INODS
) == 0 &&
385 uid
== kauth_cred_getuid(cred
)) {
386 dq
->dq_flags
|= DQ_INODS
;
393 * If user is over their soft limit for too long, disallow cnode
394 * allocation. Reset time limit as they cross their soft limit.
396 if (ncurinodes
>= dq
->dq_isoftlimit
&& dq
->dq_isoftlimit
) {
400 if (dq
->dq_curinodes
< dq
->dq_isoftlimit
) {
401 dq
->dq_itime
= tv
.tv_sec
+ hfsmp
->hfs_qfiles
[type
].qf_itime
;
405 if (tv
.tv_sec
> (time_t)dq
->dq_itime
) {
406 if (((dq
->dq_flags
& DQ_INODS
) == 0) &&
407 (uid
== kauth_cred_getuid(cred
))) {
408 dq
->dq_flags
|= DQ_INODS
;
422 * Check for a valid change to a users allocation.
423 * Issue an error message if appropriate.
426 hfs_chkiqchg(cp
, change
, cred
, type
)
432 register struct dquot
*dq
= cp
->c_dquot
[type
];
433 u_int32_t ncurinodes
;
434 struct vnode
*vp
= cp
->c_vp
? cp
->c_vp
: cp
->c_rsrc_vp
;
438 ncurinodes
= dq
->dq_curinodes
+ change
;
440 * If user would exceed their hard limit, disallow cnode allocation.
442 if (ncurinodes
>= dq
->dq_ihardlimit
&& dq
->dq_ihardlimit
) {
443 if ((dq
->dq_flags
& DQ_INODS
) == 0 &&
444 cp
->c_uid
== kauth_cred_getuid(cred
)) {
446 printf("\nhfs: write failed, %s cnode limit reached\n",
449 dq
->dq_flags
|= DQ_INODS
;
456 * If user is over their soft limit for too long, disallow cnode
457 * allocation. Reset time limit as they cross their soft limit.
459 if (ncurinodes
>= dq
->dq_isoftlimit
&& dq
->dq_isoftlimit
) {
463 if (dq
->dq_curinodes
< dq
->dq_isoftlimit
) {
464 dq
->dq_itime
= tv
.tv_sec
+
465 VTOHFS(vp
)->hfs_qfiles
[type
].qf_itime
;
467 if (cp
->c_uid
== kauth_cred_getuid(cred
))
468 printf("\nhfs: warning, %s %s\n",
469 quotatypes
[type
], "cnode quota exceeded");
475 if (tv
.tv_sec
> (time_t)dq
->dq_itime
) {
476 if ((dq
->dq_flags
& DQ_INODS
) == 0 &&
477 cp
->c_uid
== kauth_cred_getuid(cred
)) {
479 printf("\nhfs: write failed, %s %s\n",
481 "cnode quota exceeded for too long");
483 dq
->dq_flags
|= DQ_INODS
;
497 * On filesystems with quotas enabled, it is an error for a file to change
498 * size and not to have a dquot structure associated with it.
502 register struct cnode
*cp
;
504 struct vnode
*vp
= cp
->c_vp
? cp
->c_vp
: cp
->c_rsrc_vp
;
505 struct hfsmount
*hfsmp
= VTOHFS(vp
);
508 for (i
= 0; i
< MAXQUOTAS
; i
++) {
509 if (hfsmp
->hfs_qfiles
[i
].qf_vp
== NULLVP
)
511 if (cp
->c_dquot
[i
] == NODQUOT
) {
512 vprint("chkdquot: missing dquot", vp
);
513 panic("missing dquot");
520 * Code to process quotactl commands.
524 * Q_QUOTAON - set up a quota file for a particular file system.
526 struct hfs_quotaon_cargs
{
531 hfs_quotaon_callback(struct vnode
*vp
, void *cargs
)
533 struct hfs_quotaon_cargs
*args
;
535 args
= (struct hfs_quotaon_cargs
*)cargs
;
537 args
->error
= hfs_getinoquota(VTOC(vp
));
539 return (VNODE_RETURNED_DONE
);
541 return (VNODE_RETURNED
);
545 hfs_quotaon(p
, mp
, type
, fnamep
)
551 struct hfsmount
*hfsmp
= VFSTOHFS(mp
);
552 struct quotafile
*qfp
;
555 struct hfs_quotaon_cargs args
;
557 /* Finish setting up quota structures. */
560 qfp
= &hfsmp
->hfs_qfiles
[type
];
562 if ( (qf_get(qfp
, QTF_OPENING
)) )
565 error
= vnode_open(fnamep
, FREAD
|FWRITE
, 0, 0, &vp
, NULL
);
569 if (!vnode_isreg(vp
)) {
570 (void) vnode_close(vp
, FREAD
|FWRITE
, NULL
);
574 vfs_setflags(mp
, (u_int64_t
)((unsigned int)MNT_QUOTA
));
575 HFS_MOUNT_LOCK(hfsmp
, TRUE
)
576 hfsmp
->hfs_flags
|= HFS_QUOTAS
;
577 HFS_MOUNT_UNLOCK(hfsmp
, TRUE
);
578 vnode_setnoflush(vp
);
580 * Save the credential of the process that turned on quotas.
582 qfp
->qf_cred
= kauth_cred_proc_ref(p
);
585 * Finish initializing the quota file
587 error
= dqfileopen(qfp
, type
);
589 (void) vnode_close(vp
, FREAD
|FWRITE
, NULL
);
591 if (IS_VALID_CRED(qfp
->qf_cred
))
592 kauth_cred_unref(&qfp
->qf_cred
);
596 qf_put(qfp
, QTF_OPENING
);
599 * Search vnodes associated with this mount point,
600 * adding references to quota file being opened.
601 * NB: only need to add dquot's for cnodes being modified.
603 * hfs_quota_callback will be called for each vnode open for
604 * 'write' (VNODE_WRITEABLE) hung off of this mount point
605 * the vnode will be in an 'unbusy' state (VNODE_WAIT) and
606 * properly referenced and unreferenced around the callback
610 vnode_iterate(mp
, VNODE_WRITEABLE
| VNODE_WAIT
, hfs_quotaon_callback
, (void *)&args
);
615 hfs_quotaoff(p
, mp
, type
);
620 qf_put(qfp
, QTF_OPENING
);
627 * Q_QUOTAOFF - turn off disk quotas for a filesystem.
629 struct hfs_quotaoff_cargs
{
634 hfs_quotaoff_callback(struct vnode
*vp
, void *cargs
)
636 struct hfs_quotaoff_cargs
*args
;
640 args
= (struct hfs_quotaoff_cargs
*)cargs
;
644 dq
= cp
->c_dquot
[args
->type
];
645 cp
->c_dquot
[args
->type
] = NODQUOT
;
649 return (VNODE_RETURNED
);
653 hfs_quotaoff(__unused
struct proc
*p
, struct mount
*mp
, register int type
)
656 struct hfsmount
*hfsmp
= VFSTOHFS(mp
);
657 struct quotafile
*qfp
;
659 struct hfs_quotaoff_cargs args
;
662 * If quotas haven't been initialized, there's no work to be done.
664 if (!dqisinitialized())
667 qfp
= &hfsmp
->hfs_qfiles
[type
];
669 if ( (qf_get(qfp
, QTF_CLOSING
)) )
674 * Sync out any orpaned dirty dquot entries.
679 * Search vnodes associated with this mount point,
680 * deleting any references to quota file being closed.
682 * hfs_quotaoff_callback will be called for each vnode
683 * hung off of this mount point
684 * the vnode will be in an 'unbusy' state (VNODE_WAIT) and
685 * properly referenced and unreferenced around the callback
689 vnode_iterate(mp
, VNODE_WAIT
, hfs_quotaoff_callback
, (void *)&args
);
692 /* Finish tearing down the quota file */
693 dqfileclose(qfp
, type
);
695 vnode_clearnoflush(qvp
);
696 error
= vnode_close(qvp
, FREAD
|FWRITE
, NULL
);
700 if (IS_VALID_CRED(qfp
->qf_cred
))
701 kauth_cred_unref(&qfp
->qf_cred
);
702 for (type
= 0; type
< MAXQUOTAS
; type
++)
703 if (hfsmp
->hfs_qfiles
[type
].qf_vp
!= NULLVP
)
705 if (type
== MAXQUOTAS
) {
706 vfs_clearflags(mp
, (u_int64_t
)((unsigned int)MNT_QUOTA
));
707 HFS_MOUNT_LOCK(hfsmp
, TRUE
)
708 hfsmp
->hfs_flags
&= ~HFS_QUOTAS
;
709 HFS_MOUNT_UNLOCK(hfsmp
, TRUE
);
712 qf_put(qfp
, QTF_CLOSING
);
718 * hfs_quotacheck - checks quotas mountwide for a hypothetical situation. It probes
719 * the quota data structures to see if adding an inode would be allowed or not. If it
720 * will be allowed, the change is made. Otherwise, it reports an error back out so the
721 * caller will know not to proceed with inode allocation in the HFS Catalog.
723 * Note that this function ONLY tests for addition of inodes, not subtraction.
725 int hfs_quotacheck(hfsmp
, change
, uid
, gid
, cred
)
726 struct hfsmount
*hfsmp
;
732 struct dquot
*dq
= NULL
;
739 if (!IS_VALID_CRED(cred
)) {
740 /* This use of proc_ucred() is safe because kernproc credential never changes */
741 cred
= proc_ucred(kernproc
);
744 if (suser(cred
, NULL
) || proc_forcequota(p
)) {
745 for (i
= 0; i
< MAXQUOTAS
; i
++) {
746 /* Select if user or group id should be used */
749 else if (i
== GRPQUOTA
)
752 error
= dqget(id
, &hfsmp
->hfs_qfiles
[i
], i
, &dq
);
753 if (error
&& (error
!= EINVAL
))
760 /* Check quota information */
761 error
= hfs_isiqchg_allowed(dq
, hfsmp
, change
, cred
, i
, id
);
768 /* Update quota information */
769 dq
->dq_curinodes
+= change
;
780 * Q_GETQUOTA - return current values in a dqblk structure.
783 hfs_getquota(mp
, id
, type
, datap
)
792 error
= dqget(id
, &VFSTOHFS(mp
)->hfs_qfiles
[type
], type
, &dq
);
797 bcopy(&dq
->dq_dqb
, datap
, sizeof(dq
->dq_dqb
));
806 * Q_SETQUOTA - assign an entire dqblk structure.
809 hfs_setquota(mp
, id
, type
, datap
)
816 struct hfsmount
*hfsmp
= VFSTOHFS(mp
);
817 struct dqblk
* newlimp
= (struct dqblk
*) datap
;
821 error
= dqget(id
, &hfsmp
->hfs_qfiles
[type
], type
, &dq
);
827 * Copy all but the current values.
828 * Reset time limit if previously had no soft limit or were
829 * under it, but now have a soft limit and are over it.
831 newlimp
->dqb_curbytes
= dq
->dq_curbytes
;
832 newlimp
->dqb_curinodes
= dq
->dq_curinodes
;
833 if (dq
->dq_id
!= 0) {
834 newlimp
->dqb_btime
= dq
->dq_btime
;
835 newlimp
->dqb_itime
= dq
->dq_itime
;
837 if (newlimp
->dqb_bsoftlimit
&&
838 dq
->dq_curbytes
>= newlimp
->dqb_bsoftlimit
&&
839 (dq
->dq_bsoftlimit
== 0 || dq
->dq_curbytes
< dq
->dq_bsoftlimit
)) {
841 newlimp
->dqb_btime
= tv
.tv_sec
+ hfsmp
->hfs_qfiles
[type
].qf_btime
;
843 if (newlimp
->dqb_isoftlimit
&&
844 dq
->dq_curinodes
>= newlimp
->dqb_isoftlimit
&&
845 (dq
->dq_isoftlimit
== 0 || dq
->dq_curinodes
< dq
->dq_isoftlimit
)) {
847 newlimp
->dqb_itime
= tv
.tv_sec
+ hfsmp
->hfs_qfiles
[type
].qf_itime
;
849 bcopy(newlimp
, &dq
->dq_dqb
, sizeof(dq
->dq_dqb
));
850 if (dq
->dq_curbytes
< dq
->dq_bsoftlimit
)
851 dq
->dq_flags
&= ~DQ_BLKS
;
852 if (dq
->dq_curinodes
< dq
->dq_isoftlimit
)
853 dq
->dq_flags
&= ~DQ_INODS
;
854 if (dq
->dq_isoftlimit
== 0 && dq
->dq_bsoftlimit
== 0 &&
855 dq
->dq_ihardlimit
== 0 && dq
->dq_bhardlimit
== 0)
856 dq
->dq_flags
|= DQ_FAKE
;
858 dq
->dq_flags
&= ~DQ_FAKE
;
859 dq
->dq_flags
|= DQ_MOD
;
868 * Q_SETUSE - set current cnode and byte usage.
871 hfs_setuse(mp
, id
, type
, datap
)
877 struct hfsmount
*hfsmp
= VFSTOHFS(mp
);
881 struct dqblk
*quotablkp
= (struct dqblk
*) datap
;
883 error
= dqget(id
, &hfsmp
->hfs_qfiles
[type
], type
, &dq
);
889 * Reset time limit if have a soft limit and were
890 * previously under it, but are now over it.
892 if (dq
->dq_bsoftlimit
&& dq
->dq_curbytes
< dq
->dq_bsoftlimit
&&
893 quotablkp
->dqb_curbytes
>= dq
->dq_bsoftlimit
) {
895 dq
->dq_btime
= tv
.tv_sec
+ hfsmp
->hfs_qfiles
[type
].qf_btime
;
897 if (dq
->dq_isoftlimit
&& dq
->dq_curinodes
< dq
->dq_isoftlimit
&&
898 quotablkp
->dqb_curinodes
>= dq
->dq_isoftlimit
) {
900 dq
->dq_itime
= tv
.tv_sec
+ hfsmp
->hfs_qfiles
[type
].qf_itime
;
902 dq
->dq_curbytes
= quotablkp
->dqb_curbytes
;
903 dq
->dq_curinodes
= quotablkp
->dqb_curinodes
;
904 if (dq
->dq_curbytes
< dq
->dq_bsoftlimit
)
905 dq
->dq_flags
&= ~DQ_BLKS
;
906 if (dq
->dq_curinodes
< dq
->dq_isoftlimit
)
907 dq
->dq_flags
&= ~DQ_INODS
;
908 dq
->dq_flags
|= DQ_MOD
;
918 * Q_SYNC - sync quota files to disk.
921 hfs_qsync_callback(struct vnode
*vp
, __unused
void *cargs
)
929 for (i
= 0; i
< MAXQUOTAS
; i
++) {
931 if (dq
!= NODQUOT
&& (dq
->dq_flags
& DQ_MOD
))
934 return (VNODE_RETURNED
);
941 struct hfsmount
*hfsmp
= VFSTOHFS(mp
);
944 if (!dqisinitialized())
948 * Check if the mount point has any quotas.
949 * If not, simply return.
951 for (i
= 0; i
< MAXQUOTAS
; i
++)
952 if (hfsmp
->hfs_qfiles
[i
].qf_vp
!= NULLVP
)
958 * Sync out any orpaned dirty dquot entries.
960 for (i
= 0; i
< MAXQUOTAS
; i
++)
961 if (hfsmp
->hfs_qfiles
[i
].qf_vp
!= NULLVP
)
962 dqsync_orphans(&hfsmp
->hfs_qfiles
[i
]);
965 * Search vnodes associated with this mount point,
966 * synchronizing any modified dquot structures.
968 * hfs_qsync_callback will be called for each vnode
969 * hung off of this mount point
971 * properly referenced and unreferenced around the callback
973 vnode_iterate(mp
, 0, hfs_qsync_callback
, (void *)NULL
);
979 * Q_QUOTASTAT - get quota on/off status
982 hfs_quotastat(mp
, type
, datap
)
987 struct hfsmount
*hfsmp
= VFSTOHFS(mp
);
991 if ((((unsigned int)vfs_flags(mp
)) & MNT_QUOTA
) && (hfsmp
->hfs_qfiles
[type
].qf_vp
!= NULLVP
))
992 qstat
= 1; /* quotas are on for this type */
994 qstat
= 0; /* quotas are off for this type */
996 *((int *)datap
) = qstat
;