Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/quota.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	qid_eq - Test to see if to kquid values are the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	@left: A qid value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	@right: Another quid value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *	Return true if the two qid values are equal and false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) bool qid_eq(struct kqid left, struct kqid right)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	if (left.type != right.type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	switch(left.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	case USRQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 		return uid_eq(left.uid, right.uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	case GRPQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		return gid_eq(left.gid, right.gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	case PRJQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		return projid_eq(left.projid, right.projid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) EXPORT_SYMBOL(qid_eq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *	qid_lt - Test to see if one qid value is less than another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *	@left: The possibly lesser qid value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *	@right: The possibly greater qid value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *	Return true if left is less than right and false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) bool qid_lt(struct kqid left, struct kqid right)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (left.type < right.type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (left.type > right.type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	switch (left.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	case USRQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		return uid_lt(left.uid, right.uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	case GRPQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		return gid_lt(left.gid, right.gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	case PRJQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return projid_lt(left.projid, right.projid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) EXPORT_SYMBOL(qid_lt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *	from_kqid - Create a qid from a kqid user-namespace pair.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *	@targ: The user namespace we want a qid in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *	@kqid: The kernel internal quota identifier to start with.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *	Map @kqid into the user-namespace specified by @targ and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *	return the resulting qid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *	There is always a mapping into the initial user_namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *	If @kqid has no mapping in @targ (qid_t)-1 is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) qid_t from_kqid(struct user_namespace *targ, struct kqid kqid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	switch (kqid.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	case USRQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return from_kuid(targ, kqid.uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	case GRPQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return from_kgid(targ, kqid.gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	case PRJQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return from_kprojid(targ, kqid.projid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) EXPORT_SYMBOL(from_kqid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  *	from_kqid_munged - Create a qid from a kqid user-namespace pair.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  *	@targ: The user namespace we want a qid in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  *	@kqid: The kernel internal quota identifier to start with.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  *	Map @kqid into the user-namespace specified by @targ and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  *	return the resulting qid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  *	There is always a mapping into the initial user_namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  *	Unlike from_kqid from_kqid_munged never fails and always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  *	returns a valid projid.  This makes from_kqid_munged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  *	appropriate for use in places where failing to provide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  *	a qid_t is not a good option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  *	If @kqid has no mapping in @targ the kqid.type specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  *	overflow identifier is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) qid_t from_kqid_munged(struct user_namespace *targ, struct kqid kqid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	switch (kqid.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	case USRQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return from_kuid_munged(targ, kqid.uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	case GRPQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		return from_kgid_munged(targ, kqid.gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	case PRJQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		return from_kprojid_munged(targ, kqid.projid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) EXPORT_SYMBOL(from_kqid_munged);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  *	qid_valid - Report if a valid value is stored in a kqid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  *	@qid: The kernel internal quota identifier to test.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) bool qid_valid(struct kqid qid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	switch (qid.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	case USRQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return uid_valid(qid.uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	case GRPQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return gid_valid(qid.gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	case PRJQUOTA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		return projid_valid(qid.projid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) EXPORT_SYMBOL(qid_valid);