dynamically allocate private part
[unix-history] / usr / src / sys / ufs / ffs / quota.h
index 405f5a4..ce5c6b2 100644 (file)
-/*     quota.h Melb 4.1        82/07/16        */
-
 /*
 /*
- *     Various junk to do with various quotas (etc) imposed upon
- *     the average user (big brother finally hits unix)
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Robert Elz at The University of Melbourne.
  *
  *
- *     The following structure exists in core for each logged on user
- *     It contains global junk relevant to that user's quotas
+ * %sccs.include.redist.c%
  *
  *
- *     The u_quota field of each user struct contains a pointer to
- *     the quota struct relevant to the current process, this is changed
- *     by 'setuid' sys call, &/or by the Q_SETUID quota() call
+ *     @(#)quota.h     7.10 (Berkeley) %G%
  */
 
  */
 
-typedef        long    class_t;
-
-struct quinfo {
-       u_short qu_shares;      /* allocated shares (MUSH) */
-       short   qu_plim;        /* process limit */
-       long    qu_syflags;     /* system permission flags */
-       float   qu_usage;       /* current resource usage (MUSH) */
-       class_t qu_class;       /* user classes (MUSH) */
-};
-
-#ifdef KERNEL
-struct quota {
-       struct  quota   *q_forw;        /* hash chain - MUST be first */
-       struct  quota   *q_back;        /* hash chain - MUST be last */
-       char    q_flg;                  /* struct management flags */
-       char    q_lcnt;                 /* count of logins for user */
-       short   q_cnt;                  /* ref count (# processes) */
-       short   q_uid;                  /* real uid of owner */
-       short   q_nice;                 /* nice added to p_cpu (MUSH) */
-       short   q_acnt;                 /* count of 'at' processes (MUSH) */
-       union   {
-               struct  {
-                       long    Q_rate; /* recent work rate (MUSH) */
-                       long    Q_cost; /* cost in recent period (MUSH) */
-               } q_s1;
-               struct  {
-                       struct quota *Q_freef;
-                       struct quota **Q_freeb;
-               } q_s2;
-       } q_u;
-       struct  quinfo q_uinfo;         /* user limits & usage (MUSH) */
-       struct  dquot *q_dq[NMOUNT];    /* disc quotas for mounted filesys's */
-};
-#define        NOQUOT  ((struct quota *) 0)
-#define        q_rate          q_u.q_s1.Q_rate
-#define        q_cost          q_u.q_s1.Q_cost
-#define        q_freef         q_u.q_s2.Q_freef
-#define        q_freeb         q_u.q_s2.Q_freeb
-#define        q_shares        q_uinfo.qu_shares
-#define        q_plim          q_uinfo.qu_plim
-#define        q_syflags       q_uinfo.qu_syflags
-#define        q_usage         q_uinfo.qu_usage
-#define        q_class         q_uinfo.qu_class
-#endif
+#ifndef _QUOTA_
+#define _QUOTA_
 
 
-#define        QF_KASYNC       0x02            /* kill async procs at logout */
-#define        QF_FASTTY       0x04            /* permitted to raise tty speed */
-#define        QF_NASYNC       0x08            /* nice async procs at logout */
-#define        QF_MODTTY       0x10            /* permitted to modify other tty */
-#define        QF_UMASK        0x20            /* not permitted to alter umask */
+/*
+ * Definitions for disk quotas imposed on the average user
+ * (big brother finally hits UNIX).
+ *
+ * The following constants define the amount of time given a user before the
+ * soft limits are treated as hard limits (usually resulting in an allocation
+ * failure). The timer is started when the user crosses their soft limit, it
+ * is reset when they go below their soft limit.
+ */
+#define        MAX_IQ_TIME     (7*24*60*60)    /* 1 week */
+#define        MAX_DQ_TIME     (7*24*60*60)    /* 1 week */
 
 
-#ifdef KERNEL
-struct quota *quota, *quotaNQUOTA;
-int    nquota;
-struct quota *getquota(), *qfind();
-#endif
+/*
+ * The following constants define the usage of the quota file array in the
+ * ufsmount structure and dquot array in the inode structure.  The semantics
+ * of the elements of these arrays are defined in the routine getinoquota;
+ * the remainder of the quota code treats them generically and need not be
+ * inspected when changing the size of the array.
+ */
+#define        MAXQUOTAS       2
+#define        USRQUOTA        0       /* element used for user quotas */
+#define        GRPQUOTA        1       /* element used for group quotas */
 
 
-/*     q_flg flags     */
-#define        Q_LOCK          0x01            /* quota struct locked (for disc i/o) */
-#define        Q_WANT          0x02            /* issue a wakeup when lock goes off */
-#define        Q_NEW           0x04            /* new quota - no proc1 msg sent yet */
-#define        Q_NDQ           0x08            /* account has NO disc quota */
+/*
+ * Definitions for the default names of the quotas files.
+ */
+#define INITQFNAMES { \
+       "user",         /* USRQUOTA */ \
+       "group",        /* GRPQUOTA */ \
+       "undefined", \
+};
+#define        QUOTAFILENAME   "quota"
+#define        QUOTAGROUP      "operator"
 
 /*
 
 /*
- *     The following structure defines the format of the disc quota file
- *     (as it appears on disc) - the file is an array of these structures
- *     indexed by user number. A sys call (setquota) establishes the
- *     inode for each applicable file (a pointer is retained in the mount
- *     structure)
- *
- *     nb: warning fields contain the number of warnings left before
- *             allocation is halted completely
+ * Command definitions for the 'quotactl' system call.  The commands are
+ * broken into a main command defined below and a subcommand that is used
+ * to convey the type of quota that is being manipulated (see above).
  */
  */
