quota.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* This just represents the non-kernel parts of <linux/quota.h>.
  2. *
  3. * here's the corresponding copyright:
  4. * Copyright (c) 1982, 1986 Regents of the University of California.
  5. * All rights reserved.
  6. *
  7. * This code is derived from software contributed to Berkeley by
  8. * Robert Elz at The University of Melbourne.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 4. Neither the name of the University nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. */
  34. #ifndef _SYS_QUOTA_H
  35. #define _SYS_QUOTA_H 1
  36. #include <features.h>
  37. #include <sys/types.h>
  38. #ifdef __UCLIBC__
  39. # undef _LINUX_QUOTA_VERSION
  40. # define _LINUX_QUOTA_VERSION 1
  41. #endif
  42. /*
  43. * Select between different incompatible quota versions.
  44. * Default to the version used by Linux kernel version 2.4.22
  45. * or later. */
  46. #ifndef _LINUX_QUOTA_VERSION
  47. # define _LINUX_QUOTA_VERSION 2
  48. #endif
  49. /*
  50. * Convert diskblocks to blocks and the other way around.
  51. * currently only to fool the BSD source. :-)
  52. */
  53. #define dbtob(num) ((num) << 10)
  54. #define btodb(num) ((num) >> 10)
  55. /*
  56. * Convert count of filesystem blocks to diskquota blocks, meant
  57. * for filesystems where i_blksize != BLOCK_SIZE
  58. */
  59. #define fs_to_dq_blocks(num, blksize) (((num) * (blksize)) / BLOCK_SIZE)
  60. /*
  61. * Definitions for disk quotas imposed on the average user
  62. * (big brother finally hits Linux).
  63. *
  64. * The following constants define the amount of time given a user
  65. * before the soft limits are treated as hard limits (usually resulting
  66. * in an allocation failure). The timer is started when the user crosses
  67. * their soft limit, it is reset when they go below their soft limit.
  68. */
  69. #define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */
  70. #define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */
  71. #define MAXQUOTAS 2
  72. #define USRQUOTA 0 /* element used for user quotas */
  73. #define GRPQUOTA 1 /* element used for group quotas */
  74. /*
  75. * Definitions for the default names of the quotas files.
  76. */
  77. #define INITQFNAMES { \
  78. "user", /* USRQUOTA */ \
  79. "group", /* GRPQUOTA */ \
  80. "undefined", \
  81. };
  82. #define QUOTAFILENAME "quota"
  83. #define QUOTAGROUP "staff"
  84. #define NR_DQHASH 43 /* Just an arbitrary number any suggestions ? */
  85. #define NR_DQUOTS 256 /* Number of quotas active at one time */
  86. /*
  87. * Command definitions for the 'quotactl' system call.
  88. * The commands are broken into a main command defined below
  89. * and a subcommand that is used to convey the type of
  90. * quota that is being manipulated (see above).
  91. */
  92. #define SUBCMDMASK 0x00ff
  93. #define SUBCMDSHIFT 8
  94. #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
  95. #if _LINUX_QUOTA_VERSION < 2
  96. # define Q_QUOTAON 0x0100 /* enable quotas */
  97. # define Q_QUOTAOFF 0x0200 /* disable quotas */
  98. # define Q_GETQUOTA 0x0300 /* get limits and usage */
  99. # define Q_SETQUOTA 0x0400 /* set limits and usage */
  100. # define Q_SETUSE 0x0500 /* set usage */
  101. # define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */
  102. # define Q_SETQLIM 0x0700 /* set limits */
  103. # define Q_GETSTATS 0x0800 /* get collected stats */
  104. # define Q_RSQUASH 0x1000 /* set root_squash option */
  105. #else
  106. # define Q_SYNC 0x800001 /* sync disk copy of a filesystems quotas */
  107. # define Q_QUOTAON 0x800002 /* turn quotas on */
  108. # define Q_QUOTAOFF 0x800003 /* turn quotas off */
  109. # define Q_GETFMT 0x800004 /* get quota format used on given filesystem */
  110. # define Q_GETINFO 0x800005 /* get information about quota files */
  111. # define Q_SETINFO 0x800006 /* set information about quota files */
  112. # define Q_GETQUOTA 0x800007 /* get user quota structure */
  113. # define Q_SETQUOTA 0x800008 /* set user quota structure */
  114. #endif
  115. /*
  116. * The following structure defines the format of the disk quota file
  117. * (as it appears on disk) - the file is an array of these structures
  118. * indexed by user or group number.
  119. */
  120. #if _LINUX_QUOTA_VERSION < 2
  121. struct dqblk
  122. {
  123. u_int32_t dqb_bhardlimit; /* absolute limit on disk blks alloc */
  124. u_int32_t dqb_bsoftlimit; /* preferred limit on disk blks */
  125. u_int32_t dqb_curblocks; /* current block count */
  126. u_int32_t dqb_ihardlimit; /* maximum # allocated inodes */
  127. u_int32_t dqb_isoftlimit; /* preferred inode limit */
  128. u_int32_t dqb_curinodes; /* current # allocated inodes */
  129. time_t dqb_btime; /* time limit for excessive disk use */
  130. time_t dqb_itime; /* time limit for excessive files */
  131. };
  132. #else
  133. /* Flags that indicate which fields in dqblk structure are valid. */
  134. #define QIF_BLIMITS 1
  135. #define QIF_SPACE 2
  136. #define QIF_ILIMITS 4
  137. #define QIF_INODES 8
  138. #define QIF_BTIME 16
  139. #define QIF_ITIME 32
  140. #define QIF_LIMITS (QIF_BLIMITS | QIF_ILIMITS)
  141. #define QIF_USAGE (QIF_SPACE | QIF_INODES)
  142. #define QIF_TIMES (QIF_BTIME | QIF_ITIME)
  143. #define QIF_ALL (QIF_LIMITS | QIF_USAGE | QIF_TIMES)
  144. struct dqblk
  145. {
  146. u_int64_t dqb_bhardlimit; /* absolute limit on disk quota blocks alloc */
  147. u_int64_t dqb_bsoftlimit; /* preferred limit on disk quota blocks */
  148. u_int64_t dqb_curspace; /* current quota block count */
  149. u_int64_t dqb_ihardlimit; /* maximum # allocated inodes */
  150. u_int64_t dqb_isoftlimit; /* preferred inode limit */
  151. u_int64_t dqb_curinodes; /* current # allocated inodes */
  152. u_int64_t dqb_btime; /* time limit for excessive disk use */
  153. u_int64_t dqb_itime; /* time limit for excessive files */
  154. u_int32_t dqb_valid; /* bitmask of QIF_* constants */
  155. };
  156. #endif
  157. /*
  158. * Shorthand notation.
  159. */
  160. #define dq_bhardlimit dq_dqb.dqb_bhardlimit
  161. #define dq_bsoftlimit dq_dqb.dqb_bsoftlimit
  162. #if _LINUX_QUOTA_VERSION < 2
  163. # define dq_curblocks dq_dqb.dqb_curblocks
  164. #else
  165. # define dq_curspace dq_dqb.dqb_curspace
  166. # define dq_valid dq_dqb.dqb_valid
  167. #endif
  168. #define dq_ihardlimit dq_dqb.dqb_ihardlimit
  169. #define dq_isoftlimit dq_dqb.dqb_isoftlimit
  170. #define dq_curinodes dq_dqb.dqb_curinodes
  171. #define dq_btime dq_dqb.dqb_btime
  172. #define dq_itime dq_dqb.dqb_itime
  173. #define dqoff(UID) ((loff_t)((UID) * sizeof (struct dqblk)))
  174. #if _LINUX_QUOTA_VERSION < 2
  175. struct dqstats
  176. {
  177. u_int32_t lookups;
  178. u_int32_t drops;
  179. u_int32_t reads;
  180. u_int32_t writes;
  181. u_int32_t cache_hits;
  182. u_int32_t pages_allocated;
  183. u_int32_t allocated_dquots;
  184. u_int32_t free_dquots;
  185. u_int32_t syncs;
  186. };
  187. #else
  188. /* Flags that indicate which fields in dqinfo structure are valid. */
  189. # define IIF_BGRACE 1
  190. # define IIF_IGRACE 2
  191. # define IIF_FLAGS 4
  192. # define IIF_ALL (IIF_BGRACE | IIF_IGRACE | IIF_FLAGS)
  193. struct dqinfo
  194. {
  195. u_int64_t dqi_bgrace;
  196. u_int64_t dqi_igrace;
  197. u_int32_t dqi_flags;
  198. u_int32_t dqi_valid;
  199. };
  200. #endif
  201. __BEGIN_DECLS
  202. extern int quotactl (int __cmd, const char *__special, int __id,
  203. caddr_t __addr) __THROW;
  204. __END_DECLS
  205. #endif /* sys/quota.h */