Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/fs.h>
0003 #include <linux/quota.h>
0004 #include <linux/export.h>
0005 
0006 /**
0007  *  qid_eq - Test to see if to kquid values are the same
0008  *  @left: A qid value
0009  *  @right: Another quid value
0010  *
0011  *  Return true if the two qid values are equal and false otherwise.
0012  */
0013 bool qid_eq(struct kqid left, struct kqid right)
0014 {
0015     if (left.type != right.type)
0016         return false;
0017     switch(left.type) {
0018     case USRQUOTA:
0019         return uid_eq(left.uid, right.uid);
0020     case GRPQUOTA:
0021         return gid_eq(left.gid, right.gid);
0022     case PRJQUOTA:
0023         return projid_eq(left.projid, right.projid);
0024     default:
0025         BUG();
0026     }
0027 }
0028 EXPORT_SYMBOL(qid_eq);
0029 
0030 /**
0031  *  qid_lt - Test to see if one qid value is less than another
0032  *  @left: The possibly lesser qid value
0033  *  @right: The possibly greater qid value
0034  *
0035  *  Return true if left is less than right and false otherwise.
0036  */
0037 bool qid_lt(struct kqid left, struct kqid right)
0038 {
0039     if (left.type < right.type)
0040         return true;
0041     if (left.type > right.type)
0042         return false;
0043     switch (left.type) {
0044     case USRQUOTA:
0045         return uid_lt(left.uid, right.uid);
0046     case GRPQUOTA:
0047         return gid_lt(left.gid, right.gid);
0048     case PRJQUOTA:
0049         return projid_lt(left.projid, right.projid);
0050     default:
0051         BUG();
0052     }
0053 }
0054 EXPORT_SYMBOL(qid_lt);
0055 
0056 /**
0057  *  from_kqid - Create a qid from a kqid user-namespace pair.
0058  *  @targ: The user namespace we want a qid in.
0059  *  @kqid: The kernel internal quota identifier to start with.
0060  *
0061  *  Map @kqid into the user-namespace specified by @targ and
0062  *  return the resulting qid.
0063  *
0064  *  There is always a mapping into the initial user_namespace.
0065  *
0066  *  If @kqid has no mapping in @targ (qid_t)-1 is returned.
0067  */
0068 qid_t from_kqid(struct user_namespace *targ, struct kqid kqid)
0069 {
0070     switch (kqid.type) {
0071     case USRQUOTA:
0072         return from_kuid(targ, kqid.uid);
0073     case GRPQUOTA:
0074         return from_kgid(targ, kqid.gid);
0075     case PRJQUOTA:
0076         return from_kprojid(targ, kqid.projid);
0077     default:
0078         BUG();
0079     }
0080 }
0081 EXPORT_SYMBOL(from_kqid);
0082 
0083 /**
0084  *  from_kqid_munged - Create a qid from a kqid user-namespace pair.
0085  *  @targ: The user namespace we want a qid in.
0086  *  @kqid: The kernel internal quota identifier to start with.
0087  *
0088  *  Map @kqid into the user-namespace specified by @targ and
0089  *  return the resulting qid.
0090  *
0091  *  There is always a mapping into the initial user_namespace.
0092  *
0093  *  Unlike from_kqid from_kqid_munged never fails and always
0094  *  returns a valid projid.  This makes from_kqid_munged
0095  *  appropriate for use in places where failing to provide
0096  *  a qid_t is not a good option.
0097  *
0098  *  If @kqid has no mapping in @targ the kqid.type specific
0099  *  overflow identifier is returned.
0100  */
0101 qid_t from_kqid_munged(struct user_namespace *targ, struct kqid kqid)
0102 {
0103     switch (kqid.type) {
0104     case USRQUOTA:
0105         return from_kuid_munged(targ, kqid.uid);
0106     case GRPQUOTA:
0107         return from_kgid_munged(targ, kqid.gid);
0108     case PRJQUOTA:
0109         return from_kprojid_munged(targ, kqid.projid);
0110     default:
0111         BUG();
0112     }
0113 }
0114 EXPORT_SYMBOL(from_kqid_munged);
0115 
0116 /**
0117  *  qid_valid - Report if a valid value is stored in a kqid.
0118  *  @qid: The kernel internal quota identifier to test.
0119  */
0120 bool qid_valid(struct kqid qid)
0121 {
0122     switch (qid.type) {
0123     case USRQUOTA:
0124         return uid_valid(qid.uid);
0125     case GRPQUOTA:
0126         return gid_valid(qid.gid);
0127     case PRJQUOTA:
0128         return projid_valid(qid.projid);
0129     default:
0130         BUG();
0131     }
0132 }
0133 EXPORT_SYMBOL(qid_valid);