+#define SUBCMDMASK     0x00ff
+#define SUBCMDSHIFT    8
+#define        QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
 
 
-typedef        unsigned short  dlim_t;
+#define        Q_QUOTAON       0x0100  /* enable quotas */
+#define        Q_QUOTAOFF      0x0200  /* disable quotas */
+#define        Q_GETQUOTA      0x0300  /* get limits and usage */
+#define        Q_SETQUOTA      0x0400  /* set limits and usage */
+#define        Q_SETUSE        0x0500  /* set usage */
+#define        Q_SYNC          0x0600  /* sync disk copy of a filesystems quotas */
 
 
+/*
+ * The following structure defines the format of the disk quota file
+ * (as it appears on disk) - the file is an array of these structures
+ * indexed by user or group number.  The setquota system call establishes
+ * the vnode for each quota file (a pointer is retained in the ufsmount
+ * structure).
+ */
 struct dqblk {
 struct dqblk {
-       dlim_t  dqb_ilim;       /* max num allocated inodes + 1 */
-       dlim_t  dqb_iq;         /* preferred inode limit */
-       dlim_t  dqb_inod;       /* current num allocated inodes */
-       dlim_t  dqb_iwarn;      /* # warnings about excessive inodes */
-       dlim_t  dqb_blim;       /* abs limit on disc blks alloc */
-       dlim_t  dqb_quot;       /* preferred limit on disc blks */
-       dlim_t  dqb_blks;       /* current block count */
-       dlim_t  dqb_dwarn;      /* # warnings about excessive disc use */
+       u_long  dqb_bhardlimit; /* absolute limit on disk blks alloc */
+       u_long  dqb_bsoftlimit; /* preferred limit on disk blks */
+       u_long  dqb_curblocks;  /* current block count */
+       u_long  dqb_ihardlimit; /* maximum # allocated inodes + 1 */
+       u_long  dqb_isoftlimit; /* preferred inode limit */
+       u_long  dqb_curinodes;  /* current # allocated inodes */
+       time_t  dqb_btime;      /* time limit for excessive disk use */
+       time_t  dqb_itime;      /* time limit for excessive files */
 };
 };
-#define        MAX_IQ_WARN     3
-#define        MAX_DQ_WARN     3
 
 /*
 
 /*
- *     The following structure records disc usage for a user on a filesystem
- *     There is one allocated for each quota that exists on any filesystem
- *     for the current user. A cache is kept of other recently used entries.
+ * The following structure records disk usage for a user or group on a
+ * filesystem. There is one allocated for each quota that exists on any
+ * filesystem for the current user or group. A cache is kept of recently
+ * used entries.
  */
  */
