quota.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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. #ifndef _LINUX_QUOTA_
  33. #define _LINUX_QUOTA_
  34. #include <linux/list.h>
  35. #include <linux/mutex.h>
  36. #include <linux/rwsem.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/wait.h>
  39. #include <linux/percpu_counter.h>
  40. #include <linux/dqblk_xfs.h>
  41. #include <linux/dqblk_v1.h>
  42. #include <linux/dqblk_v2.h>
  43. #include <linux/atomic.h>
  44. #include <linux/uidgid.h>
  45. #include <linux/projid.h>
  46. #include <uapi/linux/quota.h>
  47. #undef USRQUOTA
  48. #undef GRPQUOTA
  49. #undef PRJQUOTA
  50. enum quota_type {
  51. USRQUOTA = 0, /* element used for user quotas */
  52. GRPQUOTA = 1, /* element used for group quotas */
  53. PRJQUOTA = 2, /* element used for project quotas */
  54. };
  55. /* Masks for quota types when used as a bitmask */
  56. #define QTYPE_MASK_USR (1 << USRQUOTA)
  57. #define QTYPE_MASK_GRP (1 << GRPQUOTA)
  58. #define QTYPE_MASK_PRJ (1 << PRJQUOTA)
  59. typedef __kernel_uid32_t qid_t; /* Type in which we store ids in memory */
  60. typedef long long qsize_t; /* Type in which we store sizes */
  61. struct kqid { /* Type in which we store the quota identifier */
  62. union {
  63. kuid_t uid;
  64. kgid_t gid;
  65. kprojid_t projid;
  66. };
  67. enum quota_type type; /* USRQUOTA (uid) or GRPQUOTA (gid) or PRJQUOTA (projid) */
  68. };
  69. extern bool qid_eq(struct kqid left, struct kqid right);
  70. extern bool qid_lt(struct kqid left, struct kqid right);
  71. extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
  72. extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
  73. extern bool qid_valid(struct kqid qid);
  74. /**
  75. * make_kqid - Map a user-namespace, type, qid tuple into a kqid.
  76. * @from: User namespace that the qid is in
  77. * @type: The type of quota
  78. * @qid: Quota identifier
  79. *
  80. * Maps a user-namespace, type qid tuple into a kernel internal
  81. * kqid, and returns that kqid.
  82. *
  83. * When there is no mapping defined for the user-namespace, type,
  84. * qid tuple an invalid kqid is returned. Callers are expected to
  85. * test for and handle invalid kqids being returned.
  86. * Invalid kqids may be tested for using qid_valid().
  87. */
  88. static inline struct kqid make_kqid(struct user_namespace *from,
  89. enum quota_type type, qid_t qid)
  90. {
  91. struct kqid kqid;
  92. kqid.type = type;
  93. switch (type) {
  94. case USRQUOTA:
  95. kqid.uid = make_kuid(from, qid);
  96. break;
  97. case GRPQUOTA:
  98. kqid.gid = make_kgid(from, qid);
  99. break;
  100. case PRJQUOTA:
  101. kqid.projid = make_kprojid(from, qid);
  102. break;
  103. default:
  104. BUG();
  105. }
  106. return kqid;
  107. }
  108. /**
  109. * make_kqid_invalid - Explicitly make an invalid kqid
  110. * @type: The type of quota identifier
  111. *
  112. * Returns an invalid kqid with the specified type.
  113. */
  114. static inline struct kqid make_kqid_invalid(enum quota_type type)
  115. {
  116. struct kqid kqid;
  117. kqid.type = type;
  118. switch (type) {
  119. case USRQUOTA:
  120. kqid.uid = INVALID_UID;
  121. break;
  122. case GRPQUOTA:
  123. kqid.gid = INVALID_GID;
  124. break;
  125. case PRJQUOTA:
  126. kqid.projid = INVALID_PROJID;
  127. break;
  128. default:
  129. BUG();
  130. }
  131. return kqid;
  132. }
  133. /**
  134. * make_kqid_uid - Make a kqid from a kuid
  135. * @uid: The kuid to make the quota identifier from
  136. */
  137. static inline struct kqid make_kqid_uid(kuid_t uid)
  138. {
  139. struct kqid kqid;
  140. kqid.type = USRQUOTA;
  141. kqid.uid = uid;
  142. return kqid;
  143. }
  144. /**
  145. * make_kqid_gid - Make a kqid from a kgid
  146. * @gid: The kgid to make the quota identifier from
  147. */
  148. static inline struct kqid make_kqid_gid(kgid_t gid)
  149. {
  150. struct kqid kqid;
  151. kqid.type = GRPQUOTA;
  152. kqid.gid = gid;
  153. return kqid;
  154. }
  155. /**
  156. * make_kqid_projid - Make a kqid from a projid
  157. * @projid: The kprojid to make the quota identifier from
  158. */
  159. static inline struct kqid make_kqid_projid(kprojid_t projid)
  160. {
  161. struct kqid kqid;
  162. kqid.type = PRJQUOTA;
  163. kqid.projid = projid;
  164. return kqid;
  165. }
  166. /**
  167. * qid_has_mapping - Report if a qid maps into a user namespace.
  168. * @ns: The user namespace to see if a value maps into.
  169. * @qid: The kernel internal quota identifier to test.
  170. */
  171. static inline bool qid_has_mapping(struct user_namespace *ns, struct kqid qid)
  172. {
  173. return from_kqid(ns, qid) != (qid_t) -1;
  174. }
  175. extern spinlock_t dq_data_lock;
  176. /* Maximal numbers of writes for quota operation (insert/delete/update)
  177. * (over VFS all formats) */
  178. #define DQUOT_INIT_ALLOC max(V1_INIT_ALLOC, V2_INIT_ALLOC)
  179. #define DQUOT_INIT_REWRITE max(V1_INIT_REWRITE, V2_INIT_REWRITE)
  180. #define DQUOT_DEL_ALLOC max(V1_DEL_ALLOC, V2_DEL_ALLOC)
  181. #define DQUOT_DEL_REWRITE max(V1_DEL_REWRITE, V2_DEL_REWRITE)
  182. /*
  183. * Data for one user/group kept in memory
  184. */
  185. struct mem_dqblk {
  186. qsize_t dqb_bhardlimit; /* absolute limit on disk blks alloc */
  187. qsize_t dqb_bsoftlimit; /* preferred limit on disk blks */
  188. qsize_t dqb_curspace; /* current used space */
  189. qsize_t dqb_rsvspace; /* current reserved space for delalloc*/
  190. qsize_t dqb_ihardlimit; /* absolute limit on allocated inodes */
  191. qsize_t dqb_isoftlimit; /* preferred inode limit */
  192. qsize_t dqb_curinodes; /* current # allocated inodes */
  193. time64_t dqb_btime; /* time limit for excessive disk use */
  194. time64_t dqb_itime; /* time limit for excessive inode use */
  195. };
  196. /*
  197. * Data for one quotafile kept in memory
  198. */
  199. struct quota_format_type;
  200. struct mem_dqinfo {
  201. struct quota_format_type *dqi_format;
  202. int dqi_fmt_id; /* Id of the dqi_format - used when turning
  203. * quotas on after remount RW */
  204. struct list_head dqi_dirty_list; /* List of dirty dquots [dq_list_lock] */
  205. unsigned long dqi_flags; /* DFQ_ flags [dq_data_lock] */
  206. unsigned int dqi_bgrace; /* Space grace time [dq_data_lock] */
  207. unsigned int dqi_igrace; /* Inode grace time [dq_data_lock] */
  208. qsize_t dqi_max_spc_limit; /* Maximum space limit [static] */
  209. qsize_t dqi_max_ino_limit; /* Maximum inode limit [static] */
  210. void *dqi_priv;
  211. };
  212. struct super_block;
  213. /* Mask for flags passed to userspace */
  214. #define DQF_GETINFO_MASK (DQF_ROOT_SQUASH | DQF_SYS_FILE)
  215. /* Mask for flags modifiable from userspace */
  216. #define DQF_SETINFO_MASK DQF_ROOT_SQUASH
  217. enum {
  218. DQF_INFO_DIRTY_B = DQF_PRIVATE,
  219. };
  220. #define DQF_INFO_DIRTY (1 << DQF_INFO_DIRTY_B) /* Is info dirty? */
  221. extern void mark_info_dirty(struct super_block *sb, int type);
  222. static inline int info_dirty(struct mem_dqinfo *info)
  223. {
  224. return test_bit(DQF_INFO_DIRTY_B, &info->dqi_flags);
  225. }
  226. enum {
  227. DQST_LOOKUPS,
  228. DQST_DROPS,
  229. DQST_READS,
  230. DQST_WRITES,
  231. DQST_CACHE_HITS,
  232. DQST_ALLOC_DQUOTS,
  233. DQST_FREE_DQUOTS,
  234. DQST_SYNCS,
  235. _DQST_DQSTAT_LAST
  236. };
  237. struct dqstats {
  238. unsigned long stat[_DQST_DQSTAT_LAST];
  239. struct percpu_counter counter[_DQST_DQSTAT_LAST];
  240. };
  241. extern struct dqstats dqstats;
  242. static inline void dqstats_inc(unsigned int type)
  243. {
  244. percpu_counter_inc(&dqstats.counter[type]);
  245. }
  246. static inline void dqstats_dec(unsigned int type)
  247. {
  248. percpu_counter_dec(&dqstats.counter[type]);
  249. }
  250. #define DQ_MOD_B 0 /* dquot modified since read */
  251. #define DQ_BLKS_B 1 /* uid/gid has been warned about blk limit */
  252. #define DQ_INODES_B 2 /* uid/gid has been warned about inode limit */
  253. #define DQ_FAKE_B 3 /* no limits only usage */
  254. #define DQ_READ_B 4 /* dquot was read into memory */
  255. #define DQ_ACTIVE_B 5 /* dquot is active (dquot_release not called) */
  256. #define DQ_RELEASING_B 6 /* dquot is in releasing_dquots list waiting
  257. * to be cleaned up */
  258. #define DQ_LASTSET_B 7 /* Following 6 bits (see QIF_) are reserved\
  259. * for the mask of entries set via SETQUOTA\
  260. * quotactl. They are set under dq_data_lock\
  261. * and the quota format handling dquot can\
  262. * clear them when it sees fit. */
  263. struct dquot {
  264. struct hlist_node dq_hash; /* Hash list in memory [dq_list_lock] */
  265. struct list_head dq_inuse; /* List of all quotas [dq_list_lock] */
  266. struct list_head dq_free; /* Free list element [dq_list_lock] */
  267. struct list_head dq_dirty; /* List of dirty dquots [dq_list_lock] */
  268. struct mutex dq_lock; /* dquot IO lock */
  269. spinlock_t dq_dqb_lock; /* Lock protecting dq_dqb changes */
  270. atomic_t dq_count; /* Use count */
  271. struct super_block *dq_sb; /* superblock this applies to */
  272. struct kqid dq_id; /* ID this applies to (uid, gid, projid) */
  273. loff_t dq_off; /* Offset of dquot on disk [dq_lock, stable once set] */
  274. unsigned long dq_flags; /* See DQ_* */
  275. struct mem_dqblk dq_dqb; /* Diskquota usage [dq_dqb_lock] */
  276. };
  277. /* Operations which must be implemented by each quota format */
  278. struct quota_format_ops {
  279. int (*check_quota_file)(struct super_block *sb, int type); /* Detect whether file is in our format */
  280. int (*read_file_info)(struct super_block *sb, int type); /* Read main info about file - called on quotaon() */
  281. int (*write_file_info)(struct super_block *sb, int type); /* Write main info about file */
  282. int (*free_file_info)(struct super_block *sb, int type); /* Called on quotaoff() */
  283. int (*read_dqblk)(struct dquot *dquot); /* Read structure for one user */
  284. int (*commit_dqblk)(struct dquot *dquot); /* Write structure for one user */
  285. int (*release_dqblk)(struct dquot *dquot); /* Called when last reference to dquot is being dropped */
  286. int (*get_next_id)(struct super_block *sb, struct kqid *qid); /* Get next ID with existing structure in the quota file */
  287. ANDROID_KABI_RESERVE(1);
  288. ANDROID_KABI_RESERVE(2);
  289. };
  290. /* Operations working with dquots */
  291. struct dquot_operations {
  292. int (*write_dquot) (struct dquot *); /* Ordinary dquot write */
  293. struct dquot *(*alloc_dquot)(struct super_block *, int); /* Allocate memory for new dquot */
  294. void (*destroy_dquot)(struct dquot *); /* Free memory for dquot */
  295. int (*acquire_dquot) (struct dquot *); /* Quota is going to be created on disk */
  296. int (*release_dquot) (struct dquot *); /* Quota is going to be deleted from disk */
  297. int (*mark_dirty) (struct dquot *); /* Dquot is marked dirty */
  298. int (*write_info) (struct super_block *, int); /* Write of quota "superblock" */
  299. /* get reserved quota for delayed alloc, value returned is managed by
  300. * quota code only */
  301. qsize_t *(*get_reserved_space) (struct inode *);
  302. int (*get_projid) (struct inode *, kprojid_t *);/* Get project ID */
  303. /* Get number of inodes that were charged for a given inode */
  304. int (*get_inode_usage) (struct inode *, qsize_t *);
  305. /* Get next ID with active quota structure */
  306. int (*get_next_id) (struct super_block *sb, struct kqid *qid);
  307. ANDROID_KABI_RESERVE(1);
  308. ANDROID_KABI_RESERVE(2);
  309. };
  310. struct path;
  311. /* Structure for communicating via ->get_dqblk() & ->set_dqblk() */
  312. struct qc_dqblk {
  313. int d_fieldmask; /* mask of fields to change in ->set_dqblk() */
  314. u64 d_spc_hardlimit; /* absolute limit on used space */
  315. u64 d_spc_softlimit; /* preferred limit on used space */
  316. u64 d_ino_hardlimit; /* maximum # allocated inodes */
  317. u64 d_ino_softlimit; /* preferred inode limit */
  318. u64 d_space; /* Space owned by the user */
  319. u64 d_ino_count; /* # inodes owned by the user */
  320. s64 d_ino_timer; /* zero if within inode limits */
  321. /* if not, we refuse service */
  322. s64 d_spc_timer; /* similar to above; for space */
  323. int d_ino_warns; /* # warnings issued wrt num inodes */
  324. int d_spc_warns; /* # warnings issued wrt used space */
  325. u64 d_rt_spc_hardlimit; /* absolute limit on realtime space */
  326. u64 d_rt_spc_softlimit; /* preferred limit on RT space */
  327. u64 d_rt_space; /* realtime space owned */
  328. s64 d_rt_spc_timer; /* similar to above; for RT space */
  329. int d_rt_spc_warns; /* # warnings issued wrt RT space */
  330. };
  331. /*
  332. * Field specifiers for ->set_dqblk() in struct qc_dqblk and also for
  333. * ->set_info() in struct qc_info
  334. */
  335. #define QC_INO_SOFT (1<<0)
  336. #define QC_INO_HARD (1<<1)
  337. #define QC_SPC_SOFT (1<<2)
  338. #define QC_SPC_HARD (1<<3)
  339. #define QC_RT_SPC_SOFT (1<<4)
  340. #define QC_RT_SPC_HARD (1<<5)
  341. #define QC_LIMIT_MASK (QC_INO_SOFT | QC_INO_HARD | QC_SPC_SOFT | QC_SPC_HARD | \
  342. QC_RT_SPC_SOFT | QC_RT_SPC_HARD)
  343. #define QC_SPC_TIMER (1<<6)
  344. #define QC_INO_TIMER (1<<7)
  345. #define QC_RT_SPC_TIMER (1<<8)
  346. #define QC_TIMER_MASK (QC_SPC_TIMER | QC_INO_TIMER | QC_RT_SPC_TIMER)
  347. #define QC_SPC_WARNS (1<<9)
  348. #define QC_INO_WARNS (1<<10)
  349. #define QC_RT_SPC_WARNS (1<<11)
  350. #define QC_WARNS_MASK (QC_SPC_WARNS | QC_INO_WARNS | QC_RT_SPC_WARNS)
  351. #define QC_SPACE (1<<12)
  352. #define QC_INO_COUNT (1<<13)
  353. #define QC_RT_SPACE (1<<14)
  354. #define QC_ACCT_MASK (QC_SPACE | QC_INO_COUNT | QC_RT_SPACE)
  355. #define QC_FLAGS (1<<15)
  356. #define QCI_SYSFILE (1 << 0) /* Quota file is hidden from userspace */
  357. #define QCI_ROOT_SQUASH (1 << 1) /* Root squash turned on */
  358. #define QCI_ACCT_ENABLED (1 << 2) /* Quota accounting enabled */
  359. #define QCI_LIMITS_ENFORCED (1 << 3) /* Quota limits enforced */
  360. /* Structures for communicating via ->get_state */
  361. struct qc_type_state {
  362. unsigned int flags; /* Flags QCI_* */
  363. unsigned int spc_timelimit; /* Time after which space softlimit is
  364. * enforced */
  365. unsigned int ino_timelimit; /* Ditto for inode softlimit */
  366. unsigned int rt_spc_timelimit; /* Ditto for real-time space */
  367. unsigned int spc_warnlimit; /* Limit for number of space warnings */
  368. unsigned int ino_warnlimit; /* Ditto for inodes */
  369. unsigned int rt_spc_warnlimit; /* Ditto for real-time space */
  370. unsigned long long ino; /* Inode number of quota file */
  371. blkcnt_t blocks; /* Number of 512-byte blocks in the file */
  372. blkcnt_t nextents; /* Number of extents in the file */
  373. };
  374. struct qc_state {
  375. unsigned int s_incoredqs; /* Number of dquots in core */
  376. struct qc_type_state s_state[MAXQUOTAS]; /* Per quota type information */
  377. };
  378. /* Structure for communicating via ->set_info */
  379. struct qc_info {
  380. int i_fieldmask; /* mask of fields to change in ->set_info() */
  381. unsigned int i_flags; /* Flags QCI_* */
  382. unsigned int i_spc_timelimit; /* Time after which space softlimit is
  383. * enforced */
  384. unsigned int i_ino_timelimit; /* Ditto for inode softlimit */
  385. unsigned int i_rt_spc_timelimit;/* Ditto for real-time space */
  386. unsigned int i_spc_warnlimit; /* Limit for number of space warnings */
  387. unsigned int i_ino_warnlimit; /* Limit for number of inode warnings */
  388. unsigned int i_rt_spc_warnlimit; /* Ditto for real-time space */
  389. };
  390. /* Operations handling requests from userspace */
  391. struct quotactl_ops {
  392. int (*quota_on)(struct super_block *, int, int, const struct path *);
  393. int (*quota_off)(struct super_block *, int);
  394. int (*quota_enable)(struct super_block *, unsigned int);
  395. int (*quota_disable)(struct super_block *, unsigned int);
  396. int (*quota_sync)(struct super_block *, int);
  397. int (*set_info)(struct super_block *, int, struct qc_info *);
  398. int (*get_dqblk)(struct super_block *, struct kqid, struct qc_dqblk *);
  399. int (*get_nextdqblk)(struct super_block *, struct kqid *,
  400. struct qc_dqblk *);
  401. int (*set_dqblk)(struct super_block *, struct kqid, struct qc_dqblk *);
  402. int (*get_state)(struct super_block *, struct qc_state *);
  403. int (*rm_xquota)(struct super_block *, unsigned int);
  404. ANDROID_KABI_RESERVE(1);
  405. ANDROID_KABI_RESERVE(2);
  406. };
  407. struct quota_format_type {
  408. int qf_fmt_id; /* Quota format id */
  409. const struct quota_format_ops *qf_ops; /* Operations of format */
  410. struct module *qf_owner; /* Module implementing quota format */
  411. struct quota_format_type *qf_next;
  412. };
  413. /**
  414. * Quota state flags - they come in three flavors - for users, groups and projects.
  415. *
  416. * Actual typed flags layout:
  417. * USRQUOTA GRPQUOTA PRJQUOTA
  418. * DQUOT_USAGE_ENABLED 0x0001 0x0002 0x0004
  419. * DQUOT_LIMITS_ENABLED 0x0008 0x0010 0x0020
  420. * DQUOT_SUSPENDED 0x0040 0x0080 0x0100
  421. *
  422. * Following bits are used for non-typed flags:
  423. * DQUOT_QUOTA_SYS_FILE 0x0200
  424. * DQUOT_NEGATIVE_USAGE 0x0400
  425. * DQUOT_NOLIST_DIRTY 0x0800
  426. */
  427. enum {
  428. _DQUOT_USAGE_ENABLED = 0, /* Track disk usage for users */
  429. _DQUOT_LIMITS_ENABLED, /* Enforce quota limits for users */
  430. _DQUOT_SUSPENDED, /* User diskquotas are off, but
  431. * we have necessary info in
  432. * memory to turn them on */
  433. _DQUOT_STATE_FLAGS
  434. };
  435. #define DQUOT_USAGE_ENABLED (1 << _DQUOT_USAGE_ENABLED * MAXQUOTAS)
  436. #define DQUOT_LIMITS_ENABLED (1 << _DQUOT_LIMITS_ENABLED * MAXQUOTAS)
  437. #define DQUOT_SUSPENDED (1 << _DQUOT_SUSPENDED * MAXQUOTAS)
  438. #define DQUOT_STATE_FLAGS (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED | \
  439. DQUOT_SUSPENDED)
  440. /* Other quota flags */
  441. #define DQUOT_STATE_LAST (_DQUOT_STATE_FLAGS * MAXQUOTAS)
  442. #define DQUOT_QUOTA_SYS_FILE (1 << DQUOT_STATE_LAST)
  443. /* Quota file is a special
  444. * system file and user cannot
  445. * touch it. Filesystem is
  446. * responsible for setting
  447. * S_NOQUOTA, S_NOATIME flags
  448. */
  449. #define DQUOT_NEGATIVE_USAGE (1 << (DQUOT_STATE_LAST + 1))
  450. /* Allow negative quota usage */
  451. /* Do not track dirty dquots in a list */
  452. #define DQUOT_NOLIST_DIRTY (1 << (DQUOT_STATE_LAST + 2))
  453. static inline unsigned int dquot_state_flag(unsigned int flags, int type)
  454. {
  455. return flags << type;
  456. }
  457. static inline unsigned int dquot_generic_flag(unsigned int flags, int type)
  458. {
  459. return (flags >> type) & DQUOT_STATE_FLAGS;
  460. }
  461. /* Bitmap of quota types where flag is set in flags */
  462. static __always_inline unsigned dquot_state_types(unsigned flags, unsigned flag)
  463. {
  464. BUILD_BUG_ON_NOT_POWER_OF_2(flag);
  465. return (flags / flag) & ((1 << MAXQUOTAS) - 1);
  466. }
  467. #ifdef CONFIG_QUOTA_NETLINK_INTERFACE
  468. extern void quota_send_warning(struct kqid qid, dev_t dev,
  469. const char warntype);
  470. #else
  471. static inline void quota_send_warning(struct kqid qid, dev_t dev,
  472. const char warntype)
  473. {
  474. return;
  475. }
  476. #endif /* CONFIG_QUOTA_NETLINK_INTERFACE */
  477. struct quota_info {
  478. unsigned int flags; /* Flags for diskquotas on this device */
  479. struct rw_semaphore dqio_sem; /* Lock quota file while I/O in progress */
  480. struct inode *files[MAXQUOTAS]; /* inodes of quotafiles */
  481. struct mem_dqinfo info[MAXQUOTAS]; /* Information for each quota type */
  482. const struct quota_format_ops *ops[MAXQUOTAS]; /* Operations for each type */
  483. };
  484. int register_quota_format(struct quota_format_type *fmt);
  485. void unregister_quota_format(struct quota_format_type *fmt);
  486. struct quota_module_name {
  487. int qm_fmt_id;
  488. char *qm_mod_name;
  489. };
  490. #define INIT_QUOTA_MODULE_NAMES {\
  491. {QFMT_VFS_OLD, "quota_v1"},\
  492. {QFMT_VFS_V0, "quota_v2"},\
  493. {QFMT_VFS_V1, "quota_v2"},\
  494. {0, NULL}}
  495. #endif /* _QUOTA_ */