1 #ifndef _LINUX_PROJID_H
2 #define _LINUX_PROJID_H
5 * A set of types for the internal kernel types representing project ids.
7 * The types defined in this header allow distinguishing which project ids in
8 * the kernel are values used by userspace and which project id values are
9 * the internal kernel values. With the addition of user namespaces the values
10 * can be different. Using the type system makes it possible for the compiler
11 * to detect when we overlook these differences.
14 #include <linux/types.h>
16 struct user_namespace;
17 extern struct user_namespace init_user_ns;
19 typedef __kernel_uid32_t projid_t;
21 #ifdef CONFIG_UIDGID_STRICT_TYPE_CHECKS
27 static inline projid_t __kprojid_val(kprojid_t projid)
32 #define KPROJIDT_INIT(value) (kprojid_t){ value }
36 typedef projid_t kprojid_t;
38 static inline projid_t __kprojid_val(kprojid_t projid)
43 #define KPROJIDT_INIT(value) ((kprojid_t) value )
47 #define INVALID_PROJID KPROJIDT_INIT(-1)
48 #define OVERFLOW_PROJID 65534
50 static inline bool projid_eq(kprojid_t left, kprojid_t right)
52 return __kprojid_val(left) == __kprojid_val(right);
55 static inline bool projid_lt(kprojid_t left, kprojid_t right)
57 return __kprojid_val(left) < __kprojid_val(right);
60 static inline bool projid_valid(kprojid_t projid)
62 return !projid_eq(projid, INVALID_PROJID);
67 extern kprojid_t make_kprojid(struct user_namespace *from, projid_t projid);
69 extern projid_t from_kprojid(struct user_namespace *to, kprojid_t projid);
70 extern projid_t from_kprojid_munged(struct user_namespace *to, kprojid_t projid);
72 static inline bool kprojid_has_mapping(struct user_namespace *ns, kprojid_t projid)
74 return from_kprojid(ns, projid) != (projid_t)-1;
79 static inline kprojid_t make_kprojid(struct user_namespace *from, projid_t projid)
81 return KPROJIDT_INIT(projid);
84 static inline projid_t from_kprojid(struct user_namespace *to, kprojid_t kprojid)
86 return __kprojid_val(kprojid);
89 static inline projid_t from_kprojid_munged(struct user_namespace *to, kprojid_t kprojid)
91 projid_t projid = from_kprojid(to, kprojid);
92 if (projid == (projid_t)-1)
93 projid = OVERFLOW_PROJID;
97 static inline bool kprojid_has_mapping(struct user_namespace *ns, kprojid_t projid)
102 #endif /* CONFIG_USER_NS */
104 #endif /* _LINUX_PROJID_H */