-
 struct dquot {
 struct dquot {
-       struct  dquot   *dq_forw;       /* MUST be first entry */
-       struct  dquot   *dq_back;       /* MUST be second entry */
-       union   {
-               struct quota *Dq_own;   /* the quota that points to this */
-               struct {
-                       struct dquot *Dq_freef; /* forward free chain ptr */
-                       struct dquot **Dq_freeb;/* backward free chain ptr */
-               } dq_f;
-       } dq_u;
-       short   dq_flg;
+       struct  dquot *dq_forw, *dq_back;/* MUST be first entry */
+       struct  dquot *dq_freef, **dq_freeb; /* free list */
+       short   dq_flags;               /* flags, see below */
        short   dq_cnt;                 /* count of active references */
        short   dq_cnt;                 /* count of active references */
-       short   dq_uid;                 /* user this applies to */
-       dev_t   dq_dev;                 /* filesystem this relates to */
-       struct dqblk dq_dqb;            /* actual usage & quotas */
+       short   dq_spare;               /* unused spare padding */
+       short   dq_type;                /* quota type of this dquot */
+       u_long  dq_id;                  /* identifier this applies to */
+       struct  ufsmount *dq_ump;       /* filesystem that this is taken from */
+       struct  dqblk dq_dqb;           /* actual usage & quotas */
 };
 };
-#define        dq_own          dq_u.Dq_own
-#define        dq_freef        dq_u.dq_f.Dq_freef
-#define        dq_freeb        dq_u.dq_f.Dq_freeb
-#define        dq_ilim         dq_dqb.dqb_ilim
-#define        dq_iq           dq_dqb.dqb_iq
-#define        dq_inod         dq_dqb.dqb_inod
-#define        dq_iwarn        dq_dqb.dqb_iwarn
-#define        dq_blim         dq_dqb.dqb_blim
-#define        dq_quot         dq_dqb.dqb_quot
-#define        dq_blks         dq_dqb.dqb_blks
-#define        dq_dwarn        dq_dqb.dqb_dwarn
-#define        NODQUOT         ((struct dquot *) 0)
-#define        LOSTDQUOT       ((struct dquot *) 1)
-
-#ifdef KERNEL
-struct dquot   *dquot, *dquotNDQUOT;
-int    ndquot;
-struct dquot   *discquota(), *inoquota(), *dqalloc();
-#endif
-
-/*     dq_flg flags    */
+/*
+ * Flag values.
+ */
 #define        DQ_LOCK         0x01            /* this quota locked (no MODS) */
 #define        DQ_WANT         0x02            /* wakeup on unlock */
 #define        DQ_MOD          0x04            /* this quota modified since read */
 #define        DQ_FAKE         0x08            /* no limits here, just usage */
 #define        DQ_BLKS         0x10            /* has been warned about blk limit */
 #define        DQ_INODS        0x20            /* has been warned about inode limit */
 #define        DQ_LOCK         0x01            /* this quota locked (no MODS) */
 #define        DQ_WANT         0x02            /* wakeup on unlock */
 #define        DQ_MOD          0x04            /* this quota modified since read */
 #define        DQ_FAKE         0x08            /* no limits here, just usage */
 #define        DQ_BLKS         0x10            /* has been warned about blk limit */
 #define        DQ_INODS        0x20            /* has been warned about inode limit */
-
 /*
 /*
- * Commands for the 'quota' system call
+ * Shorthand notation.
  */
  */
