1 /* 2 * Copyright (c) 1982, 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Robert Elz at The University of Melbourne. 7 * 8 * %sccs.include.redist.c% 9 * 10 * @(#)quota.h 7.7 (Berkeley) 09/11/90 11 */ 12 13 #ifndef _QUOTA_ 14 #define _QUOTA_ 15 16 /* 17 * Definitions for disk quotas imposed on the average user 18 * (big brother finally hits UNIX). 19 * 20 * The following constants define the amount of time given a user 21 * before the soft limits are treated as hard limits (usually resulting 22 * in an allocation failure). The timer is started when the user crosses 23 * their soft limit, it is reset when they go below their soft limit. 24 */ 25 #define MAX_IQ_TIME (7*24*60*60) /* 1 week */ 26 #define MAX_DQ_TIME (7*24*60*60) /* 1 week */ 27 28 /* 29 * The following constants define the usage of the quota file array 30 * in the ufsmount structure and dquot array in the inode structure. 31 * The semantics of the elements of these arrays are defined in the 32 * routine getinoquota; the remainder of the quota code treats them 33 * generically and need not be inspected when changing the size of 34 * the array. 35 */ 36 #define MAXQUOTAS 2 37 #define USRQUOTA 0 /* element used for user quotas */ 38 #define GRPQUOTA 1 /* element used for group quotas */ 39 40 /* 41 * Definitions for the default names of the quotas files. 42 */ 43 #define INITQFNAMES { \ 44 "user", /* USRQUOTA */ \ 45 "group", /* GRPQUOTA */ \ 46 "undefined", \ 47 }; 48 #ifndef KERNEL 49 char *qfname = "quota"; 50 char *qfextension[] = INITQFNAMES; 51 char *quotagroup = "operator"; 52 #endif 53 54 /* 55 * Command definitions for the 'quotactl' system call. 56 * The commands are broken into a main command defined below 57 * and a subcommand that is used to convey the type of 58 * quota that is being manipulated (see above). 59 */ 60 #define SUBCMDMASK 0x00ff 61 #define SUBCMDSHIFT 8 62 #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK)) 63 64 #define Q_QUOTAON 0x0100 /* enable quotas */ 65 #define Q_QUOTAOFF 0x0200 /* disable quotas */ 66 #define Q_GETQUOTA 0x0300 /* get limits and usage */ 67 #define Q_SETQUOTA 0x0400 /* set limits and usage */ 68 #define Q_SETUSE 0x0500 /* set usage */ 69 #define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */ 70 71 /* 72 * The following structure defines the format of the disk quota file 73 * (as it appears on disk) - the file is an array of these structures 74 * indexed by user or group number. The setquota system call establishes 75 * the vnode for each quota file (a pointer is retained in the ufsmount 76 * structure). 77 */ 78 struct dqblk { 79 u_long dqb_bhardlimit; /* absolute limit on disk blks alloc */ 80 u_long dqb_bsoftlimit; /* preferred limit on disk blks */ 81 u_long dqb_curblocks; /* current block count */ 82 u_long dqb_ihardlimit; /* maximum # allocated inodes + 1 */ 83 u_long dqb_isoftlimit; /* preferred inode limit */ 84 u_long dqb_curinodes; /* current # allocated inodes */ 85 time_t dqb_btime; /* time limit for excessive disk use */ 86 time_t dqb_itime; /* time limit for excessive files */ 87 }; 88 89 #ifdef KERNEL 90 /* 91 * The following structure records disk usage for a user or group on a 92 * filesystem. There is one allocated for each quota that exists on any 93 * filesystem for the current user or group. A cache is kept of recently 94 * used entries. 95 */ 96 struct dquot { 97 struct dquot *dq_forw, *dq_back;/* MUST be first entry */ 98 struct dquot *dq_freef, **dq_freeb; /* free list */ 99 short dq_flags; /* flags, see below */ 100 short dq_cnt; /* count of active references */ 101 short dq_spare; /* unused spare padding */ 102 short dq_type; /* quota type of this dquot */ 103 u_long dq_id; /* identifier this applies to */ 104 struct ufsmount *dq_ump; /* filesystem that this is taken from */ 105 struct dqblk dq_dqb; /* actual usage & quotas */ 106 }; 107 /* 108 * Flag values. 109 */ 110 #define DQ_LOCK 0x01 /* this quota locked (no MODS) */ 111 #define DQ_WANT 0x02 /* wakeup on unlock */ 112 #define DQ_MOD 0x04 /* this quota modified since read */ 113 #define DQ_FAKE 0x08 /* no limits here, just usage */ 114 #define DQ_BLKS 0x10 /* has been warned about blk limit */ 115 #define DQ_INODS 0x20 /* has been warned about inode limit */ 116 /* 117 * Shorthand notation. 118 */ 119 #define dq_bhardlimit dq_dqb.dqb_bhardlimit 120 #define dq_bsoftlimit dq_dqb.dqb_bsoftlimit 121 #define dq_curblocks dq_dqb.dqb_curblocks 122 #define dq_ihardlimit dq_dqb.dqb_ihardlimit 123 #define dq_isoftlimit dq_dqb.dqb_isoftlimit 124 #define dq_curinodes dq_dqb.dqb_curinodes 125 #define dq_btime dq_dqb.dqb_btime 126 #define dq_itime dq_dqb.dqb_itime 127 128 /* 129 * If the system has never checked for a quota for this file, 130 * then it is set to NODQUOT. Once a write attempt is made 131 * the inode pointer is set to reference a dquot structure. 132 */ 133 #define NODQUOT ((struct dquot *) 0) 134 135 /* 136 * Flags to chkdq() and chkiq() 137 */ 138 #define FORCE 0x01 /* force usage changes independent of limits */ 139 #define CHOWN 0x02 /* (advisory) change initiated by chown */ 140 141 /* 142 * Macros to avoid subroutine calls to trivial functions. 143 */ 144 #ifndef DIAGNOSTIC 145 #define DQREF(dq) (dq)->dq_cnt++ 146 #else 147 #define DQREF(dq) dqref(dq) 148 #endif /* DIAGNOSTIC */ 149 #endif /* KERNEL */ 150 #endif /* _QUOTA_ */ 151