quota.h 18 KB

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