123433Smckusick /* 2*63376Sbostic * Copyright (c) 1982, 1986, 1993 3*63376Sbostic * The Regents of the University of California. All rights reserved. 423433Smckusick * 541307Smckusick * This code is derived from software contributed to Berkeley by 641307Smckusick * Robert Elz at The University of Melbourne. 741307Smckusick * 844536Sbostic * %sccs.include.redist.c% 934371Sbostic * 10*63376Sbostic * @(#)quota.h 8.1 (Berkeley) 06/11/93 1123433Smckusick */ 127450Skre 1345225Smckusick #ifndef _QUOTA_ 1445225Smckusick #define _QUOTA_ 1545225Smckusick 167450Skre /* 1741307Smckusick * Definitions for disk quotas imposed on the average user 1841307Smckusick * (big brother finally hits UNIX). 197450Skre * 2051515Sbostic * The following constants define the amount of time given a user before the 2151515Sbostic * soft limits are treated as hard limits (usually resulting in an allocation 2251515Sbostic * failure). The timer is started when the user crosses their soft limit, it 2351515Sbostic * is reset when they go below their soft limit. 247450Skre */ 2541307Smckusick #define MAX_IQ_TIME (7*24*60*60) /* 1 week */ 2641307Smckusick #define MAX_DQ_TIME (7*24*60*60) /* 1 week */ 277450Skre 2841307Smckusick /* 2951515Sbostic * The following constants define the usage of the quota file array in the 3051515Sbostic * ufsmount structure and dquot array in the inode structure. The semantics 3151515Sbostic * of the elements of these arrays are defined in the routine getinoquota; 3251515Sbostic * the remainder of the quota code treats them generically and need not be 3351515Sbostic * inspected when changing the size of the array. 3441307Smckusick */ 3541307Smckusick #define MAXQUOTAS 2 3641307Smckusick #define USRQUOTA 0 /* element used for user quotas */ 3741307Smckusick #define GRPQUOTA 1 /* element used for group quotas */ 3812657Ssam 3941307Smckusick /* 4041307Smckusick * Definitions for the default names of the quotas files. 4141307Smckusick */ 4241307Smckusick #define INITQFNAMES { \ 4341307Smckusick "user", /* USRQUOTA */ \ 4441307Smckusick "group", /* GRPQUOTA */ \ 4541307Smckusick "undefined", \ 4641307Smckusick }; 4751515Sbostic #define QUOTAFILENAME "quota" 4851515Sbostic #define QUOTAGROUP "operator" 497450Skre 507450Skre /* 5151515Sbostic * Command definitions for the 'quotactl' system call. The commands are 5251515Sbostic * broken into a main command defined below and a subcommand that is used 5351515Sbostic * to convey the type of quota that is being manipulated (see above). 547450Skre */ 5541307Smckusick #define SUBCMDMASK 0x00ff 5641307Smckusick #define SUBCMDSHIFT 8 5741307Smckusick #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK)) 587450Skre 5941307Smckusick #define Q_QUOTAON 0x0100 /* enable quotas */ 6041307Smckusick #define Q_QUOTAOFF 0x0200 /* disable quotas */ 6141307Smckusick #define Q_GETQUOTA 0x0300 /* get limits and usage */ 6241307Smckusick #define Q_SETQUOTA 0x0400 /* set limits and usage */ 6341307Smckusick #define Q_SETUSE 0x0500 /* set usage */ 6441307Smckusick #define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */ 6541307Smckusick 6641307Smckusick /* 6741307Smckusick * The following structure defines the format of the disk quota file 6841307Smckusick * (as it appears on disk) - the file is an array of these structures 6941307Smckusick * indexed by user or group number. The setquota system call establishes 7041307Smckusick * the vnode for each quota file (a pointer is retained in the ufsmount 7141307Smckusick * structure). 7241307Smckusick */ 737450Skre struct dqblk { 7441307Smckusick u_long dqb_bhardlimit; /* absolute limit on disk blks alloc */ 7541307Smckusick u_long dqb_bsoftlimit; /* preferred limit on disk blks */ 7612657Ssam u_long dqb_curblocks; /* current block count */ 7741307Smckusick u_long dqb_ihardlimit; /* maximum # allocated inodes + 1 */ 7841307Smckusick u_long dqb_isoftlimit; /* preferred inode limit */ 7941307Smckusick u_long dqb_curinodes; /* current # allocated inodes */ 8041307Smckusick time_t dqb_btime; /* time limit for excessive disk use */ 8141307Smckusick time_t dqb_itime; /* time limit for excessive files */ 827450Skre }; 837450Skre 847450Skre /* 8541307Smckusick * The following structure records disk usage for a user or group on a 8641307Smckusick * filesystem. There is one allocated for each quota that exists on any 8741307Smckusick * filesystem for the current user or group. A cache is kept of recently 8841307Smckusick * used entries. 897450Skre */ 907450Skre struct dquot { 9155414Smckusick struct dquot *dq_forw, **dq_back; /* hash list */ 9241307Smckusick struct dquot *dq_freef, **dq_freeb; /* free list */ 9341307Smckusick short dq_flags; /* flags, see below */ 9441307Smckusick short dq_cnt; /* count of active references */ 9541307Smckusick short dq_spare; /* unused spare padding */ 9641307Smckusick short dq_type; /* quota type of this dquot */ 9741307Smckusick u_long dq_id; /* identifier this applies to */ 9841307Smckusick struct ufsmount *dq_ump; /* filesystem that this is taken from */ 9941307Smckusick struct dqblk dq_dqb; /* actual usage & quotas */ 10041307Smckusick }; 10141307Smckusick /* 10241307Smckusick * Flag values. 10341307Smckusick */ 10412652Ssam #define DQ_LOCK 0x01 /* this quota locked (no MODS) */ 10512652Ssam #define DQ_WANT 0x02 /* wakeup on unlock */ 10612652Ssam #define DQ_MOD 0x04 /* this quota modified since read */ 10712652Ssam #define DQ_FAKE 0x08 /* no limits here, just usage */ 10812652Ssam #define DQ_BLKS 0x10 /* has been warned about blk limit */ 10912652Ssam #define DQ_INODS 0x20 /* has been warned about inode limit */ 11041307Smckusick /* 11141307Smckusick * Shorthand notation. 11241307Smckusick */ 11312657Ssam #define dq_bhardlimit dq_dqb.dqb_bhardlimit 11412657Ssam #define dq_bsoftlimit dq_dqb.dqb_bsoftlimit 11512657Ssam #define dq_curblocks dq_dqb.dqb_curblocks 11612657Ssam #define dq_ihardlimit dq_dqb.dqb_ihardlimit 11712657Ssam #define dq_isoftlimit dq_dqb.dqb_isoftlimit 11812657Ssam #define dq_curinodes dq_dqb.dqb_curinodes 11941307Smckusick #define dq_btime dq_dqb.dqb_btime 12041307Smckusick #define dq_itime dq_dqb.dqb_itime 12112657Ssam 1227450Skre /* 12351515Sbostic * If the system has never checked for a quota for this file, then it is set 12451515Sbostic * to NODQUOT. Once a write attempt is made the inode pointer is set to 12551515Sbostic * reference a dquot structure. 1267450Skre */ 12741307Smckusick #define NODQUOT ((struct dquot *) 0) 12812657Ssam 12912657Ssam /* 13041307Smckusick * Flags to chkdq() and chkiq() 13112657Ssam */ 13241307Smckusick #define FORCE 0x01 /* force usage changes independent of limits */ 13341307Smckusick #define CHOWN 0x02 /* (advisory) change initiated by chown */ 13412657Ssam 13512657Ssam /* 13641307Smckusick * Macros to avoid subroutine calls to trivial functions. 13712657Ssam */ 13851515Sbostic #ifdef DIAGNOSTIC 13941307Smckusick #define DQREF(dq) dqref(dq) 14046540Sdonn #else 14151515Sbostic #define DQREF(dq) (dq)->dq_cnt++ 14251515Sbostic #endif 14346540Sdonn 14446540Sdonn #include <sys/cdefs.h> 14546540Sdonn 14651515Sbostic struct dquot; 14751515Sbostic struct inode; 14851515Sbostic struct mount; 14951515Sbostic struct proc; 15051515Sbostic struct ucred; 15151515Sbostic struct ufsmount; 15251515Sbostic struct vnode; 15346540Sdonn __BEGIN_DECLS 15451515Sbostic int chkdq __P((struct inode *, long, struct ucred *, int)); 15551515Sbostic int chkdqchg __P((struct inode *, long, struct ucred *, int)); 15651515Sbostic int chkiq __P((struct inode *, long, struct ucred *, int)); 15751515Sbostic int chkiqchg __P((struct inode *, long, struct ucred *, int)); 15851515Sbostic void dqflush __P((struct vnode *)); 15951515Sbostic int dqget __P((struct vnode *, 16051515Sbostic u_long, struct ufsmount *, int, struct dquot **)); 16151515Sbostic void dqinit __P((void)); 16251515Sbostic void dqref __P((struct dquot *)); 16351515Sbostic void dqrele __P((struct vnode *, struct dquot *)); 16451515Sbostic int dqsync __P((struct vnode *, struct dquot *)); 16551515Sbostic int getinoquota __P((struct inode *)); 16651515Sbostic int getquota __P((struct mount *, u_long, int, caddr_t)); 16751515Sbostic int qsync __P((struct mount *mp)); 16851515Sbostic int quotaoff __P((struct proc *, struct mount *, int)); 16951515Sbostic int quotaon __P((struct proc *, struct mount *, int, caddr_t)); 17051515Sbostic int setquota __P((struct mount *, u_long, int, caddr_t)); 17151515Sbostic int setuse __P((struct mount *, u_long, int, caddr_t)); 17254452Smckusick int ufs_quotactl __P((struct mount *, int, uid_t, caddr_t, struct proc *)); 17346540Sdonn __END_DECLS 17446540Sdonn 17551515Sbostic #ifdef DIAGNOSTIC 17651515Sbostic __BEGIN_DECLS 17751515Sbostic void chkdquot __P((struct inode *)); 17851515Sbostic __END_DECLS 17951515Sbostic #endif 18051515Sbostic 18145225Smckusick #endif /* _QUOTA_ */ 182