/*
- * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2002-2005 Apple Computer, Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
*
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
*
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*
* Copyright (c) 1982, 1986, 1990, 1993, 1995
#include <sys/proc.h>
#include <sys/kauth.h>
#include <sys/vnode.h>
+#include <sys/vnode_internal.h>
#include <sys/quota.h>
#include <sys/proc_internal.h>
#include <kern/kalloc.h>
#include <hfs/hfs_quota.h>
#include <hfs/hfs_mount.h>
+
/*
* Quota name to error message mapping.
*/
return (0);
}
p = current_proc();
- if (cred == NOCRED)
+ /*
+ * This use of proc_ucred() is safe because kernproc credential never
+ * changes.
+ */
+ if (!IS_VALID_CRED(cred))
cred = proc_ucred(kernproc);
if (suser(cred, NULL) || proc_forcequota(p)) {
for (i = 0; i < MAXQUOTAS; i++) {
return (0);
}
p = current_proc();
- if (cred == NOCRED)
+ /*
+ * This use of proc_ucred() is safe because kernproc credential never
+ * changes.
+ */
+ if (!IS_VALID_CRED(cred))
cred = proc_ucred(kernproc);
if (suser(cred, NULL) || proc_forcequota(p)) {
for (i = 0; i < MAXQUOTAS; i++) {
int type;
{
register struct dquot *dq = cp->c_dquot[type];
- long ncurinodes;
+ unsigned long ncurinodes;
struct vnode *vp = cp->c_vp ? cp->c_vp : cp->c_rsrc_vp;
dqlock(dq);
int error = 0;
struct hfs_quotaon_cargs args;
+ /* Finish setting up quota structures. */
+ dqhashinit();
+
qfp = &hfsmp->hfs_qfiles[type];
if ( (qf_get(qfp, QTF_OPENING)) )
error = EACCES;
goto out;
}
- vfs_setflags(mp, (uint64_t)((unsigned int)MNT_QUOTA));
+ vfs_setflags(mp, (u_int64_t)((unsigned int)MNT_QUOTA));
+ HFS_MOUNT_LOCK(hfsmp, TRUE)
+ hfsmp->hfs_flags |= HFS_QUOTAS;
+ HFS_MOUNT_UNLOCK(hfsmp, TRUE);
vnode_setnoflush(vp);
/*
* Save the credential of the process that turned on quotas.
if (error) {
(void) vnode_close(vp, FREAD|FWRITE, NULL);
- kauth_cred_rele(qfp->qf_cred);
- qfp->qf_cred = NOCRED;
+ if (IS_VALID_CRED(qfp->qf_cred))
+ kauth_cred_unref(&qfp->qf_cred);
qfp->qf_vp = NULLVP;
goto out;
}
struct hfsmount *hfsmp = VFSTOHFS(mp);
struct quotafile *qfp;
int error;
- kauth_cred_t cred;
struct hfs_quotaoff_cargs args;
+ /*
+ * If quotas haven't been initialized, there's no work to be done.
+ */
+ if (!dqisinitialized())
+ return (0);
+
qfp = &hfsmp->hfs_qfiles[type];
if ( (qf_get(qfp, QTF_CLOSING)) )
error = vnode_close(qvp, FREAD|FWRITE, NULL);
qfp->qf_vp = NULLVP;
- cred = qfp->qf_cred;
- if (cred != NOCRED) {
- qfp->qf_cred = NOCRED;
- kauth_cred_rele(cred);
- }
+
+ if (IS_VALID_CRED(qfp->qf_cred))
+ kauth_cred_unref(&qfp->qf_cred);
for (type = 0; type < MAXQUOTAS; type++)
if (hfsmp->hfs_qfiles[type].qf_vp != NULLVP)
break;
- if (type == MAXQUOTAS)
- vfs_clearflags(mp, (uint64_t)((unsigned int)MNT_QUOTA));
+ if (type == MAXQUOTAS) {
+ vfs_clearflags(mp, (u_int64_t)((unsigned int)MNT_QUOTA));
+ HFS_MOUNT_LOCK(hfsmp, TRUE)
+ hfsmp->hfs_flags &= ~HFS_QUOTAS;
+ HFS_MOUNT_UNLOCK(hfsmp, TRUE);
+ }
qf_put(qfp, QTF_CLOSING);
struct hfsmount *hfsmp = VFSTOHFS(mp);
int i;
+ if (!dqisinitialized())
+ return (0);
+
/*
* Check if the mount point has any quotas.
* If not, simply return.