quota.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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 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_LASTSET_B 6 /* Following 6 bits (see QIF_) are reserved\
  257. * for the mask of entries set via SETQUOTA\
  258. * quotactl. They are set under dq_data_lock\
  259. * and the quota format handling dquot can\
  260. * clear them when it sees fit. */
  261. struct dquot {
  262. struct hlist_node dq_hash; /* Hash list in memory [dq_list_lock] */
  263. struct list_head dq_inuse; /* List of all quotas [dq_list_lock] */
  264. struct list_head dq_free; /* Free list element [dq_list_lock] */
  265. struct list_head dq_dirty; /* List of dirty dquots [dq_list_lock] */
  266. struct mutex dq_lock; /* dquot IO lock */
  267. spinlock_t dq_dqb_lock; /* Lock protecting dq_dqb changes */
  268. atomic_t dq_count; /* Use count */
  269. struct super_block *dq_sb; /* superblock this applies to */
  270. struct kqid dq_id; /* ID this applies to (uid, gid, projid) */
  271. loff_t dq_off; /* Offset of dquot on disk [dq_lock, stable once set] */
  272. unsigned long dq_flags; /* See DQ_* */
  273. struct mem_dqblk dq_dqb; /* Diskquota usage [dq_dqb_lock] */
  274. };
  275. /* Operations which must be implemented by each quota format */
  276. struct quota_format_ops {
  277. int (*check_quota_file)(struct super_block *sb, int type); /* Detect whether file is in our format */
  278. int (*read_file_info)(struct super_block *sb, int type); /* Read main info about file - called on quotaon() */
  279. int (*write_file_info)(struct super_block *sb, int type); /* Write main info about file */
  280. int (*free_file_info)(struct super_block *sb, int type); /* Called on quotaoff() */
  281. int (*read_dqblk)(struct dquot *dquot); /* Read structure for one user */
  282. int (*commit_dqblk)(struct dquot *dquot); /* Write structure for one user */
  283. int (*release_dqblk)(struct dquot *dquot); /* Called when last reference to dquot is being dropped */
  284. int (*get_next_id)(struct super_block *sb, struct kqid *qid); /* Get next ID with existing structure in the quota file */
  285. ANDROID_KABI_RESERVE(1);
  286. ANDROID_KABI_RESERVE(2);
  287. };
  288. /* Operations working with dquots */
  289. struct dquot_operations {
  290. int (*write_dquot) (struct dquot *); /* Ordinary dquot write */
  291. struct dquot *(*alloc_dquot)(struct super_block *, int); /* Allocate memory for new dquot */
  292. void (*destroy_dquot)(struct dquot *); /* Free memory for dquot */
  293. int (*acquire_dquot) (struct dquot *); /* Quota is going to be created on disk */
  294. int (*release_dquot) (struct dquot *); /* Quota is going to be deleted from disk */
  295. int (*mark_dirty) (struct dquot *); /* Dquot is marked dirty */
  296. int (*write_info) (struct super_block *, int); /* Write of quota "superblock" */
  297. /* get reserved quota for delayed alloc, value returned is managed by
  298. * quota code only */
  299. qsize_t *(*get_reserved_space) (struct inode *);
  300. int (*get_projid) (struct inode *, kprojid_t *);/* Get project ID */
  301. /* Get number of inodes that were charged for a given inode */
  302. int (*get_inode_usage) (struct inode *, qsize_t *);
  303. /* Get next ID with active quota structure */
  304. int (*get_next_id) (struct super_block *sb, struct kqid *qid);
  305. ANDROID_KABI_RESERVE(1);
  306. ANDROID_KABI_RESERVE(2);
  307. };
  308. struct path;
  309. /* Structure for communicating via ->get_dqblk() & ->set_dqblk() */
  310. struct qc_dqblk {
  311. int d_fieldmask; /* mask of fields to change in ->set_dqblk() */
  312. u64 d_spc_hardlimit; /* absolute limit on used space */
  313. u64 d_spc_softlimit; /* preferred limit on used space */
  314. u64 d_ino_hardlimit; /* maximum # allocated inodes */
  315. u64 d_ino_softlimit; /* preferred inode limit */
  316. u64 d_space; /* Space owned by the user */
  317. u64 d_ino_count; /* # inodes owned by the user */
  318. s64 d_ino_timer; /* zero if within inode limits */
  319. /* if not, we refuse service */
  320. s64 d_spc_timer; /* similar to above; for space */
  321. int d_ino_warns; /* # warnings issued wrt num inodes */
  322. int d_spc_warns; /* # warnings issued wrt used space */
  323. u64 d_rt_spc_hardlimit; /* absolute limit on realtime space */
  324. u64 d_rt_spc_softlimit; /* preferred limit on RT space */
  325. u64 d_rt_space; /* realtime space owned */
  326. s64 d_rt_spc_timer; /* similar to above; for RT space */
  327. int d_rt_spc_warns; /* # warnings issued wrt RT space */
  328. };
  329. /*
  330. * Field specifiers for ->set_dqblk() in struct qc_dqblk and also for
  331. * ->set_info() in struct qc_info
  332. */
  333. #define QC_INO_SOFT (1<<0)
  334. #define QC_INO_HARD (1<<1)
  335. #define QC_SPC_SOFT (1<<2)
  336. #define QC_SPC_HARD (1<<3)
  337. #define QC_RT_SPC_SOFT (1<<4)
  338. #define QC_RT_SPC_HARD (1<<5)
  339. #define QC_LIMIT_MASK (QC_INO_SOFT | QC_INO_HARD | QC_SPC_SOFT | QC_SPC_HARD | \
  340. QC_RT_SPC_SOFT | QC_RT_SPC_HARD)
  341. #define QC_SPC_TIMER (1<<6)
  342. #define QC_INO_TIMER (1<<7)
  343. #define QC_RT_SPC_TIMER (1<<8)
  344. #define QC_TIMER_MASK (QC_SPC_TIMER | QC_INO_TIMER | QC_RT_SPC_TIMER)
  345. #define QC_SPC_WARNS (1<<9)
  346. #define QC_INO_WARNS (1<<10)
  347. #define QC_RT_SPC_WARNS (1<<11)
  348. #define QC_WARNS_MASK (QC_SPC_WARNS | QC_INO_WARNS | QC_RT_SPC_WARNS)
  349. #define QC_SPACE (1<<12)
  350. #define QC_INO_COUNT (1<<13)
  351. #define QC_RT_SPACE (1<<14)
  352. #define QC_ACCT_MASK (QC_SPACE | QC_INO_COUNT | QC_RT_SPACE)
  353. #define QC_FLAGS (1<<15)
  354. #define QCI_SYSFILE (1 << 0) /* Quota file is hidden from userspace */
  355. #define QCI_ROOT_SQUASH (1 << 1) /* Root squash turned on */
  356. #define QCI_ACCT_ENABLED (1 << 2) /* Quota accounting enabled */
  357. #define QCI_LIMITS_ENFORCED (1 << 3) /* Quota limits enforced */
  358. /* Structures for communicating via ->get_state */
  359. struct qc_type_state {
  360. unsigned int flags; /* Flags QCI_* */
  361. unsigned int spc_timelimit; /* Time after which space softlimit is
  362. * enforced */
  363. unsigned int ino_timelimit; /* Ditto for inode softlimit */
  364. unsigned int rt_spc_timelimit; /* Ditto for real-time space */
  365. unsigned int spc_warnlimit; /* Limit for number of space warnings */
  366. unsigned int ino_warnlimit; /* Ditto for inodes */
  367. unsigned int rt_spc_warnlimit; /* Ditto for real-time space */
  368. unsigned long long ino; /* Inode number of quota file */
  369. blkcnt_t blocks; /* Number of 512-byte blocks in the file */
  370. blkcnt_t nextents; /* Number of extents in the file */
  371. };
  372. struct qc_state {
  373. unsigned int s_incoredqs; /* Number of dquots in core */
  374. struct qc_type_state s_state[MAXQUOTAS]; /* Per quota type information */
  375. };
  376. /* Structure for communicating via ->set_info */
  377. struct qc_info {
  378. int i_fieldmask; /* mask of fields to change in ->set_info() */
  379. unsigned int i_flags; /* Flags QCI_* */
  380. unsigned int i_spc_timelimit; /* Time after which space softlimit is
  381. * enforced */
  382. unsigned int i_ino_timelimit; /* Ditto for inode softlimit */
  383. unsigned int i_rt_spc_timelimit;/* Ditto for real-time space */
  384. unsigned int i_spc_warnlimit; /* Limit for number of space warnings */
  385. unsigned int i_ino_warnlimit; /* Limit for number of inode warnings */
  386. unsigned int i_rt_spc_warnlimit; /* Ditto for real-time space */
  387. };
  388. /* Operations handling requests from userspace */
  389. struct quotactl_ops {
  390. int (*quota_on)(struct super_block *, int, int, const struct path *);
  391. int (*quota_off)(struct super_block *, int);
  392. int (*quota_enable)(struct super_block *, unsigned int);
  393. int (*quota_disable)(struct super_block *, unsigned int);
  394. int (*quota_sync)(struct super_block *, int);
  395. int (*set_info)(struct super_block *, int, struct qc_info *);
  396. int (*get_dqblk)(struct super_block *, struct kqid, struct qc_dqblk *);
  397. int (*get_nextdqblk)(struct super_block *, struct kqid *,
  398. struct qc_dqblk *);
  399. int (*set_dqblk)(struct super_block *, struct kqid, struct qc_dqblk *);
  400. int (*get_state)(struct super_block *, struct qc_state *);
  401. int (*rm_xquota)(struct super_block *, unsigned int);
  402. ANDROID_KABI_RESERVE(1);
  403. ANDROID_KABI_RESERVE(2);
  404. };
  405. struct quota_format_type {
  406. int qf_fmt_id; /* Quota format id */
  407. const struct quota_format_ops *qf_ops; /* Operations of format */
  408. struct module *qf_owner; /* Module implementing quota format */
  409. struct quota_format_type *qf_next;
  410. };
  411. /**
  412. * Quota state flags - they actually come in two flavors - for users and groups.
  413. *
  414. * Actual typed flags layout:
  415. * USRQUOTA GRPQUOTA
  416. * DQUOT_USAGE_ENABLED 0x0001 0x0002
  417. * DQUOT_LIMITS_ENABLED 0x0004 0x0008
  418. * DQUOT_SUSPENDED 0x0010 0x0020
  419. *
  420. * Following bits are used for non-typed flags:
  421. * DQUOT_QUOTA_SYS_FILE 0x0040
  422. * DQUOT_NEGATIVE_USAGE 0x0080
  423. */
  424. enum {
  425. _DQUOT_USAGE_ENABLED = 0, /* Track disk usage for users */
  426. _DQUOT_LIMITS_ENABLED, /* Enforce quota limits for users */
  427. _DQUOT_SUSPENDED, /* User diskquotas are off, but
  428. * we have necessary info in
  429. * memory to turn them on */
  430. _DQUOT_STATE_FLAGS
  431. };
  432. #define DQUOT_USAGE_ENABLED (1 << _DQUOT_USAGE_ENABLED * MAXQUOTAS)
  433. #define DQUOT_LIMITS_ENABLED (1 << _DQUOT_LIMITS_ENABLED * MAXQUOTAS)
  434. #define DQUOT_SUSPENDED (1 << _DQUOT_SUSPENDED * MAXQUOTAS)
  435. #define DQUOT_STATE_FLAGS (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED | \
  436. DQUOT_SUSPENDED)
  437. /* Other quota flags */
  438. #define DQUOT_STATE_LAST (_DQUOT_STATE_FLAGS * MAXQUOTAS)
  439. #define DQUOT_QUOTA_SYS_FILE (1 << DQUOT_STATE_LAST)
  440. /* Quota file is a special
  441. * system file and user cannot
  442. * touch it. Filesystem is
  443. * responsible for setting
  444. * S_NOQUOTA, S_NOATIME flags
  445. */
  446. #define DQUOT_NEGATIVE_USAGE (1 << (DQUOT_STATE_LAST + 1))
  447. /* Allow negative quota usage */
  448. /* Do not track dirty dquots in a list */
  449. #define DQUOT_NOLIST_DIRTY (1 << (DQUOT_STATE_LAST + 2))
  450. static inline unsigned int dquot_state_flag(unsigned int flags, int type)
  451. {
  452. return flags << type;
  453. }
  454. static inline unsigned int dquot_generic_flag(unsigned int flags, int type)
  455. {
  456. return (flags >> type) & DQUOT_STATE_FLAGS;
  457. }
  458. /* Bitmap of quota types where flag is set in flags */
  459. static __always_inline unsigned dquot_state_types(unsigned flags, unsigned flag)
  460. {
  461. BUILD_BUG_ON_NOT_POWER_OF_2(flag);
  462. return (flags / flag) & ((1 << MAXQUOTAS) - 1);
  463. }
  464. #ifdef CONFIG_QUOTA_NETLINK_INTERFACE
  465. extern void quota_send_warning(struct kqid qid, dev_t dev,
  466. const char warntype);
  467. #else
  468. static inline void quota_send_warning(struct kqid qid, dev_t dev,
  469. const char warntype)
  470. {
  471. return;
  472. }
  473. #endif /* CONFIG_QUOTA_NETLINK_INTERFACE */
  474. struct quota_info {
  475. unsigned int flags; /* Flags for diskquotas on this device */
  476. struct rw_semaphore dqio_sem; /* Lock quota file while I/O in progress */
  477. struct inode *files[MAXQUOTAS]; /* inodes of quotafiles */
  478. struct mem_dqinfo info[MAXQUOTAS]; /* Information for each quota type */
  479. const struct quota_format_ops *ops[MAXQUOTAS]; /* Operations for each type */
  480. };
  481. int register_quota_format(struct quota_format_type *fmt);
  482. void unregister_quota_format(struct quota_format_type *fmt);
  483. struct quota_module_name {
  484. int qm_fmt_id;
  485. char *qm_mod_name;
  486. };
  487. #define INIT_QUOTA_MODULE_NAMES {\
  488. {QFMT_VFS_OLD, "quota_v1"},\
  489. {QFMT_VFS_V0, "quota_v2"},\
  490. {QFMT_VFS_V1, "quota_v2"},\
  491. {0, NULL}}
  492. #endif /* _QUOTA_ */