quota.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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, 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. * Version: $Id: quota.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
  33. */
  34. #ifndef _LINUX_QUOTA_
  35. #define _LINUX_QUOTA_
  36. #include <linux/errno.h>
  37. #include <linux/types.h>
  38. #define __DQUOT_VERSION__ "dquot_6.5.1"
  39. #define __DQUOT_NUM_VERSION__ 6*10000+5*100+1
  40. typedef __kernel_uid32_t qid_t; /* Type in which we store ids in memory */
  41. typedef __u64 qsize_t; /* Type in which we store sizes */
  42. extern spinlock_t dq_data_lock;
  43. /* Size of blocks in which are counted size limits */
  44. #define QUOTABLOCK_BITS 10
  45. #define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS)
  46. /* Conversion routines from and to quota blocks */
  47. #define qb2kb(x) ((x) << (QUOTABLOCK_BITS-10))
  48. #define kb2qb(x) ((x) >> (QUOTABLOCK_BITS-10))
  49. #define toqb(x) (((x) + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS)
  50. #define MAXQUOTAS 2
  51. #define USRQUOTA 0 /* element used for user quotas */
  52. #define GRPQUOTA 1 /* element used for group quotas */
  53. /*
  54. * Definitions for the default names of the quotas files.
  55. */
  56. #define INITQFNAMES { \
  57. "user", /* USRQUOTA */ \
  58. "group", /* GRPQUOTA */ \
  59. "undefined", \
  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. #define Q_SYNC 0x800001 /* sync disk copy of a filesystems quotas */
  71. #define Q_QUOTAON 0x800002 /* turn quotas on */
  72. #define Q_QUOTAOFF 0x800003 /* turn quotas off */
  73. #define Q_GETFMT 0x800004 /* get quota format used on given filesystem */
  74. #define Q_GETINFO 0x800005 /* get information about quota files */
  75. #define Q_SETINFO 0x800006 /* set information about quota files */
  76. #define Q_GETQUOTA 0x800007 /* get user quota structure */
  77. #define Q_SETQUOTA 0x800008 /* set user quota structure */
  78. /*
  79. * Quota structure used for communication with userspace via quotactl
  80. * Following flags are used to specify which fields are valid
  81. */
  82. #define QIF_BLIMITS 1
  83. #define QIF_SPACE 2
  84. #define QIF_ILIMITS 4
  85. #define QIF_INODES 8
  86. #define QIF_BTIME 16
  87. #define QIF_ITIME 32
  88. #define QIF_LIMITS (QIF_BLIMITS | QIF_ILIMITS)
  89. #define QIF_USAGE (QIF_SPACE | QIF_INODES)
  90. #define QIF_TIMES (QIF_BTIME | QIF_ITIME)
  91. #define QIF_ALL (QIF_LIMITS | QIF_USAGE | QIF_TIMES)
  92. struct if_dqblk {
  93. __u64 dqb_bhardlimit;
  94. __u64 dqb_bsoftlimit;
  95. __u64 dqb_curspace;
  96. __u64 dqb_ihardlimit;
  97. __u64 dqb_isoftlimit;
  98. __u64 dqb_curinodes;
  99. __u64 dqb_btime;
  100. __u64 dqb_itime;
  101. __u32 dqb_valid;
  102. };
  103. /*
  104. * Structure used for setting quota information about file via quotactl
  105. * Following flags are used to specify which fields are valid
  106. */
  107. #define IIF_BGRACE 1
  108. #define IIF_IGRACE 2
  109. #define IIF_FLAGS 4
  110. #define IIF_ALL (IIF_BGRACE | IIF_IGRACE | IIF_FLAGS)
  111. struct if_dqinfo {
  112. __u64 dqi_bgrace;
  113. __u64 dqi_igrace;
  114. __u32 dqi_flags;
  115. __u32 dqi_valid;
  116. };
  117. #ifdef __KERNEL__
  118. #include <linux/spinlock.h>
  119. #include <linux/rwsem.h>
  120. #include <linux/mutex.h>
  121. #include <linux/dqblk_xfs.h>
  122. #include <linux/dqblk_v1.h>
  123. #include <linux/dqblk_v2.h>
  124. /* Maximal numbers of writes for quota operation (insert/delete/update)
  125. * (over VFS all formats) */
  126. #define DQUOT_INIT_ALLOC max(V1_INIT_ALLOC, V2_INIT_ALLOC)
  127. #define DQUOT_INIT_REWRITE max(V1_INIT_REWRITE, V2_INIT_REWRITE)
  128. #define DQUOT_DEL_ALLOC max(V1_DEL_ALLOC, V2_DEL_ALLOC)
  129. #define DQUOT_DEL_REWRITE max(V1_DEL_REWRITE, V2_DEL_REWRITE)
  130. /*
  131. * Data for one user/group kept in memory
  132. */
  133. struct mem_dqblk {
  134. __u32 dqb_bhardlimit; /* absolute limit on disk blks alloc */
  135. __u32 dqb_bsoftlimit; /* preferred limit on disk blks */
  136. qsize_t dqb_curspace; /* current used space */
  137. __u32 dqb_ihardlimit; /* absolute limit on allocated inodes */
  138. __u32 dqb_isoftlimit; /* preferred inode limit */
  139. __u32 dqb_curinodes; /* current # allocated inodes */
  140. time_t dqb_btime; /* time limit for excessive disk use */
  141. time_t dqb_itime; /* time limit for excessive inode use */
  142. };
  143. /*
  144. * Data for one quotafile kept in memory
  145. */
  146. struct quota_format_type;
  147. struct mem_dqinfo {
  148. struct quota_format_type *dqi_format;
  149. struct list_head dqi_dirty_list; /* List of dirty dquots */
  150. unsigned long dqi_flags;
  151. unsigned int dqi_bgrace;
  152. unsigned int dqi_igrace;
  153. union {
  154. struct v1_mem_dqinfo v1_i;
  155. struct v2_mem_dqinfo v2_i;
  156. } u;
  157. };
  158. struct super_block;
  159. #define DQF_MASK 0xffff /* Mask for format specific flags */
  160. #define DQF_INFO_DIRTY_B 16
  161. #define DQF_INFO_DIRTY (1 << DQF_INFO_DIRTY_B) /* Is info dirty? */
  162. extern void mark_info_dirty(struct super_block *sb, int type);
  163. #define info_dirty(info) test_bit(DQF_INFO_DIRTY_B, &(info)->dqi_flags)
  164. #define info_any_dquot_dirty(info) (!list_empty(&(info)->dqi_dirty_list))
  165. #define info_any_dirty(info) (info_dirty(info) || info_any_dquot_dirty(info))
  166. #define sb_dqopt(sb) (&(sb)->s_dquot)
  167. #define sb_dqinfo(sb, type) (sb_dqopt(sb)->info+(type))
  168. struct dqstats {
  169. int lookups;
  170. int drops;
  171. int reads;
  172. int writes;
  173. int cache_hits;
  174. int allocated_dquots;
  175. int free_dquots;
  176. int syncs;
  177. };
  178. extern struct dqstats dqstats;
  179. #define DQ_MOD_B 0 /* dquot modified since read */
  180. #define DQ_BLKS_B 1 /* uid/gid has been warned about blk limit */
  181. #define DQ_INODES_B 2 /* uid/gid has been warned about inode limit */
  182. #define DQ_FAKE_B 3 /* no limits only usage */
  183. #define DQ_READ_B 4 /* dquot was read into memory */
  184. #define DQ_ACTIVE_B 5 /* dquot is active (dquot_release not called) */
  185. struct dquot {
  186. struct hlist_node dq_hash; /* Hash list in memory */
  187. struct list_head dq_inuse; /* List of all quotas */
  188. struct list_head dq_free; /* Free list element */
  189. struct list_head dq_dirty; /* List of dirty dquots */
  190. struct mutex dq_lock; /* dquot IO lock */
  191. atomic_t dq_count; /* Use count */
  192. wait_queue_head_t dq_wait_unused; /* Wait queue for dquot to become unused */
  193. struct super_block *dq_sb; /* superblock this applies to */
  194. unsigned int dq_id; /* ID this applies to (uid, gid) */
  195. loff_t dq_off; /* Offset of dquot on disk */
  196. unsigned long dq_flags; /* See DQ_* */
  197. short dq_type; /* Type of quota */
  198. struct mem_dqblk dq_dqb; /* Diskquota usage */
  199. };
  200. #define NODQUOT (struct dquot *)NULL
  201. #define QUOTA_OK 0
  202. #define NO_QUOTA 1
  203. /* Operations which must be implemented by each quota format */
  204. struct quota_format_ops {
  205. int (*check_quota_file)(struct super_block *sb, int type); /* Detect whether file is in our format */
  206. int (*read_file_info)(struct super_block *sb, int type); /* Read main info about file - called on quotaon() */
  207. int (*write_file_info)(struct super_block *sb, int type); /* Write main info about file */
  208. int (*free_file_info)(struct super_block *sb, int type); /* Called on quotaoff() */
  209. int (*read_dqblk)(struct dquot *dquot); /* Read structure for one user */
  210. int (*commit_dqblk)(struct dquot *dquot); /* Write structure for one user */
  211. int (*release_dqblk)(struct dquot *dquot); /* Called when last reference to dquot is being dropped */
  212. };
  213. /* Operations working with dquots */
  214. struct dquot_operations {
  215. int (*initialize) (struct inode *, int);
  216. int (*drop) (struct inode *);
  217. int (*alloc_space) (struct inode *, qsize_t, int);
  218. int (*alloc_inode) (const struct inode *, unsigned long);
  219. int (*free_space) (struct inode *, qsize_t);
  220. int (*free_inode) (const struct inode *, unsigned long);
  221. int (*transfer) (struct inode *, struct iattr *);
  222. int (*write_dquot) (struct dquot *); /* Ordinary dquot write */
  223. int (*acquire_dquot) (struct dquot *); /* Quota is going to be created on disk */
  224. int (*release_dquot) (struct dquot *); /* Quota is going to be deleted from disk */
  225. int (*mark_dirty) (struct dquot *); /* Dquot is marked dirty */
  226. int (*write_info) (struct super_block *, int); /* Write of quota "superblock" */
  227. };
  228. /* Operations handling requests from userspace */
  229. struct quotactl_ops {
  230. int (*quota_on)(struct super_block *, int, int, char *);
  231. int (*quota_off)(struct super_block *, int);
  232. int (*quota_sync)(struct super_block *, int);
  233. int (*get_info)(struct super_block *, int, struct if_dqinfo *);
  234. int (*set_info)(struct super_block *, int, struct if_dqinfo *);
  235. int (*get_dqblk)(struct super_block *, int, qid_t, struct if_dqblk *);
  236. int (*set_dqblk)(struct super_block *, int, qid_t, struct if_dqblk *);
  237. int (*get_xstate)(struct super_block *, struct fs_quota_stat *);
  238. int (*set_xstate)(struct super_block *, unsigned int, int);
  239. int (*get_xquota)(struct super_block *, int, qid_t, struct fs_disk_quota *);
  240. int (*set_xquota)(struct super_block *, int, qid_t, struct fs_disk_quota *);
  241. };
  242. struct quota_format_type {
  243. int qf_fmt_id; /* Quota format id */
  244. struct quota_format_ops *qf_ops; /* Operations of format */
  245. struct module *qf_owner; /* Module implementing quota format */
  246. struct quota_format_type *qf_next;
  247. };
  248. #define DQUOT_USR_ENABLED 0x01 /* User diskquotas enabled */
  249. #define DQUOT_GRP_ENABLED 0x02 /* Group diskquotas enabled */
  250. struct quota_info {
  251. unsigned int flags; /* Flags for diskquotas on this device */
  252. struct mutex dqio_mutex; /* lock device while I/O in progress */
  253. struct mutex dqonoff_mutex; /* Serialize quotaon & quotaoff */
  254. struct rw_semaphore dqptr_sem; /* serialize ops using quota_info struct, pointers from inode to dquots */
  255. struct inode *files[MAXQUOTAS]; /* inodes of quotafiles */
  256. struct mem_dqinfo info[MAXQUOTAS]; /* Information for each quota type */
  257. struct quota_format_ops *ops[MAXQUOTAS]; /* Operations for each type */
  258. };
  259. /* Inline would be better but we need to dereference super_block which is not defined yet */
  260. int mark_dquot_dirty(struct dquot *dquot);
  261. #define dquot_dirty(dquot) test_bit(DQ_MOD_B, &(dquot)->dq_flags)
  262. #define sb_has_quota_enabled(sb, type) ((type)==USRQUOTA ? \
  263. (sb_dqopt(sb)->flags & DQUOT_USR_ENABLED) : (sb_dqopt(sb)->flags & DQUOT_GRP_ENABLED))
  264. #define sb_any_quota_enabled(sb) (sb_has_quota_enabled(sb, USRQUOTA) | \
  265. sb_has_quota_enabled(sb, GRPQUOTA))
  266. int register_quota_format(struct quota_format_type *fmt);
  267. void unregister_quota_format(struct quota_format_type *fmt);
  268. struct quota_module_name {
  269. int qm_fmt_id;
  270. char *qm_mod_name;
  271. };
  272. #define INIT_QUOTA_MODULE_NAMES {\
  273. {QFMT_VFS_OLD, "quota_v1"},\
  274. {QFMT_VFS_V0, "quota_v2"},\
  275. {0, NULL}}
  276. #else
  277. # /* nodep */ include <sys/cdefs.h>
  278. __BEGIN_DECLS
  279. long quotactl __P ((unsigned int, const char *, int, caddr_t));
  280. __END_DECLS
  281. #endif /* __KERNEL__ */
  282. #endif /* _QUOTA_ */