aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/projid.h
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2012-08-30 04:24:05 -0400
committerEric W. Biederman <ebiederm@xmission.com>2012-09-18 04:01:37 -0400
commitf76d207a66c3a53defea67e7d36c3eb1b7d6d61d (patch)
tree2d2a459c539d6f0b92e8ca856632e65f6c293af7 /include/linux/projid.h
parent69552c0c50f3f950f304fb07a4320e46f7f60c21 (diff)
userns: Add kprojid_t and associated infrastructure in projid.h
Implement kprojid_t a cousin of the kuid_t and kgid_t. The per user namespace mapping of project id values can be set with /proc/<pid>/projid_map. A full compliment of helpers is provided: make_kprojid, from_kprojid, from_kprojid_munged, kporjid_has_mapping, projid_valid, projid_eq, projid_eq, projid_lt. Project identifiers are part of the generic disk quota interface, although it appears only xfs implements project identifiers currently. The xfs code allows anyone who has permission to set the project identifier on a file to use any project identifier so when setting up the user namespace project identifier mappings I do not require a capability. Cc: Dave Chinner <david@fromorbit.com> Cc: Jan Kara <jack@suse.cz> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Diffstat (limited to 'include/linux/projid.h')
-rw-r--r--include/linux/projid.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/include/linux/projid.h b/include/linux/projid.h
new file mode 100644
index 000000000000..36517b95be5c
--- /dev/null
+++ b/include/linux/projid.h
@@ -0,0 +1,104 @@
1#ifndef _LINUX_PROJID_H
2#define _LINUX_PROJID_H
3
4/*
5 * A set of types for the internal kernel types representing project ids.
6 *
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.
12 *
13 */
14#include <linux/types.h>
15
16struct user_namespace;
17extern struct user_namespace init_user_ns;
18
19typedef __kernel_uid32_t projid_t;
20
21#ifdef CONFIG_UIDGID_STRICT_TYPE_CHECKS
22
23typedef struct {
24 projid_t val;
25} kprojid_t;
26
27static inline projid_t __kprojid_val(kprojid_t projid)
28{
29 return projid.val;
30}
31
32#define KPROJIDT_INIT(value) (kprojid_t){ value }
33
34#else
35
36typedef projid_t kprojid_t;
37
38static inline projid_t __kprojid_val(kprojid_t projid)
39{
40 return projid;
41}
42
43#define KPROJIDT_INIT(value) ((kprojid_t) value )
44
45#endif
46
47#define INVALID_PROJID KPROJIDT_INIT(-1)
48#define OVERFLOW_PROJID 65534
49
50static inline bool projid_eq(kprojid_t left, kprojid_t right)
51{
52 return __kprojid_val(left) == __kprojid_val(right);
53}
54
55static inline bool projid_lt(kprojid_t left, kprojid_t right)
56{
57 return __kprojid_val(left) < __kprojid_val(right);
58}
59
60static inline bool projid_valid(kprojid_t projid)
61{
62 return !projid_eq(projid, INVALID_PROJID);
63}
64
65#ifdef CONFIG_USER_NS
66
67extern kprojid_t make_kprojid(struct user_namespace *from, projid_t projid);
68
69extern projid_t from_kprojid(struct user_namespace *to, kprojid_t projid);
70extern projid_t from_kprojid_munged(struct user_namespace *to, kprojid_t projid);
71
72static inline bool kprojid_has_mapping(struct user_namespace *ns, kprojid_t projid)
73{
74 return from_kprojid(ns, projid) != (projid_t)-1;
75}
76
77#else
78
79static inline kprojid_t make_kprojid(struct user_namespace *from, projid_t projid)
80{
81 return KPROJIDT_INIT(projid);
82}
83
84static inline projid_t from_kprojid(struct user_namespace *to, kprojid_t kprojid)
85{
86 return __kprojid_val(kprojid);
87}
88
89static inline projid_t from_kprojid_munged(struct user_namespace *to, kprojid_t kprojid)
90{
91 projid_t projid = from_kprojid(to, kprojid);
92 if (projid == (projid_t)-1)
93 projid = OVERFLOW_PROJID;
94 return projid;
95}
96
97static inline bool kprojid_has_mapping(struct user_namespace *ns, kprojid_t projid)
98{
99 return true;
100}
101
102#endif /* CONFIG_USER_NS */
103
104#endif /* _LINUX_PROJID_H */