1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/quota.h>
4 #include <linux/export.h>
7 * qid_eq - Test to see if to kquid values are the same
9 * @right: Another quid value
11 * Return true if the two qid values are equal and false otherwise.
13 bool qid_eq(struct kqid left, struct kqid right)
15 if (left.type != right.type)
19 return uid_eq(left.uid, right.uid);
21 return gid_eq(left.gid, right.gid);
23 return projid_eq(left.projid, right.projid);
28 EXPORT_SYMBOL(qid_eq);
31 * qid_lt - Test to see if one qid value is less than another
32 * @left: The possibly lesser qid value
33 * @right: The possibly greater qid value
35 * Return true if left is less than right and false otherwise.
37 bool qid_lt(struct kqid left, struct kqid right)
39 if (left.type < right.type)
41 if (left.type > right.type)
45 return uid_lt(left.uid, right.uid);
47 return gid_lt(left.gid, right.gid);
49 return projid_lt(left.projid, right.projid);
54 EXPORT_SYMBOL(qid_lt);
57 * from_kqid - Create a qid from a kqid user-namespace pair.
58 * @targ: The user namespace we want a qid in.
59 * @kqid: The kernel internal quota identifier to start with.
61 * Map @kqid into the user-namespace specified by @targ and
62 * return the resulting qid.
64 * There is always a mapping into the initial user_namespace.
66 * If @kqid has no mapping in @targ (qid_t)-1 is returned.
68 qid_t from_kqid(struct user_namespace *targ, struct kqid kqid)
72 return from_kuid(targ, kqid.uid);
74 return from_kgid(targ, kqid.gid);
76 return from_kprojid(targ, kqid.projid);
81 EXPORT_SYMBOL(from_kqid);
84 * from_kqid_munged - Create a qid from a kqid user-namespace pair.
85 * @targ: The user namespace we want a qid in.
86 * @kqid: The kernel internal quota identifier to start with.
88 * Map @kqid into the user-namespace specified by @targ and
89 * return the resulting qid.
91 * There is always a mapping into the initial user_namespace.
93 * Unlike from_kqid from_kqid_munged never fails and always
94 * returns a valid projid. This makes from_kqid_munged
95 * appropriate for use in places where failing to provide
96 * a qid_t is not a good option.
98 * If @kqid has no mapping in @targ the kqid.type specific
99 * overflow identifier is returned.
101 qid_t from_kqid_munged(struct user_namespace *targ, struct kqid kqid)
105 return from_kuid_munged(targ, kqid.uid);
107 return from_kgid_munged(targ, kqid.gid);
109 return from_kprojid_munged(targ, kqid.projid);
114 EXPORT_SYMBOL(from_kqid_munged);
117 * qid_valid - Report if a valid value is stored in a kqid.
118 * @qid: The kernel internal quota identifier to test.
120 bool qid_valid(struct kqid qid)
124 return uid_valid(qid.uid);
126 return gid_valid(qid.gid);
128 return projid_valid(qid.projid);
133 EXPORT_SYMBOL(qid_valid);