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