staging: rtl8723au: core: Drop unneeded pointer cast
[linux/fpc-iii.git] / fs / quota / kqid.c
blobebc5e62858007d8f9ed6acee5f6aef2afb28c9c0
1 #include <linux/fs.h>
2 #include <linux/quota.h>
3 #include <linux/export.h>
5 /**
6 * qid_eq - Test to see if to kquid values are the same
7 * @left: A qid value
8 * @right: Another quid value
10 * Return true if the two qid values are equal and false otherwise.
12 bool qid_eq(struct kqid left, struct kqid right)
14 if (left.type != right.type)
15 return false;
16 switch(left.type) {
17 case USRQUOTA:
18 return uid_eq(left.uid, right.uid);
19 case GRPQUOTA:
20 return gid_eq(left.gid, right.gid);
21 case PRJQUOTA:
22 return projid_eq(left.projid, right.projid);
23 default:
24 BUG();
27 EXPORT_SYMBOL(qid_eq);
29 /**
30 * qid_lt - Test to see if one qid value is less than another
31 * @left: The possibly lesser qid value
32 * @right: The possibly greater qid value
34 * Return true if left is less than right and false otherwise.
36 bool qid_lt(struct kqid left, struct kqid right)
38 if (left.type < right.type)
39 return true;
40 if (left.type > right.type)
41 return false;
42 switch (left.type) {
43 case USRQUOTA:
44 return uid_lt(left.uid, right.uid);
45 case GRPQUOTA:
46 return gid_lt(left.gid, right.gid);
47 case PRJQUOTA:
48 return projid_lt(left.projid, right.projid);
49 default:
50 BUG();
53 EXPORT_SYMBOL(qid_lt);
55 /**
56 * from_kqid - Create a qid from a kqid user-namespace pair.
57 * @targ: The user namespace we want a qid in.
58 * @kqid: The kernel internal quota identifier to start with.
60 * Map @kqid into the user-namespace specified by @targ and
61 * return the resulting qid.
63 * There is always a mapping into the initial user_namespace.
65 * If @kqid has no mapping in @targ (qid_t)-1 is returned.
67 qid_t from_kqid(struct user_namespace *targ, struct kqid kqid)
69 switch (kqid.type) {
70 case USRQUOTA:
71 return from_kuid(targ, kqid.uid);
72 case GRPQUOTA:
73 return from_kgid(targ, kqid.gid);
74 case PRJQUOTA:
75 return from_kprojid(targ, kqid.projid);
76 default:
77 BUG();
80 EXPORT_SYMBOL(from_kqid);
82 /**
83 * from_kqid_munged - Create a qid from a kqid user-namespace pair.
84 * @targ: The user namespace we want a qid in.
85 * @kqid: The kernel internal quota identifier to start with.
87 * Map @kqid into the user-namespace specified by @targ and
88 * return the resulting qid.
90 * There is always a mapping into the initial user_namespace.
92 * Unlike from_kqid from_kqid_munged never fails and always
93 * returns a valid projid. This makes from_kqid_munged
94 * appropriate for use in places where failing to provide
95 * a qid_t is not a good option.
97 * If @kqid has no mapping in @targ the kqid.type specific
98 * overflow identifier is returned.
100 qid_t from_kqid_munged(struct user_namespace *targ, struct kqid kqid)
102 switch (kqid.type) {
103 case USRQUOTA:
104 return from_kuid_munged(targ, kqid.uid);
105 case GRPQUOTA:
106 return from_kgid_munged(targ, kqid.gid);
107 case PRJQUOTA:
108 return from_kprojid_munged(targ, kqid.projid);
109 default:
110 BUG();
113 EXPORT_SYMBOL(from_kqid_munged);
116 * qid_valid - Report if a valid value is stored in a kqid.
117 * @qid: The kernel internal quota identifier to test.
119 bool qid_valid(struct kqid qid)
121 switch (qid.type) {
122 case USRQUOTA:
123 return uid_valid(qid.uid);
124 case GRPQUOTA:
125 return gid_valid(qid.gid);
126 case PRJQUOTA:
127 return projid_valid(qid.projid);
128 default:
129 BUG();
132 EXPORT_SYMBOL(qid_valid);