127acac22Smckusick /* 276403e9cSbostic * Copyright (c) 1982, 1986, 1993 376403e9cSbostic * The Regents of the University of California. All rights reserved. 427acac22Smckusick * 54d67415cSmckusick * This code is derived from software contributed to Berkeley by 64d67415cSmckusick * Robert Elz at The University of Melbourne. 74d67415cSmckusick * 888f5dc9aSbostic * %sccs.include.redist.c% 98610d286Sbostic * 10*ac1e5d22Smckusick * @(#)quota.h 8.3 (Berkeley) 08/19/94 1127acac22Smckusick */ 122debeb82Skre 133c1ddcbeSmckusick #ifndef _QUOTA_ 143c1ddcbeSmckusick #define _QUOTA_ 153c1ddcbeSmckusick 162debeb82Skre /* 174d67415cSmckusick * Definitions for disk quotas imposed on the average user 184d67415cSmckusick * (big brother finally hits UNIX). 192debeb82Skre * 20606099abSbostic * The following constants define the amount of time given a user before the 21606099abSbostic * soft limits are treated as hard limits (usually resulting in an allocation 22606099abSbostic * failure). The timer is started when the user crosses their soft limit, it 23606099abSbostic * is reset when they go below their soft limit. 242debeb82Skre */ 25881b9f79Smckusick #define MAX_IQ_TIME (7*24*60*60) /* seconds in 1 week */ 26881b9f79Smckusick #define MAX_DQ_TIME (7*24*60*60) /* seconds in 1 week */ 274d67415cSmckusick 284d67415cSmckusick /* 29606099abSbostic * The following constants define the usage of the quota file array in the 30606099abSbostic * ufsmount structure and dquot array in the inode structure. The semantics 31606099abSbostic * of the elements of these arrays are defined in the routine getinoquota; 32606099abSbostic * the remainder of the quota code treats them generically and need not be 33606099abSbostic * inspected when changing the size of the array. 344d67415cSmckusick */ 354d67415cSmckusick #define MAXQUOTAS 2 364d67415cSmckusick #define USRQUOTA 0 /* element used for user quotas */ 374d67415cSmckusick #define GRPQUOTA 1 /* element used for group quotas */ 384d67415cSmckusick 394d67415cSmckusick /* 404d67415cSmckusick * Definitions for the default names of the quotas files. 414d67415cSmckusick */ 424d67415cSmckusick #define INITQFNAMES { \ 434d67415cSmckusick "user", /* USRQUOTA */ \ 444d67415cSmckusick "group", /* GRPQUOTA */ \ 454d67415cSmckusick "undefined", \ 462debeb82Skre }; 4781159eacSmckusick #define QUOTAFILENAME "quota" 4881159eacSmckusick #define QUOTAGROUP "operator" 492debeb82Skre 502debeb82Skre /* 51606099abSbostic * Command definitions for the 'quotactl' system call. The commands are 52606099abSbostic * broken into a main command defined below and a subcommand that is used 53606099abSbostic * to convey the type of quota that is being manipulated (see above). 542debeb82Skre */ 554d67415cSmckusick #define SUBCMDMASK 0x00ff 564d67415cSmckusick #define SUBCMDSHIFT 8 574d67415cSmckusick #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK)) 582debeb82Skre 594d67415cSmckusick #define Q_QUOTAON 0x0100 /* enable quotas */ 604d67415cSmckusick #define Q_QUOTAOFF 0x0200 /* disable quotas */ 614d67415cSmckusick #define Q_GETQUOTA 0x0300 /* get limits and usage */ 624d67415cSmckusick #define Q_SETQUOTA 0x0400 /* set limits and usage */ 634d67415cSmckusick #define Q_SETUSE 0x0500 /* set usage */ 644d67415cSmckusick #define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */ 652debeb82Skre 662debeb82Skre /* 674d67415cSmckusick * The following structure defines the format of the disk quota file 684d67415cSmckusick * (as it appears on disk) - the file is an array of these structures 694d67415cSmckusick * indexed by user or group number. The setquota system call establishes 704d67415cSmckusick * the vnode for each quota file (a pointer is retained in the ufsmount 714d67415cSmckusick * structure). 724d67415cSmckusick */ 734d67415cSmckusick struct dqblk { 74881b9f79Smckusick u_int32_t dqb_bhardlimit; /* absolute limit on disk blks alloc */ 75881b9f79Smckusick u_int32_t dqb_bsoftlimit; /* preferred limit on disk blks */ 76881b9f79Smckusick u_int32_t dqb_curblocks; /* current block count */ 77881b9f79Smckusick u_int32_t dqb_ihardlimit; /* maximum # allocated inodes + 1 */ 78881b9f79Smckusick u_int32_t dqb_isoftlimit; /* preferred inode limit */ 79881b9f79Smckusick u_int32_t dqb_curinodes; /* current # allocated inodes */ 804d67415cSmckusick time_t dqb_btime; /* time limit for excessive disk use */ 814d67415cSmckusick time_t dqb_itime; /* time limit for excessive files */ 824d67415cSmckusick }; 834d67415cSmckusick 844d67415cSmckusick /* 854d67415cSmckusick * The following structure records disk usage for a user or group on a 864d67415cSmckusick * filesystem. There is one allocated for each quota that exists on any 874d67415cSmckusick * filesystem for the current user or group. A cache is kept of recently 884d67415cSmckusick * used entries. 892debeb82Skre */ 902debeb82Skre struct dquot { 91*ac1e5d22Smckusick LIST_ENTRY(dquot) dq_hash; /* hash list */ 92*ac1e5d22Smckusick TAILQ_ENTRY(dquot) dq_freelist; /* free list */ 93881b9f79Smckusick u_int16_t dq_flags; /* flags, see below */ 94881b9f79Smckusick u_int16_t dq_cnt; /* count of active references */ 95881b9f79Smckusick u_int16_t dq_spare; /* unused spare padding */ 96881b9f79Smckusick u_int16_t dq_type; /* quota type of this dquot */ 97881b9f79Smckusick u_int32_t dq_id; /* identifier this applies to */ 984d67415cSmckusick struct ufsmount *dq_ump; /* filesystem that this is taken from */ 994d67415cSmckusick struct dqblk dq_dqb; /* actual usage & quotas */ 1004d67415cSmckusick }; 1014d67415cSmckusick /* 1024d67415cSmckusick * Flag values. 1034d67415cSmckusick */ 104a48ca1d2Ssam #define DQ_LOCK 0x01 /* this quota locked (no MODS) */ 105a48ca1d2Ssam #define DQ_WANT 0x02 /* wakeup on unlock */ 106a48ca1d2Ssam #define DQ_MOD 0x04 /* this quota modified since read */ 107a48ca1d2Ssam #define DQ_FAKE 0x08 /* no limits here, just usage */ 108a48ca1d2Ssam #define DQ_BLKS 0x10 /* has been warned about blk limit */ 109a48ca1d2Ssam #define DQ_INODS 0x20 /* has been warned about inode limit */ 1104d67415cSmckusick /* 1114d67415cSmckusick * Shorthand notation. 1124d67415cSmckusick */ 113ffdbd733Ssam #define dq_bhardlimit dq_dqb.dqb_bhardlimit 114ffdbd733Ssam #define dq_bsoftlimit dq_dqb.dqb_bsoftlimit 115ffdbd733Ssam #define dq_curblocks dq_dqb.dqb_curblocks 116ffdbd733Ssam #define dq_ihardlimit dq_dqb.dqb_ihardlimit 117ffdbd733Ssam #define dq_isoftlimit dq_dqb.dqb_isoftlimit 118ffdbd733Ssam #define dq_curinodes dq_dqb.dqb_curinodes 1194d67415cSmckusick #define dq_btime dq_dqb.dqb_btime 1204d67415cSmckusick #define dq_itime dq_dqb.dqb_itime 121ffdbd733Ssam 1224d67415cSmckusick /* 123881b9f79Smckusick * If the system has never checked for a quota for this file, then it is 124881b9f79Smckusick * set to NODQUOT. Once a write attempt is made the inode pointer is set 125881b9f79Smckusick * to reference a dquot structure. 1264d67415cSmckusick */ 127881b9f79Smckusick #define NODQUOT NULL 1282debeb82Skre 1292debeb82Skre /* 1304d67415cSmckusick * Flags to chkdq() and chkiq() 1312debeb82Skre */ 1324d67415cSmckusick #define FORCE 0x01 /* force usage changes independent of limits */ 1334d67415cSmckusick #define CHOWN 0x02 /* (advisory) change initiated by chown */ 134ffdbd733Ssam 135ffdbd733Ssam /* 1364d67415cSmckusick * Macros to avoid subroutine calls to trivial functions. 137ffdbd733Ssam */ 138606099abSbostic #ifdef DIAGNOSTIC 1394d67415cSmckusick #define DQREF(dq) dqref(dq) 140873c056cSdonn #else 141606099abSbostic #define DQREF(dq) (dq)->dq_cnt++ 142606099abSbostic #endif 143873c056cSdonn 144873c056cSdonn #include <sys/cdefs.h> 145873c056cSdonn 146606099abSbostic struct dquot; 147606099abSbostic struct inode; 148606099abSbostic struct mount; 149606099abSbostic struct proc; 150606099abSbostic struct ucred; 151606099abSbostic struct ufsmount; 152606099abSbostic struct vnode; 153873c056cSdonn __BEGIN_DECLS 154606099abSbostic int chkdq __P((struct inode *, long, struct ucred *, int)); 155606099abSbostic int chkdqchg __P((struct inode *, long, struct ucred *, int)); 156606099abSbostic int chkiq __P((struct inode *, long, struct ucred *, int)); 157606099abSbostic int chkiqchg __P((struct inode *, long, struct ucred *, int)); 158606099abSbostic void dqflush __P((struct vnode *)); 159606099abSbostic int dqget __P((struct vnode *, 160606099abSbostic u_long, struct ufsmount *, int, struct dquot **)); 161606099abSbostic void dqinit __P((void)); 162606099abSbostic void dqref __P((struct dquot *)); 163606099abSbostic void dqrele __P((struct vnode *, struct dquot *)); 164606099abSbostic int dqsync __P((struct vnode *, struct dquot *)); 165606099abSbostic int getinoquota __P((struct inode *)); 166606099abSbostic int getquota __P((struct mount *, u_long, int, caddr_t)); 167606099abSbostic int qsync __P((struct mount *mp)); 168606099abSbostic int quotaoff __P((struct proc *, struct mount *, int)); 169606099abSbostic int quotaon __P((struct proc *, struct mount *, int, caddr_t)); 170606099abSbostic int setquota __P((struct mount *, u_long, int, caddr_t)); 171606099abSbostic int setuse __P((struct mount *, u_long, int, caddr_t)); 17264b8dc47Smckusick int ufs_quotactl __P((struct mount *, int, uid_t, caddr_t, struct proc *)); 173873c056cSdonn __END_DECLS 174873c056cSdonn 175606099abSbostic #ifdef DIAGNOSTIC 176606099abSbostic __BEGIN_DECLS 177606099abSbostic void chkdquot __P((struct inode *)); 178606099abSbostic __END_DECLS 179606099abSbostic #endif 180606099abSbostic 1813c1ddcbeSmckusick #endif /* _QUOTA_ */ 182