-#define        Q_SETDLIM       1       /* set disc limits & usage */
-#define        Q_GETDLIM       2       /* get disc limits & usage */
-#define        Q_SETDUSE       3       /* set disc usage only */
-#define        Q_SYNC          4       /* update disc copy if quota usages */
-#define        Q_LOGIN         5       /* Count this as a login process */
-#define        Q_LCOUNT        6       /* get count of login processes */
-#define        Q_PCOUNT        7       /* get count of processes */
-#define        Q_USAGE         8       /* get current usage */
-#define        Q_SFLAGS        9       /* set system flags */
-#define        Q_SUSAGE        10      /* set usage */
-#define        Q_SPLIMIT       11      /* set process limit */
-#define        Q_ISLOGIN       12      /* is this a login process ?? */
-#define        Q_SCLASS        13      /* set user class */
-#define        Q_SCURCL        14      /* set current system classes */
-#define        Q_GCURCL        15      /* get current system classes */
-#define        Q_SETUID        16      /* change proc to use quotas for uid */
-#define        Q_FLOGIN        17      /* "fake" login (counts as 1, but isn't) */
-#define        Q_SETCOST       18      /* set system charge rates */
-#define        Q_GETCOST       19      /* get system charge rates */
-#define        Q_SSHARE        20      /* set shares */
-#define        Q_SUINFO        21      /* set user info */
-#define        Q_GUINFO        22      /* get user info */
-#define        Q_ATJOB         23      /* this process is an 'at' job (background) */
-#define        Q_ACOUNT        24      /* return count of procs descended from ATJ */
-#define        Q_SETWARN       25      /* alter inode/block warning counts */
-#define        Q_DOWARN        26      /* warn user about excessive space/inodes */
-#define        Q_KILL          27      /* send signal to procs attatched to quota */
-#define        Q_NICE          28      /* set niceness for procs attatched to quota */
+#define        dq_bhardlimit   dq_dqb.dqb_bhardlimit
+#define        dq_bsoftlimit   dq_dqb.dqb_bsoftlimit
+#define        dq_curblocks    dq_dqb.dqb_curblocks
+#define        dq_ihardlimit   dq_dqb.dqb_ihardlimit
+#define        dq_isoftlimit   dq_dqb.dqb_isoftlimit
+#define        dq_curinodes    dq_dqb.dqb_curinodes
+#define        dq_btime        dq_dqb.dqb_btime
+#define        dq_itime        dq_dqb.dqb_itime
 
 /*
 
 /*
- * current class information
- *
- *     records sched biasing for classes that are to have priority
- *     enhanced or degraded
+ * If the system has never checked for a quota for this file, then it is set
+ * to NODQUOT.  Once a write attempt is made the inode pointer is set to
+ * reference a dquot structure.
  */
  */
+#define        NODQUOT         ((struct dquot *) 0)
 
 
-#define        NCLASS  8
+/*
+ * Flags to chkdq() and chkiq()
+ */
+#define        FORCE   0x01    /* force usage changes independent of limits */
+#define        CHOWN   0x02    /* (advisory) change initiated by chown */
 
 
-struct qclass {
-       class_t class;          /* classes this applies to */
-       long    cost;           /* +/- mod to cost incurred */
-       short   maxn;           /* in this class, no nice > this */
-       short   minn;           /* in this class, no nice < this */
-};
+/*
+ * Macros to avoid subroutine calls to trivial functions.
+ */
+#ifdef DIAGNOSTIC
+#define        DQREF(dq)       dqref(dq)
+#else
+#define        DQREF(dq)       (dq)->dq_cnt++
+#endif
 
 
-#ifdef KERNEL
-struct qclass  curclass[NCLASS];
+#include <sys/cdefs.h>
+
+struct dquot;
+struct inode;
+struct mount;
+struct proc;
+struct ucred;
+struct ufsmount;
+struct vnode;
+__BEGIN_DECLS
+int    chkdq __P((struct inode *, long, struct ucred *, int));
+int    chkdqchg __P((struct inode *, long, struct ucred *, int));
+int    chkiq __P((struct inode *, long, struct ucred *, int));
+int    chkiqchg __P((struct inode *, long, struct ucred *, int));
+void   dqflush __P((struct vnode *));
+int    dqget __P((struct vnode *,
+           u_long, struct ufsmount *, int, struct dquot **));
+void   dqinit __P((void));
+void   dqref __P((struct dquot *));
+void   dqrele __P((struct vnode *, struct dquot *));
+int    dqsync __P((struct vnode *, struct dquot *));
+int    getinoquota __P((struct inode *));
+int    getquota __P((struct mount *, u_long, int, caddr_t));
+int    qsync __P((struct mount *mp));
+int    quotaoff __P((struct proc *, struct mount *, int));
+int    quotaon __P((struct proc *, struct mount *, int, caddr_t));
+int    setquota __P((struct mount *, u_long, int, caddr_t));
+int    setuse __P((struct mount *, u_long, int, caddr_t));
+int    ufs_quotactl __P((struct mount *, int, u_int, caddr_t, struct proc *));
+__END_DECLS
+
+#ifdef DIAGNOSTIC
+__BEGIN_DECLS
+void   chkdquot __P((struct inode *));
+__END_DECLS
 #endif
 
 #endif
 
-/*
- * Flag definitions for u_qflags in user struct (u_qflags)
- */
-#define        QUF_LOGIN       0x0001          /* this process incremented login cnt */
-#define        QUF_ATJ         0x0002          /* this process descended from atrun */
+#endif /* _QUOTA_ */