1
0

quota.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*-
  2. * Copyright (c) 1982, 1986, 1993
  3. * The Regents of the University of California. 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, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the name of the University nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  21. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * @(#)quota.h 8.3 (Berkeley) 8/19/94
  33. * $FreeBSD$
  34. */
  35. /*
  36. * Definitions for disk quotas imposed on the average user
  37. * (big brother finally hits UNIX).
  38. *
  39. * The following constants define the amount of time given a user before the
  40. * soft limits are treated as hard limits (usually resulting in an allocation
  41. * failure). The timer is started when the user crosses their soft limit, it
  42. * is reset when they go below their soft limit.
  43. */
  44. #define MAX_IQ_TIME (7*24*60*60) /* seconds in 1 week */
  45. #define MAX_DQ_TIME (7*24*60*60) /* seconds in 1 week */
  46. /*
  47. * The following constants define the usage of the quota file array in the
  48. * ufsmount structure and dquot array in the inode structure. The semantics
  49. * of the elements of these arrays are defined in the routine getinoquota;
  50. * the remainder of the quota code treats them generically and need not be
  51. * inspected when changing the size of the array.
  52. */
  53. #define MAXQUOTAS 2
  54. #define USRQUOTA 0 /* element used for user quotas */
  55. #define GRPQUOTA 1 /* element used for group quotas */
  56. /*
  57. * Definitions for the default names of the quotas files.
  58. */
  59. #define INITQFNAMES { \
  60. "user", /* USRQUOTA */ \
  61. "group", /* GRPQUOTA */ \
  62. "undefined", \
  63. }
  64. #define QUOTAFILENAME "quota"
  65. #define QUOTAGROUP "operator"
  66. /*
  67. * Command definitions for the 'quotactl' system call. The commands are
  68. * broken into a main command defined below and a subcommand that is used
  69. * to convey the type of quota that is being manipulated (see above).
  70. */
  71. #define SUBCMDMASK 0x00ff
  72. #define SUBCMDSHIFT 8
  73. #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
  74. #define Q_QUOTAON 0x0100 /* enable quotas */
  75. #define Q_QUOTAOFF 0x0200 /* disable quotas */
  76. #define Q_GETQUOTA32 0x0300 /* get limits and usage (32-bit version) */
  77. #define Q_SETQUOTA32 0x0400 /* set limits and usage (32-bit version) */
  78. #define Q_SETUSE32 0x0500 /* set usage (32-bit version) */
  79. #define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */
  80. #define Q_GETQUOTA 0x0700 /* get limits and usage (64-bit version) */
  81. #define Q_SETQUOTA 0x0800 /* set limits and usage (64-bit version) */
  82. #define Q_SETUSE 0x0900 /* set usage (64-bit version) */
  83. #define Q_GETQUOTASIZE 0x0A00 /* get bit-size of quota file fields */
  84. #if 0
  85. /*
  86. * The following structure defines the format of the disk quota file
  87. * (as it appears on disk) - the file is an array of these structures
  88. * indexed by user or group number. The setquota system call establishes
  89. * the vnode for each quota file (a pointer is retained in the ufsmount
  90. * structure).
  91. */
  92. struct dqblk32 {
  93. uint32_t dqb_bhardlimit; /* absolute limit on disk blks alloc */
  94. uint32_t dqb_bsoftlimit; /* preferred limit on disk blks */
  95. uint32_t dqb_curblocks; /* current block count */
  96. uint32_t dqb_ihardlimit; /* maximum # allocated inodes + 1 */
  97. uint32_t dqb_isoftlimit; /* preferred inode limit */
  98. uint32_t dqb_curinodes; /* current # allocated inodes */
  99. int32_t dqb_btime; /* time limit for excessive disk use */
  100. int32_t dqb_itime; /* time limit for excessive files */
  101. };
  102. struct dqblk64 {
  103. uint64_t dqb_bhardlimit; /* absolute limit on disk blks alloc */
  104. uint64_t dqb_bsoftlimit; /* preferred limit on disk blks */
  105. uint64_t dqb_curblocks; /* current block count */
  106. uint64_t dqb_ihardlimit; /* maximum # allocated inodes + 1 */
  107. uint64_t dqb_isoftlimit; /* preferred inode limit */
  108. uint64_t dqb_curinodes; /* current # allocated inodes */
  109. int64_t dqb_btime; /* time limit for excessive disk use */
  110. int64_t dqb_itime; /* time limit for excessive files */
  111. };
  112. #define dqblk dqblk64
  113. #define Q_DQHDR64_MAGIC "QUOTA64"
  114. #define Q_DQHDR64_VERSION 0x20081104
  115. struct dqhdr64 {
  116. char dqh_magic[8]; /* Q_DQHDR64_MAGIC */
  117. uint32_t dqh_version; /* Q_DQHDR64_VERSION */
  118. uint32_t dqh_hdrlen; /* header length */
  119. uint32_t dqh_reclen; /* record length */
  120. char dqh_unused[44]; /* reserved for future extension */
  121. };
  122. /*
  123. * The following structure records disk usage for a user or group on a
  124. * filesystem. There is one allocated for each quota that exists on any
  125. * filesystem for the current user or group. A cache is kept of recently
  126. * used entries.
  127. * (h) protected by dqhlock
  128. */
  129. struct dquot {
  130. LIST_ENTRY(dquot) dq_hash; /* (h) hash list */
  131. TAILQ_ENTRY(dquot) dq_freelist; /* (h) free list */
  132. struct mtx dq_lock; /* lock for concurrency */
  133. uint16_t dq_flags; /* flags, see below */
  134. uint16_t dq_type; /* quota type of this dquot */
  135. uint32_t dq_cnt; /* (h) count of active references */
  136. uint32_t dq_id; /* identifier this applies to */
  137. struct ufsmount *dq_ump; /* (h) filesystem that this is
  138. taken from */
  139. struct dqblk64 dq_dqb; /* actual usage & quotas */
  140. };
  141. /*
  142. * Flag values.
  143. */
  144. #define DQ_LOCK 0x01 /* this quota locked (no MODS) */
  145. #define DQ_WANT 0x02 /* wakeup on unlock */
  146. #define DQ_MOD 0x04 /* this quota modified since read */
  147. #define DQ_FAKE 0x08 /* no limits here, just usage */
  148. #define DQ_BLKS 0x10 /* has been warned about blk limit */
  149. #define DQ_INODS 0x20 /* has been warned about inode limit */
  150. /*
  151. * Shorthand notation.
  152. */
  153. #define dq_bhardlimit dq_dqb.dqb_bhardlimit
  154. #define dq_bsoftlimit dq_dqb.dqb_bsoftlimit
  155. #define dq_curblocks dq_dqb.dqb_curblocks
  156. #define dq_ihardlimit dq_dqb.dqb_ihardlimit
  157. #define dq_isoftlimit dq_dqb.dqb_isoftlimit
  158. #define dq_curinodes dq_dqb.dqb_curinodes
  159. #define dq_btime dq_dqb.dqb_btime
  160. #define dq_itime dq_dqb.dqb_itime
  161. /*
  162. * If the system has never checked for a quota for this file, then it is
  163. * set to NODQUOT. Once a write attempt is made the inode pointer is set
  164. * to reference a dquot structure.
  165. */
  166. #define NODQUOT nil
  167. /*
  168. * Flags to chkdq() and chkiq()
  169. */
  170. #define FORCE 0x01 /* force usage changes independent of limits */
  171. #define CHOWN 0x02 /* (advisory) change initiated by chown */
  172. /*
  173. * Macros to avoid subroutine calls to trivial functions.
  174. */
  175. #ifdef DIAGNOSTIC
  176. #define DQREF(dq) dqref(dq)
  177. #else
  178. #define DQREF(dq) (dq)->dq_cnt++
  179. #endif
  180. #define DQI_LOCK(dq) mtx_lock(&(dq)->dq_lock)
  181. #define DQI_UNLOCK(dq) mtx_unlock(&(dq)->dq_lock)
  182. #define DQI_WAIT(dq, prio, msg) do { \
  183. while ((dq)->dq_flags & DQ_LOCK) { \
  184. (dq)->dq_flags |= DQ_WANT; \
  185. (void) msleep((dq), \
  186. &(dq)->dq_lock, (prio), (msg), 0); \
  187. } \
  188. } while (0)
  189. #define DQI_WAKEUP(dq) do { \
  190. if ((dq)->dq_flags & DQ_WANT) \
  191. wakeup((dq)); \
  192. (dq)->dq_flags &= ~(DQ_WANT|DQ_LOCK); \
  193. } while (0)
  194. struct inode;
  195. struct mount;
  196. struct thread;
  197. struct ucred;
  198. struct vnode;
  199. int chkdq(struct inode *, int64_t, struct ucred *, int);
  200. int chkiq(struct inode *, int, struct ucred *, int);
  201. void dqinit(void);
  202. void dqrele(struct vnode *, struct dquot *);
  203. void dquninit(void);
  204. int getinoquota(struct inode *);
  205. int qsync(struct mount *);
  206. int qsyncvp(struct vnode *);
  207. int quotaoff(struct thread *, struct mount *, int);
  208. int quotaon(struct thread *, struct mount *, int, void *);
  209. int getquota32(struct thread *, struct mount *, uint64_t, int, void *);
  210. int setquota32(struct thread *, struct mount *, uint64_t, int, void *);
  211. int setuse32(struct thread *, struct mount *, uint64_t, int, void *);
  212. int getquota(struct thread *, struct mount *, uint64_t, int, void *);
  213. int setquota(struct thread *, struct mount *, uint64_t, int, void *);
  214. int setuse(struct thread *, struct mount *, uint64_t, int, void *);
  215. int getquotasize(struct thread *, struct mount *, uint64_t, int,
  216. void *);
  217. vfs_quotactl_t ufs_quotactl;
  218. #ifdef SOFTUPDATES
  219. int quotaref(struct vnode *, struct dquot **);
  220. void quotarele(struct dquot **);
  221. void quotaadj(struct dquot **, struct ufsmount *, int64_t);
  222. #endif /* SOFTUPDATES */
  223. int quotactl(const char *, int, int, void *);
  224. #endif // 0