xref: /illumos-gate/usr/src/uts/common/sys/fs/ufs_quota.h (revision b4203d75)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*b4203d75SMarcel Telka /*	  All Rights Reserved	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate  * The Regents of the University of California
337c478bd9Sstevel@tonic-gate  * All Rights Reserved
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate  * contributors.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifndef	_SYS_FS_UFS_QUOTA_H
417c478bd9Sstevel@tonic-gate #define	_SYS_FS_UFS_QUOTA_H
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
447c478bd9Sstevel@tonic-gate extern "C" {
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Lock order for the quota sub-system:
497c478bd9Sstevel@tonic-gate  *
507c478bd9Sstevel@tonic-gate  *  vfs_dqrwlock > ip.i_contents > dq_cachelock > dquot.dq_lock > dq_freelock
517c478bd9Sstevel@tonic-gate  *  vfs_dqrwlock > ip.i_contents > dq_cachelock >                 dq_freelock
527c478bd9Sstevel@tonic-gate  *  vfs_dqrwlock > ip.i_contents >                dquot.dq_lock > dq_freelock
537c478bd9Sstevel@tonic-gate  *  vfs_dqrwlock > ip.i_contents >                                dq_freelock
547c478bd9Sstevel@tonic-gate  *  vfs_dqrwlock > ip.i_contents > dq_cachelock > dquot.dq_lock > qip.i_contents
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate  * The following constants define the default amount of time given a user
597c478bd9Sstevel@tonic-gate  * before the soft limits are treated as hard limits (usually resulting
607c478bd9Sstevel@tonic-gate  * in an allocation failure). These may be  modified by the quotactl
617c478bd9Sstevel@tonic-gate  * system call with the Q_SETQLIM or Q_SETQUOTA commands.
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #define	DQ_FTIMELIMIT	(7 * 24*60*60)		/* 1 week */
657c478bd9Sstevel@tonic-gate #define	DQ_BTIMELIMIT	(7 * 24*60*60)		/* 1 week */
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate  * The dqblk structure defines the format of the disk quota file
697c478bd9Sstevel@tonic-gate  * (as it appears on disk) - the file is an array of these structures
707c478bd9Sstevel@tonic-gate  * indexed by user number.  The setquota sys call establishes the inode
717c478bd9Sstevel@tonic-gate  * for each quota file (a pointer is retained in the mount structure).
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate struct dqblk {
757c478bd9Sstevel@tonic-gate 	uint32_t  dqb_bhardlimit; /* absolute limit on disk blks alloc */
767c478bd9Sstevel@tonic-gate 	uint32_t  dqb_bsoftlimit; /* preferred limit on disk blks */
777c478bd9Sstevel@tonic-gate 	uint32_t  dqb_curblocks;  /* current block count */
787c478bd9Sstevel@tonic-gate 	uint32_t  dqb_fhardlimit; /* maximum # allocated files + 1 */
797c478bd9Sstevel@tonic-gate 	uint32_t  dqb_fsoftlimit; /* preferred file limit */
807c478bd9Sstevel@tonic-gate 	uint32_t  dqb_curfiles;   /* current # allocated files */
817c478bd9Sstevel@tonic-gate 	uint32_t  dqb_btimelimit; /* time limit for excessive disk use */
827c478bd9Sstevel@tonic-gate 	uint32_t  dqb_ftimelimit; /* time limit for excessive files */
837c478bd9Sstevel@tonic-gate };
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate #define	dqoff(UID)	(((offset_t)(UID) * sizeof (struct dqblk)))
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate  * The dquot structure records disk usage for a user on a filesystem.
897c478bd9Sstevel@tonic-gate  * There is one allocated for each quota that exists on any filesystem
907c478bd9Sstevel@tonic-gate  * for the current user. A cache is kept of recently used entries.
917c478bd9Sstevel@tonic-gate  * Active inodes have a pointer to the dquot associated with them.
927c478bd9Sstevel@tonic-gate  */
937c478bd9Sstevel@tonic-gate struct  dquot {
947c478bd9Sstevel@tonic-gate 	struct dquot *dq_forw, *dq_back; /* hash list, MUST be first entry */
957c478bd9Sstevel@tonic-gate 	struct dquot *dq_freef, *dq_freeb; /* free list */
967c478bd9Sstevel@tonic-gate 	short	dq_flags;
977c478bd9Sstevel@tonic-gate #define	DQ_ERROR	0x01		/* An error occurred reading dq */
987c478bd9Sstevel@tonic-gate #define	DQ_MOD		0x04		/* this quota modified since read */
997c478bd9Sstevel@tonic-gate #define	DQ_BLKS		0x10		/* has been warned about blk limit */
1007c478bd9Sstevel@tonic-gate #define	DQ_FILES	0x20		/* has been warned about file limit */
1017c478bd9Sstevel@tonic-gate #define	DQ_TRANS	0x40		/* logging ufs operation started */
1027c478bd9Sstevel@tonic-gate 	ulong_t	dq_cnt;			/* count of active references */
1037c478bd9Sstevel@tonic-gate 	uid_t	dq_uid;			/* user this applies to */
1047c478bd9Sstevel@tonic-gate 	struct ufsvfs *dq_ufsvfsp;	/* filesystem this relates to */
1057c478bd9Sstevel@tonic-gate 	offset_t dq_mof;		/* master disk offset of quota record */
1067c478bd9Sstevel@tonic-gate 	struct dqblk dq_dqb;		/* actual usage & quotas */
1077c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1087c478bd9Sstevel@tonic-gate 	kmutex_t	dq_lock;	/* per dq structure lock */
1097c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1107c478bd9Sstevel@tonic-gate };
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate #define	dq_bhardlimit	dq_dqb.dqb_bhardlimit
1137c478bd9Sstevel@tonic-gate #define	dq_bsoftlimit	dq_dqb.dqb_bsoftlimit
1147c478bd9Sstevel@tonic-gate #define	dq_curblocks	dq_dqb.dqb_curblocks
1157c478bd9Sstevel@tonic-gate #define	dq_fhardlimit	dq_dqb.dqb_fhardlimit
1167c478bd9Sstevel@tonic-gate #define	dq_fsoftlimit	dq_dqb.dqb_fsoftlimit
1177c478bd9Sstevel@tonic-gate #define	dq_curfiles	dq_dqb.dqb_curfiles
1187c478bd9Sstevel@tonic-gate #define	dq_btimelimit	dq_dqb.dqb_btimelimit
1197c478bd9Sstevel@tonic-gate #define	dq_ftimelimit	dq_dqb.dqb_ftimelimit
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /*
1227c478bd9Sstevel@tonic-gate  * flags for vfs_qflags in ufsvfs struct
1237c478bd9Sstevel@tonic-gate  */
1247c478bd9Sstevel@tonic-gate #define	MQ_ENABLED	0x01		/* quotas are enabled */
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * dquot chach hash chain headers
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate #define	NDQHASH		64			/* smallish power of two */
1327c478bd9Sstevel@tonic-gate #define	DQHASH(uid, mp) \
1337c478bd9Sstevel@tonic-gate 	(((uintptr_t)(mp) + (unsigned)(uid)) & (NDQHASH-1))
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate struct	dqhead {
1367c478bd9Sstevel@tonic-gate 	struct	dquot	*dqh_forw;	/* MUST be first */
1377c478bd9Sstevel@tonic-gate 	struct	dquot	*dqh_back;	/* MUST be second */
1387c478bd9Sstevel@tonic-gate };
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate extern struct dqhead dqhead[NDQHASH];
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate extern struct dquot *dquot, *dquotNDQUOT;
1437c478bd9Sstevel@tonic-gate extern int ndquot;
1447c478bd9Sstevel@tonic-gate extern krwlock_t dq_rwlock;		/* quota sub-system init lock */
1457c478bd9Sstevel@tonic-gate extern int quotas_initialized;		/* quota sub-system init flag */
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate extern void qtinit();
1487c478bd9Sstevel@tonic-gate extern void qtinit2();
1497c478bd9Sstevel@tonic-gate extern struct dquot *getinoquota(struct inode *);
1507c478bd9Sstevel@tonic-gate extern int chkdq(struct inode *ip, long, int, struct cred *, char **errp,
1517c478bd9Sstevel@tonic-gate 		size_t *lenp);
1527c478bd9Sstevel@tonic-gate extern int chkiq(struct ufsvfs *, int, struct inode *, uid_t, int,
1537c478bd9Sstevel@tonic-gate 		struct cred *, char **errp, size_t *lenp);
1547c478bd9Sstevel@tonic-gate extern void dqrele(struct dquot *);
1557c478bd9Sstevel@tonic-gate extern int closedq(struct ufsvfs *, struct cred *);
1567c478bd9Sstevel@tonic-gate extern int qsync(struct ufsvfs *);
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate extern int getdiskquota(uid_t, struct ufsvfs *, int, struct dquot **);
1597c478bd9Sstevel@tonic-gate extern void dqput(struct dquot *);
1607c478bd9Sstevel@tonic-gate extern void dqupdate(struct dquot *);
1617c478bd9Sstevel@tonic-gate extern void dqinval(struct dquot *);
1627c478bd9Sstevel@tonic-gate extern void invalidatedq(struct ufsvfs *);
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate extern int quotactl(struct vnode *, intptr_t, int flag, struct cred *);
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate  * Definitions for the 'quotactl' system call.
1707c478bd9Sstevel@tonic-gate  */
1717c478bd9Sstevel@tonic-gate #define	Q_QUOTAON	1	/* turn quotas on */
1727c478bd9Sstevel@tonic-gate #define	Q_QUOTAOFF	2	/* turn quotas off */
1737c478bd9Sstevel@tonic-gate #define	Q_SETQUOTA	3	/* set disk limits & usage */
1747c478bd9Sstevel@tonic-gate #define	Q_GETQUOTA	4	/* get disk limits & usage */
1757c478bd9Sstevel@tonic-gate #define	Q_SETQLIM	5	/* set disk limits only */
1767c478bd9Sstevel@tonic-gate #define	Q_SYNC		6	/* update disk copy of quota usages */
1777c478bd9Sstevel@tonic-gate #define	Q_ALLSYNC	7	/* update disk copy of quota usages for all */
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
1807c478bd9Sstevel@tonic-gate /* ILP32 compatible structure for LP64 kernel. */
1817c478bd9Sstevel@tonic-gate struct quotctl32 {
1827c478bd9Sstevel@tonic-gate 	int		op;
1837c478bd9Sstevel@tonic-gate 	uid_t		uid;
1847c478bd9Sstevel@tonic-gate 	uint32_t	addr;
1857c478bd9Sstevel@tonic-gate };
1867c478bd9Sstevel@tonic-gate #endif /* SYSCALL32 */
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate struct quotctl {
1897c478bd9Sstevel@tonic-gate 	int	op;
1907c478bd9Sstevel@tonic-gate 	uid_t	uid;
1917c478bd9Sstevel@tonic-gate 	caddr_t	addr;
1927c478bd9Sstevel@tonic-gate };
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate #define	Q_QUOTACTL	0x00030189	/* ioctl command for quotactl */
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate #endif
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate #endif	/* _SYS_FS_UFS_QUOTA_H */
201